summaryrefslogtreecommitdiff
path: root/cpp/src/Slice
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2017-01-26 21:52:52 +0100
committerJose <jose@zeroc.com>2017-01-26 21:52:52 +0100
commitf3eeced45abdcbb8af31569bf8cee55f0d2a3b4b (patch)
treef98f59d56e7185ee90d504cf077e57465655f7fd /cpp/src/Slice
parentFixed ICE-6920 - Communicator::destroy is now noexcept (diff)
downloadice-f3eeced45abdcbb8af31569bf8cee55f0d2a3b4b.tar.bz2
ice-f3eeced45abdcbb8af31569bf8cee55f0d2a3b4b.tar.xz
ice-f3eeced45abdcbb8af31569bf8cee55f0d2a3b4b.zip
Python: Ice.Value implementation
Diffstat (limited to 'cpp/src/Slice')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp714
1 files changed, 425 insertions, 289 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index e1001869e8a..9dc1830cb1b 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -124,9 +124,14 @@ public:
private:
//
+ // Emit Python code for the class operations
+ //
+ void writeOperations(const ClassDefPtr&);
+
+ //
// Return a Python symbol for the given parser element.
//
- string getSymbol(const ContainedPtr&, const string& = string());
+ string getSymbol(const ContainedPtr&, const string& = "", const string& = "");
//
// Emit Python code to assign the given symbol in the current module.
@@ -269,7 +274,7 @@ splitScopedName(const string& scoped)
}
static string
-getDictLookup(const ContainedPtr& cont, const string& suffix = string())
+getDictLookup(const ContainedPtr& cont, const string& suffix = "", const string& prefix = "")
{
string scope = Slice::Python::scopedToName(cont->scope());
assert(!scope.empty());
@@ -280,7 +285,7 @@ getDictLookup(const ContainedPtr& cont, const string& suffix = string())
scope = package + "." + scope;
}
- return "'" + suffix + Slice::Python::fixIdent(cont->name()) + "' not in _M_" + scope + "__dict__";
+ return "'" + suffix + Slice::Python::fixIdent(cont->name() + prefix) + "' not in _M_" + scope + "__dict__";
}
//
@@ -421,10 +426,15 @@ Slice::Python::CodeVisitor::visitClassDecl(const ClassDeclPtr& p)
{
_out << sp << nl << "if " << getDictLookup(p) << ':';
_out.inc();
- string type = getAbsolute(p, "_t_");
- _out << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')";
- if(!p->isLocal())
+
+ if(!p->isInterface() || p->isLocal())
{
+ _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.declareValue('" << scoped << "')";
+ }
+
+ if(!p->isLocal() && (p->isInterface() || p->definition()->allOperations().size()))
+ {
+ _out << nl << "_M_" << getAbsolute(p, "_t_", "Disp") << " = IcePy.declareClass('" << scoped << "')";
_out << nl << "_M_" << getAbsolute(p, "_t_", "Prx") << " = IcePy.declareProxy('" << scoped << "')";
}
_out.dec();
@@ -432,150 +442,10 @@ Slice::Python::CodeVisitor::visitClassDecl(const ClassDeclPtr& p)
}
}
-bool
-Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
+void
+Slice::Python::CodeVisitor::writeOperations(const ClassDefPtr& p)
{
- string scoped = p->scoped();
- string type = getAbsolute(p, "_t_");
- string abs = getAbsolute(p);
- string name = fixIdent(p->name());
- string prxAbs = getAbsolute(p, "", "Prx");
- string prxName = fixIdent(p->name() + "Prx");
- string prxType = getAbsolute(p, "_t_", "Prx");
- ClassList bases = p->bases();
- ClassDefPtr base;
OperationList ops = p->operations();
- bool isAbstract = p->isInterface() || p->allOperations().size() > 0; // Don't use isAbstract() - see bug 3739
-
- //
- // Define the class.
- //
- _out << sp << nl << "if " << getDictLookup(p) << ':';
- _out.inc();
- _out << nl << "_M_" << abs << " = Ice.createTempClass()";
- _out << nl << "class " << name << '(';
- if(bases.empty())
- {
- if(p->isLocal())
- {
- _out << "object";
- }
- else
- {
- _out << "Ice.Object";
- }
- }
- else
- {
- for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
- {
- if(q != bases.begin())
- {
- _out << ", ";
- }
- _out << getSymbol(*q);
- }
- if(!bases.front()->isInterface())
- {
- base = bases.front();
- }
- }
- _out << "):";
-
- _out.inc();
-
- writeDocstring(p->comment(), p->dataMembers());
-
- //
- // __init__
- //
- _out << nl << "def __init__(self";
- MemberInfoList allMembers;
- collectClassMembers(p, allMembers, false);
- writeConstructorParams(allMembers);
- _out << "):";
- _out.inc();
- if(!base && !p->hasDataMembers() && !isAbstract)
- {
- _out << nl << "pass";
- }
- else
- {
- if(isAbstract)
- {
- _out << nl << "if Ice.getType(self) == _M_" << abs << ':';
- _out.inc();
- _out << nl << "raise RuntimeError('" << abs << " is an abstract class')";
- _out.dec();
- }
- if(base)
- {
- _out << nl << getSymbol(base) << ".__init__(self";
- for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q)
- {
- if(q->inherited)
- {
- _out << ", " << q->fixedName;
- }
- }
- _out << ')';
- }
- for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q)
- {
- if(!q->inherited)
- {
- writeAssign(*q);
- }
- }
- }
- _out.dec();
-
- if(!p->isLocal())
- {
- //
- // ice_ids
- //
- ClassList allBases = p->allBases();
- StringList ids;
- transform(allBases.begin(), allBases.end(), back_inserter(ids), IceUtil::constMemFun(&Contained::scoped));
- StringList other;
- other.push_back(scoped);
- other.push_back("::Ice::Object");
- other.sort();
- ids.merge(other);
- ids.unique();
- _out << sp << nl << "def ice_ids(self, current=None):";
- _out.inc();
- _out << nl << "return (";
- for(StringList::iterator q = ids.begin(); q != ids.end(); ++q)
- {
- if(q != ids.begin())
- {
- _out << ", ";
- }
- _out << "'" << *q << "'";
- }
- _out << ')';
- _out.dec();
-
- //
- // ice_id
- //
- _out << sp << nl << "def ice_id(self, current=None):";
- _out.inc();
- _out << nl << "return '" << scoped << "'";
- _out.dec();
-
- //
- // ice_staticId
- //
- _out << sp << nl << "@staticmethod";
- _out << nl << "def ice_staticId():";
- _out.inc();
- _out << nl << "return '" << scoped << "'";
- _out.dec();
- }
-
if(!ops.empty())
{
//
@@ -637,44 +507,276 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
}
}
}
+}
- //
- // __str__
- //
- _out << sp << nl << "def __str__(self):";
- _out.inc();
- _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, "_t_") << ")";
- _out.dec();
- _out << sp << nl << "__repr__ = __str__";
+bool
+Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
+{
+ bool isLocal = p->isLocal();
+ bool isInterface = p->isInterface();
+ bool isAbstract = isInterface || p->allOperations().size() > 0; // Don't use isAbstract() - see bug 3739
- _out.dec();
+ string scoped = p->scoped();
+ string type = getAbsolute(p, "_t_");
+ string classType = getAbsolute(p, "_t_", "Disp");
+ string abs = getAbsolute(p);
+ string className = isLocal ? fixIdent(p->name()) : isAbstract ? fixIdent("_" + p->name() + "Disp") : "None";
+ string classAbs = getAbsolute(p, "_", "Disp");
+ string valueName = (isInterface && !isLocal) ? "Ice.Value" : fixIdent(p->name());
+ string prxAbs = getAbsolute(p, "", "Prx");
+ string prxName = fixIdent(p->name() + "Prx");
+ string prxType = getAbsolute(p, "_t_", "Prx");
+ ClassList bases = p->bases();
+ ClassDefPtr base;
+
+ if(!bases.empty() && !bases.front()->isInterface())
+ {
+ base = bases.front();
+ }
//
- // Define the proxy class.
+ // Define a class type for Value types or local classes.
//
- if(!p->isLocal())
+ if(isLocal || !isInterface)
{
- _out << sp << nl << "_M_" << prxAbs << " = Ice.createTempClass()";
- _out << nl << "class " << prxName << "(";
- if(bases.empty())
+ _out << sp << nl << "if " << getDictLookup(p) << ':';
+ _out.inc();
+ _out << nl << "_M_" << abs << " = Ice.createTempClass()";
+ _out << nl << "class " << valueName << '(';
+ if(isLocal)
+ {
+ if(bases.empty())
+ {
+ _out << "object";
+ }
+ else
+ {
+ for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
+ {
+ if(q != bases.begin())
+ {
+ _out << ", ";
+ }
+ _out << getSymbol(*q);
+ }
+ }
+ }
+ else
{
- _out << "Ice.ObjectPrx";
+ if(bases.empty() || bases.front()->isInterface())
+ {
+ _out << "Ice.Value";
+ }
+ else
+ {
+ _out << getSymbol(bases.front());
+ }
+ }
+ _out << "):";
+
+ _out.inc();
+
+ writeDocstring(p->comment(), p->dataMembers());
+
+ //
+ // __init__
+ //
+ _out << nl << "def __init__(self";
+ MemberInfoList allMembers;
+ collectClassMembers(p, allMembers, false);
+ writeConstructorParams(allMembers);
+ _out << "):";
+ _out.inc();
+ if(!base && !p->hasDataMembers() && (!isAbstract || !isLocal))
+ {
+ _out << nl << "pass";
}
else
{
- ClassList::const_iterator q = bases.begin();
- while(q != bases.end())
+ if(isAbstract && isLocal)
{
- _out << getSymbol(*q, "Prx");
- if(++q != bases.end())
+ _out << nl << "if Ice.getType(self) == _M_" << abs << ':';
+ _out.inc();
+ _out << nl << "raise RuntimeError('" << abs << " is an abstract class')";
+ _out.dec();
+ }
+ if(base)
+ {
+ _out << nl << getSymbol(base) << ".__init__(self";
+ for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q)
{
- _out << ", ";
+ if(q->inherited)
+ {
+ _out << ", " << q->fixedName;
+ }
+ }
+ _out << ')';
+ }
+ for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q)
+ {
+ if(!q->inherited)
+ {
+ writeAssign(*q);
}
}
}
- _out << "):";
+ _out.dec();
+
+ if(!isLocal)
+ {
+ //
+ // ice_id
+ //
+ _out << sp << nl << "def ice_id(self, current=None):";
+ _out.inc();
+ _out << nl << "return '" << scoped << "'";
+ _out.dec();
+
+ //
+ // ice_staticId
+ //
+ _out << sp << nl << "@staticmethod";
+ _out << nl << "def ice_staticId():";
+ _out.inc();
+ _out << nl << "return '" << scoped << "'";
+ _out.dec();
+ }
+ else
+ {
+ writeOperations(p);
+ }
+
+ //
+ // __str__
+ //
+ _out << sp << nl << "def __str__(self):";
+ _out.inc();
+ _out << nl << "return IcePy.stringify(self, _M_" << type << ")";
+ _out.dec();
+ _out << sp << nl << "__repr__ = __str__";
+
+ _out.dec();
+
+ if(_classHistory.count(scoped) == 0 && p->canBeCyclic())
+ {
+ //
+ // Emit a forward declaration for the class in case a data member refers to this type.
+ //
+ _out << sp << nl << "_M_" << type << " = IcePy.declareValue('" << scoped << "')";
+ }
+ DataMemberList members = p->dataMembers();
+ _out << sp << nl << "_M_" << type << " = IcePy.defineValue('" << scoped << "', " << valueName
+ << ", " << p->compactId() << ", ";
+ writeMetaData(p->getMetaData());
+ const bool preserved = p->hasMetaData("preserve-slice") || p->inheritsMetaData("preserve-slice");
+ _out << ", " << (preserved ? "True" : "False") << ", " << (isInterface ? "True" : "False") << ", ";
+ if(!base)
+ {
+ _out << "None";
+ }
+ else
+ {
+ _out << "_M_" << getAbsolute(base, "_t_");
+ }
+ _out << ", (";
+ //
+ // Members
+ //
+ // Data members are represented as a tuple:
+ //
+ // ('MemberName', MemberMetaData, MemberType, Optional, Tag)
+ //
+ // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type.
+ //
+ if(members.size() > 1)
+ {
+ _out.inc();
+ _out << nl;
+ }
+ bool isProtected = p->hasMetaData("protected");
+ for(DataMemberList::iterator r = members.begin(); r != members.end(); ++r)
+ {
+ if(r != members.begin())
+ {
+ _out << ',' << nl;
+ }
+ _out << "('";
+ if(isProtected || (*r)->hasMetaData("protected"))
+ {
+ _out << '_';
+ }
+ _out << fixIdent((*r)->name()) << "', ";
+ writeMetaData((*r)->getMetaData());
+ _out << ", ";
+ writeType((*r)->type());
+ _out << ", " << ((*r)->optional() ? "True" : "False") << ", "
+ << ((*r)->optional() ? (*r)->tag() : 0) << ')';
+ }
+ if(members.size() == 1)
+ {
+ _out << ',';
+ }
+ else if(members.size() > 1)
+ {
+ _out.dec();
+ _out << nl;
+ }
+ _out << "))";
+ _out << nl << valueName << "._ice_type = _M_" << type;
+
+ registerName(valueName);
+
+ _out.dec();
+ }
+ else if(!isLocal && isInterface)
+ {
+ _out << sp << nl << "_M_" << type << " = IcePy.defineValue('" << scoped << "', Ice.Value, -1, ";
+ writeMetaData(p->getMetaData());
+ _out << ", False, True, None, ())";
+ }
+
+ if(!isLocal && isAbstract)
+ {
+ _out << sp << nl << "if " << getDictLookup(p, "", "Prx") << ':';
_out.inc();
+ // Define the proxy class
+ _out << nl << "_M_" << prxAbs << " = Ice.createTempClass()";
+ _out << nl << "class " << prxName << '(';
+
+ {
+ vector<string> baseClasses;
+ for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
+ {
+ ClassDefPtr d = *q;
+ if(d->isInterface() || d->allOperations().size() > 0)
+ {
+ baseClasses.push_back(getSymbol(*q, "", "Prx"));
+ }
+ }
+
+ if(baseClasses.empty())
+ {
+ _out << "Ice.ObjectPrx";
+ }
+ else
+ {
+ vector<string>::const_iterator q = baseClasses.begin();
+ while(q != baseClasses.end())
+ {
+ _out << *q;
+
+ if(++q != baseClasses.end())
+ {
+ _out << ", ";
+ }
+ }
+ }
+ }
+ _out << "):";
+ _out.inc();
+
+ OperationList ops = p->operations();
for(OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli)
{
string fixedOpName = fixIdent((*oli)->name());
@@ -708,7 +810,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
const string contextParamName = getEscapedParamName(*oli, "context");
_out << ", " << contextParamName << "=None):";
_out.inc();
- _out << nl << "return _M_" << abs << "._op_" << (*oli)->name() << ".invoke(self, ((" << inParams;
+ _out << nl << "return _M_" << classAbs << "._op_" << (*oli)->name() << ".invoke(self, ((" << inParams;
if(!inParams.empty() && inParams.find(',') == string::npos)
{
_out << ", ";
@@ -728,7 +830,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
}
_out << ", " << contextParamName << "=None):";
_out.inc();
- _out << nl << "return _M_" << abs << "._op_" << (*oli)->name() << ".invokeAsync(self, ((" << inParams;
+ _out << nl << "return _M_" << classAbs << "._op_" << (*oli)->name() << ".invokeAsync(self, ((" << inParams;
if(!inParams.empty() && inParams.find(',') == string::npos)
{
_out << ", ";
@@ -745,7 +847,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
}
_out << ", _response=None, _ex=None, _sent=None, " << contextParamName << "=None):";
_out.inc();
- _out << nl << "return _M_" << abs << "._op_" << (*oli)->name() << ".begin(self, ((" << inParams;
+ _out << nl << "return _M_" << classAbs << "._op_" << (*oli)->name() << ".begin(self, ((" << inParams;
if(!inParams.empty() && inParams.find(',') == string::npos)
{
_out << ", ";
@@ -757,7 +859,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
writeDocstring(*oli, DocAsyncEnd, false);
_out << nl << "def end_" << (*oli)->name() << "(self, _r):";
_out.inc();
- _out << nl << "return _M_" << abs << "._op_" << (*oli)->name() << ".end(self, _r)";
+ _out << nl << "return _M_" << classAbs << "._op_" << (*oli)->name() << ".end(self, _r)";
_out.dec();
}
@@ -783,110 +885,149 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
_out << nl << "return '" << scoped << "'";
_out.dec();
- _out.dec();
+ _out.dec(); // end prx class
+
+ _out << nl << "_M_" << prxType << " = IcePy.defineProxy('" << scoped << "', " << prxName << ")";
- _out << sp << nl << "_M_" << prxType << " = IcePy.defineProxy('" << scoped << "', " << prxName << ")";
- }
+ registerName(prxName);
- if(_classHistory.count(scoped) == 0 && p->canBeCyclic())
- {
+ // Define the servant class
+ _out << sp << nl << "_M_" << classAbs << " = Ice.createTempClass()";
+ _out << nl << "class " << className << '(';
+ {
+ vector<string> baseClasses;
+ for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
+ {
+ ClassDefPtr d = *q;
+ if(d->isInterface() || d->allOperations().size() > 0)
+ {
+ baseClasses.push_back(getSymbol(*q, "_", "Disp"));
+ }
+ }
+
+ if(baseClasses.empty())
+ {
+ _out << "Ice.Object";
+ }
+ else
+ {
+ vector<string>::const_iterator q = baseClasses.begin();
+ while(q != baseClasses.end())
+ {
+ _out << *q;
+
+ if(++q != baseClasses.end())
+ {
+ _out << ", ";
+ }
+ }
+ }
+ }
+ _out << "):";
+
+ _out.inc();
+
//
- // Emit a forward declaration for the class in case a data member refers to this type.
+ // ice_ids
//
- _out << sp << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')";
- }
-
- DataMemberList members = p->dataMembers();
- _out << sp << nl << "_M_" << type << " = IcePy.defineClass('" << scoped << "', " << name << ", " << p->compactId()
- << ", ";
- writeMetaData(p->getMetaData());
- const bool preserved = p->hasMetaData("preserve-slice") || p->inheritsMetaData("preserve-slice");
- _out << ", " << (isAbstract ? "True" : "False") << ", " << (preserved ? "True" : "False") << ", ";
- if(!base)
- {
- _out << "None";
- }
- else
- {
- _out << "_M_" << getAbsolute(base, "_t_");
- }
- _out << ", (";
- //
- // Interfaces
- //
- int interfaceCount = 0;
- for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
- {
- if((*q)->isInterface())
+ ClassList allBases = p->allBases();
+ StringList ids;
+ transform(allBases.begin(), allBases.end(), back_inserter(ids), IceUtil::constMemFun(&Contained::scoped));
+ StringList other;
+ other.push_back(scoped);
+ other.push_back("::Ice::Object");
+ other.sort();
+ ids.merge(other);
+ ids.unique();
+ _out << sp << nl << "def ice_ids(self, current=None):";
+ _out.inc();
+ _out << nl << "return (";
+ for(StringList::iterator q = ids.begin(); q != ids.end(); ++q)
{
- if(interfaceCount > 0)
+ if(q != ids.begin())
{
_out << ", ";
}
- _out << "_M_" << getAbsolute(*q, "_t_");
- ++interfaceCount;
+ _out << "'" << *q << "'";
}
- }
- if(interfaceCount == 1)
- {
- _out << ',';
- }
- //
- // Members
- //
- // Data members are represented as a tuple:
- //
- // ('MemberName', MemberMetaData, MemberType, Optional, Tag)
- //
- // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type.
- //
- _out << "), (";
- if(members.size() > 1)
- {
+ _out << ')';
+ _out.dec();
+
+ //
+ // ice_id
+ //
+ _out << sp << nl << "def ice_id(self, current=None):";
_out.inc();
- _out << nl;
- }
- bool isProtected = p->hasMetaData("protected");
- for(DataMemberList::iterator r = members.begin(); r != members.end(); ++r)
- {
- if(r != members.begin())
+ _out << nl << "return '" << scoped << "'";
+ _out.dec();
+
+ //
+ // ice_staticId
+ //
+ _out << sp << nl << "@staticmethod";
+ _out << nl << "def ice_staticId():";
+ _out.inc();
+ _out << nl << "return '" << scoped << "'";
+ _out.dec();
+
+ writeOperations(p);
+
+ //
+ // __str__
+ //
+ _out << sp << nl << "def __str__(self):";
+ _out.inc();
+ _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, "_t_", "Disp") << ")";
+ _out.dec();
+ _out << sp << nl << "__repr__ = __str__";
+
+ _out.dec();
+
+ _out << sp << nl << "_M_" << classType << " = IcePy.defineClass('" << scoped << "', " << className
+ << ", ";
+ writeMetaData(p->getMetaData());
+ _out << ", ";
+ if(!base || (!base->isInterface() && base->allOperations().size() == 0))
{
- _out << ',' << nl;
+ _out << "None";
+ }
+ else
+ {
+ _out << "_M_" << getAbsolute(base, "_t_", "Disp");
}
- _out << "('";
- if(isProtected || (*r)->hasMetaData("protected"))
+ _out << ", (";
+ //
+ // Interfaces
+ //
+ int interfaceCount = 0;
+ for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
{
- _out << '_';
+ if((*q)->isInterface())
+ {
+ if(interfaceCount > 0)
+ {
+ _out << ", ";
+ }
+ _out << "_M_" << getAbsolute(*q, "_t_", "Disp");
+ ++interfaceCount;
+ }
}
- _out << fixIdent((*r)->name()) << "', ";
- writeMetaData((*r)->getMetaData());
- _out << ", ";
- writeType((*r)->type());
- _out << ", " << ((*r)->optional() ? "True" : "False") << ", "
- << ((*r)->optional() ? (*r)->tag() : 0) << ')';
- }
- if(members.size() == 1)
- {
- _out << ',';
- }
- else if(members.size() > 1)
- {
- _out.dec();
- _out << nl;
- }
- _out << "))";
- _out << nl << name << "._ice_type = _M_" << type;
-
- //
- // Define each operation. The arguments to the IcePy.Operation constructor are:
- //
- // 'opName', Mode, SendMode, AMD, Format, MetaData, (InParams), (OutParams), ReturnParam, (Exceptions)
- //
- // where InParams and OutParams are tuples of type descriptions, and Exceptions
- // is a tuple of exception type ids.
- //
- if(!p->isLocal())
- {
+ if(interfaceCount == 1)
+ {
+ _out << ',';
+ }
+ _out << "))";
+ _out << nl << className << "._ice_type = _M_" << classType;
+
+
+ //
+ // Define each operation. The arguments to the IcePy.Operation constructor are:
+ //
+ // 'opName', Mode, SendMode, AMD, Format, MetaData, (InParams), (OutParams), ReturnParam, (Exceptions)
+ //
+ // where InParams and OutParams are tuples of type descriptions, and Exceptions
+ // is a tuple of exception type ids.
+ //
if(!ops.empty())
{
_out << sp;
@@ -910,10 +1051,10 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
break;
}
- _out << nl << name << "._op_" << (*s)->name() << " = IcePy.Operation('" << (*s)->name() << "', "
- << getOperationMode((*s)->mode()) << ", " << getOperationMode((*s)->sendMode()) << ", "
- << ((p->hasMetaData("amd") || (*s)->hasMetaData("amd")) ? "True" : "False") << ", "
- << format << ", ";
+ _out << nl << className << "._op_" << (*s)->name() << " = IcePy.Operation('" << (*s)->name() << "', "
+ << getOperationMode((*s)->mode()) << ", " << getOperationMode((*s)->sendMode()) << ", "
+ << ((p->hasMetaData("amd") || (*s)->hasMetaData("amd")) ? "True" : "False") << ", "
+ << format << ", ";
writeMetaData((*s)->getMetaData());
_out << ", (";
for(t = params.begin(), count = 0; t != params.end(); ++t)
@@ -951,7 +1092,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
_out << ", ";
writeType((*t)->type());
_out << ", " << ((*t)->optional() ? "True" : "False") << ", "
- << ((*t)->optional() ? (*t)->tag() : 0) << ')';
+ << ((*t)->optional() ? (*t)->tag() : 0) << ')';
++count;
}
}
@@ -1002,20 +1143,14 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
{
msg = deprecateMetadata.substr(pos + 1);
}
- _out << nl << name << "._op_" << (*s)->name() << ".deprecate(\"" << msg << "\")";
+ _out << nl << className << "._op_" << (*s)->name() << ".deprecate(\"" << msg << "\")";
}
}
- }
-
- registerName(name);
- if(!p->isLocal())
- {
- registerName(prxName);
+ registerName(className);
+ _out.dec();
}
- _out.dec();
-
if(_classHistory.count(scoped) == 0)
{
_classHistory.insert(scoped); // Avoid redundant declarations.
@@ -1588,12 +1723,12 @@ Slice::Python::CodeVisitor::visitConst(const ConstPtr& p)
}
string
-Slice::Python::CodeVisitor::getSymbol(const ContainedPtr& p, const string& nameSuffix)
+Slice::Python::CodeVisitor::getSymbol(const ContainedPtr& p, const string& prefix, const string& suffix)
{
//
// An explicit reference to another type must always be prefixed with "_M_".
//
- return "_M_" + getAbsolute(p, "", nameSuffix);
+ return "_M_" + getAbsolute(p, prefix, suffix);
}
void
@@ -1655,7 +1790,7 @@ Slice::Python::CodeVisitor::writeType(const TypePtr& p)
case Builtin::KindObject:
case Builtin::KindValue:
{
- _out << "IcePy._t_Object";
+ _out << "IcePy._t_Value";
break;
}
case Builtin::KindObjectProxy:
@@ -1675,7 +1810,15 @@ Slice::Python::CodeVisitor::writeType(const TypePtr& p)
ProxyPtr prx = ProxyPtr::dynamicCast(p);
if(prx)
{
- _out << "_M_" << getAbsolute(prx->_class(), "_t_", "Prx");
+ ClassDefPtr def = prx->_class()->definition();
+ if(def->isInterface() || def->allOperations().size() > 0)
+ {
+ _out << "_M_" << getAbsolute(prx->_class(), "_t_", "Prx");
+ }
+ else
+ {
+ _out << "IcePy._t_ObjectPrx";
+ }
return;
}
@@ -2815,14 +2958,7 @@ Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix, const
}
}
- if(suffix.empty())
- {
- return scope + fixIdent(cont->name() + nameSuffix);
- }
- else
- {
- return scope + suffix + fixIdent(cont->name() + nameSuffix);
- }
+ return scope + suffix + fixIdent(cont->name() + nameSuffix);
}
void