[hydra-commits] file: branch ice/slice-translator-versioning r657 - in /ice/branches/slice-tr...
SVN commits to the Hydra project
hydra-commits at lists.digium.com
Thu Jun 3 11:49:48 CDT 2010
Author: file
Date: Thu Jun 3 11:49:48 2010
New Revision: 657
URL: https://origsvn.digium.com/svn-view/hydra?view=rev&rev=657
Log:
Add suppress support to the python translator. This is still in progress and being tested.
Modified:
ice/branches/slice-translator-versioning/cpp/include/Slice/PythonUtil.h
ice/branches/slice-translator-versioning/cpp/src/Slice/PythonUtil.cpp
ice/branches/slice-translator-versioning/cpp/src/slice2py/Main.cpp
Modified: ice/branches/slice-translator-versioning/cpp/include/Slice/PythonUtil.h
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-translator-versioning/cpp/include/Slice/PythonUtil.h?view=diff&rev=657&r1=656&r2=657
==============================================================================
--- ice/branches/slice-translator-versioning/cpp/include/Slice/PythonUtil.h (original)
+++ ice/branches/slice-translator-versioning/cpp/include/Slice/PythonUtil.h Thu Jun 3 11:49:48 2010
@@ -21,7 +21,7 @@
//
// Generate Python code for a translation unit.
//
-SLICE_API void generate(const Slice::UnitPtr&, bool, bool, const std::vector<std::string>&, IceUtilInternal::Output&);
+SLICE_API void generate(const Slice::UnitPtr&, bool, bool, const std::vector<std::string>&, IceUtilInternal::Output&, bool);
//
// Convert a scoped name into a Python name.
@@ -49,7 +49,7 @@
// COMPILERFIX: MSVC 6 seems to have a problem with const std::string
// = std::string(), const std::string = std::string().
//
-SLICE_API std::string getAbsolute(const Slice::ContainedPtr&, const std::string& = "", const std::string& = "");
+SLICE_API std::string getAbsolute(const Slice::ContainedPtr&, bool suppress, const std::string& = "", const std::string& = "");
//
// Emit a comment header.
Modified: ice/branches/slice-translator-versioning/cpp/src/Slice/PythonUtil.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-translator-versioning/cpp/src/Slice/PythonUtil.cpp?view=diff&rev=657&r1=656&r2=657
==============================================================================
--- ice/branches/slice-translator-versioning/cpp/src/Slice/PythonUtil.cpp (original)
+++ ice/branches/slice-translator-versioning/cpp/src/Slice/PythonUtil.cpp Thu Jun 3 11:49:48 2010
@@ -73,7 +73,7 @@
{
public:
- ModuleVisitor(Output&, set<string>&);
+ ModuleVisitor(Output&, set<string>&, bool);
virtual bool visitModuleStart(const ModulePtr&);
@@ -81,6 +81,8 @@
Output& _out;
set<string>& _history;
+
+ bool _suppress;
};
//
@@ -90,7 +92,7 @@
{
public:
- CodeVisitor(IceUtilInternal::Output&, set<string>&);
+ CodeVisitor(IceUtilInternal::Output&, set<string>&, bool);
virtual bool visitModuleStart(const ModulePtr&);
virtual void visitModuleEnd(const ModulePtr&);
@@ -172,9 +174,30 @@
set<string>& _moduleHistory;
list<string> _moduleStack;
set<string> _classHistory;
+
+ bool _suppress;
};
}
+}
+
+static string
+suppressedscoped(const ContainerPtr& cp, string scope, bool _suppress)
+{
+ string suppressed_scope = scope;
+
+ if (_suppress) {
+ for (ContainedPtr contained = ContainedPtr::dynamicCast(cp); contained; contained = ContainedPtr::dynamicCast(contained->container())) {
+ ModulePtr mod = ModulePtr::dynamicCast(contained);
+ if (mod && mod->hasMetaData("suppress")) {
+ string suppress_string = "::" + mod->name();
+ string::size_type pos = suppressed_scope.rfind(suppress_string);
+ suppressed_scope.replace(pos, suppress_string.length(), "");
+ }
+ }
+ }
+
+ return suppressed_scope;
}
static string
@@ -231,9 +254,9 @@
}
static string
-getDictLookup(const ContainedPtr& cont, const string& suffix = string())
-{
- string scope = Slice::Python::scopedToName(cont->scope());
+getDictLookup(const ContainedPtr& cont, bool suppress, const string& suffix = string())
+{
+ string scope = Slice::Python::scopedToName(suppressedscoped(cont->container(), cont->scope(), suppress));
assert(!scope.empty());
string package = Slice::Python::getPackageMetadata(cont);
@@ -248,17 +271,17 @@
//
// ModuleVisitor implementation.
//
-Slice::Python::ModuleVisitor::ModuleVisitor(Output& out, set<string>& history) :
- _out(out), _history(history)
+Slice::Python::ModuleVisitor::ModuleVisitor(Output& out, set<string>& history, bool suppress) :
+ _out(out), _history(history), _suppress(suppress)
{
}
bool
Slice::Python::ModuleVisitor::visitModuleStart(const ModulePtr& p)
{
- if(p->includeLevel() > 0)
- {
- string abs = getAbsolute(p);
+ if(p->includeLevel() > 0 && (!p->hasMetaData("suppress") || !_suppress))
+ {
+ string abs = getAbsolute(p, _suppress);
if(_history.count(abs) == 0)
{
//
@@ -298,8 +321,8 @@
//
// CodeVisitor implementation.
//
-Slice::Python::CodeVisitor::CodeVisitor(Output& out, set<string>& moduleHistory) :
- _out(out), _moduleHistory(moduleHistory)
+Slice::Python::CodeVisitor::CodeVisitor(Output& out, set<string>& moduleHistory, bool suppress) :
+ _out(out), _moduleHistory(moduleHistory), _suppress(suppress)
{
}
@@ -320,7 +343,11 @@
//
// This allows us to create types in the module Foo.
//
- string abs = getAbsolute(p);
+ if (p->hasMetaData("suppress") && _suppress) {
+ return true;
+ }
+
+ string abs = getAbsolute(p, _suppress);
_out << sp << nl << "# Start of module " << abs;
if(_moduleHistory.count(abs) == 0) // Don't emit this more than once for each module.
{
@@ -366,13 +393,15 @@
void
Slice::Python::CodeVisitor::visitModuleEnd(const ModulePtr& p)
{
- assert(!_moduleStack.empty());
- _out << sp << nl << "# End of module " << _moduleStack.front();
- _moduleStack.pop_front();
-
- if(!_moduleStack.empty())
- {
- _out << sp << nl << "__name__ = '" << _moduleStack.front() << "'";
+ if (!p->hasMetaData("suppress") || !_suppress) {
+ assert(!_moduleStack.empty());
+ _out << sp << nl << "# End of module " << _moduleStack.front();
+ _moduleStack.pop_front();
+
+ if(!_moduleStack.empty())
+ {
+ _out << sp << nl << "__name__ = '" << _moduleStack.front() << "'";
+ }
}
}
@@ -385,13 +414,13 @@
string scoped = p->scoped();
if(_classHistory.count(scoped) == 0)
{
- _out << sp << nl << "if not " << getDictLookup(p) << ':';
+ _out << sp << nl << "if not " << getDictLookup(p, _suppress) << ':';
_out.inc();
- string type = getAbsolute(p, "_t_");
+ string type = getAbsolute(p, _suppress, "_t_");
_out << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')";
if(!p->isLocal())
{
- _out << nl << "_M_" << getAbsolute(p, "_t_", "Prx") << " = IcePy.declareProxy('" << scoped << "')";
+ _out << nl << "_M_" << getAbsolute(p, _suppress, "_t_", "Prx") << " = IcePy.declareProxy('" << scoped << "')";
}
_out.dec();
_classHistory.insert(scoped); // Avoid redundant declarations.
@@ -402,12 +431,12 @@
Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
{
string scoped = p->scoped();
- string type = getAbsolute(p, "_t_");
- string abs = getAbsolute(p);
+ string type = getAbsolute(p, _suppress, "_t_");
+ string abs = getAbsolute(p, _suppress);
string name = fixIdent(p->name());
- string prxAbs = getAbsolute(p, "", "Prx");
+ string prxAbs = getAbsolute(p, _suppress, "", "Prx");
string prxName = fixIdent(p->name() + "Prx");
- string prxType = getAbsolute(p, "_t_", "Prx");
+ string prxType = getAbsolute(p, _suppress, "_t_", "Prx");
ClassList bases = p->bases();
ClassDefPtr base;
OperationList ops = p->operations();
@@ -417,7 +446,7 @@
//
// Define the class.
//
- _out << sp << nl << "if not " << getDictLookup(p) << ':';
+ _out << sp << nl << "if not " << getDictLookup(p, _suppress) << ':';
_out.inc();
_out << nl << "_M_" << abs << " = Ice.createTempClass()";
_out << nl << "class " << name << '(';
@@ -627,7 +656,7 @@
//
_out << sp << nl << "def __str__(self):";
_out.inc();
- _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, "_t_") << ")";
+ _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, _suppress, "_t_") << ")";
_out.dec();
_out << sp << nl << "__repr__ = __str__";
@@ -805,7 +834,7 @@
}
else
{
- _out << "_M_" << getAbsolute(base, "_t_");
+ _out << "_M_" << getAbsolute(base, _suppress, "_t_");
}
_out << ", (";
//
@@ -820,7 +849,7 @@
{
_out << ", ";
}
- _out << "_M_" << getAbsolute(*q, "_t_");
+ _out << "_M_" << getAbsolute(*q, _suppress, "_t_");
++interfaceCount;
}
}
@@ -957,7 +986,7 @@
{
_out << ", ";
}
- _out << "_M_" << getAbsolute(*u, "_t_");
+ _out << "_M_" << getAbsolute(*u, _suppress, "_t_");
}
if(exceptions.size() == 1)
{
@@ -1000,10 +1029,10 @@
Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
{
string scoped = p->scoped();
- string abs = getAbsolute(p);
+ string abs = getAbsolute(p, _suppress);
string name = fixIdent(p->name());
- _out << sp << nl << "if not " << getDictLookup(p) << ':';
+ _out << sp << nl << "if not " << getDictLookup(p, _suppress) << ':';
_out.inc();
_out << nl << "_M_" << abs << " = Ice.createTempClass()";
_out << nl << "class " << name << '(';
@@ -1090,7 +1119,7 @@
//
// Emit the type information.
//
- string type = getAbsolute(p, "_t_");
+ string type = getAbsolute(p, _suppress, "_t_");
_out << sp << nl << "_M_" << type << " = IcePy.defineException('" << scoped << "', " << name << ", ";
writeMetaData(p->getMetaData());
_out << ", ";
@@ -1100,7 +1129,7 @@
}
else
{
- _out << "_M_" << getAbsolute(base, "_t_");
+ _out << "_M_" << getAbsolute(base, _suppress, "_t_");
}
_out << ", (";
if(members.size() > 1)
@@ -1150,7 +1179,7 @@
Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
{
string scoped = p->scoped();
- string abs = getAbsolute(p);
+ string abs = getAbsolute(p, _suppress);
string name = fixIdent(p->name());
MemberInfoList memberList;
MemberInfoList::iterator r;
@@ -1166,7 +1195,7 @@
}
}
- _out << sp << nl << "if not " << getDictLookup(p) << ':';
+ _out << sp << nl << "if not " << getDictLookup(p, _suppress) << ':';
_out.inc();
_out << nl << "_M_" << abs << " = Ice.createTempClass()";
_out << nl << "class " << name << "(object):";
@@ -1257,7 +1286,7 @@
//
_out << sp << nl << "def __str__(self):";
_out.inc();
- _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, "_t_") << ")";
+ _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, _suppress, "_t_") << ")";
_out.dec();
_out << sp << nl << "__repr__ = __str__";
@@ -1266,7 +1295,7 @@
//
// Emit the type information.
//
- _out << sp << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineStruct('" << scoped << "', " << name << ", ";
+ _out << sp << nl << "_M_" << getAbsolute(p, _suppress, "_t_") << " = IcePy.defineStruct('" << scoped << "', " << name << ", ";
writeMetaData(p->getMetaData());
_out << ", (";
//
@@ -1337,18 +1366,18 @@
// Emit the type information.
//
string scoped = p->scoped();
- _out << sp << nl << "if not " << getDictLookup(p, "_t_") << ':';
+ _out << sp << nl << "if not " << getDictLookup(p, _suppress, "_t_") << ':';
_out.inc();
if(isCustom)
{
string package = customType.substr(0, customType.find('.'));
_out << nl << "import " << package;
- _out << nl << "_M_" << getAbsolute(p, "_t_")
+ _out << nl << "_M_" << getAbsolute(p, _suppress, "_t_")
<< " = IcePy.defineCustom('" << scoped << "', " << customType << ")";
}
else
{
- _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineSequence('" << scoped << "', ";
+ _out << nl << "_M_" << getAbsolute(p, _suppress, "_t_") << " = IcePy.defineSequence('" << scoped << "', ";
writeMetaData(metaData);
_out << ", ";
writeType(p->type());
@@ -1364,9 +1393,9 @@
// Emit the type information.
//
string scoped = p->scoped();
- _out << sp << nl << "if not " << getDictLookup(p, "_t_") << ':';
+ _out << sp << nl << "if not " << getDictLookup(p, _suppress, "_t_") << ':';
_out.inc();
- _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineDictionary('" << scoped << "', ";
+ _out << nl << "_M_" << getAbsolute(p, _suppress, "_t_") << " = IcePy.defineDictionary('" << scoped << "', ";
writeMetaData(p->getMetaData());
_out << ", ";
writeType(p->keyType());
@@ -1380,13 +1409,13 @@
Slice::Python::CodeVisitor::visitEnum(const EnumPtr& p)
{
string scoped = p->scoped();
- string abs = getAbsolute(p);
+ string abs = getAbsolute(p, _suppress);
string name = fixIdent(p->name());
EnumeratorList enums = p->getEnumerators();
EnumeratorList::iterator q;
int i;
- _out << sp << nl << "if not " << getDictLookup(p) << ':';
+ _out << sp << nl << "if not " << getDictLookup(p, _suppress) << ':';
_out.inc();
_out << nl << "_M_" << abs << " = Ice.createTempClass()";
_out << nl << "class " << name << "(object):";
@@ -1476,7 +1505,7 @@
//
// Emit the type information.
//
- _out << sp << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineEnum('" << scoped << "', " << name
+ _out << sp << nl << "_M_" << getAbsolute(p, _suppress, "_t_") << " = IcePy.defineEnum('" << scoped << "', " << name
<< ", ";
writeMetaData(p->getMetaData());
_out << ", (";
@@ -1507,7 +1536,7 @@
string value = p->value();
string name = fixIdent(p->name());
- _out << sp << nl << "_M_" << getAbsolute(p) << " = ";
+ _out << sp << nl << "_M_" << getAbsolute(p, _suppress) << " = ";
writeConstantValue(type, value);
}
@@ -1517,7 +1546,7 @@
//
// An explicit reference to another type must always be prefixed with "_M_".
//
- return "_M_" + getAbsolute(p, "", nameSuffix);
+ return "_M_" + getAbsolute(p, _suppress, "", nameSuffix);
}
void
@@ -1598,13 +1627,13 @@
ProxyPtr prx = ProxyPtr::dynamicCast(p);
if(prx)
{
- _out << "_M_" << getAbsolute(prx->_class(), "_t_", "Prx");
+ _out << "_M_" << getAbsolute(prx->_class(), _suppress, "_t_", "Prx");
return;
}
ContainedPtr cont = ContainedPtr::dynamicCast(p);
assert(cont);
- _out << "_M_" << getAbsolute(cont, "_t_");
+ _out << "_M_" << getAbsolute(cont, _suppress, "_t_");
}
void
@@ -2189,7 +2218,7 @@
}
void
-Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, const vector<string>& includePaths, Output& out)
+Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, const vector<string>& includePaths, Output& out, bool suppress)
{
Slice::Python::MetaDataVisitor visitor;
un->visit(&visitor, false);
@@ -2215,10 +2244,10 @@
set<string> moduleHistory;
- ModuleVisitor moduleVisitor(out, moduleHistory);
+ ModuleVisitor moduleVisitor(out, moduleHistory, suppress);
un->visit(&moduleVisitor, true);
- CodeVisitor codeVisitor(out, moduleHistory);
+ CodeVisitor codeVisitor(out, moduleHistory, suppress);
un->visit(&codeVisitor, false);
if(checksum)
@@ -2299,9 +2328,9 @@
}
string
-Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix, const string& nameSuffix)
-{
- string scope = scopedToName(cont->scope());
+Slice::Python::getAbsolute(const ContainedPtr& cont, bool suppress, const string& suffix, const string& nameSuffix)
+{
+ string scope = scopedToName(suppressedscoped(cont->container(), cont->scope(), suppress));
string package = getPackageMetadata(cont);
if(!package.empty())
Modified: ice/branches/slice-translator-versioning/cpp/src/slice2py/Main.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-translator-versioning/cpp/src/slice2py/Main.cpp?view=diff&rev=657&r1=656&r2=657
==============================================================================
--- ice/branches/slice-translator-versioning/cpp/src/slice2py/Main.cpp (original)
+++ ice/branches/slice-translator-versioning/cpp/src/slice2py/Main.cpp Thu Jun 3 11:49:48 2010
@@ -170,7 +170,7 @@
// Collect the most deeply-nested modules. For example, if we have a
// module named M.N.O, then we don't need to keep M or M.N in the list.
//
- string abs = getAbsolute(p);
+ string abs = getAbsolute(p, false);
if(find(_modules.begin(), _modules.end(), abs) == _modules.end())
{
_modules.push_back(abs);
@@ -377,6 +377,7 @@
"--all Generate code for Slice definitions in included files.\n"
"--checksum Generate checksums for Slice definitions.\n"
"--prefix PREFIX Prepend filenames of Python modules with PREFIX.\n"
+ "--suppress Suppress tagged modules from being written.\n"
;
}
@@ -398,6 +399,7 @@
opts.addOpt("", "no-package");
opts.addOpt("", "checksum");
opts.addOpt("", "prefix", IceUtilInternal::Options::NeedArg);
+ opts.addOpt("", "suppress");
vector<string> args;
try
@@ -460,6 +462,8 @@
bool checksum = opts.isSet("checksum");
string prefix = opts.optArg("prefix");
+
+ bool suppress = opts.isSet("suppress");
if(args.empty())
{
@@ -584,7 +588,7 @@
//
// Generate the Python mapping.
//
- generate(u, all, checksum, includePaths, out);
+ generate(u, all, checksum, includePaths, out, suppress);
out.close();
More information about the asterisk-scf-commits
mailing list