CompilerDeclContext.h revision 294024
1//===-- CompilerDeclContext.h -----------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_CompilerDeclContext_h_ 11#define liblldb_CompilerDeclContext_h_ 12 13#include <vector> 14 15#include "lldb/lldb-private.h" 16#include "lldb/Core/ConstString.h" 17 18namespace lldb_private { 19 20class CompilerDeclContext 21{ 22public: 23 //---------------------------------------------------------------------- 24 // Constructors and Destructors 25 //---------------------------------------------------------------------- 26 CompilerDeclContext () : 27 m_type_system (nullptr), 28 m_opaque_decl_ctx (nullptr) 29 { 30 } 31 32 CompilerDeclContext (TypeSystem *type_system, void *decl_ctx) : 33 m_type_system (type_system), 34 m_opaque_decl_ctx (decl_ctx) 35 { 36 } 37 38 ~CompilerDeclContext() 39 { 40 } 41 42 //---------------------------------------------------------------------- 43 // Tests 44 //---------------------------------------------------------------------- 45 46 explicit operator bool () const 47 { 48 return IsValid (); 49 } 50 51 bool 52 operator < (const CompilerDeclContext &rhs) const 53 { 54 if (m_type_system == rhs.m_type_system) 55 return m_opaque_decl_ctx < rhs.m_opaque_decl_ctx; 56 return m_type_system < rhs.m_type_system; 57 } 58 59 bool 60 IsValid () const 61 { 62 return m_type_system != nullptr && m_opaque_decl_ctx != nullptr; 63 } 64 65 bool 66 IsClang () const; 67 68 std::vector<CompilerDecl> 69 FindDeclByName (ConstString name); 70 71 //---------------------------------------------------------------------- 72 /// Checks if this decl context represents a method of a class. 73 /// 74 /// @param[out] language_ptr 75 /// If non NULL and \b true is returned from this function, 76 /// this will indicate if the language that respresents the method. 77 /// 78 /// @param[out] is_instance_method_ptr 79 /// If non NULL and \b true is returned from this function, 80 /// this will indicate if the method is an instance function (true) 81 /// or a class method (false indicating the function is static, or 82 /// doesn't require an instance of the class to be called). 83 /// 84 /// @param[out] language_object_name_ptr 85 /// If non NULL and \b true is returned from this function, 86 /// this will indicate if implicit object name for the language 87 /// like "this" for C++, and "self" for Objective C. 88 /// 89 /// @return 90 /// Returns true if this is a decl context that represents a method 91 /// in a struct, union or class. 92 //---------------------------------------------------------------------- 93 bool 94 IsClassMethod (lldb::LanguageType *language_ptr, 95 bool *is_instance_method_ptr, 96 ConstString *language_object_name_ptr); 97 98 //---------------------------------------------------------------------- 99 // Accessors 100 //---------------------------------------------------------------------- 101 102 TypeSystem * 103 GetTypeSystem() const 104 { 105 return m_type_system; 106 } 107 108 void * 109 GetOpaqueDeclContext() const 110 { 111 return m_opaque_decl_ctx; 112 } 113 114 void 115 SetDeclContext (TypeSystem* type_system, void* decl_ctx) 116 { 117 m_type_system = type_system; 118 m_opaque_decl_ctx = decl_ctx; 119 } 120 121 void 122 Clear() 123 { 124 m_type_system = nullptr; 125 m_opaque_decl_ctx = nullptr; 126 } 127 128 ConstString 129 GetName () const; 130 131 ConstString 132 GetScopeQualifiedName() const; 133 134 bool 135 IsStructUnionOrClass () const; 136 137private: 138 TypeSystem *m_type_system; 139 void *m_opaque_decl_ctx; 140 141}; 142 143bool operator == (const CompilerDeclContext &lhs, const CompilerDeclContext &rhs); 144bool operator != (const CompilerDeclContext &lhs, const CompilerDeclContext &rhs); 145 146 147} // namespace lldb_private 148 149#endif // #ifndef liblldb_CompilerDeclContext_h_ 150