1 //===-- ClangModulesDeclVendor.h --------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H
12 #include "lldb/Symbol/SourceModule.h"
13 #include "lldb/Target/Platform.h"
15 #include "Plugins/ExpressionParser/Clang/ClangDeclVendor.h"
20 namespace lldb_private
{
22 class ClangModulesDeclVendor
: public ClangDeclVendor
{
24 // Constructors and Destructors
25 ClangModulesDeclVendor();
27 ~ClangModulesDeclVendor() override
;
29 static bool classof(const DeclVendor
*vendor
) {
30 return vendor
->GetKind() == eClangModuleDeclVendor
;
33 static ClangModulesDeclVendor
*Create(Target
&target
);
35 typedef std::vector
<ConstString
> ModulePath
;
36 typedef uintptr_t ModuleID
;
37 typedef std::vector
<ModuleID
> ModuleVector
;
39 /// Add a module to the list of modules to search.
42 /// The path to the exact module to be loaded. E.g., if the desired
43 /// module is std.io, then this should be { "std", "io" }.
45 /// \param[in] exported_modules
46 /// If non-NULL, a pointer to a vector to populate with the ID of every
47 /// module that is re-exported by the specified module.
49 /// \param[in] error_stream
50 /// A stream to populate with the output of the Clang parser when
51 /// it tries to load the module.
54 /// True if the module could be loaded; false if not. If the
55 /// compiler encountered a fatal error during a previous module
56 /// load, then this will always return false for this ModuleImporter.
57 virtual bool AddModule(const SourceModule
&module
,
58 ModuleVector
*exported_modules
,
59 Stream
&error_stream
) = 0;
61 /// Add all modules referred to in a given compilation unit to the list
62 /// of modules to search.
65 /// The compilation unit to scan for imported modules.
67 /// \param[in] exported_modules
68 /// A vector to populate with the ID of each module loaded (directly
69 /// and via re-exports) in this way.
71 /// \param[in] error_stream
72 /// A stream to populate with the output of the Clang parser when
73 /// it tries to load the modules.
76 /// True if all modules referred to by the compilation unit could be
77 /// loaded; false if one could not be loaded. If the compiler
78 /// encountered a fatal error during a previous module
79 /// load, then this will always return false for this ModuleImporter.
80 virtual bool AddModulesForCompileUnit(CompileUnit
&cu
,
81 ModuleVector
&exported_modules
,
82 Stream
&error_stream
) = 0;
84 /// Enumerate all the macros that are defined by a given set of modules
85 /// that are already imported.
87 /// \param[in] modules
88 /// The unique IDs for all modules to query. Later modules have higher
89 /// priority, just as if you @imported them in that order. This matters
90 /// if module A #defines a macro and module B #undefs it.
92 /// \param[in] handler
93 /// A function to call with the identifier of this macro and the text of
94 /// each #define (including the #define directive). #undef directives are
95 /// not included; we simply elide any corresponding #define. If this
96 /// function returns true, we stop the iteration immediately.
97 virtual void ForEachMacro(
98 const ModuleVector
&modules
,
99 std::function
<bool(llvm::StringRef
, llvm::StringRef
)> handler
) = 0;
101 /// Query whether Clang supports modules for a particular language.
102 /// LLDB uses this to decide whether to try to find the modules loaded
103 /// by a given compile unit.
105 /// \param[in] language
106 /// The language to query for.
109 /// True if Clang has modules for the given language.
110 static bool LanguageSupportsClangModules(lldb::LanguageType language
);
113 } // namespace lldb_private
115 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H