1 //===-- CompilerDeclContext.h -----------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef liblldb_CompilerDeclContext_h_ 10 #define liblldb_CompilerDeclContext_h_ 11 12 #include <vector> 13 14 #include "lldb/Utility/ConstString.h" 15 #include "lldb/lldb-private.h" 16 17 namespace lldb_private { 18 19 class CompilerDeclContext { 20 public: 21 //---------------------------------------------------------------------- 22 // Constructors and Destructors 23 //---------------------------------------------------------------------- 24 CompilerDeclContext() : m_type_system(nullptr), m_opaque_decl_ctx(nullptr) {} 25 26 CompilerDeclContext(TypeSystem *type_system, void *decl_ctx) 27 : m_type_system(type_system), m_opaque_decl_ctx(decl_ctx) {} 28 29 ~CompilerDeclContext() {} 30 31 //---------------------------------------------------------------------- 32 // Tests 33 //---------------------------------------------------------------------- 34 35 explicit operator bool() const { return IsValid(); } 36 37 bool operator<(const CompilerDeclContext &rhs) const { 38 if (m_type_system == rhs.m_type_system) 39 return m_opaque_decl_ctx < rhs.m_opaque_decl_ctx; 40 return m_type_system < rhs.m_type_system; 41 } 42 43 bool IsValid() const { 44 return m_type_system != nullptr && m_opaque_decl_ctx != nullptr; 45 } 46 47 bool IsClang() const; 48 49 std::vector<CompilerDecl> FindDeclByName(ConstString name, 50 const bool ignore_using_decls); 51 52 //---------------------------------------------------------------------- 53 /// Checks if this decl context represents a method of a class. 54 /// 55 /// \param[out] language_ptr 56 /// If non NULL and \b true is returned from this function, 57 /// this will indicate if the language that respresents the method. 58 /// 59 /// \param[out] is_instance_method_ptr 60 /// If non NULL and \b true is returned from this function, 61 /// this will indicate if the method is an instance function (true) 62 /// or a class method (false indicating the function is static, or 63 /// doesn't require an instance of the class to be called). 64 /// 65 /// \param[out] language_object_name_ptr 66 /// If non NULL and \b true is returned from this function, 67 /// this will indicate if implicit object name for the language 68 /// like "this" for C++, and "self" for Objective C. 69 /// 70 /// \return 71 /// Returns true if this is a decl context that represents a method 72 /// in a struct, union or class. 73 //---------------------------------------------------------------------- 74 bool IsClassMethod(lldb::LanguageType *language_ptr, 75 bool *is_instance_method_ptr, 76 ConstString *language_object_name_ptr); 77 78 //---------------------------------------------------------------------- 79 /// Check if the given other decl context is contained in the lookup 80 /// of this decl context (for example because the other context is a nested 81 /// inline namespace). 82 /// 83 /// @param[in] other 84 /// The other decl context for which we should check if it is contained 85 /// in the lookoup of this context. 86 /// 87 /// @return 88 /// Returns true iff the other decl context is contained in the lookup 89 /// of this decl context. 90 //---------------------------------------------------------------------- 91 bool IsContainedInLookup(CompilerDeclContext other) const; 92 93 //---------------------------------------------------------------------- 94 // Accessors 95 //---------------------------------------------------------------------- 96 97 TypeSystem *GetTypeSystem() const { return m_type_system; } 98 99 void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; } 100 101 void SetDeclContext(TypeSystem *type_system, void *decl_ctx) { 102 m_type_system = type_system; 103 m_opaque_decl_ctx = decl_ctx; 104 } 105 106 void Clear() { 107 m_type_system = nullptr; 108 m_opaque_decl_ctx = nullptr; 109 } 110 111 ConstString GetName() const; 112 113 ConstString GetScopeQualifiedName() const; 114 115 bool IsStructUnionOrClass() const; 116 117 private: 118 TypeSystem *m_type_system; 119 void *m_opaque_decl_ctx; 120 }; 121 122 bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs); 123 bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs); 124 125 } // namespace lldb_private 126 127 #endif // #ifndef liblldb_CompilerDeclContext_h_ 128