blob: df3b20550f9a07b2274a3681e9b0cfe75e7145cd [file] [log] [blame]
Sean Callananc631b642014-12-05 01:26:42 +00001//===-- ClangModulesDeclVendor.h --------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Pavel Labath083645b2015-08-18 09:18:19 +000010#ifndef liblldb_ClangModulesDeclVendor_h
11#define liblldb_ClangModulesDeclVendor_h
Sean Callananc631b642014-12-05 01:26:42 +000012
13#include "lldb/Core/ArchSpec.h"
14#include "lldb/Core/ClangForward.h"
15#include "lldb/Symbol/DeclVendor.h"
16#include "lldb/Target/Platform.h"
17
Sean Callananf0c5aeb2015-04-20 16:31:29 +000018#include <set>
Sean Callananc631b642014-12-05 01:26:42 +000019#include <vector>
20
21namespace lldb_private
22{
23
24class ClangModulesDeclVendor : public DeclVendor
25{
26public:
27 //------------------------------------------------------------------
28 // Constructors and Destructors
29 //------------------------------------------------------------------
30 ClangModulesDeclVendor();
31
Pavel Labath083645b2015-08-18 09:18:19 +000032 ~ClangModulesDeclVendor() override;
Sean Callananc631b642014-12-05 01:26:42 +000033
34 static ClangModulesDeclVendor *
35 Create(Target &target);
36
Sean Callananf0c5aeb2015-04-20 16:31:29 +000037 typedef std::vector<ConstString> ModulePath;
38 typedef uintptr_t ModuleID;
39 typedef std::vector<ModuleID> ModuleVector;
40
Sean Callananc631b642014-12-05 01:26:42 +000041 //------------------------------------------------------------------
42 /// Add a module to the list of modules to search.
43 ///
44 /// @param[in] path
45 /// The path to the exact module to be loaded. E.g., if the desired
46 /// module is std.io, then this should be { "std", "io" }.
47 ///
Sean Callananf0c5aeb2015-04-20 16:31:29 +000048 /// @param[in] exported_modules
49 /// If non-NULL, a pointer to a vector to populate with the ID of every
50 /// module that is re-exported by the specified module.
51 ///
Sean Callananc631b642014-12-05 01:26:42 +000052 /// @param[in] error_stream
53 /// A stream to populate with the output of the Clang parser when
54 /// it tries to load the module.
55 ///
56 /// @return
57 /// True if the module could be loaded; false if not. If the
58 /// compiler encountered a fatal error during a previous module
59 /// load, then this will always return false for this ModuleImporter.
60 //------------------------------------------------------------------
61 virtual bool
Sean Callananf0c5aeb2015-04-20 16:31:29 +000062 AddModule(ModulePath &path,
63 ModuleVector *exported_modules,
64 Stream &error_stream) = 0;
Sean Callananb8bf6ef2015-04-14 18:36:17 +000065
Sean Callanan26760a82015-04-14 18:50:05 +000066 //------------------------------------------------------------------
Sean Callananf0c5aeb2015-04-20 16:31:29 +000067 /// Add all modules referred to in a given compilation unit to the list
68 /// of modules to search.
69 ///
70 /// @param[in] cu
71 /// The compilation unit to scan for imported modules.
72 ///
73 /// @param[in] exported_modules
74 /// A vector to populate with the ID of each module loaded (directly
75 /// and via re-exports) in this way.
76 ///
77 /// @param[in] error_stream
78 /// A stream to populate with the output of the Clang parser when
79 /// it tries to load the modules.
80 ///
81 /// @return
82 /// True if all modules referred to by the compilation unit could be
83 /// loaded; false if one could not be loaded. If the compiler
84 /// encountered a fatal error during a previous module
85 /// load, then this will always return false for this ModuleImporter.
86 //------------------------------------------------------------------
87 virtual bool
88 AddModulesForCompileUnit(CompileUnit &cu,
89 ModuleVector &exported_modules,
90 Stream &error_stream) = 0;
91
92 //------------------------------------------------------------------
93 /// Enumerate all the macros that are defined by a given set of modules
94 /// that are already imported.
95 ///
96 /// @param[in] modules
97 /// The unique IDs for all modules to query. Later modules have higher
98 /// priority, just as if you @imported them in that order. This matters
99 /// if module A #defines a macro and module B #undefs it.
Sean Callanan26760a82015-04-14 18:50:05 +0000100 ///
101 /// @param[in] handler
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000102 /// A function to call with the text of each #define (including the
103 /// #define directive). #undef directives are not included; we simply
104 /// elide any corresponding #define. If this function returns true,
105 /// we stop the iteration immediately.
Sean Callanan26760a82015-04-14 18:50:05 +0000106 //------------------------------------------------------------------
Sean Callananb8bf6ef2015-04-14 18:36:17 +0000107 virtual void
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000108 ForEachMacro(const ModuleVector &modules,
109 std::function<bool (const std::string &)> handler) = 0;
110
111 //------------------------------------------------------------------
112 /// Query whether Clang supports modules for a particular language.
113 /// LLDB uses this to decide whether to try to find the modules loaded
114 /// by a gaiven compile unit.
115 ///
116 /// @param[in] language
117 /// The language to query for.
118 ///
119 /// @return
120 /// True if Clang has modules for the given language.
121 //------------------------------------------------------------------
122 static bool
123 LanguageSupportsClangModules (lldb::LanguageType language);
Sean Callananc631b642014-12-05 01:26:42 +0000124};
125
Pavel Labath083645b2015-08-18 09:18:19 +0000126} // namespace lldb_private
127
128#endif // liblldb_ClangModulesDeclVendor_h