1 //===-- CompilerDeclContext.h -----------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_CompilerDeclContext_h_
10 #define liblldb_CompilerDeclContext_h_
14 #include "lldb/Utility/ConstString.h"
15 #include "lldb/lldb-private.h"
17 namespace lldb_private {
19 class CompilerDeclContext {
21 // Constructors and Destructors
22 CompilerDeclContext() : m_type_system(nullptr), m_opaque_decl_ctx(nullptr) {}
24 CompilerDeclContext(TypeSystem *type_system, void *decl_ctx)
25 : m_type_system(type_system), m_opaque_decl_ctx(decl_ctx) {}
27 ~CompilerDeclContext() {}
31 explicit operator bool() const { return IsValid(); }
33 bool operator<(const CompilerDeclContext &rhs) const {
34 if (m_type_system == rhs.m_type_system)
35 return m_opaque_decl_ctx < rhs.m_opaque_decl_ctx;
36 return m_type_system < rhs.m_type_system;
39 bool IsValid() const {
40 return m_type_system != nullptr && m_opaque_decl_ctx != nullptr;
45 std::vector<CompilerDecl> FindDeclByName(ConstString name,
46 const bool ignore_using_decls);
48 /// Checks if this decl context represents a method of a class.
50 /// \param[out] language_ptr
51 /// If non NULL and \b true is returned from this function,
52 /// this will indicate if the language that respresents the method.
54 /// \param[out] is_instance_method_ptr
55 /// If non NULL and \b true is returned from this function,
56 /// this will indicate if the method is an instance function (true)
57 /// or a class method (false indicating the function is static, or
58 /// doesn't require an instance of the class to be called).
60 /// \param[out] language_object_name_ptr
61 /// If non NULL and \b true is returned from this function,
62 /// this will indicate if implicit object name for the language
63 /// like "this" for C++, and "self" for Objective C.
66 /// Returns true if this is a decl context that represents a method
67 /// in a struct, union or class.
68 bool IsClassMethod(lldb::LanguageType *language_ptr,
69 bool *is_instance_method_ptr,
70 ConstString *language_object_name_ptr);
72 /// Check if the given other decl context is contained in the lookup
73 /// of this decl context (for example because the other context is a nested
74 /// inline namespace).
77 /// The other decl context for which we should check if it is contained
78 /// in the lookoup of this context.
81 /// Returns true iff the other decl context is contained in the lookup
82 /// of this decl context.
83 bool IsContainedInLookup(CompilerDeclContext other) const;
87 TypeSystem *GetTypeSystem() const { return m_type_system; }
89 void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; }
91 void SetDeclContext(TypeSystem *type_system, void *decl_ctx) {
92 m_type_system = type_system;
93 m_opaque_decl_ctx = decl_ctx;
97 m_type_system = nullptr;
98 m_opaque_decl_ctx = nullptr;
101 ConstString GetName() const;
103 ConstString GetScopeQualifiedName() const;
105 bool IsStructUnionOrClass() const;
108 TypeSystem *m_type_system;
109 void *m_opaque_decl_ctx;
112 bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
113 bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
115 } // namespace lldb_private
117 #endif // #ifndef liblldb_CompilerDeclContext_h_