From: Steve Naroff Date: Tue, 29 Jul 2008 18:15:38 +0000 (+0000) Subject: Fix incomplete implementation for rewriting protocol refs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f95b750534f2111f28434b282bcbd5656002816;p=clang Fix incomplete implementation for rewriting protocol refs. clang ObjC rewriter: no translation of id git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54163 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index 56f3b3d0f4..c454307310 100644 --- a/Driver/RewriteObjC.cpp +++ b/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(S)) return RewriteContinueStmt(StmtContinueStmt); + + // Need to check for protocol refs (id

, Foo

*) in variable decls and cast exprs. + if (DeclStmt *DS = dyn_cast(S)) + RewriteObjCQualifiedInterfaceTypes(DS->getDecl()); + if (CastExpr *CE = dyn_cast(S)) + RewriteObjCQualifiedInterfaceTypes(CE); if (isa(S) || isa(S) || isa(S) || isa(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;