]> granicus.if.org Git - clang/commitdiff
Keep proper source location information for the type in an Objective-C
authorDouglas Gregor <dgregor@apple.com>
Tue, 20 Apr 2010 15:39:42 +0000 (15:39 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 20 Apr 2010 15:39:42 +0000 (15:39 +0000)
@encode expression.

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

include/clang/AST/ExprObjC.h
lib/Frontend/PCHReaderStmt.cpp
lib/Frontend/PCHWriterStmt.cpp
lib/Sema/Sema.h
lib/Sema/SemaExprObjC.cpp
lib/Sema/TreeTransform.h
test/Index/annotate-tokens.m
tools/CIndex/CIndex.cpp

index 6f43973a3e1dcdb9725c8497a3a9ed251f62ac94..9c28be76e528f91bf3f8ff30a42a0523223e02a6 100644 (file)
@@ -59,13 +59,14 @@ public:
 /// and behavior as StringLiteral except that the string initializer is obtained
 /// from ASTContext with the encoding type as an argument.
 class ObjCEncodeExpr : public Expr {
-  QualType EncType;
+  TypeSourceInfo *EncodedType;
   SourceLocation AtLoc, RParenLoc;
 public:
-  ObjCEncodeExpr(QualType T, QualType ET,
+  ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType,
                  SourceLocation at, SourceLocation rp)
-    : Expr(ObjCEncodeExprClass, T, ET->isDependentType(),
-           ET->isDependentType()), EncType(ET), AtLoc(at), RParenLoc(rp) {}
+    : Expr(ObjCEncodeExprClass, T, EncodedType->getType()->isDependentType(),
+           EncodedType->getType()->isDependentType()), 
+      EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {}
 
   explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
 
@@ -75,9 +76,12 @@ public:
   SourceLocation getRParenLoc() const { return RParenLoc; }
   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
-  QualType getEncodedType() const { return EncType; }
-  void setEncodedType(QualType T) { EncType = T; }
+  QualType getEncodedType() const { return EncodedType->getType(); }
 
+  TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
+  void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 
+    EncodedType = EncType; 
+  }
 
   virtual SourceRange getSourceRange() const {
     return SourceRange(AtLoc, RParenLoc);
index 2c954a68ac38985f1793991093444cdadcf808d2..60318dee77aed0af8f85c50336bdad94c4505e33 100644 (file)
@@ -725,7 +725,7 @@ unsigned PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
 
 unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
   VisitExpr(E);
-  E->setEncodedType(Reader.GetType(Record[Idx++]));
+  E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
   E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   return 0;
index 9a5417ca61020260d22609f8d715a5ae34818fd1..9c9f8911157de21e95008ba2bb3276d69952a358 100644 (file)
@@ -655,7 +655,7 @@ void PCHStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
 
 void PCHStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
   VisitExpr(E);
-  Writer.AddTypeRef(E->getEncodedType(), Record);
+  Writer.AddTypeSourceInfo(E->getEncodedTypeSourceInfo(), Record);
   Writer.AddSourceLocation(E->getAtLoc(), Record);
   Writer.AddSourceLocation(E->getRParenLoc(), Record);
   Code = pch::EXPR_OBJC_ENCODE;
index 0535923d6b97199fef7bfc433101e55aa1cfa50e..2578332743d7f44e5349d0bb69ac615777ab34de 100644 (file)
@@ -2411,7 +2411,7 @@ public:
                                             unsigned NumStrings);
 
   Expr *BuildObjCEncodeExpression(SourceLocation AtLoc,
-                                  QualType EncodedType,
+                                  TypeSourceInfo *EncodedTypeInfo,
                                   SourceLocation RParenLoc);
   CXXMemberCallExpr *BuildCXXMemberCallExpr(Expr *Exp,
                                             NamedDecl *FoundDecl,
index ad95f00d246939e57d1f3b7631d6670f5b693f93..ce06abec4d45a2f244771936ec0495af1542b8cf 100644 (file)
@@ -95,8 +95,9 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
 }
 
 Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
-                                      QualType EncodedType,
+                                      TypeSourceInfo *EncodedTypeInfo,
                                       SourceLocation RParenLoc) {
+  QualType EncodedType = EncodedTypeInfo->getType();
   QualType StrTy;
   if (EncodedType->isDependentType())
     StrTy = Context.DependentTy;
@@ -114,7 +115,7 @@ Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
                                          ArrayType::Normal, 0);
   }
 
-  return new (Context) ObjCEncodeExpr(StrTy, EncodedType, AtLoc, RParenLoc);
+  return new (Context) ObjCEncodeExpr(StrTy, EncodedTypeInfo, AtLoc, RParenLoc);
 }
 
 Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
