clang: include/clang/Frontend/Utils.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_CLANG_FRONTEND_UTILS_H
14#define LLVM_CLANG_FRONTEND_UTILS_H
15
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/IntrusiveRefCntPtr.h"
22#include "llvm/ADT/StringMap.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/ADT/StringSet.h"
25#include "llvm/Support/FileCollector.h"
26#include "llvm/Support/VirtualFileSystem.h"
27#include
28#include
29#include
30#include <system_error>
31#include
32#include
33
35
36class ASTReader;
37class CompilerInstance;
38class CompilerInvocation;
39class DiagnosticsEngine;
40class ExternalSemaSource;
41class FrontendOptions;
42class PCHContainerReader;
43class Preprocessor;
44class PreprocessorOptions;
45class PreprocessorOutputOptions;
46class CodeGenOptions;
47
48
49
51 const PCHContainerReader &PCHContainerRdr,
52 const FrontendOptions &FEOpts,
53 const CodeGenOptions &CodeGenOpts);
54
55
57 const PreprocessorOutputOptions &Opts);
58
59
60
61
62
64public:
66
70
71
72
73
74
76 bool IsSystem, bool IsModuleFile, bool IsMissing);
77
78
80
81
83
84
85
87 bool IsSystem, bool IsModuleFile,
88 bool IsMissing);
89
90protected:
91
92
94
95private:
96 llvm::StringSet<> Seen;
97 std::vectorstd::string Dependencies;
98};
99
100
101
102
103
105public:
107
109
111
113
115 bool IsModuleFile, bool IsMissing) final;
116
117protected:
119
120private:
122
123 std::string OutputFile;
124 std::vectorstd::string Targets;
125 bool IncludeSystemHeaders;
126 bool PhonyTarget;
127 bool AddMissingHeaderDeps;
128 bool SeenMissingHeader;
129 bool IncludeModuleFiles;
131 unsigned InputFileIndex;
132};
133
134
135
137 std::string DestDir;
138 bool HasErrors = false;
139 llvm::StringSet<> Seen;
140 llvm::vfs::YAMLVFSWriter VFSWriter;
141 llvm::FileCollector::PathCanonicalizer Canonicalizer;
142
143 std::error_code copyToRoot(StringRef Src, StringRef Dst = {});
144
145public:
147 : DestDir(std::move(DestDir)) {}
149
150 StringRef getDest() { return DestDir; }
152 virtual void addFile(StringRef Filename, StringRef FileDst = {});
153
155 VFSWriter.addFileMapping(VPath, RPath);
156 }
157
160
162 virtual bool hasErrors() { return HasErrors; }
163};
164
165
166
168 StringRef SysRoot);
169
170
171
172
173
174
175
176
177
178
179
180
181
183 const DependencyOutputOptions &DepOpts,
184 bool ShowAllHeaders = false,
185 StringRef OutputPath = {},
186 bool ShowDepth = true, bool MSStyle = false);
187
188
189
190IntrusiveRefCntPtr
192 IntrusiveRefCntPtr &Reader);
193
194
196
197
199
200
201
203
204
205
207
208
209
210
212
213
214 std::vectorstd::string *CC1Args = nullptr;
215};
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235std::unique_ptr
238
239}
240
241#endif
Defines the Diagnostic-related interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Reads an AST files chain containing the contents of a translation unit.
An interface for collecting the dependencies of a compilation.
virtual void maybeAddDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing)
Add a dependency Filename if it has not been seen before and sawDependency() returns true.
bool addDependency(StringRef Filename)
Return true if the filename was added to the list of dependencies, false otherwise.
virtual void attachToPreprocessor(Preprocessor &PP)
ArrayRef< std::string > getDependencies() const
virtual void finishedMainFile(DiagnosticsEngine &Diags)
Called when the end of the main file is reached.
virtual void attachToASTReader(ASTReader &R)
virtual ~DependencyCollector()
virtual bool needSystemDependencies()
Return true if system files should be passed to sawDependency().
virtual bool sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing)
Called when a new file is seen.
Builds a dependency file when attached to a Preprocessor (for includes) and ASTReader (for module imp...
void outputDependencyFile(llvm::raw_ostream &OS)
void attachToPreprocessor(Preprocessor &PP) override
void finishedMainFile(DiagnosticsEngine &Diags) override
Called when the end of the main file is reached.
bool needSystemDependencies() final
Return true if system files should be passed to sawDependency().
bool sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing) final
Called when a new file is seen.
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Concrete class used by the front-end to report problems and issues.
Collects the dependencies for imported modules into a directory.
void attachToASTReader(ASTReader &R) override
~ModuleDependencyCollector() override
virtual void addFileMapping(StringRef VPath, StringRef RPath)
void attachToPreprocessor(Preprocessor &PP) override
virtual void addFile(StringRef Filename, StringRef FileDst={})
virtual bool insertSeen(StringRef Filename)
virtual void writeFileMap()
ModuleDependencyCollector(std::string DestDir)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
The JSON file list parser is used to communicate input to InstallAPI.
void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, const FrontendOptions &FEOpts, const CodeGenOptions &CodeGenOpts)
InitializePreprocessor - Initialize the preprocessor getting it and the environment ready to process ...
IntrusiveRefCntPtr< ExternalSemaSource > createChainedIncludesSource(CompilerInstance &CI, IntrusiveRefCntPtr< ExternalSemaSource > &Reader)
The ChainedIncludesSource class converts headers to chained PCHs in memory, mainly for testing.
std::unique_ptr< CompilerInvocation > createInvocation(ArrayRef< const char * > Args, CreateInvocationOptions Opts={})
Interpret clang arguments in preparation to parse a file.
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts)
DoPrintPreprocessedInput - Implement -E mode.
DependencyOutputFormat
DependencyOutputFormat - Format for the compiler dependency file.
void AttachHeaderIncludeGen(Preprocessor &PP, const DependencyOutputOptions &DepOpts, bool ShowAllHeaders=false, StringRef OutputPath={}, bool ShowDepth=true, bool MSStyle=false)
AttachHeaderIncludeGen - Create a header include list generator, and attach it to the given preproces...
void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, StringRef SysRoot)
AttachDependencyGraphGen - Create a dependency graph generator, and attach it to the given preprocess...
Optional inputs to createInvocation.
IntrusiveRefCntPtr< DiagnosticsEngine > Diags
Receives diagnostics encountered while parsing command-line flags.
bool ProbePrecompiled
Allow the driver to probe the filesystem for PCH files.
bool RecoverOnError
Whether to attempt to produce a non-null (possibly incorrect) invocation if any errors were encounter...
IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS
Used e.g.
std::vector< std::string > * CC1Args
If set, the target is populated with the cc1 args produced by the driver.