123 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H10#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H11 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 17namespace lldb_private {18 19/// \class NameSearchContext ClangASTSource.h20/// "lldb/Expression/ClangASTSource.h" Container for all objects relevant to a21/// single name lookup22///23/// LLDB needs to create Decls for entities it finds. This class communicates24/// what name is being searched for and provides helper functions to construct25/// Decls given appropriate type information.26struct 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 their32 /// 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't39 /// report conflicts.40 llvm::SmallSet<CompilerType, 5> m_function_types;41 42 bool m_found_variable = false;43 bool m_found_local_vars_nsp = false;44 bool m_found_type = false;45 46 /// Constructor47 ///48 /// Initializes class variables.49 ///50 /// \param[in] clang_ts51 /// The TypeSystemClang from which the request originates.52 ///53 /// \param[in] decls54 /// A reference to a list into which new Decls will be placed. This55 /// list is typically empty when the function is called.56 ///57 /// \param[in] name58 /// The name being searched for (always an Identifier).59 ///60 /// \param[in] dc61 /// The DeclContext to register Decls in.62 NameSearchContext(TypeSystemClang &clang_ts,63 llvm::SmallVectorImpl<clang::NamedDecl *> &decls,64 clang::DeclarationName name, const clang::DeclContext *dc)65 : m_clang_ts(clang_ts), m_decls(decls),66 m_namespace_map(std::make_shared<ClangASTImporter::NamespaceMap>()),67 m_decl_name(name), m_decl_context(dc) {68 ;69 }70 71 /// Create a VarDecl with the name being searched for and the provided type72 /// and register it in the right places.73 ///74 /// \param[in] type75 /// The opaque QualType for the VarDecl being registered.76 clang::NamedDecl *AddVarDecl(const CompilerType &type);77 78 /// Create a FunDecl with the name being searched for and the provided type79 /// and register it in the right places.80 ///81 /// \param[in] type82 /// The opaque QualType for the FunDecl being registered.83 ///84 /// \param[in] extern_c85 /// If true, build an extern "C" linkage specification for this.86 clang::NamedDecl *AddFunDecl(const CompilerType &type, bool extern_c = false);87 88 /// Create a FunDecl with the name being searched for and generic type (i.e.89 /// intptr_t NAME_GOES_HERE(...)) and register it in the right places.90 clang::NamedDecl *AddGenericFunDecl();91 92 /// Create a TypeDecl with the name being searched for and the provided type93 /// and register it in the right places.94 ///95 /// \param[in] compiler_type96 /// The opaque QualType for the TypeDecl being registered.97 clang::NamedDecl *AddTypeDecl(const CompilerType &compiler_type);98 99 /// Add Decls from the provided DeclContextLookupResult to the list of100 /// results.101 ///102 /// \param[in] result103 /// The DeclContextLookupResult, usually returned as the result104 /// of querying a DeclContext.105 void AddLookupResult(clang::DeclContextLookupResult result);106 107 /// Add a NamedDecl to the list of results.108 ///109 /// \param[in] decl110 /// The NamedDecl, usually returned as the result111 /// of querying a DeclContext.112 void AddNamedDecl(clang::NamedDecl *decl);113 114private:115 clang::ASTContext &GetASTContext() const {116 return m_clang_ts.getASTContext();117 }118};119 120} // namespace lldb_private121 122#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H123