14 #ifndef LLVM_CLANG_FRONTEND_UTILS_H
15 #define LLVM_CLANG_FRONTEND_UTILS_H
19 #include "llvm/ADT/IntrusiveRefCntPtr.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/StringSet.h"
22 #include "llvm/Option/OptSpecifier.h"
37 class CompilerInstance;
38 class CompilerInvocation;
40 class DependencyOutputOptions;
41 class DiagnosticsEngine;
42 class DiagnosticOptions;
43 class ExternalSemaSource;
46 class HeaderSearchOptions;
47 class IdentifierTable;
49 class PCHContainerReader;
51 class PreprocessorOptions;
52 class PreprocessorOutputOptions;
56 class FrontendOptions;
60 const HeaderSearchOptions &HSOpts,
61 const LangOptions &Lang,
62 const llvm::Triple &triple);
67 const PCHContainerReader &PCHContainerRdr,
68 const FrontendOptions &FEOpts);
72 const PreprocessorOutputOptions &Opts);
90 bool IsSystem,
bool IsModuleFile,
bool IsMissing);
101 bool IsModuleFile,
bool IsMissing);
103 llvm::StringSet<> Seen;
104 std::vector<std::string> Dependencies;
124 bool HasErrors =
false;
125 llvm::StringSet<> Seen;
128 llvm::StringMap<std::string> SymLinkMap;
131 std::error_code copyToRoot(StringRef Src);
146 : DestDir(std::move(DestDir)) {}
168 const DependencyOutputOptions &DepOpts,
169 bool ShowAllHeaders =
false,
170 StringRef OutputPath =
"",
171 bool ShowDepth =
true,
bool MSStyle =
false);
174 void CacheTokens(Preprocessor &PP, raw_pwrite_stream *OS);
178 IntrusiveRefCntPtr<ExternalSemaSource>
180 IntrusiveRefCntPtr<ExternalSemaSource> &Reader);
189 IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
190 IntrusiveRefCntPtr<DiagnosticsEngine>());
195 llvm::opt::OptSpecifier Id,
int Default,
196 DiagnosticsEngine *Diags =
nullptr);
199 llvm::opt::OptSpecifier Id,
int Default,
205 llvm::opt::OptSpecifier Id, uint64_t Default,
206 DiagnosticsEngine *Diags =
nullptr);
209 llvm::opt::OptSpecifier Id,
llvm::ArrayRef< std::string > getDependencies() const
IntrusiveRefCntPtr< ExternalSemaSource > createChainedIncludesSource(CompilerInstance &CI, IntrusiveRefCntPtr< ExternalSemaSource > &Reader)
The ChainedIncludesSource class converts headers to chained PCHs in memory, mainly for testing...
An interface for collecting the dependencies of a compilation.
void attachToASTReader(ASTReader &R) override
void addFile(StringRef Filename)
virtual bool needSystemDependencies()
Return true if system files should be passed to sawDependency().
virtual void attachToASTReader(ASTReader &R)
void addFileMapping(StringRef VirtualPath, StringRef RealPath)
Concrete class used by the front-end to report problems and issues.
void attachToPreprocessor(Preprocessor &PP) override
void CacheTokens(Preprocessor &PP, raw_pwrite_stream *OS)
Cache tokens for use with PCH. Note that this requires a seekable stream.
ModuleDependencyCollector(std::string DestDir)
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...
Builds a depdenency file when attached to a Preprocessor (for includes) and ASTReader (for module imp...
static DependencyFileGenerator * CreateAndAttachToPreprocessor(Preprocessor &PP, const DependencyOutputOptions &Opts)
uint64_t getLastArgUInt64Value(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, uint64_t Default, DiagnosticsEngine *Diags=nullptr)
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts)
DoPrintPreprocessedInput - Implement -E mode.
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...
void addFileMapping(StringRef VPath, StringRef RPath)
virtual void finishedMainFile()
Called when the end of the main file is reached.
Collects the dependencies for imported modules into a directory.
The result type of a method or function.
void ApplyHeaderSearchOptions(HeaderSearch &HS, const HeaderSearchOptions &HSOpts, const LangOptions &Lang, const llvm::Triple &triple)
Apply the header search options to get given HeaderSearch object.
void AttachToASTReader(ASTReader &R)
void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, StringRef SysRoot)
AttachDependencyGraphGen - Create a dependency graph generator, and attach it to the given preprocess...
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Reads an AST files chain containing the contents of a translation unit.
CompilerInvocation * createInvocationFromCommandLine(ArrayRef< const char * > Args, IntrusiveRefCntPtr< DiagnosticsEngine > Diags=IntrusiveRefCntPtr< DiagnosticsEngine >())
createInvocationFromCommandLine - Construct a compiler invocation object for a command line argument ...
Defines the virtual file system interface vfs::FileSystem.
virtual ~DependencyCollector()
Defines the Diagnostic-related interfaces.
~ModuleDependencyCollector()
void BuryPointer(const void *Ptr)
virtual void attachToPreprocessor(Preprocessor &PP)
int getLastArgIntValue(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, int Default, DiagnosticsEngine *Diags=nullptr)
Return the value of the last argument as an integer, or a default.
void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, const FrontendOptions &FEOpts)
InitializePreprocessor - Initialize the preprocessor getting it and the environment ready to process ...
virtual bool sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing)
Called when a new file is seen.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool insertSeen(StringRef Filename)