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