diff options
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 151 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 98 |
2 files changed, 213 insertions, 36 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index bb39a436abe..7f48746d830 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1,4 +1,4 @@ -//===-- ASTReader.cpp - AST File Reader ----------------------------------===// +//===-- ASTReader.cpp - AST File Reader -----------------------------------===// // // The LLVM Compiler Infrastructure // @@ -16,39 +16,62 @@ #include "ASTReaderInternals.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTMutationListener.h" +#include "clang/AST/ASTUnresolvedSet.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclGroup.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" -#include "clang/Frontend/PCHContainerOperations.h" -#include "clang/AST/ASTMutationListener.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/RawCommentList.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLocVisitor.h" +#include "clang/AST/UnresolvedSet.h" +#include "clang/Basic/CommentOptions.h" #include "clang/Basic/DiagnosticOptions.h" +#include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/FileSystemOptions.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/ObjCRuntime.h" +#include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/Sanitizers.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManagerInternals.h" +#include "clang/Basic/Specifiers.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "clang/Basic/TokenKinds.h" #include "clang/Basic/Version.h" #include "clang/Basic/VersionTuple.h" -#include "clang/Frontend/Utils.h" +#include "clang/Frontend/PCHContainerOperations.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/MacroInfo.h" +#include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessingRecord.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Sema/Scope.h" #include "clang/Sema/Sema.h" +#include "clang/Sema/Weak.h" #include "clang/Serialization/ASTDeserializationListener.h" #include "clang/Serialization/GlobalModuleIndex.h" #include "clang/Serialization/ModuleManager.h" #include "clang/Serialization/SerializationDiagnostic.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/APSInt.h" #include "llvm/ADT/Hashing.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/Triple.h" #include "llvm/Bitcode/BitstreamReader.h" #include "llvm/Support/Compression.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" @@ -56,16 +79,27 @@ #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> +#include <cassert> +#include <cstdint> #include <cstdio> +#include <cstring> +#include <ctime> #include <iterator> +#include <limits> +#include <map> +#include <memory> +#include <new> +#include <string> #include <system_error> +#include <tuple> +#include <utility> +#include <vector> using namespace clang; using namespace clang::serialization; using namespace clang::serialization::reader; using llvm::BitstreamCursor; - //===----------------------------------------------------------------------===// // ChainedASTReaderListener implementation //===----------------------------------------------------------------------===// @@ -75,14 +109,17 @@ ChainedASTReaderListener::ReadFullVersionInformation(StringRef FullVersion) { return First->ReadFullVersionInformation(FullVersion) || Second->ReadFullVersionInformation(FullVersion); } + void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) { First->ReadModuleName(ModuleName); Second->ReadModuleName(ModuleName); } + void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { First->ReadModuleMapFile(ModuleMapPath); Second->ReadModuleMapFile(ModuleMapPath); } + bool ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, @@ -92,6 +129,7 @@ ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, Second->ReadLanguageOptions(LangOpts, Complain, AllowCompatibleDifferences); } + bool ChainedASTReaderListener::ReadTargetOptions( const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) { @@ -100,11 +138,13 @@ bool ChainedASTReaderListener::ReadTargetOptions( Second->ReadTargetOptions(TargetOpts, Complain, AllowCompatibleDifferences); } + bool ChainedASTReaderListener::ReadDiagnosticOptions( IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { return First->ReadDiagnosticOptions(DiagOpts, Complain) || Second->ReadDiagnosticOptions(DiagOpts, Complain); } + bool ChainedASTReaderListener::ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain) { @@ -120,6 +160,7 @@ bool ChainedASTReaderListener::ReadHeaderSearchOptions( Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, Complain); } + bool ChainedASTReaderListener::ReadPreprocessorOptions( const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) { @@ -145,6 +186,7 @@ void ChainedASTReaderListener::visitModuleFile(StringRef Filename, First->visitModuleFile(Filename, Kind); Second->visitModuleFile(Filename, Kind); } + bool ChainedASTReaderListener::visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, @@ -336,11 +378,13 @@ bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, } namespace { + typedef llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> > MacroDefinitionsMap; typedef llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > DeclsMap; -} + +} // end anonymous namespace static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, @@ -679,13 +723,10 @@ void ASTReader::setDeserializationListener(ASTDeserializationListener *Listener, OwnsDeserializationListener = TakeOwnership; } - - unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { return serialization::ComputeHash(Sel); } - std::pair<unsigned, unsigned> ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { using namespace llvm::support; @@ -1715,6 +1756,7 @@ void ASTReader::ReadDefinedMacros() { } namespace { + /// \brief Visitor class used to look up identifirs in an AST file. class IdentifierLookupVisitor { StringRef Name; @@ -1766,7 +1808,8 @@ namespace { // files. IdentifierInfo *getIdentifierInfo() const { return Found; } }; -} + +} // end anonymous namespace void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { // Note that we are loading an identifier. @@ -1990,7 +2033,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { ErrorStr += "' referenced by AST file '"; ErrorStr += F.FileName; ErrorStr += "'"; - Error(ErrorStr.c_str()); + Error(ErrorStr); } // Record that we didn't find the file. F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); @@ -2107,7 +2150,7 @@ ASTReader::ASTReadResult ASTReader::ReadOptionsBlock( // Read all of the records in the options block. RecordData Record; ASTReadResult Result = Success; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advance(); switch (Entry.Kind) { @@ -2195,7 +2238,7 @@ ASTReader::ReadControlBlock(ModuleFile &F, RecordData Record; unsigned NumInputs = 0; unsigned NumUserInputs = 0; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advance(); switch (Entry.Kind) { @@ -2480,7 +2523,7 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { // Read all of the records and blocks for the AST file. RecordData Record; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advance(); switch (Entry.Kind) { @@ -3467,7 +3510,7 @@ static void updateModuleTimestamp(ModuleFile &MF) { /// cursor into the start of the given block ID, returning false on success and /// true on failure. static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { - while (1) { + while (true) { llvm::BitstreamEntry Entry = Cursor.advance(); switch (Entry.Kind) { case llvm::BitstreamEntry::Error: @@ -3815,7 +3858,7 @@ ASTReader::ReadASTCore(StringRef FileName, // This is used for compatibility with older PCH formats. bool HaveReadControlBlock = false; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advance(); switch (Entry.Kind) { @@ -4105,7 +4148,7 @@ static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile){ // Scan for SIGNATURE inside the control block. ASTReader::RecordData Record; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); if (Entry.Kind == llvm::BitstreamEntry::EndBlock || Entry.Kind != llvm::BitstreamEntry::Record) @@ -4151,7 +4194,7 @@ std::string ASTReader::getOriginalSourceFile( // Scan for ORIGINAL_FILE inside the control block. RecordData Record; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); if (Entry.Kind == llvm::BitstreamEntry::EndBlock) return std::string(); @@ -4169,6 +4212,7 @@ std::string ASTReader::getOriginalSourceFile( } namespace { + class SimplePCHValidator : public ASTReaderListener { const LangOptions &ExistingLangOpts; const TargetOptions &ExistingTargetOpts; @@ -4195,11 +4239,13 @@ namespace { return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, AllowCompatibleDifferences); } + bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) override { return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, AllowCompatibleDifferences); } + bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override { @@ -4207,6 +4253,7 @@ namespace { ExistingModuleCachePath, nullptr, ExistingLangOpts); } + bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) override { @@ -4214,7 +4261,8 @@ namespace { SuggestedPredefines, ExistingLangOpts); } }; -} + +} // end anonymous namespace bool ASTReader::readASTFileControlBlock( StringRef Filename, FileManager &FileMgr, @@ -5040,7 +5088,7 @@ struct PPEntityComp { } }; -} +} // end anonymous namespace PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const { @@ -5130,6 +5178,7 @@ Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, } namespace { + /// \brief Visitor used to search for information about a header file. class HeaderFileInfoVisitor { const FileEntry *FE; @@ -5157,7 +5206,8 @@ namespace { Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } }; -} + +} // end anonymous namespace HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { HeaderFileInfoVisitor Visitor(FE); @@ -5195,7 +5245,7 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { Diag.DiagStatePoints.push_back( DiagnosticsEngine::DiagStatePoint(NewState, FullSourceLoc(Loc, SourceMgr))); - while (1) { + while (true) { assert(Idx < F.PragmaDiagMappings.size() && "Invalid data, didn't find '-1' marking end of diag/map pairs"); if (Idx >= F.PragmaDiagMappings.size()) { @@ -5771,6 +5821,7 @@ public: void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { // nothing to do } + void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); if (TL.needsExtraLocalData()) { @@ -5780,31 +5831,40 @@ void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { TL.setModeAttr(Record[Idx++]); } } + void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { TL.setStarLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { // nothing to do } + void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { // nothing to do } + void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { TL.setCaretLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { TL.setAmpLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { TL.setStarLoc(ReadSourceLocation(Record, Idx)); TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); } + void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); @@ -5813,29 +5873,37 @@ void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { else TL.setSizeExpr(nullptr); } + void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocReader::VisitDependentSizedArrayTypeLoc( DependentSizedArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( DependentSizedExtVectorTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); TL.setLParenLoc(ReadSourceLocation(Record, Idx)); @@ -5845,9 +5913,11 @@ void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { TL.setParam(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); } } + void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { VisitFunctionTypeLoc(TL); } + void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { VisitFunctionTypeLoc(TL); } @@ -5871,21 +5941,26 @@ void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { TL.setKWLoc(ReadSourceLocation(Record, Idx)); TL.setLParenLoc(ReadSourceLocation(Record, Idx)); TL.setRParenLoc(ReadSourceLocation(Record, Idx)); TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); } + void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); if (TL.hasAttrOperand()) { @@ -5902,9 +5977,11 @@ void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { } else if (TL.hasAttrEnumOperand()) TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( SubstTemplateTypeParmTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); @@ -5929,18 +6006,22 @@ void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { TL.setLParenLoc(ReadSourceLocation(Record, Idx)); TL.setRParenLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); } + void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( DependentTemplateSpecializationTypeLoc TL) { TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); @@ -5955,12 +6036,15 @@ void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( TL.getTypePtr()->getArg(I).getKind(), Record, Idx)); } + void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { TL.setHasBaseTypeAsWritten(Record[Idx++]); TL.setTypeArgsLAngleLoc(ReadSourceLocation(Record, Idx)); @@ -5972,14 +6056,17 @@ void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { TL.setStarLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { TL.setKWLoc(ReadSourceLocation(Record, Idx)); TL.setLParenLoc(ReadSourceLocation(Record, Idx)); TL.setRParenLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { TL.setKWLoc(ReadSourceLocation(Record, Idx)); } @@ -6625,7 +6712,7 @@ public: } }; -} +} // end anonymous namespace void ASTReader::FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, @@ -7033,6 +7120,7 @@ IdentifierInfo *ASTReader::get(StringRef Name) { } namespace clang { + /// \brief An identifier-lookup iterator that enumerates all of the /// identifiers stored within a set of AST files. class ASTIdentifierIterator : public IdentifierIterator { @@ -7060,7 +7148,8 @@ namespace clang { StringRef Next() override; }; -} + +} // end namespace clang ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader, bool SkipModules) @@ -7092,6 +7181,7 @@ StringRef ASTIdentifierIterator::Next() { } namespace { + /// A utility for appending two IdentifierIterators. class ChainedIdentifierIterator : public IdentifierIterator { std::unique_ptr<IdentifierIterator> Current; @@ -7116,6 +7206,7 @@ public: return Next(); } }; + } // end anonymous namespace. IdentifierIterator *ASTReader::getIdentifiers() { @@ -7131,7 +7222,9 @@ IdentifierIterator *ASTReader::getIdentifiers() { return new ASTIdentifierIterator(*this); } -namespace clang { namespace serialization { +namespace clang { +namespace serialization { + class ReadMethodPoolVisitor { ASTReader &Reader; Selector Sel; @@ -7201,7 +7294,9 @@ namespace clang { namespace serialization { } bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } }; -} } // end namespace clang::serialization + +} // end namespace serialization +} // end namespace clang /// \brief Add the given set of methods to the method list. static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, @@ -7796,7 +7891,7 @@ void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, Info.NumTemplParamLists = NumTPLists; if (NumTPLists) { Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; - for (unsigned i=0; i != NumTPLists; ++i) + for (unsigned i = 0; i != NumTPLists; ++i) Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); } } @@ -8016,7 +8111,7 @@ ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, } else { SourceOrderOrNumArrayIndices = Record[Idx++]; Indices.reserve(SourceOrderOrNumArrayIndices); - for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) + for (unsigned i = 0; i != SourceOrderOrNumArrayIndices; ++i) Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); } diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 7f9ae8df1cd..be93ca6f4d2 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -16,18 +16,27 @@ #include "ASTReaderInternals.h" #include "MultiOnDiskHashTable.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTUnresolvedSet.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclContextInternals.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclFriend.h" -#include "clang/AST/DeclLookups.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/LambdaCapture.h" +#include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/RawCommentList.h" +#include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLocVisitor.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" -#include "clang/Basic/FileSystemStatCache.h" +#include "clang/Basic/FileSystemOptions.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/Module.h" +#include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManagerInternals.h" #include "clang/Basic/TargetInfo.h" @@ -37,28 +46,48 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/MacroInfo.h" +#include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessingRecord.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" +#include "clang/Lex/Token.h" #include "clang/Sema/IdentifierResolver.h" +#include "clang/Sema/ObjCMethodList.h" #include "clang/Sema/Sema.h" +#include "clang/Sema/Weak.h" #include "clang/Serialization/ASTReader.h" +#include "clang/Serialization/Module.h" #include "clang/Serialization/ModuleFileExtension.h" #include "clang/Serialization/SerializationDiagnostic.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/Hashing.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Bitcode/BitCodes.h" #include "llvm/Bitcode/BitstreamWriter.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Compression.h" #include "llvm/Support/EndianStream.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/OnDiskHashTable.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" +#include "llvm/Support/raw_ostream.h" #include <algorithm> -#include <cstdio> -#include <string.h> +#include <cassert> +#include <cstdint> +#include <cstdlib> +#include <cstring> +#include <deque> +#include <limits> +#include <new> +#include <tuple> #include <utility> using namespace clang; @@ -82,6 +111,7 @@ static StringRef bytes(const SmallVectorImpl<T> &v) { //===----------------------------------------------------------------------===// namespace clang { + class ASTTypeWriter { ASTWriter &Writer; ASTRecordWriter Record; @@ -126,6 +156,7 @@ namespace clang { #define ABSTRACT_TYPE(Class, Base) #include "clang/AST/TypeNodes.def" }; + } // end namespace clang void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { @@ -503,6 +534,7 @@ public: void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { // nothing to do } + void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { Record.AddSourceLocation(TL.getBuiltinLoc()); if (TL.needsExtraLocalData()) { @@ -512,31 +544,40 @@ void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { Record.push_back(TL.hasModeAttr()); } } + void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { Record.AddSourceLocation(TL.getStarLoc()); } + void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { // nothing to do } + void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { // nothing to do } + void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { Record.AddSourceLocation(TL.getCaretLoc()); } + void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { Record.AddSourceLocation(TL.getAmpLoc()); } + void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { Record.AddSourceLocation(TL.getAmpAmpLoc()); } + void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { Record.AddSourceLocation(TL.getStarLoc()); Record.AddTypeSourceInfo(TL.getClassTInfo()); } + void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { Record.AddSourceLocation(TL.getLBracketLoc()); Record.AddSourceLocation(TL.getRBracketLoc()); @@ -544,29 +585,37 @@ void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { if (TL.getSizeExpr()) Record.AddStmt(TL.getSizeExpr()); } + void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocWriter::VisitDependentSizedArrayTypeLoc( DependentSizedArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( DependentSizedExtVectorTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { Record.AddSourceLocation(TL.getLocalRangeBegin()); Record.AddSourceLocation(TL.getLParenLoc()); @@ -592,30 +641,37 @@ void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); } + void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { Record.AddSourceLocation(TL.getTypeofLoc()); Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); } + void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { Record.AddSourceLocation(TL.getKWLoc()); Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); } + void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { Record.AddSourceLocation(TL.getAttrNameLoc()); if (TL.hasAttrOperand()) { @@ -631,17 +687,21 @@ void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { Record.AddSourceLocation(TL.getAttrEnumOperandLoc()); } } + void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( SubstTemplateTypeParmTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( SubstTemplateTypeParmPackTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitTemplateSpecializationTypeLoc( TemplateSpecializationTypeLoc TL) { Record.AddSourceLocation(TL.getTemplateKeywordLoc()); @@ -652,22 +712,27 @@ void TypeLocWriter::VisitTemplateSpecializationTypeLoc( Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), TL.getArgLoc(i).getLocInfo()); } + void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); } + void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); } + void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( DependentTemplateSpecializationTypeLoc TL) { Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); @@ -680,12 +745,15 @@ void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), TL.getArgLoc(I).getLocInfo()); } + void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { Record.AddSourceLocation(TL.getEllipsisLoc()); } + void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { Record.push_back(TL.hasBaseTypeAsWritten()); Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); @@ -697,14 +765,17 @@ void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) Record.AddSourceLocation(TL.getProtocolLoc(i)); } + void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { Record.AddSourceLocation(TL.getStarLoc()); } + void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { Record.AddSourceLocation(TL.getKWLoc()); Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); } + void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { Record.AddSourceLocation(TL.getKWLoc()); } @@ -1212,7 +1283,7 @@ adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { } static ASTFileSignature getSignature() { - while (1) { + while (true) { if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) return S; // Rely on GetRandomNumber to eventually return non-zero... @@ -1534,6 +1605,7 @@ uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP, } namespace { + /// \brief An input file. struct InputFileEntry { const FileEntry *File; @@ -1541,6 +1613,7 @@ namespace { bool IsTransient; bool BufferOverridden; }; + } // end anonymous namespace void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, @@ -1701,6 +1774,7 @@ static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { } namespace { + // Trait used for the on-disk hash table of header search information. class HeaderFileInfoTrait { ASTWriter &Writer; @@ -1809,6 +1883,7 @@ namespace { const char *strings_begin() const { return FrameworkStringData.begin(); } const char *strings_end() const { return FrameworkStringData.end(); } }; + } // end anonymous namespace /// \brief Write the header search block for the list of files that @@ -2869,6 +2944,7 @@ void ASTWriter::WriteComments() { //===----------------------------------------------------------------------===// namespace { + // Trait used for the on-disk hash table used in the method pool. class ASTMethodPoolTrait { ASTWriter &Writer; @@ -2973,6 +3049,7 @@ public: assert(Out.tell() - Start == DataLen && "Data length is wrong"); } }; + } // end anonymous namespace /// \brief Write ObjC data: selectors and the method pool. @@ -3144,6 +3221,7 @@ static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, } namespace { + class ASTIdentifierTableTrait { ASTWriter &Writer; Preprocessor &PP; @@ -3194,6 +3272,7 @@ public: auto MacroOffset = Writer.getMacroDirectivesOffset(II); return isInterestingIdentifier(II, MacroOffset); } + bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { return isInterestingIdentifier(II, 0); } @@ -3287,6 +3366,7 @@ public: } } }; + } // end anonymous namespace /// \brief Write the identifier table into the AST file. @@ -3393,6 +3473,7 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP, //===----------------------------------------------------------------------===// namespace { + // Trait used for the on-disk hash table used in the method pool. class ASTDeclContextNameLookupTrait { ASTWriter &Writer; @@ -3518,6 +3599,7 @@ public: assert(Out.tell() - Start == DataLen && "Data length is wrong"); } }; + } // end anonymous namespace bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, @@ -5184,7 +5266,7 @@ void ASTRecordWriter::AddDeclarationNameInfo( void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { AddNestedNameSpecifierLoc(Info.QualifierLoc); Record->push_back(Info.NumTemplParamLists); - for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) + for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i) AddTemplateParameterList(Info.TemplParamLists[i]); } @@ -5397,7 +5479,7 @@ void ASTRecordWriter::AddTemplateArgumentList( const TemplateArgumentList *TemplateArgs) { assert(TemplateArgs && "No TemplateArgs!"); Record->push_back(TemplateArgs->size()); - for (int i=0, e = TemplateArgs->size(); i != e; ++i) + for (int i = 0, e = TemplateArgs->size(); i != e; ++i) AddTemplateArgument(TemplateArgs->get(i)); } @@ -5408,7 +5490,7 @@ void ASTRecordWriter::AddASTTemplateArgumentListInfo( AddSourceLocation(ASTTemplArgList->RAngleLoc); Record->push_back(ASTTemplArgList->NumTemplateArgs); const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); - for (int i=0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) + for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) AddTemplateArgumentLoc(TemplArgs[i]); } |