diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2009-02-23 12:59:30 -0330 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2009-02-23 12:59:30 -0330 |
commit | d361daf963af38cf35acf2ea9606cc6771d608e6 (patch) | |
tree | 62da23601f9e7739f4b90fa2c4b66345651a1d2e /cpp/src/slice2cpp/Gen.cpp | |
parent | bug 3374 & general metadata clean up (diff) | |
download | ice-d361daf963af38cf35acf2ea9606cc6771d608e6.tar.bz2 ice-d361daf963af38cf35acf2ea9606cc6771d608e6.tar.xz ice-d361daf963af38cf35acf2ea9606cc6771d608e6.zip |
Bug 3740 - issue warning for improper protobuf usage
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 132014e8501..5eae2adf2e0 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1125,6 +1125,26 @@ void Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) { string name = fixKwd(p->name()); + TypePtr type = p->type(); + if(StructPtr::dynamicCast(p->container()) || ExceptionPtr::dynamicCast(p->container()) && + SequencePtr::dynamicCast(type)) + { + SequencePtr s = SequencePtr::dynamicCast(type); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(s->type()); + if(builtin && builtin->kind() == Builtin::KindByte) + { + StringList metaData = s->getMetaData(); + bool protobuf; + findMetaData(s, metaData, false, protobuf); + if(protobuf) + { + emitWarning(p->file(), p->line(), string("protobuf cannot be used as a ") + + (StructPtr::dynamicCast(p->container()) ? "struct" : "exception") + + " member in C++"); + } + } + } + string s = typeToString(p->type(), _useWstring, p->getMetaData()); H << nl << s << ' ' << name << ';'; } @@ -1423,6 +1443,22 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) { string name = fixKwd(p->name()); TypePtr keyType = p->keyType(); + if(SequencePtr::dynamicCast(keyType)) + { + SequencePtr s = SequencePtr::dynamicCast(keyType); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(s->type()); + if(builtin && builtin->kind() == Builtin::KindByte) + { + StringList metaData = s->getMetaData(); + bool protobuf; + findMetaData(s, metaData, false, protobuf); + if(protobuf) + { + emitWarning(p->file(), p->line(), "protobuf cannot be used as a dictionary key in C++"); + } + } + } + TypePtr valueType = p->valueType(); string ks = typeToString(keyType, _useWstring, p->keyMetaData()); if(ks[0] == ':') @@ -3870,6 +3906,23 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) bool prot = p->hasMetaData("protected"); for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { + TypePtr type = (*q)->type(); + if(SequencePtr::dynamicCast(type)) + { + SequencePtr s = SequencePtr::dynamicCast(type); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(s->type()); + if(builtin && builtin->kind() == Builtin::KindByte) + { + StringList metaData = s->getMetaData(); + bool protobuf; + findMetaData(s, metaData, false, protobuf); + if(protobuf) + { + emitWarning((*q)->file(), (*q)->line(), "protobuf cannot be used as a class member in C++"); + } + } + } + if(prot || (*q)->hasMetaData("protected")) { if(!inProtected) |