зеркало из https://github.com/microsoft/clang.git
Add a couple fixes for rewriting ivars/methods that use/contain blocks.
Now this: @interface Test { void (^ivar)(void); } - (void)name; @end @implementation Test - (void)name { ivar = ^{ printf("hello\n"); }; // ((struct Test_IMPL *)self)->ivar = (void (*)(void))&__name_block_impl_0((void *)__name_block_func_0); ivar(); // ((void (*)(struct __block_impl *))((struct __block_impl *)((struct Test_IMPL *)self)->ivar)->FuncPtr)((struct __block_impl *)((struct Test_IMPL *)self)->ivar); } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58428 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
aa4d5ae6c4
Коммит
ced80a848d
Driver
|
@ -711,6 +711,7 @@ void RewriteObjC::RewriteForwardProtocolDecl(ObjCForwardProtocolDecl *PDecl) {
|
||||||
|
|
||||||
void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD,
|
void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD,
|
||||||
std::string &ResultStr) {
|
std::string &ResultStr) {
|
||||||
|
//fprintf(stderr,"In RewriteObjCMethodDecl\n");
|
||||||
const FunctionType *FPRetType = 0;
|
const FunctionType *FPRetType = 0;
|
||||||
ResultStr += "\nstatic ";
|
ResultStr += "\nstatic ";
|
||||||
if (OMD->getResultType()->isObjCQualifiedIdType())
|
if (OMD->getResultType()->isObjCQualifiedIdType())
|
||||||
|
@ -2439,6 +2440,9 @@ void RewriteObjC::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl,
|
||||||
cursor++;
|
cursor++;
|
||||||
atLoc = LocStart.getFileLocWithOffset(cursor-startBuf);
|
atLoc = LocStart.getFileLocWithOffset(cursor-startBuf);
|
||||||
InsertText(atLoc, " */", 3);
|
InsertText(atLoc, " */", 3);
|
||||||
|
} else if (*cursor == '^') { // rewrite block specifier.
|
||||||
|
SourceLocation caretLoc = LocStart.getFileLocWithOffset(cursor-startBuf);
|
||||||
|
ReplaceText(caretLoc, 1, "*", 1);
|
||||||
}
|
}
|
||||||
cursor++;
|
cursor++;
|
||||||
}
|
}
|
||||||
|
@ -3267,7 +3271,7 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
|
||||||
|
|
||||||
std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag,
|
std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag,
|
||||||
bool hasCopyDisposeHelpers) {
|
bool hasCopyDisposeHelpers) {
|
||||||
std::string S = "struct " + Tag;
|
std::string S = "\nstruct " + Tag;
|
||||||
std::string Constructor = " " + Tag;
|
std::string Constructor = " " + Tag;
|
||||||
|
|
||||||
S += " {\n struct __block_impl impl;\n";
|
S += " {\n struct __block_impl impl;\n";
|
||||||
|
@ -3421,7 +3425,10 @@ void RewriteObjC::InsertBlockLiteralsWithinFunction(FunctionDecl *FD) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RewriteObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) {
|
void RewriteObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) {
|
||||||
SourceLocation FunLocStart = MD->getLocStart();
|
//fprintf(stderr,"In InsertBlockLiteralsWitinMethod\n");
|
||||||
|
//SourceLocation FunLocStart = MD->getLocStart();
|
||||||
|
// FIXME: This hack works around a bug in Rewrite.InsertText().
|
||||||
|
SourceLocation FunLocStart = MD->getLocStart().getFileLocWithOffset(-1);
|
||||||
std::string FuncName = std::string(MD->getSelector().getName());
|
std::string FuncName = std::string(MD->getSelector().getName());
|
||||||
// Convert colons to underscores.
|
// Convert colons to underscores.
|
||||||
std::string::size_type loc = 0;
|
std::string::size_type loc = 0;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче