Improve the tracking of source locations for parentheses in constructor calls.

This adds them where missing, and traces them through PCH. We fix at least one
bug in the extents found by the Index library, and make a lot of refactoring
tools which care about the exact formulation of a constructor call easier to
write. Also some minor cleanups to more consistently follow the friend pattern
instead of the setter pattern when rebuilding a serialized AST.

Patch originally by Samuel Benzaquen.

llvm-svn: 117254
This commit is contained in:
Chandler Carruth 2010-10-25 08:47:36 +00:00
parent 01769904d3
commit 0171815ae1
10 changed files with 89 additions and 56 deletions

View File

@ -712,6 +712,7 @@ private:
CXXConstructorDecl *Constructor; CXXConstructorDecl *Constructor;
SourceLocation Loc; SourceLocation Loc;
SourceRange ParenRange;
bool Elidable : 1; bool Elidable : 1;
bool ZeroInitialization : 1; bool ZeroInitialization : 1;
unsigned ConstructKind : 2; unsigned ConstructKind : 2;
@ -724,7 +725,8 @@ protected:
CXXConstructorDecl *d, bool elidable, CXXConstructorDecl *d, bool elidable,
Expr **args, unsigned numargs, Expr **args, unsigned numargs,
bool ZeroInitialization = false, bool ZeroInitialization = false,
ConstructionKind ConstructKind = CK_Complete); ConstructionKind ConstructKind = CK_Complete,
SourceRange ParenRange = SourceRange());
/// \brief Construct an empty C++ construction expression. /// \brief Construct an empty C++ construction expression.
CXXConstructExpr(StmtClass SC, EmptyShell Empty) CXXConstructExpr(StmtClass SC, EmptyShell Empty)
@ -743,7 +745,8 @@ public:
CXXConstructorDecl *D, bool Elidable, CXXConstructorDecl *D, bool Elidable,
Expr **Args, unsigned NumArgs, Expr **Args, unsigned NumArgs,
bool ZeroInitialization = false, bool ZeroInitialization = false,
ConstructionKind ConstructKind = CK_Complete); ConstructionKind ConstructKind = CK_Complete,
SourceRange ParenRange = SourceRange());
CXXConstructorDecl* getConstructor() const { return Constructor; } CXXConstructorDecl* getConstructor() const { return Constructor; }
@ -800,6 +803,7 @@ public:
} }
virtual SourceRange getSourceRange() const; virtual SourceRange getSourceRange() const;
SourceRange getParenRange() const { return ParenRange; }
static bool classof(const Stmt *T) { static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXConstructExprClass || return T->getStmtClass() == CXXConstructExprClass ||
@ -872,20 +876,18 @@ public:
/// }; /// };
/// @endcode /// @endcode
class CXXTemporaryObjectExpr : public CXXConstructExpr { class CXXTemporaryObjectExpr : public CXXConstructExpr {
SourceLocation RParenLoc;
TypeSourceInfo *Type; TypeSourceInfo *Type;
public: public:
CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
TypeSourceInfo *Type, TypeSourceInfo *Type,
Expr **Args,unsigned NumArgs, Expr **Args,unsigned NumArgs,
SourceLocation rParenLoc, SourceRange parenRange,
bool ZeroInitialization = false); bool ZeroInitialization = false);
explicit CXXTemporaryObjectExpr(EmptyShell Empty) explicit CXXTemporaryObjectExpr(EmptyShell Empty)
: CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
TypeSourceInfo *getTypeSourceInfo() const { return Type; } TypeSourceInfo *getTypeSourceInfo() const { return Type; }
SourceLocation getRParenLoc() const { return RParenLoc; }
virtual SourceRange getSourceRange() const; virtual SourceRange getSourceRange() const;
@ -974,6 +976,8 @@ class CXXNewExpr : public Expr {
SourceLocation StartLoc; SourceLocation StartLoc;
SourceLocation EndLoc; SourceLocation EndLoc;
SourceLocation ConstructorLParen;
SourceLocation ConstructorRParen;
friend class ASTStmtReader; friend class ASTStmtReader;
public: public:
@ -984,7 +988,9 @@ public:
Expr **constructorArgs, unsigned numConsArgs, Expr **constructorArgs, unsigned numConsArgs,
FunctionDecl *operatorDelete, QualType ty, FunctionDecl *operatorDelete, QualType ty,
TypeSourceInfo *AllocatedTypeInfo, TypeSourceInfo *AllocatedTypeInfo,
SourceLocation startLoc, SourceLocation endLoc); SourceLocation startLoc, SourceLocation endLoc,
SourceLocation constructorLParen,
SourceLocation constructorRParen);
explicit CXXNewExpr(EmptyShell Shell) explicit CXXNewExpr(EmptyShell Shell)
: Expr(CXXNewExprClass, Shell), SubExprs(0) { } : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
@ -1080,12 +1086,12 @@ public:
const_arg_iterator raw_arg_begin() const { return SubExprs; } const_arg_iterator raw_arg_begin() const { return SubExprs; }
const_arg_iterator raw_arg_end() const { return constructor_arg_end(); } const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
SourceLocation getStartLoc() const { return StartLoc; } SourceLocation getStartLoc() const { return StartLoc; }
void setStartLoc(SourceLocation L) { StartLoc = L; }
SourceLocation getEndLoc() const { return EndLoc; } SourceLocation getEndLoc() const { return EndLoc; }
void setEndLoc(SourceLocation L) { EndLoc = L; }
SourceLocation getConstructorLParen() const { return ConstructorLParen; }
SourceLocation getConstructorRParen() const { return ConstructorRParen; }
virtual SourceRange getSourceRange() const { virtual SourceRange getSourceRange() const {
return SourceRange(StartLoc, EndLoc); return SourceRange(StartLoc, EndLoc);
} }

View File

@ -2065,7 +2065,8 @@ public:
ExprResult ExprResult
BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
CXXConstructorDecl *Constructor, MultiExprArg Exprs, CXXConstructorDecl *Constructor, MultiExprArg Exprs,
bool RequiresZeroInit, unsigned ConstructKind); bool RequiresZeroInit, unsigned ConstructKind,
SourceRange ParenRange);
// FIXME: Can re remove this and have the above BuildCXXConstructExpr check if // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
// the constructor can be elidable? // the constructor can be elidable?
@ -2073,7 +2074,8 @@ public:
BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
CXXConstructorDecl *Constructor, bool Elidable, CXXConstructorDecl *Constructor, bool Elidable,
MultiExprArg Exprs, bool RequiresZeroInit, MultiExprArg Exprs, bool RequiresZeroInit,
unsigned ConstructKind); unsigned ConstructKind,
SourceRange ParenRange);
/// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
/// the default expr if needed. /// the default expr if needed.

View File

@ -113,14 +113,16 @@ CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Expr **constructorArgs, unsigned numConsArgs, Expr **constructorArgs, unsigned numConsArgs,
FunctionDecl *operatorDelete, QualType ty, FunctionDecl *operatorDelete, QualType ty,
TypeSourceInfo *AllocatedTypeInfo, TypeSourceInfo *AllocatedTypeInfo,
SourceLocation startLoc, SourceLocation endLoc) SourceLocation startLoc, SourceLocation endLoc,
SourceLocation constructorLParen,
SourceLocation constructorRParen)
: Expr(CXXNewExprClass, ty, ty->isDependentType(), ty->isDependentType()), : Expr(CXXNewExprClass, ty, ty->isDependentType(), ty->isDependentType()),
GlobalNew(globalNew), GlobalNew(globalNew),
Initializer(initializer), SubExprs(0), OperatorNew(operatorNew), Initializer(initializer), SubExprs(0), OperatorNew(operatorNew),
OperatorDelete(operatorDelete), Constructor(constructor), OperatorDelete(operatorDelete), Constructor(constructor),
AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens), AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens),
StartLoc(startLoc), EndLoc(endLoc) { StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen),
ConstructorRParen(constructorRParen) {
AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs); AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs);
unsigned i = 0; unsigned i = 0;
if (Array) if (Array)
@ -344,16 +346,10 @@ StmtIterator DependentScopeDeclRefExpr::child_end() {
return child_iterator(); return child_iterator();
} }
SourceRange CXXConstructExpr::getSourceRange() const { SourceRange CXXConstructExpr::getSourceRange() const {
// FIXME: Should we know where the parentheses are, if there are any? return ParenRange.isValid() ?
for (std::reverse_iterator<Stmt**> I(&Args[NumArgs]), E(&Args[0]); I!=E;++I) { SourceRange(Loc, ParenRange.getEnd()) :
// Ignore CXXDefaultExprs when computing the range, as they don't SourceRange(Loc);
// have a range.
if (!isa<CXXDefaultArgExpr>(*I))
return SourceRange(Loc, (*I)->getLocEnd());
}
return SourceRange(Loc);
} }
SourceRange CXXOperatorCallExpr::getSourceRange() const { SourceRange CXXOperatorCallExpr::getSourceRange() const {
@ -535,17 +531,19 @@ CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
TypeSourceInfo *Type, TypeSourceInfo *Type,
Expr **Args, Expr **Args,
unsigned NumArgs, unsigned NumArgs,
SourceLocation rParenLoc, SourceRange parenRange,
bool ZeroInitialization) bool ZeroInitialization)
: CXXConstructExpr(C, CXXTemporaryObjectExprClass, : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
Type->getType().getNonReferenceType(), Type->getType().getNonReferenceType(),
Type->getTypeLoc().getBeginLoc(), Type->getTypeLoc().getBeginLoc(),
Cons, false, Args, NumArgs, ZeroInitialization), Cons, false, Args, NumArgs, ZeroInitialization,
RParenLoc(rParenLoc), Type(Type) { CXXConstructExpr::CK_Complete, parenRange),
Type(Type) {
} }
SourceRange CXXTemporaryObjectExpr::getSourceRange() const { SourceRange CXXTemporaryObjectExpr::getSourceRange() const {
return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc); return SourceRange(Type->getTypeLoc().getBeginLoc(),
getParenRange().getEnd());
} }
CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
@ -553,10 +551,11 @@ CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
CXXConstructorDecl *D, bool Elidable, CXXConstructorDecl *D, bool Elidable,
Expr **Args, unsigned NumArgs, Expr **Args, unsigned NumArgs,
bool ZeroInitialization, bool ZeroInitialization,
ConstructionKind ConstructKind) { ConstructionKind ConstructKind,
SourceRange ParenRange) {
return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Elidable, Args, NumArgs, ZeroInitialization, Elidable, Args, NumArgs, ZeroInitialization,
ConstructKind); ConstructKind, ParenRange);
} }
CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
@ -564,12 +563,13 @@ CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
CXXConstructorDecl *D, bool elidable, CXXConstructorDecl *D, bool elidable,
Expr **args, unsigned numargs, Expr **args, unsigned numargs,
bool ZeroInitialization, bool ZeroInitialization,
ConstructionKind ConstructKind) ConstructionKind ConstructKind,
SourceRange ParenRange)
: Expr(SC, T, : Expr(SC, T,
T->isDependentType(), T->isDependentType(),
(T->isDependentType() || (T->isDependentType() ||
CallExpr::hasAnyValueDependentArguments(args, numargs))), CallExpr::hasAnyValueDependentArguments(args, numargs))),
Constructor(D), Loc(Loc), Elidable(elidable), Constructor(D), Loc(Loc), ParenRange(ParenRange), Elidable(elidable),
ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind), ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind),
Args(0), NumArgs(numargs) Args(0), NumArgs(numargs)
{ {

View File

@ -5365,7 +5365,8 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
CXXConstructorDecl *Constructor, CXXConstructorDecl *Constructor,
MultiExprArg ExprArgs, MultiExprArg ExprArgs,
bool RequiresZeroInit, bool RequiresZeroInit,
unsigned ConstructKind) { unsigned ConstructKind,
SourceRange ParenRange) {
bool Elidable = false; bool Elidable = false;
// C++0x [class.copy]p34: // C++0x [class.copy]p34:
@ -5386,7 +5387,7 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
return BuildCXXConstructExpr(ConstructLoc, DeclInitType, Constructor, return BuildCXXConstructExpr(ConstructLoc, DeclInitType, Constructor,
Elidable, move(ExprArgs), RequiresZeroInit, Elidable, move(ExprArgs), RequiresZeroInit,
ConstructKind); ConstructKind, ParenRange);
} }
/// BuildCXXConstructExpr - Creates a complete call to a constructor, /// BuildCXXConstructExpr - Creates a complete call to a constructor,
@ -5396,7 +5397,8 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
CXXConstructorDecl *Constructor, bool Elidable, CXXConstructorDecl *Constructor, bool Elidable,
MultiExprArg ExprArgs, MultiExprArg ExprArgs,
bool RequiresZeroInit, bool RequiresZeroInit,
unsigned ConstructKind) { unsigned ConstructKind,
SourceRange ParenRange) {
unsigned NumExprs = ExprArgs.size(); unsigned NumExprs = ExprArgs.size();
Expr **Exprs = (Expr **)ExprArgs.release(); Expr **Exprs = (Expr **)ExprArgs.release();
@ -5404,15 +5406,18 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
return Owned(CXXConstructExpr::Create(Context, DeclInitType, ConstructLoc, return Owned(CXXConstructExpr::Create(Context, DeclInitType, ConstructLoc,
Constructor, Elidable, Exprs, NumExprs, Constructor, Elidable, Exprs, NumExprs,
RequiresZeroInit, RequiresZeroInit,
static_cast<CXXConstructExpr::ConstructionKind>(ConstructKind))); static_cast<CXXConstructExpr::ConstructionKind>(ConstructKind),
ParenRange));
} }
bool Sema::InitializeVarWithConstructor(VarDecl *VD, bool Sema::InitializeVarWithConstructor(VarDecl *VD,
CXXConstructorDecl *Constructor, CXXConstructorDecl *Constructor,
MultiExprArg Exprs) { MultiExprArg Exprs) {
// FIXME: Provide the correct paren SourceRange when available.
ExprResult TempResult = ExprResult TempResult =
BuildCXXConstructExpr(VD->getLocation(), VD->getType(), Constructor, BuildCXXConstructExpr(VD->getLocation(), VD->getType(), Constructor,
move(Exprs), false, CXXConstructExpr::CK_Complete); move(Exprs), false, CXXConstructExpr::CK_Complete,
SourceRange());
if (TempResult.isInvalid()) if (TempResult.isInvalid())
return true; return true;

View File

@ -911,7 +911,8 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
ResultType, AllocTypeInfo, ResultType, AllocTypeInfo,
StartLoc, StartLoc,
Init ? ConstructorRParen : Init ? ConstructorRParen :
TypeRange.getEnd())); TypeRange.getEnd(),
ConstructorLParen, ConstructorRParen));
} }
/// CheckAllocatedType - Checks that a type is suitable as the allocated type /// CheckAllocatedType - Checks that a type is suitable as the allocated type
@ -1668,7 +1669,8 @@ static ExprResult BuildCXXCastArgument(Sema &S,
ExprResult Result = ExprResult Result =
S.BuildCXXConstructExpr(CastLoc, Ty, cast<CXXConstructorDecl>(Method), S.BuildCXXConstructExpr(CastLoc, Ty, cast<CXXConstructorDecl>(Method),
move_arg(ConstructorArgs), move_arg(ConstructorArgs),
/*ZeroInit*/ false, CXXConstructExpr::CK_Complete); /*ZeroInit*/ false, CXXConstructExpr::CK_Complete,
SourceRange());
if (Result.isInvalid()) if (Result.isInvalid())
return ExprError(); return ExprError();
@ -1801,7 +1803,8 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
ToType, SCS.CopyConstructor, ToType, SCS.CopyConstructor,
move_arg(ConstructorArgs), move_arg(ConstructorArgs),
/*ZeroInit*/ false, /*ZeroInit*/ false,
CXXConstructExpr::CK_Complete); CXXConstructExpr::CK_Complete,
SourceRange());
if (FromResult.isInvalid()) if (FromResult.isInvalid())
return true; return true;
From = FromResult.takeAs<Expr>(); From = FromResult.takeAs<Expr>();
@ -1812,7 +1815,8 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
ToType, SCS.CopyConstructor, ToType, SCS.CopyConstructor,
MultiExprArg(*this, &From, 1), MultiExprArg(*this, &From, 1),
/*ZeroInit*/ false, /*ZeroInit*/ false,
CXXConstructExpr::CK_Complete); CXXConstructExpr::CK_Complete,
SourceRange());
if (FromResult.isInvalid()) if (FromResult.isInvalid())
return true; return true;

View File

@ -3444,7 +3444,8 @@ static ExprResult CopyObject(Sema &S,
CurInit = S.BuildCXXConstructExpr(Loc, T, Constructor, Elidable, CurInit = S.BuildCXXConstructExpr(Loc, T, Constructor, Elidable,
move_arg(ConstructorArgs), move_arg(ConstructorArgs),
/*ZeroInit*/ false, /*ZeroInit*/ false,
CXXConstructExpr::CK_Complete); CXXConstructExpr::CK_Complete,
SourceRange());
// If we're supposed to bind temporaries, do so. // If we're supposed to bind temporaries, do so.
if (!CurInit.isInvalid() && shouldBindAsTemporary(Entity)) if (!CurInit.isInvalid() && shouldBindAsTemporary(Entity))
@ -3707,7 +3708,8 @@ InitializationSequence::Perform(Sema &S,
CurInit = S.BuildCXXConstructExpr(Loc, Step->Type, Constructor, CurInit = S.BuildCXXConstructExpr(Loc, Step->Type, Constructor,
move_arg(ConstructorArgs), move_arg(ConstructorArgs),
/*ZeroInit*/ false, /*ZeroInit*/ false,
CXXConstructExpr::CK_Complete); CXXConstructExpr::CK_Complete,
SourceRange());
if (CurInit.isInvalid()) if (CurInit.isInvalid())
return ExprError(); return ExprError();
@ -3870,7 +3872,7 @@ InitializationSequence::Perform(Sema &S,
TSInfo, TSInfo,
Exprs, Exprs,
NumExprs, NumExprs,
Kind.getParenRange().getEnd(), Kind.getParenRange(),
ConstructorInitRequiresZeroInit)); ConstructorInitRequiresZeroInit));
} else { } else {
CXXConstructExpr::ConstructionKind ConstructKind = CXXConstructExpr::ConstructionKind ConstructKind =
@ -3882,6 +3884,11 @@ InitializationSequence::Perform(Sema &S,
CXXConstructExpr::CK_NonVirtualBase; CXXConstructExpr::CK_NonVirtualBase;
} }
// Only get the parenthesis range if it is a direct construction.
SourceRange parenRange =
Kind.getKind() == InitializationKind::IK_Direct ?
Kind.getParenRange() : SourceRange();
// If the entity allows NRVO, mark the construction as elidable // If the entity allows NRVO, mark the construction as elidable
// unconditionally. // unconditionally.
if (Entity.allowsNRVO()) if (Entity.allowsNRVO())
@ -3889,13 +3896,15 @@ InitializationSequence::Perform(Sema &S,
Constructor, /*Elidable=*/true, Constructor, /*Elidable=*/true,
move_arg(ConstructorArgs), move_arg(ConstructorArgs),
ConstructorInitRequiresZeroInit, ConstructorInitRequiresZeroInit,
ConstructKind); ConstructKind,
parenRange);
else else
CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(), CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(),
Constructor, Constructor,
move_arg(ConstructorArgs), move_arg(ConstructorArgs),
ConstructorInitRequiresZeroInit, ConstructorInitRequiresZeroInit,
ConstructKind); ConstructKind,
parenRange);
} }
if (CurInit.isInvalid()) if (CurInit.isInvalid())
return ExprError(); return ExprError();

View File

@ -1688,7 +1688,8 @@ public:
bool IsElidable, bool IsElidable,
MultiExprArg Args, MultiExprArg Args,
bool RequiresZeroInit, bool RequiresZeroInit,
CXXConstructExpr::ConstructionKind ConstructKind) { CXXConstructExpr::ConstructionKind ConstructKind,
SourceRange ParenRange) {
ASTOwningVector<Expr*> ConvertedArgs(SemaRef); ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
ConvertedArgs)) ConvertedArgs))
@ -1696,7 +1697,8 @@ public:
return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
move_arg(ConvertedArgs), move_arg(ConvertedArgs),
RequiresZeroInit, ConstructKind); RequiresZeroInit, ConstructKind,
ParenRange);
} }
/// \brief Build a new object-construction expression. /// \brief Build a new object-construction expression.
@ -5725,7 +5727,8 @@ TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Constructor, E->isElidable(), Constructor, E->isElidable(),
move_arg(Args), move_arg(Args),
E->requiresZeroInitialization(), E->requiresZeroInitialization(),
E->getConstructionKind()); E->getConstructionKind(),
E->getParenRange());
} }
/// \brief Transform a C++ temporary-binding expression. /// \brief Transform a C++ temporary-binding expression.

View File

@ -1001,12 +1001,12 @@ void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
E->setElidable(Record[Idx++]); E->setElidable(Record[Idx++]);
E->setRequiresZeroInitialization(Record[Idx++]); E->setRequiresZeroInitialization(Record[Idx++]);
E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]); E->setConstructionKind((CXXConstructExpr::ConstructionKind)Record[Idx++]);
E->ParenRange = ReadSourceRange(Record, Idx);
} }
void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
VisitCXXConstructExpr(E); VisitCXXConstructExpr(E);
E->Type = GetTypeSourceInfo(Record, Idx); E->Type = GetTypeSourceInfo(Record, Idx);
E->RParenLoc = ReadSourceLocation(Record, Idx);
} }
void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
@ -1122,9 +1122,11 @@ void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
TypeIdParens.setBegin(ReadSourceLocation(Record, Idx)); TypeIdParens.setBegin(ReadSourceLocation(Record, Idx));
TypeIdParens.setEnd(ReadSourceLocation(Record, Idx)); TypeIdParens.setEnd(ReadSourceLocation(Record, Idx));
E->TypeIdParens = TypeIdParens; E->TypeIdParens = TypeIdParens;
E->setStartLoc(ReadSourceLocation(Record, Idx)); E->StartLoc = ReadSourceLocation(Record, Idx);
E->setEndLoc(ReadSourceLocation(Record, Idx)); E->EndLoc = ReadSourceLocation(Record, Idx);
E->ConstructorLParen = ReadSourceLocation(Record, Idx);
E->ConstructorRParen = ReadSourceLocation(Record, Idx);
E->AllocateArgsArray(*Reader.getContext(), isArray, NumPlacementArgs, E->AllocateArgsArray(*Reader.getContext(), isArray, NumPlacementArgs,
NumCtorArgs); NumCtorArgs);

