Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / ExpressionParser / Clang / NameSearchContext.h
blobdc8621dd6aba522df5018cded8e383974455829c
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 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H
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"
17 namespace lldb_private {
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;
42 bool m_found_variable = false;
43 bool m_found_function_with_type_info = false;
44 bool m_found_function = false;
45 bool m_found_local_vars_nsp = false;
46 bool m_found_type = false;
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.
64 NameSearchContext(TypeSystemClang &clang_ts,
65 llvm::SmallVectorImpl<clang::NamedDecl *> &decls,
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) {
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);
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);
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();
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);
101 /// Add Decls from the provided DeclContextLookupResult to the list of
102 /// results.
104 /// \param[in] result
105 /// The DeclContextLookupResult, usually returned as the result
106 /// of querying a DeclContext.
107 void AddLookupResult(clang::DeclContextLookupResult result);
109 /// Add a NamedDecl to the list of results.
111 /// \param[in] decl
112 /// The NamedDecl, usually returned as the result
113 /// of querying a DeclContext.
114 void AddNamedDecl(clang::NamedDecl *decl);
116 private:
117 clang::ASTContext &GetASTContext() const {
118 return m_clang_ts.getASTContext();
122 } // namespace lldb_private
124 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_NAME_SEARCH_CONTEXT_H