summaryrefslogtreecommitdiff
path: root/cpp/src/slice2objc/Gen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2objc/Gen.cpp')
-rw-r--r--cpp/src/slice2objc/Gen.cpp68
1 files changed, 33 insertions, 35 deletions
diff --git a/cpp/src/slice2objc/Gen.cpp b/cpp/src/slice2objc/Gen.cpp
index 9872a07388f..17a91efac8e 100644
--- a/cpp/src/slice2objc/Gen.cpp
+++ b/cpp/src/slice2objc/Gen.cpp
@@ -1892,10 +1892,13 @@ Slice::Gen::TypesVisitor::writeMemberDefaultValueInit(const DataMemberList& data
_M << nl << "self->" << name << " = " << firstEnum << ';';
}
- StructPtr st = StructPtr::dynamicCast((*p)->type());
- if(st)
+ if(!(*p)->optional())
{
- _M << nl << "self->" << name << " = [[" << typeToString(st) << " alloc] init];";
+ StructPtr st = StructPtr::dynamicCast((*p)->type());
+ if(st)
+ {
+ _M << nl << "self->" << name << " = [[" << typeToString(st) << " alloc] init];";
+ }
}
}
}
@@ -2146,48 +2149,43 @@ Slice::Gen::TypesVisitor::writeMemberEquals(const DataMemberList& dataMembers, i
void
Slice::Gen::TypesVisitor::writeMemberDealloc(const DataMemberList& dataMembers, int baseType, const string& slicedData) const
{
- if(dataMembers.empty())
+ bool needsDealloc = !slicedData.empty();
+ for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- return;
+ if(!isValueType((*q)->type()))
+ {
+ needsDealloc = true;
+ break;
+ }
+ }
+ if(!needsDealloc)
+ {
+ return; // No reference type data members.
}
- bool once = false;
+ _M << sp;
+ _M.zeroIndent();
+ _M << nl << "#if defined(__clang__) && !__has_feature(objc_arc)";
+ _M.restoreIndent();
+ _M << nl << "-(void) dealloc";
+ _M << sb;
for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- TypePtr type = (*q)->type();
- if(!isValueType(type))
+ if(!isValueType((*q)->type()))
{
- if(!once)
- {
- once = true;
- _M << sp;
- _M.zeroIndent();
- _M << nl << "#if defined(__clang__) && !__has_feature(objc_arc)";
- _M.restoreIndent();
- _M << nl << "-(void) dealloc";
- _M << sb;
- }
-
- bool isValue = isValueType(type);
- if(!isValue)
- {
- _M << nl << "[self->" << fixId((*q)->name(), baseType) << " release];";
- }
+ _M << nl << "[self->" << fixId((*q)->name(), baseType) << " release];";
}
}
- if(once)
+ if(!slicedData.empty())
{
- if(!slicedData.empty())
- {
- _M << nl << "[(NSObject*)" << slicedData << " release];";
- }
- _M << nl << "[super dealloc];";
- _M << eb;
- _M.zeroIndent();
- _M << nl << "#endif";
- _M.restoreIndent();
- _H << nl << "// This class also overrides dealloc";
+ _M << nl << "[(NSObject*)" << slicedData << " release];";
}
+ _M << nl << "[super dealloc];";
+ _M << eb;
+ _M.zeroIndent();
+ _M << nl << "#endif";
+ _M.restoreIndent();
+ _H << nl << "// This class also overrides dealloc";
}
void