diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-03-21 10:50:08 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-03-21 10:50:08 +0000 |
commit | 1e255aab650a7fa2047fd953cae65b12215280af (patch) | |
tree | 508d4388db78f87d35bf26a0400b4b03bc4c1f13 /include/clang/Frontend | |
parent | 1033b7c1e32962948b01a25145829f17bc70a8de (diff) | |
download | FreeBSD-src-1e255aab650a7fa2047fd953cae65b12215280af.zip FreeBSD-src-1e255aab650a7fa2047fd953cae65b12215280af.tar.gz |
Update clang to r99115.
Diffstat (limited to 'include/clang/Frontend')
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 24 | ||||
-rw-r--r-- | include/clang/Frontend/CompilerInstance.h | 1 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendActions.h | 16 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendOptions.h | 5 | ||||
-rw-r--r-- | include/clang/Frontend/PCHBitCodes.h | 23 | ||||
-rw-r--r-- | include/clang/Frontend/PCHReader.h | 53 | ||||
-rw-r--r-- | include/clang/Frontend/PCHWriter.h | 17 | ||||
-rw-r--r-- | include/clang/Frontend/PreprocessorOptions.h | 6 | ||||
-rw-r--r-- | include/clang/Frontend/Utils.h | 2 | ||||
-rw-r--r-- | include/clang/Frontend/VerifyDiagnosticsClient.h | 1 |
10 files changed, 108 insertions, 40 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 27ec12e..61db323 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -14,12 +14,14 @@ #ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H #define LLVM_CLANG_FRONTEND_ASTUNIT_H +#include "clang/Lex/PreprocessingRecord.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/OwningPtr.h" #include "clang/Basic/FileManager.h" #include "clang/Index/ASTLocation.h" #include "llvm/ADT/SmallVector.h" #include "llvm/System/Path.h" +#include <map> #include <string> #include <vector> #include <cassert> @@ -46,6 +48,11 @@ using namespace idx; /// \brief Utility class for loading a ASTContext from a PCH file. /// class ASTUnit { +public: + typedef std::map<FileID, std::vector<PreprocessedEntity *> > + PreprocessedEntitiesByFileMap; +private: + FileManager FileMgr; SourceManager SourceMgr; @@ -53,7 +60,7 @@ class ASTUnit { llvm::OwningPtr<TargetInfo> Target; llvm::OwningPtr<Preprocessor> PP; llvm::OwningPtr<ASTContext> Ctx; - + /// Optional owned invocation, just used to make the invocation used in /// LoadFromCommandLine available. llvm::OwningPtr<CompilerInvocation> Invocation; @@ -89,6 +96,15 @@ class ASTUnit { /// destroyed. llvm::SmallVector<llvm::sys::Path, 4> TemporaryFiles; + /// \brief A mapping from file IDs to the set of preprocessed entities + /// stored in that file. + /// + /// FIXME: This is just an optimization hack to avoid searching through + /// many preprocessed entities during cursor traversal in the CIndex library. + /// Ideally, we would just be able to perform a binary search within the + /// list of preprocessed entities. + PreprocessedEntitiesByFileMap PreprocessedEntitiesByFile; + /// \brief Simple hack to allow us to assert that ASTUnit is not being /// used concurrently, which is not supported. /// @@ -162,6 +178,12 @@ public: return TopLevelDecls; } + /// \brief Retrieve the mapping from File IDs to the preprocessed entities + /// within that file. + PreprocessedEntitiesByFileMap &getPreprocessedEntitiesByFile() { + return PreprocessedEntitiesByFile; + } + // Retrieve the diagnostics associated with this AST typedef const StoredDiagnostic * diag_iterator; diag_iterator diag_begin() const { return Diagnostics.begin(); } diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 828e9b5..3444b64 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -34,7 +34,6 @@ class ExternalASTSource; class FileManager; class FrontendAction; class Preprocessor; -class Source; class SourceManager; class TargetInfo; diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h index 5348e6b..a7b6aa7 100644 --- a/include/clang/Frontend/FrontendActions.h +++ b/include/clang/Frontend/FrontendActions.h @@ -18,6 +18,22 @@ namespace clang { class FixItRewriter; //===----------------------------------------------------------------------===// +// Custom Consumer Actions +//===----------------------------------------------------------------------===// + +class InitOnlyAction : public FrontendAction { + virtual void ExecuteAction(); + + virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, + llvm::StringRef InFile); + +public: + // Don't claim to only use the preprocessor, we want to follow the AST path, + // but do nothing. + virtual bool usesPreprocessorOnly() const { return false; } +}; + +//===----------------------------------------------------------------------===// // AST Consumer Actions //===----------------------------------------------------------------------===// diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 80ba778..ee3811a 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -36,6 +36,7 @@ namespace frontend { GeneratePCH, ///< Generate pre-compiled header. GeneratePTH, ///< Generate pre-tokenized header. InheritanceView, ///< View C++ inheritance for a specified class. + InitOnly, ///< Only execute frontend initialization. ParseNoop, ///< Parse with noop callbacks. ParsePrintCallbacks, ///< Parse and print each callback. ParseSyntaxOnly, ///< Parse and perform semantic analysis. @@ -71,9 +72,6 @@ public: unsigned DebugCodeCompletionPrinter : 1; ///< Use the debug printer for code /// completion results. unsigned DisableFree : 1; ///< Disable memory freeing on exit. - unsigned EmptyInputOnly : 1; ///< Force input files to be treated - /// as if they were empty, for timing - /// the frontend startup. unsigned RelocatablePCH : 1; ///< When generating PCH files, /// instruct the PCH writer to create /// relocatable PCH files. @@ -117,7 +115,6 @@ public: FrontendOptions() { DebugCodeCompletionPrinter = 1; DisableFree = 0; - EmptyInputOnly = 0; ProgramAction = frontend::ParseSyntaxOnly; ActionName = ""; RelocatablePCH = 0; diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index e234e98..f975c49 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -215,17 +215,18 @@ namespace clang { /// generate the precompiled header. ORIGINAL_FILE_NAME = 19, - /// \brief Record code for the sorted array of source ranges where - /// comments were encountered in the source code. - COMMENT_RANGES = 20, + /// Record #20 intentionally left blank. /// \brief Record code for the version control branch and revision /// information of the compiler used to build this PCH file. VERSION_CONTROL_BRANCH_REVISION = 21, /// \brief Record code for the array of unused static functions. - UNUSED_STATIC_FUNCS = 22 + UNUSED_STATIC_FUNCS = 22, + /// \brief Record code for the table of offsets to macro definition + /// entries in the preprocessing record. + MACRO_DEFINITION_OFFSETS = 23 }; /// \brief Record types used within a source manager block. @@ -245,10 +246,7 @@ namespace clang { SM_SLOC_INSTANTIATION_ENTRY = 4, /// \brief Describes the SourceManager's line table, with /// information about #line directives. - SM_LINE_TABLE = 5, - /// \brief Describes one header file info [isImport, DirInfo, NumIncludes] - /// ControllingMacro is optional. - SM_HEADER_FILE_INFO = 6 + SM_LINE_TABLE = 5 }; /// \brief Record types used within a preprocessor block. @@ -267,7 +265,14 @@ namespace clang { /// \brief Describes one token. /// [PP_TOKEN, SLoc, Length, IdentInfoID, Kind, Flags] - PP_TOKEN = 3 + PP_TOKEN = 3, + + /// \brief Describes a macro instantiation within the preprocessing + /// record. + PP_MACRO_INSTANTIATION = 4, + + /// \brief Describes a macro definition within the preprocessing record. + PP_MACRO_DEFINITION = 5 }; /// \defgroup PCHAST Precompiled header AST constants diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h index 065006f..73c1bf4 100644 --- a/include/clang/Frontend/PCHReader.h +++ b/include/clang/Frontend/PCHReader.h @@ -21,6 +21,7 @@ #include "clang/AST/Type.h" #include "clang/AST/TemplateBase.h" #include "clang/Lex/ExternalPreprocessorSource.h" +#include "clang/Lex/PreprocessingRecord.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceManager.h" @@ -53,6 +54,7 @@ class Decl; class DeclContext; class GotoStmt; class LabelStmt; +class MacroDefinition; class NamedDecl; class Preprocessor; class Sema; @@ -106,7 +108,7 @@ public: } /// \brief Receives a HeaderFileInfo entry. - virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI) {} + virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {} /// \brief Receives __COUNTER__ value. virtual void ReadCounter(unsigned Value) {} @@ -130,8 +132,11 @@ public: FileID PCHBufferID, llvm::StringRef OriginalFileName, std::string &SuggestedPredefines); - virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI); + virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID); virtual void ReadCounter(unsigned Value); + +private: + void Error(const char *Msg); }; /// \brief Reads a precompiled head containing the contents of a @@ -148,13 +153,14 @@ public: /// actually required will be de-serialized. class PCHReader : public ExternalPreprocessorSource, + public ExternalPreprocessingRecordSource, public ExternalSemaSource, public IdentifierInfoLookup, public ExternalIdentifierLookup, public ExternalSLocEntrySource { public: enum PCHReadResult { Success, Failure, IgnorePCH }; - + friend class PCHValidator; private: /// \ brief The receiver of some callbacks invoked by PCHReader. llvm::OwningPtr<PCHReaderListener> Listener; @@ -293,12 +299,17 @@ private: /// been loaded. llvm::SmallVector<Selector, 16> SelectorsLoaded; - /// \brief A sorted array of source ranges containing comments. - SourceRange *Comments; - - /// \brief The number of source ranges in the Comments array. - unsigned NumComments; - + /// \brief Offsets of all of the macro definitions in the preprocessing + /// record in the PCH file. + const uint32_t *MacroDefinitionOffsets; + + /// \brief The macro definitions we have already loaded. + llvm::SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded; + + /// \brief The number of preallocated preprocessing entities in the + /// preprocessing record. + unsigned NumPreallocatedPreprocessingEntities; + /// \brief The set of external definitions stored in the the PCH /// file. llvm::SmallVector<uint64_t, 16> ExternalDefinitions; @@ -472,7 +483,7 @@ private: /// /// This routine should only be used for fatal errors that have to /// do with non-routine failures (e.g., corrupted PCH file). - bool Error(const char *Msg); + void Error(const char *Msg); PCHReader(const PCHReader&); // do not implement PCHReader &operator=(const PCHReader &); // do not implement @@ -524,9 +535,7 @@ public: } /// \brief Set the Preprocessor to use. - void setPreprocessor(Preprocessor &pp) { - PP = &pp; - } + void setPreprocessor(Preprocessor &pp); /// \brief Sets and initializes the given Context. void InitializeContext(ASTContext &Context); @@ -547,14 +556,9 @@ public: /// which contains a (typically-empty) subset of the predefines /// build prior to including the precompiled header. const std::string &getSuggestedPredefines() { return SuggestedPredefines; } - - /// \brief Reads the source ranges that correspond to comments from - /// an external AST source. - /// - /// \param Comments the contents of this vector will be - /// replaced with the sorted set of source ranges corresponding to - /// comments in the source code. - virtual void ReadComments(std::vector<SourceRange> &Comments); + + /// \brief Read preprocessed entities into the + virtual void ReadPreprocessedEntities(); /// \brief Reads a TemplateArgumentLocInfo appropriate for the /// given TemplateArgument kind. @@ -724,6 +728,9 @@ public: /// \brief Read the set of macros defined by this external macro source. virtual void ReadDefinedMacros(); + /// \brief Retrieve the macro definition with the given ID. + MacroDefinition *getMacroDefinition(pch::IdentID ID); + /// \brief Retrieve the AST context that this PCH reader /// supplements. ASTContext *getContext() { return Context; } @@ -790,6 +797,10 @@ private: uint64_t Offset; }; +inline void PCHValidator::Error(const char *Msg) { + Reader.Error(Msg); +} + } // end namespace clang #endif diff --git a/include/clang/Frontend/PCHWriter.h b/include/clang/Frontend/PCHWriter.h index 212130e..e006de5 100644 --- a/include/clang/Frontend/PCHWriter.h +++ b/include/clang/Frontend/PCHWriter.h @@ -33,6 +33,7 @@ namespace clang { class ASTContext; class LabelStmt; +class MacroDefinition; class MemorizeStatCalls; class Preprocessor; class Sema; @@ -160,6 +161,14 @@ private: /// defined. llvm::DenseMap<const IdentifierInfo *, uint64_t> MacroOffsets; + /// \brief Mapping from macro definitions (as they occur in the preprocessing + /// record) to the index into the macro definitions table. + llvm::DenseMap<const MacroDefinition *, pch::IdentID> MacroDefinitions; + + /// \brief Mapping from the macro definition indices in \c MacroDefinitions + /// to the corresponding offsets within the preprocessor block. + std::vector<uint32_t> MacroDefinitionOffsets; + /// \brief Declarations encountered that might be external /// definitions. /// @@ -206,7 +215,6 @@ private: const Preprocessor &PP, const char* isysroot); void WritePreprocessor(const Preprocessor &PP); - void WriteComments(ASTContext &Context); void WriteType(QualType T); uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC); uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC); @@ -234,6 +242,9 @@ public: /// /// \param isysroot if non-NULL, write a relocatable PCH file whose headers /// are relative to the given system root. + /// + /// \param PPRec Record of the preprocessing actions that occurred while + /// preprocessing this file, e.g., macro instantiations void WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls, const char* isysroot); @@ -269,6 +280,10 @@ public: return MacroOffsets[II]; } + /// \brief Retrieve the ID number corresponding to the given macro + /// definition. + pch::IdentID getMacroDefinitionID(MacroDefinition *MD); + /// \brief Emit a reference to a type. void AddTypeRef(QualType T, RecordData &Record); diff --git a/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h index 7ba7c5c..891359b 100644 --- a/include/clang/Frontend/PreprocessorOptions.h +++ b/include/clang/Frontend/PreprocessorOptions.h @@ -36,6 +36,10 @@ public: 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 + /// instantiations. + /// The implicit PCH included at the start of the translation unit, or empty. std::string ImplicitPCHInclude; @@ -77,7 +81,7 @@ public: } public: - PreprocessorOptions() : UsePredefines(true) {} + PreprocessorOptions() : UsePredefines(true), DetailedRecord(false) {} void addMacroDef(llvm::StringRef Name) { Macros.push_back(std::make_pair(Name, false)); diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index 7f43b2a..c1d4831 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -59,7 +59,7 @@ void InitializePreprocessor(Preprocessor &PP, /// ProcessWarningOptions - Initialize the diagnostic client and process the /// warning options specified on the command line. -bool ProcessWarningOptions(Diagnostic &Diags, const DiagnosticOptions &Opts); +void ProcessWarningOptions(Diagnostic &Diags, const DiagnosticOptions &Opts); /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS, diff --git a/include/clang/Frontend/VerifyDiagnosticsClient.h b/include/clang/Frontend/VerifyDiagnosticsClient.h index 6f7ebbe..08adbb0 100644 --- a/include/clang/Frontend/VerifyDiagnosticsClient.h +++ b/include/clang/Frontend/VerifyDiagnosticsClient.h @@ -16,7 +16,6 @@ namespace clang { class Diagnostic; -class SourceMgr; class TextDiagnosticBuffer; /// VerifyDiagnosticsClient - Create a diagnostic client which will use markers |