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 liblldb_ClangModulesDeclVendor_h 10 #define liblldb_ClangModulesDeclVendor_h 11 12 #include "lldb/Core/ClangForward.h" 13 #include "lldb/Symbol/DeclVendor.h" 14 #include "lldb/Symbol/SourceModule.h" 15 #include "lldb/Target/Platform.h" 16 17 #include <set> 18 #include <vector> 19 20 namespace lldb_private { 21 22 class ClangModulesDeclVendor : public DeclVendor { 23 public: 24 // Constructors and Destructors 25 ClangModulesDeclVendor(); 26 27 ~ClangModulesDeclVendor() override; 28 29 static ClangModulesDeclVendor *Create(Target &target); 30 31 typedef std::vector<ConstString> ModulePath; 32 typedef uintptr_t ModuleID; 33 typedef std::vector<ModuleID> ModuleVector; 34 35 /// Add a module to the list of modules to search. 36 /// 37 /// \param[in] module 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" }. 40 /// 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. 44 /// 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. 48 /// 49 /// \return 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; 56 57 /// Add all modules referred to in a given compilation unit to the list 58 /// of modules to search. 59 /// 60 /// \param[in] cu 61 /// The compilation unit to scan for imported modules. 62 /// 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. 66 /// 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. 70 /// 71 /// \return 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; 79 80 /// Enumerate all the macros that are defined by a given set of modules 81 /// that are already imported. 82 /// 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. 87 /// 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. 93 virtual void 94 ForEachMacro(const ModuleVector &modules, 95 std::function<bool(const std::string &)> handler) = 0; 96 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. 100 /// 101 /// \param[in] language 102 /// The language to query for. 103 /// 104 /// \return 105 /// True if Clang has modules for the given language. 106 static bool LanguageSupportsClangModules(lldb::LanguageType language); 107 }; 108 109 } // namespace lldb_private 110 111 #endif // liblldb_ClangModulesDeclVendor_h 112