[asterisk-scf-commits] asterisk-scf/integration/ice.git branch "slice2java-classes" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Feb 18 12:43:03 CST 2011


branch "slice2java-classes" has been created
        at  c4fdc88e262c8e6d3bb47434b8e6e213cbf5a2af (commit)

- Log -----------------------------------------------------------------
commit c4fdc88e262c8e6d3bb47434b8e6e213cbf5a2af
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Wed Jun 16 17:56:59 2010 -0500

    import slice2java-classes code

diff --git a/cpp/include/Slice/FileTracker.h b/cpp/include/Slice/FileTracker.h
index 0110f5b..b7cd691 100644
--- a/cpp/include/Slice/FileTracker.h
+++ b/cpp/include/Slice/FileTracker.h
@@ -54,6 +54,7 @@ public:
 
     void cleanup();
     void dumpxml();
+    void dumpfiles();
 
 private:
 
diff --git a/cpp/include/Slice/JavaUtil.h b/cpp/include/Slice/JavaUtil.h
index c1fdd50..246b462 100644
--- a/cpp/include/Slice/JavaUtil.h
+++ b/cpp/include/Slice/JavaUtil.h
@@ -36,7 +36,7 @@ public:
     // printHeader() and then emits a "package" statement if
     // necessary.
     //
-    void openClass(const std::string&, const std::string& = std::string());
+    virtual void openClass(const std::string&, const std::string& = std::string());
 
     virtual void printHeader();
 };
diff --git a/cpp/src/Slice/FileTracker.cpp b/cpp/src/Slice/FileTracker.cpp
index 9f79cac..ac4c282 100644
--- a/cpp/src/Slice/FileTracker.cpp
+++ b/cpp/src/Slice/FileTracker.cpp
@@ -178,6 +178,22 @@ Slice::FileTracker::dumpxml()
     cout << "</generated>" << endl;
 }
 
+void
+Slice::FileTracker::dumpfiles()
+{
+    for(map<string, string>::const_iterator p = _errors.begin(); p != _errors.end(); ++p)
+    {
+        map<string, list<string> >::const_iterator q = _generated.find(p->first);
+        if(q != _generated.end())
+	{
+            for(list<string>::const_iterator r = q->second.begin(); r != q->second.end(); ++r)
+            {
+                cout << *r << endl;
+            }
+	}
+    }
+}
+
 string
 Slice::FileTracker::escape(const string& str) const
 {
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 2564f7e..95ff36b 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -11,12 +11,90 @@
 #include <Gen.h>
 #include <Slice/Checksum.h>
 #include <Slice/Util.h>
+#include <Slice/FileTracker.h>
 #include <IceUtil/Functional.h>
 #include <IceUtil/Iterator.h>
 #include <IceUtil/StringUtil.h>
 #include <cstring>
 
 #include <limits>
+//
+// This class was added to support generating a listing of the files that would be
+// generated without actually generating them.
+//
+class NullJavaOutput : public Slice::JavaOutput
+{
+public:
+    NullJavaOutput() 
+    {
+    }
+
+    NullJavaOutput(std::ostream& os) :
+	Slice::JavaOutput(os)
+    {
+    }
+
+    NullJavaOutput(const char* s) :
+	Slice::JavaOutput(s)
+    {
+    }
+
+    void openClass(const std::string& cls, const std::string& prefix)
+    {
+	std::string package;
+	std::string file;
+	std::string path = prefix;
+
+	std::string::size_type pos = cls.rfind('.');
+	if(pos != std::string::npos)
+	{
+	    package = cls.substr(0, pos);
+	    file = cls.substr(pos + 1);
+	    std::string dir = package;
+
+	    //
+	    // Create package directories if necessary.
+	    //
+	    pos = 0;
+	    std::string::size_type start = 0;
+	    do
+	    {
+		if(!path.empty())
+		{
+		    path += "/";
+		}
+		pos = dir.find('.', start);
+		if(pos != std::string::npos)
+		{
+		    path += dir.substr(start, pos - start);
+		    start = pos + 1;
+		}
+		else
+		{
+		    path += dir.substr(start);
+		}
+		Slice::FileTracker::instance()->addDirectory(path);
+	    }
+	    while(pos != std::string::npos);
+	}
+	else
+	{
+	    file = cls;
+	}
+	file += ".java";
+
+	//
+	// Open class file.
+	//
+	if(!path.empty())
+	{
+	    path += "/";
+	}
+	path += file;
+
+	Slice::FileTracker::instance()->addFile(path);
+    }
+};
 
 using namespace std;
 using namespace Slice;
@@ -80,8 +158,9 @@ getDeprecateReason(const ContainedPtr& p1, const ContainedPtr& p2, const string&
     return deprecateReason;
 }
 
-Slice::JavaVisitor::JavaVisitor(const string& dir) :
-    JavaGenerator(dir)
+Slice::JavaVisitor::JavaVisitor(const string& dir, bool listOnly) :
+    JavaGenerator(dir),
+    _listOnly(listOnly)
 {
 }
 
@@ -1355,6 +1434,17 @@ Slice::JavaVisitor::writeDataMemberInitializers(Output& out, const DataMemberLis
     }
 }
 
+Slice::JavaOutput*
+Slice::JavaVisitor::createOutput()
+{
+    if(_listOnly) 
+    {
+	return new NullJavaOutput(_os);
+    }
+
+    return JavaGenerator::createOutput();
+}
+
 StringList
 Slice::JavaVisitor::splitComment(const ContainedPtr& p)
 {
@@ -1721,10 +1811,11 @@ Slice::JavaVisitor::writeDocCommentParam(Output& out, const OperationPtr& p, Par
     }
 }
 
-Slice::Gen::Gen(const string& name, const string& base, const vector<string>& includePaths, const string& dir) :
+Slice::Gen::Gen(const string& name, const string& base, const vector<string>& includePaths, const string& dir, bool listOnly) :
     _base(base),
     _includePaths(includePaths),
-    _dir(dir)
+    _dir(dir),
+    _listOnly(listOnly)
 {
 }
 
@@ -1737,58 +1828,58 @@ Slice::Gen::generate(const UnitPtr& p, bool stream)
 {
     JavaGenerator::validateMetaData(p);
 
-    OpsVisitor opsVisitor(_dir);
+    OpsVisitor opsVisitor(_dir, _listOnly);
     p->visit(&opsVisitor, false);
 
-    PackageVisitor packageVisitor(_dir);
+    PackageVisitor packageVisitor(_dir, _listOnly);
     p->visit(&packageVisitor, false);
 
-    TypesVisitor typesVisitor(_dir, stream);
+    TypesVisitor typesVisitor(_dir, _listOnly, stream);
     p->visit(&typesVisitor, false);
 
-    HolderVisitor holderVisitor(_dir, stream);
+    HolderVisitor holderVisitor(_dir, _listOnly, stream);
     p->visit(&holderVisitor, false);
 
-    HelperVisitor helperVisitor(_dir, stream);
+    HelperVisitor helperVisitor(_dir, _listOnly, stream);
     p->visit(&helperVisitor, false);
 
-    ProxyVisitor proxyVisitor(_dir);
+    ProxyVisitor proxyVisitor(_dir, _listOnly);
     p->visit(&proxyVisitor, false);
 
-    DelegateVisitor delegateVisitor(_dir);
+    DelegateVisitor delegateVisitor(_dir, _listOnly);
     p->visit(&delegateVisitor, false);
 
-    DelegateMVisitor delegateMVisitor(_dir);
+    DelegateMVisitor delegateMVisitor(_dir, _listOnly);
     p->visit(&delegateMVisitor, false);
 
-    DelegateDVisitor delegateDVisitor(_dir);
+    DelegateDVisitor delegateDVisitor(_dir, _listOnly);
     p->visit(&delegateDVisitor, false);
 
-    DispatcherVisitor dispatcherVisitor(_dir, stream);
+    DispatcherVisitor dispatcherVisitor(_dir, _listOnly, stream);
     p->visit(&dispatcherVisitor, false);
 
-    AsyncVisitor asyncVisitor(_dir);
+    AsyncVisitor asyncVisitor(_dir, _listOnly);
     p->visit(&asyncVisitor, false);
 }
 
 void
 Slice::Gen::generateTie(const UnitPtr& p)
 {
-    TieVisitor tieVisitor(_dir);
+    TieVisitor tieVisitor(_dir, _listOnly);
     p->visit(&tieVisitor, false);
 }
 
 void
 Slice::Gen::generateImpl(const UnitPtr& p)
 {
-    ImplVisitor implVisitor(_dir);
+    ImplVisitor implVisitor(_dir, _listOnly);
     p->visit(&implVisitor, false);
 }
 
 void
 Slice::Gen::generateImplTie(const UnitPtr& p)
 {
-    ImplTieVisitor implTieVisitor(_dir);
+    ImplTieVisitor implTieVisitor(_dir, _listOnly);
     p->visit(&implTieVisitor, false);
 }
 
