/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Symbol/CompilerDeclContext.h
Line | Count | Source (jump to first uncovered line) |
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 LLDB_SYMBOL_COMPILERDECLCONTEXT_H |
10 | | #define LLDB_SYMBOL_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 | | /// Represents a generic declaration context in a program. A declaration context |
20 | | /// is data structure that contains declarations (e.g. namespaces). |
21 | | /// |
22 | | /// This class serves as an abstraction for a declaration context inside one of |
23 | | /// the TypeSystems implemented by the language plugins. It does not have any |
24 | | /// actual logic in it but only stores an opaque pointer and a pointer to the |
25 | | /// TypeSystem that gives meaning to this opaque pointer. All methods of this |
26 | | /// class should call their respective method in the TypeSystem interface and |
27 | | /// pass the opaque pointer along. |
28 | | /// |
29 | | /// \see lldb_private::TypeSystem |
30 | | class CompilerDeclContext { |
31 | | public: |
32 | | /// Constructs an invalid CompilerDeclContext. |
33 | 5.29M | CompilerDeclContext() = default; |
34 | | |
35 | | /// Constructs a CompilerDeclContext with the given opaque decl context |
36 | | /// and its respective TypeSystem instance. |
37 | | /// |
38 | | /// This constructor should only be called from the respective TypeSystem |
39 | | /// implementation. |
40 | | /// |
41 | | /// \see lldb_private::TypeSystemClang::CreateDeclContext(clang::DeclContext*) |
42 | | CompilerDeclContext(TypeSystem *type_system, void *decl_ctx) |
43 | 145k | : m_type_system(type_system), m_opaque_decl_ctx(decl_ctx) {} |
44 | | |
45 | | // Tests |
46 | | |
47 | 1.02M | explicit operator bool() const { return IsValid(); } |
48 | | |
49 | 0 | bool operator<(const CompilerDeclContext &rhs) const { |
50 | 0 | if (m_type_system == rhs.m_type_system) |
51 | 0 | return m_opaque_decl_ctx < rhs.m_opaque_decl_ctx; |
52 | 0 | return m_type_system < rhs.m_type_system; |
53 | 0 | } |
54 | | |
55 | 1.42M | bool IsValid() const { |
56 | 1.42M | return m_type_system != nullptr && m_opaque_decl_ctx != nullptr240k ; |
57 | 1.42M | } |
58 | | |
59 | | std::vector<CompilerDecl> FindDeclByName(ConstString name, |
60 | | const bool ignore_using_decls); |
61 | | |
62 | | /// Checks if this decl context represents a method of a class. |
63 | | /// |
64 | | /// \return |
65 | | /// Returns true if this is a decl context that represents a method |
66 | | /// in a struct, union or class. |
67 | | bool IsClassMethod(); |
68 | | |
69 | | /// Determines the original language of the decl context. |
70 | | lldb::LanguageType GetLanguage(); |
71 | | |
72 | | /// Check if the given other decl context is contained in the lookup |
73 | | /// of this decl context (for example because the other context is a nested |
74 | | /// inline namespace). |
75 | | /// |
76 | | /// @param[in] other |
77 | | /// The other decl context for which we should check if it is contained |
78 | | /// in the lookoup of this context. |
79 | | /// |
80 | | /// @return |
81 | | /// Returns true iff the other decl context is contained in the lookup |
82 | | /// of this decl context. |
83 | | bool IsContainedInLookup(CompilerDeclContext other) const; |
84 | | |
85 | | // Accessors |
86 | | |
87 | 81.0k | TypeSystem *GetTypeSystem() const { return m_type_system; } |
88 | | |
89 | 58.7k | void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; } |
90 | | |
91 | 0 | void SetDeclContext(TypeSystem *type_system, void *decl_ctx) { |
92 | 0 | m_type_system = type_system; |
93 | 0 | m_opaque_decl_ctx = decl_ctx; |
94 | 0 | } |
95 | | |
96 | 0 | void Clear() { |
97 | 0 | m_type_system = nullptr; |
98 | 0 | m_opaque_decl_ctx = nullptr; |
99 | 0 | } |
100 | | |
101 | | ConstString GetName() const; |
102 | | |
103 | | ConstString GetScopeQualifiedName() const; |
104 | | |
105 | | private: |
106 | | TypeSystem *m_type_system = nullptr; |
107 | | void *m_opaque_decl_ctx = nullptr; |
108 | | }; |
109 | | |
110 | | bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs); |
111 | | bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs); |
112 | | |
113 | | } // namespace lldb_private |
114 | | |
115 | | #endif // LLDB_SYMBOL_COMPILERDECLCONTEXT_H |