View File

@ -978,13 +978,13 @@ void ASTStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Record.push_back(E->isElidable()); Record.push_back(E->isElidable());
Record.push_back(E->requiresZeroInitialization()); Record.push_back(E->requiresZeroInitialization());
Record.push_back(E->getConstructionKind()); // FIXME: stable encoding Record.push_back(E->getConstructionKind()); // FIXME: stable encoding
Writer.AddSourceRange(E->getParenRange(), Record);
Code = serialization::EXPR_CXX_CONSTRUCT; Code = serialization::EXPR_CXX_CONSTRUCT;
} }
void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { void ASTStmtWriter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
VisitCXXConstructExpr(E); VisitCXXConstructExpr(E);
Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record); Writer.AddTypeSourceInfo(E->getTypeSourceInfo(), Record);
Writer.AddSourceLocation(E->getRParenLoc(), Record);
Code = serialization::EXPR_CXX_TEMPORARY_OBJECT; Code = serialization::EXPR_CXX_TEMPORARY_OBJECT;
} }
@ -1113,6 +1113,8 @@ void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Writer.AddSourceRange(E->getTypeIdParens(), Record); Writer.AddSourceRange(E->getTypeIdParens(), Record);
Writer.AddSourceLocation(E->getStartLoc(), Record); Writer.AddSourceLocation(E->getStartLoc(), Record);
Writer.AddSourceLocation(E->getEndLoc(), Record); Writer.AddSourceLocation(E->getEndLoc(), Record);
Writer.AddSourceLocation(E->getConstructorLParen(), Record);
Writer.AddSourceLocation(E->getConstructorRParen(), Record);
for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end(); for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
I != e; ++I) I != e; ++I)
Writer.AddStmt(*I); Writer.AddStmt(*I);

