[hydra-commits] beagles: branch ice/slice-preserving-translators r585 - in /ice/branches/slic...

SVN commits to the Hydra project hydra-commits at lists.digium.com
Fri Apr 23 17:51:52 CDT 2010


Author: beagles
Date: Fri Apr 23 17:51:51 2010
New Revision: 585

URL: https://origsvn.digium.com/svn-view/hydra?view=rev&rev=585
Log:
adding support for a 'preserve' metadata tag to create unsliceable class and exception hiearchies (first rough cut)

Modified:
    ice/branches/slice-preserving-translators/cpp/src/Slice/Parser.cpp
    ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp
    ice/branches/slice-preserving-translators/cpp/src/slice2cs/Gen.cpp
    ice/branches/slice-preserving-translators/cpp/src/slice2java/Gen.cpp

Modified: ice/branches/slice-preserving-translators/cpp/src/Slice/Parser.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/src/Slice/Parser.cpp?view=diff&rev=585&r1=584&r2=585
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/src/Slice/Parser.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/src/Slice/Parser.cpp Fri Apr 23 17:51:51 2010
@@ -5755,3 +5755,39 @@
     return e2->isBaseOf(e1);
 }
 #endif
+
+//
+// Checks to see if the metadata string appears somewhere in the hierarchy.
+//
+bool 
+::Slice::scanParentsMetaData(const ClassDefPtr& p, const std::string& tag, std::string& result)
+{
+    ClassList parents = p->allBases();
+    std::string value;
+    for(ClassList::const_iterator i = parents.begin(); i != parents.end(); ++i)
+    {
+	if((*i)->findMetaData(tag, value))
+	{
+	    result = value;
+	    return true;
+	}
+    }
+    return false;
+}
+
+bool 
+::Slice::scanParentsMetaData(const ExceptionPtr& p, const std::string& tag, std::string& result)
+{
+    ExceptionList parents = p->allBases();
+    std::string value;
+    for(ExceptionList::const_iterator i = parents.begin(); i != parents.end(); ++i)
+    {
+	if((*i)->findMetaData(tag, value))
+	{
+	    result = value;
+	    return true;
+	}
+    }
+    return false;
+}
+

Modified: ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp?view=diff&rev=585&r1=584&r2=585
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp Fri Apr 23 17:51:51 2010
@@ -25,6 +25,8 @@
 using namespace Slice;
 using namespace IceUtil;
 using namespace IceUtilInternal;
+
+const std::string preserveTag("preserve");
 
 static string
 getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2)
@@ -801,11 +803,25 @@
 
     string factoryName;
 
+    bool switchWrites = false;
+
     if(!p->isLocal())
     {
+	std::string dummy;
+	bool preserving = scanParentsMetaData(p, preserveTag, dummy);
+	if(!preserving)
+	{
+	    switchWrites = p->findMetaData(preserveTag, dummy);
+	    preserving = switchWrites;
+	}
+			    
         ExceptionPtr base = p->base();
 
         H << sp << nl << "virtual void __write(::IceInternal::BasicStream*) const;";
+	if(preserving) 
+	{
+	    H << sp << nl << "virtual void __writeImpl(::IceInternal::BasicStream*) const;";
+	}
         H << nl << "virtual void __read(::IceInternal::BasicStream*, bool);";
         
         H.zeroIndent();
@@ -813,13 +829,30 @@
         H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
         H.restoreIndent();
         H << nl << "virtual void __write(const ::Ice::OutputStreamPtr&) const;";
+		
         H << nl << "virtual void __read(const ::Ice::InputStreamPtr&, bool);";
         H.zeroIndent();
         H << nl << "#endif";
         H.restoreIndent();
+
+	if(switchWrites) {
+		H.zeroIndent();
+		H << nl << "protected:";
+		H.restoreIndent();
+		H << nl << "std::vector< ::Ice::Byte > __preserved;";
+	}
+	
+        C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const";
+        C << sb;
+	if(preserving) 
+	{
+	    C << nl << "__os->writeBlob(__preserved);";
+	    C << nl << "__writeImpl(__os);";
+	    C << eb;
+	    C << sp << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::IceInternal::BasicStream* __os) const";
+	    C << sb;
+	}
         
-        C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const";
-        C << sb;
         C << nl << "__os->write(::std::string(\"" << p->scoped() << "\"), false);";
         C << nl << "__os->startWriteSlice();";
         for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
@@ -828,13 +861,27 @@
         }
         C << nl << "__os->endWriteSlice();";
         if(base)
-        {
-            emitUpcall(base, "::__write(__os);");
-        }
+	{
+	    if(preserving && !switchWrites) 
+	    {
+		emitUpcall(base, "::__writeImpl(__os);");
+	    } 
+	    else 
+	    {			
+		emitUpcall(base, "::__write(__os);");
+	    }
+	}
         C << eb;
 
         C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is, bool __rid)";
         C << sb;
+	if(preserving) 
+	{
+	    C << nl << "if(__preserved.empty())";
+	    C << sb;
+	    C << nl << "__is->readSkippedSlicesBlob(__preserved);";
+	    C << eb;
+	}
         C << nl << "if(__rid)";
         C << sb;
         C << nl << "::std::string myId;";
@@ -3704,6 +3751,14 @@
     DataMemberList dataMembers = p->dataMembers();
     DataMemberList allDataMembers = p->allDataMembers();
 
+    std::string dummy;
+    bool preserving = scanParentsMetaData(p, preserveTag, dummy);
+    bool switchWrites = false;
+    if(!preserving)
+    {
+	switchWrites = p->findMetaData(preserveTag, dummy);
+	preserving = switchWrites;
+    }
 
     H << sp << nl << "class " << _dllExport << name << " : ";
     H.useCurrentPosAsIndent();
@@ -4032,8 +4087,18 @@
     string scoped = fixKwd(p->scoped());
     string scope = fixKwd(p->scope());
 
+    bool switchWrites = false;
+
     if(!p->isLocal())
     {
+	std::string dummy;
+	bool preserving = scanParentsMetaData(p, "preserve", dummy);
+	if(!preserving)
+	{
+	    switchWrites = p->findMetaData("preserve", dummy);
+	    preserving = switchWrites;
+	}
+
         ClassList bases = p->bases();
         ClassDefPtr base;
         if(!bases.empty() && !bases.front()->isInterface())
@@ -4180,6 +4245,10 @@
 
         H << sp;
         H << nl << "virtual void __write(::IceInternal::BasicStream*) const;";
+	if(preserving)
+	{
+	    H << nl << "virtual void __writeImpl(::IceInternal::BasicStream*) const;";
+	}
         H << nl << "virtual void __read(::IceInternal::BasicStream*, bool);";
       
         
@@ -4192,25 +4261,56 @@
         H.zeroIndent();
         H << nl << "#endif";
         H.restoreIndent();
-        
-        C << sp;
-        C << nl << "void" << nl << scoped.substr(2)
-          << "::__write(::IceInternal::BasicStream* __os) const";
-        C << sb;
-        C << nl << "__os->writeTypeId(ice_staticId());";
-        C << nl << "__os->startWriteSlice();";
-        DataMemberList dataMembers = p->dataMembers();
-        DataMemberList::const_iterator q;
-        for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
-        {
-            writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), true, "", true, (*q)->getMetaData());
-        }
-        C << nl << "__os->endWriteSlice();";
-        emitUpcall(base, "::__write(__os);");
-        C << eb;
+
+	DataMemberList dataMembers = p->dataMembers();
+	DataMemberList::const_iterator q;
+
+	C << sp;
+	C << nl << "void" << nl << scoped.substr(2)
+	  << "::__write(::IceInternal::BasicStream* __os) const";
+	C << sb;
+
+	if(preserving)
+	{
+	    C << nl << "__os->writeBlob(__preserved);";
+	    C << nl << "__writeImpl(__os);";
+	    C << eb;
+
+	    C << sp;
+	    C << nl << "void" << nl << scoped.substr(2)
+	      << "::__writeImpl(::IceInternal::BasicStream* __os) const";
+	    C << sb;
+	}
+
+	C << nl << "__os->writeTypeId(ice_staticId());";
+	C << nl << "__os->startWriteSlice();";
+	for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+	{
+	    writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), true, "", true, (*q)->getMetaData());
+	}
+	C << nl << "__os->endWriteSlice();";
+
+	if(preserving && !switchWrites)
+	{
+	    emitUpcall(base, "::__writeImpl(__os);");
+	}
+	else
+	{
+	    emitUpcall(base, "::__write(__os);");
+	}
+	C << eb;
+
         C << sp;
         C << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is, bool __rid)";
         C << sb;
+	if(preserving)
+	{
+	    C << nl << "if(__preserved.empty())";
+	    C << sb;
+	    C << nl << "__is->readSkippedSlicesBlob(__preserved);";
+	    C << eb;
+	}
+
         C << nl << "if(__rid)";
         C << sb;
         C << nl << "::std::string myId;";
@@ -4417,6 +4517,14 @@
         string name = fixKwd((*q)->name());
         string s = typeToString((*q)->type(), (*q)->getMetaData(), _useWstring);
         H << sp << nl << s << ' ' << name << ';';
+    }
+    if(switchWrites)
+    {
+	if(!inProtected)
+	{
+	    H << sp << "protected:";
+	}
+	H << sp << nl << "::std::vector< ::Ice::Byte > __preserved;";
     }
 
     H << eb << ';';

Modified: ice/branches/slice-preserving-translators/cpp/src/slice2cs/Gen.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/src/slice2cs/Gen.cpp?view=diff&rev=585&r1=584&r2=585
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/src/slice2cs/Gen.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/src/slice2cs/Gen.cpp Fri Apr 23 17:51:51 2010
@@ -43,6 +43,8 @@
 using IceUtilInternal::epar;
 using IceUtilInternal::trim;
 
+static const string preserveTag("preserve");
+
 static string // Should be an anonymous namespace, but VC++ 6 can't handle that.
 sliceModeToIceMode(Operation::Mode opMode)
 {
@@ -200,6 +202,15 @@
     other.sort();
     ids.merge(other);
     ids.unique();
+
+    string dummy;
+    bool preserving = scanParentsMetaData(p, preserveTag, dummy);
+    bool switchWrites = false;
+    if(!preserving)
+    {
+	switchWrites = p->findMetaData(preserveTag, dummy);
+	preserving = switchWrites;
+    }
 
     StringList::const_iterator firstIter = ids.begin();
     StringList::const_iterator scopedIter = find(ids.begin(), ids.end(), scoped);
@@ -680,8 +691,31 @@
 
     _out << sp << nl << "#region Marshaling support";
 
+    if(switchWrites)
+    {
+	_out << sp << nl << "protected byte[] preserved__ = null;";
+    }
+
     _out << sp << nl << "public override void write__(IceInternal.BasicStream os__)";
     _out << sb;
+    if(preserving)
+    {
+	_out << nl << "if(preserved__ != null)";
+	_out << sb;
+	_out << nl << "os__.writeBlob(preserved__);";
+	_out << eb;
+	_out << nl << "writeImpl__(os__);";
+	_out << eb;
+	if(switchWrites)
+	{
+	    _out << sp << nl << "public virtual void writeImpl__(IceInternal.BasicStream os__)";
+	}
+	else
+	{
+	    _out << sp << nl << "public override void writeImpl__(IceInternal.BasicStream os__)";
+	}
+	_out << sb;
+    }
     _out << nl << "os__.writeTypeId(ice_staticId());";
     _out << nl << "os__.startWriteSlice();";
     for(d = members.begin(); d != members.end(); ++d)
@@ -690,7 +724,14 @@
                                   true, false, false);
     }
     _out << nl << "os__.endWriteSlice();";
-    _out << nl << "base.write__(os__);";
+    if(preserving && !switchWrites)
+    {
+	_out << nl << "base.writeImpl__(os__);";
+    }
+    else
+    {
+	_out << nl << "base.write__(os__);";
+    }
     _out << eb;
 
     if(allClassMembers.size() != 0)
@@ -768,6 +809,13 @@
 
     _out << sp << nl << "public override void read__(IceInternal.BasicStream is__, bool rid__)";
     _out << sb;
+    if(preserving)
+    {
+	_out << nl << "if(preserved__ == null)";
+	_out << sb;
+	_out << nl << "preserved__ = is__.getSkippedSlices();";
+	_out << eb;
+    }
     _out << nl << "if(rid__)";
     _out << sb;
     _out << nl << "/* string myId = */ is__.readTypeId();";
@@ -2703,12 +2751,43 @@
     {
         _out << sp << nl << "#region Marshaling support";
 
+	string dummy;
+	bool preserving = scanParentsMetaData(p, preserveTag, dummy);
+	bool switchWrites = false;
+	if(!preserving)
+	{
+	    switchWrites = p->findMetaData(preserveTag, dummy);
+	    preserving = switchWrites;
+	}
+
+	if(switchWrites)
+	{
+	    _out << sp << nl << "protected byte[] preserved__ = null;";
+	}
+
         string scoped = p->scoped();
         ExceptionPtr base = p->base();
 
-
         _out << sp << nl << "public override void write__(IceInternal.BasicStream os__)";
         _out << sb;
+	if(preserving)
+	{
+	    _out << nl << "if(preserved__ != null)";
+	    _out << sb;
+	    _out << nl << "os__.writeBlob(preserved__);";
+	    _out << eb;
+	    _out << nl << "writeImpl__(os__);";
+	    _out << eb;
+	    if(switchWrites)
+	    {
+		_out << sp << nl << "public virtual void writeImpl__(IceInternal.BasicStream os__)";
+	    }
+	    else
+	    {
+		_out << sp << nl << "public override void writeImpl__(IceInternal.BasicStream os__)";
+	    }
+	    _out << sb;
+	}
         _out << nl << "os__.writeString(\"" << scoped << "\");";
         _out << nl << "os__.startWriteSlice();";
         for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
@@ -2719,7 +2798,14 @@
         _out << nl << "os__.endWriteSlice();";
         if(base)
         {
-            _out << nl << "base.write__(os__);";
+	    if(preserving && !switchWrites)
+	    {
+		_out << nl << "base.writeImpl__(os__);";
+	    }
+	    else
+	    {
+		_out << nl << "base.write__(os__);";
+	    }
         }
         _out << eb;
 
@@ -2799,6 +2885,14 @@
 
         _out << sp << nl << "public override void read__(IceInternal.BasicStream is__, bool rid__)";
         _out << sb;
+	if(preserving)
+	{
+	    _out << nl << "if(preserved__ == null)";
+	    _out << sb;
+	    _out << nl << "preserved__ = is__.getSkippedSlices();";
+	    _out << eb;
+	}
+
         _out << nl << "if(rid__)";
         _out << sb;
         _out << nl << "/* string myId = */ is__.readString();";

Modified: ice/branches/slice-preserving-translators/cpp/src/slice2java/Gen.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/src/slice2java/Gen.cpp?view=diff&rev=585&r1=584&r2=585
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/src/slice2java/Gen.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/src/slice2java/Gen.cpp Fri Apr 23 17:51:51 2010
@@ -33,6 +33,8 @@
 using IceUtilInternal::eb;
 using IceUtilInternal::spar;
 using IceUtilInternal::epar;
+
+static const string preserveTag("preserve");
 
 static string
 sliceModeToIceMode(Operation::Mode opMode)
@@ -417,9 +419,17 @@
     assert(scopedIter != ids.end());
     StringList::difference_type scopedPos = IceUtilInternal::distance(firstIter, scopedIter);
 
+    std::string dummy;
+    bool preserving = scanParentsMetaData(p, preserveTag, dummy);
+    bool switchWrites = false;
+    if(!preserving)
+    {
+	switchWrites = p->findMetaData(preserveTag, dummy);
+	preserving = switchWrites;
+    }
+
     out << sp << nl << "public static final String[] __ids =";
     out << sb;
-
     {
         StringList::const_iterator q = ids.begin();
         while(q != ids.end())
@@ -1036,9 +1046,24 @@
     int iter;
     DataMemberList members = p->dataMembers();
     DataMemberList::const_iterator d;
+    if(switchWrites)
+    {
+	out << sp << nl << "protected byte[] __preserved = null;";
+    }
 
     out << sp << nl << "public void" << nl << "__write(IceInternal.BasicStream __os)";
     out << sb;
+    if(preserving)
+    {
+	out << nl << "if(__preserved != null)";
+	out << sb;
+	out << nl << "__os.writeBlob(__preserved);";
+	out << eb;
+	out << nl << "__writeImpl(__os);";
+	out << eb;
+	out << sp << nl << "public void" << nl << "__writeImpl(IceInternal.BasicStream __os)";
+	out << sb;
+    }
     out << nl << "__os.writeTypeId(ice_staticId());";
     out << nl << "__os.startWriteSlice();";
     iter = 0;
@@ -1048,7 +1073,14 @@
         writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), true, iter, false, metaData);
     }
     out << nl << "__os.endWriteSlice();";
-    out << nl << "super.__write(__os);";
+    if(preserving && !switchWrites)
+    {
+	out << nl << "super.__writeImpl(__os);";
+    }
+    else 
+    {
+	out << nl << "super.__write(__os);";
+    }
     out << eb;
 
     DataMemberList allClassMembers = p->allClassDataMembers();
@@ -1140,6 +1172,13 @@
 
     out << sp << nl << "public void" << nl << "__read(IceInternal.BasicStream __is, boolean __rid)";
     out << sb;
+    if(preserving)
+    {
+	out << nl << "if(__preserved == null)";
+	out << sb;
+	out << nl << "__preserved = __is.getSkippedSlices();";
+	out << eb;
+    }
     out << nl << "if(__rid)";
     out << sb;
     out << nl << "__is.readTypeId();";
@@ -2653,6 +2692,15 @@
 
     if(!p->isLocal())
     {
+	std::string dummy;
+	bool preserving = scanParentsMetaData(p, preserveTag, dummy);
+	bool switchWrites = false;
+	if(!preserving)
+	{
+	    switchWrites = p->findMetaData(preserveTag, dummy);
+	    preserving = switchWrites;
+	}
+
         string name = fixKwd(p->name());
         string scoped = p->scoped();
         string package = getPackage(p);
@@ -2662,8 +2710,27 @@
         DataMemberList::const_iterator d;
         int iter;
 
+	if(switchWrites)
+	{
+	    out << sp << nl << "protected byte[] __preserved = null;";
+	}
+
         out << sp << nl << "public void" << nl << "__write(IceInternal.BasicStream __os)";
         out << sb;
+	if(preserving)
+	{
+	    out << nl << "System.err.println(\"modded write called\");";
+	    out << nl << "System.err.flush();";
+	    out << nl << "if(__preserved != null)";
+	    out << sb;
+	    out << nl << "__os.writeBlob(__preserved);";
+	    out << eb;
+	    out << nl << "__writeImpl(__os);";
+	    out << eb;
+
+	    out << sp << nl << "public void" << nl << "__writeImpl(IceInternal.BasicStream __os)";
+	    out << sb;
+	}
         out << nl << "__os.writeString(\"" << scoped << "\");";
         out << nl << "__os.startWriteSlice();";
         iter = 0;
@@ -2675,7 +2742,14 @@
         out << nl << "__os.endWriteSlice();";
         if(base)
         {
-            out << nl << "super.__write(__os);";
+	    if(preserving && !switchWrites)
+	    {
+		out << nl << "super.__writeImpl(__os);";
+	    }
+	    else
+	    {
+		out << nl << "super.__write(__os);";
+	    }
         }
         out << eb;
 
@@ -2767,6 +2841,15 @@
         }
         out << sp << nl << "public void" << nl << "__read(IceInternal.BasicStream __is, boolean __rid)";
         out << sb;
+	if(preserving)
+	{
+	    out << nl << "if(__preserved == null)";
+	    out << sb;
+	    out << nl << "System.err.println(\"modded read called\");";
+	    out << nl << "System.err.flush();";
+	    out << nl << "__preserved = __is.getSkippedSlices();";
+	    out << eb;
+	}
         out << nl << "if(__rid)";
         out << sb;
         out << nl << "__is.readString();";





More information about the asterisk-scf-commits mailing list