diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1744,9 +1744,9 @@ return Macro; unsigned NextIndex = 1; // Skip identifier ID. - SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); - MacroInfo *MI = PP.AllocateMacroInfo(Loc); - MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); + SourceRange Range = ReadSourceRange(F, Record, NextIndex); + MacroInfo *MI = PP.AllocateMacroInfo(Range.getBegin()); + MI->setDefinitionEndLoc(Range.getEnd()); MI->setIsUsed(Record[NextIndex++]); MI->setUsedForHeaderGuard(Record[NextIndex++]); MacroTokens = MI->allocateTokens(Record[NextIndex++], @@ -6547,8 +6547,9 @@ } void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { - TL.setLBracketLoc(readSourceLocation()); - TL.setRBracketLoc(readSourceLocation()); + SourceRange BracketRange = Reader.readSourceRange(); + TL.setLBracketLoc(BracketRange.getBegin()); + TL.setRBracketLoc(BracketRange.getEnd()); if (Reader.readBool()) TL.setSizeExpr(Reader.readExpr()); else @@ -6614,11 +6615,13 @@ } void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { - TL.setLocalRangeBegin(readSourceLocation()); - TL.setLParenLoc(readSourceLocation()); - TL.setRParenLoc(readSourceLocation()); + SourceRange LocalRange = Reader.readSourceRange(); + TL.setLocalRangeBegin(LocalRange.getBegin()); + TL.setLocalRangeEnd(LocalRange.getBegin()); + SourceRange ParensRange = Reader.readSourceRange(); + TL.setLParenLoc(ParensRange.getBegin()); + TL.setRParenLoc(ParensRange.getEnd()); TL.setExceptionSpecRange(Reader.readSourceRange()); - TL.setLocalRangeEnd(readSourceLocation()); for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) { TL.setParam(i, Reader.readDeclAs()); } @@ -6646,14 +6649,12 @@ void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { TL.setTypeofLoc(readSourceLocation()); - TL.setLParenLoc(readSourceLocation()); - TL.setRParenLoc(readSourceLocation()); + TL.setParensRange(Reader.readSourceRange()); } void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { TL.setTypeofLoc(readSourceLocation()); - TL.setLParenLoc(readSourceLocation()); - TL.setRParenLoc(readSourceLocation()); + TL.setParensRange(Reader.readSourceRange()); TL.setUnderlyingTInfo(GetTypeSourceInfo()); } @@ -6664,8 +6665,7 @@ void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { TL.setKWLoc(readSourceLocation()); - TL.setLParenLoc(readSourceLocation()); - TL.setRParenLoc(readSourceLocation()); + TL.setParensRange(Reader.readSourceRange()); TL.setUnderlyingTInfo(GetTypeSourceInfo()); } @@ -6676,8 +6676,9 @@ TL.setTemplateKWLoc(readSourceLocation()); TL.setConceptNameLoc(readSourceLocation()); TL.setFoundDecl(Reader.readDeclAs()); - TL.setLAngleLoc(readSourceLocation()); - TL.setRAngleLoc(readSourceLocation()); + SourceRange AngleRange = Reader.readSourceRange(); + TL.setLAngleLoc(AngleRange.getBegin()); + TL.setRAngleLoc(AngleRange.getEnd()); for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) TL.setArgLocInfo(i, Reader.readTemplateArgumentLocInfo( TL.getTypePtr()->getArg(i).getKind())); @@ -6725,8 +6726,9 @@ TemplateSpecializationTypeLoc TL) { TL.setTemplateKeywordLoc(readSourceLocation()); TL.setTemplateNameLoc(readSourceLocation()); - TL.setLAngleLoc(readSourceLocation()); - TL.setRAngleLoc(readSourceLocation()); + SourceRange AngleRange = Reader.readSourceRange(); + TL.setLAngleLoc(AngleRange.getBegin()); + TL.setRAngleLoc(AngleRange.getEnd()); for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) TL.setArgLocInfo( i, @@ -6735,8 +6737,9 @@ } void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { - TL.setLParenLoc(readSourceLocation()); - TL.setRParenLoc(readSourceLocation()); + SourceRange ParenRange = Reader.readSourceRange(); + TL.setLParenLoc(ParenRange.getBegin()); + TL.setRParenLoc(ParenRange.getEnd()); } void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { @@ -6760,8 +6763,9 @@ TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); TL.setTemplateKeywordLoc(readSourceLocation()); TL.setTemplateNameLoc(readSourceLocation()); - TL.setLAngleLoc(readSourceLocation()); - TL.setRAngleLoc(readSourceLocation()); + SourceRange AngleRange = Reader.readSourceRange(); + TL.setLAngleLoc(AngleRange.getBegin()); + TL.setRAngleLoc(AngleRange.getEnd()); for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) TL.setArgLocInfo( I, @@ -6779,8 +6783,9 @@ void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { if (TL.getNumProtocols()) { - TL.setProtocolLAngleLoc(readSourceLocation()); - TL.setProtocolRAngleLoc(readSourceLocation()); + SourceRange ProtocolAngleRange = Reader.readSourceRange(); + TL.setProtocolLAngleLoc(ProtocolAngleRange.getBegin()); + TL.setProtocolRAngleLoc(ProtocolAngleRange.getEnd()); } for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) TL.setProtocolLoc(i, readSourceLocation()); @@ -6788,12 +6793,14 @@ void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { TL.setHasBaseTypeAsWritten(Reader.readBool()); - TL.setTypeArgsLAngleLoc(readSourceLocation()); - TL.setTypeArgsRAngleLoc(readSourceLocation()); + SourceRange TypeArgsAngleRange = Reader.readSourceRange(); + TL.setTypeArgsLAngleLoc(TypeArgsAngleRange.getBegin()); + TL.setTypeArgsRAngleLoc(TypeArgsAngleRange.getEnd()); for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) TL.setTypeArgTInfo(i, GetTypeSourceInfo()); - TL.setProtocolLAngleLoc(readSourceLocation()); - TL.setProtocolRAngleLoc(readSourceLocation()); + SourceRange ProtocolAngleRange = Reader.readSourceRange(); + TL.setProtocolLAngleLoc(ProtocolAngleRange.getBegin()); + TL.setProtocolRAngleLoc(ProtocolAngleRange.getEnd()); for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) TL.setProtocolLoc(i, readSourceLocation()); } @@ -6804,8 +6811,7 @@ void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { TL.setKWLoc(readSourceLocation()); - TL.setLParenLoc(readSourceLocation()); - TL.setRParenLoc(readSourceLocation()); + TL.setParensRange(Reader.readSourceRange()); } void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { @@ -7184,10 +7190,10 @@ const ASTTemplateArgumentListInfo * ASTRecordReader::readASTTemplateArgumentListInfo() { - SourceLocation LAngleLoc = readSourceLocation(); - SourceLocation RAngleLoc = readSourceLocation(); + SourceRange AngleRange = readSourceRange(); unsigned NumArgsAsWritten = readInt(); - TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); + TemplateArgumentListInfo TemplArgsInfo(AngleRange.getBegin(), + AngleRange.getEnd()); for (unsigned i = 0; i != NumArgsAsWritten; ++i) TemplArgsInfo.addArgument(readTemplateArgumentLoc()); return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo); @@ -8810,8 +8816,7 @@ TemplateParameterList * ASTRecordReader::readTemplateParameterList() { SourceLocation TemplateLoc = readSourceLocation(); - SourceLocation LAngleLoc = readSourceLocation(); - SourceLocation RAngleLoc = readSourceLocation(); + SourceRange AngleRange = readSourceRange(); unsigned NumParams = readInt(); SmallVector Params; @@ -8823,7 +8828,8 @@ Expr *RequiresClause = HasRequiresClause ? readExpr() : nullptr; TemplateParameterList *TemplateParams = TemplateParameterList::Create( - getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause); + getContext(), TemplateLoc, AngleRange.getBegin(), Params, + AngleRange.getEnd(), RequiresClause); return TemplateParams; } @@ -8896,25 +8902,24 @@ SourceLocation MemberOrEllipsisLoc = readSourceLocation(); Expr *Init = readExpr(); - SourceLocation LParenLoc = readSourceLocation(); - SourceLocation RParenLoc = readSourceLocation(); + SourceRange ParenRange = readSourceRange(); CXXCtorInitializer *BOMInit; if (Type == CTOR_INITIALIZER_BASE) - BOMInit = new (Context) - CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init, - RParenLoc, MemberOrEllipsisLoc); + BOMInit = new (Context) CXXCtorInitializer( + Context, TInfo, IsBaseVirtual, ParenRange.getBegin(), Init, + ParenRange.getEnd(), MemberOrEllipsisLoc); else if (Type == CTOR_INITIALIZER_DELEGATING) - BOMInit = new (Context) - CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc); + BOMInit = new (Context) CXXCtorInitializer( + Context, TInfo, ParenRange.getBegin(), Init, ParenRange.getEnd()); else if (Member) BOMInit = new (Context) - CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc, - Init, RParenLoc); + CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, + ParenRange.getBegin(), Init, ParenRange.getEnd()); else BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, - LParenLoc, Init, RParenLoc); + ParenRange.getBegin(), Init, ParenRange.getEnd()); if (/*IsWritten*/readBool()) { unsigned SourceOrder = readInt(); @@ -8992,9 +8997,12 @@ SourceRange ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, unsigned &Idx) { - SourceLocation beg = ReadSourceLocation(F, Record, Idx); - SourceLocation end = ReadSourceLocation(F, Record, Idx); - return SourceRange(beg, end); + SourceLocation::UIntTy Begin = Record[Idx++]; + SourceLocation::UIntTy Delta = Record[Idx++]; + return SourceRange( + TranslateSourceLocation(F, ReadUntranslatedSourceLocation(Begin)), + TranslateSourceLocation(F, + ReadUntranslatedSourceLocation(Begin + Delta))); } /// Read a floating-point value @@ -11934,8 +11942,9 @@ assert(C && "Unknown OMPClause type"); Visit(C); - C->setLocStart(Record.readSourceLocation()); - C->setLocEnd(Record.readSourceLocation()); + SourceRange Range = Record.readSourceRange(); + C->setLocStart(Range.getBegin()); + C->setLocEnd(Range.getEnd()); return C; } diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -963,7 +963,7 @@ // Template args as written. SmallVector TemplArgLocs; - SourceLocation LAngleLoc, RAngleLoc; + SourceRange AngleRange; bool HasTemplateArgumentsAsWritten = Record.readInt(); if (HasTemplateArgumentsAsWritten) { unsigned NumTemplateArgLocs = Record.readInt(); @@ -971,8 +971,7 @@ for (unsigned i = 0; i != NumTemplateArgLocs; ++i) TemplArgLocs.push_back(Record.readTemplateArgumentLoc()); - LAngleLoc = readSourceLocation(); - RAngleLoc = readSourceLocation(); + AngleRange = readSourceRange(); } SourceLocation POI = readSourceLocation(); @@ -980,7 +979,8 @@ ASTContext &C = Reader.getContext(); TemplateArgumentList *TemplArgList = TemplateArgumentList::CreateCopy(C, TemplArgs); - TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); + TemplateArgumentListInfo TemplArgsInfo(AngleRange.getBegin(), + AngleRange.getEnd()); for (unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i) TemplArgsInfo.addArgument(TemplArgLocs[i]); @@ -1038,8 +1038,9 @@ unsigned NumArgs = Record.readInt(); while (NumArgs--) TemplArgs.addArgument(Record.readTemplateArgumentLoc()); - TemplArgs.setLAngleLoc(readSourceLocation()); - TemplArgs.setRAngleLoc(readSourceLocation()); + SourceRange AngleRange = readSourceRange(); + TemplArgs.setLAngleLoc(AngleRange.getBegin()); + TemplArgs.setRAngleLoc(AngleRange.getEnd()); FD->setDependentTemplateSpecialization(Reader.getContext(), TemplDecls, TemplArgs); @@ -1138,11 +1139,10 @@ typeParams.push_back(typeParam); } - SourceLocation lAngleLoc = readSourceLocation(); - SourceLocation rAngleLoc = readSourceLocation(); + SourceRange angleRange = readSourceRange(); - return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc, - typeParams, rAngleLoc); + return ObjCTypeParamList::create(Reader.getContext(), angleRange.getBegin(), + typeParams, angleRange.getEnd()); } void ASTDeclReader::ReadObjCDefinitionData( @@ -1297,8 +1297,9 @@ void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { VisitObjCContainerDecl(CD); CD->setCategoryNameLoc(readSourceLocation()); - CD->setIvarLBraceLoc(readSourceLocation()); - CD->setIvarRBraceLoc(readSourceLocation()); + SourceRange IvarBraceRange = readSourceRange(); + CD->setIvarLBraceLoc(IvarBraceRange.getBegin()); + CD->setIvarRBraceLoc(IvarBraceRange.getEnd()); // Note that this category has been deserialized. We do this before // deserializing the interface declaration, so that it will consider this @@ -1368,8 +1369,9 @@ VisitObjCImplDecl(D); D->setSuperClass(readDeclAs()); D->SuperLoc = readSourceLocation(); - D->setIvarLBraceLoc(readSourceLocation()); - D->setIvarRBraceLoc(readSourceLocation()); + SourceRange IvarBraceRange = readSourceRange(); + D->setIvarLBraceLoc(IvarBraceRange.getBegin()); + D->setIvarRBraceLoc(IvarBraceRange.getEnd()); D->setHasNonZeroConstructors(Record.readInt()); D->setHasDestructors(Record.readInt()); D->NumIvarInitializers = Record.readInt(); diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -131,8 +131,9 @@ unsigned NumTemplateArgs) { SourceLocation TemplateKWLoc = readSourceLocation(); TemplateArgumentListInfo ArgInfo; - ArgInfo.setLAngleLoc(readSourceLocation()); - ArgInfo.setRAngleLoc(readSourceLocation()); + SourceRange AngleRange = readSourceRange(); + ArgInfo.setLAngleLoc(AngleRange.getBegin()); + ArgInfo.setRAngleLoc(AngleRange.getEnd()); for (unsigned i = 0; i != NumTemplateArgs; ++i) ArgInfo.addArgument(Record.readTemplateArgumentLoc()); Args.initializeFrom(TemplateKWLoc, ArgInfo, ArgsLocArray); @@ -155,8 +156,9 @@ while (NumStmts--) Stmts.push_back(Record.readSubStmt()); S->setStmts(Stmts); - S->CompoundStmtBits.LBraceLoc = readSourceLocation(); - S->RBraceLoc = readSourceLocation(); + SourceRange BraceRange = readSourceRange(); + S->CompoundStmtBits.LBraceLoc = BraceRange.getBegin(); + S->RBraceLoc = BraceRange.getEnd(); } void ASTStmtReader::VisitSwitchCase(SwitchCase *S) { @@ -227,8 +229,9 @@ S->setInit(Record.readSubStmt()); S->setIfLoc(readSourceLocation()); - S->setLParenLoc(readSourceLocation()); - S->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + S->setLParenLoc(ParenRange.getBegin()); + S->setRParenLoc(ParenRange.getEnd()); if (HasElse) S->setElseLoc(readSourceLocation()); } @@ -250,8 +253,9 @@ S->setConditionVariable(Record.getContext(), readDeclAs()); S->setSwitchLoc(readSourceLocation()); - S->setLParenLoc(readSourceLocation()); - S->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + S->setLParenLoc(ParenRange.getBegin()); + S->setRParenLoc(ParenRange.getEnd()); SwitchCase *PrevSC = nullptr; for (auto E = Record.size(); Record.getIdx() != E; ) { @@ -276,8 +280,9 @@ S->setConditionVariable(Record.getContext(), readDeclAs()); S->setWhileLoc(readSourceLocation()); - S->setLParenLoc(readSourceLocation()); - S->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + S->setLParenLoc(ParenRange.getBegin()); + S->setRParenLoc(ParenRange.getEnd()); } void ASTStmtReader::VisitDoStmt(DoStmt *S) { @@ -297,8 +302,9 @@ S->setInc(Record.readSubExpr()); S->setBody(Record.readSubStmt()); S->setForLoc(readSourceLocation()); - S->setLParenLoc(readSourceLocation()); - S->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + S->setLParenLoc(ParenRange.getBegin()); + S->setRParenLoc(ParenRange.getEnd()); } void ASTStmtReader::VisitGotoStmt(GotoStmt *S) { @@ -339,8 +345,9 @@ void ASTStmtReader::VisitDeclStmt(DeclStmt *S) { VisitStmt(S); - S->setStartLoc(readSourceLocation()); - S->setEndLoc(readSourceLocation()); + SourceRange Range = readSourceRange(); + S->setStartLoc(Range.getBegin()); + S->setEndLoc(Range.getEnd()); if (Record.size() - Record.getIdx() == 1) { // Single declaration @@ -565,8 +572,9 @@ VisitExpr(E); E->setLocation(readSourceLocation()); - E->setLParenLocation(readSourceLocation()); - E->setRParenLocation(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + E->setLParenLocation(ParenRange.getBegin()); + E->setRParenLocation(ParenRange.getEnd()); E->setTypeSourceInfo(Record.readTypeSourceInfo()); } @@ -680,8 +688,9 @@ void ASTStmtReader::VisitParenExpr(ParenExpr *E) { VisitExpr(E); - E->setLParen(readSourceLocation()); - E->setRParen(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + E->setLParen(ParenRange.getBegin()); + E->setRParen(ParenRange.getEnd()); E->setSubExpr(Record.readSubExpr()); } @@ -691,8 +700,9 @@ assert((NumExprs == E->getNumExprs()) && "Wrong NumExprs!"); for (unsigned I = 0; I != NumExprs; ++I) E->getTrailingObjects()[I] = Record.readSubStmt(); - E->LParenLoc = readSourceLocation(); - E->RParenLoc = readSourceLocation(); + SourceRange ParenRange = readSourceRange(); + E->LParenLoc = ParenRange.getBegin(); + E->RParenLoc = ParenRange.getEnd(); } void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) { @@ -719,22 +729,21 @@ E->setTypeSourceInfo(readTypeSourceInfo()); for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { auto Kind = static_cast(Record.readInt()); - SourceLocation Start = readSourceLocation(); - SourceLocation End = readSourceLocation(); + SourceRange Range = readSourceRange(); switch (Kind) { case OffsetOfNode::Array: - E->setComponent(I, OffsetOfNode(Start, Record.readInt(), End)); + E->setComponent( + I, OffsetOfNode(Range.getBegin(), Record.readInt(), Range.getEnd())); break; case OffsetOfNode::Field: - E->setComponent( - I, OffsetOfNode(Start, readDeclAs(), End)); + E->setComponent(I, OffsetOfNode(Range.getBegin(), readDeclAs(), + Range.getEnd())); break; case OffsetOfNode::Identifier: - E->setComponent( - I, - OffsetOfNode(Start, Record.readIdentifier(), End)); + E->setComponent(I, OffsetOfNode(Range.getBegin(), Record.readIdentifier(), + Range.getEnd())); break; case OffsetOfNode::Base: { @@ -954,16 +963,18 @@ for (unsigned I = 0; I < NumDims; ++I) SRs[I] = readSourceRange(); E->setBracketsRanges(SRs); - E->setLParenLoc(readSourceLocation()); - E->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + E->setLParenLoc(ParenRange.getBegin()); + E->setRParenLoc(ParenRange.getEnd()); } void ASTStmtReader::VisitOMPIteratorExpr(OMPIteratorExpr *E) { VisitExpr(E); unsigned NumIters = Record.readInt(); E->setIteratorKwLoc(readSourceLocation()); - E->setLParenLoc(readSourceLocation()); - E->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + E->setLParenLoc(ParenRange.getBegin()); + E->setRParenLoc(ParenRange.getEnd()); for (unsigned I = 0; I < NumIters; ++I) { E->setIteratorDeclaration(I, Record.readDeclRef()); E->setAssignmentLoc(I, readSourceLocation()); @@ -1141,8 +1152,9 @@ void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { VisitExplicitCastExpr(E); - E->setLParenLoc(readSourceLocation()); - E->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + E->setLParenLoc(ParenRange.getBegin()); + E->setRParenLoc(ParenRange.getEnd()); } void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { @@ -1164,8 +1176,9 @@ VisitExpr(E); if (auto *SyntForm = cast_or_null(Record.readSubStmt())) E->setSyntacticForm(SyntForm); - E->setLBraceLoc(readSourceLocation()); - E->setRBraceLoc(readSourceLocation()); + SourceRange BraceRange = readSourceRange(); + E->setLBraceLoc(BraceRange.getBegin()); + E->setRBraceLoc(BraceRange.getEnd()); bool isArrayFiller = Record.readInt(); Expr *filler = nullptr; if (isArrayFiller) { @@ -1221,19 +1234,18 @@ case DESIG_ARRAY: { unsigned Index = Record.readInt(); - SourceLocation LBracketLoc = readSourceLocation(); - SourceLocation RBracketLoc = readSourceLocation(); - Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc)); + SourceRange BracketRange = readSourceRange(); + Designators.push_back( + Designator(Index, BracketRange.getBegin(), BracketRange.getEnd())); break; } case DESIG_ARRAY_RANGE: { unsigned Index = Record.readInt(); - SourceLocation LBracketLoc = readSourceLocation(); + SourceRange BracketRange = readSourceRange(); SourceLocation EllipsisLoc = readSourceLocation(); - SourceLocation RBracketLoc = readSourceLocation(); - Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc, - RBracketLoc)); + Designators.push_back(Designator(Index, BracketRange.getBegin(), + EllipsisLoc, BracketRange.getEnd())); break; } } @@ -1293,8 +1305,9 @@ void ASTStmtReader::VisitStmtExpr(StmtExpr *E) { VisitExpr(E); - E->setLParenLoc(readSourceLocation()); - E->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + E->setLParenLoc(ParenRange.getBegin()); + E->setRParenLoc(ParenRange.getEnd()); E->setSubStmt(cast_or_null(Record.readSubStmt())); E->StmtExprBits.TemplateDepth = Record.readInt(); } @@ -1537,8 +1550,9 @@ else E->setSelector(Record.readSelector()); - E->LBracLoc = readSourceLocation(); - E->RBracLoc = readSourceLocation(); + SourceRange BracketRange = readSourceRange(); + E->LBracLoc = BracketRange.getBegin(); + E->RBracLoc = BracketRange.getEnd(); for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) E->setArg(I, Record.readSubExpr()); @@ -1769,8 +1783,9 @@ void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { VisitExplicitCastExpr(E); - E->setLParenLoc(readSourceLocation()); - E->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + E->setLParenLoc(ParenRange.getBegin()); + E->setRParenLoc(ParenRange.getEnd()); } void ASTStmtReader::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) { @@ -1987,8 +2002,9 @@ for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) E->setArg(I, Record.readSubExpr()); E->TSI = readTypeSourceInfo(); - E->setLParenLoc(readSourceLocation()); - E->setRParenLoc(readSourceLocation()); + SourceRange ParenRange = readSourceRange(); + E->setLParenLoc(ParenRange.getBegin()); + E->setRParenLoc(ParenRange.getEnd()); } void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) { @@ -2176,8 +2192,9 @@ void ASTStmtReader::VisitRecoveryExpr(RecoveryExpr *E) { VisitExpr(E); unsigned NumArgs = Record.readInt(); - E->BeginLoc = readSourceLocation(); - E->EndLoc = readSourceLocation(); + SourceRange Range = readSourceRange(); + E->BeginLoc = Range.getBegin(); + E->EndLoc = Range.getEnd(); assert((NumArgs + 0LL == std::distance(E->children().begin(), E->children().end())) && "Wrong NumArgs!"); @@ -2272,8 +2289,9 @@ void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) { Record.readOMPChildren(E->Data); - E->setLocStart(readSourceLocation()); - E->setLocEnd(readSourceLocation()); + SourceRange Range = readSourceRange(); + E->setLocStart(Range.getBegin()); + E->setLocEnd(Range.getEnd()); } void ASTStmtReader::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) { diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -309,8 +309,7 @@ } void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { - Record.AddSourceLocation(TL.getLBracketLoc()); - Record.AddSourceLocation(TL.getRBracketLoc()); + Record.AddSourceRange(TL.getBracketsRange()); Record.push_back(TL.getSizeExpr() ? 1 : 0); if (TL.getSizeExpr()) Record.AddStmt(TL.getSizeExpr()); @@ -336,9 +335,7 @@ void TypeLocWriter::VisitDependentAddressSpaceTypeLoc( DependentAddressSpaceTypeLoc TL) { Record.AddSourceLocation(TL.getAttrNameLoc()); - SourceRange range = TL.getAttrOperandParensRange(); - Record.AddSourceLocation(range.getBegin()); - Record.AddSourceLocation(range.getEnd()); + Record.AddSourceRange(TL.getAttrOperandParensRange()); Record.AddStmt(TL.getAttrExprOperand()); } @@ -362,9 +359,7 @@ void TypeLocWriter::VisitConstantMatrixTypeLoc(ConstantMatrixTypeLoc TL) { Record.AddSourceLocation(TL.getAttrNameLoc()); - SourceRange range = TL.getAttrOperandParensRange(); - Record.AddSourceLocation(range.getBegin()); - Record.AddSourceLocation(range.getEnd()); + Record.AddSourceRange(TL.getAttrOperandParensRange()); Record.AddStmt(TL.getAttrRowOperand()); Record.AddStmt(TL.getAttrColumnOperand()); } @@ -372,19 +367,15 @@ void TypeLocWriter::VisitDependentSizedMatrixTypeLoc( DependentSizedMatrixTypeLoc TL) { Record.AddSourceLocation(TL.getAttrNameLoc()); - SourceRange range = TL.getAttrOperandParensRange(); - Record.AddSourceLocation(range.getBegin()); - Record.AddSourceLocation(range.getEnd()); + Record.AddSourceRange(TL.getAttrOperandParensRange()); Record.AddStmt(TL.getAttrRowOperand()); Record.AddStmt(TL.getAttrColumnOperand()); } void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { - Record.AddSourceLocation(TL.getLocalRangeBegin()); - Record.AddSourceLocation(TL.getLParenLoc()); - Record.AddSourceLocation(TL.getRParenLoc()); + Record.AddSourceRange(TL.getLocalSourceRange()); + Record.AddSourceRange(TL.getParensRange()); Record.AddSourceRange(TL.getExceptionSpecRange()); - Record.AddSourceLocation(TL.getLocalRangeEnd()); for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) Record.AddDeclRef(TL.getParam(i)); } @@ -410,24 +401,21 @@ } void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { - if (TL.getNumProtocols()) { - Record.AddSourceLocation(TL.getProtocolLAngleLoc()); - Record.AddSourceLocation(TL.getProtocolRAngleLoc()); - } + if (TL.getNumProtocols()) + Record.AddSourceRange( + {TL.getProtocolLAngleLoc(), TL.getProtocolRAngleLoc()}); for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) Record.AddSourceLocation(TL.getProtocolLoc(i)); } void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { Record.AddSourceLocation(TL.getTypeofLoc()); - Record.AddSourceLocation(TL.getLParenLoc()); - Record.AddSourceLocation(TL.getRParenLoc()); + Record.AddSourceRange(TL.getParensRange()); } void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { Record.AddSourceLocation(TL.getTypeofLoc()); - Record.AddSourceLocation(TL.getLParenLoc()); - Record.AddSourceLocation(TL.getRParenLoc()); + Record.AddSourceRange(TL.getParensRange()); Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); } @@ -438,8 +426,7 @@ void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { Record.AddSourceLocation(TL.getKWLoc()); - Record.AddSourceLocation(TL.getLParenLoc()); - Record.AddSourceLocation(TL.getRParenLoc()); + Record.AddSourceRange(TL.getParensRange()); Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); } @@ -451,8 +438,7 @@ Record.AddSourceLocation(TL.getTemplateKWLoc()); Record.AddSourceLocation(TL.getConceptNameLoc()); Record.AddDeclRef(TL.getFoundDecl()); - Record.AddSourceLocation(TL.getLAngleLoc()); - Record.AddSourceLocation(TL.getRAngleLoc()); + Record.AddSourceRange({TL.getLAngleLoc(), TL.getRAngleLoc()}); for (unsigned I = 0; I < TL.getNumArgs(); ++I) Record.AddTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(), TL.getArgLocInfo(I)); @@ -501,16 +487,14 @@ TemplateSpecializationTypeLoc TL) { Record.AddSourceLocation(TL.getTemplateKeywordLoc()); Record.AddSourceLocation(TL.getTemplateNameLoc()); - Record.AddSourceLocation(TL.getLAngleLoc()); - Record.AddSourceLocation(TL.getRAngleLoc()); + Record.AddSourceRange({TL.getLAngleLoc(), TL.getRAngleLoc()}); for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), TL.getArgLoc(i).getLocInfo()); } void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { - Record.AddSourceLocation(TL.getLParenLoc()); - Record.AddSourceLocation(TL.getRParenLoc()); + Record.AddSourceRange({TL.getLParenLoc(), TL.getRParenLoc()}); } void TypeLocWriter::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) { @@ -538,8 +522,7 @@ Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); Record.AddSourceLocation(TL.getTemplateKeywordLoc()); Record.AddSourceLocation(TL.getTemplateNameLoc()); - Record.AddSourceLocation(TL.getLAngleLoc()); - Record.AddSourceLocation(TL.getRAngleLoc()); + Record.AddSourceRange({TL.getLAngleLoc(), TL.getRAngleLoc()}); for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), TL.getArgLoc(I).getLocInfo()); @@ -555,12 +538,10 @@ void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { Record.push_back(TL.hasBaseTypeAsWritten()); - Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); - Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); + Record.AddSourceRange({TL.getTypeArgsLAngleLoc(), TL.getTypeArgsRAngleLoc()}); for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); - Record.AddSourceLocation(TL.getProtocolLAngleLoc()); - Record.AddSourceLocation(TL.getProtocolRAngleLoc()); + Record.AddSourceRange({TL.getProtocolLAngleLoc(), TL.getProtocolRAngleLoc()}); for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) Record.AddSourceLocation(TL.getProtocolLoc(i)); } @@ -571,8 +552,7 @@ void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { Record.AddSourceLocation(TL.getKWLoc()); - Record.AddSourceLocation(TL.getLParenLoc()); - Record.AddSourceLocation(TL.getRParenLoc()); + Record.AddSourceRange(TL.getParensRange()); } void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { @@ -2442,8 +2422,7 @@ MacroOffsets[Index] = Offset; AddIdentifierRef(Name, Record); - AddSourceLocation(MI->getDefinitionLoc(), Record); - AddSourceLocation(MI->getDefinitionEndLoc(), Record); + AddSourceRange({MI->getDefinitionLoc(), MI->getDefinitionEndLoc()}, Record); Record.push_back(MI->isUsed()); Record.push_back(MI->isUsedForHeaderGuard()); Record.push_back(MI->getNumTokens()); @@ -5202,14 +5181,19 @@ Record.push_back(Raw); } -void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { +static SourceLocation::UIntTy encodeForWrite(SourceLocation Loc) { SourceLocation::UIntTy Raw = Loc.getRawEncoding(); - Record.push_back((Raw << 1) | (Raw >> (8 * sizeof(Raw) - 1))); + return SourceLocation::UIntTy{(Raw << 1) | (Raw >> (8 * sizeof(Raw) - 1))}; +} + +void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { + Record.push_back(encodeForWrite(Loc)); } void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { AddSourceLocation(Range.getBegin(), Record); - AddSourceLocation(Range.getEnd(), Record); + Record.push_back(encodeForWrite(Range.getEnd()) - + encodeForWrite(Range.getBegin())); } void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) { @@ -5594,8 +5578,8 @@ const TemplateParameterList *TemplateParams) { assert(TemplateParams && "No TemplateParams!"); AddSourceLocation(TemplateParams->getTemplateLoc()); - AddSourceLocation(TemplateParams->getLAngleLoc()); - AddSourceLocation(TemplateParams->getRAngleLoc()); + AddSourceRange( + {TemplateParams->getLAngleLoc(), TemplateParams->getRAngleLoc()}); Record->push_back(TemplateParams->size()); for (const auto &P : *TemplateParams) @@ -5620,8 +5604,8 @@ void ASTRecordWriter::AddASTTemplateArgumentListInfo( const ASTTemplateArgumentListInfo *ASTTemplArgList) { assert(ASTTemplArgList && "No ASTTemplArgList!"); - AddSourceLocation(ASTTemplArgList->LAngleLoc); - AddSourceLocation(ASTTemplArgList->RAngleLoc); + AddSourceRange( + {ASTTemplArgList->getLAngleLoc(), ASTTemplArgList->getRAngleLoc()}); Record->push_back(ASTTemplArgList->NumTemplateArgs); const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) @@ -5691,8 +5675,7 @@ Writer.AddSourceLocation(Init->getMemberLocation()); Writer.AddStmt(Init->getInit()); - Writer.AddSourceLocation(Init->getLParenLoc()); - Writer.AddSourceLocation(Init->getRParenLoc()); + Writer.AddSourceRange({Init->getLParenLoc(), Init->getRParenLoc()}); Writer.push_back(Init->isWritten()); if (Init->isWritten()) Writer.push_back(Init->getSourceOrder()); @@ -6180,8 +6163,7 @@ void OMPClauseWriter::writeClause(OMPClause *C) { Record.push_back(unsigned(C->getClauseKind())); Visit(C); - Record.AddSourceLocation(C->getBeginLoc()); - Record.AddSourceLocation(C->getEndLoc()); + Record.AddSourceRange({C->getBeginLoc(), C->getEndLoc()}); } void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -170,8 +170,8 @@ for (auto typeParam : *typeParams) { Record.AddDeclRef(typeParam); } - Record.AddSourceLocation(typeParams->getLAngleLoc()); - Record.AddSourceLocation(typeParams->getRAngleLoc()); + Record.AddSourceRange( + {typeParams->getLAngleLoc(), typeParams->getRAngleLoc()}); } /// Add to the record the first declaration from each module file that @@ -615,8 +615,9 @@ i!=e; ++i) Record.AddTemplateArgumentLoc( (*FTSInfo->TemplateArgumentsAsWritten)[i]); - Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc); - Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc); + Record.AddSourceRange( + {FTSInfo->TemplateArgumentsAsWritten->getLAngleLoc(), + FTSInfo->TemplateArgumentsAsWritten->getRAngleLoc()}); } Record.AddSourceLocation(FTSInfo->getPointOfInstantiation()); @@ -651,8 +652,7 @@ Record.push_back(DFTSInfo->getNumTemplateArgs()); for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i) Record.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i)); - Record.AddSourceLocation(DFTSInfo->getLAngleLoc()); - Record.AddSourceLocation(DFTSInfo->getRAngleLoc()); + Record.AddSourceRange({DFTSInfo->getLAngleLoc(), DFTSInfo->getRAngleLoc()}); break; } } @@ -835,8 +835,7 @@ void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { VisitObjCContainerDecl(D); Record.AddSourceLocation(D->getCategoryNameLoc()); - Record.AddSourceLocation(D->getIvarLBraceLoc()); - Record.AddSourceLocation(D->getIvarRBraceLoc()); + Record.AddSourceRange({D->getIvarLBraceLoc(), D->getIvarRBraceLoc()}); Record.AddDeclRef(D->getClassInterface()); AddObjCTypeParamList(D->TypeParamList); Record.push_back(D->protocol_size()); @@ -890,8 +889,7 @@ VisitObjCImplDecl(D); Record.AddDeclRef(D->getSuperClass()); Record.AddSourceLocation(D->getSuperClassLoc()); - Record.AddSourceLocation(D->getIvarLBraceLoc()); - Record.AddSourceLocation(D->getIvarRBraceLoc()); + Record.AddSourceRange({D->getIvarLBraceLoc(), D->getIvarRBraceLoc()}); Record.push_back(D->hasNonZeroConstructors()); Record.push_back(D->hasDestructors()); Record.push_back(D->NumIvarInitializers); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -62,8 +62,7 @@ void ASTStmtWriter::AddTemplateKWAndArgsInfo( const ASTTemplateKWAndArgsInfo &ArgInfo, const TemplateArgumentLoc *Args) { Record.AddSourceLocation(ArgInfo.TemplateKWLoc); - Record.AddSourceLocation(ArgInfo.LAngleLoc); - Record.AddSourceLocation(ArgInfo.RAngleLoc); + Record.AddSourceRange({ArgInfo.LAngleLoc, ArgInfo.RAngleLoc}); for (unsigned i = 0; i != ArgInfo.NumTemplateArgs; ++i) Record.AddTemplateArgumentLoc(Args[i]); } @@ -83,8 +82,7 @@ Record.push_back(S->size()); for (auto *CS : S->body()) Record.AddStmt(CS); - Record.AddSourceLocation(S->getLBracLoc()); - Record.AddSourceLocation(S->getRBracLoc()); + Record.AddSourceRange({S->getLBracLoc(), S->getRBracLoc()}); Code = serialization::STMT_COMPOUND; } @@ -152,8 +150,7 @@ Record.AddStmt(S->getInit()); Record.AddSourceLocation(S->getIfLoc()); - Record.AddSourceLocation(S->getLParenLoc()); - Record.AddSourceLocation(S->getRParenLoc()); + Record.AddSourceRange({S->getLParenLoc(), S->getRParenLoc()}); if (HasElse) Record.AddSourceLocation(S->getElseLoc()); @@ -177,8 +174,7 @@ Record.AddDeclRef(S->getConditionVariable()); Record.AddSourceLocation(S->getSwitchLoc()); - Record.AddSourceLocation(S->getLParenLoc()); - Record.AddSourceLocation(S->getRParenLoc()); + Record.AddSourceRange({S->getLParenLoc(), S->getRParenLoc()}); for (SwitchCase *SC = S->getSwitchCaseList(); SC; SC = SC->getNextSwitchCase()) @@ -198,8 +194,7 @@ Record.AddDeclRef(S->getConditionVariable()); Record.AddSourceLocation(S->getWhileLoc()); - Record.AddSourceLocation(S->getLParenLoc()); - Record.AddSourceLocation(S->getRParenLoc()); + Record.AddSourceRange({S->getLParenLoc(), S->getRParenLoc()}); Code = serialization::STMT_WHILE; } @@ -221,8 +216,7 @@ Record.AddStmt(S->getInc()); Record.AddStmt(S->getBody()); Record.AddSourceLocation(S->getForLoc()); - Record.AddSourceLocation(S->getLParenLoc()); - Record.AddSourceLocation(S->getRParenLoc()); + Record.AddSourceRange({S->getLParenLoc(), S->getRParenLoc()}); Code = serialization::STMT_FOR; } @@ -270,8 +264,7 @@ void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) { VisitStmt(S); - Record.AddSourceLocation(S->getBeginLoc()); - Record.AddSourceLocation(S->getEndLoc()); + Record.AddSourceRange({S->getBeginLoc(), S->getEndLoc()}); DeclGroupRef DG = S->getDeclGroup(); for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D) Record.AddDeclRef(*D); @@ -579,8 +572,7 @@ VisitExpr(E); Record.AddSourceLocation(E->getLocation()); - Record.AddSourceLocation(E->getLParenLocation()); - Record.AddSourceLocation(E->getRParenLocation()); + Record.AddSourceRange({E->getLParenLocation(), E->getRParenLocation()}); Record.AddTypeSourceInfo(E->getTypeSourceInfo()); Code = serialization::EXPR_SYCL_UNIQUE_STABLE_NAME; @@ -708,8 +700,7 @@ void ASTStmtWriter::VisitParenExpr(ParenExpr *E) { VisitExpr(E); - Record.AddSourceLocation(E->getLParen()); - Record.AddSourceLocation(E->getRParen()); + Record.AddSourceRange({E->getLParen(), E->getRParen()}); Record.AddStmt(E->getSubExpr()); Code = serialization::EXPR_PAREN; } @@ -719,8 +710,7 @@ Record.push_back(E->getNumExprs()); for (auto *SubStmt : E->exprs()) Record.AddStmt(SubStmt); - Record.AddSourceLocation(E->getLParenLoc()); - Record.AddSourceLocation(E->getRParenLoc()); + Record.AddSourceRange({E->getLParenLoc(), E->getRParenLoc()}); Code = serialization::EXPR_PAREN_LIST; } @@ -749,8 +739,7 @@ for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { const OffsetOfNode &ON = E->getComponent(I); Record.push_back(ON.getKind()); // FIXME: Stable encoding - Record.AddSourceLocation(ON.getSourceRange().getBegin()); - Record.AddSourceLocation(ON.getSourceRange().getEnd()); + Record.AddSourceRange(ON.getSourceRange()); switch (ON.getKind()) { case OffsetOfNode::Array: Record.push_back(ON.getArrayExprIndex()); @@ -825,8 +814,7 @@ Record.AddStmt(Dim); for (SourceRange SR : E->getBracketsRanges()) Record.AddSourceRange(SR); - Record.AddSourceLocation(E->getLParenLoc()); - Record.AddSourceLocation(E->getRParenLoc()); + Record.AddSourceRange({E->getLParenLoc(), E->getRParenLoc()}); Code = serialization::EXPR_OMP_ARRAY_SHAPING; } @@ -834,8 +822,7 @@ VisitExpr(E); Record.push_back(E->numOfIterators()); Record.AddSourceLocation(E->getIteratorKwLoc()); - Record.AddSourceLocation(E->getLParenLoc()); - Record.AddSourceLocation(E->getRParenLoc()); + Record.AddSourceRange({E->getLParenLoc(), E->getRParenLoc()}); for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) { Record.AddDeclRef(E->getIteratorDecl(I)); Record.AddSourceLocation(E->getAssignLoc(I)); @@ -874,8 +861,7 @@ void ASTStmtWriter::VisitRecoveryExpr(RecoveryExpr *E) { VisitExpr(E); Record.push_back(std::distance(E->children().begin(), E->children().end())); - Record.AddSourceLocation(E->getBeginLoc()); - Record.AddSourceLocation(E->getEndLoc()); + Record.AddSourceRange({E->getBeginLoc(), E->getEndLoc()}); for (Stmt *Child : E->children()) Record.AddStmt(Child); Code = serialization::EXPR_RECOVERY; @@ -1027,8 +1013,7 @@ void ASTStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) { VisitExplicitCastExpr(E); - Record.AddSourceLocation(E->getLParenLoc()); - Record.AddSourceLocation(E->getRParenLoc()); + Record.AddSourceRange({E->getLParenLoc(), E->getRParenLoc()}); Code = serialization::EXPR_CSTYLE_CAST; } @@ -1054,8 +1039,7 @@ // NOTE: only add the (possibly null) syntactic form. // No need to serialize the isSemanticForm flag and the semantic form. Record.AddStmt(E->getSyntacticForm()); - Record.AddSourceLocation(E->getLBraceLoc()); - Record.AddSourceLocation(E->getRBraceLoc()); + Record.AddSourceRange({E->getLBraceLoc(), E->getRBraceLoc()}); bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is(); Record.push_back(isArrayFiller); if (isArrayFiller) @@ -1098,15 +1082,13 @@ } else if (D.isArrayDesignator()) { Record.push_back(serialization::DESIG_ARRAY); Record.push_back(D.getFirstExprIndex()); - Record.AddSourceLocation(D.getLBracketLoc()); - Record.AddSourceLocation(D.getRBracketLoc()); + Record.AddSourceRange({D.getLBracketLoc(), D.getRBracketLoc()}); } else { assert(D.isArrayRangeDesignator() && "Unknown designator"); Record.push_back(serialization::DESIG_ARRAY_RANGE); Record.push_back(D.getFirstExprIndex()); - Record.AddSourceLocation(D.getLBracketLoc()); + Record.AddSourceRange({D.getLBracketLoc(), D.getRBracketLoc()}); Record.AddSourceLocation(D.getEllipsisLoc()); - Record.AddSourceLocation(D.getRBracketLoc()); } } Code = serialization::EXPR_DESIGNATED_INIT; @@ -1171,8 +1153,7 @@ void ASTStmtWriter::VisitStmtExpr(StmtExpr *E) { VisitExpr(E); Record.AddStmt(E->getSubStmt()); - Record.AddSourceLocation(E->getLParenLoc()); - Record.AddSourceLocation(E->getRParenLoc()); + Record.AddSourceRange({E->getLParenLoc(), E->getRParenLoc()}); Record.push_back(E->getTemplateDepth()); Code = serialization::EXPR_STMT; } @@ -1426,8 +1407,7 @@ Record.AddSelectorRef(E->getSelector()); } - Record.AddSourceLocation(E->getLeftLoc()); - Record.AddSourceLocation(E->getRightLoc()); + Record.AddSourceRange({E->getLeftLoc(), E->getRightLoc()}); for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); Arg != ArgEnd; ++Arg) @@ -1681,8 +1661,7 @@ void ASTStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { VisitExplicitCastExpr(E); - Record.AddSourceLocation(E->getLParenLoc()); - Record.AddSourceLocation(E->getRParenLoc()); + Record.AddSourceRange({E->getLParenLoc(), E->getRParenLoc()}); Code = serialization::EXPR_CXX_FUNCTIONAL_CAST; } @@ -1912,8 +1891,7 @@ ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI) Record.AddStmt(*ArgI); Record.AddTypeSourceInfo(E->getTypeSourceInfo()); - Record.AddSourceLocation(E->getLParenLoc()); - Record.AddSourceLocation(E->getRParenLoc()); + Record.AddSourceRange({E->getLParenLoc(), E->getRParenLoc()}); Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT; } @@ -2186,8 +2164,7 @@ void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) { Record.writeOMPChildren(E->Data); - Record.AddSourceLocation(E->getBeginLoc()); - Record.AddSourceLocation(E->getEndLoc()); + Record.AddSourceRange({E->getBeginLoc(), E->getEndLoc()}); } void ASTStmtWriter::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {