diff options
Diffstat (limited to 'include/clang/Frontend/Utils.h')
-rw-r--r-- | include/clang/Frontend/Utils.h | 108 |
1 files changed, 96 insertions, 12 deletions
diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index dff56c3a8a4e..4c0a7b7a9c66 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -15,8 +15,10 @@ #define LLVM_CLANG_FRONTEND_UTILS_H #include "clang/Basic/Diagnostic.h" +#include "clang/Basic/VirtualFileSystem.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Option/OptSpecifier.h" namespace llvm { @@ -30,12 +32,14 @@ class ArgList; namespace clang { class ASTConsumer; +class ASTReader; class CompilerInstance; class CompilerInvocation; class Decl; class DependencyOutputOptions; class DiagnosticsEngine; class DiagnosticOptions; +class ExternalSemaSource; class FileManager; class HeaderSearch; class HeaderSearchOptions; @@ -59,23 +63,81 @@ void ApplyHeaderSearchOptions(HeaderSearch &HS, /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, - const HeaderSearchOptions &HSOpts, const FrontendOptions &FEOpts); -/// ProcessWarningOptions - Initialize the diagnostic client and process the -/// warning options specified on the command line. -void ProcessWarningOptions(DiagnosticsEngine &Diags, - const DiagnosticOptions &Opts, - bool ReportDiags = true); - /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream* OS, const PreprocessorOutputOptions &Opts); -/// AttachDependencyFileGen - Create a dependency file generator, and attach -/// it to the given preprocessor. This takes ownership of the output stream. -void AttachDependencyFileGen(Preprocessor &PP, - const DependencyOutputOptions &Opts); +/// An interface for collecting the dependencies of a compilation. Users should +/// use \c attachToPreprocessor and \c attachToASTReader to get all of the +/// dependencies. +// FIXME: Migrate DependencyFileGen, DependencyGraphGen, ModuleDepCollectory to +// use this interface. +class DependencyCollector { +public: + void attachToPreprocessor(Preprocessor &PP); + void attachToASTReader(ASTReader &R); + llvm::ArrayRef<std::string> getDependencies() const { return Dependencies; } + + /// Called when a new file is seen. Return true if \p Filename should be added + /// to the list of dependencies. + /// + /// The default implementation ignores <built-in> and system files. + virtual bool sawDependency(StringRef Filename, bool FromModule, + bool IsSystem, bool IsModuleFile, bool IsMissing); + /// Called when the end of the main file is reached. + virtual void finishedMainFile() { } + /// Return true if system files should be passed to sawDependency(). + virtual bool needSystemDependencies() { return false; } + virtual ~DependencyCollector(); + +public: // implementation detail + /// Add a dependency \p Filename if it has not been seen before and + /// sawDependency() returns true. + void maybeAddDependency(StringRef Filename, bool FromModule, bool IsSystem, + bool IsModuleFile, bool IsMissing); +private: + llvm::StringSet<> Seen; + std::vector<std::string> Dependencies; +}; + +/// Builds a depdenency file when attached to a Preprocessor (for includes) and +/// ASTReader (for module imports), and writes it out at the end of processing +/// a source file. Users should attach to the ast reader whenever a module is +/// loaded. +class DependencyFileGenerator { + void *Impl; // Opaque implementation + DependencyFileGenerator(void *Impl); +public: + static DependencyFileGenerator *CreateAndAttachToPreprocessor( + Preprocessor &PP, const DependencyOutputOptions &Opts); + void AttachToASTReader(ASTReader &R); +}; + +/// Collects the dependencies for imported modules into a directory. Users +/// should attach to the AST reader whenever a module is loaded. +class ModuleDependencyCollector { + std::string DestDir; + bool HasErrors; + llvm::StringSet<> Seen; + vfs::YAMLVFSWriter VFSWriter; + +public: + StringRef getDest() { return DestDir; } + bool insertSeen(StringRef Filename) { return Seen.insert(Filename); } + void setHasErrors() { HasErrors = true; } + void addFileMapping(StringRef VPath, StringRef RPath) { + VFSWriter.addFileMapping(VPath, RPath); + } + + void attachToASTReader(ASTReader &R); + void writeFileMap(); + bool hasErrors() { return HasErrors; } + ModuleDependencyCollector(std::string DestDir) + : DestDir(DestDir), HasErrors(false) {} + ~ModuleDependencyCollector() { writeFileMap(); } +}; /// AttachDependencyGraphGen - Create a dependency graph generator, and attach /// it to the given preprocessor. @@ -101,6 +163,12 @@ void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false, /// a seekable stream. void CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS); +/// The ChainedIncludesSource class converts headers to chained PCHs in +/// memory, mainly for testing. +IntrusiveRefCntPtr<ExternalSemaSource> +createChainedIncludesSource(CompilerInstance &CI, + IntrusiveRefCntPtr<ExternalSemaSource> &Reader); + /// createInvocationFromCommandLine - Construct a compiler invocation object for /// a command line argument vector. /// @@ -115,7 +183,7 @@ createInvocationFromCommandLine(ArrayRef<const char *> Args, /// is non-null, emits an error if the argument is given, but non-integral. int getLastArgIntValue(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, int Default, - DiagnosticsEngine *Diags = 0); + DiagnosticsEngine *Diags = nullptr); inline int getLastArgIntValue(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, int Default, @@ -123,6 +191,22 @@ inline int getLastArgIntValue(const llvm::opt::ArgList &Args, return getLastArgIntValue(Args, Id, Default, &Diags); } +uint64_t getLastArgUInt64Value(const llvm::opt::ArgList &Args, + llvm::opt::OptSpecifier Id, uint64_t Default, + DiagnosticsEngine *Diags = nullptr); + +inline uint64_t getLastArgUInt64Value(const llvm::opt::ArgList &Args, + llvm::opt::OptSpecifier Id, + uint64_t Default, + DiagnosticsEngine &Diags) { + return getLastArgUInt64Value(Args, Id, Default, &Diags); +} + +// When Clang->getFrontendOpts().DisableFree is set we don't delete some of the +// global objects, but we don't want LeakDetectors to complain, so we bury them +// in a globally visible array. +void BuryPointer(const void *Ptr); + } // end namespace clang #endif |