diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-08-27 20:50:59 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-08-27 20:50:59 +0000 |
commit | 95ed7784a335aca53b0c6e952cf31a4cfb633360 (patch) | |
tree | dccf10738853796c0c6669e8f882a2788f57f56c /lib/Rewrite/RewriteObjC.cpp | |
parent | 74cfb23d44de82f1932f0229b742805b0b3c3719 (diff) |
objective-c: Treat top-level objective-c declarations
, such as list of forward @class decls, in a DeclGroup
node. Deal with its consequence throught clang. This
is in preparation for more Sema work ahead. // rdar://8843851.
Feel free to reverse if it breaks something important
and I am unavailable.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138709 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/RewriteObjC.cpp')
-rw-r--r-- | lib/Rewrite/RewriteObjC.cpp | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp index 3ba7e90dac..ba518069eb 100644 --- a/lib/Rewrite/RewriteObjC.cpp +++ b/lib/Rewrite/RewriteObjC.cpp @@ -161,8 +161,13 @@ namespace { // Top Level Driver code. virtual void HandleTopLevelDecl(DeclGroupRef D) { - for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) + for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { + if (isa<ObjCClassDecl>((*I))) { + RewriteForwardClassDecl(D); + break; + } HandleTopLevelSingleDecl(*I); + } } void HandleTopLevelSingleDecl(Decl *D); void HandleDeclInMainFile(Decl *D); @@ -241,7 +246,7 @@ namespace { // Syntactic Rewriting. void RewriteInclude(); - void RewriteForwardClassDecl(ObjCClassDecl *Dcl); + void RewriteForwardClassDecl(DeclGroupRef D); void RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, ObjCImplementationDecl *IMD, ObjCCategoryImplDecl *CID); @@ -886,30 +891,28 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, InsertText(onePastSemiLoc, Setr); } -void RewriteObjC::RewriteForwardClassDecl(ObjCClassDecl *ClassDecl) { - // Get the start location and compute the semi location. - SourceLocation startLoc = ClassDecl->getLocation(); - const char *startBuf = SM->getCharacterData(startLoc); - const char *semiPtr = strchr(startBuf, ';'); - - // Translate to typedef's that forward reference structs with the same name - // as the class. As a convenience, we include the original declaration - // as a comment. +void RewriteObjC::RewriteForwardClassDecl(DeclGroupRef D) { + SourceLocation startLoc; std::string typedefString; - typedefString += "// @class "; - for (ObjCClassDecl::iterator I = ClassDecl->begin(), E = ClassDecl->end(); - I != E; ++I) { - ObjCInterfaceDecl *ForwardDecl = I->getInterface(); - typedefString += ForwardDecl->getNameAsString(); - if (I+1 != E) - typedefString += ", "; - else + const char *startBuf = 0; + const char *semiPtr = 0; + for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { + ObjCClassDecl *ClassDecl = cast<ObjCClassDecl>(*I); + ObjCInterfaceDecl *ForwardDecl = ClassDecl->getForwardInterfaceDecl(); + if (I == D.begin()) { + // Get the start location and compute the semi location. + startLoc = ClassDecl->getLocation(); + startBuf = SM->getCharacterData(startLoc); + semiPtr = strchr(startBuf, ';'); + typedefString += "// @class "; + typedefString += ForwardDecl->getNameAsString(); typedefString += ";\n"; - } + } + // Translate to typedef's that forward reference structs with the same name + // as the class. As a convenience, we include the original declaration + // as a comment. + - for (ObjCClassDecl::iterator I = ClassDecl->begin(), E = ClassDecl->end(); - I != E; ++I) { - ObjCInterfaceDecl *ForwardDecl = I->getInterface(); typedefString += "#ifndef _REWRITER_typedef_"; typedefString += ForwardDecl->getNameAsString(); typedefString += "\n"; @@ -5887,8 +5890,8 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) { ClassImplementation.push_back(CI); else if (ObjCCategoryImplDecl *CI = dyn_cast<ObjCCategoryImplDecl>(D)) CategoryImplementation.push_back(CI); - else if (ObjCClassDecl *CD = dyn_cast<ObjCClassDecl>(D)) - RewriteForwardClassDecl(CD); + else if (isa<ObjCClassDecl>(D)) + assert(false && "RewriteObjC::HandleDeclInMainFile - ObjCClassDecl"); else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { RewriteObjCQualifiedInterfaceTypes(VD); if (isTopLevelBlockPointerType(VD->getType())) |