LLDB  mainline
ClangModulesDeclVendor.h
Go to the documentation of this file.
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 
13 #include "lldb/Target/Platform.h"
14 
16 
17 #include <set>
18 #include <vector>
19 
20 namespace lldb_private {
21 
23 public:
24  // Constructors and Destructors
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 text of each #define (including the
94  /// #define directive). #undef directives are not included; we simply
95  /// elide any corresponding #define. If this function returns true,
96  /// we stop the iteration immediately.
97  virtual void
98  ForEachMacro(const ModuleVector &modules,
99  std::function<bool(const std::string &)> 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
DeclVendorKind GetKind() const
Definition: DeclVendor.h:33
A class that represents a running process on the host machine.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
static bool classof(const DeclVendor *vendor)
static ClangModulesDeclVendor * Create(Target &target)
virtual bool AddModulesForCompileUnit(CompileUnit &cu, ModuleVector &exported_modules, Stream &error_stream)=0
Add all modules referred to in a given compilation unit to the list of modules to search...
A class that describes a compilation unit.
Definition: CompileUnit.h:37
virtual bool AddModule(const SourceModule &module, ModuleVector *exported_modules, Stream &error_stream)=0
Add a module to the list of modules to search.
LanguageType
Programming language type.
virtual void ForEachMacro(const ModuleVector &modules, std::function< bool(const std::string &)> handler)=0
Enumerate all the macros that are defined by a given set of modules that are already imported...
static bool LanguageSupportsClangModules(lldb::LanguageType language)
Query whether Clang supports modules for a particular language.
Information needed to import a source-language module.
Definition: SourceModule.h:18