More refactoring of objc rewriter.

llvm-svn: 145867
This commit is contained in:
Fariborz Jahanian 2011-12-05 22:59:54 +00:00
parent 3277557741
commit 7b1866930e
1 changed files with 106 additions and 86 deletions

View File

@ -5784,7 +5784,9 @@ void RewriteObjC::RewriteRecordBody(RecordDecl *RD) {
/// HandleDeclInMainFile - This is called for each top-level decl defined in the /// HandleDeclInMainFile - This is called for each top-level decl defined in the
/// main file of the input. /// main file of the input.
void RewriteObjC::HandleDeclInMainFile(Decl *D) { void RewriteObjC::HandleDeclInMainFile(Decl *D) {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { switch (D->getKind()) {
case Decl::Function: {
FunctionDecl *FD = cast<FunctionDecl>(D);
if (FD->isOverloadedOperator()) if (FD->isOverloadedOperator())
return; return;
@ -5812,9 +5814,10 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
CurFunctionDef = 0; CurFunctionDef = 0;
CurFunctionDeclToDeclareForBlock = 0; CurFunctionDeclToDeclareForBlock = 0;
} }
return; break;
} }
if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { case Decl::ObjCMethod: {
ObjCMethodDecl *MD = cast<ObjCMethodDecl>(D);
if (CompoundStmt *Body = MD->getCompoundBody()) { if (CompoundStmt *Body = MD->getCompoundBody()) {
CurMethodDef = MD; CurMethodDef = MD;
CurrentBody = Body; CurrentBody = Body;
@ -5829,14 +5832,20 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
InsertBlockLiteralsWithinMethod(MD); InsertBlockLiteralsWithinMethod(MD);
CurMethodDef = 0; CurMethodDef = 0;
} }
break;
} }
if (ObjCImplementationDecl *CI = dyn_cast<ObjCImplementationDecl>(D)) case Decl::ObjCImplementation: {
ObjCImplementationDecl *CI = cast<ObjCImplementationDecl>(D);
ClassImplementation.push_back(CI); ClassImplementation.push_back(CI);
else if (ObjCCategoryImplDecl *CI = dyn_cast<ObjCCategoryImplDecl>(D)) break;
}
case Decl::ObjCCategoryImpl: {
ObjCCategoryImplDecl *CI = cast<ObjCCategoryImplDecl>(D);
CategoryImplementation.push_back(CI); CategoryImplementation.push_back(CI);
else if (isa<ObjCClassDecl>(D)) break;
llvm_unreachable("RewriteObjC::HandleDeclInMainFile - ObjCClassDecl"); }
else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { case Decl::Var: {
VarDecl *VD = cast<VarDecl>(D);
RewriteObjCQualifiedInterfaceTypes(VD); RewriteObjCQualifiedInterfaceTypes(VD);
if (isTopLevelBlockPointerType(VD->getType())) if (isTopLevelBlockPointerType(VD->getType()))
RewriteBlockPointerDecl(VD); RewriteBlockPointerDecl(VD);
@ -5861,8 +5870,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
delete PropParentMap; delete PropParentMap;
PropParentMap = 0; PropParentMap = 0;
} }
SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(), SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(), VD->getName());
VD->getName());
GlobalVarDecl = 0; GlobalVarDecl = 0;
// This is needed for blocks. // This is needed for blocks.
@ -5870,19 +5878,31 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
RewriteCastExpr(CE); RewriteCastExpr(CE);
} }
} }
return; break;
} }
case Decl::TypeAlias:
case Decl::Typedef: {
if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) { if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
if (isTopLevelBlockPointerType(TD->getUnderlyingType())) if (isTopLevelBlockPointerType(TD->getUnderlyingType()))
RewriteBlockPointerDecl(TD); RewriteBlockPointerDecl(TD);
else if (TD->getUnderlyingType()->isFunctionPointerType()) else if (TD->getUnderlyingType()->isFunctionPointerType())
CheckFunctionPointerDecl(TD->getUnderlyingType(), TD); CheckFunctionPointerDecl(TD->getUnderlyingType(), TD);
return;
} }
if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) { break;
}
case Decl::CXXRecord:
case Decl::Record: {
RecordDecl *RD = cast<RecordDecl>(D);
if (RD->isCompleteDefinition()) if (RD->isCompleteDefinition())
RewriteRecordBody(RD); RewriteRecordBody(RD);
return; break;
}
case Decl::ObjCClass: {
llvm_unreachable("RewriteObjC::HandleDeclInMainFile - ObjCClassDecl");
break;
}
default:
break;
} }
// Nothing yet. // Nothing yet.
} }