1 //===-- CompilerDeclContext.h -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_CompilerDeclContext_h_
11 #define liblldb_CompilerDeclContext_h_
15 #include "lldb/Utility/ConstString.h"
16 #include "lldb/lldb-private.h"
18 namespace lldb_private {
20 class CompilerDeclContext {
22 //----------------------------------------------------------------------
23 // Constructors and Destructors
24 //----------------------------------------------------------------------
25 CompilerDeclContext() : m_type_system(nullptr), m_opaque_decl_ctx(nullptr) {}
27 CompilerDeclContext(TypeSystem *type_system, void *decl_ctx)
28 : m_type_system(type_system), m_opaque_decl_ctx(decl_ctx) {}
30 ~CompilerDeclContext() {}
32 //----------------------------------------------------------------------
34 //----------------------------------------------------------------------
36 explicit operator bool() const { return IsValid(); }
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;
44 bool IsValid() const {
45 return m_type_system != nullptr && m_opaque_decl_ctx != nullptr;
50 std::vector<CompilerDecl> FindDeclByName(ConstString name,
51 const bool ignore_using_decls);
53 //----------------------------------------------------------------------
54 /// Checks if this decl context represents a method of a class.
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.
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).
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.
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);
79 //----------------------------------------------------------------------
81 //----------------------------------------------------------------------
83 TypeSystem *GetTypeSystem() const { return m_type_system; }
85 void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; }
87 void SetDeclContext(TypeSystem *type_system, void *decl_ctx) {
88 m_type_system = type_system;
89 m_opaque_decl_ctx = decl_ctx;
93 m_type_system = nullptr;
94 m_opaque_decl_ctx = nullptr;
97 ConstString GetName() const;
99 ConstString GetScopeQualifiedName() const;
101 bool IsStructUnionOrClass() const;
104 TypeSystem *m_type_system;
105 void *m_opaque_decl_ctx;
108 bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
109 bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
111 } // namespace lldb_private
113 #endif // #ifndef liblldb_CompilerDeclContext_h_