]> granicus.if.org Git - clang/commitdiff
Fix location processing of @encode: the range should include the @ sign.
authorChris Lattner <sabre@nondot.org>
Tue, 16 Oct 2007 22:51:17 +0000 (22:51 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 16 Oct 2007 22:51:17 +0000 (22:51 +0000)
@selector probably gets this wrong also.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43048 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp
Parse/ParseObjc.cpp
Rewrite/Rewriter.cpp
Sema/Sema.h
Sema/SemaExpr.cpp
include/clang/AST/Expr.h
include/clang/Parse/Action.h
include/clang/Parse/Parser.h

index 731d6fe7774caa62d844441f57c69fd81ac76f2b..8a6d1df1b4e7da4d8a29048d3cf2ea839d67acc9 100644 (file)
@@ -114,7 +114,7 @@ void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) {
     printf("BLAH!");
   }
   
-  Rewrite.RemoveText(Exp->getEncLoc(), Size);
+  Rewrite.RemoveText(Exp->getAtLoc(), Size);
 #endif
 }
 
index 5412a6f570b6ad684cdf4a29170a68a7d0a00a5a..4579650085fe228c0b774aec242705fed9ace1c6 100644 (file)
@@ -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);
 }
 
index 0c50b4b4e4dec8fd2149b9334a4a03c8983be500..87a5deaf1a9862a978facb5d7996bf4e677c4654 100644 (file)
@@ -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!");
index 9d587791b4fd43ab76e1115534bd25309a2e456c..569891a45412b97c28050f00a172eb8f7cbc368a 100644 (file)
@@ -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);
index 896b318d5df2ea7cad4c31188830efbedc5ba75e..37fd798568f3148a9995442877a6537f8c0fe484 100644 (file)
@@ -1910,6 +1910,7 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string) {
 }
 
 Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
+                                                 SourceLocation EncodeLoc,
                                                  SourceLocation LParenLoc,
                                                  TypeTy *Ty,
                                                  SourceLocation RParenLoc) {
index 10273529cdac59bcb97983cba526e957d405c878..1b932deedcc4b287d57f844b8e80f970d17bfc11 100644 (file)
@@ -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; }
 
index fdd30c0eb9f468356d1cfe0618f92530be562025..faadf17945d9d71d19b434ee670491ad1ede78e8 100644 (file)
@@ -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) {
index 02cbaa55900569b6410d9dff558f9370c4c2a848..bc249bb4df34cc8a399d056fdbdc7a42fc3e7d8a 100644 (file)
@@ -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();