diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:08 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:08 +0000 |
commit | bab175ec4b075c8076ba14c762900392533f6ee4 (patch) | |
tree | 01f4f29419a2cb10abe13c1e63cd2a66068b0137 /include/clang/Serialization | |
parent | 8b7a8012d223fac5d17d16a66bb39168a9a1dfc0 (diff) |
Notes
Diffstat (limited to 'include/clang/Serialization')
-rw-r--r-- | include/clang/Serialization/ASTBitCodes.h | 65 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 349 | ||||
-rw-r--r-- | include/clang/Serialization/ASTWriter.h | 29 | ||||
-rw-r--r-- | include/clang/Serialization/Module.h | 10 | ||||
-rw-r--r-- | include/clang/Serialization/ModuleManager.h | 2 |
5 files changed, 410 insertions, 45 deletions
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 79c6a06222570..861fe64096af9 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -344,7 +344,7 @@ namespace clang { /// /// The TYPE_OFFSET constant describes the record that occurs /// within the AST block. The record itself is an array of offsets that - /// point into the declarations and types block (identified by + /// point into the declarations and types block (identified by /// DECLTYPES_BLOCK_ID). The index into the array is based on the ID /// of a type. For a given type ID @c T, the lower three bits of /// @c T are its qualifiers (const, volatile, restrict), as in @@ -446,10 +446,10 @@ namespace clang { /// \brief Record code for the set of ext_vector type names. EXT_VECTOR_DECLS = 16, - + /// \brief Record code for the array of unused file scoped decls. UNUSED_FILESCOPED_DECLS = 17, - + /// \brief Record code for the table of offsets to entries in the /// preprocessing record. PPD_ENTITIES_OFFSETS = 18, @@ -465,7 +465,7 @@ namespace clang { /// \brief Record code for an update to the TU's lexically contained /// declarations. TU_UPDATE_LEXICAL = 22, - + // ID 23 used to be for a list of local redeclarations. /// \brief Record code for declarations that Sema keeps references of. @@ -490,7 +490,7 @@ namespace clang { // ID 30 used to be a decl update record. These are now in the DECLTYPES // block. - + // ID 31 used to be a list of offsets to DECL_CXX_BASE_SPECIFIERS records. /// \brief Record code for \#pragma diagnostic mappings. @@ -498,7 +498,7 @@ namespace clang { /// \brief Record code for special CUDA declarations. CUDA_SPECIAL_DECL_REFS = 33, - + /// \brief Record code for header search information. HEADER_SEARCH_TABLE = 34, @@ -516,7 +516,7 @@ namespace clang { KNOWN_NAMESPACES = 38, /// \brief Record code for the remapping information used to relate - /// loaded modules to the various offsets and IDs(e.g., source location + /// loaded modules to the various offsets and IDs(e.g., source location /// offests, declaration and type IDs) that are used in that module to /// refer to other modules. MODULE_OFFSET_MAP = 39, @@ -525,20 +525,20 @@ namespace clang { /// which stores information about \#line directives. SOURCE_MANAGER_LINE_TABLE = 40, - /// \brief Record code for map of Objective-C class definition IDs to the + /// \brief Record code for map of Objective-C class definition IDs to the /// ObjC categories in a module that are attached to that class. OBJC_CATEGORIES_MAP = 41, /// \brief Record code for a file sorted array of DeclIDs in a module. FILE_SORTED_DECLS = 42, - + /// \brief Record code for an array of all of the (sub)modules that were /// imported by the AST file. IMPORTED_MODULES = 43, - + // ID 44 used to be a table of merged canonical declarations. // ID 45 used to be a list of declaration IDs of local redeclarations. - + /// \brief Record code for the array of Objective-C categories (including /// extensions). /// @@ -580,7 +580,17 @@ namespace clang { MSSTRUCT_PRAGMA_OPTIONS = 55, /// \brief Record code for \#pragma ms_struct options. - POINTERS_TO_MEMBERS_PRAGMA_OPTIONS = 56 + POINTERS_TO_MEMBERS_PRAGMA_OPTIONS = 56, + + /// \brief Number of unmatched #pragma clang cuda_force_host_device begin + /// directives we've seen. + CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH = 57, + + /// \brief Record code for types associated with OpenCL extensions. + OPENCL_EXTENSION_TYPES = 58, + + /// \brief Record code for declarations associated with OpenCL extensions. + OPENCL_EXTENSION_DECLS = 59, }; /// \brief Record types used within a source manager block. @@ -684,6 +694,9 @@ namespace clang { /// \brief Specifies a header that is private to this submodule but /// must be textually included. SUBMODULE_PRIVATE_TEXTUAL_HEADER = 15, + /// \brief Specifies some declarations with initializers that must be + /// emitted to initialize the module. + SUBMODULE_INITIALIZERS = 16, }; /// \brief Record types used within a comments block. @@ -899,7 +912,9 @@ namespace clang { /// \brief An AdjustedType record. TYPE_ADJUSTED = 42, /// \brief A PipeType record. - TYPE_PIPE = 43 + TYPE_PIPE = 43, + /// \brief An ObjCTypeParamType record. + TYPE_OBJC_TYPE_PARAM = 44 }; /// \brief The type IDs for special types constructed by semantic @@ -1053,6 +1068,10 @@ namespace clang { DECL_IMPLICIT_PARAM, /// \brief A ParmVarDecl record. DECL_PARM_VAR, + /// \brief A DecompositionDecl record. + DECL_DECOMPOSITION, + /// \brief A BindingDecl record. + DECL_BINDING, /// \brief A FileScopeAsmDecl record. DECL_FILE_SCOPE_ASM, /// \brief A BlockDecl record. @@ -1084,6 +1103,8 @@ namespace clang { DECL_NAMESPACE_ALIAS, /// \brief A UsingDecl record. DECL_USING, + /// \brief A UsingPackDecl record. + DECL_USING_PACK, /// \brief A UsingShadowDecl record. DECL_USING_SHADOW, /// \brief A ConstructorUsingShadowDecl record. @@ -1096,6 +1117,8 @@ namespace clang { DECL_UNRESOLVED_USING_TYPENAME, /// \brief A LinkageSpecDecl record. DECL_LINKAGE_SPEC, + /// \brief An ExportDecl record. + DECL_EXPORT, /// \brief A CXXRecordDecl record. DECL_CXX_RECORD, /// \brief A CXXMethodDecl record. @@ -1277,10 +1300,14 @@ namespace clang { EXPR_DESIGNATED_INIT, /// \brief A DesignatedInitUpdateExpr record. EXPR_DESIGNATED_INIT_UPDATE, - /// \brief An ImplicitValueInitExpr record. - EXPR_IMPLICIT_VALUE_INIT, /// \brief An NoInitExpr record. EXPR_NO_INIT, + /// \brief An ArrayInitLoopExpr record. + EXPR_ARRAY_INIT_LOOP, + /// \brief An ArrayInitIndexExpr record. + EXPR_ARRAY_INIT_INDEX, + /// \brief An ImplicitValueInitExpr record. + EXPR_IMPLICIT_VALUE_INIT, /// \brief A VAArgExpr record. EXPR_VA_ARG, /// \brief An AddrLabelExpr record. @@ -1481,6 +1508,14 @@ namespace clang { STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE, STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE, STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE, + STMT_OMP_TARGET_SIMD_DIRECTIVE, + STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE, + STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE, + STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE, + STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE, + STMT_OMP_TARGET_TEAMS_DIRECTIVE, + STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE, + STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE, EXPR_OMP_ARRAY_SECTION, // ARC diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 18e23870a7653..5230e2ae00131 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -18,10 +18,8 @@ #include "clang/AST/DeclarationName.h" #include "clang/AST/TemplateBase.h" #include "clang/Basic/Diagnostic.h" -#include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" #include "clang/Basic/IdentifierTable.h" -#include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Lex/ExternalPreprocessorSource.h" #include "clang/Lex/HeaderSearch.h" @@ -33,9 +31,6 @@ #include "clang/Serialization/Module.h" #include "clang/Serialization/ModuleFileExtension.h" #include "clang/Serialization/ModuleManager.h" -#include "llvm/ADT/APFloat.h" -#include "llvm/ADT/APInt.h" -#include "llvm/ADT/APSInt.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" @@ -43,22 +38,27 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/TinyPtrVector.h" -#include "llvm/Bitcode/BitstreamReader.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Timer.h" #include <deque> -#include <map> #include <memory> #include <string> #include <utility> #include <vector> namespace llvm { + class BitstreamCursor; class MemoryBuffer; + class APInt; + class APSInt; + class APFloat; } namespace clang { +class SourceManager; +class HeaderSearchOptions; +class FileManager; class AddrLabelExpr; class ASTConsumer; class ASTContext; @@ -89,6 +89,7 @@ class ASTWriter; class ASTReader; class ASTDeclReader; class ASTStmtReader; +class ASTRecordReader; class TypeLocReader; struct HeaderFileInfo; class VersionTuple; @@ -285,6 +286,21 @@ private: void Error(const char *Msg); }; +/// \brief ASTReaderListenter implementation to set SuggestedPredefines of +/// ASTReader which is required to use a pch file. This is the replacement +/// of PCHValidator or SimplePCHValidator when using a pch file without +/// validating it. +class SimpleASTReaderListener : public ASTReaderListener { + Preprocessor &PP; + +public: + SimpleASTReaderListener(Preprocessor &PP) + : PP(PP) {} + + bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, + std::string &SuggestedPredefines) override; +}; + namespace serialization { class ReadMethodPoolVisitor; @@ -342,7 +358,7 @@ public: /// \brief The AST file has errors. HadErrors }; - + /// \brief Types of AST files. friend class PCHValidator; friend class ASTDeclReader; @@ -350,6 +366,7 @@ public: friend class ASTIdentifierIterator; friend class serialization::reader::ASTIdentifierLookupTrait; friend class TypeLocReader; + friend class ASTRecordReader; friend class ASTWriter; friend class ASTUnit; // ASTUnit needs to remap source locations. friend class serialization::ReadMethodPoolVisitor; @@ -758,6 +775,10 @@ private: /// Sema tracks these to emit warnings. SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates; + /// \brief Our current depth in #pragma cuda force_host_device begin/end + /// macros. + unsigned ForceCUDAHostDeviceDepth = 0; + /// \brief The IDs of the declarations Sema stores directly. /// /// Sema tracks a few important decls, such as namespace std, directly. @@ -788,7 +809,13 @@ private: SourceLocation PointersToMembersPragmaLocation; /// \brief The OpenCL extension settings. - SmallVector<uint64_t, 1> OpenCLExtensions; + OpenCLOptions OpenCLExtensions; + + /// \brief Extensions required by an OpenCL type. + llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap; + + /// \brief Extensions required by an OpenCL declaration. + llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap; /// \brief A list of the namespaces we've seen. SmallVector<uint64_t, 4> KnownNamespaces; @@ -803,6 +830,7 @@ private: // \brief A list of late parsed template function data. SmallVector<uint64_t, 1> LateParsedTemplates; +public: struct ImportedSubmodule { serialization::SubmoduleID ID; SourceLocation ImportLoc; @@ -811,6 +839,7 @@ private: : ID(ID), ImportLoc(ImportLoc) {} }; +private: /// \brief A list of modules that were imported by precompiled headers or /// any other non-module AST file. SmallVector<ImportedSubmodule, 2> ImportedModules; @@ -1154,7 +1183,7 @@ private: static ASTReadResult ReadOptionsBlock( llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities, bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, - std::string &SuggestedPredefines); + std::string &SuggestedPredefines, bool ValidateDiagnosticOptions); ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities); ASTReadResult ReadExtensionBlock(ModuleFile &F); bool ParseLineTable(ModuleFile &F, const RecordData &Record); @@ -1386,9 +1415,13 @@ public: /// \param ClientLoadCapabilities The set of client load-failure /// capabilities, represented as a bitset of the enumerators of /// LoadFailureCapabilities. + /// + /// \param Imported optional out-parameter to append the list of modules + /// that were imported by precompiled headers or any other non-module AST file ASTReadResult ReadAST(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, - unsigned ClientLoadCapabilities); + unsigned ClientLoadCapabilities, + SmallVectorImpl<ImportedSubmodule> *Imported = nullptr); /// \brief Make the entities in the given module and any of its (non-explicit) /// submodules visible to name lookup. @@ -1406,6 +1439,10 @@ public: /// \brief Make the names within this set of hidden names visible. void makeNamesVisible(const HiddenNames &Names, Module *Owner); + /// \brief Note that MergedDef is a redefinition of the canonical definition + /// Def, so Def should be visible whenever MergedDef is. + void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef); + /// \brief Take the AST callbacks listener. std::unique_ptr<ASTReaderListener> takeListener() { return std::move(Listener); @@ -1517,7 +1554,8 @@ public: readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions, - ASTReaderListener &Listener); + ASTReaderListener &Listener, + bool ValidateDiagnosticOptions); /// \brief Determine whether the given AST file is acceptable to load into a /// translation unit with the given language and target options. @@ -1854,8 +1892,8 @@ public: SourceLocation> > &Pending) override; void ReadLateParsedTemplates( - llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) - override; + llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> + &LPTMap) override; /// \brief Load a selector from disk, registering its ID if it exists. void LoadSelector(Selector Sel); @@ -1910,7 +1948,7 @@ public: /// number. serialization::SubmoduleID getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID); - + /// \brief Retrieve the submodule that corresponds to a global submodule ID. /// Module *getSubmodule(serialization::SubmoduleID GlobalID); @@ -2154,6 +2192,287 @@ public: bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } }; +/// \brief An object for streaming information from a record. +class ASTRecordReader { + typedef serialization::ModuleFile ModuleFile; + + ASTReader *Reader; + ModuleFile *F; + unsigned Idx = 0; + ASTReader::RecordData Record; + + typedef ASTReader::RecordData RecordData; + typedef ASTReader::RecordDataImpl RecordDataImpl; + +public: + /// Construct an ASTRecordReader that uses the default encoding scheme. + ASTRecordReader(ASTReader &Reader, ModuleFile &F) + : Reader(&Reader), F(&F) {} + + /// \brief Reads a record with id AbbrevID from Cursor, resetting the + /// internal state. + unsigned readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID); + + /// \brief Is this a module file for a module (rather than a PCH or similar). + bool isModule() const { return F->isModule(); } + + /// \brief Retrieve the AST context that this AST reader supplements. + ASTContext &getContext() { return Reader->getContext(); } + + /// \brief The current position in this record. + unsigned getIdx() const { return Idx; } + /// \brief The length of this record. + size_t size() const { return Record.size(); } + + /// \brief An arbitrary index in this record. + const uint64_t &operator[](size_t N) { return Record[N]; } + /// \brief The last element in this record. + const uint64_t &back() const { return Record.back(); } + + /// \brief Returns the current value in this record, and advances to the + /// next value. + const uint64_t &readInt() { return Record[Idx++]; } + /// \brief Returns the current value in this record, without advancing. + const uint64_t &peekInt() { return Record[Idx]; } + + /// \brief Skips the specified number of values. + void skipInts(unsigned N) { Idx += N; } + + /// \brief Retrieve the global submodule ID its local ID number. + serialization::SubmoduleID + getGlobalSubmoduleID(unsigned LocalID) { + return Reader->getGlobalSubmoduleID(*F, LocalID); + } + + /// \brief Retrieve the submodule that corresponds to a global submodule ID. + Module *getSubmodule(serialization::SubmoduleID GlobalID) { + return Reader->getSubmodule(GlobalID); + } + + /// \brief Read the record that describes the lexical contents of a DC. + bool readLexicalDeclContextStorage(uint64_t Offset, DeclContext *DC) { + return Reader->ReadLexicalDeclContextStorage(*F, F->DeclsCursor, Offset, + DC); + } + + /// \brief Read the record that describes the visible contents of a DC. + bool readVisibleDeclContextStorage(uint64_t Offset, + serialization::DeclID ID) { + return Reader->ReadVisibleDeclContextStorage(*F, F->DeclsCursor, Offset, + ID); + } + + void readExceptionSpec(SmallVectorImpl<QualType> &ExceptionStorage, + FunctionProtoType::ExceptionSpecInfo &ESI) { + return Reader->readExceptionSpec(*F, ExceptionStorage, ESI, Record, Idx); + } + + /// \brief Get the global offset corresponding to a local offset. + uint64_t getGlobalBitOffset(uint32_t LocalOffset) { + return Reader->getGlobalBitOffset(*F, LocalOffset); + } + + /// \brief Reads a statement. + Stmt *readStmt() { return Reader->ReadStmt(*F); } + + /// \brief Reads an expression. + Expr *readExpr() { return Reader->ReadExpr(*F); } + + /// \brief Reads a sub-statement operand during statement reading. + Stmt *readSubStmt() { return Reader->ReadSubStmt(); } + + /// \brief Reads a sub-expression operand during statement reading. + Expr *readSubExpr() { return Reader->ReadSubExpr(); } + + /// \brief Reads a TemplateArgumentLocInfo appropriate for the + /// given TemplateArgument kind, advancing Idx. + TemplateArgumentLocInfo + getTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) { + return Reader->GetTemplateArgumentLocInfo(*F, Kind, Record, Idx); + } + + /// \brief Reads a TemplateArgumentLoc, advancing Idx. + TemplateArgumentLoc + readTemplateArgumentLoc() { + return Reader->ReadTemplateArgumentLoc(*F, Record, Idx); + } + + const ASTTemplateArgumentListInfo* + readASTTemplateArgumentListInfo() { + return Reader->ReadASTTemplateArgumentListInfo(*F, Record, Idx); + } + + /// \brief Reads a declarator info from the given record, advancing Idx. + TypeSourceInfo *getTypeSourceInfo() { + return Reader->GetTypeSourceInfo(*F, Record, Idx); + } + + /// \brief Map a local type ID within a given AST file to a global type ID. + serialization::TypeID getGlobalTypeID(unsigned LocalID) const { + return Reader->getGlobalTypeID(*F, LocalID); + } + + /// \brief Read a type from the current position in the record. + QualType readType() { + return Reader->readType(*F, Record, Idx); + } + + /// \brief Reads a declaration ID from the given position in this record. + /// + /// \returns The declaration ID read from the record, adjusted to a global ID. + serialization::DeclID readDeclID() { + return Reader->ReadDeclID(*F, Record, Idx); + } + + /// \brief Reads a declaration from the given position in a record in the + /// given module, advancing Idx. + Decl *readDecl() { + return Reader->ReadDecl(*F, Record, Idx); + } + + /// \brief Reads a declaration from the given position in the record, + /// advancing Idx. + /// + /// \returns The declaration read from this location, casted to the given + /// result type. + template<typename T> + T *readDeclAs() { + return Reader->ReadDeclAs<T>(*F, Record, Idx); + } + + IdentifierInfo *getIdentifierInfo() { + return Reader->GetIdentifierInfo(*F, Record, Idx); + } + + /// \brief Read a selector from the Record, advancing Idx. + Selector readSelector() { + return Reader->ReadSelector(*F, Record, Idx); + } + + /// \brief Read a declaration name, advancing Idx. + DeclarationName readDeclarationName() { + return Reader->ReadDeclarationName(*F, Record, Idx); + } + void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) { + return Reader->ReadDeclarationNameLoc(*F, DNLoc, Name, Record, Idx); + } + void readDeclarationNameInfo(DeclarationNameInfo &NameInfo) { + return Reader->ReadDeclarationNameInfo(*F, NameInfo, Record, Idx); + } + + void readQualifierInfo(QualifierInfo &Info) { + return Reader->ReadQualifierInfo(*F, Info, Record, Idx); + } + + NestedNameSpecifier *readNestedNameSpecifier() { + return Reader->ReadNestedNameSpecifier(*F, Record, Idx); + } + + NestedNameSpecifierLoc readNestedNameSpecifierLoc() { + return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx); + } + + /// \brief Read a template name, advancing Idx. + TemplateName readTemplateName() { + return Reader->ReadTemplateName(*F, Record, Idx); + } + + /// \brief Read a template argument, advancing Idx. + TemplateArgument readTemplateArgument(bool Canonicalize = false) { + return Reader->ReadTemplateArgument(*F, Record, Idx, Canonicalize); + } + + /// \brief Read a template parameter list, advancing Idx. + TemplateParameterList *readTemplateParameterList() { + return Reader->ReadTemplateParameterList(*F, Record, Idx); + } + + /// \brief Read a template argument array, advancing Idx. + void readTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, + bool Canonicalize = false) { + return Reader->ReadTemplateArgumentList(TemplArgs, *F, Record, Idx, + Canonicalize); + } + + /// \brief Read a UnresolvedSet structure, advancing Idx. + void readUnresolvedSet(LazyASTUnresolvedSet &Set) { + return Reader->ReadUnresolvedSet(*F, Set, Record, Idx); + } + + /// \brief Read a C++ base specifier, advancing Idx. + CXXBaseSpecifier readCXXBaseSpecifier() { + return Reader->ReadCXXBaseSpecifier(*F, Record, Idx); + } + + /// \brief Read a CXXCtorInitializer array, advancing Idx. + CXXCtorInitializer **readCXXCtorInitializers() { + return Reader->ReadCXXCtorInitializers(*F, Record, Idx); + } + + CXXTemporary *readCXXTemporary() { + return Reader->ReadCXXTemporary(*F, Record, Idx); + } + + /// \brief Read a source location, advancing Idx. + SourceLocation readSourceLocation() { + return Reader->ReadSourceLocation(*F, Record, Idx); + } + + /// \brief Read a source range, advancing Idx. + SourceRange readSourceRange() { + return Reader->ReadSourceRange(*F, Record, Idx); + } + + /// \brief Read an integral value, advancing Idx. + llvm::APInt readAPInt() { + return Reader->ReadAPInt(Record, Idx); + } + + /// \brief Read a signed integral value, advancing Idx. + llvm::APSInt readAPSInt() { + return Reader->ReadAPSInt(Record, Idx); + } + + /// \brief Read a floating-point value, advancing Idx. + llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem) { + return Reader->ReadAPFloat(Record, Sem,Idx); + } + + /// \brief Read a string, advancing Idx. + std::string readString() { + return Reader->ReadString(Record, Idx); + } + + /// \brief Read a path, advancing Idx. + std::string readPath() { + return Reader->ReadPath(*F, Record, Idx); + } + + /// \brief Read a version tuple, advancing Idx. + VersionTuple readVersionTuple() { + return ASTReader::ReadVersionTuple(Record, Idx); + } + + /// \brief Reads attributes from the current stream position, advancing Idx. + void readAttributes(AttrVec &Attrs) { + return Reader->ReadAttributes(*F, Attrs, Record, Idx); + } + + /// \brief Reads a token out of a record, advancing Idx. + Token readToken() { + return Reader->ReadToken(*F, Record, Idx); + } + + void recordSwitchCaseID(SwitchCase *SC, unsigned ID) { + Reader->RecordSwitchCaseID(SC, ID); + } + + /// \brief Retrieve the switch-case statement with the given ID. + SwitchCase *getSwitchCaseWithID(unsigned ID) { + return Reader->getSwitchCaseWithID(ID); + } +}; + /// \brief Helper class that saves the current stream position and /// then restores it when destroyed. struct SavedStreamPosition { diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index bfdb9f2262b50..1469555ec21e6 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -16,9 +16,8 @@ #include "clang/AST/ASTMutationListener.h" #include "clang/AST/Decl.h" -#include "clang/AST/DeclarationName.h" -#include "clang/Frontend/PCHContainerOperations.h" #include "clang/AST/TemplateBase.h" +#include "clang/Frontend/PCHContainerOperations.h" #include "clang/Sema/SemaConsumer.h" #include "clang/Serialization/ASTBitCodes.h" #include "clang/Serialization/ASTDeserializationListener.h" @@ -26,21 +25,19 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/SetVector.h" -#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Bitcode/BitstreamWriter.h" -#include <map> #include <queue> #include <vector> namespace llvm { class APFloat; class APInt; - class BitstreamWriter; } namespace clang { +class DeclarationName; class ASTContext; class Attr; class NestedNameSpecifier; @@ -376,9 +373,10 @@ private: /// it. llvm::SmallSetVector<const DeclContext *, 16> UpdatedDeclContexts; - /// \brief Keeps track of visible decls that were added in DeclContexts - /// coming from another AST file. - SmallVector<const Decl *, 16> UpdatingVisibleDecls; + /// \brief Keeps track of declarations that we must emit, even though we're + /// not guaranteed to be able to find them by walking the AST starting at the + /// translation unit. + SmallVector<const Decl *, 16> DeclsToEmitEvenIfUnreferenced; /// \brief The set of Objective-C class that have categories we /// should serialize. @@ -461,6 +459,9 @@ private: void WriteDeclContextVisibleUpdate(const DeclContext *DC); void WriteFPPragmaOptions(const FPOptions &Opts); void WriteOpenCLExtensions(Sema &SemaRef); + void WriteOpenCLExtensionTypes(Sema &SemaRef); + void WriteOpenCLExtensionDecls(Sema &SemaRef); + void WriteCUDAPragmas(Sema &SemaRef); void WriteObjCCategories(); void WriteLateParsedTemplates(Sema &SemaRef); void WriteOptimizePragmaOptions(Sema &SemaRef); @@ -670,6 +671,14 @@ private: void CompletedTagDefinition(const TagDecl *D) override; void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override; void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override; + void AddedCXXTemplateSpecialization( + const ClassTemplateDecl *TD, + const ClassTemplateSpecializationDecl *D) override; + void AddedCXXTemplateSpecialization( + const VarTemplateDecl *TD, + const VarTemplateSpecializationDecl *D) override; + void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, + const FunctionDecl *D) override; void ResolvedExceptionSpec(const FunctionDecl *FD) override; void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override; void ResolvedOperatorDelete(const CXXDestructorDecl *DD, @@ -677,6 +686,7 @@ private: void CompletedImplicitDefinition(const FunctionDecl *D) override; void StaticDataMemberInstantiated(const VarDecl *D) override; void DefaultArgumentInstantiated(const ParmVarDecl *D) override; + void DefaultMemberInitializerInstantiated(const FieldDecl *D) override; void FunctionDefinitionInstantiated(const FunctionDecl *D) override; void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, const ObjCInterfaceDecl *IFD) override; @@ -911,7 +921,6 @@ public: class PCHGenerator : public SemaConsumer { const Preprocessor &PP; std::string OutputFile; - clang::Module *Module; std::string isysroot; Sema *SemaPtr; std::shared_ptr<PCHBuffer> Buffer; @@ -927,7 +936,7 @@ protected: public: PCHGenerator( const Preprocessor &PP, StringRef OutputFile, - clang::Module *Module, StringRef isysroot, + StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer, ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions, bool AllowASTWithErrors = false, diff --git a/include/clang/Serialization/Module.h b/include/clang/Serialization/Module.h index aa0392f0ecfb2..58b3149d407e7 100644 --- a/include/clang/Serialization/Module.h +++ b/include/clang/Serialization/Module.h @@ -48,7 +48,8 @@ enum ModuleKind { MK_ExplicitModule, ///< File is an explicitly-loaded module. MK_PCH, ///< File is a PCH file treated as such. MK_Preamble, ///< File is a PCH file treated as the preamble. - MK_MainFile ///< File is a PCH file treated as the actual main file. + MK_MainFile, ///< File is a PCH file treated as the actual main file. + MK_PrebuiltModule ///< File is from a prebuilt module path. }; /// \brief The input file that has been loaded from this AST file, along with @@ -172,8 +173,8 @@ public: /// \brief The global bit offset (or base) of this module uint64_t GlobalBitOffset; - /// \brief The bitstream reader from which we'll read the AST file. - llvm::BitstreamReader StreamFile; + /// \brief The serialized bitstream data for this file. + StringRef Data; /// \brief The main bitstream cursor for the main block. llvm::BitstreamCursor Stream; @@ -447,7 +448,8 @@ public: /// \brief Is this a module file for a module (rather than a PCH or similar). bool isModule() const { - return Kind == MK_ImplicitModule || Kind == MK_ExplicitModule; + return Kind == MK_ImplicitModule || Kind == MK_ExplicitModule || + Kind == MK_PrebuiltModule; } /// \brief Dump debugging output for this module. diff --git a/include/clang/Serialization/ModuleManager.h b/include/clang/Serialization/ModuleManager.h index 08e7d4049e556..1c4d88e979e3a 100644 --- a/include/clang/Serialization/ModuleManager.h +++ b/include/clang/Serialization/ModuleManager.h @@ -175,7 +175,7 @@ public: OutOfDate }; - typedef ASTFileSignature(*ASTFileSignatureReader)(llvm::BitstreamReader &); + typedef ASTFileSignature(*ASTFileSignatureReader)(StringRef); /// \brief Attempts to create a new module and add it to the list of known /// modules. |