aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-01-07 23:12:05 +0000
committerDouglas Gregor <dgregor@apple.com>2010-01-07 23:12:05 +0000
commit828a197317288e3333b0ce6f5cedadd036e3531f (patch)
tree11b4307b3f971868641db8a8d84e4a20c5111516
parentf292fcf6bd5118499a830e0950429effeb373c28 (diff)
Add an "implicit" bit to CXXThisExpr, so that we can track
implicitness without losing track of the (logical or actual) location where "this" would occur in the source. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92958 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/ExprCXX.h10
-rw-r--r--lib/Sema/SemaExpr.cpp13
-rw-r--r--lib/Sema/SemaExprCXX.cpp3
-rw-r--r--lib/Sema/SemaOverload.cpp11
-rw-r--r--lib/Sema/TreeTransform.h8
5 files changed, 32 insertions, 13 deletions
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h
index d0e21f576d..55d5108e61 100644
--- a/include/clang/AST/ExprCXX.h
+++ b/include/clang/AST/ExprCXX.h
@@ -324,17 +324,21 @@ public:
/// @endcode
class CXXThisExpr : public Expr {
SourceLocation Loc;
-
+ bool Implicit : 1;
+
public:
- CXXThisExpr(SourceLocation L, QualType Type)
+ CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
: Expr(CXXThisExprClass, Type,
// 'this' is type-dependent if the class type of the enclosing
// member function is dependent (C++ [temp.dep.expr]p2)
Type->isDependentType(), Type->isDependentType()),
- Loc(L) { }
+ Loc(L), Implicit(isImplicit) { }
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
+ bool isImplicit() const { return Implicit; }
+ void setImplicit(bool I) { Implicit = I; }
+
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXThisExprClass;
}
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 730375e5cd..216e2e6098 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -565,7 +565,8 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
IsDerivedFrom(ThisType, AnonFieldType)) {
// Our base object expression is "this".
BaseObjectExpr = new (Context) CXXThisExpr(Loc,
- MD->getThisType(Context));
+ MD->getThisType(Context),
+ /*isImplicit=*/true);
BaseObjectIsPointer = true;
}
} else {
@@ -1366,7 +1367,10 @@ Sema::BuildImplicitMemberExpr(const CXXScopeSpec &SS,
QualType ThisType = cast<CXXMethodDecl>(CurContext)->getThisType(Context);
Expr *This = 0; // null signifies implicit access
if (IsKnownInstance) {
- This = new (Context) CXXThisExpr(SourceLocation(), ThisType);
+ SourceLocation Loc = R.getNameLoc();
+ if (SS.getRange().isValid())
+ Loc = SS.getRange().getBegin();
+ This = new (Context) CXXThisExpr(Loc, ThisType, /*isImplicit=*/true);
}
return BuildMemberReferenceExpr(ExprArg(*this, This), ThisType,
@@ -2541,7 +2545,10 @@ Sema::BuildMemberReferenceExpr(ExprArg Base, QualType BaseExprType,
if (!IsInstanceMember(MemberDecl))
return BuildDeclarationNameExpr(SS, R.getNameLoc(), MemberDecl);
- BaseExpr = new (Context) CXXThisExpr(SourceLocation(), BaseExprType);
+ SourceLocation Loc = R.getNameLoc();
+ if (SS.getRange().isValid())
+ Loc = SS.getRange().getBegin();
+ BaseExpr = new (Context) CXXThisExpr(Loc, BaseExprType,/*isImplicit=*/true);
}
bool ShouldCheckUse = true;
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 130b6e857b..fa1a62b14a 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -179,7 +179,8 @@ Action::OwningExprResult Sema::ActOnCXXThis(SourceLocation ThisLoc) {
if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext))
if (MD->isInstance())
return Owned(new (Context) CXXThisExpr(ThisLoc,
- MD->getThisType(Context)));
+ MD->getThisType(Context),
+ /*isImplicit=*/false));
return ExprError(Diag(ThisLoc, diag::err_invalid_this_use));
}
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index d2bd4eea98..423657e3cd 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -6064,9 +6064,14 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) {
MemExpr->getMemberLoc(),
Fn->getType(),
TemplateArgs);
- } else
- Base = new (Context) CXXThisExpr(SourceLocation(),
- MemExpr->getBaseType());
+ } else {
+ SourceLocation Loc = MemExpr->getMemberLoc();
+ if (MemExpr->getQualifier())
+ Loc = MemExpr->getQualifierRange().getBegin();
+ Base = new (Context) CXXThisExpr(Loc,
+ MemExpr->getBaseType(),
+ /*isImplicit=*/true);
+ }
} else
Base = MemExpr->getBase()->Retain();
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 208c8851e5..e966daa976 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -1344,9 +1344,11 @@ public:
/// semantic analysis. Subclasses may override this routine to provide
/// different behavior.
OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
- QualType ThisType) {
+ QualType ThisType,
+ bool isImplicit) {
return getSema().Owned(
- new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
+ new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
+ isImplicit));
}
/// \brief Build a new C++ throw expression.
@@ -4386,7 +4388,7 @@ TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
T == E->getType())
return SemaRef.Owned(E->Retain());
- return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
+ return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
}
template<typename Derived>