diff options
author | Steve Naroff <snaroff@apple.com> | 2008-07-29 18:15:38 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-07-29 18:15:38 +0000 |
commit | 873bd8497a610ef8174c7516b6ea08d63808bf74 (patch) | |
tree | ea16f8d4d9cec3871e6f8e9aefc25ae35cfd59c9 | |
parent | 837fd272f8d3ed684a984fc92d09b6a0e5b407be (diff) | |
download | bcm5719-llvm-873bd8497a610ef8174c7516b6ea08d63808bf74.tar.gz bcm5719-llvm-873bd8497a610ef8174c7516b6ea08d63808bf74.zip |
Fix incomplete implementation for rewriting protocol refs.
<rdar://problem/6108127> clang ObjC rewriter: no translation of id <proto>
llvm-svn: 54163
-rw-r--r-- | clang/Driver/RewriteObjC.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/Driver/RewriteObjC.cpp b/clang/Driver/RewriteObjC.cpp index 56f3b3d0f44..c4543073106 100644 --- a/clang/Driver/RewriteObjC.cpp +++ b/clang/Driver/RewriteObjC.cpp @@ -163,6 +163,7 @@ namespace { 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 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { 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 @@ bool RewriteObjC::needToScanForQualifiers(QualType T) { 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; |