@@ -1847,8 +1938,8 @@ Slice::Gen::writeChecksumClass(const string& checksumClass, const string& dir, c
     out << nl;
 }
 
-Slice::Gen::OpsVisitor::OpsVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::OpsVisitor::OpsVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
@@ -1989,8 +2080,8 @@ Slice::Gen::OpsVisitor::writeOperations(const ClassDefPtr& p, bool noCurrent)
     close();
 }
 
-Slice::Gen::TieVisitor::TieVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::TieVisitor::TieVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
@@ -2187,8 +2278,8 @@ Slice::Gen::TieVisitor::visitClassDefStart(const ClassDefPtr& p)
     return false;
 }
 
-Slice::Gen::PackageVisitor::PackageVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::PackageVisitor::PackageVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
@@ -2212,8 +2303,8 @@ Slice::Gen::PackageVisitor::visitModuleStart(const ModulePtr& p)
     return false;
 }
 
-Slice::Gen::TypesVisitor::TypesVisitor(const string& dir, bool stream) :
-    JavaVisitor(dir), _stream(stream)
+Slice::Gen::TypesVisitor::TypesVisitor(const string& dir, bool listOnly, bool stream) :
+    JavaVisitor(dir, listOnly), _stream(stream)
 {
 }
 
@@ -3565,8 +3656,8 @@ Slice::Gen::TypesVisitor::validateGetterSetter(const OperationList& ops, const s
     return true;
 }
 
-Slice::Gen::HolderVisitor::HolderVisitor(const string& dir, bool stream) :
-    JavaVisitor(dir), _stream(stream)
+Slice::Gen::HolderVisitor::HolderVisitor(const string& dir, bool listOnly, bool stream) :
+    JavaVisitor(dir, listOnly), _stream(stream)
 {
 }
 
@@ -3718,8 +3809,8 @@ Slice::Gen::HolderVisitor::writeHolder(const TypePtr& p)
     close();
 }
 
-Slice::Gen::HelperVisitor::HelperVisitor(const string& dir, bool stream) :
-    JavaVisitor(dir), _stream(stream)
+Slice::Gen::HelperVisitor::HelperVisitor(const string& dir, bool listOnly, bool stream) :
+    JavaVisitor(dir, listOnly), _stream(stream)
 {
 }
 
@@ -4610,8 +4701,8 @@ Slice::Gen::HelperVisitor::visitEnum(const EnumPtr& p)
     }
 }
 
-Slice::Gen::ProxyVisitor::ProxyVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::ProxyVisitor::ProxyVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
@@ -4788,8 +4879,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
     }
 }
 
-Slice::Gen::DelegateVisitor::DelegateVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::DelegateVisitor::DelegateVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
@@ -4862,8 +4953,8 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p)
     return false;
 }
 
-Slice::Gen::DelegateMVisitor::DelegateMVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::DelegateMVisitor::DelegateMVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
@@ -5061,8 +5152,8 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p)
     return false;
 }
 
-Slice::Gen::DelegateDVisitor::DelegateDVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::DelegateDVisitor::DelegateDVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
@@ -5246,8 +5337,8 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p)
     return false;
 }
 
-Slice::Gen::DispatcherVisitor::DispatcherVisitor(const string& dir, bool stream) :
-    JavaVisitor(dir), _stream(stream)
+Slice::Gen::DispatcherVisitor::DispatcherVisitor(const string& dir, bool listOnly, bool stream) :
+    JavaVisitor(dir, listOnly), _stream(stream)
 {
 }
 
@@ -5288,8 +5379,8 @@ Slice::Gen::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p)
     return false;
 }
 
-Slice::Gen::BaseImplVisitor::BaseImplVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::BaseImplVisitor::BaseImplVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
@@ -5542,8 +5633,8 @@ Slice::Gen::BaseImplVisitor::writeOperation(Output& out, const string& package,
     }
 }
 
