| 1 | //===-- ClangModulesDeclVendor.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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H |
| 10 | #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H |
| 11 | |
| 12 | #include "lldb/Symbol/SourceModule.h" |
| 13 | #include "lldb/Target/Platform.h" |
| 14 | |
| 15 | #include "Plugins/ExpressionParser/Clang/ClangDeclVendor.h" |
| 16 | |
| 17 | #include <set> |
| 18 | #include <vector> |
| 19 | |
| 20 | namespace lldb_private { |
| 21 | |
| 22 | class ClangModulesDeclVendor : public ClangDeclVendor { |
| 23 | public: |
| 24 | // Constructors and Destructors |
| 25 | ClangModulesDeclVendor(); |
| 26 | |
| 27 | ~ClangModulesDeclVendor() override; |
| 28 | |
| 29 | static bool classof(const DeclVendor *vendor) { |
| 30 | return vendor->GetKind() == eClangModuleDeclVendor; |
| 31 | } |
| 32 | |
| 33 | static ClangModulesDeclVendor *Create(Target &target); |
| 34 | |
| 35 | typedef std::vector<ConstString> ModulePath; |
| 36 | typedef uintptr_t ModuleID; |
| 37 | typedef std::vector<ModuleID> ModuleVector; |
| 38 | |
| 39 | /// Add a module to the list of modules to search. |
| 40 | /// |
| 41 | /// \param[in] module |
| 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" }. |
| 44 | /// |
| 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. |
| 48 | /// |
| 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. |
| 52 | /// |
| 53 | /// \return |
| 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; |
| 60 | |
| 61 | /// Add all modules referred to in a given compilation unit to the list |
| 62 | /// of modules to search. |
| 63 | /// |
| 64 | /// \param[in] cu |
| 65 | /// The compilation unit to scan for imported modules. |
| 66 | /// |
| 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. |
| 70 | /// |
| 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. |
| 74 | /// |
| 75 | /// \return |
| 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; |
| 83 | |
| 84 | /// Enumerate all the macros that are defined by a given set of modules |
| 85 | /// that are already imported. |
| 86 | /// |
| 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. |
| 91 | /// |
| 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; |
| 100 | |
| 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. |
| 104 | /// |
| 105 | /// \param[in] language |
| 106 | /// The language to query for. |
| 107 | /// |
| 108 | /// \return |
| 109 | /// True if Clang has modules for the given language. |
| 110 | static bool LanguageSupportsClangModules(lldb::LanguageType language); |
| 111 | }; |
| 112 | |
| 113 | } // namespace lldb_private |
| 114 | |
| 115 | #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H |
| 116 | |