diff options
Diffstat (limited to 'clang/include/clang/Frontend')
-rw-r--r-- | clang/include/clang/Frontend/CommandLineSourceLoc.h | 7 | ||||
-rw-r--r-- | clang/include/clang/Frontend/CompilerInstance.h | 25 | ||||
-rw-r--r-- | clang/include/clang/Frontend/CompilerInvocation.h | 148 | ||||
-rw-r--r-- | clang/include/clang/Frontend/DependencyOutputOptions.h | 20 | ||||
-rw-r--r-- | clang/include/clang/Frontend/FrontendAction.h | 5 | ||||
-rw-r--r-- | clang/include/clang/Frontend/FrontendActions.h | 11 | ||||
-rw-r--r-- | clang/include/clang/Frontend/FrontendOptions.h | 9 | ||||
-rw-r--r-- | clang/include/clang/Frontend/PreprocessorOutputOptions.h | 2 | ||||
-rw-r--r-- | clang/include/clang/Frontend/TextDiagnostic.h | 3 |
9 files changed, 144 insertions, 86 deletions
diff --git a/clang/include/clang/Frontend/CommandLineSourceLoc.h b/clang/include/clang/Frontend/CommandLineSourceLoc.h index 0827433462e1..dfc4454b4baf 100644 --- a/clang/include/clang/Frontend/CommandLineSourceLoc.h +++ b/clang/include/clang/Frontend/CommandLineSourceLoc.h @@ -48,6 +48,13 @@ public: return PSL; } + + /// Serialize ParsedSourceLocation back to a string. + std::string ToString() const { + return (llvm::Twine(FileName == "<stdin>" ? "-" : FileName) + ":" + + Twine(Line) + ":" + Twine(Column)) + .str(); + } }; /// A source range that has been parsed on the command line. diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 57632f8770f0..861b15020329 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -22,6 +22,7 @@ #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/BuryPointer.h" +#include "llvm/Support/FileSystem.h" #include <cassert> #include <list> #include <memory> @@ -150,7 +151,7 @@ class CompilerInstance : public ModuleLoader { bool HaveFullGlobalModuleIndex = false; /// One or more modules failed to build. - bool ModuleBuildFailed = false; + bool DisableGeneratingGlobalModuleIndex = false; /// The stream for verbose output if owned, otherwise nullptr. std::unique_ptr<raw_ostream> OwnedVerboseOutputStream; @@ -165,11 +166,10 @@ class CompilerInstance : public ModuleLoader { /// failed. struct OutputFile { std::string Filename; - std::string TempFilename; + Optional<llvm::sys::fs::TempFile> File; - OutputFile(std::string filename, std::string tempFilename) - : Filename(std::move(filename)), TempFilename(std::move(tempFilename)) { - } + OutputFile(std::string filename, Optional<llvm::sys::fs::TempFile> file) + : Filename(std::move(filename)), File(std::move(file)) {} }; /// The list of active output files. @@ -382,6 +382,9 @@ public: /// Replace the current AuxTarget. void setAuxTarget(TargetInfo *Value); + // Create Target and AuxTarget based on current options + bool createTarget(); + /// } /// @name Virtual File System /// { @@ -693,15 +696,13 @@ public: /// The files created by this are usually removed on signal, and, depending /// on FrontendOptions, may also use a temporary file (that is, the data is /// written to a temporary file which will atomically replace the target - /// output on success). If a client (like libclang) needs to disable - /// RemoveFileOnSignal, temporary files will be forced on. + /// output on success). /// /// \return - Null on error. - std::unique_ptr<raw_pwrite_stream> - createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "", - StringRef Extension = "", - bool RemoveFileOnSignal = true, - bool CreateMissingDirectories = false); + std::unique_ptr<raw_pwrite_stream> createDefaultOutputFile( + bool Binary = true, StringRef BaseInput = "", StringRef Extension = "", + bool RemoveFileOnSignal = true, bool CreateMissingDirectories = false, + bool ForceUseTemporary = false); /// Create a new output file, optionally deriving the output path name, and /// add it to the list of tracked output files. diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 0d83a228c301..2245439d0632 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -61,7 +61,15 @@ bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, DiagnosticsEngine *Diags = nullptr, bool DefaultDiagColor = true); -class CompilerInvocationBase { +/// The base class of CompilerInvocation with reference semantics. +/// +/// This class stores option objects behind reference-counted pointers. This is +/// useful for clients that want to keep some option object around even after +/// CompilerInvocation gets destroyed, without making a copy. +/// +/// This is a separate class so that we can implement the copy constructor and +/// assignment here and leave them defaulted in the rest of CompilerInvocation. +class CompilerInvocationRefBase { public: /// Options controlling the language variant. std::shared_ptr<LangOptions> LangOpts; @@ -78,10 +86,15 @@ public: /// Options controlling the preprocessor (aside from \#include handling). std::shared_ptr<PreprocessorOptions> PreprocessorOpts; - CompilerInvocationBase(); - CompilerInvocationBase(const CompilerInvocationBase &X); - CompilerInvocationBase &operator=(const CompilerInvocationBase &) = delete; - ~CompilerInvocationBase(); + /// Options controlling the static analyzer. + AnalyzerOptionsRef AnalyzerOpts; + + CompilerInvocationRefBase(); + CompilerInvocationRefBase(const CompilerInvocationRefBase &X); + CompilerInvocationRefBase(CompilerInvocationRefBase &&X); + CompilerInvocationRefBase &operator=(CompilerInvocationRefBase X); + CompilerInvocationRefBase &operator=(CompilerInvocationRefBase &&X); + ~CompilerInvocationRefBase(); LangOptions *getLangOpts() { return LangOpts.get(); } const LangOptions *getLangOpts() const { return LangOpts.get(); } @@ -110,17 +123,13 @@ public: const PreprocessorOptions &getPreprocessorOpts() const { return *PreprocessorOpts; } -}; -/// Helper class for holding the data necessary to invoke the compiler. -/// -/// This class is designed to represent an abstract "invocation" of the -/// compiler, including data such as the include paths, the code generation -/// options, the warning flags, and so on. -class CompilerInvocation : public CompilerInvocationBase { - /// Options controlling the static analyzer. - AnalyzerOptionsRef AnalyzerOpts; + AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; } +}; +/// The base class of CompilerInvocation with value semantics. +class CompilerInvocationValueBase { +protected: MigratorOptions MigratorOpts; /// Options controlling IRgen and the backend. @@ -139,11 +148,46 @@ class CompilerInvocation : public CompilerInvocationBase { PreprocessorOutputOptions PreprocessorOutputOpts; public: - CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {} + MigratorOptions &getMigratorOpts() { return MigratorOpts; } + const MigratorOptions &getMigratorOpts() const { return MigratorOpts; } - /// @name Utility Methods - /// @{ + CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; } + const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } + + DependencyOutputOptions &getDependencyOutputOpts() { + return DependencyOutputOpts; + } + + const DependencyOutputOptions &getDependencyOutputOpts() const { + return DependencyOutputOpts; + } + + FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; } + + const FileSystemOptions &getFileSystemOpts() const { + return FileSystemOpts; + } + + FrontendOptions &getFrontendOpts() { return FrontendOpts; } + const FrontendOptions &getFrontendOpts() const { return FrontendOpts; } + + PreprocessorOutputOptions &getPreprocessorOutputOpts() { + return PreprocessorOutputOpts; + } + + const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { + return PreprocessorOutputOpts; + } +}; +/// Helper class for holding the data necessary to invoke the compiler. +/// +/// This class is designed to represent an abstract "invocation" of the +/// compiler, including data such as the include paths, the code generation +/// options, the warning flags, and so on. +class CompilerInvocation : public CompilerInvocationRefBase, + public CompilerInvocationValueBase { +public: /// Create a compiler invocation from a list of input options. /// \returns true on success. /// @@ -199,67 +243,41 @@ public: void generateCC1CommandLine(llvm::SmallVectorImpl<const char *> &Args, StringAllocator SA) const; - /// @} - /// @name Option Subgroups - /// @{ - - AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; } - - MigratorOptions &getMigratorOpts() { return MigratorOpts; } - const MigratorOptions &getMigratorOpts() const { return MigratorOpts; } - - CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; } - const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } - - DependencyOutputOptions &getDependencyOutputOpts() { - return DependencyOutputOpts; - } - - const DependencyOutputOptions &getDependencyOutputOpts() const { - return DependencyOutputOpts; - } - - FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; } - - const FileSystemOptions &getFileSystemOpts() const { - return FileSystemOpts; - } - - FrontendOptions &getFrontendOpts() { return FrontendOpts; } - const FrontendOptions &getFrontendOpts() const { return FrontendOpts; } - - PreprocessorOutputOptions &getPreprocessorOutputOpts() { - return PreprocessorOutputOpts; - } - - const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { - return PreprocessorOutputOpts; - } - - /// @} - private: - /// Parse options for flags that expose marshalling information in their - /// table-gen definition - /// - /// \param Args - The argument list containing the arguments to parse - /// \param Diags - The DiagnosticsEngine associated with CreateFromArgs - /// \returns - True if parsing was successful, false otherwise - bool parseSimpleArgs(const llvm::opt::ArgList &Args, - DiagnosticsEngine &Diags); + static bool CreateFromArgsImpl(CompilerInvocation &Res, + ArrayRef<const char *> CommandLineArgs, + DiagnosticsEngine &Diags, const char *Argv0); + + /// Generate command line options from DiagnosticOptions. + static void GenerateDiagnosticArgs(const DiagnosticOptions &Opts, + SmallVectorImpl<const char *> &Args, + StringAllocator SA, bool DefaultDiagColor); /// Parse command line options that map to LangOptions. - static void ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args, + static bool ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args, InputKind IK, const llvm::Triple &T, std::vector<std::string> &Includes, DiagnosticsEngine &Diags); + /// Generate command line options from LangOptions. + static void GenerateLangArgs(const LangOptions &Opts, + SmallVectorImpl<const char *> &Args, + StringAllocator SA, const llvm::Triple &T, + InputKind IK); + /// Parse command line options that map to CodeGenOptions. static bool ParseCodeGenArgs(CodeGenOptions &Opts, llvm::opt::ArgList &Args, InputKind IK, DiagnosticsEngine &Diags, const llvm::Triple &T, const std::string &OutputFile, const LangOptions &LangOptsRef); + + // Generate command line options from CodeGenOptions. + static void GenerateCodeGenArgs(const CodeGenOptions &Opts, + SmallVectorImpl<const char *> &Args, + StringAllocator SA, const llvm::Triple &T, + const std::string &OutputFile, + const LangOptions *LangOpts); }; IntrusiveRefCntPtr<llvm::vfs::FileSystem> diff --git a/clang/include/clang/Frontend/DependencyOutputOptions.h b/clang/include/clang/Frontend/DependencyOutputOptions.h index 7a4f3337936f..78a2841d1e10 100644 --- a/clang/include/clang/Frontend/DependencyOutputOptions.h +++ b/clang/include/clang/Frontend/DependencyOutputOptions.h @@ -20,6 +20,14 @@ enum class ShowIncludesDestination { None, Stdout, Stderr }; /// DependencyOutputFormat - Format for the compiler dependency file. enum class DependencyOutputFormat { Make, NMake }; +/// ExtraDepKind - The kind of extra dependency file. +enum ExtraDepKind { + EDK_SanitizeIgnorelist, + EDK_ProfileList, + EDK_ModuleFile, + EDK_DepFileEntry, +}; + /// DependencyOutputOptions - Options for controlling the compiler dependency /// file generation. class DependencyOutputOptions { @@ -31,6 +39,10 @@ public: /// problems. unsigned AddMissingHeaderDeps : 1; ///< Add missing headers to dependency list unsigned IncludeModuleFiles : 1; ///< Include module file dependencies. + unsigned ShowSkippedHeaderIncludes : 1; ///< With ShowHeaderIncludes, show + /// also includes that were skipped + /// due to the "include guard + /// optimization" or #pragma once. /// Destination of cl.exe style /showIncludes info. ShowIncludesDestination ShowIncludesDest = ShowIncludesDestination::None; @@ -51,8 +63,9 @@ public: /// must contain at least one entry. std::vector<std::string> Targets; - /// A list of filenames to be used as extra dependencies for every target. - std::vector<std::string> ExtraDeps; + /// A list of extra dependencies (filename and kind) to be used for every + /// target. + std::vector<std::pair<std::string, ExtraDepKind>> ExtraDeps; /// In /showIncludes mode, pretend the main TU is a header with this name. std::string ShowIncludesPretendHeader; @@ -66,7 +79,8 @@ public: public: DependencyOutputOptions() : IncludeSystemHeaders(0), ShowHeaderIncludes(0), UsePhonyTargets(0), - AddMissingHeaderDeps(0), IncludeModuleFiles(0) {} + AddMissingHeaderDeps(0), IncludeModuleFiles(0), + ShowSkippedHeaderIncludes(0) {} }; } // end namespace clang diff --git a/clang/include/clang/Frontend/FrontendAction.h b/clang/include/clang/Frontend/FrontendAction.h index 319b3bc62cc4..dfefddfb4527 100644 --- a/clang/include/clang/Frontend/FrontendAction.h +++ b/clang/include/clang/Frontend/FrontendAction.h @@ -234,7 +234,7 @@ public: /// Perform any per-file post processing, deallocate per-file /// objects, and run statistics and output file cleanup code. - void EndSourceFile(); + virtual void EndSourceFile(); /// @} }; @@ -302,15 +302,16 @@ public: /// some existing action's behavior. It implements every virtual method in /// the FrontendAction interface by forwarding to the wrapped action. class WrapperFrontendAction : public FrontendAction { +protected: std::unique_ptr<FrontendAction> WrappedAction; -protected: bool PrepareToExecuteAction(CompilerInstance &CI) override; std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override; bool BeginInvocation(CompilerInstance &CI) override; bool BeginSourceFileAction(CompilerInstance &CI) override; void ExecuteAction() override; + void EndSourceFile() override; void EndSourceFileAction() override; bool shouldEraseOutputFiles() override; diff --git a/clang/include/clang/Frontend/FrontendActions.h b/clang/include/clang/Frontend/FrontendActions.h index 25ca95980806..ff8d4417eaa4 100644 --- a/clang/include/clang/Frontend/FrontendActions.h +++ b/clang/include/clang/Frontend/FrontendActions.h @@ -34,6 +34,17 @@ public: bool usesPreprocessorOnly() const override { return false; } }; +/// Preprocessor-based frontend action that also loads PCH files. +class ReadPCHAndPreprocessAction : public FrontendAction { + void ExecuteAction() override; + + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; + +public: + bool usesPreprocessorOnly() const override { return false; } +}; + class DumpCompilerOptionsAction : public FrontendAction { std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override { diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index 223c1e05d053..15c905d712a3 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -15,10 +15,11 @@ #include "clang/Sema/CodeCompleteOptions.h" #include "clang/Serialization/ModuleFileExtension.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/MemoryBuffer.h" #include <cassert> +#include <map> #include <memory> #include <string> -#include <unordered_map> #include <vector> namespace llvm { @@ -374,6 +375,10 @@ public: std::string MTMigrateDir; std::string ARCMTMigrateReportOut; + /// The input kind, either specified via -x argument or deduced from the input + /// file name. + InputKind DashX; + /// The input files and their types. SmallVector<FrontendInputFile, 0> Inputs; @@ -400,7 +405,7 @@ public: std::string ActionName; /// Args to pass to the plugins - std::unordered_map<std::string,std::vector<std::string>> PluginArgs; + std::map<std::string, std::vector<std::string>> PluginArgs; /// The list of plugin actions to run in addition to the normal action. std::vector<std::string> AddPluginActions; diff --git a/clang/include/clang/Frontend/PreprocessorOutputOptions.h b/clang/include/clang/Frontend/PreprocessorOutputOptions.h index 72e5ad1137fb..257538ee0606 100644 --- a/clang/include/clang/Frontend/PreprocessorOutputOptions.h +++ b/clang/include/clang/Frontend/PreprocessorOutputOptions.h @@ -24,6 +24,7 @@ public: unsigned ShowIncludeDirectives : 1; ///< Print includes, imports etc. within preprocessed output. unsigned RewriteIncludes : 1; ///< Preprocess include directives only. unsigned RewriteImports : 1; ///< Include contents of transitively-imported modules. + unsigned MinimizeWhitespace : 1; ///< Ignore whitespace from input. public: PreprocessorOutputOptions() { @@ -36,6 +37,7 @@ public: ShowIncludeDirectives = 0; RewriteIncludes = 0; RewriteImports = 0; + MinimizeWhitespace = 0; } }; diff --git a/clang/include/clang/Frontend/TextDiagnostic.h b/clang/include/clang/Frontend/TextDiagnostic.h index 7cf54839afbe..a2eec46beccd 100644 --- a/clang/include/clang/Frontend/TextDiagnostic.h +++ b/clang/include/clang/Frontend/TextDiagnostic.h @@ -50,8 +50,7 @@ public: /// TextDiagnostic logic requires. static void printDiagnosticLevel(raw_ostream &OS, DiagnosticsEngine::Level Level, - bool ShowColors, - bool CLFallbackMode = false); + bool ShowColors); /// Pretty-print a diagnostic message to a raw_ostream. /// |