-Slice::Gen::ImplVisitor::ImplVisitor(const string& dir) :
-    BaseImplVisitor(dir)
+Slice::Gen::ImplVisitor::ImplVisitor(const string& dir, bool listOnly) :
+    BaseImplVisitor(dir, listOnly)
 {
 }
 
@@ -5600,8 +5691,8 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p)
     return false;
 }
 
-Slice::Gen::ImplTieVisitor::ImplTieVisitor(const string& dir) :
-    BaseImplVisitor(dir)
+Slice::Gen::ImplTieVisitor::ImplTieVisitor(const string& dir, bool listOnly) :
+    BaseImplVisitor(dir, listOnly)
 {
 }
 
@@ -5690,8 +5781,8 @@ Slice::Gen::ImplTieVisitor::visitClassDefStart(const ClassDefPtr& p)
     return false;
 }
 
-Slice::Gen::AsyncVisitor::AsyncVisitor(const string& dir) :
-    JavaVisitor(dir)
+Slice::Gen::AsyncVisitor::AsyncVisitor(const string& dir, bool listOnly) :
+    JavaVisitor(dir, listOnly)
 {
 }
 
diff --git a/cpp/src/slice2java/Gen.h b/cpp/src/slice2java/Gen.h
index 5e3f828..fea37cc 100644
--- a/cpp/src/slice2java/Gen.h
+++ b/cpp/src/slice2java/Gen.h
@@ -25,7 +25,7 @@ public:
 
 protected:
 
-    JavaVisitor(const std::string&);
+    JavaVisitor(const std::string&, bool listOnly);
 
     enum ParamDir { InParam, OutParam };
 
@@ -77,6 +77,8 @@ protected:
     //
     void writeDataMemberInitializers(::IceUtilInternal::Output&, const DataMemberList&, const std::string&);
 
+    JavaOutput* createOutput();
+
     //
     // Write doc comments.
     //
@@ -90,6 +92,10 @@ protected:
     static void writeDocCommentAMI(::IceUtilInternal::Output&, const OperationPtr&, ParamDir, const std::string& = "",
                                    const std::string& = "", const std::string& = "");
     static void writeDocCommentParam(::IceUtilInternal::Output&, const OperationPtr&, ParamDir, bool = true);
+
+private:
+    bool _listOnly;
+    std::ostringstream _os;
 };
 
 class Gen : private ::IceUtil::noncopyable
@@ -99,7 +105,8 @@ public:
     Gen(const std::string&,
         const std::string&,
         const std::vector<std::string>&,
-        const std::string&);
+        const std::string&,
+	bool listOnly);
     ~Gen();
 
     void generate(const UnitPtr&, bool);
@@ -114,12 +121,13 @@ private:
     std::string _base;
     std::vector<std::string> _includePaths;
     std::string _dir;
