LLDB mainline
CompilerDeclContext.h
Go to the documentation of this file.
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/Symbol/Type.h"
16#include "lldb/lldb-private.h"
17
18namespace lldb_private {
19
20/// Represents a generic declaration context in a program. A declaration context
21/// is data structure that contains declarations (e.g. namespaces).
22///
23/// This class serves as an abstraction for a declaration context inside one of
24/// the TypeSystems implemented by the language plugins. It does not have any
25/// actual logic in it but only stores an opaque pointer and a pointer to the
26/// TypeSystem that gives meaning to this opaque pointer. All methods of this
27/// class should call their respective method in the TypeSystem interface and
28/// pass the opaque pointer along.
29///
30/// \see lldb_private::TypeSystem
32public:
33 /// Constructs an invalid CompilerDeclContext.
35
36 /// Constructs a CompilerDeclContext with the given opaque decl context
37 /// and its respective TypeSystem instance.
38 ///
39 /// This constructor should only be called from the respective TypeSystem
40 /// implementation.
41 ///
42 /// \see lldb_private::TypeSystemClang::CreateDeclContext(clang::DeclContext*)
43 CompilerDeclContext(TypeSystem *type_system, void *decl_ctx)
44 : m_type_system(type_system), m_opaque_decl_ctx(decl_ctx) {}
45
46 // Tests
47
48 explicit operator bool() const { return IsValid(); }
49
50 bool operator<(const CompilerDeclContext &rhs) const {
53 return m_type_system < rhs.m_type_system;
54 }
55
56 bool IsValid() const {
57 return m_type_system != nullptr && m_opaque_decl_ctx != nullptr;
58 }
59
60 /// Populate a valid compiler context from the current decl context.
61 ///
62 /// \returns A valid vector of CompilerContext entries that describes
63 /// this declaration context. The first entry in the vector is the parent of
64 /// the subsequent entry, so the topmost entry is the global namespace.
65 std::vector<lldb_private::CompilerContext> GetCompilerContext() const;
66
67 std::vector<CompilerDecl> FindDeclByName(ConstString name,
68 const bool ignore_using_decls);
69
70 /// Checks if this decl context represents a method of a class.
71 ///
72 /// \return
73 /// Returns true if this is a decl context that represents a method
74 /// in a struct, union or class.
75 bool IsClassMethod();
76
77 /// Determines the original language of the decl context.
79
80 /// Check if the given other decl context is contained in the lookup
81 /// of this decl context (for example because the other context is a nested
82 /// inline namespace).
83 ///
84 /// @param[in] other
85 /// The other decl context for which we should check if it is contained
86 /// in the lookoup of this context.
87 ///
88 /// @return
89 /// Returns true iff the other decl context is contained in the lookup
90 /// of this decl context.
92
93 // Accessors
94
96
97 void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; }
98
99 void SetDeclContext(TypeSystem *type_system, void *decl_ctx) {
100 m_type_system = type_system;
101 m_opaque_decl_ctx = decl_ctx;
102 }
103
104 void Clear() {
105 m_type_system = nullptr;
106 m_opaque_decl_ctx = nullptr;
107 }
108
109 ConstString GetName() const;
110
112
113private:
115 void *m_opaque_decl_ctx = nullptr;
116};
117
118bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
119bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
120
121} // namespace lldb_private
122
123#endif // LLDB_SYMBOL_COMPILERDECLCONTEXT_H
Represents a generic declaration context in a program.
std::vector< CompilerDecl > FindDeclByName(ConstString name, const bool ignore_using_decls)
bool IsClassMethod()
Checks if this decl context represents a method of a class.
bool IsContainedInLookup(CompilerDeclContext other) const
Check if the given other decl context is contained in the lookup of this decl context (for example be...
CompilerDeclContext(TypeSystem *type_system, void *decl_ctx)
Constructs a CompilerDeclContext with the given opaque decl context and its respective TypeSystem ins...
CompilerDeclContext()=default
Constructs an invalid CompilerDeclContext.
lldb::LanguageType GetLanguage()
Determines the original language of the decl context.
std::vector< lldb_private::CompilerContext > GetCompilerContext() const
Populate a valid compiler context from the current decl context.
void SetDeclContext(TypeSystem *type_system, void *decl_ctx)
bool operator<(const CompilerDeclContext &rhs) const
A uniqued constant string class.
Definition: ConstString.h:40
Interface for representing a type system.
Definition: TypeSystem.h:70
A class that represents a running process on the host machine.
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1029
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1023
LanguageType
Programming language type.