LLDB  mainline
NameSearchContext.h
Go to the documentation of this file.
1 //===-- NameSearchContext.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_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H
11 
15 #include "llvm/ADT/SmallSet.h"
16 
17 namespace lldb_private {
18 
19 /// \class NameSearchContext ClangASTSource.h
20 /// "lldb/Expression/ClangASTSource.h" Container for all objects relevant to a
21 /// single name lookup
22 ///
23 /// LLDB needs to create Decls for entities it finds. This class communicates
24 /// what name is being searched for and provides helper functions to construct
25 /// Decls given appropriate type information.
27  /// The type system of the AST from which the lookup originated.
29  /// The list of declarations already constructed.
31  /// The mapping of all namespaces found for this request back to their
32  /// modules.
34  /// The name being looked for.
35  const clang::DeclarationName m_decl_name;
36  /// The DeclContext to put declarations into.
37  const clang::DeclContext *m_decl_context;
38  /// All the types of functions that have been reported, so we don't
39  /// report conflicts.
40  llvm::SmallSet<CompilerType, 5> m_function_types;
41 
42  bool m_found_variable = false;
44  bool m_found_function = false;
45  bool m_found_local_vars_nsp = false;
46  bool m_found_type = false;
47 
48  /// Constructor
49  ///
50  /// Initializes class variables.
51  ///
52  /// \param[in] clang_ts
53  /// The TypeSystemClang from which the request originates.
54  ///
55  /// \param[in] decls
56  /// A reference to a list into which new Decls will be placed. This
57  /// list is typically empty when the function is called.
58  ///
59  /// \param[in] name
60  /// The name being searched for (always an Identifier).
61  ///
62  /// \param[in] dc
63  /// The DeclContext to register Decls in.
66  clang::DeclarationName name, const clang::DeclContext *dc)
67  : m_clang_ts(clang_ts), m_decls(decls),
68  m_namespace_map(std::make_shared<ClangASTImporter::NamespaceMap>()),
69  m_decl_name(name), m_decl_context(dc) {
70  ;
71  }
72 
73  /// Create a VarDecl with the name being searched for and the provided type
74  /// and register it in the right places.
75  ///
76  /// \param[in] type
77  /// The opaque QualType for the VarDecl being registered.
78  clang::NamedDecl *AddVarDecl(const CompilerType &type);
79 
80  /// Create a FunDecl with the name being searched for and the provided type
81  /// and register it in the right places.
82  ///
83  /// \param[in] type
84  /// The opaque QualType for the FunDecl being registered.
85  ///
86  /// \param[in] extern_c
87  /// If true, build an extern "C" linkage specification for this.
88  clang::NamedDecl *AddFunDecl(const CompilerType &type, bool extern_c = false);
89 
90  /// Create a FunDecl with the name being searched for and generic type (i.e.
91  /// intptr_t NAME_GOES_HERE(...)) and register it in the right places.
92  clang::NamedDecl *AddGenericFunDecl();
93 
94  /// Create a TypeDecl with the name being searched for and the provided type
95  /// and register it in the right places.
96  ///
97  /// \param[in] compiler_type
98  /// The opaque QualType for the TypeDecl being registered.
99  clang::NamedDecl *AddTypeDecl(const CompilerType &compiler_type);
100 
101  /// Add Decls from the provided DeclContextLookupResult to the list of
102  /// results.
103  ///
104  /// \param[in] result
105  /// The DeclContextLookupResult, usually returned as the result
106  /// of querying a DeclContext.
107  void AddLookupResult(clang::DeclContextLookupResult result);
108 
109  /// Add a NamedDecl to the list of results.
110  ///
111  /// \param[in] decl
112  /// The NamedDecl, usually returned as the result
113  /// of querying a DeclContext.
114  void AddNamedDecl(clang::NamedDecl *decl);
115 
116 private:
117  clang::ASTContext &GetASTContext() const {
118  return m_clang_ts.getASTContext();
119  }
120 };
121 
122 } // namespace lldb_private
123 
124 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H
clang::ASTContext & GetASTContext() const
A class that represents a running process on the host machine.
A TypeSystem implementation based on Clang.
"lldb/Expression/ClangASTSource.h" Container for all objects relevant to a single name lookup ...
clang::ASTContext & getASTContext()
Returns the clang::ASTContext instance managed by this TypeSystemClang.
void AddLookupResult(clang::DeclContextLookupResult result)
Add Decls from the provided DeclContextLookupResult to the list of results.
llvm::SmallSet< CompilerType, 5 > m_function_types
All the types of functions that have been reported, so we don&#39;t report conflicts. ...
NameSearchContext(TypeSystemClang &clang_ts, llvm::SmallVectorImpl< clang::NamedDecl *> &decls, clang::DeclarationName name, const clang::DeclContext *dc)
Constructor.
llvm::SmallVectorImpl< clang::NamedDecl * > & m_decls
The list of declarations already constructed.
std::shared_ptr< NamespaceMap > NamespaceMapSP
clang::NamedDecl * AddGenericFunDecl()
Create a FunDecl with the name being searched for and generic type (i.e.
TypeSystemClang & m_clang_ts
The type system of the AST from which the lookup originated.
clang::NamedDecl * AddTypeDecl(const CompilerType &compiler_type)
Create a TypeDecl with the name being searched for and the provided type and register it in the right...
clang::NamedDecl * AddFunDecl(const CompilerType &type, bool extern_c=false)
Create a FunDecl with the name being searched for and the provided type and register it in the right ...
clang::NamedDecl * AddVarDecl(const CompilerType &type)
Create a VarDecl with the name being searched for and the provided type and register it in the right ...
Represents a generic type in a programming language.
Definition: CompilerType.h:33
ClangASTImporter::NamespaceMapSP m_namespace_map
The mapping of all namespaces found for this request back to their modules.
const clang::DeclContext * m_decl_context
The DeclContext to put declarations into.
void AddNamedDecl(clang::NamedDecl *decl)
Add a NamedDecl to the list of results.
const clang::DeclarationName m_decl_name
The name being looked for.