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
15#include "lldb/lldb-private.h"
16
17namespace 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
31public:
32 /// Constructs an invalid CompilerDeclContext.
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 : m_type_system(type_system), m_opaque_decl_ctx(decl_ctx) {}
44
45 // Tests
46
47 explicit operator bool() const { return IsValid(); }
48
49 bool operator<(const CompilerDeclContext &rhs) const {
52 return m_type_system < rhs.m_type_system;
53 }
54
55 bool IsValid() const {
56 return m_type_system != nullptr && m_opaque_decl_ctx != nullptr;
57 }
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.
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.
84
85 // Accessors
86
88
89 void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; }
90
91 void SetDeclContext(TypeSystem *type_system, void *decl_ctx) {
92 m_type_system = type_system;
93 m_opaque_decl_ctx = decl_ctx;
94 }
95
96 void Clear() {
97 m_type_system = nullptr;
98 m_opaque_decl_ctx = nullptr;
99 }
100
101 ConstString GetName() const;
102
104
105private:
107 void *m_opaque_decl_ctx = nullptr;
108};
109
110bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
111bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
112
113} // namespace lldb_private
114
115#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.
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:77
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1022
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1016
LanguageType
Programming language type.