105 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H10#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H11 12#include "lldb/Symbol/DeclVendor.h"13#include "lldb/Symbol/SourceModule.h"14#include "lldb/Target/Platform.h"15 16#include <set>17#include <vector>18 19namespace lldb_private {20 21class ClangModulesDeclVendor : public DeclVendor {22public:23 // Constructors and Destructors24 ClangModulesDeclVendor();25 26 ~ClangModulesDeclVendor() override;27 28 static bool classof(const DeclVendor *vendor) {29 return vendor->GetKind() == eClangModuleDeclVendor;30 }31 32 static ClangModulesDeclVendor *Create(Target &target);33 34 typedef std::vector<ConstString> ModulePath;35 typedef uintptr_t ModuleID;36 typedef std::vector<ModuleID> ModuleVector;37 38 /// Add a module to the list of modules to search.39 ///40 /// \param[in] module41 /// The path to the exact module to be loaded. E.g., if the desired42 /// module is std.io, then this should be { "std", "io" }.43 ///44 /// \param[out] exported_modules45 /// If non-NULL, a pointer to a vector to populate with the ID of every46 /// module that is re-exported by the specified module.47 ///48 /// \return49 /// True if the module could be loaded; false if not. If the50 /// compiler encountered a fatal error during a previous module51 /// load, then this will always return false for this ModuleImporter.52 virtual llvm::Error AddModule(const SourceModule &module,53 ModuleVector *exported_modules) = 0;54 55 /// Add all modules referred to in a given compilation unit to the list56 /// of modules to search.57 ///58 /// \param[in] cu59 /// The compilation unit to scan for imported modules.60 ///61 /// \param[out] exported_modules62 /// A vector to populate with the ID of each module loaded (directly63 /// and via re-exports) in this way.64 ///65 /// \return66 /// True if all modules referred to by the compilation unit could be67 /// loaded; false if one could not be loaded. If the compiler68 /// encountered a fatal error during a previous module69 /// load, then this will always return false for this ModuleImporter.70 virtual llvm::Error71 AddModulesForCompileUnit(CompileUnit &cu, ModuleVector &exported_modules) = 0;72 73 /// Enumerate all the macros that are defined by a given set of modules74 /// that are already imported.75 ///76 /// \param[in] modules77 /// The unique IDs for all modules to query. Later modules have higher78 /// priority, just as if you @imported them in that order. This matters79 /// if module A #defines a macro and module B #undefs it.80 ///81 /// \param[in] handler82 /// A function to call with the identifier of this macro and the text of83 /// each #define (including the #define directive). #undef directives are84 /// not included; we simply elide any corresponding #define. If this85 /// function returns true, we stop the iteration immediately.86 virtual void ForEachMacro(87 const ModuleVector &modules,88 std::function<bool(llvm::StringRef, llvm::StringRef)> handler) = 0;89 90 /// Query whether Clang supports modules for a particular language.91 /// LLDB uses this to decide whether to try to find the modules loaded92 /// by a given compile unit.93 ///94 /// \param[in] language95 /// The language to query for.96 ///97 /// \return98 /// True if Clang has modules for the given language.99 static bool LanguageSupportsClangModules(lldb::LanguageType language);100};101 102} // namespace lldb_private103 104#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGMODULESDECLVENDOR_H105