[cfe-commits] r54163 - /cfe/trunk/Driver/RewriteObjC.cpp

Steve Naroff snaroff at apple.com
Tue Jul 29 11:15:38 PDT 2008


Author: snaroff
Date: Tue Jul 29 13:15:38 2008
New Revision: 54163

URL: http://llvm.org/viewvc/llvm-project?rev=54163&view=rev
Log:
Fix incomplete implementation for rewriting protocol refs.

<rdar://problem/6108127> clang ObjC rewriter: no translation of id <proto>

Modified:
    cfe/trunk/Driver/RewriteObjC.cpp

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=54163&r1=54162&r2=54163&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Tue Jul 29 13:15:38 2008
@@ -163,6 +163,7 @@
     void RewriteProperties(unsigned nProperties, ObjCPropertyDecl **Properties);
     void RewriteFunctionDecl(FunctionDecl *FD);
     void RewriteObjCQualifiedInterfaceTypes(Decl *Dcl);
+    void RewriteObjCQualifiedInterfaceTypes(Expr *E);
     bool needToScanForQualifiers(QualType T);
     ObjCInterfaceDecl *isSuperReceiver(Expr *recExpr);
     QualType getSuperStructType();
@@ -1011,6 +1012,12 @@
   if (ContinueStmt *StmtContinueStmt =
       dyn_cast<ContinueStmt>(S))
     return RewriteContinueStmt(StmtContinueStmt);
+	
+  // Need to check for protocol refs (id <P>, Foo <P> *) in variable decls and cast exprs.
+  if (DeclStmt *DS = dyn_cast<DeclStmt>(S))
+    RewriteObjCQualifiedInterfaceTypes(DS->getDecl());
+  if (CastExpr *CE = dyn_cast<CastExpr>(S))
+    RewriteObjCQualifiedInterfaceTypes(CE);
   
   if (isa<SwitchStmt>(S) || isa<WhileStmt>(S) || 
       isa<DoStmt>(S) || isa<ForStmt>(S)) {
@@ -1598,6 +1605,24 @@
   return false;
 }
 
+void RewriteObjC::RewriteObjCQualifiedInterfaceTypes(Expr *E) {
+  QualType Type = E->getType();
+  if (needToScanForQualifiers(Type)) {
+    SourceLocation Loc = E->getLocStart();
+    const char *startBuf = SM->getCharacterData(Loc);
+    const char *endBuf = SM->getCharacterData(E->getLocEnd());
+    const char *startRef = 0, *endRef = 0;
+    if (scanForProtocolRefs(startBuf, endBuf, startRef, endRef)) {
+      // Get the locations of the startRef, endRef.
+      SourceLocation LessLoc = Loc.getFileLocWithOffset(startRef-startBuf);
+      SourceLocation GreaterLoc = Loc.getFileLocWithOffset(endRef-startBuf+1);
+      // Comment out the protocol references.
+      InsertText(LessLoc, "/*", 2);
+      InsertText(GreaterLoc, "*/", 2);
+    }
+  }
+}
+
 void RewriteObjC::RewriteObjCQualifiedInterfaceTypes(Decl *Dcl) {
   SourceLocation Loc;
   QualType Type;





More information about the cfe-commits mailing list