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