[cfe-commits] r45200 - in /cfe/trunk: Driver/RewriteTest.cpp include/clang/AST/Expr.h
Steve Naroff
snaroff at apple.com
Wed Dec 19 06:32:58 PST 2007
Author: snaroff
Date: Wed Dec 19 08:32:56 2007
New Revision: 45200
URL: http://llvm.org/viewvc/llvm-project?rev=45200&view=rev
Log:
Emit errors when attempting to rewrite ObjC expressions that originate from a macro expansion.
We plan on fixing this and removing this restriction after the break...
Modified:
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=45200&r1=45199&r2=45200&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Wed Dec 19 08:32:56 2007
@@ -644,7 +644,15 @@
if (IV->isFreeIvar()) {
Expr *Replacement = new MemberExpr(IV->getBase(), true, D,
IV->getLocation());
- Rewrite.ReplaceStmt(IV, Replacement);
+ if (Rewrite.ReplaceStmt(IV, Replacement)) {
+ // replacement failed.
+ unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
+ "rewriter could not replace sub-expression due to macros");
+ SourceRange Range = IV->getSourceRange();
+ Diags.Report(Context->getFullLoc(IV->getLocation()), DiagID, 0, 0, &Range, 1);
+ delete IV;
+ return Replacement;
+ }
delete IV;
return Replacement;
} else {
@@ -660,7 +668,15 @@
CastExpr *castExpr = new CastExpr(castT, IV->getBase(), SourceLocation());
// Don't forget the parens to enforce the proper binding.
ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), castExpr);
- Rewrite.ReplaceStmt(IV->getBase(), PE);
+ if (Rewrite.ReplaceStmt(IV->getBase(), PE)) {
+ // replacement failed.
+ unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
+ "rewriter could not replace sub-expression due to macros");
+ SourceRange Range = IV->getBase()->getSourceRange();
+ Diags.Report(Context->getFullLoc(IV->getBase()->getLocStart()), DiagID, 0, 0, &Range, 1);
+ delete IV->getBase();
+ return PE;
+ }
delete IV->getBase();
return PE;
}
@@ -943,7 +959,15 @@
SourceLocation()));
CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl,
&SelExprs[0], SelExprs.size());
- Rewrite.ReplaceStmt(Exp, SelExp);
+ if (Rewrite.ReplaceStmt(Exp, SelExp)) {
+ // replacement failed.
+ unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
+ "rewriter could not replace sub-expression due to macros");
+ SourceRange Range = Exp->getSourceRange();
+ Diags.Report(Context->getFullLoc(Exp->getAtLoc()), DiagID, 0, 0, &Range, 1);
+ delete SelExp;
+ return Exp;
+ }
delete Exp;
return SelExp;
}
@@ -1269,7 +1293,15 @@
&StrExpr[0], StrExpr.size());
// cast to NSConstantString *
CastExpr *cast = new CastExpr(Exp->getType(), call, SourceLocation());
- Rewrite.ReplaceStmt(Exp, cast);
+ if (Rewrite.ReplaceStmt(Exp, cast)) {
+ // replacement failed.
+ unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
+ "rewriter could not replace sub-expression due to macros");
+ SourceRange Range = Exp->getSourceRange();
+ Diags.Report(Context->getFullLoc(Exp->getAtLoc()), DiagID, 0, 0, &Range, 1);
+ delete cast;
+ return Exp;
+ }
delete Exp;
return cast;
#else
@@ -1634,12 +1666,28 @@
new ConditionalOperator(lessThanExpr, CE, STCE, returnType);
ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), CondExpr);
// Now do the actual rewrite.
- Rewrite.ReplaceStmt(Exp, PE);
+ if (Rewrite.ReplaceStmt(Exp, PE)) {
+ // replacement failed.
+ unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
+ "rewriter could not replace sub-expression due to macros");
+ SourceRange Range = Exp->getSourceRange();
+ Diags.Report(Context->getFullLoc(Exp->getLocStart()), DiagID, 0, 0, &Range, 1);
+ delete PE;
+ return Exp;
+ }
delete Exp;
return PE;
}
// Now do the actual rewrite.
- Rewrite.ReplaceStmt(Exp, CE);
+ if (Rewrite.ReplaceStmt(Exp, CE)) {
+ // replacement failed.
+ unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
+ "rewriter could not replace sub-expression due to macros");
+ SourceRange Range = Exp->getSourceRange();
+ Diags.Report(Context->getFullLoc(Exp->getLocStart()), DiagID, 0, 0, &Range, 1);
+ delete CE;
+ return Exp;
+ }
delete Exp;
return CE;
@@ -1660,7 +1708,15 @@
CallExpr *ProtoExp = SynthesizeCallToFunctionDecl(GetProtocolFunctionDecl,
&ProtoExprs[0],
ProtoExprs.size());
- Rewrite.ReplaceStmt(Exp, ProtoExp);
+ if (Rewrite.ReplaceStmt(Exp, ProtoExp)) {
+ // replacement failed.
+ unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
+ "rewriter could not replace sub-expression due to macros");
+ SourceRange Range = Exp->getSourceRange();
+ Diags.Report(Context->getFullLoc(Exp->getAtLoc()), DiagID, 0, 0, &Range, 1);
+ delete ProtoExp;
+ return Exp;
+ }
delete Exp;
return ProtoExp;
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=45200&r1=45199&r2=45200&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Dec 19 08:32:56 2007
@@ -1172,6 +1172,8 @@
const StringLiteral* getString() const { return String; }
+ SourceLocation getAtLoc() const { return AtLoc; }
+
virtual SourceRange getSourceRange() const {
return SourceRange(AtLoc, String->getLocEnd());
}
More information about the cfe-commits
mailing list