summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/PythonUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Slice/PythonUtil.cpp')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp468
1 files changed, 234 insertions, 234 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index c8cd601580b..426ceff6949 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -144,7 +144,7 @@ private:
string fixedName;
TypePtr type;
bool inherited;
- StringList metaData;
+ StringList metaData;
};
typedef list<MemberInfo> MemberInfoList;
@@ -222,7 +222,7 @@ getDictLookup(const ContainedPtr& cont, const string& suffix = string())
string package = Slice::Python::getPackageMetadata(cont);
if(!package.empty())
{
- scope = package + "." + scope;
+ scope = package + "." + scope;
}
return "_M_" + scope + "__dict__.has_key('" + suffix + Slice::Python::fixIdent(cont->name()) + "')";
@@ -361,15 +361,15 @@ Slice::Python::CodeVisitor::visitClassDecl(const ClassDeclPtr& p)
string scoped = p->scoped();
if(_classHistory.count(scoped) == 0)
{
- _out << sp << nl << "if not " << getDictLookup(p) << ':';
- _out.inc();
+ _out << sp << nl << "if not " << getDictLookup(p) << ':';
+ _out.inc();
string type = getAbsolute(p, "_t_");
_out << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')";
- if(!p->isLocal())
- {
- _out << nl << "_M_" << type << "Prx = IcePy.declareProxy('" << scoped << "')";
- }
- _out.dec();
+ if(!p->isLocal())
+ {
+ _out << nl << "_M_" << type << "Prx = IcePy.declareProxy('" << scoped << "')";
+ }
+ _out.dec();
_classHistory.insert(scoped); // Avoid redundant declarations.
}
}
@@ -688,10 +688,10 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
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.declareClass('" << scoped << "')";
+ //
+ // Emit a forward declaration for the class in case a data member refers to this type.
+ //
+ _out << sp << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')";
}
DataMemberList members = p->dataMembers();
@@ -700,11 +700,11 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
_out << ", " << (p->isAbstract() ? "True" : "False") << ", ";
if(!base)
{
- _out << "None";
+ _out << "None";
}
else
{
- _out << "_M_" << getAbsolute(base, "_t_");
+ _out << "_M_" << getAbsolute(base, "_t_");
}
_out << ", (";
//
@@ -713,19 +713,19 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
int interfaceCount = 0;
for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
{
- if((*q)->isInterface())
- {
- if(interfaceCount > 0)
- {
- _out << ", ";
- }
- _out << "_M_" << getAbsolute(*q, "_t_");
- ++interfaceCount;
- }
+ if((*q)->isInterface())
+ {
+ if(interfaceCount > 0)
+ {
+ _out << ", ";
+ }
+ _out << "_M_" << getAbsolute(*q, "_t_");
+ ++interfaceCount;
+ }
}
if(interfaceCount == 1)
{
- _out << ',';
+ _out << ',';
}
//
// Members
@@ -739,29 +739,29 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
_out << "), (";
if(members.size() > 1)
{
- _out.inc();
- _out << nl;
+ _out.inc();
+ _out << nl;
}
for(DataMemberList::iterator r = members.begin(); r != members.end(); ++r)
{
- if(r != members.begin())
- {
- _out << ',' << nl;
- }
- _out << "('" << fixIdent((*r)->name()) << "', ";
- writeMetaData((*r)->getMetaData());
- _out << ", ";
- writeType((*r)->type());
- _out << ')';
+ if(r != members.begin())
+ {
+ _out << ',' << nl;
+ }
+ _out << "('" << fixIdent((*r)->name()) << "', ";
+ writeMetaData((*r)->getMetaData());
+ _out << ", ";
+ writeType((*r)->type());
+ _out << ')';
}
if(members.size() == 1)
{
- _out << ',';
+ _out << ',';
}
else if(members.size() > 1)
{
- _out.dec();
- _out << nl;
+ _out.dec();
+ _out << nl;
}
_out << "))";
_out << nl << name << ".ice_type = _M_" << type;
@@ -776,100 +776,100 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
//
if(!p->isLocal())
{
- if(!ops.empty())
- {
- _out << sp;
- }
- for(OperationList::iterator s = ops.begin(); s != ops.end(); ++s)
- {
- ParamDeclList params = (*s)->parameters();
- ParamDeclList::iterator t;
- int count;
-
- _out << nl << name << "._op_" << (*s)->name() << " = IcePy.Operation('" << (*s)->name() << "', "
- << getOperationMode((*s)->mode()) << ", " << getOperationMode((*s)->sendMode()) << ", "
- << ((p->hasMetaData("amd") || (*s)->hasMetaData("amd")) ? "True" : "False") << ", ";
- writeMetaData((*s)->getMetaData());
- _out << ", (";
- for(t = params.begin(), count = 0; t != params.end(); ++t)
- {
- if(!(*t)->isOutParam())
- {
- if(count > 0)
- {
- _out << ", ";
- }
- _out << '(';
- writeMetaData((*t)->getMetaData());
- _out << ", ";
- writeType((*t)->type());
- _out << ')';
- ++count;
- }
- }
- if(count == 1)
- {
- _out << ',';
- }
- _out << "), (";
- for(t = params.begin(), count = 0; t != params.end(); ++t)
- {
- if((*t)->isOutParam())
- {
- if(count > 0)
- {
- _out << ", ";
- }
- _out << '(';
- writeMetaData((*t)->getMetaData());
- _out << ", ";
- writeType((*t)->type());
- _out << ')';
- ++count;
- }
- }
- if(count == 1)
- {
- _out << ',';
- }
- _out << "), ";
- TypePtr returnType = (*s)->returnType();
- if(returnType)
- {
- writeType(returnType);
- }
- else
- {
- _out << "None";
- }
- _out << ", (";
- ExceptionList exceptions = (*s)->throws();
- for(ExceptionList::iterator u = exceptions.begin(); u != exceptions.end(); ++u)
- {
- if(u != exceptions.begin())
- {
- _out << ", ";
- }
- _out << "_M_" << getAbsolute(*u, "_t_");
- }
- if(exceptions.size() == 1)
- {
- _out << ',';
- }
- _out << "))";
-
- string deprecateMetadata;
- if((*s)->findMetaData("deprecate", deprecateMetadata) || p->findMetaData("deprecate", deprecateMetadata))
- {
- string msg;
- string::size_type pos = deprecateMetadata.find(':');
- if(pos != string::npos && pos < deprecateMetadata.size() - 1)
- {
- msg = deprecateMetadata.substr(pos + 1);
- }
- _out << nl << name << "._op_" << (*s)->name() << ".deprecate(\"" << msg << "\")";
- }
- }
+ if(!ops.empty())
+ {
+ _out << sp;
+ }
+ for(OperationList::iterator s = ops.begin(); s != ops.end(); ++s)
+ {
+ ParamDeclList params = (*s)->parameters();
+ ParamDeclList::iterator t;
+ int count;
+
+ _out << nl << name << "._op_" << (*s)->name() << " = IcePy.Operation('" << (*s)->name() << "', "
+ << getOperationMode((*s)->mode()) << ", " << getOperationMode((*s)->sendMode()) << ", "
+ << ((p->hasMetaData("amd") || (*s)->hasMetaData("amd")) ? "True" : "False") << ", ";
+ writeMetaData((*s)->getMetaData());
+ _out << ", (";
+ for(t = params.begin(), count = 0; t != params.end(); ++t)
+ {
+ if(!(*t)->isOutParam())
+ {
+ if(count > 0)
+ {
+ _out << ", ";
+ }
+ _out << '(';
+ writeMetaData((*t)->getMetaData());
+ _out << ", ";
+ writeType((*t)->type());
+ _out << ')';
+ ++count;
+ }
+ }
+ if(count == 1)
+ {
+ _out << ',';
+ }
+ _out << "), (";
+ for(t = params.begin(), count = 0; t != params.end(); ++t)
+ {
+ if((*t)->isOutParam())
+ {
+ if(count > 0)
+ {
+ _out << ", ";
+ }
+ _out << '(';
+ writeMetaData((*t)->getMetaData());
+ _out << ", ";
+ writeType((*t)->type());
+ _out << ')';
+ ++count;
+ }
+ }
+ if(count == 1)
+ {
+ _out << ',';
+ }
+ _out << "), ";
+ TypePtr returnType = (*s)->returnType();
+ if(returnType)
+ {
+ writeType(returnType);
+ }
+ else
+ {
+ _out << "None";
+ }
+ _out << ", (";
+ ExceptionList exceptions = (*s)->throws();
+ for(ExceptionList::iterator u = exceptions.begin(); u != exceptions.end(); ++u)
+ {
+ if(u != exceptions.begin())
+ {
+ _out << ", ";
+ }
+ _out << "_M_" << getAbsolute(*u, "_t_");
+ }
+ if(exceptions.size() == 1)
+ {
+ _out << ',';
+ }
+ _out << "))";
+
+ string deprecateMetadata;
+ if((*s)->findMetaData("deprecate", deprecateMetadata) || p->findMetaData("deprecate", deprecateMetadata))
+ {
+ string msg;
+ string::size_type pos = deprecateMetadata.find(':');
+ if(pos != string::npos && pos < deprecateMetadata.size() - 1)
+ {
+ msg = deprecateMetadata.substr(pos + 1);
+ }
+ _out << nl << name << "._op_" << (*s)->name() << ".deprecate(\"" << msg << "\")";
+ }
+ }
}
registerName(name);
@@ -993,17 +993,17 @@ Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
_out << ", ";
if(!base)
{
- _out << "None";
+ _out << "None";
}
else
{
- _out << "_M_" << getAbsolute(base, "_t_");
+ _out << "_M_" << getAbsolute(base, "_t_");
}
_out << ", (";
if(members.size() > 1)
{
- _out.inc();
- _out << nl;
+ _out.inc();
+ _out << nl;
}
//
// Data members are represented as a tuple:
@@ -1014,24 +1014,24 @@ Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
//
for(dmli = members.begin(); dmli != members.end(); ++dmli)
{
- if(dmli != members.begin())
- {
- _out << ',' << nl;
- }
- _out << "('" << fixIdent((*dmli)->name()) << "', ";
- writeMetaData((*dmli)->getMetaData());
- _out << ", ";
- writeType((*dmli)->type());
- _out << ')';
+ if(dmli != members.begin())
+ {
+ _out << ',' << nl;
+ }
+ _out << "('" << fixIdent((*dmli)->name()) << "', ";
+ writeMetaData((*dmli)->getMetaData());
+ _out << ", ";
+ writeType((*dmli)->type());
+ _out << ')';
}
if(members.size() == 1)
{
- _out << ',';
+ _out << ',';
}
else if(members.size() > 1)
{
- _out.dec();
- _out << nl;
+ _out.dec();
+ _out << nl;
}
_out << "))";
_out << nl << name << ".ice_type = _M_" << type;
@@ -1132,29 +1132,29 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
//
if(memberList.size() > 1)
{
- _out.inc();
- _out << nl;
+ _out.inc();
+ _out << nl;
}
for(r = memberList.begin(); r != memberList.end(); ++r)
{
- if(r != memberList.begin())
- {
- _out << ',' << nl;
- }
- _out << "('" << r->fixedName << "', ";
- writeMetaData(r->metaData);
- _out << ", ";
- writeType(r->type);
- _out << ')';
+ if(r != memberList.begin())
+ {
+ _out << ',' << nl;
+ }
+ _out << "('" << r->fixedName << "', ";
+ writeMetaData(r->metaData);
+ _out << ", ";
+ writeType(r->type);
+ _out << ')';
}
if(memberList.size() == 1)
{
- _out << ',';
+ _out << ',';
}
else if(memberList.size() > 1)
{
- _out.dec();
- _out << nl;
+ _out.dec();
+ _out << nl;
}
_out << "))";
@@ -1271,21 +1271,21 @@ Slice::Python::CodeVisitor::visitEnum(const EnumPtr& p)
// Emit the type information.
//
_out << sp << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineEnum('" << scoped << "', " << name
- << ", ";
+ << ", ";
writeMetaData(p->getMetaData());
_out << ", (";
for(q = enums.begin(); q != enums.end(); ++q)
{
- if(q != enums.begin())
- {
- _out << ", ";
- }
- string fixedEnum = fixIdent((*q)->name());
- _out << name << '.' << fixedEnum;
+ if(q != enums.begin())
+ {
+ _out << ", ";
+ }
+ string fixedEnum = fixIdent((*q)->name());
+ _out << name << '.' << fixedEnum;
}
if(enums.size() == 1)
{
- _out << ',';
+ _out << ',';
}
_out << "))";
@@ -1400,13 +1400,13 @@ Slice::Python::CodeVisitor::visitConst(const ConstPtr& p)
if(charSet.find(*c) == charSet.end())
{
unsigned char uc = *c; // Char may be signed, so make it positive.
- stringstream s;
+ stringstream s;
s << "\\"; // Print as octal if not in basic source character set.
s.flags(ios_base::oct);
s.width(3);
s.fill('0');
s << static_cast<unsigned>(uc);
- _out << s.str();
+ _out << s.str();
}
else
{
@@ -1653,19 +1653,19 @@ Slice::Python::CodeVisitor::writeMetaData(const StringList& meta)
_out << '(';
for(StringList::const_iterator p = meta.begin(); p != meta.end(); ++p)
{
- if(p->find("python:") == 0)
- {
- if(i > 0)
- {
- _out << ", ";
- }
- _out << "'" << *p << "'";
- ++i;
- }
+ if(p->find("python:") == 0)
+ {
+ if(i > 0)
+ {
+ _out << ", ";
+ }
+ _out << "'" << *p << "'";
+ ++i;
+ }
}
if(i == 1)
{
- _out << ',';
+ _out << ',';
}
_out << ')';
}
@@ -1677,14 +1677,14 @@ Slice::Python::CodeVisitor::getOperationMode(Slice::Operation::Mode mode)
switch(mode)
{
case Operation::Normal:
- result = "Ice.OperationMode.Normal";
- break;
+ result = "Ice.OperationMode.Normal";
+ break;
case Operation::Nonmutating:
- result = "Ice.OperationMode.Nonmutating";
- break;
+ result = "Ice.OperationMode.Nonmutating";
+ break;
case Operation::Idempotent:
- result = "Ice.OperationMode.Idempotent";
- break;
+ result = "Ice.OperationMode.Idempotent";
+ break;
}
return result;
}
@@ -1706,7 +1706,7 @@ Slice::Python::CodeVisitor::collectClassMembers(const ClassDefPtr& p, MemberInfo
m.fixedName = fixIdent((*q)->name());
m.type = (*q)->type();
m.inherited = inherited;
- m.metaData = (*q)->getMetaData();
+ m.metaData = (*q)->getMetaData();
allMembers.push_back(m);
}
}
@@ -1728,7 +1728,7 @@ Slice::Python::CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, Membe
m.fixedName = fixIdent((*q)->name());
m.type = (*q)->type();
m.inherited = inherited;
- m.metaData = (*q)->getMetaData();
+ m.metaData = (*q)->getMetaData();
allMembers.push_back(m);
}
}
@@ -1988,10 +1988,10 @@ Slice::Python::MetaDataVisitor::visitModuleStart(const ModulePtr& p)
{
if(!ModulePtr::dynamicCast(p->container()))
{
- //
- // We only need to validate global metadata for top-level modules.
- //
- validateGlobal(p->definitionContext());
+ //
+ // We only need to validate global metadata for top-level modules.
+ //
+ validateGlobal(p->definitionContext());
}
reject(p);
return true;
@@ -2033,13 +2033,13 @@ Slice::Python::MetaDataVisitor::visitOperation(const OperationPtr& p)
TypePtr ret = p->returnType();
if(ret)
{
- validateSequence(dc, p->line(), ret, p->getMetaData());
+ validateSequence(dc, p->line(), ret, p->getMetaData());
}
ParamDeclList params = p->parameters();
for(ParamDeclList::iterator q = params.begin(); q != params.end(); ++q)
{
- validateSequence(dc, (*q)->line(), (*q)->type(), (*q)->getMetaData());
+ validateSequence(dc, (*q)->line(), (*q)->type(), (*q)->getMetaData());
}
}
@@ -2082,48 +2082,48 @@ Slice::Python::MetaDataVisitor::validateGlobal(const DefinitionContextPtr& dc)
for(StringList::const_iterator p = globalMetaData.begin(); p != globalMetaData.end(); ++p)
{
- string s = *p;
- if(_history.count(s) == 0)
- {
- if(s.find(prefix) == 0)
- {
- static const string packagePrefix = "python:package:";
- if(s.find(packagePrefix) != 0 || s.size() == packagePrefix.size())
- {
- cout << dc->filename() << ": warning: ignoring invalid global metadata `" << s << "'" << endl;
- }
- }
- _history.insert(s);
- }
+ string s = *p;
+ if(_history.count(s) == 0)
+ {
+ if(s.find(prefix) == 0)
+ {
+ static const string packagePrefix = "python:package:";
+ if(s.find(packagePrefix) != 0 || s.size() == packagePrefix.size())
+ {
+ cout << dc->filename() << ": warning: ignoring invalid global metadata `" << s << "'" << endl;
+ }
+ }
+ _history.insert(s);
+ }
}
}
void
Slice::Python::MetaDataVisitor::validateSequence(const DefinitionContextPtr& dc, const string& line,
- const TypePtr& type, const StringList& meta)
+ const TypePtr& type, const StringList& meta)
{
static const string prefix = "python:";
for(StringList::const_iterator p = meta.begin(); p != meta.end(); ++p)
{
string s = *p;
- if(s.find(prefix) == 0)
- {
- string::size_type pos = s.find(':', prefix.size());
- if(pos != string::npos && s.substr(prefix.size(), pos - prefix.size()) == "seq")
- {
- static const string seqPrefix = "python:seq:";
- string arg = s.substr(seqPrefix.size(), pos - seqPrefix.size());
- if(SequencePtr::dynamicCast(type))
- {
- if(arg == "tuple" || arg == "list" || arg == "default")
- {
- continue;
- }
- }
- }
- cout << dc->filename() << ":" << line << ": warning: ignoring metadata `" << s << "'" << endl;
- }
+ if(s.find(prefix) == 0)
+ {
+ string::size_type pos = s.find(':', prefix.size());
+ if(pos != string::npos && s.substr(prefix.size(), pos - prefix.size()) == "seq")
+ {
+ static const string seqPrefix = "python:seq:";
+ string arg = s.substr(seqPrefix.size(), pos - seqPrefix.size());
+ if(SequencePtr::dynamicCast(type))
+ {
+ if(arg == "tuple" || arg == "list" || arg == "default")
+ {
+ continue;
+ }
+ }
+ }
+ cout << dc->filename() << ":" << line << ": warning: ignoring metadata `" << s << "'" << endl;
+ }
}
}
@@ -2136,11 +2136,11 @@ Slice::Python::MetaDataVisitor::reject(const ContainedPtr& cont)
for(StringList::const_iterator p = localMetaData.begin(); p != localMetaData.end(); ++p)
{
- if(p->find(prefix) == 0)
- {
- DefinitionContextPtr dc = cont->definitionContext();
- assert(dc);
- cout << dc->filename() << ":" << cont->line() << ": warning: ignoring metadata `" << *p << "'" << endl;
- }
+ if(p->find(prefix) == 0)
+ {
+ DefinitionContextPtr dc = cont->definitionContext();
+ assert(dc);
+ cout << dc->filename() << ":" << cont->line() << ": warning: ignoring metadata `" << *p << "'" << endl;
+ }
}
}