1 //===-- ClangModulesDeclVendor.h --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ClangModulesDeclVendor_h
11 #define liblldb_ClangModulesDeclVendor_h
13 #include "lldb/Core/ArchSpec.h"
14 #include "lldb/Core/ClangForward.h"
15 #include "lldb/Symbol/DeclVendor.h"
16 #include "lldb/Target/Platform.h"
21 namespace lldb_private {
23 class ClangModulesDeclVendor : public DeclVendor {
25 //------------------------------------------------------------------
26 // Constructors and Destructors
27 //------------------------------------------------------------------
28 ClangModulesDeclVendor();
30 ~ClangModulesDeclVendor() override;
32 static ClangModulesDeclVendor *Create(Target &target);
34 typedef std::vector<ConstString> ModulePath;
35 typedef uintptr_t ModuleID;
36 typedef std::vector<ModuleID> ModuleVector;
38 //------------------------------------------------------------------
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 //------------------------------------------------------------------
58 virtual bool AddModule(ModulePath &path, ModuleVector *exported_modules,
59 Stream &error_stream) = 0;
61 //------------------------------------------------------------------
62 /// Add all modules referred to in a given compilation unit to the list
63 /// of modules to search.
66 /// The compilation unit to scan for imported modules.
68 /// @param[in] exported_modules
69 /// A vector to populate with the ID of each module loaded (directly
70 /// and via re-exports) in this way.
72 /// @param[in] error_stream
73 /// A stream to populate with the output of the Clang parser when
74 /// it tries to load the modules.
77 /// True if all modules referred to by the compilation unit could be
78 /// loaded; false if one could not be loaded. If the compiler
79 /// encountered a fatal error during a previous module
80 /// load, then this will always return false for this ModuleImporter.
81 //------------------------------------------------------------------
82 virtual bool AddModulesForCompileUnit(CompileUnit &cu,
83 ModuleVector &exported_modules,
84 Stream &error_stream) = 0;
86 //------------------------------------------------------------------
87 /// Enumerate all the macros that are defined by a given set of modules
88 /// that are already imported.
90 /// @param[in] modules
91 /// The unique IDs for all modules to query. Later modules have higher
92 /// priority, just as if you @imported them in that order. This matters
93 /// if module A #defines a macro and module B #undefs it.
95 /// @param[in] handler
96 /// A function to call with the text of each #define (including the
97 /// #define directive). #undef directives are not included; we simply
98 /// elide any corresponding #define. If this function returns true,
99 /// we stop the iteration immediately.
100 //------------------------------------------------------------------
102 ForEachMacro(const ModuleVector &modules,
103 std::function<bool(const std::string &)> handler) = 0;
105 //------------------------------------------------------------------
106 /// Query whether Clang supports modules for a particular language.
107 /// LLDB uses this to decide whether to try to find the modules loaded
108 /// by a gaiven compile unit.
110 /// @param[in] language
111 /// The language to query for.
114 /// True if Clang has modules for the given language.
115 //------------------------------------------------------------------
116 static bool LanguageSupportsClangModules(lldb::LanguageType language);
119 } // namespace lldb_private
121 #endif // liblldb_ClangModulesDeclVendor_h