Skip to content

Commit

Permalink
Factor out duplicated code building a MemberExpr and marking it
Browse files Browse the repository at this point in the history
referenced.

This reinstates r362563, reverted in r362597.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362757 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
zygoloid committed Jun 6, 2019
1 parent ae3e0f3 commit 0f5e488
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 44 deletions.
17 changes: 17 additions & 0 deletions include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -4510,6 +4510,23 @@ class Sema {
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,
Expand Down
15 changes: 6 additions & 9 deletions lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7189,15 +7189,12 @@ ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl,
}
}

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);
Expand Down
71 changes: 43 additions & 28 deletions lib/Sema/SemaExprMember.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,18 +893,31 @@ BuildMSPropertyRefExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
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;
}

Expand Down Expand Up @@ -1115,10 +1128,10 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
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)) {
Expand All @@ -1132,24 +1145,25 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
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();
}

Expand Down Expand Up @@ -1805,9 +1819,10 @@ Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
}
}

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
Expand Down
11 changes: 4 additions & 7 deletions lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13912,14 +13912,11 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, DeclAccessPair Found,
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");
Expand Down

0 comments on commit 0f5e488

Please sign in to comment.