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 12 #include "Plugins/ExpressionParser/Clang/ClangASTImporter.h" 13 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" 14 #include "lldb/Symbol/CompilerType.h" 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. 26 struct NameSearchContext { 27 /// The type system of the AST from which the lookup originated. 28 TypeSystemClang &m_clang_ts; 29 /// The list of declarations already constructed. 30 llvm::SmallVectorImpl<clang::NamedDecl *> &m_decls; 31 /// The mapping of all namespaces found for this request back to their 32 /// modules. 33 ClangASTImporter::NamespaceMapSP m_namespace_map; 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; 43 bool m_found_function_with_type_info = false; 44 bool m_found_local_vars_nsp = false; 45 bool m_found_type = false; 46 47 /// Constructor 48 /// 49 /// Initializes class variables. 50 /// 51 /// \param[in] clang_ts 52 /// The TypeSystemClang from which the request originates. 53 /// 54 /// \param[in] decls 55 /// A reference to a list into which new Decls will be placed. This 56 /// list is typically empty when the function is called. 57 /// 58 /// \param[in] name 59 /// The name being searched for (always an Identifier). 60 /// 61 /// \param[in] dc 62 /// The DeclContext to register Decls in. NameSearchContextNameSearchContext63 NameSearchContext(TypeSystemClang &clang_ts, 64 llvm::SmallVectorImpl<clang::NamedDecl *> &decls, 65 clang::DeclarationName name, const clang::DeclContext *dc) 66 : m_clang_ts(clang_ts), m_decls(decls), 67 m_namespace_map(std::make_shared<ClangASTImporter::NamespaceMap>()), 68 m_decl_name(name), m_decl_context(dc) { 69 ; 70 } 71 72 /// Create a VarDecl with the name being searched for and the provided type 73 /// and register it in the right places. 74 /// 75 /// \param[in] type 76 /// The opaque QualType for the VarDecl being registered. 77 clang::NamedDecl *AddVarDecl(const CompilerType &type); 78 79 /// Create a FunDecl with the name being searched for and the provided type 80 /// and register it in the right places. 81 /// 82 /// \param[in] type 83 /// The opaque QualType for the FunDecl being registered. 84 /// 85 /// \param[in] extern_c 86 /// If true, build an extern "C" linkage specification for this. 87 clang::NamedDecl *AddFunDecl(const CompilerType &type, bool extern_c = false); 88 89 /// Create a FunDecl with the name being searched for and generic type (i.e. 90 /// intptr_t NAME_GOES_HERE(...)) and register it in the right places. 91 clang::NamedDecl *AddGenericFunDecl(); 92 93 /// Create a TypeDecl with the name being searched for and the provided type 94 /// and register it in the right places. 95 /// 96 /// \param[in] compiler_type 97 /// The opaque QualType for the TypeDecl being registered. 98 clang::NamedDecl *AddTypeDecl(const CompilerType &compiler_type); 99 100 /// Add Decls from the provided DeclContextLookupResult to the list of 101 /// results. 102 /// 103 /// \param[in] result 104 /// The DeclContextLookupResult, usually returned as the result 105 /// of querying a DeclContext. 106 void AddLookupResult(clang::DeclContextLookupResult result); 107 108 /// Add a NamedDecl to the list of results. 109 /// 110 /// \param[in] decl 111 /// The NamedDecl, usually returned as the result 112 /// of querying a DeclContext. 113 void AddNamedDecl(clang::NamedDecl *decl); 114 115 private: GetASTContextNameSearchContext116 clang::ASTContext &GetASTContext() const { 117 return m_clang_ts.getASTContext(); 118 } 119 }; 120 121 } // namespace lldb_private 122 123 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H 124