@@ -123,9 +124,13 @@ Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
                                                  TypeTy *ty,
                                                  SourceLocation RParenLoc) {
   // FIXME: Preserve type source info ?
-  QualType EncodedType = GetTypeFromParser(ty);
+  TypeSourceInfo *TInfo;
+  QualType EncodedType = GetTypeFromParser(ty, &TInfo);
+  if (!TInfo)
+    TInfo = Context.getTrivialTypeSourceInfo(EncodedType,
+                                             PP.getLocForEndOfToken(LParenLoc));
 
-  return BuildObjCEncodeExpression(AtLoc, EncodedType, RParenLoc);
+  return BuildObjCEncodeExpression(AtLoc, TInfo, RParenLoc);
 }
 
 Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
index e2fdf66442d48d815eeb16c423d059b7b75a1ac4..ba714e886779285f20db4b4819d05268793e6ac6 100644 (file)
@@ -1688,9 +1688,9 @@ public:
   /// By default, performs semantic analysis to build the new expression.
   /// Subclasses may override this routine to provide different behavior.
   OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
-                                         QualType T,
+                                         TypeSourceInfo *EncodeTypeInfo,
                                          SourceLocation RParenLoc) {
-    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
+    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
                                                            RParenLoc));
   }
 
@@ -5464,18 +5464,17 @@ TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
 template<typename Derived>
 Sema::OwningExprResult
 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
-  // FIXME: poor source location
-  TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
-  QualType EncodedType = getDerived().TransformType(E->getEncodedType());
-  if (EncodedType.isNull())
+  TypeSourceInfo *EncodedTypeInfo
+    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
+  if (!EncodedTypeInfo)
     return SemaRef.ExprError();
 
   if (!getDerived().AlwaysRebuild() &&
-      EncodedType == E->getEncodedType())
+      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
     return SemaRef.Owned(E->Retain());
 
   return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
-                                            EncodedType,
+                                            EncodedTypeInfo,
                                             E->getRParenLoc());
 }
 
index 1badeb20be79a5dda82fb872b8a1f6db18a3a50e..ce399d34c6f2b89b4a8d3ca6f45d42b9a6d9d5c5 100644 (file)
@@ -5,10 +5,11 @@
 @implementation Foo
 - (int)compare:(Foo*)other {
   return 0;
+  (void)@encode(Foo);
 }
 @end
 
-// RUN: c-index-test -test-annotate-tokens=%s:1:1:9:5 %s | FileCheck %s
+// RUN: c-index-test -test-annotate-tokens=%s:1:1:10:5 %s | FileCheck %s
 // CHECK: Punctuation: "@" [1:1 - 1:2]
 // CHECK: Identifier: "interface" [1:2 - 1:11]
 // CHECK: Identifier: "Foo" [1:12 - 1:15] ObjCInterfaceDecl=Foo:1:12
 // CHECK: Keyword: "return" [7:3 - 7:9]
 // CHECK: Literal: "0" [7:10 - 7:11]
 // CHECK: Punctuation: ";" [7:11 - 7:12]
-// CHECK: Punctuation: "}" [8:1 - 8:2]
-// CHECK: Punctuation: "@" [9:1 - 9:2]
-// CHECK: Identifier: "end" [9:2 - 9:5]
+// CHECK: Punctuation: "(" [8:3 - 8:4]
+// CHECK: Keyword: "void" [8:4 - 8:8]
+// CHECK: Punctuation: ")" [8:8 - 8:9]
+// CHECK: Punctuation: "@" [8:9 - 8:10]
+// CHECK: Identifier: "encode" [8:10 - 8:16]
+// CHECK: Punctuation: "(" [8:16 - 8:17]
+// CHECK: Identifier: "Foo" [8:17 - 8:20] ObjCClassRef=Foo:1:12
+// CHECK: Punctuation: ")" [8:20 - 8:21]
+// CHECK: Punctuation: ";" [8:21 - 8:22]
+// CHECK: Punctuation: "}" [9:1 - 9:2]
+// CHECK: Punctuation: "@" [10:1 - 10:2]
+// CHECK: Identifier: "end" [10:2 - 10:5]
index 10c399591bb948d286be326bcf265aba7637118e..eb93a8f3017055c9f97925ef1c709be7e08475de 100644 (file)
@@ -305,6 +305,7 @@ public:
   bool VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
   bool VisitExplicitCastExpr(ExplicitCastExpr *E);
   bool VisitObjCMessageExpr(ObjCMessageExpr *E);
+  bool VisitObjCEncodeExpr(ObjCEncodeExpr *E);
   bool VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
 };
 
@@ -977,6 +978,11 @@ bool CursorVisitor::VisitObjCMessageExpr(ObjCMessageExpr *E) {
   return VisitExpr(E);
 }
 
+bool CursorVisitor::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
+  return Visit(E->getEncodedTypeSourceInfo()->getTypeLoc());
+}
+
+
 bool CursorVisitor::VisitAttributes(Decl *D) {
   for (const Attr *A = D->getAttrs(); A; A = A->getNext())
     if (Visit(MakeCXCursor(A, D, TU)))