View File

@ -215,7 +215,7 @@ void considered_harmful(int x) {
// CHECK: load-stmts.cpp:104:5: MemberRef=member:100:7 Extent=[104:5 - 104:11] // CHECK: load-stmts.cpp:104:5: MemberRef=member:100:7 Extent=[104:5 - 104:11]
// CHECK: load-stmts.cpp:104:12: DeclRefExpr=x:103:22 Extent=[104:12 - 104:13] // CHECK: load-stmts.cpp:104:12: DeclRefExpr=x:103:22 Extent=[104:12 - 104:13]
// CHECK: load-stmts.cpp:104:16: TypeRef=struct Base:94:8 Extent=[104:16 - 104:2 // CHECK: load-stmts.cpp:104:16: TypeRef=struct Base:94:8 Extent=[104:16 - 104:2
// CHECK: load-stmts.cpp:104:16: CallExpr= Extent=[104:16 - 104:22] // CHECK: load-stmts.cpp:104:16: CallExpr= Extent=[104:16 - 104:23]
// CHECK: load-stmts.cpp:104:21: DeclRefExpr=x:103:22 Extent=[104:21 - 104:22] // CHECK: load-stmts.cpp:104:21: DeclRefExpr=x:103:22 Extent=[104:21 - 104:22]
// CHECK: load-stmts.cpp:107:6: FunctionDecl=considered_harmful:107:6 (Definition) // CHECK: load-stmts.cpp:107:6: FunctionDecl=considered_harmful:107:6 (Definition)
// CHECK: load-stmts.cpp:108:2: LabelStmt=start_over Extent=[108:2 - 109:28] // CHECK: load-stmts.cpp:108:2: LabelStmt=start_over Extent=[108:2 - 109:28]