diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 056abd2059c65a3e908193aeae16fad98017437c (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /include/clang/Frontend | |
parent | cc73504950eb7b5dff2dded9bedd67bc36d64641 (diff) | |
download | FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'include/clang/Frontend')
21 files changed, 430 insertions, 1010 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 144b796..5e409bd 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -19,11 +19,13 @@ #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Lex/ModuleLoader.h" #include "clang/Lex/PreprocessingRecord.h" +#include "clang/Lex/HeaderSearchOptions.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" +#include "clang/Basic/TargetOptions.h" #include "clang-c/Index.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/OwningPtr.h" @@ -56,21 +58,27 @@ class Preprocessor; class SourceManager; class TargetInfo; class ASTFrontendAction; +class ASTDeserializationListener; /// \brief Utility class for loading a ASTContext from an AST file. /// class ASTUnit : public ModuleLoader { private: - IntrusiveRefCntPtr<LangOptions> LangOpts; - IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics; - IntrusiveRefCntPtr<FileManager> FileMgr; - IntrusiveRefCntPtr<SourceManager> SourceMgr; - OwningPtr<HeaderSearch> HeaderInfo; - IntrusiveRefCntPtr<TargetInfo> Target; - IntrusiveRefCntPtr<Preprocessor> PP; - IntrusiveRefCntPtr<ASTContext> Ctx; + IntrusiveRefCntPtr<LangOptions> LangOpts; + IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics; + IntrusiveRefCntPtr<FileManager> FileMgr; + IntrusiveRefCntPtr<SourceManager> SourceMgr; + OwningPtr<HeaderSearch> HeaderInfo; + IntrusiveRefCntPtr<TargetInfo> Target; + IntrusiveRefCntPtr<Preprocessor> PP; + IntrusiveRefCntPtr<ASTContext> Ctx; + IntrusiveRefCntPtr<TargetOptions> TargetOpts; + IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts; ASTReader *Reader; + struct ASTWriterData; + OwningPtr<ASTWriterData> WriterData; + FileSystemOptions FileSystemOpts; /// \brief The AST consumer that received information about the translation @@ -85,13 +93,6 @@ private: /// LoadFromCommandLine available. IntrusiveRefCntPtr<CompilerInvocation> Invocation; - /// \brief The set of target features. - /// - /// FIXME: each time we reparse, we need to restore the set of target - /// features from this vector, because TargetInfo::CreateTargetInfo() - /// mangles the target options in place. Yuck! - std::vector<std::string> TargetFeatures; - // OnlyLocalDecls - when true, walking this AST should only visit declarations // that come from the AST itself, not from included precompiled headers. // FIXME: This is temporary; eventually, CIndex will always do this. @@ -374,8 +375,8 @@ private: /// \brief Clear out and deallocate void ClearCachedCompletionResults(); - ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT - ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT + ASTUnit(const ASTUnit &) LLVM_DELETED_FUNCTION; + void operator=(const ASTUnit &) LLVM_DELETED_FUNCTION; explicit ASTUnit(bool MainFileIsAST); @@ -466,7 +467,11 @@ public: const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; } - const std::string &getOriginalSourceFileName(); + StringRef getOriginalSourceFileName() { + return OriginalSourceFile; + } + + ASTDeserializationListener *getDeserializationListener(); /// \brief Add a temporary file that the ASTUnit depends on. /// @@ -515,7 +520,7 @@ public: void addFileLevelDecl(Decl *D); /// \brief Get the decls that are contained in a file in the Offset/Length - /// range. \arg Length can be 0 to indicate a point at \arg Offset instead of + /// range. \p Length can be 0 to indicate a point at \p Offset instead of /// a range. void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl<Decl *> &Decls); @@ -542,14 +547,14 @@ public: /// \brief Get the source location for the given file:offset pair. SourceLocation getLocation(const FileEntry *File, unsigned Offset) const; - /// \brief If \arg Loc is a loaded location from the preamble, returns + /// \brief If \p Loc is a loaded location from the preamble, returns /// the corresponding local location of the main file, otherwise it returns - /// \arg Loc. + /// \p Loc. SourceLocation mapLocationFromPreamble(SourceLocation Loc); - /// \brief If \arg Loc is a local location of the main file but inside the + /// \brief If \p Loc is a local location of the main file but inside the /// preamble chunk, returns the corresponding loaded location from the - /// preamble, otherwise it returns \arg Loc. + /// preamble, otherwise it returns \p Loc. SourceLocation mapLocationToPreamble(SourceLocation Loc); bool isInPreambleFileID(SourceLocation Loc); @@ -557,13 +562,13 @@ public: SourceLocation getStartOfMainFileID(); SourceLocation getEndOfPreambleFileID(); - /// \brief \see mapLocationFromPreamble. + /// \see mapLocationFromPreamble. SourceRange mapRangeFromPreamble(SourceRange R) { return SourceRange(mapLocationFromPreamble(R.getBegin()), mapLocationFromPreamble(R.getEnd())); } - /// \brief \see mapLocationToPreamble. + /// \see mapLocationToPreamble. SourceRange mapRangeToPreamble(SourceRange R) { return SourceRange(mapLocationToPreamble(R.getBegin()), mapLocationToPreamble(R.getEnd())); @@ -607,6 +612,29 @@ public: return CachedCompletionResults.size(); } + /// \brief Returns an iterator range for the local preprocessing entities + /// of the local Preprocessor, if this is a parsed source file, or the loaded + /// preprocessing entities of the primary module if this is an AST file. + std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator> + getLocalPreprocessingEntities() const; + + /// \brief Type for a function iterating over a number of declarations. + /// \returns true to continue iteration and false to abort. + typedef bool (*DeclVisitorFn)(void *context, const Decl *D); + + /// \brief Iterate over local declarations (locally parsed if this is a parsed + /// source file or the loaded declarations of the primary module if this is an + /// AST file). + /// \returns true if the iteration was complete or false if it was aborted. + bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn); + + /// \brief Get the PCH file if one was included. + const FileEntry *getPCHFile(); + + /// \brief Returns true if the ASTUnit was constructed from a serialized + /// module file. + bool isModuleFile(); + llvm::MemoryBuffer *getBufferForFile(StringRef Filename, std::string *ErrorStr = 0); @@ -679,7 +707,7 @@ public: /// (e.g. because the PCH could not be loaded), this accepts the ASTUnit /// mainly to allow the caller to see the diagnostics. /// This will only receive an ASTUnit if a new one was created. If an already - /// created ASTUnit was passed in \param Unit then the caller can check that. + /// created ASTUnit was passed in \p Unit then the caller can check that. /// static ASTUnit *LoadFromCompilerInvocationAction(CompilerInvocation *CI, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, @@ -750,6 +778,7 @@ public: bool AllowPCHWithCompilerErrors = false, bool SkipFunctionBodies = false, bool UserFilesAreVolatile = false, + bool ForSerialization = false, OwningPtr<ASTUnit> *ErrAST = 0); /// \brief Reparse the source files using the same command-line options that @@ -792,8 +821,9 @@ public: /// \brief Save this translation unit to a file with the given name. /// - /// \returns An indication of whether the save was successful or not. - CXSaveError Save(StringRef File); + /// \returns true if there was a file error or false if the save was + /// successful. + bool Save(StringRef File); /// \brief Serialize this translation unit with the given output stream. /// diff --git a/include/clang/Frontend/Analyses.def b/include/clang/Frontend/Analyses.def deleted file mode 100644 index 29ddc9e..0000000 --- a/include/clang/Frontend/Analyses.def +++ /dev/null @@ -1,67 +0,0 @@ -//===-- Analyses.def - Metadata about Static Analyses -----------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the set of static analyses used by AnalysisConsumer. -// -//===----------------------------------------------------------------------===// - -#ifndef ANALYSIS_STORE -#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) -#endif - -ANALYSIS_STORE(RegionStore, "region", "Use region-based analyzer store", CreateRegionStoreManager) - -#ifndef ANALYSIS_CONSTRAINTS -#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) -#endif - -ANALYSIS_CONSTRAINTS(BasicConstraints, "basic", "Use basic constraint tracking", CreateBasicConstraintManager) -ANALYSIS_CONSTRAINTS(RangeConstraints, "range", "Use constraint tracking of concrete value ranges", CreateRangeConstraintManager) - -#ifndef ANALYSIS_DIAGNOSTICS -#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE) -#endif - -ANALYSIS_DIAGNOSTICS(HTML, "html", "Output analysis results using HTML", createHTMLDiagnosticConsumer, false) -ANALYSIS_DIAGNOSTICS(PLIST, "plist", "Output analysis results using Plists", createPlistDiagnosticConsumer, true) -ANALYSIS_DIAGNOSTICS(PLIST_MULTI_FILE, "plist-multi-file", "Output analysis results using Plists (allowing for mult-file bugs)", createPlistMultiFileDiagnosticConsumer, true) -ANALYSIS_DIAGNOSTICS(PLIST_HTML, "plist-html", "Output analysis results using HTML wrapped with Plists", createPlistHTMLDiagnosticConsumer, true) -ANALYSIS_DIAGNOSTICS(TEXT, "text", "Text output of analysis results", createTextPathDiagnosticConsumer, true) - -#ifndef ANALYSIS_PURGE -#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) -#endif - -ANALYSIS_PURGE(PurgeStmt, "statement", "Purge symbols, bindings, and constraints before every statement") -ANALYSIS_PURGE(PurgeBlock, "block", "Purge symbols, bindings, and constraints before every basic block") -ANALYSIS_PURGE(PurgeNone, "none", "Do not purge symbols, bindings, or constraints") - -#ifndef ANALYSIS_IPA -#define ANALYSIS_IPA(NAME, CMDFLAG, DESC) -#endif - -ANALYSIS_IPA(None, "none", "Perform only intra-procedural analysis") -ANALYSIS_IPA(Inlining, "inlining", "Inline callees when their definitions are available") -ANALYSIS_IPA(DynamicDispatch, "dynamic", "Experimental: Enable inlining of dynamically dispatched methods") -ANALYSIS_IPA(DynamicDispatchBifurcate, "dynamic-bifurcate", "Experimental: Enable inlining of dynamically dispatched methods, bifurcate paths when exact type info is unavailable") - -#ifndef ANALYSIS_INLINING_MODE -#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) -#endif - -ANALYSIS_INLINING_MODE(All, "all", "Analyze all functions in the order defined in the TU") -ANALYSIS_INLINING_MODE(NoRedundancy, "noredundancy", "Do not analyze a function which has been previously inlined, use call graph to order") - -#undef ANALYSIS_STORE -#undef ANALYSIS_CONSTRAINTS -#undef ANALYSIS_DIAGNOSTICS -#undef ANALYSIS_PURGE -#undef ANALYSIS_INLINING_MODE -#undef ANALYSIS_IPA - diff --git a/include/clang/Frontend/AnalyzerOptions.h b/include/clang/Frontend/AnalyzerOptions.h deleted file mode 100644 index 4e489fe..0000000 --- a/include/clang/Frontend/AnalyzerOptions.h +++ /dev/null @@ -1,135 +0,0 @@ -//===--- AnalyzerOptions.h - Analysis Engine Options ------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This header contains the structures necessary for a front-end to specify -// various analyses. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_FRONTEND_ANALYZEROPTIONS_H -#define LLVM_CLANG_FRONTEND_ANALYZEROPTIONS_H - -#include <string> -#include <vector> - -namespace clang { -class ASTConsumer; -class DiagnosticsEngine; -class Preprocessor; -class LangOptions; - -/// Analysis - Set of available source code analyses. -enum Analyses { -#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE) NAME, -#include "clang/Frontend/Analyses.def" -NumAnalyses -}; - -/// AnalysisStores - Set of available analysis store models. -enum AnalysisStores { -#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) NAME##Model, -#include "clang/Frontend/Analyses.def" -NumStores -}; - -/// AnalysisConstraints - Set of available constraint models. -enum AnalysisConstraints { -#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) NAME##Model, -#include "clang/Frontend/Analyses.def" -NumConstraints -}; - -/// AnalysisDiagClients - Set of available diagnostic clients for rendering -/// analysis results. -enum AnalysisDiagClients { -#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREAT) PD_##NAME, -#include "clang/Frontend/Analyses.def" -NUM_ANALYSIS_DIAG_CLIENTS -}; - -/// AnalysisPurgeModes - Set of available strategies for dead symbol removal. -enum AnalysisPurgeMode { -#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) NAME, -#include "clang/Frontend/Analyses.def" -NumPurgeModes -}; - -/// AnalysisIPAMode - Set of inter-procedural modes. -enum AnalysisIPAMode { -#define ANALYSIS_IPA(NAME, CMDFLAG, DESC) NAME, -#include "clang/Frontend/Analyses.def" -NumIPAModes -}; - -/// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics. -enum AnalysisInliningMode { -#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME, -#include "clang/Frontend/Analyses.def" -NumInliningModes -}; - -class AnalyzerOptions { -public: - /// \brief Pair of checker name and enable/disable. - std::vector<std::pair<std::string, bool> > CheckersControlList; - AnalysisStores AnalysisStoreOpt; - AnalysisConstraints AnalysisConstraintsOpt; - AnalysisDiagClients AnalysisDiagOpt; - AnalysisPurgeMode AnalysisPurgeOpt; - AnalysisIPAMode IPAMode; - std::string AnalyzeSpecificFunction; - unsigned MaxNodes; - unsigned MaxLoop; - unsigned ShowCheckerHelp : 1; - unsigned AnalyzeAll : 1; - unsigned AnalyzerDisplayProgress : 1; - unsigned AnalyzeNestedBlocks : 1; - unsigned EagerlyAssume : 1; - unsigned TrimGraph : 1; - unsigned VisualizeEGDot : 1; - unsigned VisualizeEGUbi : 1; - unsigned UnoptimizedCFG : 1; - unsigned CFGAddImplicitDtors : 1; - unsigned EagerlyTrimEGraph : 1; - unsigned PrintStats : 1; - unsigned NoRetryExhausted : 1; - unsigned InlineMaxStackDepth; - unsigned InlineMaxFunctionSize; - AnalysisInliningMode InliningMode; - -public: - AnalyzerOptions() { - AnalysisStoreOpt = RegionStoreModel; - AnalysisConstraintsOpt = RangeConstraintsModel; - AnalysisDiagOpt = PD_HTML; - AnalysisPurgeOpt = PurgeStmt; - IPAMode = Inlining; - ShowCheckerHelp = 0; - AnalyzeAll = 0; - AnalyzerDisplayProgress = 0; - AnalyzeNestedBlocks = 0; - EagerlyAssume = 0; - TrimGraph = 0; - VisualizeEGDot = 0; - VisualizeEGUbi = 0; - UnoptimizedCFG = 0; - CFGAddImplicitDtors = 0; - EagerlyTrimEGraph = 0; - PrintStats = 0; - NoRetryExhausted = 0; - // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls). - InlineMaxStackDepth = 5; - InlineMaxFunctionSize = 200; - InliningMode = NoRedundancy; - } -}; - -} - -#endif diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def new file mode 100644 index 0000000..558e6f1 --- /dev/null +++ b/include/clang/Frontend/CodeGenOptions.def @@ -0,0 +1,132 @@ +//===--- CodeGenOptions.def - Code generation option database ------ C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the code generation options. Users of this file +// must define the CODEGENOPT macro to make use of this information. +// Optionally, the user may also define ENUM_CODEGENOPT (for options +// that have enumeration type and VALUE_CODEGENOPT is a code +// generation option that describes a value rather than a flag. +// +//===----------------------------------------------------------------------===// +#ifndef CODEGENOPT +# error Define the CODEGENOPT macro to handle language options +#endif + +#ifndef VALUE_CODEGENOPT +# define VALUE_CODEGENOPT(Name, Bits, Default) \ +CODEGENOPT(Name, Bits, Default) +#endif + +#ifndef ENUM_CODEGENOPT +# define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ +CODEGENOPT(Name, Bits, Default) +#endif + +CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm. +CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe. +CODEGENOPT(CUDAIsDevice , 1, 0) ///< Set when compiling for CUDA device. +CODEGENOPT(CXAAtExit , 1, 1) ///< Use __cxa_atexit for calling destructors. +CODEGENOPT(CXXCtorDtorAliases, 1, 0) ///< Emit complete ctors/dtors as linker + ///< aliases to base ctors when possible. +CODEGENOPT(DataSections , 1, 0) ///< Set when -fdata-sections is enabled. +CODEGENOPT(DisableFPElim , 1, 0) ///< Set when -fomit-frame-pointer is enabled. +CODEGENOPT(DisableLLVMOpts , 1, 0) ///< Don't run any optimizations, for use in + ///< getting .bc files that correspond to the + ///< internal state before optimizations are + ///< done. +CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled. +CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls. +CODEGENOPT(EmitDeclMetadata , 1, 0) ///< Emit special metadata indicating what + ///< Decl* various IR entities came from. + ///< Only useful when running CodeGen as a + ///< subroutine. +CODEGENOPT(EmitGcovArcs , 1, 0) ///< Emit coverage data files, aka. GCDA. +CODEGENOPT(EmitGcovNotes , 1, 0) ///< Emit coverage "notes" files, aka GCNO. +CODEGENOPT(EmitOpenCLArgMetadata , 1, 0) ///< Emit OpenCL kernel arg metadata. +CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard variables + ///< are required. +CODEGENOPT(FunctionSections , 1, 0) ///< Set when -ffunction-sections is enabled. +CODEGENOPT(HiddenWeakVTables , 1, 0) ///< Emit weak vtables, RTTI, and thunks with + ///< hidden visibility. +CODEGENOPT(InstrumentFunctions , 1, 0) ///< Set when -finstrument-functions is + ///< enabled. +CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled. +CODEGENOPT(LessPreciseFPMAD , 1, 0) ///< Enable less precise MAD instructions to + ///< be generated. +CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants. +CODEGENOPT(NoCommon , 1, 0) ///< Set when -fno-common or C++ is enabled. +CODEGENOPT(NoDwarf2CFIAsm , 1, 0) ///< Set when -fno-dwarf2-cfi-asm is enabled. +CODEGENOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm is + ///< enabled. +CODEGENOPT(NoExecStack , 1, 0) ///< Set when -Wa,--noexecstack is enabled. +CODEGENOPT(NoGlobalMerge , 1, 0) ///< Set when -mno-global-merge is enabled. +CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled. +CODEGENOPT(NoInfsFPMath , 1, 0) ///< Assume FP arguments, results not +-Inf. +CODEGENOPT(NoInline , 1, 0) ///< Set when -fno-inline is enabled. + ///< Disables use of the inline keyword. +CODEGENOPT(NoNaNsFPMath , 1, 0) ///< Assume FP arguments, results not NaN. +CODEGENOPT(NoZeroInitializedInBSS , 1, 0) ///< -fno-zero-initialized-in-bss. +/// \brief Method of Objective-C dispatch to use. +ENUM_CODEGENOPT(ObjCDispatchMethod, ObjCDispatchMethodKind, 2, Legacy) +CODEGENOPT(OmitLeafFramePointer , 1, 0) ///< Set when -momit-leaf-frame-pointer is + ///< enabled. +VALUE_CODEGENOPT(OptimizationLevel, 3, 0) ///< The -O[0-4] option specified. +VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is specified. +CODEGENOPT(RelaxAll , 1, 0) ///< Relax all machine code instructions. +CODEGENOPT(RelaxedAliasing , 1, 0) ///< Set when -fno-strict-aliasing is enabled. +CODEGENOPT(SaveTempLabels , 1, 0) ///< Save temporary labels. +CODEGENOPT(SimplifyLibCalls , 1, 1) ///< Set when -fbuiltin is enabled. +CODEGENOPT(SoftFloat , 1, 0) ///< -soft-float. +CODEGENOPT(StrictEnums , 1, 0) ///< Optimize based on strict enum definition. +CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report is enabled. +CODEGENOPT(UnitAtATime , 1, 1) ///< Unused. For mirroring GCC optimization + ///< selection. +CODEGENOPT(UnrollLoops , 1, 0) ///< Control whether loops are unrolled. +CODEGENOPT(UnsafeFPMath , 1, 0) ///< Allow unsafe floating point optzns. +CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. + + /// Attempt to use register sized accesses to bit-fields in structures, when + /// possible. +CODEGENOPT(UseRegisterSizedBitfieldAccess , 1, 0) + +CODEGENOPT(VerifyModule , 1, 1) ///< Control whether the module should be run + ///< through the LLVM Verifier. + +CODEGENOPT(StackRealignment , 1, 0) ///< Control whether to permit stack + ///< realignment. +CODEGENOPT(UseInitArray , 1, 0) ///< Control whether to use .init_array or + ///< .ctors. +VALUE_CODEGENOPT(StackAlignment , 32, 0) ///< Overrides default stack + ///< alignment, if not 0. +CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information + ///< in debug info. + +/// The user specified number of registers to be used for integral arguments, +/// or 0 if unspecified. +VALUE_CODEGENOPT(NumRegisterParameters, 32, 0) + +/// The run-time penalty for bounds checking, or 0 to disable. +VALUE_CODEGENOPT(BoundsChecking, 8, 0) + +/// The lower bound for a buffer to be considered for stack protection. +VALUE_CODEGENOPT(SSPBufferSize, 32, 0) + +/// The kind of generated debug info. +ENUM_CODEGENOPT(DebugInfo, DebugInfoKind, 2, NoDebugInfo) + +/// The kind of inlining to perform. +ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NoInlining) + +/// The default TLS model to use. +ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel) + +#undef CODEGENOPT +#undef ENUM_CODEGENOPT +#undef VALUE_CODEGENOPT + diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h index 3e34093..3567187 100644 --- a/include/clang/Frontend/CodeGenOptions.h +++ b/include/clang/Frontend/CodeGenOptions.h @@ -19,9 +19,23 @@ namespace clang { +/// \brief Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure +/// that this large collection of bitfields is a trivial class type. +class CodeGenOptionsBase { +public: +#define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits; +#define ENUM_CODEGENOPT(Name, Type, Bits, Default) +#include "clang/Frontend/CodeGenOptions.def" + +protected: +#define CODEGENOPT(Name, Bits, Default) +#define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits; +#include "clang/Frontend/CodeGenOptions.def" +}; + /// CodeGenOptions - Track various options which control how the code /// is optimized and passed to the backend. -class CodeGenOptions { +class CodeGenOptions : public CodeGenOptionsBase { public: enum InliningMethod { NoInlining, // Perform no inlining whatsoever. @@ -51,86 +65,6 @@ public: LocalExecTLSModel }; - unsigned AsmVerbose : 1; ///< -dA, -fverbose-asm. - unsigned ObjCAutoRefCountExceptions : 1; ///< Whether ARC should be EH-safe. - unsigned CUDAIsDevice : 1; ///< Set when compiling for CUDA device. - unsigned CXAAtExit : 1; ///< Use __cxa_atexit for calling destructors. - unsigned CXXCtorDtorAliases: 1; ///< Emit complete ctors/dtors as linker - ///< aliases to base ctors when possible. - unsigned DataSections : 1; ///< Set when -fdata-sections is enabled. - unsigned DisableFPElim : 1; ///< Set when -fomit-frame-pointer is enabled. - unsigned DisableLLVMOpts : 1; ///< Don't run any optimizations, for use in - ///< getting .bc files that correspond to the - ///< internal state before optimizations are - ///< done. - unsigned DisableRedZone : 1; ///< Set when -mno-red-zone is enabled. - unsigned DisableTailCalls : 1; ///< Do not emit tail calls. - unsigned EmitDeclMetadata : 1; ///< Emit special metadata indicating what - ///< Decl* various IR entities came from. Only - ///< useful when running CodeGen as a - ///< subroutine. - unsigned EmitGcovArcs : 1; ///< Emit coverage data files, aka. GCDA. - unsigned EmitGcovNotes : 1; ///< Emit coverage "notes" files, aka GCNO. - unsigned EmitOpenCLArgMetadata : 1; ///< Emit OpenCL kernel arg metadata. - unsigned EmitMicrosoftInlineAsm : 1; ///< Enable emission of MS-style inline - ///< assembly. - unsigned ForbidGuardVariables : 1; ///< Issue errors if C++ guard variables - ///< are required. - unsigned FunctionSections : 1; ///< Set when -ffunction-sections is enabled. - unsigned HiddenWeakTemplateVTables : 1; ///< Emit weak vtables and RTTI for - ///< template classes with hidden visibility - unsigned HiddenWeakVTables : 1; ///< Emit weak vtables, RTTI, and thunks with - ///< hidden visibility. - unsigned InstrumentFunctions : 1; ///< Set when -finstrument-functions is - ///< enabled. - unsigned InstrumentForProfiling : 1; ///< Set when -pg is enabled. - unsigned LessPreciseFPMAD : 1; ///< Enable less precise MAD instructions to - ///< be generated. - unsigned MergeAllConstants : 1; ///< Merge identical constants. - unsigned NoCommon : 1; ///< Set when -fno-common or C++ is enabled. - unsigned NoDwarf2CFIAsm : 1; ///< Set when -fno-dwarf2-cfi-asm is enabled. - unsigned NoDwarfDirectoryAsm : 1; ///< Set when -fno-dwarf-directory-asm is - ///< enabled. - unsigned NoExecStack : 1; ///< Set when -Wa,--noexecstack is enabled. - unsigned NoGlobalMerge : 1; ///< Set when -mno-global-merge is enabled. - unsigned NoImplicitFloat : 1; ///< Set when -mno-implicit-float is enabled. - unsigned NoInfsFPMath : 1; ///< Assume FP arguments, results not +-Inf. - unsigned NoInline : 1; ///< Set when -fno-inline is enabled. Disables - ///< use of the inline keyword. - unsigned NoNaNsFPMath : 1; ///< Assume FP arguments, results not NaN. - unsigned NoZeroInitializedInBSS : 1; ///< -fno-zero-initialized-in-bss. - unsigned ObjCDispatchMethod : 2; ///< Method of Objective-C dispatch to use. - unsigned OmitLeafFramePointer : 1; ///< Set when -momit-leaf-frame-pointer is - ///< enabled. - unsigned OptimizationLevel : 3; ///< The -O[0-4] option specified. - unsigned OptimizeSize : 2; ///< If -Os (==1) or -Oz (==2) is specified. - unsigned RelaxAll : 1; ///< Relax all machine code instructions. - unsigned RelaxedAliasing : 1; ///< Set when -fno-strict-aliasing is enabled. - unsigned SaveTempLabels : 1; ///< Save temporary labels. - unsigned SimplifyLibCalls : 1; ///< Set when -fbuiltin is enabled. - unsigned SoftFloat : 1; ///< -soft-float. - unsigned StrictEnums : 1; ///< Optimize based on strict enum definition. - unsigned TimePasses : 1; ///< Set when -ftime-report is enabled. - unsigned UnitAtATime : 1; ///< Unused. For mirroring GCC optimization - ///< selection. - unsigned UnrollLoops : 1; ///< Control whether loops are unrolled. - unsigned UnsafeFPMath : 1; ///< Allow unsafe floating point optzns. - unsigned UnwindTables : 1; ///< Emit unwind tables. - - /// Attempt to use register sized accesses to bit-fields in structures, when - /// possible. - unsigned UseRegisterSizedBitfieldAccess : 1; - - unsigned VerifyModule : 1; ///< Control whether the module should be run - ///< through the LLVM Verifier. - - unsigned StackRealignment : 1; ///< Control whether to permit stack - ///< realignment. - unsigned UseInitArray : 1; ///< Control whether to use .init_array or - ///< .ctors. - unsigned StackAlignment; ///< Overrides default stack alignment, - ///< if not 0. - /// The code model to use (-mcmodel). std::string CodeModel; @@ -144,9 +78,6 @@ public: /// The string to embed in debug information as the current working directory. std::string DebugCompilationDir; - /// The kind of generated debug info. - DebugInfoKind DebugInfo; - /// The string to embed in the debug information for the compile unit, if /// non-empty. std::string DwarfDebugFlags; @@ -160,9 +91,6 @@ public: /// The name of the bitcode file to link before optzns. std::string LinkBitcodeFile; - /// The kind of inlining to perform. - InliningMethod Inlining; - /// The user provided name for the "main file", if non-empty. This is useful /// in situations where the input file name does not match the original input /// file, for example with -save-temps. @@ -178,79 +106,21 @@ public: /// A list of command-line options to forward to the LLVM backend. std::vector<std::string> BackendOptions; - /// The user specified number of registers to be used for integral arguments, - /// or 0 if unspecified. - unsigned NumRegisterParameters; - - /// The run-time penalty for bounds checking, or 0 to disable. - unsigned char BoundsChecking; - - /// The default TLS model to use. - TLSModel DefaultTLSModel; - public: + // Define accessors/mutators for code generation options of enumeration type. +#define CODEGENOPT(Name, Bits, Default) +#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ + Type get##Name() const { return static_cast<Type>(Name); } \ + void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } +#include "clang/Frontend/CodeGenOptions.def" + CodeGenOptions() { - AsmVerbose = 0; - CUDAIsDevice = 0; - CXAAtExit = 1; - CXXCtorDtorAliases = 0; - DataSections = 0; - DisableFPElim = 0; - DisableLLVMOpts = 0; - DisableRedZone = 0; - DisableTailCalls = 0; - EmitDeclMetadata = 0; - EmitGcovArcs = 0; - EmitGcovNotes = 0; - EmitOpenCLArgMetadata = 0; - EmitMicrosoftInlineAsm = 0; - ForbidGuardVariables = 0; - FunctionSections = 0; - HiddenWeakTemplateVTables = 0; - HiddenWeakVTables = 0; - InstrumentFunctions = 0; - InstrumentForProfiling = 0; - LessPreciseFPMAD = 0; - MergeAllConstants = 1; - NoCommon = 0; - NoDwarf2CFIAsm = 0; - NoImplicitFloat = 0; - NoInfsFPMath = 0; - NoInline = 0; - NoNaNsFPMath = 0; - NoZeroInitializedInBSS = 0; - NumRegisterParameters = 0; - ObjCAutoRefCountExceptions = 0; - ObjCDispatchMethod = Legacy; - OmitLeafFramePointer = 0; - OptimizationLevel = 0; - OptimizeSize = 0; - RelaxAll = 0; - RelaxedAliasing = 0; - SaveTempLabels = 0; - SimplifyLibCalls = 1; - SoftFloat = 0; - StrictEnums = 0; - TimePasses = 0; - UnitAtATime = 1; - UnrollLoops = 0; - UnsafeFPMath = 0; - UnwindTables = 0; - UseRegisterSizedBitfieldAccess = 0; - VerifyModule = 1; - StackRealignment = 0; - StackAlignment = 0; - BoundsChecking = 0; - UseInitArray = 0; +#define CODEGENOPT(Name, Bits, Default) Name = Default; +#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ + set##Name(Default); +#include "clang/Frontend/CodeGenOptions.def" - DebugInfo = NoDebugInfo; - Inlining = NoInlining; RelocationModel = "pic"; - DefaultTLSModel = GeneralDynamicTLSModel; - } - - ObjCDispatchMethodKind getObjCDispatchMethod() const { - return ObjCDispatchMethodKind(ObjCDispatchMethod); } }; diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index b28e103..2f3dc3f 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -11,6 +11,7 @@ #define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ #include "clang/Frontend/CompilerInvocation.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/ModuleLoader.h" #include "llvm/ADT/ArrayRef.h" @@ -130,8 +131,8 @@ class CompilerInstance : public ModuleLoader { /// The list of active output files. std::list<OutputFile> OutputFiles; - void operator=(const CompilerInstance &); // DO NOT IMPLEMENT - CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT + CompilerInstance(const CompilerInstance &) LLVM_DELETED_FUNCTION; + void operator=(const CompilerInstance &) LLVM_DELETED_FUNCTION; public: CompilerInstance(); ~CompilerInstance(); @@ -189,10 +190,7 @@ public: /// @name Forwarding Methods /// { - AnalyzerOptions &getAnalyzerOpts() { - return Invocation->getAnalyzerOpts(); - } - const AnalyzerOptions &getAnalyzerOpts() const { + AnalyzerOptionsRef getAnalyzerOpts() { return Invocation->getAnalyzerOpts(); } @@ -393,7 +391,7 @@ public: ASTConsumer *takeASTConsumer() { return Consumer.take(); } /// setASTConsumer - Replace the current AST consumer; the compiler instance - /// takes ownership of \arg Value. + /// takes ownership of \p Value. void setASTConsumer(ASTConsumer *Value); /// } @@ -433,7 +431,7 @@ public: } /// setCodeCompletionConsumer - Replace the current code completion consumer; - /// the compiler instance takes ownership of \arg Value. + /// the compiler instance takes ownership of \p Value. void setCodeCompletionConsumer(CodeCompleteConsumer *Value); /// } @@ -488,7 +486,7 @@ public: /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter. /// - /// The \arg Argc and \arg Argv arguments are used only for logging purposes, + /// The \p Argc and \p Argv arguments are used only for logging purposes, /// when the diagnostic options indicate that the compiler should output /// logging information. /// @@ -498,8 +496,7 @@ public: /// releasing the returned DiagnosticsEngine's client eventually. /// /// \param Opts - The diagnostic options; note that the created text - /// diagnostic object contains a reference to these options and its lifetime - /// must extend past that of the diagnostic engine. + /// diagnostic object contains a reference to these options. /// /// \param Client If non-NULL, a diagnostic client that will be /// attached to (and, then, owned by) the returned DiagnosticsEngine @@ -510,7 +507,7 @@ public: /// /// \return The new object on success, or null on failure. static IntrusiveRefCntPtr<DiagnosticsEngine> - createDiagnostics(const DiagnosticOptions &Opts, int Argc, + createDiagnostics(DiagnosticOptions *Opts, int Argc, const char* const *Argv, DiagnosticConsumer *Client = 0, bool ShouldOwnClient = true, @@ -534,7 +531,6 @@ public: /// context. void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation, - bool DisableStatCache, bool AllowPCHWithCompilerErrors, void *DeserializationListener); @@ -544,7 +540,6 @@ public: static ExternalASTSource * createPCHExternalASTSource(StringRef Path, const std::string &Sysroot, bool DisablePCHValidation, - bool DisableStatCache, bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context, void *DeserializationListener, bool Preamble); @@ -555,8 +550,7 @@ public: void createCodeCompletionConsumer(); /// Create a code completion consumer to print code completion results, at - /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg - /// OS. + /// \p Filename, \p Line, and \p Column, to the given output stream \p OS. static CodeCompleteConsumer * createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, unsigned Line, unsigned Column, @@ -596,15 +590,15 @@ public: /// Create a new output file, optionally deriving the output path name. /// - /// If \arg OutputPath is empty, then createOutputFile will derive an output - /// path location as \arg BaseInput, with any suffix removed, and \arg - /// Extension appended. If OutputPath is not stdout and \arg UseTemporary + /// If \p OutputPath is empty, then createOutputFile will derive an output + /// path location as \p BaseInput, with any suffix removed, and \p Extension + /// appended. If \p OutputPath is not stdout and \p UseTemporary /// is true, createOutputFile will create a new temporary file that must be - /// renamed to OutputPath in the end. + /// renamed to \p OutputPath in the end. /// /// \param OutputPath - If given, the path to the output file. /// \param Error [out] - On failure, the error message. - /// \param BaseInput - If \arg OutputPath is empty, the input path name to use + /// \param BaseInput - If \p OutputPath is empty, the input path name to use /// for deriving the output path. /// \param Extension - The extension to use for derived output names. /// \param Binary - The mode to open the file in. @@ -613,7 +607,7 @@ public: /// multithreaded use, as the underlying signal mechanism is not reentrant /// \param UseTemporary - Create a new temporary file that must be renamed to /// OutputPath in the end. - /// \param CreateMissingDirectories - When \arg UseTemporary is true, create + /// \param CreateMissingDirectories - When \p UseTemporary is true, create /// missing directories in the output path. /// \param ResultPathName [out] - If given, the result path name will be /// stored here on success. @@ -637,15 +631,13 @@ public: /// as the main file. /// /// \return True on success. - bool InitializeSourceManager(StringRef InputFile, - SrcMgr::CharacteristicKind Kind = SrcMgr::C_User); + bool InitializeSourceManager(const FrontendInputFile &Input); /// InitializeSourceManager - Initialize the source manager to set InputFile /// as the main file. /// /// \return True on success. - static bool InitializeSourceManager(StringRef InputFile, - SrcMgr::CharacteristicKind Kind, + static bool InitializeSourceManager(const FrontendInputFile &Input, DiagnosticsEngine &Diags, FileManager &FileMgr, SourceManager &SourceMgr, diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h index d6fe003..1314956 100644 --- a/include/clang/Frontend/CompilerInvocation.h +++ b/include/clang/Frontend/CompilerInvocation.h @@ -13,15 +13,15 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/TargetOptions.h" #include "clang/Basic/FileSystemOptions.h" -#include "clang/Frontend/AnalyzerOptions.h" +#include "clang/Basic/DiagnosticOptions.h" +#include "clang/Lex/HeaderSearchOptions.h" +#include "clang/Lex/PreprocessorOptions.h" +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "clang/Frontend/MigratorOptions.h" #include "clang/Frontend/CodeGenOptions.h" #include "clang/Frontend/DependencyOutputOptions.h" -#include "clang/Frontend/DiagnosticOptions.h" #include "clang/Frontend/FrontendOptions.h" -#include "clang/Frontend/HeaderSearchOptions.h" #include "clang/Frontend/LangStandard.h" -#include "clang/Frontend/PreprocessorOptions.h" #include "clang/Frontend/PreprocessorOutputOptions.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" @@ -52,6 +52,19 @@ class CompilerInvocationBase : public RefCountedBase<CompilerInvocation> { protected: /// Options controlling the language variant. IntrusiveRefCntPtr<LangOptions> LangOpts; + + /// Options controlling the target. + IntrusiveRefCntPtr<TargetOptions> TargetOpts; + + /// Options controlling the diagnostic engine. + IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts; + + /// Options controlling the \#include directive. + IntrusiveRefCntPtr<HeaderSearchOptions> HeaderSearchOpts; + + /// Options controlling the preprocessor (aside from \#include handling). + IntrusiveRefCntPtr<PreprocessorOptions> PreprocessorOpts; + public: CompilerInvocationBase(); @@ -59,6 +72,23 @@ public: LangOptions *getLangOpts() { return LangOpts.getPtr(); } const LangOptions *getLangOpts() const { return LangOpts.getPtr(); } + + TargetOptions &getTargetOpts() { return *TargetOpts.getPtr(); } + const TargetOptions &getTargetOpts() const { + return *TargetOpts.getPtr(); + } + + DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; } + + HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; } + const HeaderSearchOptions &getHeaderSearchOpts() const { + return *HeaderSearchOpts; + } + + PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; } + const PreprocessorOptions &getPreprocessorOpts() const { + return *PreprocessorOpts; + } }; /// \brief Helper class for holding the data necessary to invoke the compiler. @@ -68,7 +98,7 @@ public: /// options, the warning flags, and so on. class CompilerInvocation : public CompilerInvocationBase { /// Options controlling the static analyzer. - AnalyzerOptions AnalyzerOpts; + AnalyzerOptionsRef AnalyzerOpts; MigratorOptions MigratorOpts; @@ -78,29 +108,17 @@ class CompilerInvocation : public CompilerInvocationBase { /// Options controlling dependency output. DependencyOutputOptions DependencyOutputOpts; - /// Options controlling the diagnostic engine. - DiagnosticOptions DiagnosticOpts; - /// Options controlling file system operations. FileSystemOptions FileSystemOpts; /// Options controlling the frontend itself. FrontendOptions FrontendOpts; - /// Options controlling the \#include directive. - HeaderSearchOptions HeaderSearchOpts; - - /// Options controlling the preprocessor (aside from \#include handling). - PreprocessorOptions PreprocessorOpts; - /// Options controlling preprocessed output. PreprocessorOutputOptions PreprocessorOutputOpts; - /// Options controlling the target. - TargetOptions TargetOpts; - public: - CompilerInvocation() {} + CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {} /// @name Utility Methods /// @{ @@ -127,10 +145,6 @@ public: /// executable), for finding the builtin compiler path. static std::string GetResourcesPath(const char *Argv0, void *MainAddr); - /// \brief Convert the CompilerInvocation to a list of strings suitable for - /// passing to CreateFromArgs. - void toArgs(std::vector<std::string> &Res) const; - /// \brief Set language defaults for the given input language and /// language standard in the given LangOptions object. /// @@ -148,8 +162,7 @@ public: /// @name Option Subgroups /// @{ - AnalyzerOptions &getAnalyzerOpts() { return AnalyzerOpts; } - const AnalyzerOptions &getAnalyzerOpts() const { + AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; } @@ -170,29 +183,16 @@ public: return DependencyOutputOpts; } - DiagnosticOptions &getDiagnosticOpts() { return DiagnosticOpts; } - const DiagnosticOptions &getDiagnosticOpts() const { return DiagnosticOpts; } - FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; } const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; } - HeaderSearchOptions &getHeaderSearchOpts() { return HeaderSearchOpts; } - const HeaderSearchOptions &getHeaderSearchOpts() const { - return HeaderSearchOpts; - } - FrontendOptions &getFrontendOpts() { return FrontendOpts; } const FrontendOptions &getFrontendOpts() const { return FrontendOpts; } - PreprocessorOptions &getPreprocessorOpts() { return PreprocessorOpts; } - const PreprocessorOptions &getPreprocessorOpts() const { - return PreprocessorOpts; - } - PreprocessorOutputOptions &getPreprocessorOutputOpts() { return PreprocessorOutputOpts; } @@ -200,11 +200,6 @@ public: return PreprocessorOutputOpts; } - TargetOptions &getTargetOpts() { return TargetOpts; } - const TargetOptions &getTargetOpts() const { - return TargetOpts; - } - /// @} }; diff --git a/include/clang/Frontend/DiagnosticOptions.h b/include/clang/Frontend/DiagnosticOptions.h deleted file mode 100644 index 8dec37c..0000000 --- a/include/clang/Frontend/DiagnosticOptions.h +++ /dev/null @@ -1,111 +0,0 @@ -//===--- DiagnosticOptions.h ------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_FRONTEND_DIAGNOSTICOPTIONS_H -#define LLVM_CLANG_FRONTEND_DIAGNOSTICOPTIONS_H - -#include "clang/Basic/Diagnostic.h" - -#include <string> -#include <vector> - -namespace clang { - -/// DiagnosticOptions - Options for controlling the compiler diagnostics -/// engine. -class DiagnosticOptions { -public: - unsigned IgnoreWarnings : 1; /// -w - unsigned NoRewriteMacros : 1; /// -Wno-rewrite-macros - unsigned Pedantic : 1; /// -pedantic - unsigned PedanticErrors : 1; /// -pedantic-errors - unsigned ShowColumn : 1; /// Show column number on diagnostics. - unsigned ShowLocation : 1; /// Show source location information. - unsigned ShowCarets : 1; /// Show carets in diagnostics. - unsigned ShowFixits : 1; /// Show fixit information. - unsigned ShowSourceRanges : 1; /// Show source ranges in numeric form. - unsigned ShowParseableFixits : 1; /// Show machine parseable fix-its. - unsigned ShowOptionNames : 1; /// Show the option name for mappable - /// diagnostics. - unsigned ShowNoteIncludeStack : 1; /// Show include stacks for notes. - unsigned ShowCategories : 2; /// Show categories: 0 -> none, 1 -> Number, - /// 2 -> Full Name. - - unsigned Format : 2; /// Format for diagnostics: - enum TextDiagnosticFormat { Clang, Msvc, Vi }; - - unsigned ShowColors : 1; /// Show diagnostics with ANSI color sequences. - unsigned ShowOverloads : 1; /// Overload candidates to show. Values from - /// DiagnosticsEngine::OverloadsShown - unsigned VerifyDiagnostics: 1; /// Check that diagnostics match the expected - /// diagnostics, indicated by markers in the - /// input source file. - - unsigned ElideType: 1; /// Elide identical types in template diffing - unsigned ShowTemplateTree: 1; /// Print a template tree when diffing - - unsigned ErrorLimit; /// Limit # errors emitted. - unsigned MacroBacktraceLimit; /// Limit depth of macro expansion backtrace. - unsigned TemplateBacktraceLimit; /// Limit depth of instantiation backtrace. - unsigned ConstexprBacktraceLimit; /// Limit depth of constexpr backtrace. - - /// The distance between tab stops. - unsigned TabStop; - enum { DefaultTabStop = 8, MaxTabStop = 100, - DefaultMacroBacktraceLimit = 6, - DefaultTemplateBacktraceLimit = 10, - DefaultConstexprBacktraceLimit = 10 }; - - /// Column limit for formatting message diagnostics, or 0 if unused. - unsigned MessageLength; - - /// If non-empty, a file to log extended build information to, for development - /// testing and analysis. - std::string DumpBuildInformation; - - /// The file to log diagnostic output to. - std::string DiagnosticLogFile; - - /// The file to serialize diagnostics to (non-appending). - std::string DiagnosticSerializationFile; - - /// The list of -W... options used to alter the diagnostic mappings, with the - /// prefixes removed. - std::vector<std::string> Warnings; - -public: - DiagnosticOptions() { - IgnoreWarnings = 0; - TabStop = DefaultTabStop; - MessageLength = 0; - NoRewriteMacros = 0; - Pedantic = 0; - PedanticErrors = 0; - ShowCarets = 1; - ShowColors = 0; - ShowOverloads = DiagnosticsEngine::Ovl_All; - ShowColumn = 1; - ShowFixits = 1; - ShowLocation = 1; - ShowOptionNames = 0; - ShowCategories = 0; - Format = Clang; - ShowSourceRanges = 0; - ShowParseableFixits = 0; - VerifyDiagnostics = 0; - ErrorLimit = 0; - TemplateBacktraceLimit = DefaultTemplateBacktraceLimit; - MacroBacktraceLimit = DefaultMacroBacktraceLimit; - ConstexprBacktraceLimit = DefaultConstexprBacktraceLimit; - } -}; - -} // end namespace clang - -#endif diff --git a/include/clang/Frontend/DiagnosticRenderer.h b/include/clang/Frontend/DiagnosticRenderer.h index 09d7ecb..086bb13 100644 --- a/include/clang/Frontend/DiagnosticRenderer.h +++ b/include/clang/Frontend/DiagnosticRenderer.h @@ -44,7 +44,7 @@ typedef llvm::PointerUnion<const Diagnostic *, class DiagnosticRenderer { protected: const LangOptions &LangOpts; - const DiagnosticOptions &DiagOpts; + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; /// \brief The location of the previous diagnostic if known. /// @@ -66,7 +66,7 @@ protected: DiagnosticsEngine::Level LastLevel; DiagnosticRenderer(const LangOptions &LangOpts, - const DiagnosticOptions &DiagOpts); + DiagnosticOptions *DiagOpts); virtual ~DiagnosticRenderer(); @@ -124,7 +124,7 @@ public: /// \param Ranges The underlined ranges for this code snippet. /// \param FixItHints The FixIt hints active for this diagnostic. /// \param SM The SourceManager; will be null if the diagnostic came from the - /// frontend, thus \param Loc will be invalid. + /// frontend, thus \p Loc will be invalid. void emitDiagnostic(SourceLocation Loc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> FixItHints, @@ -139,7 +139,7 @@ public: class DiagnosticNoteRenderer : public DiagnosticRenderer { public: DiagnosticNoteRenderer(const LangOptions &LangOpts, - const DiagnosticOptions &DiagOpts) + DiagnosticOptions *DiagOpts) : DiagnosticRenderer(LangOpts, DiagOpts) {} virtual ~DiagnosticNoteRenderer(); diff --git a/include/clang/Frontend/FrontendAction.h b/include/clang/Frontend/FrontendAction.h index c0056de..3283444 100644 --- a/include/clang/Frontend/FrontendAction.h +++ b/include/clang/Frontend/FrontendAction.h @@ -109,7 +109,7 @@ public: /// @{ bool isCurrentFileAST() const { - assert(!CurrentInput.File.empty() && "No current file!"); + assert(!CurrentInput.isEmpty() && "No current file!"); return CurrentASTUnit != 0; } @@ -117,14 +117,14 @@ public: return CurrentInput; } - const std::string &getCurrentFile() const { - assert(!CurrentInput.File.empty() && "No current file!"); - return CurrentInput.File; + const StringRef getCurrentFile() const { + assert(!CurrentInput.isEmpty() && "No current file!"); + return CurrentInput.getFile(); } InputKind getCurrentFileKind() const { - assert(!CurrentInput.File.empty() && "No current file!"); - return CurrentInput.Kind; + assert(!CurrentInput.isEmpty() && "No current file!"); + return CurrentInput.getKind(); } ASTUnit &getCurrentASTUnit() const { @@ -167,8 +167,8 @@ public: /// @name Public Action Interface /// @{ - /// BeginSourceFile - Prepare the action for processing the input file \arg - /// Filename; this is run after the options and frontend have been + /// BeginSourceFile - Prepare the action for processing the input file + /// \p Input; this is run after the options and frontend have been /// initialized, but prior to executing any per-file processing. /// /// \param CI - The compiler instance this action is being run from. The diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index ce1cd9b..db2f5a5 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -16,6 +16,10 @@ #include <string> #include <vector> +namespace llvm { +class MemoryBuffer; +} + namespace clang { namespace frontend { @@ -72,19 +76,41 @@ enum InputKind { /// \brief An input file for the front end. -struct FrontendInputFile { +class FrontendInputFile { /// \brief The file name, or "-" to read from standard input. std::string File; + llvm::MemoryBuffer *Buffer; + /// \brief The kind of input, e.g., C source, AST file, LLVM IR. InputKind Kind; /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input). bool IsSystem; - - FrontendInputFile() : Kind(IK_None) { } + +public: + FrontendInputFile() : Buffer(0), Kind(IK_None) { } FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) - : File(File.str()), Kind(Kind), IsSystem(IsSystem) { } + : File(File.str()), Buffer(0), Kind(Kind), IsSystem(IsSystem) { } + FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind, + bool IsSystem = false) + : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { } + + InputKind getKind() const { return Kind; } + bool isSystem() const { return IsSystem; } + + bool isEmpty() const { return File.empty() && Buffer == 0; } + bool isFile() const { return !isBuffer(); } + bool isBuffer() const { return Buffer != 0; } + + StringRef getFile() const { + assert(isFile()); + return File; + } + llvm::MemoryBuffer *getBuffer() const { + assert(isBuffer()); + return Buffer; + } }; /// FrontendOptions - Options for controlling the behavior of the frontend. diff --git a/include/clang/Frontend/HeaderSearchOptions.h b/include/clang/Frontend/HeaderSearchOptions.h deleted file mode 100644 index ebc8f26..0000000 --- a/include/clang/Frontend/HeaderSearchOptions.h +++ /dev/null @@ -1,146 +0,0 @@ -//===--- HeaderSearchOptions.h ----------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_FRONTEND_HEADERSEARCHOPTIONS_H -#define LLVM_CLANG_FRONTEND_HEADERSEARCHOPTIONS_H - -#include "llvm/ADT/StringRef.h" -#include <vector> - -namespace clang { - -namespace frontend { - /// IncludeDirGroup - Identifiers the group a include entry belongs to, which - /// represents its relative positive in the search list. A \#include of a "" - /// path starts at the -iquote group, then searches the Angled group, then - /// searches the system group, etc. - enum IncludeDirGroup { - Quoted = 0, ///< '\#include ""' paths, added by 'gcc -iquote'. - Angled, ///< Paths for '\#include <>' added by '-I'. - IndexHeaderMap, ///< Like Angled, but marks header maps used when - /// building frameworks. - System, ///< Like Angled, but marks system directories. - CSystem, ///< Like System, but only used for C. - CXXSystem, ///< Like System, but only used for C++. - ObjCSystem, ///< Like System, but only used for ObjC. - ObjCXXSystem, ///< Like System, but only used for ObjC++. - After ///< Like System, but searched after the system directories. - }; -} - -/// HeaderSearchOptions - Helper class for storing options related to the -/// initialization of the HeaderSearch object. -class HeaderSearchOptions { -public: - struct Entry { - std::string Path; - frontend::IncludeDirGroup Group; - unsigned IsUserSupplied : 1; - unsigned IsFramework : 1; - - /// IgnoreSysRoot - This is false if an absolute path should be treated - /// relative to the sysroot, or true if it should always be the absolute - /// path. - unsigned IgnoreSysRoot : 1; - - /// \brief True if this entry is an internal search path. - /// - /// This typically indicates that users didn't directly provide it, but - /// instead it was provided by a compatibility layer for a particular - /// system. This isn't redundant with IsUserSupplied (even though perhaps - /// it should be) because that is false for user provided '-iwithprefix' - /// header search entries. - unsigned IsInternal : 1; - - /// \brief True if this entry's headers should be wrapped in extern "C". - unsigned ImplicitExternC : 1; - - Entry(StringRef path, frontend::IncludeDirGroup group, - bool isUserSupplied, bool isFramework, bool ignoreSysRoot, - bool isInternal, bool implicitExternC) - : Path(path), Group(group), IsUserSupplied(isUserSupplied), - IsFramework(isFramework), IgnoreSysRoot(ignoreSysRoot), - IsInternal(isInternal), ImplicitExternC(implicitExternC) {} - }; - - struct SystemHeaderPrefix { - /// A prefix to be matched against paths in \#include directives. - std::string Prefix; - - /// True if paths beginning with this prefix should be treated as system - /// headers. - bool IsSystemHeader; - - SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) - : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {} - }; - - /// If non-empty, the directory to use as a "virtual system root" for include - /// paths. - std::string Sysroot; - - /// User specified include entries. - std::vector<Entry> UserEntries; - - /// User-specified system header prefixes. - std::vector<SystemHeaderPrefix> SystemHeaderPrefixes; - - /// The directory which holds the compiler resource files (builtin includes, - /// etc.). - std::string ResourceDir; - - /// \brief The directory used for the module cache. - std::string ModuleCachePath; - - /// \brief Whether we should disable the use of the hash string within the - /// module cache. - /// - /// Note: Only used for testing! - unsigned DisableModuleHash : 1; - - /// Include the compiler builtin includes. - unsigned UseBuiltinIncludes : 1; - - /// Include the system standard include search directories. - unsigned UseStandardSystemIncludes : 1; - - /// Include the system standard C++ library include search directories. - unsigned UseStandardCXXIncludes : 1; - - /// Use libc++ instead of the default libstdc++. - unsigned UseLibcxx : 1; - - /// Whether header search information should be output as for -v. - unsigned Verbose : 1; - -public: - HeaderSearchOptions(StringRef _Sysroot = "/") - : Sysroot(_Sysroot), DisableModuleHash(0), UseBuiltinIncludes(true), - UseStandardSystemIncludes(true), UseStandardCXXIncludes(true), - UseLibcxx(false), Verbose(false) {} - - /// AddPath - Add the \arg Path path to the specified \arg Group list. - void AddPath(StringRef Path, frontend::IncludeDirGroup Group, - bool IsUserSupplied, bool IsFramework, bool IgnoreSysRoot, - bool IsInternal = false, bool ImplicitExternC = false) { - UserEntries.push_back(Entry(Path, Group, IsUserSupplied, IsFramework, - IgnoreSysRoot, IsInternal, ImplicitExternC)); - } - - /// AddSystemHeaderPrefix - Override whether \#include directives naming a - /// path starting with \arg Prefix should be considered as naming a system - /// header. - void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) { - SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, IsSystemHeader)); - } -}; - -} // end namespace clang - -#endif diff --git a/include/clang/Frontend/LangStandard.h b/include/clang/Frontend/LangStandard.h index e6f4403..f07cb02 100644 --- a/include/clang/Frontend/LangStandard.h +++ b/include/clang/Frontend/LangStandard.h @@ -18,16 +18,17 @@ namespace clang { namespace frontend { enum LangFeatures { - BCPLComment = (1 << 0), + LineComment = (1 << 0), C89 = (1 << 1), C99 = (1 << 2), C11 = (1 << 3), CPlusPlus = (1 << 4), CPlusPlus0x = (1 << 5), - Digraphs = (1 << 6), - GNUMode = (1 << 7), - HexFloat = (1 << 8), - ImplicitInt = (1 << 9) + CPlusPlus1y = (1 << 6), + Digraphs = (1 << 7), + GNUMode = (1 << 8), + HexFloat = (1 << 9), + ImplicitInt = (1 << 10) }; } @@ -53,8 +54,8 @@ public: /// getDescription - Get the description of this standard. const char *getDescription() const { return Description; } - /// hasBCPLComments - Language supports '//' comments. - bool hasBCPLComments() const { return Flags & frontend::BCPLComment; } + /// Language supports '//' comments. + bool hasLineComments() const { return Flags & frontend::LineComment; } /// isC89 - Language is a superset of C89. bool isC89() const { return Flags & frontend::C89; } @@ -71,6 +72,9 @@ public: /// isCPlusPlus0x - Language is a C++0x variant. bool isCPlusPlus0x() const { return Flags & frontend::CPlusPlus0x; } + /// isCPlusPlus1y - Language is a C++1y variant. + bool isCPlusPlus1y() const { return Flags & frontend::CPlusPlus1y; } + /// hasDigraphs - Language supports digraphs. bool hasDigraphs() const { return Flags & frontend::Digraphs; } diff --git a/include/clang/Frontend/LangStandards.def b/include/clang/Frontend/LangStandards.def index a604d4b..10807b7 100644 --- a/include/clang/Frontend/LangStandards.def +++ b/include/clang/Frontend/LangStandards.def @@ -36,91 +36,99 @@ LANGSTANDARD(c94, "iso9899:199409", LANGSTANDARD(gnu89, "gnu89", "ISO C 1990 with GNU extensions", - BCPLComment | C89 | Digraphs | GNUMode | ImplicitInt) + LineComment | C89 | Digraphs | GNUMode | ImplicitInt) LANGSTANDARD(gnu90, "gnu90", "ISO C 1990 with GNU extensions", - BCPLComment | C89 | Digraphs | GNUMode | ImplicitInt) + LineComment | C89 | Digraphs | GNUMode | ImplicitInt) // C99-ish modes LANGSTANDARD(c99, "c99", "ISO C 1999", - BCPLComment | C99 | Digraphs | HexFloat) + LineComment | C99 | Digraphs | HexFloat) LANGSTANDARD(c9x, "c9x", "ISO C 1999", - BCPLComment | C99 | Digraphs | HexFloat) + LineComment | C99 | Digraphs | HexFloat) LANGSTANDARD(iso9899_1999, "iso9899:1999", "ISO C 1999", - BCPLComment | C99 | Digraphs | HexFloat) + LineComment | C99 | Digraphs | HexFloat) LANGSTANDARD(iso9899_199x, "iso9899:199x", "ISO C 1999", - BCPLComment | C99 | Digraphs | HexFloat) + LineComment | C99 | Digraphs | HexFloat) LANGSTANDARD(gnu99, "gnu99", "ISO C 1999 with GNU extensions", - BCPLComment | C99 | Digraphs | GNUMode | HexFloat) + LineComment | C99 | Digraphs | GNUMode | HexFloat) LANGSTANDARD(gnu9x, "gnu9x", "ISO C 1999 with GNU extensions", - BCPLComment | C99 | Digraphs | GNUMode | HexFloat) + LineComment | C99 | Digraphs | GNUMode | HexFloat) // C11 modes LANGSTANDARD(c11, "c11", "ISO C 2011", - BCPLComment | C99 | C11 | Digraphs | HexFloat) + LineComment | C99 | C11 | Digraphs | HexFloat) LANGSTANDARD(c1x, "c1x", "ISO C 2011", - BCPLComment | C99 | C11 | Digraphs | HexFloat) + LineComment | C99 | C11 | Digraphs | HexFloat) LANGSTANDARD(iso9899_2011, "iso9899:2011", "ISO C 2011", - BCPLComment | C99 | C11 | Digraphs | HexFloat) + LineComment | C99 | C11 | Digraphs | HexFloat) LANGSTANDARD(iso9899_201x, "iso9899:2011", "ISO C 2011", - BCPLComment | C99 | C11 | Digraphs | HexFloat) + LineComment | C99 | C11 | Digraphs | HexFloat) LANGSTANDARD(gnu11, "gnu11", "ISO C 2011 with GNU extensions", - BCPLComment | C99 | C11 | Digraphs | GNUMode | HexFloat) + LineComment | C99 | C11 | Digraphs | GNUMode | HexFloat) LANGSTANDARD(gnu1x, "gnu1x", "ISO C 2011 with GNU extensions", - BCPLComment | C99 | C11 | Digraphs | GNUMode | HexFloat) + LineComment | C99 | C11 | Digraphs | GNUMode | HexFloat) // C++ modes LANGSTANDARD(cxx98, "c++98", "ISO C++ 1998 with amendments", - BCPLComment | CPlusPlus | Digraphs) + LineComment | CPlusPlus | Digraphs) LANGSTANDARD(cxx03, "c++03", "ISO C++ 1998 with amendments", - BCPLComment | CPlusPlus | Digraphs) + LineComment | CPlusPlus | Digraphs) LANGSTANDARD(gnucxx98, "gnu++98", "ISO C++ 1998 with amendments and GNU extensions", - BCPLComment | CPlusPlus | Digraphs | GNUMode) + LineComment | CPlusPlus | Digraphs | GNUMode) LANGSTANDARD(cxx0x, "c++0x", "ISO C++ 2011 with amendments", - BCPLComment | CPlusPlus | CPlusPlus0x | Digraphs) + LineComment | CPlusPlus | CPlusPlus0x | Digraphs) LANGSTANDARD(cxx11, "c++11", "ISO C++ 2011 with amendments", - BCPLComment | CPlusPlus | CPlusPlus0x | Digraphs) + LineComment | CPlusPlus | CPlusPlus0x | Digraphs) LANGSTANDARD(gnucxx0x, "gnu++0x", "ISO C++ 2011 with amendments and GNU extensions", - BCPLComment | CPlusPlus | CPlusPlus0x | Digraphs | GNUMode) + LineComment | CPlusPlus | CPlusPlus0x | Digraphs | GNUMode) LANGSTANDARD(gnucxx11, "gnu++11", "ISO C++ 2011 with amendments and GNU extensions", - BCPLComment | CPlusPlus | CPlusPlus0x | Digraphs | GNUMode) + LineComment | CPlusPlus | CPlusPlus0x | Digraphs | GNUMode) + +LANGSTANDARD(cxx1y, "c++1y", + "Working draft for ISO C++ 2014", + LineComment | CPlusPlus | CPlusPlus0x | CPlusPlus1y | Digraphs) +LANGSTANDARD(gnucxx1y, "gnu++1y", + "Working draft for ISO C++ 2014 with GNU extensions", + LineComment | CPlusPlus | CPlusPlus0x | CPlusPlus1y | Digraphs | + GNUMode) // OpenCL LANGSTANDARD(opencl, "cl", "OpenCL 1.0", - BCPLComment | C99 | Digraphs | HexFloat) + LineComment | C99 | Digraphs | HexFloat) LANGSTANDARD(opencl11, "CL1.1", "OpenCL 1.1", - BCPLComment | C99 | Digraphs | HexFloat) + LineComment | C99 | Digraphs | HexFloat) LANGSTANDARD(opencl12, "CL1.2", "OpenCL 1.2", - BCPLComment | C99 | Digraphs | HexFloat) + LineComment | C99 | Digraphs | HexFloat) // CUDA LANGSTANDARD(cuda, "cuda", "NVIDIA CUDA(tm)", - BCPLComment | CPlusPlus | Digraphs) + LineComment | CPlusPlus | Digraphs) #undef LANGSTANDARD diff --git a/include/clang/Frontend/LogDiagnosticPrinter.h b/include/clang/Frontend/LogDiagnosticPrinter.h index 4de15f2..f4fa876 100644 --- a/include/clang/Frontend/LogDiagnosticPrinter.h +++ b/include/clang/Frontend/LogDiagnosticPrinter.h @@ -42,7 +42,7 @@ class LogDiagnosticPrinter : public DiagnosticConsumer { raw_ostream &OS; const LangOptions *LangOpts; - const DiagnosticOptions *DiagOpts; + llvm::IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; SourceLocation LastWarningLoc; FullSourceLoc LastLoc; @@ -54,7 +54,7 @@ class LogDiagnosticPrinter : public DiagnosticConsumer { std::string DwarfDebugFlags; public: - LogDiagnosticPrinter(raw_ostream &OS, const DiagnosticOptions &Diags, + LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags, bool OwnsOutputStream = false); virtual ~LogDiagnosticPrinter(); diff --git a/include/clang/Frontend/MultiplexConsumer.h b/include/clang/Frontend/MultiplexConsumer.h index ffa7b4a..539f2c5 100644 --- a/include/clang/Frontend/MultiplexConsumer.h +++ b/include/clang/Frontend/MultiplexConsumer.h @@ -52,7 +52,6 @@ public: virtual void InitializeSema(Sema &S); virtual void ForgetSema(); - static bool classof(const MultiplexConsumer *) { return true; } private: std::vector<ASTConsumer*> Consumers; // Owns these. OwningPtr<MultiplexASTMutationListener> MutationListener; diff --git a/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h deleted file mode 100644 index d86a923..0000000 --- a/include/clang/Frontend/PreprocessorOptions.h +++ /dev/null @@ -1,224 +0,0 @@ -//===--- PreprocessorOptions.h ----------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_ -#define LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_ - -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include <cassert> -#include <string> -#include <utility> -#include <vector> -#include <set> - -namespace llvm { - class MemoryBuffer; -} - -namespace clang { - -class Preprocessor; -class LangOptions; - -/// \brief Enumerate the kinds of standard library that -enum ObjCXXARCStandardLibraryKind { - ARCXX_nolib, - /// \brief libc++ - ARCXX_libcxx, - /// \brief libstdc++ - ARCXX_libstdcxx -}; - -/// PreprocessorOptions - This class is used for passing the various options -/// used in preprocessor initialization to InitializePreprocessor(). -class PreprocessorOptions { -public: - std::vector<std::pair<std::string, bool/*isUndef*/> > Macros; - std::vector<std::string> Includes; - std::vector<std::string> MacroIncludes; - - unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler - /// and target specific predefines. - - unsigned DetailedRecord : 1; /// Whether we should maintain a detailed - /// record of all macro definitions and - /// expansions. - unsigned DetailedRecordConditionalDirectives : 1; /// Whether in the - /// preprocessing record we should also keep - /// track of locations of conditional directives - /// in non-system files. - - /// The implicit PCH included at the start of the translation unit, or empty. - std::string ImplicitPCHInclude; - - /// \brief Headers that will be converted to chained PCHs in memory. - std::vector<std::string> ChainedIncludes; - - /// \brief When true, disables most of the normal validation performed on - /// precompiled headers. - bool DisablePCHValidation; - - /// \brief When true, disables the use of the stat cache within a - /// precompiled header or AST file. - bool DisableStatCache; - - /// \brief When true, a PCH with compiler errors will not be rejected. - bool AllowPCHWithCompilerErrors; - - /// \brief Dump declarations that are deserialized from PCH, for testing. - bool DumpDeserializedPCHDecls; - - /// \brief This is a set of names for decls that we do not want to be - /// deserialized, and we emit an error if they are; for testing purposes. - std::set<std::string> DeserializedPCHDeclsToErrorOn; - - /// \brief If non-zero, the implicit PCH include is actually a precompiled - /// preamble that covers this number of bytes in the main source file. - /// - /// The boolean indicates whether the preamble ends at the start of a new - /// line. - std::pair<unsigned, bool> PrecompiledPreambleBytes; - - /// The implicit PTH input included at the start of the translation unit, or - /// empty. - std::string ImplicitPTHInclude; - - /// If given, a PTH cache file to use for speeding up header parsing. - std::string TokenCache; - - /// \brief True if the SourceManager should report the original file name for - /// contents of files that were remapped to other files. Defaults to true. - bool RemappedFilesKeepOriginalName; - - /// \brief The set of file remappings, which take existing files on - /// the system (the first part of each pair) and gives them the - /// contents of other files on the system (the second part of each - /// pair). - std::vector<std::pair<std::string, std::string> > RemappedFiles; - - /// \brief The set of file-to-buffer remappings, which take existing files - /// on the system (the first part of each pair) and gives them the contents - /// of the specified memory buffer (the second part of each pair). - std::vector<std::pair<std::string, const llvm::MemoryBuffer *> > - RemappedFileBuffers; - - /// \brief Whether the compiler instance should retain (i.e., not free) - /// the buffers associated with remapped files. - /// - /// This flag defaults to false; it can be set true only through direct - /// manipulation of the compiler invocation object, in cases where the - /// compiler invocation and its buffers will be reused. - bool RetainRemappedFileBuffers; - - /// \brief The Objective-C++ ARC standard library that we should support, - /// by providing appropriate definitions to retrofit the standard library - /// with support for lifetime-qualified pointers. - ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary; - - /// \brief The path of modules being build, which is used to detect - /// cycles in the module dependency graph as modules are being built. - /// - /// There is no way to set this value from the command line. If we ever need - /// to do so (e.g., if on-demand module construction moves out-of-process), - /// we can add a cc1-level option to do so. - SmallVector<std::string, 2> ModuleBuildPath; - - typedef std::vector<std::pair<std::string, std::string> >::iterator - remapped_file_iterator; - typedef std::vector<std::pair<std::string, std::string> >::const_iterator - const_remapped_file_iterator; - remapped_file_iterator remapped_file_begin() { - return RemappedFiles.begin(); - } - const_remapped_file_iterator remapped_file_begin() const { - return RemappedFiles.begin(); - } - remapped_file_iterator remapped_file_end() { - return RemappedFiles.end(); - } - const_remapped_file_iterator remapped_file_end() const { - return RemappedFiles.end(); - } - - typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >:: - iterator remapped_file_buffer_iterator; - typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >:: - const_iterator const_remapped_file_buffer_iterator; - remapped_file_buffer_iterator remapped_file_buffer_begin() { - return RemappedFileBuffers.begin(); - } - const_remapped_file_buffer_iterator remapped_file_buffer_begin() const { - return RemappedFileBuffers.begin(); - } - remapped_file_buffer_iterator remapped_file_buffer_end() { - return RemappedFileBuffers.end(); - } - const_remapped_file_buffer_iterator remapped_file_buffer_end() const { - return RemappedFileBuffers.end(); - } - -public: - PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), - DetailedRecordConditionalDirectives(false), - DisablePCHValidation(false), DisableStatCache(false), - AllowPCHWithCompilerErrors(false), - DumpDeserializedPCHDecls(false), - PrecompiledPreambleBytes(0, true), - RemappedFilesKeepOriginalName(true), - RetainRemappedFileBuffers(false), - ObjCXXARCStandardLibrary(ARCXX_nolib) { } - - void addMacroDef(StringRef Name) { - Macros.push_back(std::make_pair(Name, false)); - } - void addMacroUndef(StringRef Name) { - Macros.push_back(std::make_pair(Name, true)); - } - void addRemappedFile(StringRef From, StringRef To) { - RemappedFiles.push_back(std::make_pair(From, To)); - } - - remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) { - return RemappedFiles.erase(Remapped); - } - - void addRemappedFile(StringRef From, const llvm::MemoryBuffer * To) { - RemappedFileBuffers.push_back(std::make_pair(From, To)); - } - - remapped_file_buffer_iterator - eraseRemappedFile(remapped_file_buffer_iterator Remapped) { - return RemappedFileBuffers.erase(Remapped); - } - - void clearRemappedFiles() { - RemappedFiles.clear(); - RemappedFileBuffers.clear(); - } - - /// \brief Reset any options that are not considered when building a - /// module. - void resetNonModularOptions() { - Includes.clear(); - MacroIncludes.clear(); - ChainedIncludes.clear(); - DumpDeserializedPCHDecls = false; - ImplicitPCHInclude.clear(); - ImplicitPTHInclude.clear(); - TokenCache.clear(); - RetainRemappedFileBuffers = true; - PrecompiledPreambleBytes.first = 0; - PrecompiledPreambleBytes.second = 0; - } -}; - -} // end namespace clang - -#endif diff --git a/include/clang/Frontend/SerializedDiagnosticPrinter.h b/include/clang/Frontend/SerializedDiagnosticPrinter.h index aa0695f..ab70afd 100644 --- a/include/clang/Frontend/SerializedDiagnosticPrinter.h +++ b/include/clang/Frontend/SerializedDiagnosticPrinter.h @@ -54,7 +54,7 @@ enum RecordIDs { /// (via libclang) without needing to parse Clang's command line output. /// DiagnosticConsumer *create(llvm::raw_ostream *OS, - const DiagnosticOptions &diags); + DiagnosticOptions *diags); } // end serialized_diags namespace } // end clang namespace diff --git a/include/clang/Frontend/TextDiagnostic.h b/include/clang/Frontend/TextDiagnostic.h index c869c08..51f841d 100644 --- a/include/clang/Frontend/TextDiagnostic.h +++ b/include/clang/Frontend/TextDiagnostic.h @@ -40,7 +40,7 @@ class TextDiagnostic : public DiagnosticRenderer { public: TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts, - const DiagnosticOptions &DiagOpts); + DiagnosticOptions *DiagOpts); virtual ~TextDiagnostic(); diff --git a/include/clang/Frontend/TextDiagnosticPrinter.h b/include/clang/Frontend/TextDiagnosticPrinter.h index 23cf521..91ac3c8 100644 --- a/include/clang/Frontend/TextDiagnosticPrinter.h +++ b/include/clang/Frontend/TextDiagnosticPrinter.h @@ -18,6 +18,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" namespace clang { class DiagnosticOptions; @@ -26,7 +27,7 @@ class TextDiagnostic; class TextDiagnosticPrinter : public DiagnosticConsumer { raw_ostream &OS; - const DiagnosticOptions *DiagOpts; + llvm::IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; /// \brief Handle to the currently active text diagnostic emitter. OwningPtr<TextDiagnostic> TextDiag; @@ -37,7 +38,7 @@ class TextDiagnosticPrinter : public DiagnosticConsumer { unsigned OwnsOutputStream : 1; public: - TextDiagnosticPrinter(raw_ostream &os, const DiagnosticOptions &diags, + TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags, bool OwnsOutputStream = false); virtual ~TextDiagnosticPrinter(); diff --git a/include/clang/Frontend/VerifyDiagnosticConsumer.h b/include/clang/Frontend/VerifyDiagnosticConsumer.h index a74589e..06a3b24 100644 --- a/include/clang/Frontend/VerifyDiagnosticConsumer.h +++ b/include/clang/Frontend/VerifyDiagnosticConsumer.h @@ -12,9 +12,9 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Lex/Preprocessor.h" -#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" #include <climits> @@ -33,7 +33,9 @@ class FileEntry; /// Indicating that a line expects an error or a warning is simple. Put a /// comment on the line that has the diagnostic, use: /// -/// expected-{error,warning,note} +/// \code +/// expected-{error,warning,note} +/// \endcode /// /// to tag if it's an expected error or warning, and place the expected text /// between {{ and }} markers. The full text doesn't have to be included, only @@ -94,12 +96,15 @@ class FileEntry; /// /// In this example, the diagnostic may appear only once, if at all. /// -/// Regex matching mode may be selected by appending '-re' to type. Example: +/// Regex matching mode may be selected by appending '-re' to type, such as: /// +/// \code /// expected-error-re +/// \endcode /// /// Examples matching error: "variable has incomplete type 'struct s'" /// +/// \code /// // expected-error {{variable has incomplete type 'struct s'}} /// // expected-error {{variable has incomplete type}} /// @@ -107,6 +112,15 @@ class FileEntry; /// // expected-error-re {{variable has has type 'struct .*'}} /// // expected-error-re {{variable has has type 'struct (.*)'}} /// // expected-error-re {{variable has has type 'struct[[:space:]](.*)'}} +/// \endcode +/// +/// VerifyDiagnosticConsumer expects at least one expected-* directive to +/// be found inside the source code. If no diagnostics are expected the +/// following directive can be used to indicate this: +/// +/// \code +/// // expected-no-diagnostics +/// \endcode /// class VerifyDiagnosticConsumer: public DiagnosticConsumer, public CommentHandler { @@ -146,8 +160,8 @@ public: } private: - Directive(const Directive&); // DO NOT IMPLEMENT - void operator=(const Directive&); // DO NOT IMPLEMENT + Directive(const Directive &) LLVM_DELETED_FUNCTION; + void operator=(const Directive &) LLVM_DELETED_FUNCTION; }; typedef std::vector<Directive*> DirectiveList; @@ -166,10 +180,12 @@ public: } }; -#ifndef NDEBUG - typedef llvm::DenseSet<FileID> FilesWithDiagnosticsSet; - typedef llvm::SmallPtrSet<const FileEntry *, 4> FilesParsedForDirectivesSet; -#endif + enum DirectiveStatus { + HasNoDirectives, + HasNoDirectivesReported, + HasExpectedNoDiagnostics, + HasOtherExpectedDirectives + }; private: DiagnosticsEngine &Diags; @@ -177,13 +193,36 @@ private: bool OwnsPrimaryClient; OwningPtr<TextDiagnosticBuffer> Buffer; const Preprocessor *CurrentPreprocessor; + const LangOptions *LangOpts; + SourceManager *SrcManager; unsigned ActiveSourceFiles; -#ifndef NDEBUG - FilesWithDiagnosticsSet FilesWithDiagnostics; - FilesParsedForDirectivesSet FilesParsedForDirectives; -#endif + DirectiveStatus Status; ExpectedData ED; + void CheckDiagnostics(); + void setSourceManager(SourceManager &SM) { + assert((!SrcManager || SrcManager == &SM) && "SourceManager changed!"); + SrcManager = &SM; + } + +#ifndef NDEBUG + class UnparsedFileStatus { + llvm::PointerIntPair<const FileEntry *, 1, bool> Data; + + public: + UnparsedFileStatus(const FileEntry *File, bool FoundDirectives) + : Data(File, FoundDirectives) {} + + const FileEntry *getFile() const { return Data.getPointer(); } + bool foundDirectives() const { return Data.getInt(); } + }; + + typedef llvm::DenseMap<FileID, const FileEntry *> ParsedFilesMap; + typedef llvm::DenseMap<FileID, UnparsedFileStatus> UnparsedFilesMap; + + ParsedFilesMap ParsedFiles; + UnparsedFilesMap UnparsedFiles; +#endif public: /// Create a new verifying diagnostic client, which will issue errors to @@ -197,12 +236,19 @@ public: virtual void EndSourceFile(); - /// \brief Manually register a file as parsed. - inline void appendParsedFile(const FileEntry *File) { -#ifndef NDEBUG - FilesParsedForDirectives.insert(File); -#endif - } + enum ParsedStatus { + /// File has been processed via HandleComment. + IsParsed, + + /// File has diagnostics and may have directives. + IsUnparsed, + + /// File has diagnostics but guaranteed no directives. + IsUnparsedNoDirectives + }; + + /// \brief Update lists of parsed and unparsed files. + void UpdateParsedFileStatus(SourceManager &SM, FileID FID, ParsedStatus PS); virtual bool HandleComment(Preprocessor &PP, SourceRange Comment); |