[hydra-commits] file: branch ice/slice-translator-versioning r659 - in /ice/branches/slice-tr...

SVN commits to the Hydra project hydra-commits at lists.digium.com
Thu Jun 3 13:14:29 CDT 2010


Author: file
Date: Thu Jun  3 13:14:28 2010
New Revision: 659

URL: https://origsvn.digium.com/svn-view/hydra?view=rev&rev=659
Log:
Add suppress support to ruby.

Modified:
    ice/branches/slice-translator-versioning/cpp/include/Slice/RubyUtil.h
    ice/branches/slice-translator-versioning/cpp/src/Slice/RubyUtil.cpp
    ice/branches/slice-translator-versioning/cpp/src/slice2rb/Main.cpp

Modified: ice/branches/slice-translator-versioning/cpp/include/Slice/RubyUtil.h
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-translator-versioning/cpp/include/Slice/RubyUtil.h?view=diff&rev=659&r1=658&r2=659
==============================================================================
--- ice/branches/slice-translator-versioning/cpp/include/Slice/RubyUtil.h (original)
+++ ice/branches/slice-translator-versioning/cpp/include/Slice/RubyUtil.h Thu Jun  3 13:14:28 2010
@@ -21,7 +21,7 @@
 //
 // Generate Ruby 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);
 
 //
 // Check the given identifier against Ruby's list of reserved words. If it matches
@@ -39,7 +39,7 @@
 // Get the fully-qualified name of the given definition. If a prefix is provided,
 // it is prepended to the definition's unqualified name.
 //
-SLICE_API std::string getAbsolute(const Slice::ContainedPtr&, IdentStyle, const std::string& = std::string());
+SLICE_API std::string getAbsolute(const Slice::ContainedPtr&, bool, IdentStyle, const std::string& = std::string());
 
 //
 // Emit a comment header.

