summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/PythonUtil.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2009-02-11 16:02:22 +1000
committerMichi Henning <michi@zeroc.com>2009-02-11 16:02:22 +1000
commit69b75f3ccde03365be46980e1871607ae7dfc494 (patch)
treeebd8e9cb46453b2c07100a120d7f6dcbfa7c29a3 /cpp/src/Slice/PythonUtil.cpp
parentBug 3717: Bizarre magic numbery code in cs/demo/Ice/latency. (diff)
parentbug 3021 - replace StringBuffer with StringBuilder (diff)
downloadice-69b75f3ccde03365be46980e1871607ae7dfc494.tar.bz2
ice-69b75f3ccde03365be46980e1871607ae7dfc494.tar.xz
ice-69b75f3ccde03365be46980e1871607ae7dfc494.zip
Merge branch 'R3_3_branch' of ssh://cvs.zeroc.com/home/git/ice into R3_3_branch
Diffstat (limited to 'cpp/src/Slice/PythonUtil.cpp')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp64
1 files changed, 58 insertions, 6 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index c1c91b3f289..7dc251b25df 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -1204,17 +1204,46 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
void
Slice::Python::CodeVisitor::visitSequence(const SequencePtr& p)
{
+ static const string protobuf = "python:protobuf:";
+ StringList metaData = p->getMetaData();
+ bool isCustom = false;
+ string customType;
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q)
+ {
+ if(q->find(protobuf) == 0)
+ {
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
+ if(!builtin || builtin->kind() != Builtin::KindByte)
+ {
+ continue;
+ }
+ isCustom = true;
+ customType = q->substr(protobuf.size());
+ break;
+ }
+ }
+
//
// Emit the type information.
//
string scoped = p->scoped();
_out << sp << nl << "if not " << getDictLookup(p, "_t_") << ':';
_out.inc();
- _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineSequence('" << scoped << "', ";
- writeMetaData(p->getMetaData());
- _out << ", ";
- writeType(p->type());
- _out << ")";
+ if(isCustom)
+ {
+ string package = customType.substr(0, customType.find('.'));
+ _out << nl << "import " << package;
+ _out << nl << "_M_" << getAbsolute(p, "_t_")
+ << " = IcePy.defineCustom('" << scoped << "', " << customType << ")";
+ }
+ else
+ {
+ _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineSequence('" << scoped << "', ";
+ writeMetaData(metaData);
+ _out << ", ";
+ writeType(p->type());
+ _out << ")";
+ }
_out.dec();
}
@@ -2032,7 +2061,30 @@ Slice::Python::MetaDataVisitor::visitDataMember(const DataMemberPtr& p)
void
Slice::Python::MetaDataVisitor::visitSequence(const SequencePtr& p)
{
- validateSequence(p->definitionContext(), p->line(), p, p->getMetaData());
+ static const string protobuf = "python:protobuf:";
+ StringList metaData = p->getMetaData();
+ const string file = p->definitionContext()->filename();
+ const string line = p->line();
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); )
+ {
+ string s = *q++;
+ if(s.find(protobuf) == 0)
+ {
+ //
+ // Remove from list so validateSequence does not try to handle as well.
+ //
+ metaData.remove(s);
+
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
+ if(!builtin || builtin->kind() != Builtin::KindByte)
+ {
+ emitWarning(file, line, "ignoring invalid metadata `" + s + ":\n" +
+ "`protobuf' encoding must be a byte sequence");
+ }
+ }
+ }
+
+ validateSequence(p->definitionContext(), line, p, metaData);
}
void