diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
commit | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (patch) | |
tree | 02a1ac369cb734d0abfa5000dd86e5b7797e6a74 /include/clang/Serialization | |
parent | c7e70c433efc6953dc3888b9fbf9f3512d7da2b0 (diff) |
Diffstat (limited to 'include/clang/Serialization')
-rw-r--r-- | include/clang/Serialization/ASTBitCodes.h | 14 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 37 | ||||
-rw-r--r-- | include/clang/Serialization/ASTWriter.h | 18 | ||||
-rw-r--r-- | include/clang/Serialization/ContinuousRangeMap.h | 2 | ||||
-rw-r--r-- | include/clang/Serialization/GlobalModuleIndex.h | 17 | ||||
-rw-r--r-- | include/clang/Serialization/PCHContainerOperations.h | 117 | ||||
-rw-r--r-- | include/clang/Serialization/SerializationDiagnostic.h | 15 |
7 files changed, 192 insertions, 28 deletions
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 430fc48379fef..ec752fb7c796e 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -1015,6 +1015,10 @@ namespace serialization { #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ PREDEF_TYPE_##Id##_ID, #include "clang/Basic/OpenCLImageTypes.def" + /// \brief OpenCL extension types with auto numeration +#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ + PREDEF_TYPE_##Id##_ID, +#include "clang/Basic/OpenCLExtensionTypes.def" }; /// The number of predefined type IDs that are reserved for @@ -1516,6 +1520,9 @@ namespace serialization { /// An OMPThreadPrivateDecl record. DECL_OMP_THREADPRIVATE, + /// An OMPRequiresDecl record. + DECL_OMP_REQUIRES, + /// An EmptyDecl record. DECL_EMPTY, @@ -1533,6 +1540,8 @@ namespace serialization { /// An OMPDeclareReductionDecl record. DECL_OMP_DECLARE_REDUCTION, + + DECL_LAST = DECL_OMP_DECLARE_REDUCTION }; /// Record codes for each kind of statement or expression. @@ -1545,7 +1554,7 @@ namespace serialization { enum StmtCode { /// A marker record that indicates that we are at the end /// of an expression. - STMT_STOP = 128, + STMT_STOP = DECL_LAST + 1, /// A NULL expression. STMT_NULL_PTR, @@ -1613,6 +1622,9 @@ namespace serialization { /// A MS-style AsmStmt record. STMT_MSASM, + /// A constant expression context. + EXPR_CONSTANT, + /// A PredefinedExpr record. EXPR_PREDEFINED, diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 0eecb6f5d65ac..f97f545852f48 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -18,6 +18,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OpenMPClause.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" @@ -232,7 +233,7 @@ public: /// If needsImportVisitation returns \c true, this is called for each /// AST file imported by this AST file. - virtual void visitImport(StringRef Filename) {} + virtual void visitImport(StringRef ModuleName, StringRef Filename) {} /// Indicates that a particular module file extension has been read. virtual void readModuleFileExtension( @@ -539,6 +540,11 @@ private: /// declaration that has an exception specification. llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates; + /// Deduced return type updates that have been loaded but not yet propagated + /// across the relevant redeclaration chain. The map key is the canonical + /// declaration and the value is the deduced return type. + llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates; + /// Declarations that have been imported and have typedef names for /// linkage purposes. llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *> @@ -1056,6 +1062,12 @@ private: /// Objective-C protocols. std::deque<InterestingDecl> PotentiallyInterestingDecls; + /// The list of deduced function types that we have not yet read, because + /// they might contain a deduced return type that refers to a local type + /// declared within the function. + SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16> + PendingFunctionTypes; + /// The list of redeclaration chains that still need to be /// reconstructed, and the local offset to the corresponding list /// of redeclarations. @@ -2234,6 +2246,9 @@ public: CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record, unsigned &Idx); + /// Reads one attribute from the current stream position. + Attr *ReadAttr(ModuleFile &M, const RecordData &Record, unsigned &Idx); + /// Reads attributes from the current stream position. void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs); @@ -2619,6 +2634,11 @@ public: return ASTReader::ReadVersionTuple(Record, Idx); } + /// Reads one attribute from the current stream position, advancing Idx. + Attr *readAttr() { + return Reader->ReadAttr(*F, Record, Idx); + } + /// Reads attributes from the current stream position, advancing Idx. void readAttributes(AttrVec &Attrs) { return Reader->ReadAttributes(*this, Attrs); @@ -2658,6 +2678,21 @@ inline void PCHValidator::Error(const char *Msg) { Reader.Error(Msg); } +class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> { + ASTRecordReader &Record; + ASTContext &Context; + +public: + OMPClauseReader(ASTRecordReader &Record) + : Record(Record), Context(Record.getContext()) {} + +#define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *C); +#include "clang/Basic/OpenMPKinds.def" + OMPClause *readClause(); + void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); + void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); +}; + } // namespace clang #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index 7ff5d65bd7d0e..11af30ac8373e 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -19,16 +19,17 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OpenMPClause.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" -#include "clang/Frontend/PCHContainerOperations.h" #include "clang/Sema/SemaConsumer.h" #include "clang/Serialization/ASTBitCodes.h" #include "clang/Serialization/ASTDeserializationListener.h" +#include "clang/Serialization/PCHContainerOperations.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" @@ -955,6 +956,9 @@ public: return Writer->AddVersionTuple(Version, *Record); } + // Emit an attribute. + void AddAttr(const Attr *A); + /// Emit a list of attributes. void AddAttributes(ArrayRef<const Attr*> Attrs); }; @@ -990,6 +994,18 @@ public: bool hasEmittedPCH() const { return Buffer->IsComplete; } }; +class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> { + ASTRecordWriter &Record; + +public: + OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {} +#define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *S); +#include "clang/Basic/OpenMPKinds.def" + void writeClause(OMPClause *C); + void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); + void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); +}; + } // namespace clang #endif // LLVM_CLANG_SERIALIZATION_ASTWRITER_H diff --git a/include/clang/Serialization/ContinuousRangeMap.h b/include/clang/Serialization/ContinuousRangeMap.h index 73bf2ed10f044..ad827e37db2d7 100644 --- a/include/clang/Serialization/ContinuousRangeMap.h +++ b/include/clang/Serialization/ContinuousRangeMap.h @@ -118,7 +118,7 @@ public: Builder &operator=(const Builder&) = delete; ~Builder() { - llvm::sort(Self.Rep.begin(), Self.Rep.end(), Compare()); + llvm::sort(Self.Rep, Compare()); std::unique(Self.Rep.begin(), Self.Rep.end(), [](const_reference A, const_reference B) { // FIXME: we should not allow any duplicate keys, but there are a lot of diff --git a/include/clang/Serialization/GlobalModuleIndex.h b/include/clang/Serialization/GlobalModuleIndex.h index d47fe9517d762..5791fc024a329 100644 --- a/include/clang/Serialization/GlobalModuleIndex.h +++ b/include/clang/Serialization/GlobalModuleIndex.h @@ -42,11 +42,6 @@ namespace serialization { class ModuleFile; } -using llvm::SmallVector; -using llvm::SmallVectorImpl; -using llvm::StringRef; -using serialization::ModuleFile; - /// A global index for a set of module files, providing information about /// the identifiers within those module files. /// @@ -59,6 +54,8 @@ using serialization::ModuleFile; /// imported, and can be queried to determine which modules the current /// translation could or should load to fix a problem. class GlobalModuleIndex { + using ModuleFile = serialization::ModuleFile; + /// Buffer containing the index file, which is lazily accessed so long /// as the global module index is live. std::unique_ptr<llvm::MemoryBuffer> Buffer; @@ -147,7 +144,7 @@ public: /// \returns A pair containing the global module index (if it exists) and /// the error code. static std::pair<GlobalModuleIndex *, ErrorCode> - readIndex(StringRef Path); + readIndex(llvm::StringRef Path); /// Returns an iterator for identifiers stored in the index table. /// @@ -158,12 +155,12 @@ public: /// /// \param ModuleFiles Will be populated with the set of module files that /// have been indexed. - void getKnownModules(SmallVectorImpl<ModuleFile *> &ModuleFiles); + void getKnownModules(llvm::SmallVectorImpl<ModuleFile *> &ModuleFiles); /// Retrieve the set of module files on which the given module file /// directly depends. void getModuleDependencies(ModuleFile *File, - SmallVectorImpl<ModuleFile *> &Dependencies); + llvm::SmallVectorImpl<ModuleFile *> &Dependencies); /// A set of module files in which we found a result. typedef llvm::SmallPtrSet<ModuleFile *, 4> HitSet; @@ -177,7 +174,7 @@ public: /// information about this name. /// /// \returns true if the identifier is known to the index, false otherwise. - bool lookupIdentifier(StringRef Name, HitSet &Hits); + bool lookupIdentifier(llvm::StringRef Name, HitSet &Hits); /// Note that the given module file has been loaded. /// @@ -200,7 +197,7 @@ public: /// which the global index will be written. static ErrorCode writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, - StringRef Path); + llvm::StringRef Path); }; } diff --git a/include/clang/Serialization/PCHContainerOperations.h b/include/clang/Serialization/PCHContainerOperations.h new file mode 100644 index 0000000000000..2a91d9830af3c --- /dev/null +++ b/include/clang/Serialization/PCHContainerOperations.h @@ -0,0 +1,117 @@ +//===--- Serialization/PCHContainerOperations.h - PCH Containers --*- 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_SERIALIZATION_PCHCONTAINEROPERATIONS_H +#define LLVM_CLANG_SERIALIZATION_PCHCONTAINEROPERATIONS_H + +#include "clang/Basic/Module.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/Support/MemoryBuffer.h" +#include <memory> + +namespace llvm { +class raw_pwrite_stream; +} + +namespace clang { + +class ASTConsumer; +class CodeGenOptions; +class DiagnosticsEngine; +class CompilerInstance; + +struct PCHBuffer { + ASTFileSignature Signature; + llvm::SmallVector<char, 0> Data; + bool IsComplete; +}; + +/// This abstract interface provides operations for creating +/// containers for serialized ASTs (precompiled headers and clang +/// modules). +class PCHContainerWriter { +public: + virtual ~PCHContainerWriter() = 0; + virtual llvm::StringRef getFormat() const = 0; + + /// Return an ASTConsumer that can be chained with a + /// PCHGenerator that produces a wrapper file format containing a + /// serialized AST bitstream. + virtual std::unique_ptr<ASTConsumer> + CreatePCHContainerGenerator(CompilerInstance &CI, + const std::string &MainFileName, + const std::string &OutputFileName, + std::unique_ptr<llvm::raw_pwrite_stream> OS, + std::shared_ptr<PCHBuffer> Buffer) const = 0; +}; + +/// This abstract interface provides operations for unwrapping +/// containers for serialized ASTs (precompiled headers and clang +/// modules). +class PCHContainerReader { +public: + virtual ~PCHContainerReader() = 0; + /// Equivalent to the format passed to -fmodule-format= + virtual llvm::StringRef getFormat() const = 0; + + /// Returns the serialized AST inside the PCH container Buffer. + virtual llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const = 0; +}; + +/// Implements write operations for a raw pass-through PCH container. +class RawPCHContainerWriter : public PCHContainerWriter { + llvm::StringRef getFormat() const override { return "raw"; } + + /// Return an ASTConsumer that can be chained with a + /// PCHGenerator that writes the module to a flat file. + std::unique_ptr<ASTConsumer> + CreatePCHContainerGenerator(CompilerInstance &CI, + const std::string &MainFileName, + const std::string &OutputFileName, + std::unique_ptr<llvm::raw_pwrite_stream> OS, + std::shared_ptr<PCHBuffer> Buffer) const override; +}; + +/// Implements read operations for a raw pass-through PCH container. +class RawPCHContainerReader : public PCHContainerReader { + llvm::StringRef getFormat() const override { return "raw"; } + + /// Simply returns the buffer contained in Buffer. + llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override; +}; + +/// A registry of PCHContainerWriter and -Reader objects for different formats. +class PCHContainerOperations { + llvm::StringMap<std::unique_ptr<PCHContainerWriter>> Writers; + llvm::StringMap<std::unique_ptr<PCHContainerReader>> Readers; +public: + /// Automatically registers a RawPCHContainerWriter and + /// RawPCHContainerReader. + PCHContainerOperations(); + void registerWriter(std::unique_ptr<PCHContainerWriter> Writer) { + Writers[Writer->getFormat()] = std::move(Writer); + } + void registerReader(std::unique_ptr<PCHContainerReader> Reader) { + Readers[Reader->getFormat()] = std::move(Reader); + } + const PCHContainerWriter *getWriterOrNull(llvm::StringRef Format) { + return Writers[Format].get(); + } + const PCHContainerReader *getReaderOrNull(llvm::StringRef Format) { + return Readers[Format].get(); + } + const PCHContainerReader &getRawReader() { + return *getReaderOrNull("raw"); + } +}; + +} + +#endif diff --git a/include/clang/Serialization/SerializationDiagnostic.h b/include/clang/Serialization/SerializationDiagnostic.h index d50422aa466c6..2decd1c2f67be 100644 --- a/include/clang/Serialization/SerializationDiagnostic.h +++ b/include/clang/Serialization/SerializationDiagnostic.h @@ -10,19 +10,6 @@ #ifndef LLVM_CLANG_SERIALIZATION_SERIALIZATIONDIAGNOSTIC_H #define LLVM_CLANG_SERIALIZATION_SERIALIZATIONDIAGNOSTIC_H -#include "clang/Basic/Diagnostic.h" - -namespace clang { - namespace diag { - enum { -#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\ - SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) ENUM, -#define SERIALIZATIONSTART -#include "clang/Basic/DiagnosticSerializationKinds.inc" -#undef DIAG - NUM_BUILTIN_SERIALIZATION_DIAGNOSTICS - }; - } // end namespace diag -} // end namespace clang +#include "clang/Basic/DiagnosticSerialization.h" #endif |