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   // Accessors
80   //----------------------------------------------------------------------
81 
82   TypeSystem *GetTypeSystem() const { return m_type_system; }
83 
84   void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; }
85 
86   void SetDeclContext(TypeSystem *type_system, void *decl_ctx) {
87     m_type_system = type_system;
88     m_opaque_decl_ctx = decl_ctx;
89   }
90 
91   void Clear() {
92     m_type_system = nullptr;
93     m_opaque_decl_ctx = nullptr;
94   }
95 
96   ConstString GetName() const;
97 
98   ConstString GetScopeQualifiedName() const;
99 
100   bool IsStructUnionOrClass() const;
101 
102 private:
103   TypeSystem *m_type_system;
104   void *m_opaque_decl_ctx;
105 };
106 
107 bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
108 bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
109 
110 } // namespace lldb_private
111 
112 #endif // #ifndef liblldb_CompilerDeclContext_h_
113