Fix location processing of @encode: the range should include the @ sign.
@selector probably gets this wrong also.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43048 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index 731d6fe..8a6d1df 100644
--- a/Driver/RewriteTest.cpp
+++ b/Driver/RewriteTest.cpp
@@ -114,7 +114,7 @@
printf("BLAH!");
}
- Rewrite.RemoveText(Exp->getEncLoc(), Size);
+ Rewrite.RemoveText(Exp->getAtLoc(), Size);
#endif
}
diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp
index 5412a6f..4579650 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -1125,16 +1125,16 @@
}
switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
- case tok::objc_encode:
- return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression());
- case tok::objc_protocol:
- return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression());
- case tok::objc_selector:
- return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression());
- default:
- Diag(AtLoc, diag::err_unexpected_at);
- SkipUntil(tok::semi);
- break;
+ case tok::objc_encode:
+ return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
+ case tok::objc_protocol:
+ return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression());
+ case tok::objc_selector:
+ return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression());
+ default:
+ Diag(AtLoc, diag::err_unexpected_at);
+ SkipUntil(tok::semi);
+ break;
}
return 0;
@@ -1259,7 +1259,7 @@
/// objc-encode-expression:
/// @encode ( type-name )
-Parser::ExprResult Parser::ParseObjCEncodeExpression() {
+Parser::ExprResult Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) {
assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
SourceLocation EncLoc = ConsumeToken();
@@ -1275,7 +1275,7 @@
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
- return Actions.ParseObjCEncodeExpression(EncLoc, LParenLoc, Ty,
+ return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, Ty,
RParenLoc);
}
diff --git a/Rewrite/Rewriter.cpp b/Rewrite/Rewriter.cpp
index 0c50b4b..87a5dea 100644
--- a/Rewrite/Rewriter.cpp
+++ b/Rewrite/Rewriter.cpp
@@ -183,7 +183,17 @@
return I->second;
}
+/// RemoveText - Remove the specified text region. This method is only valid
+/// on a rewritable source location.
+void Rewriter::RemoveText(SourceLocation Start, unsigned Length) {
+ unsigned FileID;
+ unsigned StartOffs = getLocationOffsetAndFileID(Start, FileID);
+ getEditBuffer(FileID).RemoveText(StartOffs, Length);
+}
+/// ReplaceText - This method replaces a range of characters in the input
+/// buffer with a new string. This is effectively a combined "remove/insert"
+/// operation.
void Rewriter::ReplaceText(SourceLocation Start, unsigned OrigLength,
const char *NewStr, unsigned NewLength) {
assert(isRewritable(Start) && "Not a rewritable location!");
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 9d58779..569891a 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -440,6 +440,7 @@
// ParseObjCStringLiteral - Parse Objective-C string literals.
virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
+ SourceLocation EncodeLoc,
SourceLocation LParenLoc,
TypeTy *Ty,
SourceLocation RParenLoc);
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 896b318..37fd798 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -1910,6 +1910,7 @@
}
Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
+ SourceLocation EncodeLoc,
SourceLocation LParenLoc,
TypeTy *Ty,
SourceLocation RParenLoc) {
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 1027352..1b932de 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -1071,16 +1071,16 @@
/// ObjCEncodeExpr, used for @encode in Objective-C.
class ObjCEncodeExpr : public Expr {
QualType EncType;
- SourceLocation EncLoc, RParenLoc;
+ SourceLocation AtLoc, RParenLoc;
public:
ObjCEncodeExpr(QualType T, QualType ET,
- SourceLocation enc, SourceLocation rp)
- : Expr(ObjCEncodeExprClass, T), EncType(ET), EncLoc(enc), RParenLoc(rp) {}
+ SourceLocation at, SourceLocation rp)
+ : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {}
- SourceLocation getEncLoc() const { return EncLoc; }
+ SourceLocation getAtLoc() const { return AtLoc; }
SourceLocation getRParenLoc() const { return RParenLoc; }
- SourceRange getSourceRange() const { return SourceRange(EncLoc, RParenLoc); }
+ SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); }
QualType getEncodedType() const { return EncType; }
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index fdd30c0..faadf17 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -587,7 +587,8 @@
return 0;
}
- virtual ExprResult ParseObjCEncodeExpression(SourceLocation EncLoc,
+ virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
+ SourceLocation EncLoc,
SourceLocation LParenLoc,
TypeTy *Ty,
SourceLocation RParenLoc) {
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 02cbaa5..bc249bb 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -362,7 +362,7 @@
// Objective-C Expressions
ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
ExprResult ParseObjCStringLiteral();
- ExprResult ParseObjCEncodeExpression();
+ ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
ExprResult ParseObjCSelectorExpression();
ExprResult ParseObjCProtocolExpression();
ExprResult ParseObjCMessageExpression();