+    bool _listOnly;
 
     class OpsVisitor : public JavaVisitor
     {
     public:
 
-        OpsVisitor(const std::string&);
+        OpsVisitor(const std::string&, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
 
@@ -131,7 +139,7 @@ private:
     {
     public:
 
-        TieVisitor(const std::string&);
+        TieVisitor(const std::string&, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
     };
@@ -140,7 +148,7 @@ private:
     {
     public:
 
-        PackageVisitor(const std::string&);
+        PackageVisitor(const std::string&, bool);
 
         virtual bool visitModuleStart(const ModulePtr&);
     };
@@ -149,7 +157,7 @@ private:
     {
     public:
 
-        TypesVisitor(const std::string&, bool);
+        TypesVisitor(const std::string&, bool, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
         virtual void visitClassDefEnd(const ClassDefPtr&);
@@ -176,7 +184,7 @@ private:
     {
     public:
 
-        HolderVisitor(const std::string&, bool);
+        HolderVisitor(const std::string&, bool, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
         virtual bool visitStructStart(const StructPtr&);
@@ -195,7 +203,7 @@ private:
     {
     public:
 
-        HelperVisitor(const std::string&, bool);
+        HelperVisitor(const std::string&, bool, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
         virtual bool visitStructStart(const StructPtr&);
@@ -212,7 +220,7 @@ private:
     {
     public:
 
-        ProxyVisitor(const std::string&);
+        ProxyVisitor(const std::string&, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
         virtual void visitClassDefEnd(const ClassDefPtr&);
@@ -223,7 +231,7 @@ private:
     {
     public:
 
-        DelegateVisitor(const std::string&);
+        DelegateVisitor(const std::string&, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
     };
@@ -232,7 +240,7 @@ private:
     {
     public:
 
-        DelegateMVisitor(const std::string&);
+        DelegateMVisitor(const std::string&, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
     };
@@ -241,7 +249,7 @@ private:
     {
     public:
 
-        DelegateDVisitor(const std::string&);
+        DelegateDVisitor(const std::string&, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
     };
@@ -250,7 +258,7 @@ private:
     {
     public:
 
-        DispatcherVisitor(const std::string&, bool);
+        DispatcherVisitor(const std::string&, bool, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
 
@@ -263,7 +271,7 @@ private:
     {
     public:
 
-        BaseImplVisitor(const std::string&);
+        BaseImplVisitor(const std::string&, bool);
 
     protected:
 
@@ -288,7 +296,7 @@ private:
     {
     public:
 
-        ImplVisitor(const std::string&);
+        ImplVisitor(const std::string&, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
     };
@@ -297,7 +305,7 @@ private:
     {
     public:
 
-        ImplTieVisitor(const std::string&);
+        ImplTieVisitor(const std::string&, bool);
 
         virtual bool visitClassDefStart(const ClassDefPtr&);
     };
@@ -306,7 +314,7 @@ private:
     {
     public:
 
-        AsyncVisitor(const std::string&);
+        AsyncVisitor(const std::string&, bool);
 
         virtual void visitOperation(const OperationPtr&);
 
diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp
index 90978cf..d866405 100644
--- a/cpp/src/slice2java/Main.cpp
+++ b/cpp/src/slice2java/Main.cpp
@@ -80,6 +80,7 @@ usage(const char* n)
         "--checksum CLASS        Generate checksums for Slice definitions into CLASS.\n"
         "--stream                Generate marshaling support for public stream API.\n"
         "--meta META             Define global metadata directive META.\n"
+	"--classfiles            Generate a listing of the files that would be created, but do not generate them.\n"
         ;
 }
 
@@ -106,6 +107,7 @@ compile(int argc, char* argv[])
     opts.addOpt("", "checksum", IceUtilInternal::Options::NeedArg);
     opts.addOpt("", "stream");
     opts.addOpt("", "meta", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
+    opts.addOpt("", "classfiles");
 
     vector<string>args;
     try
@@ -176,6 +178,8 @@ compile(int argc, char* argv[])
 
     bool listGenerated = opts.isSet("list-generated");
 
+    bool listFiles = opts.isSet("classfiles");
+
     StringList globalMetadata;
     vector<string> v = opts.argVec("meta");
     copy(v.begin(), v.end(), back_inserter(globalMetadata));
@@ -194,6 +198,13 @@ compile(int argc, char* argv[])
         return EXIT_FAILURE;
     }
 
+    if(!checksumClass.empty() && listFiles)
+    {
+        getErrorStream() << argv[0] << ": error: cannot specify both --checksum and --list-files" << endl;
+        usage(argv[0]);
+        return EXIT_FAILURE;
+    }
+
     int status = EXIT_SUCCESS;
 
     ChecksumMap checksums;
@@ -308,7 +319,7 @@ compile(int argc, char* argv[])
                 {
                     try
                     {
-                        Gen gen(argv[0], icecpp->getBaseName(), includePaths, output);
+                        Gen gen(argv[0], icecpp->getBaseName(), includePaths, output, listFiles);
                         gen.generate(p, stream);
                         if(tie)
                         {
@@ -330,7 +341,7 @@ compile(int argc, char* argv[])
                             ChecksumMap m = createChecksums(p);
                             copy(m.begin(), m.end(), inserter(checksums, checksums.begin()));
                         }
-                        if(listGenerated)
+                        if(listGenerated || listFiles)
                         {
                             FileTracker::instance()->setOutput(os.str(), false);
                         }
@@ -395,6 +406,11 @@ compile(int argc, char* argv[])
         FileTracker::instance()->dumpxml();
     }
 
+    if(listFiles)
+    {
+        FileTracker::instance()->dumpfiles();
+    }
+
     return status;
 }
 

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/ice.git



More information about the asterisk-scf-commits mailing list