diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-01-05 19:21:35 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-01-05 19:21:35 +0000 |
commit | 7fac65572f0cba71fe7ea2b5a5f4f65cc38b653d (patch) | |
tree | b58cb7fa49c8ac2fbe97790295b1e5707ebd54e9 /clang/lib | |
parent | 297bfe6d711285bc9d80a3bacb3bb363c0e444c4 (diff) | |
download | bcm5719-llvm-7fac65572f0cba71fe7ea2b5a5f4f65cc38b653d.tar.gz bcm5719-llvm-7fac65572f0cba71fe7ea2b5a5f4f65cc38b653d.zip |
API support for __block variables which are also __weak.
llvm-svn: 92755
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/RewriteObjC.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/clang/lib/Frontend/RewriteObjC.cpp b/clang/lib/Frontend/RewriteObjC.cpp index 253e0816581..fd3efe560b6 100644 --- a/clang/lib/Frontend/RewriteObjC.cpp +++ b/clang/lib/Frontend/RewriteObjC.cpp @@ -603,8 +603,10 @@ void RewriteObjC::Initialize(ASTContext &context) { Preamble += "#undef __OBJC_RW_STATICIMPORT\n"; Preamble += "#define __attribute__(X)\n"; } - else + else { Preamble += "#define __block\n"; + Preamble += "#define __weak\n"; + } } @@ -4461,7 +4463,8 @@ std::string RewriteObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD, /// /// void RewriteObjC::RewriteByRefVar(VarDecl *ND) { - int flag; + int flag = 0; + int isa = 0; SourceLocation DeclLoc = ND->getTypeSpecStartLoc(); const char *startBuf = SM->getCharacterData(DeclLoc); SourceLocation X = ND->getLocEnd(); @@ -4491,6 +4494,11 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { assert(CurFunctionDef && "RewriteByRefVar - CurFunctionDef is null"); SourceLocation FunLocStart = CurFunctionDef->getTypeSpecStartLoc(); InsertText(FunLocStart, ByrefType.c_str(), ByrefType.size()); + if (Ty.isObjCGCWeak()) { + flag |= BLOCK_FIELD_IS_WEAK; + isa = 1; + } + if (HasCopyAndDispose) { flag = BLOCK_BYREF_CALLER; QualType Ty = ND->getType(); @@ -4514,8 +4522,9 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { Name = ND->getNameAsString(); ByrefType = "struct __Block_byref_" + Name; if (!hasInit) { - ByrefType += " " + Name + " = "; - ByrefType += "{0, &" + Name + ", "; + ByrefType += " " + Name + " = {(void*)"; + ByrefType += utostr(isa); + ByrefType += ", &" + Name + ", "; ByrefType += utostr(flags); ByrefType += ", "; ByrefType += "sizeof(struct __Block_byref_" + Name + ")"; @@ -4534,7 +4543,9 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { ByrefType += " " + Name; ReplaceText(DeclLoc, endBuf-startBuf, ByrefType.c_str(), ByrefType.size()); - ByrefType = " = {0, &" + Name + ", "; + ByrefType = " = {(void*)"; + ByrefType += utostr(isa); + ByrefType += ", &" + Name + ", "; ByrefType += utostr(flags); ByrefType += ", "; ByrefType += "sizeof(struct __Block_byref_" + Name + "), "; |