From 7b1b2268e2eee9bd125e15081d80eddb99e6833b Mon Sep 17 00:00:00 2001 From: Sebastian Redl Date: Fri, 1 Oct 2010 19:59:15 +0000 Subject: [PATCH] Thread PerFileData through everything. This allows us to remap stuff later. llvm-svn: 115336 --- clang/include/clang/Serialization/ASTReader.h | 88 ++-- clang/lib/Serialization/ASTReader.cpp | 398 +++++++++--------- clang/lib/Serialization/ASTReaderDecl.cpp | 208 ++++----- clang/lib/Serialization/ASTReaderStmt.cpp | 377 +++++++++-------- 4 files changed, 562 insertions(+), 509 deletions(-) diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index b2f08c183f27..e6cc9063b9ad 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -57,12 +57,15 @@ class GotoStmt; class LabelStmt; class MacroDefinition; class NamedDecl; -class ASTDeserializationListener; class Preprocessor; class Sema; class SwitchCase; +class ASTDeserializationListener; class ASTReader; class ASTDeclReader; +class ASTStmtReader; +class ASTIdentifierLookupTrait; +class TypeLocReader; struct HeaderFileInfo; struct PCHPredefinesBlock { @@ -169,6 +172,9 @@ public: enum ASTReadResult { Success, Failure, IgnorePCH }; friend class PCHValidator; friend class ASTDeclReader; + friend class ASTStmtReader; + friend class ASTIdentifierLookupTrait; + friend class TypeLocReader; private: /// \brief The receiver of some callbacks invoked by ASTReader. llvm::OwningPtr Listener; @@ -289,6 +295,10 @@ private: /// instance and factory methods. void *SelectorLookupTable; + /// \brief Method selectors used in a @selector expression. Used for + /// implementation of -Wselector. + llvm::SmallVector ReferencedSelectorsData; + // === Declarations === /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It @@ -303,6 +313,14 @@ private: /// by the declaration ID (-1). const uint32_t *DeclOffsets; + /// \brief A snapshot of the pending instantiations in the chain. + /// + /// This record tracks the instantiations that Sema has to perform at the + /// end of the TU. It consists of a pair of values for every pending + /// instantiation where the first value is the ID of the decl and the second + /// is the instantiation location. + llvm::SmallVector PendingInstantiations; + // === Types === /// \brief The number of types in this AST file. @@ -474,10 +492,6 @@ private: /// \brief Fields containing data that is used for generating diagnostics //@{ - /// \brief Method selectors used in a @selector expression. Used for - /// implementation of -Wselector. - llvm::SmallVector ReferencedSelectorsData; - /// \brief A snapshot of Sema's unused file-scoped variable tracking, for /// generating warnings. llvm::SmallVector UnusedFileScopedDecls; @@ -503,14 +517,6 @@ private: /// local external declarations. llvm::SmallVector LocallyScopedExternalDecls; - /// \brief A snapshot of the pwnsinf instantiations in the chain. - /// - /// This record tracks the instantiations that Sema has to perform at the end - /// of the TU. It consists of a pair of values for every pending instantiation - /// where the first value is the ID of the decl and the second is the - /// instantiation location. - llvm::SmallVector PendingInstantiations; - /// \brief The IDs of all dynamic class declarations in the chain. /// /// Sema tracks these because it checks for the key functions being defined @@ -685,20 +691,26 @@ private: std::string SuggestedPredefines; /// \brief Reads a statement from the specified cursor. - Stmt *ReadStmtFromStream(llvm::BitstreamCursor &Cursor); + Stmt *ReadStmtFromStream(PerFileData &F); void MaybeAddSystemRootToFilename(std::string &Filename); ASTReadResult ReadASTCore(llvm::StringRef FileName); ASTReadResult ReadASTBlock(PerFileData &F); bool CheckPredefinesBuffers(); - bool ParseLineTable(llvm::SmallVectorImpl &Record); + bool ParseLineTable(PerFileData &F, llvm::SmallVectorImpl &Record); ASTReadResult ReadSourceManagerBlock(PerFileData &F); ASTReadResult ReadSLocEntryRecord(unsigned ID); - llvm::BitstreamCursor &SLocCursorForID(unsigned ID); + PerFileData *SLocCursorForID(unsigned ID); + SourceLocation getImportLocation(PerFileData *F); bool ParseLanguageOptions(const llvm::SmallVectorImpl &Record); - typedef std::pair RecordLocation; + struct RecordLocation { + RecordLocation(PerFileData *M, uint64_t O) + : F(M), Offset(O) {} + PerFileData *F; + uint64_t Offset; + }; QualType ReadTypeRecord(unsigned Index); RecordLocation TypeCursorForIndex(unsigned Index); @@ -832,17 +844,16 @@ public: /// \brief Reads a TemplateArgumentLocInfo appropriate for the /// given TemplateArgument kind. TemplateArgumentLocInfo - GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, - llvm::BitstreamCursor &DeclsCursor, + GetTemplateArgumentLocInfo(PerFileData &F, TemplateArgument::ArgKind Kind, const RecordData &Record, unsigned &Idx); /// \brief Reads a TemplateArgumentLoc. TemplateArgumentLoc - ReadTemplateArgumentLoc(llvm::BitstreamCursor &DeclsCursor, + ReadTemplateArgumentLoc(PerFileData &F, const RecordData &Record, unsigned &Idx); /// \brief Reads a declarator info from the given record. - TypeSourceInfo *GetTypeSourceInfo(llvm::BitstreamCursor &DeclsCursor, + TypeSourceInfo *GetTypeSourceInfo(PerFileData &F, const RecordData &Record, unsigned &Idx); /// \brief Resolve and return the translation unit declaration. @@ -996,39 +1007,48 @@ public: TemplateName ReadTemplateName(const RecordData &Record, unsigned &Idx); /// \brief Read a template argument. - TemplateArgument ReadTemplateArgument(llvm::BitstreamCursor &DeclsCursor, + TemplateArgument ReadTemplateArgument(PerFileData &F, const RecordData &Record,unsigned &Idx); /// \brief Read a template parameter list. - TemplateParameterList *ReadTemplateParameterList(const RecordData &Record, + TemplateParameterList *ReadTemplateParameterList(PerFileData &F, + const RecordData &Record, unsigned &Idx); /// \brief Read a template argument array. void ReadTemplateArgumentList(llvm::SmallVector &TemplArgs, - llvm::BitstreamCursor &DeclsCursor, - const RecordData &Record, unsigned &Idx); + PerFileData &F, const RecordData &Record, + unsigned &Idx); /// \brief Read a UnresolvedSet structure. void ReadUnresolvedSet(UnresolvedSetImpl &Set, const RecordData &Record, unsigned &Idx); /// \brief Read a C++ base specifier. - CXXBaseSpecifier ReadCXXBaseSpecifier(llvm::BitstreamCursor &DeclsCursor, + CXXBaseSpecifier ReadCXXBaseSpecifier(PerFileData &F, const RecordData &Record,unsigned &Idx); /// \brief Read a CXXBaseOrMemberInitializer array. std::pair - ReadCXXBaseOrMemberInitializers(llvm::BitstreamCursor &DeclsCursor, + ReadCXXBaseOrMemberInitializers(PerFileData &F, const RecordData &Record, unsigned &Idx); + /// \brief Read a source location from raw form. + SourceLocation ReadSourceLocation(PerFileData &Module, unsigned Raw) { + (void)Module; // No remapping yet + return SourceLocation::getFromRawEncoding(Raw); + } + /// \brief Read a source location. - SourceLocation ReadSourceLocation(const RecordData &Record, unsigned& Idx) { - return SourceLocation::getFromRawEncoding(Record[Idx++]); + SourceLocation ReadSourceLocation(PerFileData &Module, + const RecordData &Record, unsigned& Idx) { + return ReadSourceLocation(Module, Record[Idx++]); } /// \brief Read a source range. - SourceRange ReadSourceRange(const RecordData &Record, unsigned& Idx); + SourceRange ReadSourceRange(PerFileData &F, + const RecordData &Record, unsigned& Idx); /// \brief Read an integral value llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); @@ -1045,13 +1065,13 @@ public: CXXTemporary *ReadCXXTemporary(const RecordData &Record, unsigned &Idx); /// \brief Reads attributes from the current stream position. - void ReadAttributes(llvm::BitstreamCursor &DeclsCursor, AttrVec &Attrs); + void ReadAttributes(PerFileData &F, AttrVec &Attrs); /// \brief Reads a statement. - Stmt *ReadStmt(llvm::BitstreamCursor &Cursor); + Stmt *ReadStmt(PerFileData &F); /// \brief Reads an expression. - Expr *ReadExpr(llvm::BitstreamCursor &Cursor); + Expr *ReadExpr(PerFileData &F); /// \brief Reads a sub-statement operand during statement reading. Stmt *ReadSubStmt() { @@ -1067,7 +1087,7 @@ public: Expr *ReadSubExpr(); /// \brief Reads the macro record located at the given offset. - void ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset); + void ReadMacroRecord(PerFileData &F, uint64_t Offset); /// \brief Read the set of macros defined by this external macro source. virtual void ReadDefinedMacros(); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index adb233ac144a..63e27d294c36 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -567,10 +567,10 @@ public: typedef OnDiskChainedHashTable ASTSelectorLookupTable; -namespace { +namespace clang { class ASTIdentifierLookupTrait { ASTReader &Reader; - llvm::BitstreamCursor &Stream; + ASTReader::PerFileData &F; // If we know the IdentifierInfo in advance, it is here and we will // not build a new one. Used when deserializing information about an @@ -584,9 +584,9 @@ public: typedef external_key_type internal_key_type; - ASTIdentifierLookupTrait(ASTReader &Reader, llvm::BitstreamCursor &Stream, + ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, IdentifierInfo *II = 0) - : Reader(Reader), Stream(Stream), KnownII(II) { } + : Reader(Reader), F(F), KnownII(II) { } static bool EqualKey(const internal_key_type& a, const internal_key_type& b) { @@ -678,7 +678,7 @@ public: // definition. if (hasMacroDefinition) { uint32_t Offset = ReadUnalignedLE32(d); - Reader.ReadMacroRecord(Stream, Offset); + Reader.ReadMacroRecord(F, Offset); DataLen -= 4; } @@ -952,8 +952,9 @@ bool ASTReader::CheckPredefinesBuffers() { //===----------------------------------------------------------------------===// /// \brief Read the line table in the source manager block. -/// \returns true if ther was an error. -bool ASTReader::ParseLineTable(llvm::SmallVectorImpl &Record) { +/// \returns true if there was an error. +bool ASTReader::ParseLineTable(PerFileData &F, + llvm::SmallVectorImpl &Record) { unsigned Idx = 0; LineTableInfo &LineTable = SourceMgr.getLineTable(); @@ -1163,7 +1164,7 @@ ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { break; case SM_LINE_TABLE: - if (ParseLineTable(Record)) + if (ParseLineTable(F, Record)) return Failure; break; @@ -1178,7 +1179,7 @@ ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { /// \brief Get a cursor that's correctly positioned for reading the source /// location entry with the given ID. -llvm::BitstreamCursor &ASTReader::SLocCursorForID(unsigned ID) { +ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { assert(ID != 0 && ID <= TotalNumSLocEntries && "SLocCursorForID should only be called for real IDs."); @@ -1193,7 +1194,7 @@ llvm::BitstreamCursor &ASTReader::SLocCursorForID(unsigned ID) { assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); - return F->SLocEntryCursor; + return F; } /// \brief Read in the source location entry with the given ID. @@ -1206,7 +1207,8 @@ ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { return Failure; } - llvm::BitstreamCursor &SLocEntryCursor = SLocCursorForID(ID); + PerFileData *F = SLocCursorForID(ID); + llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; ++NumSLocEntriesRead; unsigned Code = SLocEntryCursor.ReadCode(); @@ -1257,7 +1259,7 @@ ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { } FileID FID = SourceMgr.createFileID(File, - SourceLocation::getFromRawEncoding(Record[1]), + ReadSourceLocation(*F, Record[1]), (SrcMgr::CharacteristicKind)Record[2], ID, Record[0]); if (Record[3]) @@ -1305,11 +1307,10 @@ ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { } case SM_SLOC_INSTANTIATION_ENTRY: { - SourceLocation SpellingLoc - = SourceLocation::getFromRawEncoding(Record[1]); + SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); SourceMgr.createInstantiationLoc(SpellingLoc, - SourceLocation::getFromRawEncoding(Record[2]), - SourceLocation::getFromRawEncoding(Record[3]), + ReadSourceLocation(*F, Record[2]), + ReadSourceLocation(*F, Record[3]), Record[4], ID, Record[0]); @@ -1340,8 +1341,9 @@ bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, } } -void ASTReader::ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset){ +void ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { assert(PP && "Forgot to set Preprocessor ?"); + llvm::BitstreamCursor &Stream = F.Stream; // Keep track of where we are in the stream, then jump back there // after reading this macro. @@ -1391,7 +1393,7 @@ void ASTReader::ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset){ Error("macro must have a name in AST file"); return; } - SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[1]); + SourceLocation Loc = ReadSourceLocation(F, Record[1]); bool isUsed = Record[2]; MacroInfo *MI = PP->AllocateMacroInfo(Loc); @@ -1441,7 +1443,7 @@ void ASTReader::ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset){ Token Tok; Tok.startToken(); - Tok.setLocation(SourceLocation::getFromRawEncoding(Record[0])); + Tok.setLocation(ReadSourceLocation(F, Record[0])); Tok.setLength(Record[1]); if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) Tok.setIdentifierInfo(II); @@ -1469,9 +1471,8 @@ void ASTReader::ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset){ MacroInstantiation *MI = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), - SourceRange( - SourceLocation::getFromRawEncoding(Record[1]), - SourceLocation::getFromRawEncoding(Record[2])), + SourceRange(ReadSourceLocation(F, Record[1]), + ReadSourceLocation(F, Record[2])), getMacroDefinition(Record[4])); PPRec.SetPreallocatedEntity(Record[0], MI); return; @@ -1500,10 +1501,9 @@ void ASTReader::ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset){ MacroDefinition *MD = new (PPRec) MacroDefinition(DecodeIdentifierInfo(Record[4]), - SourceLocation::getFromRawEncoding(Record[5]), - SourceRange( - SourceLocation::getFromRawEncoding(Record[2]), - SourceLocation::getFromRawEncoding(Record[3]))); + ReadSourceLocation(F, Record[5]), + SourceRange(ReadSourceLocation(F, Record[2]), + ReadSourceLocation(F, Record[3]))); PPRec.SetPreallocatedEntity(Record[0], MD); MacroDefinitionsLoaded[Record[1]] = MD; return; @@ -1514,7 +1514,8 @@ void ASTReader::ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset){ void ASTReader::ReadDefinedMacros() { for (unsigned I = 0, N = Chain.size(); I != N; ++I) { - llvm::BitstreamCursor &MacroCursor = Chain[N - I - 1]->MacroCursor; + PerFileData &F = *Chain[N - I - 1]; + llvm::BitstreamCursor &MacroCursor = F.MacroCursor; // If there was no preprocessor block, skip this file. if (!MacroCursor.getBitStreamReader()) @@ -1574,7 +1575,7 @@ void ASTReader::ReadDefinedMacros() { case PP_MACRO_DEFINITION: // Read the macro record. // FIXME: That's a stupid way to do this. We should reuse this cursor. - ReadMacroRecord(Chain[N - I - 1]->Stream, Offset); + ReadMacroRecord(F, Offset); break; } } @@ -1590,7 +1591,7 @@ MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { for (unsigned I = 0, N = Chain.size(); I != N; ++I) { PerFileData &F = *Chain[N - I - 1]; if (Index < F.LocalNumMacroDefinitions) { - ReadMacroRecord(F.Stream, F.MacroDefinitionOffsets[Index]); + ReadMacroRecord(F, F.MacroDefinitionOffsets[Index]); break; } Index -= F.LocalNumMacroDefinitions; @@ -1703,7 +1704,7 @@ ASTReader::ReadASTBlock(PerFileData &F) { const char *BlobStart = 0; unsigned BlobLen = 0; switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, - &BlobStart, &BlobLen)) { + &BlobStart, &BlobLen)) { default: // Default behavior: ignore. break; @@ -1813,7 +1814,7 @@ ASTReader::ReadASTBlock(PerFileData &F) { = ASTIdentifierLookupTable::Create( (const unsigned char *)F.IdentifierTableData + Record[0], (const unsigned char *)F.IdentifierTableData, - ASTIdentifierLookupTrait(*this, F.Stream)); + ASTIdentifierLookupTrait(*this, F)); if (PP) PP->getIdentifierTable().setExternalIdentifierLookup(this); } @@ -1901,11 +1902,7 @@ ASTReader::ReadASTBlock(PerFileData &F) { break; case REFERENCED_SELECTOR_POOL: - if (ReferencedSelectorsData.empty()) - ReferencedSelectorsData.swap(Record); - else - ReferencedSelectorsData.insert(ReferencedSelectorsData.end(), - Record.begin(), Record.end()); + F.ReferencedSelectorsData.swap(Record); break; case PP_COUNTER_VALUE: @@ -1961,12 +1958,7 @@ ASTReader::ReadASTBlock(PerFileData &F) { break; case PENDING_IMPLICIT_INSTANTIATIONS: - // Optimization for the first block. - if (PendingInstantiations.empty()) - PendingInstantiations.swap(Record); - else - PendingInstantiations.insert(PendingInstantiations.end(), - Record.begin(), Record.end()); + F.PendingInstantiations.swap(Record); break; case SEMA_DECL_REFS: @@ -2102,7 +2094,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName) { for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { IdentifierInfo *II = Identifiers[I]; // Look in the on-disk hash tables for an entry for this identifier - ASTIdentifierLookupTrait Info(*this, Chain[J]->Stream, II); + ASTIdentifierLookupTrait Info(*this, *Chain[J], II); std::pair Key(II->getNameStart(),II->getLength()); ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); if (Pos == IdTable->end()) @@ -2508,7 +2500,7 @@ ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { Index -= F->LocalNumTypes; } assert(F && F->LocalNumTypes > Index && "Broken chain"); - return RecordLocation(&F->DeclsCursor, F->TypeOffsets[Index]); + return RecordLocation(F, F->TypeOffsets[Index]); } /// \brief Read and return the type with the given index.. @@ -2519,7 +2511,7 @@ ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { /// IDs. QualType ASTReader::ReadTypeRecord(unsigned Index) { RecordLocation Loc = TypeCursorForIndex(Index); - llvm::BitstreamCursor &DeclsCursor = *Loc.first; + llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; // Keep track of where we are in the stream, then jump back there // after reading this type. @@ -2530,7 +2522,7 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { // Note that we are loading a type record. Deserializing AType(this); - DeclsCursor.JumpToBit(Loc.second); + DeclsCursor.JumpToBit(Loc.Offset); RecordData Record; unsigned Code = DeclsCursor.ReadCode(); switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { @@ -2620,9 +2612,9 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { QualType ElementType = GetType(Record[0]); ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; unsigned IndexTypeQuals = Record[2]; - SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]); - SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]); - return Context->getVariableArrayType(ElementType, ReadExpr(DeclsCursor), + SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); + SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); + return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), ASM, IndexTypeQuals, SourceRange(LBLoc, RBLoc)); } @@ -2702,7 +2694,7 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { } case TYPE_TYPEOF_EXPR: - return Context->getTypeOfExprType(ReadExpr(DeclsCursor)); + return Context->getTypeOfExprType(ReadExpr(*Loc.F)); case TYPE_TYPEOF: { if (Record.size() != 1) { @@ -2714,7 +2706,7 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { } case TYPE_DECLTYPE: - return Context->getDecltypeType(ReadExpr(DeclsCursor)); + return Context->getDecltypeType(ReadExpr(*Loc.F)); case TYPE_RECORD: { if (Record.size() != 2) { @@ -2813,7 +2805,7 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { llvm::SmallVector Args; Args.reserve(NumArgs); while (NumArgs--) - Args.push_back(ReadTemplateArgument(DeclsCursor, Record, Idx)); + Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, Args.size(), Args.data()); } @@ -2828,8 +2820,8 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { unsigned IndexTypeQuals = Record[Idx++]; // DependentSizedArrayType - Expr *NumElts = ReadExpr(DeclsCursor); - SourceRange Brackets = ReadSourceRange(Record, Idx); + Expr *NumElts = ReadExpr(*Loc.F); + SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, IndexTypeQuals, Brackets); @@ -2840,7 +2832,7 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { bool IsDependent = Record[Idx++]; TemplateName Name = ReadTemplateName(Record, Idx); llvm::SmallVector Args; - ReadTemplateArgumentList(Args, DeclsCursor, Record, Idx); + ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); QualType Canon = GetType(Record[Idx++]); QualType T; if (Canon.isNull()) @@ -2857,18 +2849,23 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { return QualType(); } -namespace { - -class TypeLocReader : public TypeLocVisitor { +class clang::TypeLocReader : public TypeLocVisitor { ASTReader &Reader; + ASTReader::PerFileData &F; llvm::BitstreamCursor &DeclsCursor; const ASTReader::RecordData &Record; unsigned &Idx; + SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, + unsigned &I) { + return Reader.ReadSourceLocation(F, R, I); + } + public: - TypeLocReader(ASTReader &Reader, llvm::BitstreamCursor &Cursor, + TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, const ASTReader::RecordData &Record, unsigned &Idx) - : Reader(Reader), DeclsCursor(Cursor), Record(Record), Idx(Idx) { } + : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) + { } // We want compile-time assurance that we've enumerated all of // these, so unfortunately we have to declare them first, then @@ -2882,13 +2879,11 @@ public: void VisitArrayTypeLoc(ArrayTypeLoc); }; -} - void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { // nothing to do } void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { - TL.setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); if (TL.needsExtraLocalData()) { TL.setWrittenTypeSpec(static_cast(Record[Idx++])); TL.setWrittenSignSpec(static_cast(Record[Idx++])); @@ -2897,28 +2892,28 @@ void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { } } void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { - TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setStarLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { - TL.setCaretLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setCaretLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { - TL.setAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setAmpLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { - TL.setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { - TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setStarLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { - TL.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); + TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); if (Record[Idx++]) - TL.setSizeExpr(Reader.ReadExpr(DeclsCursor)); + TL.setSizeExpr(Reader.ReadExpr(F)); else TL.setSizeExpr(0); } @@ -2937,17 +2932,17 @@ void TypeLocReader::VisitDependentSizedArrayTypeLoc( } void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( DependentSizedExtVectorTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { - TL.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setLParenLoc(ReadSourceLocation(Record, Idx)); + TL.setRParenLoc(ReadSourceLocation(Record, Idx)); TL.setTrailingReturn(Record[Idx++]); for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { TL.setArg(i, cast_or_null(Reader.GetDecl(Record[Idx++]))); @@ -2960,87 +2955,89 @@ void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { VisitFunctionTypeLoc(TL); } void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { - TL.setTypeofLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); + TL.setLParenLoc(ReadSourceLocation(Record, Idx)); + TL.setRParenLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { - TL.setTypeofLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); + TL.setLParenLoc(ReadSourceLocation(Record, Idx)); + TL.setRParenLoc(ReadSourceLocation(Record, Idx)); + TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); } void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( SubstTemplateTypeParmTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitTemplateSpecializationTypeLoc( TemplateSpecializationTypeLoc TL) { - TL.setTemplateNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); + TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); + TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) TL.setArgLocInfo(i, - Reader.GetTemplateArgumentLocInfo(TL.getTypePtr()->getArg(i).getKind(), - DeclsCursor, Record, Idx)); + Reader.GetTemplateArgumentLocInfo(F, + TL.getTypePtr()->getArg(i).getKind(), + Record, Idx)); } void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { - TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setQualifierRange(Reader.ReadSourceRange(Record, Idx)); + TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); + TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); } void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { - TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setQualifierRange(Reader.ReadSourceRange(Record, Idx)); - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); + TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( DependentTemplateSpecializationTypeLoc TL) { - TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setQualifierRange(Reader.ReadSourceRange(Record, Idx)); - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); + TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); + TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); + TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) TL.setArgLocInfo(I, - Reader.GetTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(), - DeclsCursor, Record, Idx)); + Reader.GetTemplateArgumentLocInfo(F, + TL.getTypePtr()->getArg(I).getKind(), + Record, Idx)); } void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { - TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setNameLoc(ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { TL.setHasBaseTypeAsWritten(Record[Idx++]); - TL.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TL.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); + TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) - TL.setProtocolLoc(i, SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); } void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { - TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TL.setStarLoc(ReadSourceLocation(Record, Idx)); } -TypeSourceInfo *ASTReader::GetTypeSourceInfo(llvm::BitstreamCursor &DeclsCursor, +TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, const RecordData &Record, unsigned &Idx) { QualType InfoTy = GetType(Record[Idx++]); @@ -3048,7 +3045,7 @@ TypeSourceInfo *ASTReader::GetTypeSourceInfo(llvm::BitstreamCursor &DeclsCursor, return 0; TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); - TypeLocReader TLR(*this, DeclsCursor, Record, Idx); + TypeLocReader TLR(*this, F, Record, Idx); for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) TLR.Visit(TL); return TInfo; @@ -3137,18 +3134,18 @@ TypeIdx ASTReader::GetTypeIdx(QualType T) const { } TemplateArgumentLocInfo -ASTReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, - llvm::BitstreamCursor &DeclsCursor, +ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, + TemplateArgument::ArgKind Kind, const RecordData &Record, unsigned &Index) { switch (Kind) { case TemplateArgument::Expression: - return ReadExpr(DeclsCursor); + return ReadExpr(F); case TemplateArgument::Type: - return GetTypeSourceInfo(DeclsCursor, Record, Index); + return GetTypeSourceInfo(F, Record, Index); case TemplateArgument::Template: { - SourceRange QualifierRange = ReadSourceRange(Record, Index); - SourceLocation TemplateNameLoc = ReadSourceLocation(Record, Index); + SourceRange QualifierRange = ReadSourceRange(F, Record, Index); + SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc); } case TemplateArgument::Null: @@ -3162,16 +3159,15 @@ ASTReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, } TemplateArgumentLoc -ASTReader::ReadTemplateArgumentLoc(llvm::BitstreamCursor &DeclsCursor, +ASTReader::ReadTemplateArgumentLoc(PerFileData &F, const RecordData &Record, unsigned &Index) { - TemplateArgument Arg = ReadTemplateArgument(DeclsCursor, Record, Index); + TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); if (Arg.getKind() == TemplateArgument::Expression) { if (Record[Index++]) // bool InfoHasSameExpr. return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); } - return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(Arg.getKind(), - DeclsCursor, + return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), Record, Index)); } @@ -3221,7 +3217,7 @@ Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { // Since we know that this statement is part of a decl, make sure to use // the decl cursor to read it. F.DeclsCursor.JumpToBit(Offset); - return ReadStmtFromStream(F.DeclsCursor); + return ReadStmtFromStream(F); } Offset -= F.SizeInBits; } @@ -3443,21 +3439,6 @@ void ASTReader::InitializeSema(Sema &S) { SemaObj->UnusedFileScopedDecls.push_back(D); } - // If there were any weak undeclared identifiers, deserialize them and add to - // Sema's list of weak undeclared identifiers. - if (!WeakUndeclaredIdentifiers.empty()) { - unsigned Idx = 0; - for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { - IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); - IdentifierInfo *AliasId=GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); - SourceLocation Loc = ReadSourceLocation(WeakUndeclaredIdentifiers, Idx); - bool Used = WeakUndeclaredIdentifiers[Idx++]; - Sema::WeakInfo WI(AliasId, Loc); - WI.setUsed(Used); - SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); - } - } - // If there were any locally-scoped external declarations, // deserialize them and add them to Sema's table of locally-scoped // external declarations. @@ -3475,34 +3456,12 @@ void ASTReader::InitializeSema(Sema &S) { // FIXME: Do VTable uses and dynamic classes deserialize too much ? // Can we cut them down before writing them ? - // If there were any VTable uses, deserialize the information and add it - // to Sema's vector and map of VTable uses. - if (!VTableUses.empty()) { - unsigned Idx = 0; - for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { - CXXRecordDecl *Class = cast(GetDecl(VTableUses[Idx++])); - SourceLocation Loc = ReadSourceLocation(VTableUses, Idx); - bool DefinitionRequired = VTableUses[Idx++]; - SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); - SemaObj->VTablesUsed[Class] = DefinitionRequired; - } - } - // If there were any dynamic classes declarations, deserialize them // and add them to Sema's vector of such declarations. for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) SemaObj->DynamicClasses.push_back( cast(GetDecl(DynamicClasses[I]))); - // If there were any pending implicit instantiations, deserialize them - // and add them to Sema's queue of such instantiations. - assert(PendingInstantiations.size() % 2 == 0 && "Expected pairs of entries"); - for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { - ValueDecl *D=cast(GetDecl(PendingInstantiations[Idx++])); - SourceLocation Loc = ReadSourceLocation(PendingInstantiations, Idx); - SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); - } - // Load the offsets of the declarations that Sema references. // They will be lazily deserialized when needed. if (!SemaDeclRefs.empty()) { @@ -3511,16 +3470,61 @@ void ASTReader::InitializeSema(Sema &S) { SemaObj->StdBadAlloc = SemaDeclRefs[1]; } - // If there are @selector references added them to its pool. This is for - // implementation of -Wselector. - if (!ReferencedSelectorsData.empty()) { - unsigned int DataSize = ReferencedSelectorsData.size()-1; - unsigned I = 0; - while (I < DataSize) { - Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); - SourceLocation SelLoc = - SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); - SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); + for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { + + // If there are @selector references added them to its pool. This is for + // implementation of -Wselector. + if (!F->ReferencedSelectorsData.empty()) { + unsigned int DataSize = F->ReferencedSelectorsData.size()-1; + unsigned I = 0; + while (I < DataSize) { + Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); + SourceLocation SelLoc = ReadSourceLocation( + *F, F->ReferencedSelectorsData, I); + SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); + } + } + + // If there were any pending implicit instantiations, deserialize them + // and add them to Sema's queue of such instantiations. + assert(F->PendingInstantiations.size() % 2 == 0 && + "Expected pairs of entries"); + for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { + ValueDecl *D=cast(GetDecl(F->PendingInstantiations[Idx++])); + SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); + SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); + } + } + + // The two special data sets below always come from the most recent PCH, + // which is at the front of the chain. + PerFileData &F = *Chain.front(); + + // If there were any weak undeclared identifiers, deserialize them and add to + // Sema's list of weak undeclared identifiers. + if (!WeakUndeclaredIdentifiers.empty()) { + unsigned Idx = 0; + for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { + IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); + IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); + SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); + bool Used = WeakUndeclaredIdentifiers[Idx++]; + Sema::WeakInfo WI(AliasId, Loc); + WI.setUsed(Used); + SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); + } + } + + // If there were any VTable uses, deserialize the information and add it + // to Sema's vector and map of VTable uses. + if (!VTableUses.empty()) { + unsigned Idx = 0; + for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { + CXXRecordDecl *Class = cast(GetDecl(VTableUses[Idx++])); + SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); + bool DefinitionRequired = VTableUses[Idx++]; + SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); + SemaObj->VTablesUsed[Class] = DefinitionRequired; } } } @@ -3796,7 +3800,7 @@ ASTReader::ReadTemplateName(const RecordData &Record, unsigned &Idx) { } TemplateArgument -ASTReader::ReadTemplateArgument(llvm::BitstreamCursor &DeclsCursor, +ASTReader::ReadTemplateArgument(PerFileData &F, const RecordData &Record, unsigned &Idx) { switch ((TemplateArgument::ArgKind)Record[Idx++]) { case TemplateArgument::Null: @@ -3813,13 +3817,13 @@ ASTReader::ReadTemplateArgument(llvm::BitstreamCursor &DeclsCursor, case TemplateArgument::Template: return TemplateArgument(ReadTemplateName(Record, Idx)); case TemplateArgument::Expression: - return TemplateArgument(ReadExpr(DeclsCursor)); + return TemplateArgument(ReadExpr(F)); case TemplateArgument::Pack: { unsigned NumArgs = Record[Idx++]; llvm::SmallVector Args; Args.reserve(NumArgs); while (NumArgs--) - Args.push_back(ReadTemplateArgument(DeclsCursor, Record, Idx)); + Args.push_back(ReadTemplateArgument(F, Record, Idx)); TemplateArgument TemplArg; TemplArg.setArgumentPack(Args.data(), Args.size(), /*CopyArgs=*/true); return TemplArg; @@ -3831,10 +3835,11 @@ ASTReader::ReadTemplateArgument(llvm::BitstreamCursor &DeclsCursor, } TemplateParameterList * -ASTReader::ReadTemplateParameterList(const RecordData &Record, unsigned &Idx) { - SourceLocation TemplateLoc = ReadSourceLocation(Record, Idx); - SourceLocation LAngleLoc = ReadSourceLocation(Record, Idx); - SourceLocation RAngleLoc = ReadSourceLocation(Record, Idx); +ASTReader::ReadTemplateParameterList(PerFileData &F, + const RecordData &Record, unsigned &Idx) { + SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); + SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); + SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); unsigned NumParams = Record[Idx++]; llvm::SmallVector Params; @@ -3851,12 +3856,12 @@ ASTReader::ReadTemplateParameterList(const RecordData &Record, unsigned &Idx) { void ASTReader:: ReadTemplateArgumentList(llvm::SmallVector &TemplArgs, - llvm::BitstreamCursor &DeclsCursor, - const RecordData &Record, unsigned &Idx) { + PerFileData &F, const RecordData &Record, + unsigned &Idx) { unsigned NumTemplateArgs = Record[Idx++]; TemplArgs.reserve(NumTemplateArgs); while (NumTemplateArgs--) - TemplArgs.push_back(ReadTemplateArgument(DeclsCursor, Record, Idx)); + TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); } /// \brief Read a UnresolvedSet structure. @@ -3871,18 +3876,18 @@ void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, } CXXBaseSpecifier -ASTReader::ReadCXXBaseSpecifier(llvm::BitstreamCursor &DeclsCursor, +ASTReader::ReadCXXBaseSpecifier(PerFileData &F, const RecordData &Record, unsigned &Idx) { bool isVirtual = static_cast(Record[Idx++]); bool isBaseOfClass = static_cast(Record[Idx++]); AccessSpecifier AS = static_cast(Record[Idx++]); - TypeSourceInfo *TInfo = GetTypeSourceInfo(DeclsCursor, Record, Idx); - SourceRange Range = ReadSourceRange(Record, Idx); + TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); + SourceRange Range = ReadSourceRange(F, Record, Idx); return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, TInfo); } std::pair -ASTReader::ReadCXXBaseOrMemberInitializers(llvm::BitstreamCursor &Cursor, +ASTReader::ReadCXXBaseOrMemberInitializers(PerFileData &F, const RecordData &Record, unsigned &Idx) { CXXBaseOrMemberInitializer **BaseOrMemberInitializers = 0; @@ -3899,17 +3904,17 @@ ASTReader::ReadCXXBaseOrMemberInitializers(llvm::BitstreamCursor &Cursor, bool IsBaseInitializer = Record[Idx++]; if (IsBaseInitializer) { - BaseClassInfo = GetTypeSourceInfo(Cursor, Record, Idx); + BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); IsBaseVirtual = Record[Idx++]; } else { Member = cast(GetDecl(Record[Idx++])); } - SourceLocation MemberLoc = ReadSourceLocation(Record, Idx); - Expr *Init = ReadExpr(Cursor); + SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx); + Expr *Init = ReadExpr(F); FieldDecl *AnonUnionMember = cast_or_null(GetDecl(Record[Idx++])); - SourceLocation LParenLoc = ReadSourceLocation(Record, Idx); - SourceLocation RParenLoc = ReadSourceLocation(Record, Idx); + SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); + SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); bool IsWritten = Record[Idx++]; unsigned SourceOrderOrNumArrayIndices; llvm::SmallVector Indices; @@ -3987,9 +3992,10 @@ ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { } SourceRange -ASTReader::ReadSourceRange(const RecordData &Record, unsigned &Idx) { - SourceLocation beg = SourceLocation::getFromRawEncoding(Record[Idx++]); - SourceLocation end = SourceLocation::getFromRawEncoding(Record[Idx++]); +ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, + unsigned &Idx) { + SourceLocation beg = ReadSourceLocation(F, Record, Idx); + SourceLocation end = ReadSourceLocation(F, Record, Idx); return SourceRange(beg, end); } diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index d51d5162b28b..8b912efe425f 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -30,6 +30,7 @@ using namespace clang::serialization; namespace clang { class ASTDeclReader : public DeclVisitor { ASTReader &Reader; + ASTReader::PerFileData &F; llvm::BitstreamCursor &Cursor; const DeclID ThisDeclID; const ASTReader::RecordData &Record; @@ -37,13 +38,24 @@ namespace clang { TypeID TypeIDForTypeDecl; uint64_t GetCurrentCursorOffset(); + SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, + unsigned &I) { + return Reader.ReadSourceLocation(F, R, I); + } + SourceRange ReadSourceRange(const ASTReader::RecordData &R, unsigned &I) { + return Reader.ReadSourceRange(F, R, I); + } + TypeSourceInfo *GetTypeSourceInfo(const ASTReader::RecordData &R, + unsigned &I) { + return Reader.GetTypeSourceInfo(F, R, I); + } public: - ASTDeclReader(ASTReader &Reader, llvm::BitstreamCursor &Cursor, - DeclID thisDeclID, const ASTReader::RecordData &Record, - unsigned &Idx) - : Reader(Reader), Cursor(Cursor), ThisDeclID(thisDeclID), Record(Record), - Idx(Idx), TypeIDForTypeDecl(0) { } + ASTDeclReader(ASTReader &Reader, ASTReader::PerFileData &F, + llvm::BitstreamCursor &Cursor, DeclID thisDeclID, + const ASTReader::RecordData &Record, unsigned &Idx) + : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID), + Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { } void Visit(Decl *D); @@ -146,11 +158,11 @@ void ASTDeclReader::VisitDecl(Decl *D) { D->setDeclContext(cast_or_null(Reader.GetDecl(Record[Idx++]))); D->setLexicalDeclContext( cast_or_null(Reader.GetDecl(Record[Idx++]))); - D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + D->setLocation(ReadSourceLocation(Record, Idx)); D->setInvalidDecl(Record[Idx++]); if (Record[Idx++]) { AttrVec Attrs; - Reader.ReadAttributes(Cursor, Attrs); + Reader.ReadAttributes(F, Attrs); D->setAttrs(Attrs); } D->setImplicit(Record[Idx++]); @@ -178,7 +190,7 @@ void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { VisitTypeDecl(TD); - TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); + TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); } void ASTDeclReader::VisitTagDecl(TagDecl *TD) { @@ -188,8 +200,8 @@ void ASTDeclReader::VisitTagDecl(TagDecl *TD) { TD->setTagKind((TagDecl::TagKind)Record[Idx++]); TD->setDefinition(Record[Idx++]); TD->setEmbeddedInDeclarator(Record[Idx++]); - TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + TD->setRBraceLoc(ReadSourceLocation(Record, Idx)); + TD->setTagKeywordLoc(ReadSourceLocation(Record, Idx)); // FIXME: maybe read optional qualifier and its range. TD->setTypedefForAnonDecl( cast_or_null(Reader.GetDecl(Record[Idx++]))); @@ -220,13 +232,13 @@ void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { VisitValueDecl(ECD); if (Record[Idx++]) - ECD->setInitExpr(Reader.ReadExpr(Cursor)); + ECD->setInitExpr(Reader.ReadExpr(F)); ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); } void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { VisitValueDecl(DD); - TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx); + TypeSourceInfo *TInfo = GetTypeSourceInfo(Record, Idx); if (TInfo) DD->setTypeSourceInfo(TInfo); // FIXME: read optional qualifier and its range. @@ -250,7 +262,7 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { case FunctionDecl::TK_MemberSpecialization: { FunctionDecl *InstFD = cast(Reader.GetDecl(Record[Idx++])); TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; - SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); + SourceLocation POI = ReadSourceLocation(Record, Idx); FD->setInstantiationOfMemberFunction(*Reader.getContext(), InstFD, TSK); FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); break; @@ -262,7 +274,7 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { // Template arguments. llvm::SmallVector TemplArgs; - Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); + Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); // Template args as written. llvm::SmallVector TemplArgLocs; @@ -272,13 +284,13 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { TemplArgLocs.reserve(NumTemplateArgLocs); for (unsigned i=0; i != NumTemplateArgLocs; ++i) TemplArgLocs.push_back( - Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx)); + Reader.ReadTemplateArgumentLoc(F, Record, Idx)); - LAngleLoc = Reader.ReadSourceLocation(Record, Idx); - RAngleLoc = Reader.ReadSourceLocation(Record, Idx); + LAngleLoc = ReadSourceLocation(Record, Idx); + RAngleLoc = ReadSourceLocation(Record, Idx); } - SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); + SourceLocation POI = ReadSourceLocation(Record, Idx); ASTContext &C = *Reader.getContext(); TemplateArgumentList *TemplArgList @@ -324,9 +336,9 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { TemplateArgumentListInfo TemplArgs; unsigned NumArgs = Record[Idx++]; while (NumArgs--) - TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx)); - TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx)); - TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx)); + TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx)); + TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx)); + TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx)); FD->setDependentTemplateSpecialization(*Reader.getContext(), TemplDecls, TemplArgs); @@ -347,7 +359,7 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { FD->setDeleted(Record[Idx++]); FD->setTrivial(Record[Idx++]); FD->setHasImplicitReturnZero(Record[Idx++]); - FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); + FD->setLocEnd(ReadSourceLocation(Record, Idx)); // Read in the parameters. unsigned NumParams = Record[Idx++]; @@ -363,7 +375,7 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { if (Record[Idx++]) { // In practice, this won't be executed (since method definitions // don't occur in header files). - MD->setBody(Reader.ReadStmt(Cursor)); + MD->setBody(Reader.ReadStmt(F)); MD->setSelfDecl(cast(Reader.GetDecl(Record[Idx++]))); MD->setCmdDecl(cast(Reader.GetDecl(Record[Idx++]))); } @@ -375,8 +387,8 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); MD->setNumSelectorArgs(unsigned(Record[Idx++])); MD->setResultType(Reader.GetType(Record[Idx++])); - MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); - MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); + MD->setEndLoc(ReadSourceLocation(Record, Idx)); unsigned NumParams = Record[Idx++]; llvm::SmallVector Params; Params.reserve(NumParams); @@ -388,8 +400,8 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { VisitNamedDecl(CD); - SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]); - SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]); + SourceLocation A = ReadSourceLocation(Record, Idx); + SourceLocation B = ReadSourceLocation(Record, Idx); CD->setAtEndRange(SourceRange(A, B)); } @@ -408,7 +420,7 @@ void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { llvm::SmallVector ProtoLocs; ProtoLocs.reserve(NumProtocols); for (unsigned I = 0; I != NumProtocols; ++I) - ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); + ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(), *Reader.getContext()); @@ -433,9 +445,9 @@ void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { ID->setIvarList(0); ID->setForwardDecl(Record[Idx++]); ID->setImplicitInterfaceDecl(Record[Idx++]); - ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); + ID->setClassLoc(ReadSourceLocation(Record, Idx)); + ID->setSuperClassLoc(ReadSourceLocation(Record, Idx)); + ID->setLocEnd(ReadSourceLocation(Record, Idx)); } void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { @@ -450,7 +462,7 @@ void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { VisitObjCContainerDecl(PD); PD->setForwardDecl(Record[Idx++]); - PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); + PD->setLocEnd(ReadSourceLocation(Record, Idx)); unsigned NumProtoRefs = Record[Idx++]; llvm::SmallVector ProtoRefs; ProtoRefs.reserve(NumProtoRefs); @@ -459,7 +471,7 @@ void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { llvm::SmallVector ProtoLocs; ProtoLocs.reserve(NumProtoRefs); for (unsigned I = 0; I != NumProtoRefs; ++I) - ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); + ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), *Reader.getContext()); } @@ -478,7 +490,7 @@ void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) { llvm::SmallVector SLocs; SLocs.reserve(NumClassRefs); for (unsigned I = 0; I != NumClassRefs; ++I) - SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); + SLocs.push_back(ReadSourceLocation(Record, Idx)); CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(), NumClassRefs); } @@ -493,7 +505,7 @@ void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) { llvm::SmallVector ProtoLocs; ProtoLocs.reserve(NumProtoRefs); for (unsigned I = 0; I != NumProtoRefs; ++I) - ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); + ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), *Reader.getContext()); } @@ -509,13 +521,13 @@ void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { llvm::SmallVector ProtoLocs; ProtoLocs.reserve(NumProtoRefs); for (unsigned I = 0; I != NumProtoRefs; ++I) - ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); + ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), *Reader.getContext()); CD->setNextClassCategory(cast_or_null(Reader.GetDecl(Record[Idx++]))); CD->setHasSynthBitfield(Record[Idx++]); - CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + CD->setAtLoc(ReadSourceLocation(Record, Idx)); + CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx)); } void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { @@ -525,8 +537,8 @@ void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { VisitNamedDecl(D); - D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); + D->setAtLoc(ReadSourceLocation(Record, Idx)); + D->setType(GetTypeSourceInfo(Record, Idx)); // FIXME: stable encoding D->setPropertyAttributes( (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); @@ -561,27 +573,27 @@ void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { D->setSuperClass( cast_or_null(Reader.GetDecl(Record[Idx++]))); llvm::tie(D->IvarInitializers, D->NumIvarInitializers) - = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx); + = Reader.ReadCXXBaseOrMemberInitializers(F, Record, Idx); D->setHasSynthBitfield(Record[Idx++]); } void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { VisitDecl(D); - D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + D->setAtLoc(ReadSourceLocation(Record, Idx)); D->setPropertyDecl( cast_or_null(Reader.GetDecl(Record[Idx++]))); D->setPropertyIvarDecl( cast_or_null(Reader.GetDecl(Record[Idx++]))); - D->setGetterCXXConstructor(Reader.ReadExpr(Cursor)); - D->setSetterCXXAssignment(Reader.ReadExpr(Cursor)); + D->setGetterCXXConstructor(Reader.ReadExpr(F)); + D->setSetterCXXAssignment(Reader.ReadExpr(F)); } void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { VisitDeclaratorDecl(FD); FD->setMutable(Record[Idx++]); if (Record[Idx++]) - FD->setBitWidth(Reader.ReadExpr(Cursor)); + FD->setBitWidth(Reader.ReadExpr(F)); if (!FD->getDeclName()) { FieldDecl *Tmpl = cast_or_null(Reader.GetDecl(Record[Idx++])); if (Tmpl) @@ -599,12 +611,12 @@ void ASTDeclReader::VisitVarDecl(VarDecl *VD) { VD->setExceptionVariable(Record[Idx++]); VD->setNRVOVariable(Record[Idx++]); if (Record[Idx++]) - VD->setInit(Reader.ReadExpr(Cursor)); + VD->setInit(Reader.ReadExpr(F)); if (Record[Idx++]) { // HasMemberSpecializationInfo. VarDecl *Tmpl = cast(Reader.GetDecl(Record[Idx++])); TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; - SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); + SourceLocation POI = ReadSourceLocation(Record, Idx); Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); } } @@ -618,18 +630,18 @@ void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); PD->setHasInheritedDefaultArg(Record[Idx++]); if (Record[Idx++]) // hasUninstantiatedDefaultArg. - PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor)); + PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F)); } void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { VisitDecl(AD); - AD->setAsmString(cast(Reader.ReadExpr(Cursor))); + AD->setAsmString(cast(Reader.ReadExpr(F))); } void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { VisitDecl(BD); - BD->setBody(cast_or_null(Reader.ReadStmt(Cursor))); - BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); + BD->setBody(cast_or_null(Reader.ReadStmt(F))); + BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx)); unsigned NumParams = Record[Idx++]; llvm::SmallVector Params; Params.reserve(NumParams); @@ -646,8 +658,8 @@ void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { VisitNamedDecl(D); - D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx)); - D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx)); + D->setLBracLoc(ReadSourceLocation(Record, Idx)); + D->setRBracLoc(ReadSourceLocation(Record, Idx)); D->setNextNamespace( cast_or_null(Reader.GetDecl(Record[Idx++]))); @@ -659,17 +671,17 @@ void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { VisitNamedDecl(D); - D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx); - D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); + D->NamespaceLoc = ReadSourceLocation(Record, Idx); + D->setQualifierRange(ReadSourceRange(Record, Idx)); D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); - D->IdentLoc = Reader.ReadSourceLocation(Record, Idx); + D->IdentLoc = ReadSourceLocation(Record, Idx); D->Namespace = cast(Reader.GetDecl(Record[Idx++])); } void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { VisitNamedDecl(D); - D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx)); - D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx)); + D->setUsingLocation(ReadSourceLocation(Record, Idx)); + D->setNestedNameRange(ReadSourceRange(Record, Idx)); D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx)); // FIXME: read the DNLoc component. @@ -700,9 +712,9 @@ void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { VisitNamedDecl(D); - D->UsingLoc = Reader.ReadSourceLocation(Record, Idx); - D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx); - D->QualifierRange = Reader.ReadSourceRange(Record, Idx); + D->UsingLoc = ReadSourceLocation(Record, Idx); + D->NamespaceLoc = ReadSourceLocation(Record, Idx); + D->QualifierRange = ReadSourceRange(Record, Idx); D->Qualifier = Reader.ReadNestedNameSpecifier(Record, Idx); D->NominatedNamespace = cast(Reader.GetDecl(Record[Idx++])); D->CommonAncestor = cast_or_null(Reader.GetDecl(Record[Idx++])); @@ -710,8 +722,8 @@ void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { VisitValueDecl(D); - D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); - D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); + D->setTargetNestedNameRange(ReadSourceRange(Record, Idx)); + D->setUsingLoc(ReadSourceLocation(Record, Idx)); D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); // FIXME: read the DNLoc component. } @@ -719,9 +731,9 @@ void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( UnresolvedUsingTypenameDecl *D) { VisitTypeDecl(D); - D->TargetNestedNameRange = Reader.ReadSourceRange(Record, Idx); - D->UsingLocation = Reader.ReadSourceLocation(Record, Idx); - D->TypenameLocation = Reader.ReadSourceLocation(Record, Idx); + D->TargetNestedNameRange = ReadSourceRange(Record, Idx); + D->UsingLocation = ReadSourceLocation(Record, Idx); + D->TypenameLocation = ReadSourceLocation(Record, Idx); D->TargetNestedNameSpecifier = Reader.ReadNestedNameSpecifier(Record, Idx); } @@ -778,13 +790,13 @@ void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { Data.NumBases = Record[Idx++]; Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases]; for (unsigned i = 0; i != Data.NumBases; ++i) - Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx); + Data.Bases[i] = Reader.ReadCXXBaseSpecifier(F, Record, Idx); // FIXME: Make VBases lazily computed when needed to avoid storing them. Data.NumVBases = Record[Idx++]; Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases]; for (unsigned i = 0; i != Data.NumVBases; ++i) - Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx); + Data.VBases[i] = Reader.ReadCXXBaseSpecifier(F, Record, Idx); Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx); Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx); @@ -808,7 +820,7 @@ void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { case CXXRecMemberSpecialization: { CXXRecordDecl *RD = cast(Reader.GetDecl(Record[Idx++])); TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; - SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); + SourceLocation POI = ReadSourceLocation(Record, Idx); MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); MSI->setPointOfInstantiation(POI); D->TemplateOrInstantiation = MSI; @@ -834,7 +846,7 @@ void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { D->IsExplicitSpecified = Record[Idx++]; D->ImplicitlyDefined = Record[Idx++]; llvm::tie(D->BaseOrMemberInitializers, D->NumBaseOrMemberInitializers) - = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx); + = Reader.ReadCXXBaseOrMemberInitializers(F, Record, Idx); } void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { @@ -851,17 +863,17 @@ void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { VisitDecl(D); - D->setColonLoc(Reader.ReadSourceLocation(Record, Idx)); + D->setColonLoc(ReadSourceLocation(Record, Idx)); } void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { VisitDecl(D); if (Record[Idx++]) - D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx); + D->Friend = GetTypeSourceInfo(Record, Idx); else D->Friend = cast(Reader.GetDecl(Record[Idx++])); D->NextFriend = cast_or_null(Reader.GetDecl(Record[Idx++])); - D->FriendLoc = Reader.ReadSourceLocation(Record, Idx); + D->FriendLoc = ReadSourceLocation(Record, Idx); } void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { @@ -870,12 +882,12 @@ void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { D->NumParams = NumParams; D->Params = new TemplateParameterList*[NumParams]; for (unsigned i = 0; i != NumParams; ++i) - D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx); + D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx); if (Record[Idx++]) // HasFriendDecl D->Friend = cast(Reader.GetDecl(Record[Idx++])); else - D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx); - D->FriendLoc = Reader.ReadSourceLocation(Record, Idx); + D->Friend = GetTypeSourceInfo(Record, Idx); + D->FriendLoc = ReadSourceLocation(Record, Idx); } void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { @@ -884,7 +896,7 @@ void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { NamedDecl *TemplatedDecl = cast_or_null(Reader.GetDecl(Record[Idx++])); TemplateParameterList* TemplateParams - = Reader.ReadTemplateParameterList(Record, Idx); + = Reader.ReadTemplateParameterList(F, Record, Idx); D->init(TemplatedDecl, TemplateParams); } @@ -969,7 +981,7 @@ void ASTDeclReader::VisitClassTemplateSpecializationDecl( D->SpecializedTemplate = CTD; } else { llvm::SmallVector TemplArgs; - Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); + Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); TemplateArgumentList *ArgList = new (C) TemplateArgumentList(C, TemplArgs.data(), TemplArgs.size()); ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS @@ -983,19 +995,19 @@ void ASTDeclReader::VisitClassTemplateSpecializationDecl( } // Explicit info. - if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) { + if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) { ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; ExplicitInfo->TypeAsWritten = TyInfo; - ExplicitInfo->ExternLoc = Reader.ReadSourceLocation(Record, Idx); - ExplicitInfo->TemplateKeywordLoc = Reader.ReadSourceLocation(Record, Idx); + ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx); + ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx); D->ExplicitInfo = ExplicitInfo; } llvm::SmallVector TemplArgs; - Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); + Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); D->TemplateArgs.init(C, TemplArgs.data(), TemplArgs.size()); - D->PointOfInstantiation = Reader.ReadSourceLocation(Record, Idx); + D->PointOfInstantiation = ReadSourceLocation(Record, Idx); D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++]; if (D->isCanonicalDecl()) { // It's kept in the folding set. @@ -1015,14 +1027,14 @@ void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( VisitClassTemplateSpecializationDecl(D); ASTContext &C = *Reader.getContext(); - D->TemplateParams = Reader.ReadTemplateParameterList(Record, Idx); + D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx); unsigned NumArgs = Record[Idx++]; if (NumArgs) { D->NumArgsAsWritten = NumArgs; D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs]; for (unsigned i=0; i != NumArgs; ++i) - D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx); + D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx); } D->SequenceNumber = Record[Idx++]; @@ -1058,7 +1070,7 @@ void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { D->setParameterPack(Record[Idx++]); bool Inherited = Record[Idx++]; - TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx); + TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx); D->setDefaultArgument(DefArg, Inherited); } @@ -1069,7 +1081,7 @@ void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { D->setPosition(Record[Idx++]); // Rest of NonTypeTemplateParmDecl. if (Record[Idx++]) { - Expr *DefArg = Reader.ReadExpr(Cursor); + Expr *DefArg = Reader.ReadExpr(F); bool Inherited = Record[Idx++]; D->setDefaultArgument(DefArg, Inherited); } @@ -1081,15 +1093,15 @@ void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { D->setDepth(Record[Idx++]); D->setPosition(Record[Idx++]); // Rest of TemplateTemplateParmDecl. - TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx); + TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx); bool IsInherited = Record[Idx++]; D->setDefaultArgument(Arg, IsInherited); } void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { VisitDecl(D); - D->AssertExpr = Reader.ReadExpr(Cursor); - D->Message = cast(Reader.ReadExpr(Cursor)); + D->AssertExpr = Reader.ReadExpr(F); + D->Message = cast(Reader.ReadExpr(F)); } std::pair @@ -1152,8 +1164,8 @@ void ASTDeclReader::VisitRedeclarable(Redeclarable *D) { //===----------------------------------------------------------------------===// /// \brief Reads attributes from the current stream position. -void ASTReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor, - AttrVec &Attrs) { +void ASTReader::ReadAttributes(PerFileData &F, AttrVec &Attrs) { + llvm::BitstreamCursor &DeclsCursor = F.DeclsCursor; unsigned Code = DeclsCursor.ReadCode(); assert(Code == llvm::bitc::UNABBREV_RECORD && "Expected unabbreviated record"); (void)Code; @@ -1167,7 +1179,7 @@ void ASTReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor, while (Idx < Record.size()) { Attr *New = 0; attr::Kind Kind = (attr::Kind)Record[Idx++]; - SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[Idx++]); + SourceLocation Loc = ReadSourceLocation(F, Record, Idx); bool isInherited = Record[Idx++]; #include "clang/Serialization/AttrPCHRead.inc" @@ -1217,7 +1229,7 @@ ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) { // See if there's an override. DeclReplacementMap::iterator It = ReplacedDecls.find(ID); if (It != ReplacedDecls.end()) - return RecordLocation(&It->second.first->DeclsCursor, It->second.second); + return RecordLocation(It->second.first, It->second.second); PerFileData *F = 0; for (unsigned I = 0, N = Chain.size(); I != N; ++I) { @@ -1227,13 +1239,13 @@ ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) { Index -= F->LocalNumDecls; } assert(F && F->LocalNumDecls > Index && "Broken chain"); - return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]); + return RecordLocation(F, F->DeclOffsets[Index]); } /// \brief Read the declaration at the given offset from the AST file. Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { RecordLocation Loc = DeclCursorForIndex(Index, ID); - llvm::BitstreamCursor &DeclsCursor = *Loc.first; + llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; // Keep track of where we are in the stream, then jump back there // after reading this declaration. SavedStreamPosition SavedPosition(DeclsCursor); @@ -1243,11 +1255,11 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { // Note that we are loading a declaration record. Deserializing ADecl(this); - DeclsCursor.JumpToBit(Loc.second); + DeclsCursor.JumpToBit(Loc.Offset); RecordData Record; unsigned Code = DeclsCursor.ReadCode(); unsigned Idx = 0; - ASTDeclReader Reader(*this, DeclsCursor, ID, Record, Idx); + ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx); Decl *D = 0; switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) { diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index ab2bba7283bf..f361f0d2606d 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -22,14 +22,28 @@ namespace clang { class ASTStmtReader : public StmtVisitor { ASTReader &Reader; + ASTReader::PerFileData &F; llvm::BitstreamCursor &DeclsCursor; const ASTReader::RecordData &Record; unsigned &Idx; + SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, + unsigned &I) { + return Reader.ReadSourceLocation(F, R, I); + } + SourceRange ReadSourceRange(const ASTReader::RecordData &R, unsigned &I) { + return Reader.ReadSourceRange(F, R, I); + } + TypeSourceInfo *GetTypeSourceInfo(const ASTReader::RecordData &R, + unsigned &I) { + return Reader.GetTypeSourceInfo(F, R, I); + } + public: - ASTStmtReader(ASTReader &Reader, llvm::BitstreamCursor &Cursor, + ASTStmtReader(ASTReader &Reader, ASTReader::PerFileData &F, + llvm::BitstreamCursor &Cursor, const ASTReader::RecordData &Record, unsigned &Idx) - : Reader(Reader), DeclsCursor(Cursor), Record(Record), Idx(Idx) { } + : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { } /// \brief The number of record fields required for the Stmt class /// itself. @@ -164,11 +178,11 @@ void ASTStmtReader:: ReadExplicitTemplateArgumentList(ExplicitTemplateArgumentList &ArgList, unsigned NumTemplateArgs) { TemplateArgumentListInfo ArgInfo; - ArgInfo.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx)); - ArgInfo.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx)); + ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx)); + ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx)); for (unsigned i = 0; i != NumTemplateArgs; ++i) ArgInfo.addArgument( - Reader.ReadTemplateArgumentLoc(DeclsCursor, Record, Idx)); + Reader.ReadTemplateArgumentLoc(F, Record, Idx)); ArgList.initializeFrom(ArgInfo); } @@ -178,7 +192,7 @@ void ASTStmtReader::VisitStmt(Stmt *S) { void ASTStmtReader::VisitNullStmt(NullStmt *S) { VisitStmt(S); - S->setSemiLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setSemiLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) { @@ -188,8 +202,8 @@ void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) { while (NumStmts--) Stmts.push_back(Reader.ReadSubStmt()); S->setStmts(*Reader.getContext(), Stmts.data(), Stmts.size()); - S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setLBracLoc(ReadSourceLocation(Record, Idx)); + S->setRBracLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitSwitchCase(SwitchCase *S) { @@ -202,23 +216,23 @@ void ASTStmtReader::VisitCaseStmt(CaseStmt *S) { S->setLHS(Reader.ReadSubExpr()); S->setRHS(Reader.ReadSubExpr()); S->setSubStmt(Reader.ReadSubStmt()); - S->setCaseLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setEllipsisLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setCaseLoc(ReadSourceLocation(Record, Idx)); + S->setEllipsisLoc(ReadSourceLocation(Record, Idx)); + S->setColonLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) { VisitSwitchCase(S); S->setSubStmt(Reader.ReadSubStmt()); - S->setDefaultLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setDefaultLoc(ReadSourceLocation(Record, Idx)); + S->setColonLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitLabelStmt(LabelStmt *S) { VisitStmt(S); S->setID(Reader.GetIdentifierInfo(Record, Idx)); S->setSubStmt(Reader.ReadSubStmt()); - S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setIdentLoc(ReadSourceLocation(Record, Idx)); S->setUsed(Record[Idx++]); S->setUnusedAttribute(Record[Idx++]); Reader.RecordLabelStmt(S, Record[Idx++]); @@ -231,8 +245,8 @@ void ASTStmtReader::VisitIfStmt(IfStmt *S) { S->setCond(Reader.ReadSubExpr()); S->setThen(Reader.ReadSubStmt()); S->setElse(Reader.ReadSubStmt()); - S->setIfLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setElseLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setIfLoc(ReadSourceLocation(Record, Idx)); + S->setElseLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) { @@ -241,7 +255,7 @@ void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) { cast_or_null(Reader.GetDecl(Record[Idx++]))); S->setCond(Reader.ReadSubExpr()); S->setBody(Reader.ReadSubStmt()); - S->setSwitchLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setSwitchLoc(ReadSourceLocation(Record, Idx)); if (Record[Idx++]) S->setAllEnumCasesCovered(); @@ -266,16 +280,16 @@ void ASTStmtReader::VisitWhileStmt(WhileStmt *S) { cast_or_null(Reader.GetDecl(Record[Idx++]))); S->setCond(Reader.ReadSubExpr()); S->setBody(Reader.ReadSubStmt()); - S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setWhileLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitDoStmt(DoStmt *S) { VisitStmt(S); S->setCond(Reader.ReadSubExpr()); S->setBody(Reader.ReadSubStmt()); - S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setDoLoc(ReadSourceLocation(Record, Idx)); + S->setWhileLoc(ReadSourceLocation(Record, Idx)); + S->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitForStmt(ForStmt *S) { @@ -286,46 +300,46 @@ void ASTStmtReader::VisitForStmt(ForStmt *S) { cast_or_null(Reader.GetDecl(Record[Idx++]))); S->setInc(Reader.ReadSubExpr()); S->setBody(Reader.ReadSubStmt()); - S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setForLoc(ReadSourceLocation(Record, Idx)); + S->setLParenLoc(ReadSourceLocation(Record, Idx)); + S->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitGotoStmt(GotoStmt *S) { VisitStmt(S); Reader.SetLabelOf(S, Record[Idx++]); - S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setGotoLoc(ReadSourceLocation(Record, Idx)); + S->setLabelLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) { VisitStmt(S); - S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setGotoLoc(ReadSourceLocation(Record, Idx)); + S->setStarLoc(ReadSourceLocation(Record, Idx)); S->setTarget(Reader.ReadSubExpr()); } void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) { VisitStmt(S); - S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setContinueLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitBreakStmt(BreakStmt *S) { VisitStmt(S); - S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setBreakLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) { VisitStmt(S); S->setRetValue(Reader.ReadSubExpr()); - S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setReturnLoc(ReadSourceLocation(Record, Idx)); S->setNRVOCandidate(cast_or_null(Reader.GetDecl(Record[Idx++]))); } void ASTStmtReader::VisitDeclStmt(DeclStmt *S) { VisitStmt(S); - S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setStartLoc(ReadSourceLocation(Record, Idx)); + S->setEndLoc(ReadSourceLocation(Record, Idx)); if (Idx + 1 == Record.size()) { // Single declaration @@ -346,8 +360,8 @@ void ASTStmtReader::VisitAsmStmt(AsmStmt *S) { unsigned NumOutputs = Record[Idx++]; unsigned NumInputs = Record[Idx++]; unsigned NumClobbers = Record[Idx++]; - S->setAsmLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setAsmLoc(ReadSourceLocation(Record, Idx)); + S->setRParenLoc(ReadSourceLocation(Record, Idx)); S->setVolatile(Record[Idx++]); S->setSimple(Record[Idx++]); S->setMSAsm(Record[Idx++]); @@ -385,7 +399,7 @@ void ASTStmtReader::VisitExpr(Expr *E) { void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) { VisitExpr(E); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]); } @@ -400,7 +414,7 @@ void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { if (HasQualifier) { E->getNameQualifier()->NNS = Reader.ReadNestedNameSpecifier(Record, Idx); - E->getNameQualifier()->Range = Reader.ReadSourceRange(Record, Idx); + E->getNameQualifier()->Range = ReadSourceRange(Record, Idx); } if (NumTemplateArgs) @@ -409,12 +423,12 @@ void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { E->setDecl(cast(Reader.GetDecl(Record[Idx++]))); // FIXME: read DeclarationNameLoc. - E->setLocation(Reader.ReadSourceLocation(Record, Idx)); + E->setLocation(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) { VisitExpr(E); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); E->setValue(*Reader.getContext(), Reader.ReadAPInt(Record, Idx)); } @@ -422,7 +436,7 @@ void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) { VisitExpr(E); E->setValue(*Reader.getContext(), Reader.ReadAPFloat(Record, Idx)); E->setExact(Record[Idx++]); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) { @@ -445,20 +459,20 @@ void ASTStmtReader::VisitStringLiteral(StringLiteral *E) { // Read source locations for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) - E->setStrTokenLoc(I, SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setStrTokenLoc(I, ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) { VisitExpr(E); E->setValue(Record[Idx++]); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); E->setWide(Record[Idx++]); } void ASTStmtReader::VisitParenExpr(ParenExpr *E) { VisitExpr(E); - E->setLParen(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParen(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLParen(ReadSourceLocation(Record, Idx)); + E->setRParen(ReadSourceLocation(Record, Idx)); E->setSubExpr(Reader.ReadSubExpr()); } @@ -469,15 +483,15 @@ void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) { for (unsigned i = 0; i != NumExprs; ++i) E->Exprs[i] = Reader.ReadSubStmt(); E->NumExprs = NumExprs; - E->LParenLoc = Reader.ReadSourceLocation(Record, Idx); - E->RParenLoc = Reader.ReadSourceLocation(Record, Idx); + E->LParenLoc = ReadSourceLocation(Record, Idx); + E->RParenLoc = ReadSourceLocation(Record, Idx); } void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) { VisitExpr(E); E->setSubExpr(Reader.ReadSubExpr()); E->setOpcode((UnaryOperator::Opcode)Record[Idx++]); - E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setOperatorLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { @@ -487,13 +501,13 @@ void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { ++Idx; assert(E->getNumExpressions() == Record[Idx]); ++Idx; - E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setTypeSourceInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + E->setOperatorLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); + E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { Node::Kind Kind = static_cast(Record[Idx++]); - SourceLocation Start = SourceLocation::getFromRawEncoding(Record[Idx++]); - SourceLocation End = SourceLocation::getFromRawEncoding(Record[Idx++]); + SourceLocation Start = ReadSourceLocation(Record, Idx); + SourceLocation End = ReadSourceLocation(Record, Idx); switch (Kind) { case Node::Array: E->setComponent(I, Node(Start, Record[Idx++], End)); @@ -512,7 +526,7 @@ void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { case Node::Base: { CXXBaseSpecifier *Base = new (*Reader.getContext()) CXXBaseSpecifier(); - *Base = Reader.ReadCXXBaseSpecifier(DeclsCursor, Record, Idx); + *Base = Reader.ReadCXXBaseSpecifier(F, Record, Idx); E->setComponent(I, Node(Base)); break; } @@ -530,23 +544,23 @@ void ASTStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { E->setArgument(Reader.ReadSubExpr()); ++Idx; } else { - E->setArgument(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + E->setArgument(GetTypeSourceInfo(Record, Idx)); } - E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setOperatorLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { VisitExpr(E); E->setLHS(Reader.ReadSubExpr()); E->setRHS(Reader.ReadSubExpr()); - E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setRBracketLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCallExpr(CallExpr *E) { VisitExpr(E); E->setNumArgs(*Reader.getContext(), Record[Idx++]); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); E->setCallee(Reader.ReadSubExpr()); for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) E->setArg(I, Reader.ReadSubExpr()); @@ -561,7 +575,7 @@ void ASTStmtReader::VisitMemberExpr(MemberExpr *E) { void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) { VisitExpr(E); E->setBase(Reader.ReadSubExpr()); - E->setIsaMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setIsaMemberLoc(ReadSourceLocation(Record, Idx)); E->setArrow(Record[Idx++]); } @@ -574,7 +588,7 @@ void ASTStmtReader::VisitCastExpr(CastExpr *E) { CastExpr::path_iterator BaseI = E->path_begin(); while (NumBaseSpecs--) { CXXBaseSpecifier *BaseSpec = new (*Reader.getContext()) CXXBaseSpecifier; - *BaseSpec = Reader.ReadCXXBaseSpecifier(DeclsCursor, Record, Idx); + *BaseSpec = Reader.ReadCXXBaseSpecifier(F, Record, Idx); *BaseI++ = BaseSpec; } } @@ -584,7 +598,7 @@ void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) { E->setLHS(Reader.ReadSubExpr()); E->setRHS(Reader.ReadSubExpr()); E->setOpcode((BinaryOperator::Opcode)Record[Idx++]); - E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setOperatorLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) { @@ -599,8 +613,8 @@ void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) { E->setLHS(Reader.ReadSubExpr()); E->setRHS(Reader.ReadSubExpr()); E->setSAVE(Reader.ReadSubExpr()); - E->setQuestionLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setQuestionLoc(ReadSourceLocation(Record, Idx)); + E->setColonLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) { @@ -610,19 +624,19 @@ void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) { void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) { VisitCastExpr(E); - E->setTypeInfoAsWritten(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + E->setTypeInfoAsWritten(GetTypeSourceInfo(Record, Idx)); } void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { VisitExplicitCastExpr(E); - E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLParenLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { VisitExpr(E); - E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setTypeSourceInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + E->setLParenLoc(ReadSourceLocation(Record, Idx)); + E->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); E->setInitializer(Reader.ReadSubExpr()); E->setFileScope(Record[Idx++]); } @@ -631,7 +645,7 @@ void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { VisitExpr(E); E->setBase(Reader.ReadSubExpr()); E->setAccessor(Reader.GetIdentifierInfo(Record, Idx)); - E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setAccessorLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitInitListExpr(InitListExpr *E) { @@ -641,8 +655,8 @@ void ASTStmtReader::VisitInitListExpr(InitListExpr *E) { for (unsigned I = 0; I != NumInits; ++I) E->updateInit(*Reader.getContext(), I, Reader.ReadSubExpr()); E->setSyntacticForm(cast_or_null(Reader.ReadSubStmt())); - E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLBraceLoc(ReadSourceLocation(Record, Idx)); + E->setRBraceLoc(ReadSourceLocation(Record, Idx)); E->setInitializedFieldInUnion( cast_or_null(Reader.GetDecl(Record[Idx++]))); E->sawArrayRangeDesignator(Record[Idx++]); @@ -656,7 +670,7 @@ void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs"); for (unsigned I = 0; I != NumSubExprs; ++I) E->setSubExpr(I, Reader.ReadSubExpr()); - E->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setEqualOrColonLoc(ReadSourceLocation(Record, Idx)); E->setGNUSyntax(Record[Idx++]); llvm::SmallVector Designators; @@ -665,9 +679,9 @@ void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { case DESIG_FIELD_DECL: { FieldDecl *Field = cast(Reader.GetDecl(Record[Idx++])); SourceLocation DotLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); SourceLocation FieldLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); Designators.push_back(Designator(Field->getIdentifier(), DotLoc, FieldLoc)); Designators.back().setField(Field); @@ -677,9 +691,9 @@ void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { case DESIG_FIELD_NAME: { const IdentifierInfo *Name = Reader.GetIdentifierInfo(Record, Idx); SourceLocation DotLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); SourceLocation FieldLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); Designators.push_back(Designator(Name, DotLoc, FieldLoc)); break; } @@ -687,9 +701,9 @@ void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { case DESIG_ARRAY: { unsigned Index = Record[Idx++]; SourceLocation LBracketLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); SourceLocation RBracketLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc)); break; } @@ -697,11 +711,11 @@ void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { case DESIG_ARRAY_RANGE: { unsigned Index = Record[Idx++]; SourceLocation LBracketLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); SourceLocation EllipsisLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); SourceLocation RBracketLoc - = SourceLocation::getFromRawEncoding(Record[Idx++]); + = ReadSourceLocation(Record, Idx); Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc, RBracketLoc)); break; @@ -719,31 +733,31 @@ void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) { VisitExpr(E); E->setSubExpr(Reader.ReadSubExpr()); - E->setWrittenTypeInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); - E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setWrittenTypeInfo(GetTypeSourceInfo(Record, Idx)); + E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) { VisitExpr(E); - E->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setAmpAmpLoc(ReadSourceLocation(Record, Idx)); + E->setLabelLoc(ReadSourceLocation(Record, Idx)); Reader.SetLabelOf(E, Record[Idx++]); } void ASTStmtReader::VisitStmtExpr(StmtExpr *E) { VisitExpr(E); - E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLParenLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); E->setSubStmt(cast_or_null(Reader.ReadSubStmt())); } void ASTStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { VisitExpr(E); - E->setArgTInfo1(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); - E->setArgTInfo2(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); - E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setArgTInfo1(GetTypeSourceInfo(Record, Idx)); + E->setArgTInfo2(GetTypeSourceInfo(Record, Idx)); + E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) { @@ -751,13 +765,13 @@ void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) { E->setCond(Reader.ReadSubExpr()); E->setLHS(Reader.ReadSubExpr()); E->setRHS(Reader.ReadSubExpr()); - E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) { VisitExpr(E); - E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setTokenLocation(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { @@ -767,8 +781,8 @@ void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { while (NumExprs--) Exprs.push_back(Reader.ReadSubExpr()); E->setExprs(*Reader.getContext(), Exprs.data(), Exprs.size()); - E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setBuiltinLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitBlockExpr(BlockExpr *E) { @@ -780,7 +794,7 @@ void ASTStmtReader::VisitBlockExpr(BlockExpr *E) { void ASTStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { VisitExpr(E); E->setDecl(cast(Reader.GetDecl(Record[Idx++]))); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); E->setByRef(Record[Idx++]); E->setConstQualAdded(Record[Idx++]); E->setCopyConstructorExpr(Reader.ReadSubExpr()); @@ -792,34 +806,34 @@ void ASTStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) { VisitExpr(E); E->setString(cast(Reader.ReadSubStmt())); - E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setAtLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { VisitExpr(E); - E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(DeclsCursor,Record,Idx)); - E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setEncodedTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); + E->setAtLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { VisitExpr(E); E->setSelector(Reader.GetSelector(Record, Idx)); - E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setAtLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { VisitExpr(E); E->setProtocol(cast(Reader.GetDecl(Record[Idx++]))); - E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setAtLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { VisitExpr(E); E->setDecl(cast(Reader.GetDecl(Record[Idx++]))); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); E->setBase(Reader.ReadSubExpr()); E->setIsArrow(Record[Idx++]); E->setIsFreeIvar(Record[Idx++]); @@ -828,7 +842,7 @@ void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { VisitExpr(E); E->setProperty(cast(Reader.GetDecl(Record[Idx++]))); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); E->setBase(Reader.ReadSubExpr()); } @@ -842,8 +856,8 @@ void ASTStmtReader::VisitObjCImplicitSetterGetterRefExpr( E->setInterfaceDecl( cast_or_null(Reader.GetDecl(Record[Idx++]))); E->setBase(Reader.ReadSubExpr()); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); + E->setClassLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { @@ -858,13 +872,13 @@ void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { break; case ObjCMessageExpr::Class: - E->setClassReceiver(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + E->setClassReceiver(GetTypeSourceInfo(Record, Idx)); break; case ObjCMessageExpr::SuperClass: case ObjCMessageExpr::SuperInstance: { QualType T = Reader.GetType(Record[Idx++]); - SourceLocation SuperLoc = SourceLocation::getFromRawEncoding(Record[Idx++]); + SourceLocation SuperLoc = ReadSourceLocation(Record, Idx); E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance); break; } @@ -877,8 +891,8 @@ void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { else E->setSelector(Reader.GetSelector(Record, Idx)); - E->setLeftLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRightLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLeftLoc(ReadSourceLocation(Record, Idx)); + E->setRightLoc(ReadSourceLocation(Record, Idx)); for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) E->setArg(I, Reader.ReadSubExpr()); @@ -886,7 +900,7 @@ void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { void ASTStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) { VisitExpr(E); - E->setLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { @@ -894,22 +908,22 @@ void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { S->setElement(Reader.ReadSubStmt()); S->setCollection(Reader.ReadSubExpr()); S->setBody(Reader.ReadSubStmt()); - S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setForLoc(ReadSourceLocation(Record, Idx)); + S->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { VisitStmt(S); S->setCatchBody(Reader.ReadSubStmt()); S->setCatchParamDecl(cast_or_null(Reader.GetDecl(Record[Idx++]))); - S->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setAtCatchLoc(ReadSourceLocation(Record, Idx)); + S->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { VisitStmt(S); S->setFinallyBody(Reader.ReadSubStmt()); - S->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setAtFinallyLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { @@ -923,20 +937,20 @@ void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { if (HasFinally) S->setFinallyStmt(Reader.ReadSubStmt()); - S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setAtTryLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { VisitStmt(S); S->setSynchExpr(Reader.ReadSubStmt()); S->setSynchBody(Reader.ReadSubStmt()); - S->setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setAtSynchronizedLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { VisitStmt(S); S->setThrowExpr(Reader.ReadSubStmt()); - S->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + S->setThrowLoc(ReadSourceLocation(Record, Idx)); } //===----------------------------------------------------------------------===// @@ -945,7 +959,7 @@ void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) { VisitStmt(S); - S->CatchLoc = Reader.ReadSourceLocation(Record, Idx); + S->CatchLoc = ReadSourceLocation(Record, Idx); S->ExceptionDecl = cast_or_null(Reader.GetDecl(Record[Idx++])); S->HandlerBlock = Reader.ReadSubStmt(); } @@ -954,7 +968,7 @@ void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) { VisitStmt(S); assert(Record[Idx] == S->getNumHandlers() && "NumStmtFields is wrong ?"); ++Idx; - S->TryLoc = Reader.ReadSourceLocation(Record, Idx); + S->TryLoc = ReadSourceLocation(Record, Idx); S->getStmts()[0] = Reader.ReadSubStmt(); for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i) S->getStmts()[i + 1] = Reader.ReadSubStmt(); @@ -973,7 +987,7 @@ void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) { for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) E->setArg(I, Reader.ReadSubExpr()); E->setConstructor(cast(Reader.GetDecl(Record[Idx++]))); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); E->setElidable(Record[Idx++]); E->setRequiresZeroInitialization(Record[Idx++]); E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]); @@ -981,13 +995,13 @@ void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) { void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { VisitCXXConstructExpr(E); - E->Type = Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx); - E->RParenLoc = Reader.ReadSourceLocation(Record, Idx); + E->Type = GetTypeSourceInfo(Record, Idx); + E->RParenLoc = ReadSourceLocation(Record, Idx); } void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { VisitExplicitCastExpr(E); - E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setOperatorLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) { @@ -1008,27 +1022,27 @@ void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) { void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { VisitExplicitCastExpr(E); - E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setTypeBeginLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { VisitExpr(E); E->setValue(Record[Idx++]); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { VisitExpr(E); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) { VisitExpr(E); - E->setSourceRange(Reader.ReadSourceRange(Record, Idx)); + E->setSourceRange(ReadSourceRange(Record, Idx)); if (E->isTypeOperand()) { // typeid(int) E->setTypeOperandSourceInfo( - Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + GetTypeSourceInfo(Record, Idx)); return; } @@ -1037,10 +1051,10 @@ void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) { } void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) { VisitExpr(E); - E->setSourceRange(Reader.ReadSourceRange(Record, Idx)); + E->setSourceRange(ReadSourceRange(Record, Idx)); if (E->isTypeOperand()) { // __uuidof(ComType) E->setTypeOperandSourceInfo( - Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + GetTypeSourceInfo(Record, Idx)); return; } @@ -1050,13 +1064,13 @@ void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) { void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) { VisitExpr(E); - E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setLocation(ReadSourceLocation(Record, Idx)); E->setImplicit(Record[Idx++]); } void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) { VisitExpr(E); - E->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setThrowLoc(ReadSourceLocation(Record, Idx)); E->setSubExpr(Reader.ReadSubExpr()); } @@ -1066,7 +1080,7 @@ void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { assert(Record[Idx] == E->Param.getInt() && "We messed up at creation ?"); ++Idx; // HasOtherExprStored and SubExpr was handled during creation. E->Param.setPointer(cast(Reader.GetDecl(Record[Idx++]))); - E->Loc = Reader.ReadSourceLocation(Record, Idx); + E->Loc = ReadSourceLocation(Record, Idx); } void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { @@ -1077,8 +1091,8 @@ void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { VisitExpr(E); - E->TypeInfo = Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx); - E->RParenLoc = SourceLocation::getFromRawEncoding(Record[Idx++]); + E->TypeInfo = GetTypeSourceInfo(Record, Idx); + E->RParenLoc = ReadSourceLocation(Record, Idx); } void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) { @@ -1093,13 +1107,13 @@ void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) { cast_or_null(Reader.GetDecl(Record[Idx++]))); E->setConstructor( cast_or_null(Reader.GetDecl(Record[Idx++]))); - E->AllocatedTypeInfo = Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx); + E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx); SourceRange TypeIdParens; - TypeIdParens.setBegin(SourceLocation::getFromRawEncoding(Record[Idx++])); - TypeIdParens.setEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); + TypeIdParens.setBegin(ReadSourceLocation(Record, Idx)); + TypeIdParens.setEnd(ReadSourceLocation(Record, Idx)); E->TypeIdParens = TypeIdParens; - E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); - E->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + E->setStartLoc(ReadSourceLocation(Record, Idx)); + E->setEndLoc(ReadSourceLocation(Record, Idx)); E->AllocateArgsArray(*Reader.getContext(), isArray, NumPlacementArgs, NumCtorArgs); @@ -1117,7 +1131,7 @@ void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) { E->ArrayFormAsWritten = Record[Idx++]; E->OperatorDelete = cast_or_null(Reader.GetDecl(Record[Idx++])); E->Argument = Reader.ReadSubExpr(); - E->Loc = Reader.ReadSourceLocation(Record, Idx); + E->Loc = ReadSourceLocation(Record, Idx); } void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { @@ -1125,18 +1139,18 @@ void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { E->setBase(Reader.ReadSubExpr()); E->setArrow(Record[Idx++]); - E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx)); + E->setOperatorLoc(ReadSourceLocation(Record, Idx)); E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); - E->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); - E->setScopeTypeInfo(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); - E->setColonColonLoc(Reader.ReadSourceLocation(Record, Idx)); - E->setTildeLoc(Reader.ReadSourceLocation(Record, Idx)); + E->setQualifierRange(ReadSourceRange(Record, Idx)); + E->setScopeTypeInfo(GetTypeSourceInfo(Record, Idx)); + E->setColonColonLoc(ReadSourceLocation(Record, Idx)); + E->setTildeLoc(ReadSourceLocation(Record, Idx)); IdentifierInfo *II = Reader.GetIdentifierInfo(Record, Idx); if (II) - E->setDestroyedType(II, Reader.ReadSourceLocation(Record, Idx)); + E->setDestroyedType(II, ReadSourceLocation(Record, Idx)); else - E->setDestroyedType(Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx)); + E->setDestroyedType(GetTypeSourceInfo(Record, Idx)); } void ASTStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) { @@ -1164,14 +1178,14 @@ ASTStmtReader::VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E){ E->setBase(Reader.ReadSubExpr()); E->setBaseType(Reader.GetType(Record[Idx++])); E->setArrow(Record[Idx++]); - E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx)); + E->setOperatorLoc(ReadSourceLocation(Record, Idx)); E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); - E->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); + E->setQualifierRange(ReadSourceRange(Record, Idx)); E->setFirstQualifierFoundInScope( cast_or_null(Reader.GetDecl(Record[Idx++]))); // FIXME: read whole DeclarationNameInfo. E->setMember(Reader.ReadDeclarationName(Record, Idx)); - E->setMemberLoc(Reader.ReadSourceLocation(Record, Idx)); + E->setMemberLoc(ReadSourceLocation(Record, Idx)); } void @@ -1187,8 +1201,8 @@ ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { // FIXME: read whole DeclarationNameInfo. E->setDeclName(Reader.ReadDeclarationName(Record, Idx)); - E->setLocation(Reader.ReadSourceLocation(Record, Idx)); - E->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); + E->setLocation(ReadSourceLocation(Record, Idx)); + E->setQualifierRange(ReadSourceRange(Record, Idx)); E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); } @@ -1199,9 +1213,9 @@ ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) { ++Idx; // NumArgs; for (unsigned I = 0, N = E->arg_size(); I != N; ++I) E->setArg(I, Reader.ReadSubExpr()); - E->Type = Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx); - E->setLParenLoc(Reader.ReadSourceLocation(Record, Idx)); - E->setRParenLoc(Reader.ReadSourceLocation(Record, Idx)); + E->Type = GetTypeSourceInfo(Record, Idx); + E->setLParenLoc(ReadSourceLocation(Record, Idx)); + E->setRParenLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) { @@ -1226,8 +1240,8 @@ void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) { // FIXME: read whole DeclarationNameInfo. E->setName(Reader.ReadDeclarationName(Record, Idx)); E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); - E->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); - E->setNameLoc(Reader.ReadSourceLocation(Record, Idx)); + E->setQualifierRange(ReadSourceRange(Record, Idx)); + E->setNameLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { @@ -1236,7 +1250,7 @@ void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { E->setHasUnresolvedUsing(Record[Idx++]); E->setBase(Reader.ReadSubExpr()); E->setBaseType(Reader.GetType(Record[Idx++])); - E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx)); + E->setOperatorLoc(ReadSourceLocation(Record, Idx)); } void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { @@ -1250,24 +1264,24 @@ void ASTStmtReader::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { VisitExpr(E); E->UTT = (UnaryTypeTrait)Record[Idx++]; E->Value = (bool)Record[Idx++]; - SourceRange Range = Reader.ReadSourceRange(Record, Idx); + SourceRange Range = ReadSourceRange(Record, Idx); E->Loc = Range.getBegin(); E->RParen = Range.getEnd(); - E->QueriedType = Reader.GetTypeSourceInfo(DeclsCursor, Record, Idx); + E->QueriedType = GetTypeSourceInfo(Record, Idx); } void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { VisitExpr(E); E->Value = (bool)Record[Idx++]; - E->Range = Reader.ReadSourceRange(Record, Idx); + E->Range = ReadSourceRange(Record, Idx); E->Operand = Reader.ReadSubExpr(); } -Stmt *ASTReader::ReadStmt(llvm::BitstreamCursor &Cursor) { +Stmt *ASTReader::ReadStmt(PerFileData &F) { switch (ReadingKind) { case Read_Decl: case Read_Type: - return ReadStmtFromStream(Cursor); + return ReadStmtFromStream(F); case Read_Stmt: return ReadSubStmt(); } @@ -1276,8 +1290,8 @@ Stmt *ASTReader::ReadStmt(llvm::BitstreamCursor &Cursor) { return 0; } -Expr *ASTReader::ReadExpr(llvm::BitstreamCursor &Cursor) { - return cast_or_null(ReadStmt(Cursor)); +Expr *ASTReader::ReadExpr(PerFileData &F) { + return cast_or_null(ReadStmt(F)); } Expr *ASTReader::ReadSubExpr() { @@ -1291,17 +1305,18 @@ Expr *ASTReader::ReadSubExpr() { // the stack, with expressions having operands removing those operands from the // stack. Evaluation terminates when we see a STMT_STOP record, and // the single remaining expression on the stack is our result. -Stmt *ASTReader::ReadStmtFromStream(llvm::BitstreamCursor &Cursor) { +Stmt *ASTReader::ReadStmtFromStream(PerFileData &F) { ReadingKindTracker ReadingKind(Read_Stmt, *this); - + llvm::BitstreamCursor &Cursor = F.DeclsCursor; + #ifndef NDEBUG unsigned PrevNumStmts = StmtStack.size(); #endif RecordData Record; unsigned Idx; - ASTStmtReader Reader(*this, Cursor, Record, Idx); + ASTStmtReader Reader(*this, F, Cursor, Record, Idx); Stmt::EmptyShell Empty; while (true) { @@ -1481,16 +1496,16 @@ Stmt *ASTReader::ReadStmtFromStream(llvm::BitstreamCursor &Cursor) { SourceRange QualifierRange; if (Record[Idx++]) { // HasQualifier. NNS = ReadNestedNameSpecifier(Record, Idx); - QualifierRange = ReadSourceRange(Record, Idx); + QualifierRange = ReadSourceRange(F, Record, Idx); } TemplateArgumentListInfo ArgInfo; unsigned NumTemplateArgs = Record[Idx++]; if (NumTemplateArgs) { - ArgInfo.setLAngleLoc(ReadSourceLocation(Record, Idx)); - ArgInfo.setRAngleLoc(ReadSourceLocation(Record, Idx)); + ArgInfo.setLAngleLoc(ReadSourceLocation(F, Record, Idx)); + ArgInfo.setRAngleLoc(ReadSourceLocation(F, Record, Idx)); for (unsigned i = 0; i != NumTemplateArgs; ++i) - ArgInfo.addArgument(ReadTemplateArgumentLoc(Cursor, Record, Idx)); + ArgInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Idx)); } NamedDecl *FoundD = cast_or_null(GetDecl(Record[Idx++])); @@ -1501,7 +1516,7 @@ Stmt *ASTReader::ReadStmtFromStream(llvm::BitstreamCursor &Cursor) { Expr *Base = ReadSubExpr(); ValueDecl *MemberD = cast(GetDecl(Record[Idx++])); // FIXME: read DeclarationNameLoc. - SourceLocation MemberLoc = ReadSourceLocation(Record, Idx); + SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx); DeclarationNameInfo MemberNameInfo(MemberD->getDeclName(), MemberLoc); bool IsArrow = Record[Idx++];