aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-10-16 22:51:17 +0000
committerChris Lattner <sabre@nondot.org>2007-10-16 22:51:17 +0000
commit674af9541256dc3ef803e3723027a8b028f1f7a2 (patch)
treec80cf95fa5a0ac8fddfe623d1259aeee526374bc
parent311ff02fae0392bee6abe7723cdf5a69b2899a47 (diff)
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
-rw-r--r--Driver/RewriteTest.cpp2
-rw-r--r--Parse/ParseObjc.cpp24
-rw-r--r--Rewrite/Rewriter.cpp10
-rw-r--r--Sema/Sema.h1
-rw-r--r--Sema/SemaExpr.cpp1
-rw-r--r--include/clang/AST/Expr.h10
-rw-r--r--include/clang/Parse/Action.h3
-rw-r--r--include/clang/Parse/Parser.h2
8 files changed, 33 insertions, 20 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index 731d6fe777..8a6d1df1b4 100644
--- a/Driver/RewriteTest.cpp
+++ b/Driver/RewriteTest.cpp
@@ -114,7 +114,7 @@ void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) {
printf("BLAH!");
}
- Rewrite.RemoveText(Exp->getEncLoc(), Size);
+ Rewrite.RemoveText(Exp->getAtLoc(), Size);
#endif
}
diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp
index 5412a6f570..4579650085 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -1125,16 +1125,16 @@ Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
}
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 @@ Parser::ExprResult Parser::ParseObjCStringLiteral() {
/// 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 @@ Parser::ExprResult Parser::ParseObjCEncodeExpression() {
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 0c50b4b4e4..87a5deaf1a 100644
--- a/Rewrite/Rewriter.cpp
+++ b/Rewrite/Rewriter.cpp
@@ -183,7 +183,17 @@ RewriteBuffer &Rewriter::getEditBuffer(unsigned FileID) {
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 9d587791b4..569891a454 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -440,6 +440,7 @@ public:
// 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 896b318d5d..37fd798568 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -1910,6 +1910,7 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string) {
}
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 10273529cd..1b932deedc 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -1071,16 +1071,16 @@ public:
/// 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 fdd30c0eb9..faadf17945 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -587,7 +587,8 @@ public:
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 02cbaa5590..bc249bb4df 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -362,7 +362,7 @@ private:
// Objective-C Expressions
ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
ExprResult ParseObjCStringLiteral();
- ExprResult ParseObjCEncodeExpression();
+ ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
ExprResult ParseObjCSelectorExpression();
ExprResult ParseObjCProtocolExpression();
ExprResult ParseObjCMessageExpression();