diff options
author | Bernard Normier <bernard@zeroc.com> | 2017-02-08 09:41:55 -0500 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2017-02-08 09:41:55 -0500 |
commit | af38cbf2ebf9c009fcea81cc316be64176da620e (patch) | |
tree | 28d6975bf5f1c4b7b89a5c24d2e1d9f1a2ba633c /cpp/src/slice2objc | |
parent | Added wide char overloads of Ice::createProperties & Ice::initialize (diff) | |
download | ice-af38cbf2ebf9c009fcea81cc316be64176da620e.tar.bz2 ice-af38cbf2ebf9c009fcea81cc316be64176da620e.tar.xz ice-af38cbf2ebf9c009fcea81cc316be64176da620e.zip |
Make Slice enums scoped
Add new cpp:scoped and objc:scoped metadata directives
Diffstat (limited to 'cpp/src/slice2objc')
-rw-r--r-- | cpp/src/slice2objc/Gen.cpp | 20 | ||||
-rw-r--r-- | cpp/src/slice2objc/Gen.h | 2 | ||||
-rw-r--r-- | cpp/src/slice2objc/ObjCUtil.cpp | 39 |
3 files changed, 41 insertions, 20 deletions
diff --git a/cpp/src/slice2objc/Gen.cpp b/cpp/src/slice2objc/Gen.cpp index 7ad7d9883e6..290a87d268f 100644 --- a/cpp/src/slice2objc/Gen.cpp +++ b/cpp/src/slice2objc/Gen.cpp @@ -1523,7 +1523,9 @@ void Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) { string name = fixName(p); - EnumeratorList enumerators = p->getEnumerators(); + EnumeratorList enumerators = p->enumerators(); + string enumeratorPrefix = p->hasMetaData("objc:scoped") ? name : ""; + _H << sp; // @@ -1536,7 +1538,7 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) EnumeratorList::const_iterator en = enumerators.begin(); while(en != enumerators.end()) { - _H << nl << fixName(*en); + _H << nl << moduleName(findModule(*en)) << enumeratorPrefix << (*en)->name(); // // If any of the enumerators were assigned an explicit value, we emit // an explicit value for *all* enumerators. @@ -1566,12 +1568,13 @@ Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p) _H << nl << "static const " << typeToString(p->type()); } _H << " " << fixName(p) << " = "; - writeConstantValue(_H, p->type(), p->value()); + writeConstantValue(_H, p->type(), p->valueType(), p->value()); _H << ';'; } void -Slice::Gen::TypesVisitor::writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const string& val) const +Slice::Gen::TypesVisitor::writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, + const SyntaxTreeBasePtr& valueType, const string& val) const { if(isString(type)) { @@ -1582,7 +1585,10 @@ Slice::Gen::TypesVisitor::writeConstantValue(IceUtilInternal::Output& out, const EnumPtr ep = EnumPtr::dynamicCast(type); if(ep) { - out << moduleName(findModule(ep)) << val; + EnumeratorPtr lte = EnumeratorPtr::dynamicCast(valueType); + assert(lte); + string enumeratorPrefix = ep->hasMetaData("objc:scoped") ? ep->name() : ""; + out << moduleName(findModule(ep)) << enumeratorPrefix << lte->name(); } else { @@ -1868,7 +1874,7 @@ Slice::Gen::TypesVisitor::writeMemberDefaultValueInit(const DataMemberList& data _M << nl << "self->has_" << name << "__ = YES;"; } _M << nl << "self->" << name << " = "; - writeConstantValue(_M, (*p)->type(), (*p)->defaultValue()); + writeConstantValue(_M, (*p)->type(), (*p)->defaultValueType(), (*p)->defaultValue()); _M << ";"; } else @@ -1882,7 +1888,7 @@ Slice::Gen::TypesVisitor::writeMemberDefaultValueInit(const DataMemberList& data EnumPtr en = EnumPtr::dynamicCast((*p)->type()); if(en) { - string firstEnum = fixName(en->getEnumerators().front()); + string firstEnum = fixName(en->enumerators().front()); _M << nl << "self->" << name << " = " << firstEnum << ';'; } diff --git a/cpp/src/slice2objc/Gen.h b/cpp/src/slice2objc/Gen.h index 0c9ef639e7d..bb4b63752d9 100644 --- a/cpp/src/slice2objc/Gen.h +++ b/cpp/src/slice2objc/Gen.h @@ -131,7 +131,7 @@ private: enum Escape { NoEscape, WithEscape }; enum ContainerType { LocalException, Other }; - void writeConstantValue(IceUtilInternal::Output&, const TypePtr&, const std::string&) const; + void writeConstantValue(IceUtilInternal::Output&, const TypePtr&, const SyntaxTreeBasePtr&, const std::string&) const; void writeInit(const ContainedPtr&, const DataMemberList&, const DataMemberList&, const DataMemberList&, bool, int, ContainerType) const; void writeFactory(const ContainedPtr&, const DataMemberList&, int, ContainerType) const; diff --git a/cpp/src/slice2objc/ObjCUtil.cpp b/cpp/src/slice2objc/ObjCUtil.cpp index 6cd8afd835a..8e011306c89 100644 --- a/cpp/src/slice2objc/ObjCUtil.cpp +++ b/cpp/src/slice2objc/ObjCUtil.cpp @@ -1222,9 +1222,7 @@ Slice::ObjCGenerator::MetaDataVisitor::validate(const ContainedPtr& cont) bool foundPrefix = false; StringList meta = getMetaData(m); - StringList::const_iterator p; - - for(p = meta.begin(); p != meta.end();) + for(StringList::iterator p = meta.begin(); p != meta.end();) { string s = *p++; const string prefix = "objc:prefix:"; @@ -1235,10 +1233,8 @@ Slice::ObjCGenerator::MetaDataVisitor::validate(const ContainedPtr& cont) name = trim(s.substr(prefix.size())); if(name.empty()) { - string file = m->definitionContext()->filename(); - ostringstream os; - os << _msg << " `" << s << "'" << endl; - emitWarning(file, m->line(), os.str()); + m->definitionContext()->warning(InvalidMetaData, m->definitionContext()->filename(), + m->line(), _msg + " `" + s + "'"); meta.remove(s); error = true; } @@ -1252,10 +1248,8 @@ Slice::ObjCGenerator::MetaDataVisitor::validate(const ContainedPtr& cont) } else { - string file = m->definitionContext()->filename(); - ostringstream os; - os << _msg << " `" << s << "'" << endl; - emitWarning(file, m->line(), os.str()); + m->definitionContext()->warning(InvalidMetaData, m->definitionContext()->filename(), + m->line(), _msg + " `" + s + "'"); meta.remove(s); error = true; } @@ -1276,6 +1270,27 @@ Slice::ObjCGenerator::MetaDataVisitor::validate(const ContainedPtr& cont) } } } + + EnumPtr en = EnumPtr::dynamicCast(cont); + if(en) + { + StringList meta = getMetaData(en); + for(StringList::iterator p = meta.begin(); p != meta.end();) + { + string s = *p; + if(s != "objc:scoped") + { + en->definitionContext()->warning(InvalidMetaData, en->definitionContext()->filename(), + en->line(), _msg + " `" + s + "'"); + meta.erase(p++); + } + else + { + ++p; + } + } + setMetaData(en, meta); + } } StringList @@ -1333,5 +1348,5 @@ Slice::ObjCGenerator::MetaDataVisitor::modulePrefixError(const ModulePtr& m, con } os << line; os << " as `" << mp.name << "'" << endl; - emitWarning(file, line, os.str()); + m->definitionContext()->warning(All, file, line, os.str()); } |