diff options
author | Benoit Foucher <benoit@zeroc.com> | 2015-02-20 14:27:41 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2015-02-20 14:27:41 +0100 |
commit | af1544e7b81e8708c5fdee05a59328558a3030fe (patch) | |
tree | 0933eb39159b8cf714aab7fe5901d0515674d7c6 /cpp/src/slice2cs | |
parent | Simplification to Atomic usage (diff) | |
download | ice-af1544e7b81e8708c5fdee05a59328558a3030fe.tar.bz2 ice-af1544e7b81e8708c5fdee05a59328558a3030fe.tar.xz ice-af1544e7b81e8708c5fdee05a59328558a3030fe.zip |
Fix for ICE-6268, initialize enum, string and structs in Java/C#/Objective-C/JavaScript
Diffstat (limited to 'cpp/src/slice2cs')
-rw-r--r-- | cpp/src/slice2cs/Gen.cpp | 44 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.h | 1 |
2 files changed, 40 insertions, 5 deletions
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 63adc6076c2..6693a6fdc9f 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -2045,6 +2045,27 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt } } +bool +Slice::CsVisitor::requiresDataMemberInitializers(const DataMemberList& members) +{ + for(DataMemberList::const_iterator p = members.begin(); p != members.end(); ++p) + { + if((*p)->defaultValueType()) + { + return true; + } + else if((*p)->optional()) + { + return true; + } + else if(BuiltinPtr::dynamicCast((*p)->type()) || StructPtr::dynamicCast((*p)->type())) + { + return true; + } + } + return false; +} + void Slice::CsVisitor::writeDataMemberInitializers(const DataMemberList& members, int baseTypes, bool propertyMapping) { @@ -2070,6 +2091,20 @@ Slice::CsVisitor::writeDataMemberInitializers(const DataMemberList& members, int _out << nl << "this." << fixId((*p)->name(), baseTypes) << " = new " << typeToString((*p)->type(), true) << "();"; } + else + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast((*p)->type()); + if(builtin && builtin->kind() == Builtin::KindString) + { + _out << nl << fixId((*p)->name(), baseTypes) << " = \"\";"; + } + + StructPtr st = StructPtr::dynamicCast((*p)->type()); + if(st) + { + _out << nl << fixId((*p)->name(), baseTypes) << " = new " << typeToString(st, false) << "();"; + } + } } } @@ -3555,9 +3590,8 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << sp << nl << "#region Constructors"; - const bool hasDefaultValues = p->hasDefaultValues(); - - if(hasDefaultValues) + const bool hasDataMemberInitializers = requiresDataMemberInitializers(dataMembers); + if(hasDataMemberInitializers) { _out << sp << nl << "private void initDM__()"; _out << sb; @@ -3569,7 +3603,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) emitGeneratedCodeAttribute(); _out << nl << "public " << name << "()"; _out << sb; - if(hasDefaultValues) + if(hasDataMemberInitializers) { _out << nl << "initDM__();"; } @@ -3579,7 +3613,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) emitGeneratedCodeAttribute(); _out << nl << "public " << name << "(_System.Exception ex__) : base(ex__)"; _out << sb; - if(hasDefaultValues) + if(hasDataMemberInitializers) { _out << nl << "initDM__();"; } diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h index baa30e6cd79..6ccf03488c6 100644 --- a/cpp/src/slice2cs/Gen.h +++ b/cpp/src/slice2cs/Gen.h @@ -55,6 +55,7 @@ protected: // // Generate assignment statements for those data members that have default values. // + bool requiresDataMemberInitializers(const DataMemberList&); void writeDataMemberInitializers(const DataMemberList&, int = 0, bool = false); std::string toCsIdent(const std::string&); |