Modified: ice/branches/slice-translator-versioning/cpp/src/Slice/RubyUtil.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-translator-versioning/cpp/src/Slice/RubyUtil.cpp?view=diff&rev=659&r1=658&r2=659
==============================================================================
--- ice/branches/slice-translator-versioning/cpp/src/Slice/RubyUtil.cpp (original)
+++ ice/branches/slice-translator-versioning/cpp/src/Slice/RubyUtil.cpp Thu Jun  3 13:14:28 2010
@@ -34,7 +34,7 @@
 {
 public:
 
-    CodeVisitor(IceUtilInternal::Output&);
+    CodeVisitor(IceUtilInternal::Output&, bool);
 
     virtual bool visitModuleStart(const ModulePtr&);
     virtual void visitModuleEnd(const ModulePtr&);
@@ -98,9 +98,30 @@
 
     Output& _out;
     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
@@ -163,24 +184,28 @@
 //
 // CodeVisitor implementation.
 //
-Slice::Ruby::CodeVisitor::CodeVisitor(Output& out) :
-    _out(out)
+Slice::Ruby::CodeVisitor::CodeVisitor(Output& out, bool suppress) :
+    _out(out), _suppress(suppress)
 {
 }
 
 bool
 Slice::Ruby::CodeVisitor::visitModuleStart(const ModulePtr& p)
 {
-    _out << sp << nl << "module " << fixIdent(p->name(), IdentToUpper);
-    _out.inc();
+    if (!p->hasMetaData("suppress") || !_suppress) {
+	_out << sp << nl << "module " << fixIdent(p->name(), IdentToUpper);
+	_out.inc();
+    }
     return true;
 }
 
 void
 Slice::Ruby::CodeVisitor::visitModuleEnd(const ModulePtr& p)
 {
-    _out.dec();
-    _out << nl << "end";
+    if (!p->hasMetaData("suppress") || !_suppress) {
+	_out.dec();
+	_out << nl << "end";
+    }
 }
 
 void
@@ -193,7 +218,7 @@
     if(_classHistory.count(scoped) == 0)
     {
         string name = "T_" + fixIdent(p->name(), IdentToUpper);
-        _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_") << ')';
+        _out << sp << nl << "if not defined?(" << getAbsolute(p, _suppress, IdentToUpper, "T_") << ')';
         _out.inc();
         if(p->isLocal())
         {
@@ -223,7 +248,7 @@
     //
     // Define a mix-in module for the class.
     //
-    _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper) << "_mixin)";
+    _out << sp << nl << "if not defined?(" << getAbsolute(p, _suppress, IdentToUpper) << "_mixin)";
     _out.inc();
     _out << nl << "module " << name << "_mixin";
     _out.inc();
@@ -233,7 +258,7 @@
         if(!bases.empty() && !bases.front()->isInterface())
         {
             base = bases.front();
-            _out << nl << "include " << getAbsolute(bases.front(), IdentToUpper) << "_mixin";
+            _out << nl << "include " << getAbsolute(bases.front(), _suppress, IdentToUpper) << "_mixin";
         }
         else
         {
@@ -434,7 +459,7 @@
         _out << nl << "class " << name;
         if(base)
         {
-            _out << " < " << getAbsolute(base, IdentToUpper);
+            _out << " < " << getAbsolute(base, _suppress, IdentToUpper);
         }
         _out.inc();
         _out << nl << "include " << name << "_mixin";
@@ -507,7 +532,7 @@
         _out.inc();
         for(ClassList::iterator cli = bases.begin(); cli != bases.end(); ++cli)
         {
-            _out << nl << "include " << getAbsolute(*cli, IdentToUpper) << "Prx_mixin";
+            _out << nl << "include " << getAbsolute(*cli, _suppress, IdentToUpper) << "Prx_mixin";
         }
         for(oli = ops.begin(); oli != ops.end(); ++oli)
         {
@@ -591,7 +616,7 @@
     //
     // Emit type descriptions.
     //
-    _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_") << ')';
+    _out << sp << nl << "if not defined?(" << getAbsolute(p, _suppress, IdentToUpper, "T_") << ')';
     _out.inc();
     if(p->isLocal())
     {
@@ -614,7 +639,7 @@
     }
     else
     {
-        _out << getAbsolute(base, IdentToUpper, "T_");
+        _out << getAbsolute(base, _suppress, IdentToUpper, "T_");
     }
     _out << ", [";
     //
@@ -632,7 +657,7 @@
                 {
                     _out << ", ";
                 }
-                _out << getAbsolute(*q, IdentToUpper, "T_");
+                _out << getAbsolute(*q, _suppress, IdentToUpper, "T_");
                 ++interfaceCount;
             }
         }
@@ -766,7 +791,7 @@
                 {
                     _out << ", ";
                 }
-                _out << getAbsolute(*u, IdentToUpper, "T_");
+                _out << getAbsolute(*u, _suppress, IdentToUpper, "T_");
             }
             _out << "])";
 
@@ -796,14 +821,14 @@
     string scoped = p->scoped();
     string name = fixIdent(p->name(), IdentToUpper);
 
-    _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper) << ')';
+    _out << sp << nl << "if not defined?(" << getAbsolute(p, _suppress, IdentToUpper) << ')';
     _out.inc();
     _out << nl << "class " << name << " < ";
     ExceptionPtr base = p->base();
     string baseName;
     if(base)
     {
-        baseName = getAbsolute(base, IdentToUpper);
+        baseName = getAbsolute(base, _suppress, IdentToUpper);
         _out << baseName;
     }
     else if(p->isLocal())
@@ -903,7 +928,7 @@
     }
     else
     {
-         _out << getAbsolute(base, IdentToUpper, "T_");
+	_out << getAbsolute(base, _suppress, IdentToUpper, "T_");
     }
     _out << ", [";
     if(members.size() > 1)
@@ -962,7 +987,7 @@
         }
     }
 
-    _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper) << ')';
+    _out << sp << nl << "if not defined?(" << getAbsolute(p, _suppress, IdentToUpper) << ')';
     _out.inc();
     _out << nl << "class " << name;
     _out.inc();
@@ -1101,7 +1126,7 @@
     //
     string name = fixIdent(p->name(), IdentToUpper);
     string scoped = p->scoped();
-    _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_") << ')';
+    _out << sp << nl << "if not defined?(" << getAbsolute(p, _suppress, IdentToUpper, "T_") << ')';
     _out.inc();
     _out << nl << "T_" << name << " = ::Ice::__defineSequence('" << scoped << "', ";
     writeType(p->type());
@@ -1118,7 +1143,7 @@
     //
     string name = fixIdent(p->name(), IdentToUpper);
     string scoped = p->scoped();
-    _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_") << ')';
+    _out << sp << nl << "if not defined?(" << getAbsolute(p, _suppress, IdentToUpper, "T_") << ')';
     _out.inc();
     _out << nl << "T_" << name << " = ::Ice::__defineDictionary('" << scoped << "', ";
     writeType(p->keyType());
@@ -1138,7 +1163,7 @@
     EnumeratorList::iterator q;
     int i;
 
-    _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper) << ')';
+    _out << sp << nl << "if not defined?(" << getAbsolute(p, _suppress, IdentToUpper) << ')';
     _out.inc();
     _out << nl << "class " << name;
     _out.inc();
@@ -1364,13 +1389,13 @@
     ProxyPtr prx = ProxyPtr::dynamicCast(p);
     if(prx)
     {
-        _out << getAbsolute(prx->_class(), IdentToUpper, "T_") << "Prx";
+        _out << getAbsolute(prx->_class(), _suppress, IdentToUpper, "T_") << "Prx";
         return;
     }
 
     ContainedPtr cont = ContainedPtr::dynamicCast(p);
     assert(cont);
-    _out << getAbsolute(cont, IdentToUpper, "T_");
+    _out << getAbsolute(cont, _suppress, IdentToUpper, "T_");
 }
 
 string
@@ -1414,13 +1439,13 @@
     if(en)
     {
         EnumeratorList enums = en->getEnumerators();
-        return getAbsolute(en, IdentToUpper) + "::" + fixIdent(enums.front()->name(), IdentToUpper);
+        return getAbsolute(en, _suppress, IdentToUpper) + "::" + fixIdent(enums.front()->name(), IdentToUpper);
     }
 
     StructPtr st = StructPtr::dynamicCast(p);
     if(st)
     {
-        return getAbsolute(st, IdentToUpper) + ".new";
+        return getAbsolute(st, _suppress, IdentToUpper) + ".new";
     }
 
     return "nil";
@@ -1545,7 +1570,7 @@
     }
     else if(en)
     {
-        _out << getAbsolute(en, IdentToUpper) << "::";
+        _out << getAbsolute(en, _suppress, IdentToUpper) << "::";
         string::size_type colon = value.rfind(':');
         if(colon != string::npos)
         {
@@ -1629,7 +1654,7 @@
 }
 
 void
-Slice::Ruby::generate(const UnitPtr& un, bool all, bool checksum, const vector<string>& includePaths, Output& out)
+Slice::Ruby::generate(const UnitPtr& un, bool all, bool checksum, const vector<string>& includePaths, Output& out, bool suppress)
 {
     out << nl << "require 'Ice'";
 
@@ -1649,7 +1674,7 @@
         }
     }
 
-    CodeVisitor codeVisitor(out);
+    CodeVisitor codeVisitor(out, suppress);
     un->visit(&codeVisitor, false);
 
     if(checksum)
@@ -1736,9 +1761,9 @@
 }
 
 string
-Slice::Ruby::getAbsolute(const ContainedPtr& cont, IdentStyle style, const string& prefix)
-{
-    string scope = fixIdent(cont->scope(), IdentToUpper);
+Slice::Ruby::getAbsolute(const ContainedPtr& cont, bool suppress, IdentStyle style, const string& prefix)
+{
+    string scope = fixIdent(suppressedscoped(cont->container(), cont->scope(), suppress), IdentToUpper);
 
     if(prefix.empty())
     {

Modified: ice/branches/slice-translator-versioning/cpp/src/slice2rb/Main.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-translator-versioning/cpp/src/slice2rb/Main.cpp?view=diff&rev=659&r1=658&r2=659
==============================================================================
--- ice/branches/slice-translator-versioning/cpp/src/slice2rb/Main.cpp (original)
+++ ice/branches/slice-translator-versioning/cpp/src/slice2rb/Main.cpp Thu Jun  3 13:14:28 2010
@@ -89,6 +89,7 @@
         "--ice                Permit `Ice' prefix (for building Ice source code only)\n"
         "--all                Generate code for Slice definitions in included files.\n"
         "--checksum           Generate checksums for Slice definitions.\n"
+	"--suppress           Suppress tagged modules from being written.\n"
         ;
 }
 
@@ -108,6 +109,7 @@
     opts.addOpt("", "ice");
     opts.addOpt("", "all");
     opts.addOpt("", "checksum");
+    opts.addOpt("", "suppress");
      
     vector<string> args;
     try
@@ -166,6 +168,8 @@
     bool all = opts.isSet("all");
 
     bool checksum = opts.isSet("checksum");
+
+    bool suppress = opts.isSet("suppress");
 
     if(args.empty())
     {
@@ -283,7 +287,7 @@
                         //
                         // Generate the Ruby 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