r362757 - Factor out duplicated code building a MemberExpr and marking it
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 16:24:19 PDT 2019
Author: rsmith
Date: Thu Jun 6 16:24:18 2019
New Revision: 362757
URL: http://llvm.org/viewvc/llvm-project?rev=362757&view=rev
Log:
Factor out duplicated code building a MemberExpr and marking it
referenced.
This reinstates r362563, reverted in r362597.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=362757&r1=362756&r2=362757&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jun 6 16:24:18 2019
@@ -4510,6 +4510,23 @@ public:
UnqualifiedId &Member,
Decl *ObjCImpDecl);
+ MemberExpr *
+ BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc,
+ const CXXScopeSpec *SS, SourceLocation TemplateKWLoc,
+ ValueDecl *Member, DeclAccessPair FoundDecl,
+ bool HadMultipleCandidates,
+ const DeclarationNameInfo &MemberNameInfo, QualType Ty,
+ ExprValueKind VK, ExprObjectKind OK,
+ const TemplateArgumentListInfo *TemplateArgs = nullptr);
+ MemberExpr *
+ BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc,
+ NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc,
+ ValueDecl *Member, DeclAccessPair FoundDecl,
+ bool HadMultipleCandidates,
+ const DeclarationNameInfo &MemberNameInfo, QualType Ty,
+ ExprValueKind VK, ExprObjectKind OK,
+ const TemplateArgumentListInfo *TemplateArgs = nullptr);
+
void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
FunctionDecl *FDecl,
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=362757&r1=362756&r2=362757&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Jun 6 16:24:18 2019
@@ -7189,15 +7189,12 @@ ExprResult Sema::BuildCXXMemberCallExpr(
}
}
- MemberExpr *ME = MemberExpr::Create(
- Context, Exp.get(), /*IsArrow=*/false, SourceLocation(),
- NestedNameSpecifierLoc(), SourceLocation(), Method,
- DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
- DeclarationNameInfo(), /*TemplateArgs=*/nullptr, Context.BoundMemberTy,
- VK_RValue, OK_Ordinary);
- if (HadMultipleCandidates)
- ME->setHadMultipleCandidates(true);
- MarkMemberReferenced(ME);
+ MemberExpr *ME =
+ BuildMemberExpr(Exp.get(), /*IsArrow=*/false, SourceLocation(),
+ NestedNameSpecifierLoc(), SourceLocation(), Method,
+ DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
+ HadMultipleCandidates, DeclarationNameInfo(),
+ Context.BoundMemberTy, VK_RValue, OK_Ordinary);
QualType ResultType = Method->getReturnType();
ExprValueKind VK = Expr::getValueKindForType(ResultType);
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=362757&r1=362756&r2=362757&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Thu Jun 6 16:24:18 2019
@@ -893,18 +893,31 @@ BuildMSPropertyRefExpr(Sema &S, Expr *Ba
NameInfo.getLoc());
}
-/// Build a MemberExpr AST node.
-static MemberExpr *BuildMemberExpr(
- Sema &SemaRef, ASTContext &C, Expr *Base, bool isArrow,
- SourceLocation OpLoc, const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
- ValueDecl *Member, DeclAccessPair FoundDecl,
- const DeclarationNameInfo &MemberNameInfo, QualType Ty, ExprValueKind VK,
- ExprObjectKind OK, const TemplateArgumentListInfo *TemplateArgs = nullptr) {
- assert((!isArrow || Base->isRValue()) && "-> base must be a pointer rvalue");
- MemberExpr *E = MemberExpr::Create(
- C, Base, isArrow, OpLoc, SS.getWithLocInContext(C), TemplateKWLoc, Member,
- FoundDecl, MemberNameInfo, TemplateArgs, Ty, VK, OK);
- SemaRef.MarkMemberReferenced(E);
+MemberExpr *Sema::BuildMemberExpr(
+ Expr *Base, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec *SS,
+ SourceLocation TemplateKWLoc, ValueDecl *Member, DeclAccessPair FoundDecl,
+ bool HadMultipleCandidates, const DeclarationNameInfo &MemberNameInfo,
+ QualType Ty, ExprValueKind VK, ExprObjectKind OK,
+ const TemplateArgumentListInfo *TemplateArgs) {
+ NestedNameSpecifierLoc NNS =
+ SS ? SS->getWithLocInContext(Context) : NestedNameSpecifierLoc();
+ return BuildMemberExpr(Base, IsArrow, OpLoc, NNS, TemplateKWLoc, Member,
+ FoundDecl, HadMultipleCandidates, MemberNameInfo, Ty,
+ VK, OK, TemplateArgs);
+}
+
+MemberExpr *Sema::BuildMemberExpr(
+ Expr *Base, bool IsArrow, SourceLocation OpLoc, NestedNameSpecifierLoc NNS,
+ SourceLocation TemplateKWLoc, ValueDecl *Member, DeclAccessPair FoundDecl,
+ bool HadMultipleCandidates, const DeclarationNameInfo &MemberNameInfo,
+ QualType Ty, ExprValueKind VK, ExprObjectKind OK,
+ const TemplateArgumentListInfo *TemplateArgs) {
+ assert((!IsArrow || Base->isRValue()) && "-> base must be a pointer rvalue");
+ MemberExpr *E = MemberExpr::Create(Context, Base, IsArrow, OpLoc, NNS,
+ TemplateKWLoc, Member, FoundDecl,
+ MemberNameInfo, TemplateArgs, Ty, VK, OK);
+ E->setHadMultipleCandidates(HadMultipleCandidates);
+ MarkMemberReferenced(E);
return E;
}
@@ -1115,10 +1128,10 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
OpLoc);
if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) {
- return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
- TemplateKWLoc, Var, FoundDecl, MemberNameInfo,
- Var->getType().getNonReferenceType(), VK_LValue,
- OK_Ordinary);
+ return BuildMemberExpr(BaseExpr, IsArrow, OpLoc, &SS, TemplateKWLoc, Var,
+ FoundDecl, /*MultipleCandidates=*/false,
+ MemberNameInfo, Var->getType().getNonReferenceType(),
+ VK_LValue, OK_Ordinary);
}
if (CXXMethodDecl *MemberFn = dyn_cast<CXXMethodDecl>(MemberDecl)) {
@@ -1132,24 +1145,25 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
type = MemberFn->getType();
}
- return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
- TemplateKWLoc, MemberFn, FoundDecl, MemberNameInfo,
- type, valueKind, OK_Ordinary);
+ return BuildMemberExpr(BaseExpr, IsArrow, OpLoc, &SS, TemplateKWLoc,
+ MemberFn, FoundDecl, /*MultipleCandidates=*/false,
+ MemberNameInfo, type, valueKind, OK_Ordinary);
}
assert(!isa<FunctionDecl>(MemberDecl) && "member function not C++ method?");
if (EnumConstantDecl *Enum = dyn_cast<EnumConstantDecl>(MemberDecl)) {
- return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
- TemplateKWLoc, Enum, FoundDecl, MemberNameInfo,
- Enum->getType(), VK_RValue, OK_Ordinary);
+ return BuildMemberExpr(BaseExpr, IsArrow, OpLoc, &SS, TemplateKWLoc, Enum,
+ FoundDecl, /*MultipleCandidates=*/false,
+ MemberNameInfo, Enum->getType(), VK_RValue,
+ OK_Ordinary);
}
if (VarTemplateDecl *VarTempl = dyn_cast<VarTemplateDecl>(MemberDecl)) {
if (VarDecl *Var = getVarTemplateSpecialization(
*this, VarTempl, TemplateArgs, MemberNameInfo, TemplateKWLoc))
- return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
- TemplateKWLoc, Var, FoundDecl, MemberNameInfo,
- Var->getType().getNonReferenceType(), VK_LValue,
- OK_Ordinary);
+ return BuildMemberExpr(
+ BaseExpr, IsArrow, OpLoc, &SS, TemplateKWLoc, Var, FoundDecl,
+ /*MultipleCandidates=*/false, MemberNameInfo,
+ Var->getType().getNonReferenceType(), VK_LValue, OK_Ordinary);
return ExprError();
}
@@ -1805,9 +1819,10 @@ Sema::BuildFieldReferenceExpr(Expr *Base
}
}
- return BuildMemberExpr(*this, Context, Base.get(), IsArrow, OpLoc, SS,
+ return BuildMemberExpr(Base.get(), IsArrow, OpLoc, &SS,
/*TemplateKWLoc=*/SourceLocation(), Field, FoundDecl,
- MemberNameInfo, MemberType, VK, OK);
+ /*MultipleCandidates=*/false, MemberNameInfo,
+ MemberType, VK, OK);
}
/// Builds an implicit member access expression. The current context
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=362757&r1=362756&r2=362757&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Jun 6 16:24:18 2019
@@ -13912,14 +13912,11 @@ Expr *Sema::FixOverloadedFunctionReferen
type = Context.BoundMemberTy;
}
- MemberExpr *ME = MemberExpr::Create(
- Context, Base, MemExpr->isArrow(), MemExpr->getOperatorLoc(),
+ return BuildMemberExpr(
+ Base, MemExpr->isArrow(), MemExpr->getOperatorLoc(),
MemExpr->getQualifierLoc(), MemExpr->getTemplateKeywordLoc(), Fn, Found,
- MemExpr->getMemberNameInfo(), TemplateArgs, type, valueKind,
- OK_Ordinary);
- ME->setHadMultipleCandidates(true);
- MarkMemberReferenced(ME);
- return ME;
+ /*HadMultipleCandidates=*/true, MemExpr->getMemberNameInfo(),
+ type, valueKind, OK_Ordinary, TemplateArgs);
}
llvm_unreachable("Invalid reference to overloaded function");
More information about the cfe-commits
mailing list