forked from OSchip/llvm-project
parent
3277557741
commit
7b1866930e
|
@ -5784,105 +5784,125 @@ 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()) {
|
||||||
if (FD->isOverloadedOperator())
|
case Decl::Function: {
|
||||||
return;
|
FunctionDecl *FD = cast<FunctionDecl>(D);
|
||||||
|
if (FD->isOverloadedOperator())
|
||||||
|
return;
|
||||||
|
|
||||||
// Since function prototypes don't have ParmDecl's, we check the function
|
// Since function prototypes don't have ParmDecl's, we check the function
|
||||||
// prototype. This enables us to rewrite function declarations and
|
// prototype. This enables us to rewrite function declarations and
|
||||||
// definitions using the same code.
|
// definitions using the same code.
|
||||||
RewriteBlocksInFunctionProtoType(FD->getType(), FD);
|
RewriteBlocksInFunctionProtoType(FD->getType(), FD);
|
||||||
|
|
||||||
// FIXME: If this should support Obj-C++, support CXXTryStmt
|
// FIXME: If this should support Obj-C++, support CXXTryStmt
|
||||||
if (CompoundStmt *Body = dyn_cast_or_null<CompoundStmt>(FD->getBody())) {
|
if (CompoundStmt *Body = dyn_cast_or_null<CompoundStmt>(FD->getBody())) {
|
||||||
CurFunctionDef = FD;
|
CurFunctionDef = FD;
|
||||||
CurFunctionDeclToDeclareForBlock = FD;
|
CurFunctionDeclToDeclareForBlock = FD;
|
||||||
CurrentBody = Body;
|
CurrentBody = Body;
|
||||||
Body =
|
Body =
|
||||||
cast_or_null<CompoundStmt>(RewriteFunctionBodyOrGlobalInitializer(Body));
|
cast_or_null<CompoundStmt>(RewriteFunctionBodyOrGlobalInitializer(Body));
|
||||||
FD->setBody(Body);
|
FD->setBody(Body);
|
||||||
CurrentBody = 0;
|
CurrentBody = 0;
|
||||||
if (PropParentMap) {
|
if (PropParentMap) {
|
||||||
delete PropParentMap;
|
delete PropParentMap;
|
||||||
PropParentMap = 0;
|
PropParentMap = 0;
|
||||||
|
}
|
||||||
|
// This synthesizes and inserts the block "impl" struct, invoke function,
|
||||||
|
// and any copy/dispose helper functions.
|
||||||
|
InsertBlockLiteralsWithinFunction(FD);
|
||||||
|
CurFunctionDef = 0;
|
||||||
|
CurFunctionDeclToDeclareForBlock = 0;
|
||||||
}
|
}
|
||||||
// This synthesizes and inserts the block "impl" struct, invoke function,
|
break;
|
||||||
// and any copy/dispose helper functions.
|
|
||||||
InsertBlockLiteralsWithinFunction(FD);
|
|
||||||
CurFunctionDef = 0;
|
|
||||||
CurFunctionDeclToDeclareForBlock = 0;
|
|
||||||
}
|
}
|
||||||
return;
|
case Decl::ObjCMethod: {
|
||||||
}
|
ObjCMethodDecl *MD = cast<ObjCMethodDecl>(D);
|
||||||
if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
|
if (CompoundStmt *Body = MD->getCompoundBody()) {
|
||||||
if (CompoundStmt *Body = MD->getCompoundBody()) {
|
CurMethodDef = MD;
|
||||||
CurMethodDef = MD;
|
CurrentBody = Body;
|
||||||
CurrentBody = Body;
|
Body =
|
||||||
Body =
|
cast_or_null<CompoundStmt>(RewriteFunctionBodyOrGlobalInitializer(Body));
|
||||||
cast_or_null<CompoundStmt>(RewriteFunctionBodyOrGlobalInitializer(Body));
|
MD->setBody(Body);
|
||||||
MD->setBody(Body);
|
CurrentBody = 0;
|
||||||
CurrentBody = 0;
|
if (PropParentMap) {
|
||||||
if (PropParentMap) {
|
delete PropParentMap;
|
||||||
delete PropParentMap;
|
PropParentMap = 0;
|
||||||
PropParentMap = 0;
|
}
|
||||||
|
InsertBlockLiteralsWithinMethod(MD);
|
||||||
|
CurMethodDef = 0;
|
||||||
}
|
}
|
||||||
InsertBlockLiteralsWithinMethod(MD);
|
break;
|
||||||
CurMethodDef = 0;
|
|
||||||
}
|
}
|
||||||
}
|
case Decl::ObjCImplementation: {
|
||||||
if (ObjCImplementationDecl *CI = dyn_cast<ObjCImplementationDecl>(D))
|
ObjCImplementationDecl *CI = cast<ObjCImplementationDecl>(D);
|
||||||
ClassImplementation.push_back(CI);
|
ClassImplementation.push_back(CI);
|
||||||
else if (ObjCCategoryImplDecl *CI = dyn_cast<ObjCCategoryImplDecl>(D))
|
break;
|
||||||
CategoryImplementation.push_back(CI);
|
}
|
||||||
else if (isa<ObjCClassDecl>(D))
|
case Decl::ObjCCategoryImpl: {
|
||||||
llvm_unreachable("RewriteObjC::HandleDeclInMainFile - ObjCClassDecl");
|
ObjCCategoryImplDecl *CI = cast<ObjCCategoryImplDecl>(D);
|
||||||
else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
CategoryImplementation.push_back(CI);
|
||||||
RewriteObjCQualifiedInterfaceTypes(VD);
|
break;
|
||||||
if (isTopLevelBlockPointerType(VD->getType()))
|
}
|
||||||
RewriteBlockPointerDecl(VD);
|
case Decl::Var: {
|
||||||
else if (VD->getType()->isFunctionPointerType()) {
|
VarDecl *VD = cast<VarDecl>(D);
|
||||||
CheckFunctionPointerDecl(VD->getType(), VD);
|
RewriteObjCQualifiedInterfaceTypes(VD);
|
||||||
|
if (isTopLevelBlockPointerType(VD->getType()))
|
||||||
|
RewriteBlockPointerDecl(VD);
|
||||||
|
else if (VD->getType()->isFunctionPointerType()) {
|
||||||
|
CheckFunctionPointerDecl(VD->getType(), VD);
|
||||||
|
if (VD->getInit()) {
|
||||||
|
if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(VD->getInit())) {
|
||||||
|
RewriteCastExpr(CE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (VD->getType()->isRecordType()) {
|
||||||
|
RecordDecl *RD = VD->getType()->getAs<RecordType>()->getDecl();
|
||||||
|
if (RD->isCompleteDefinition())
|
||||||
|
RewriteRecordBody(RD);
|
||||||
|
}
|
||||||
if (VD->getInit()) {
|
if (VD->getInit()) {
|
||||||
|
GlobalVarDecl = VD;
|
||||||
|
CurrentBody = VD->getInit();
|
||||||
|
RewriteFunctionBodyOrGlobalInitializer(VD->getInit());
|
||||||
|
CurrentBody = 0;
|
||||||
|
if (PropParentMap) {
|
||||||
|
delete PropParentMap;
|
||||||
|
PropParentMap = 0;
|
||||||
|
}
|
||||||
|
SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(), VD->getName());
|
||||||
|
GlobalVarDecl = 0;
|
||||||
|
|
||||||
|
// This is needed for blocks.
|
||||||
if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(VD->getInit())) {
|
if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(VD->getInit())) {
|
||||||
RewriteCastExpr(CE);
|
RewriteCastExpr(CE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (VD->getType()->isRecordType()) {
|
break;
|
||||||
RecordDecl *RD = VD->getType()->getAs<RecordType>()->getDecl();
|
}
|
||||||
if (RD->isCompleteDefinition())
|
case Decl::TypeAlias:
|
||||||
|
case Decl::Typedef: {
|
||||||
|
if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
|
||||||
|
if (isTopLevelBlockPointerType(TD->getUnderlyingType()))
|
||||||
|
RewriteBlockPointerDecl(TD);
|
||||||
|
else if (TD->getUnderlyingType()->isFunctionPointerType())
|
||||||
|
CheckFunctionPointerDecl(TD->getUnderlyingType(), TD);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Decl::CXXRecord:
|
||||||
|
case Decl::Record: {
|
||||||
|
RecordDecl *RD = cast<RecordDecl>(D);
|
||||||
|
if (RD->isCompleteDefinition())
|
||||||
RewriteRecordBody(RD);
|
RewriteRecordBody(RD);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (VD->getInit()) {
|
case Decl::ObjCClass: {
|
||||||
GlobalVarDecl = VD;
|
llvm_unreachable("RewriteObjC::HandleDeclInMainFile - ObjCClassDecl");
|
||||||
CurrentBody = VD->getInit();
|
break;
|
||||||
RewriteFunctionBodyOrGlobalInitializer(VD->getInit());
|
|
||||||
CurrentBody = 0;
|
|
||||||
if (PropParentMap) {
|
|
||||||
delete PropParentMap;
|
|
||||||
PropParentMap = 0;
|
|
||||||
}
|
|
||||||
SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(),
|
|
||||||
VD->getName());
|
|
||||||
GlobalVarDecl = 0;
|
|
||||||
|
|
||||||
// This is needed for blocks.
|
|
||||||
if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(VD->getInit())) {
|
|
||||||
RewriteCastExpr(CE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
default:
|
||||||
}
|
break;
|
||||||
if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
|
|
||||||
if (isTopLevelBlockPointerType(TD->getUnderlyingType()))
|
|
||||||
RewriteBlockPointerDecl(TD);
|
|
||||||
else if (TD->getUnderlyingType()->isFunctionPointerType())
|
|
||||||
CheckFunctionPointerDecl(TD->getUnderlyingType(), TD);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
|
|
||||||
if (RD->isCompleteDefinition())
|
|
||||||
RewriteRecordBody(RD);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Nothing yet.
|
// Nothing yet.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue