xref: /NextBSD/contrib/llvm/tools/lldb/include/lldb/Expression/ClangModulesDeclVendor.h (revision 84d351007654069f9643c8e4b4802a7f5f08ee42)
1 //===-- 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 
10 #ifndef _liblldb_ClangModulesDeclVendor_
11 #define _liblldb_ClangModulesDeclVendor_
12 
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 
18 #include <set>
19 #include <vector>
20 
21 namespace lldb_private
22 {
23 
24 class ClangModulesDeclVendor : public DeclVendor
25 {
26 public:
27     //------------------------------------------------------------------
28     // Constructors and Destructors
29     //------------------------------------------------------------------
30     ClangModulesDeclVendor();
31 
32     virtual
33     ~ClangModulesDeclVendor();
34 
35     static ClangModulesDeclVendor *
36     Create(Target &target);
37 
38     typedef std::vector<ConstString> ModulePath;
39     typedef uintptr_t                ModuleID;
40     typedef std::vector<ModuleID>    ModuleVector;
41 
42     //------------------------------------------------------------------
43     /// Add a module to the list of modules to search.
44     ///
45     /// @param[in] path
46     ///     The path to the exact module to be loaded.  E.g., if the desired
47     ///     module is std.io, then this should be { "std", "io" }.
48     ///
49     /// @param[in] exported_modules
50     ///     If non-NULL, a pointer to a vector to populate with the ID of every
51     ///     module that is re-exported by the specified module.
52     ///
53     /// @param[in] error_stream
54     ///     A stream to populate with the output of the Clang parser when
55     ///     it tries to load the module.
56     ///
57     /// @return
58     ///     True if the module could be loaded; false if not.  If the
59     ///     compiler encountered a fatal error during a previous module
60     ///     load, then this will always return false for this ModuleImporter.
61     //------------------------------------------------------------------
62     virtual bool
63     AddModule(ModulePath &path,
64               ModuleVector *exported_modules,
65               Stream &error_stream) = 0;
66 
67     //------------------------------------------------------------------
68     /// Add all modules referred to in a given compilation unit to the list
69     /// of modules to search.
70     ///
71     /// @param[in] cu
72     ///     The compilation unit to scan for imported modules.
73     ///
74     /// @param[in] exported_modules
75     ///     A vector to populate with the ID of each module loaded (directly
76     ///     and via re-exports) in this way.
77     ///
78     /// @param[in] error_stream
79     ///     A stream to populate with the output of the Clang parser when
80     ///     it tries to load the modules.
81     ///
82     /// @return
83     ///     True if all modules referred to by the compilation unit could be
84     ///     loaded; false if one could not be loaded.  If the compiler
85     ///     encountered a fatal error during a previous module
86     ///     load, then this will always return false for this ModuleImporter.
87     //------------------------------------------------------------------
88     virtual bool
89     AddModulesForCompileUnit(CompileUnit &cu,
90                              ModuleVector &exported_modules,
91                              Stream &error_stream) = 0;
92 
93     //------------------------------------------------------------------
94     /// Enumerate all the macros that are defined by a given set of modules
95     /// that are already imported.
96     ///
97     /// @param[in] modules
98     ///     The unique IDs for all modules to query.  Later modules have higher
99     ///     priority, just as if you @imported them in that order.  This matters
100     ///     if module A #defines a macro and module B #undefs it.
101     ///
102     /// @param[in] handler
103     ///     A function to call with the text of each #define (including the
104     ///     #define directive).  #undef directives are not included; we simply
105     ///     elide any corresponding #define.  If this function returns true,
106     ///     we stop the iteration immediately.
107     //------------------------------------------------------------------
108     virtual void
109     ForEachMacro(const ModuleVector &modules,
110                  std::function<bool (const std::string &)> handler) = 0;
111 
112     //------------------------------------------------------------------
113     /// Query whether Clang supports modules for a particular language.
114     /// LLDB uses this to decide whether to try to find the modules loaded
115     /// by a gaiven compile unit.
116     ///
117     /// @param[in] language
118     ///     The language to query for.
119     ///
120     /// @return
121     ///     True if Clang has modules for the given language.
122     //------------------------------------------------------------------
123     static bool
124     LanguageSupportsClangModules (lldb::LanguageType language);
125 
126 };
127 
128 }
129 #endif /* defined(_lldb_ClangModulesDeclVendor_) */
130