From 5b8968cc599eb6100bb73ae87be9d6cd2577ac9e Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 15 Jul 2011 16:25:15 +0000 Subject: [PATCH] Store bracket locations for array subscript expressions, from Erik Verbruggen! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135275 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 5 +++-- lib/Sema/SemaOverload.cpp | 11 ++++++++--- lib/Sema/TreeTransform.h | 23 ++++++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 11e384f5a2..c7f870725c 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -797,9 +797,10 @@ class DeclRefExpr : public Expr { void computeDependence(); public: - DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L) + DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L, + const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), - D(D), Loc(L) { + D(D), Loc(L), DNLoc(LocInfo) { DeclRefExprBits.HasQualifier = 0; DeclRefExprBits.HasExplicitTemplateArgs = 0; DeclRefExprBits.HasFoundDecl = 0; diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index b95b886efb..437b2b5c6d 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -38,8 +38,10 @@ using namespace sema; /// function. static ExprResult CreateFunctionRefExpr(Sema &S, FunctionDecl *Fn, - SourceLocation Loc = SourceLocation()) { - ExprResult E = S.Owned(new (S.Context) DeclRefExpr(Fn, Fn->getType(), VK_LValue, Loc)); + SourceLocation Loc = SourceLocation(), + const DeclarationNameLoc &LocInfo = DeclarationNameLoc()){ + ExprResult E = S.Owned(new (S.Context) DeclRefExpr(Fn, Fn->getType(), + VK_LValue, Loc, LocInfo)); E = S.DefaultFunctionArrayConversion(E.take()); if (E.isInvalid()) return ExprError(); @@ -8878,7 +8880,10 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, ResultTy = ResultTy.getNonLValueExprType(Context); // Build the actual expression node. - ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl, LLoc); + DeclarationNameLoc LocInfo; + LocInfo.CXXOperatorName.BeginOpNameLoc = LLoc.getRawEncoding(); + LocInfo.CXXOperatorName.EndOpNameLoc = RLoc.getRawEncoding(); + ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl, LLoc, LocInfo); if (FnExpr.isInvalid()) return ExprError(); diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 0530b5a172..fa87217821 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -8357,11 +8357,24 @@ TreeTransform::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); } - if (Op == OO_Subscript) - return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), - OpLoc, - First, - Second); + if (Op == OO_Subscript) { + SourceLocation LBrace; + SourceLocation RBrace; + + if (DeclRefExpr *DRE = dyn_cast(Callee)) { + DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); + LBrace = SourceLocation::getFromRawEncoding( + NameLoc.CXXOperatorName.BeginOpNameLoc); + RBrace = SourceLocation::getFromRawEncoding( + NameLoc.CXXOperatorName.EndOpNameLoc); + } else { + LBrace = Callee->getLocStart(); + RBrace = OpLoc; + } + + return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, + First, Second); + } // Create the overloaded operator invocation for binary operators. BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); -- 2.40.0