[asterisk-scf-commits] asterisk-scf/release/ice.git branch "visitor-generators" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Jan 5 23:57:38 UTC 2011


branch "visitor-generators" has been updated
       via  1ea3dfd4c70be652c1a6931c6c43ca28fa49c27d (commit)
      from  b06b126594eb9cb371e7e5e3813561fdb678c1f3 (commit)

Summary of changes:
 cpp/include/Slice/Parser.h |   16 ++++
 cpp/include/Slice/Plugin.h |    8 +--
 cpp/src/slice2cpp/Gen.cpp  |  163 ++++++++++++++++++++++++++++++++++++++++++--
 cpp/src/slice2java/Gen.cpp |   38 ++++++++--
 4 files changed, 205 insertions(+), 20 deletions(-)


- Log -----------------------------------------------------------------
commit 1ea3dfd4c70be652c1a6931c6c43ca28fa49c27d
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Wed Jan 5 17:56:11 2011 -0600

    Simplify plugin interface slightly by removing PluginVisitorPtr; it
    wasn't providing much value and complicated the inheritance chain.
    
    Add ParserVisitor::LanguageHelper, an interface that provides operations
    that plugins can use to transform raw Slice identifier names into
    language-mapped names.
    
    Add LanguageHelper to slice2cpp (complete) and slice2java (incomplete).

diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h
index 3f39d7b..afb34a8 100644
--- a/cpp/include/Slice/Parser.h
+++ b/cpp/include/Slice/Parser.h
@@ -189,6 +189,15 @@ class SLICE_API ParserVisitor
 {
 public:
 
+    class LanguageHelper
+    {
+    public:
+        virtual std::string typeToString(const TypePtr&, const StringList&) = 0;
+        virtual std::string returnTypeToString(const TypePtr&, const StringList&) = 0;
+        virtual std::string inputTypeToString(const TypePtr&, const StringList&) = 0;
+        virtual std::string outputTypeToString(const TypePtr&, const StringList&) = 0;
+    };
+
     virtual ~ParserVisitor() { }
     virtual bool visitUnitStart(const UnitPtr&) { return true; }
     virtual void visitUnitEnd(const UnitPtr&) { }
@@ -209,6 +218,13 @@ public:
     virtual void visitDictionary(const DictionaryPtr&) { }
     virtual void visitEnum(const EnumPtr&) { }
     virtual void visitConst(const ConstPtr&) { }
+
+protected:
+
+    LanguageHelper* _languageHelper;
+
+    ParserVisitor() : _languageHelper(0) { }
+    ParserVisitor(LanguageHelper* helper) : _languageHelper(helper) { }
 };
 
 // ----------------------------------------------------------------------
diff --git a/cpp/include/Slice/Plugin.h b/cpp/include/Slice/Plugin.h
index 4bab754..22c8eb3 100644
--- a/cpp/include/Slice/Plugin.h
+++ b/cpp/include/Slice/Plugin.h
@@ -19,13 +19,9 @@ namespace Plugin
         LanguagePHP
     };
 
-    class SLICE_API PluginVisitor : virtual public ParserVisitor, virtual public ::IceUtil::SimpleShared
-    {
-    };
-
-    typedef IceUtil::Handle<PluginVisitor> PluginVisitorPtr;
+    typedef std::list<ParserVisitor *> VisitorList;
 
-    typedef std::list<PluginVisitorPtr> PluginVisitorList;
+    typedef VisitorList* (*FACTORY)(Plugin::Language, ParserVisitor::LanguageHelper*);
 
 }
 
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 4361215..8c17f76 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -170,13 +170,160 @@ Slice::Gen::~Gen()
     }
 }
 
-typedef Plugin::PluginVisitorList* (*PLUGIN_FACTORY)(Plugin::Language);
-
 void
 Slice::Gen::generate(const UnitPtr& p)
 {
     string file = p->topLevelFile();
     
+    class CPPHelper : virtual public ParserVisitor, virtual public ParserVisitor::LanguageHelper
+    {
+    public:
+        virtual bool visitUnitStart(const UnitPtr& in)
+        {
+            return _visitor->visitUnitStart(in);
+        }
+
+        virtual void visitUnitEnd(const UnitPtr& in)
+        {
+            _visitor->visitUnitEnd(in);
+        }
+
+        virtual bool visitModuleStart(const ModulePtr& in)
+        {
+            _useWstring = setUseWstring(in, _useWstringHist, _useWstring);
+            _needVisitEnd = _visitor->visitModuleStart(in);
+            return true;
+        }
+
+        virtual void visitModuleEnd(const ModulePtr& in)
+        {
+            if(_needVisitEnd)
+            {
+                _visitor->visitModuleEnd(in);
+            }
+            _useWstring = resetUseWstring(_useWstringHist);
+        }
+
+        virtual void visitClassDecl(const ClassDeclPtr& in)
+        {
+            _visitor->visitClassDecl(in);
+        }
+
+        virtual bool visitClassDefStart(const ClassDefPtr& in)
+        {
+            _useWstring = setUseWstring(in, _useWstringHist, _useWstring);
+            _needVisitEnd = _visitor->visitClassDefStart(in);
+            return true;
+        }
+
+        virtual void visitClassDefEnd(const ClassDefPtr& in)
+        {
+            if(_needVisitEnd)
+            {
+                _visitor->visitClassDefEnd(in);
+            }
+            _useWstring = resetUseWstring(_useWstringHist);
+        }
+
+        virtual bool visitExceptionStart(const ExceptionPtr& in)
+        {
+            _useWstring = setUseWstring(in, _useWstringHist, _useWstring);
+            _needVisitEnd = _visitor->visitExceptionStart(in);
+            return true;
+        }
+
+        virtual void visitExceptionEnd(const ExceptionPtr& in)
+        {
+            if(_needVisitEnd)
+            {
+                _visitor->visitExceptionEnd(in);
+            }
+            _useWstring = resetUseWstring(_useWstringHist);
+        }
+
+        virtual bool visitStructStart(const StructPtr& in)
+        {
+            _useWstring = setUseWstring(in, _useWstringHist, _useWstring);
+            _needVisitEnd = _visitor->visitStructStart(in);
+            return true;
+        }
+
+        virtual void visitStructEnd(const StructPtr& in)
+        {
+            if(_needVisitEnd)
+            {
+                _visitor->visitStructEnd(in);
+            }
+            _useWstring = resetUseWstring(_useWstringHist);
+        }
+
+        virtual void visitOperation(const OperationPtr& in)
+        {
+            _visitor->visitOperation(in);
+        }
+
+        virtual void visitGeneratedOperation(const GeneratedOperationPtr& in)
+        {
+            _visitor->visitGeneratedOperation(in);
+        }
+
+        virtual void visitParamDecl(const ParamDeclPtr& in)
+        {
+            _visitor->visitParamDecl(in);
+        }
+
+        virtual void visitDataMember(const DataMemberPtr& in)
+        {
+            _visitor->visitDataMember(in);
+        }
+
+        virtual void visitSequence(const SequencePtr& in)
+        {
+            _visitor->visitSequence(in);
+        }
+
+        virtual void visitDictionary(const DictionaryPtr& in)
+        {
+            _visitor->visitDictionary(in);
+        }
+
+        virtual void visitEnum(const EnumPtr& in)
+        {
+            _visitor->visitEnum(in);
+        }
+
+        virtual void visitConst(const ConstPtr& in)
+        {
+            _visitor->visitConst(in);
+        }
+
+        virtual string typeToString(const TypePtr& type, const StringList& metadata)
+        {
+            return Slice::typeToString(type, metadata, _useWstring);
+        }
+
+        virtual string returnTypeToString(const TypePtr& type, const StringList& metadata)
+        {
+            return Slice::returnTypeToString(type, metadata, _useWstring);
+        }
+
+        virtual string inputTypeToString(const TypePtr& type, const StringList& metadata)
+        {
+            return Slice::inputTypeToString(type, metadata, _useWstring);
+        }
+
+        virtual string outputTypeToString(const TypePtr& type, const StringList& metadata)
+        {
+            return Slice::outputTypeToString(type, metadata, _useWstring);
+        }
+
+        ParserVisitor* _visitor;
+    private:
+        int _useWstring;
+        list<int> _useWstringHist;
+        bool _needVisitEnd;
+    } pluginHelper;
+
     for(vector<string>::const_iterator plugin = _plugins.begin(); plugin != _plugins.end(); plugin++)
     {
         IceUtil::DynamicLibraryPtr library = new IceUtil::DynamicLibrary();
@@ -187,15 +334,17 @@ Slice::Gen::generate(const UnitPtr& p)
             cerr << "Unable to find " << *plugin << " = " << msg << endl;
         }
         
-        Plugin::PluginVisitorList* pluginVisitors;
-        PLUGIN_FACTORY factory = (PLUGIN_FACTORY)sym;
-        pluginVisitors = factory(Plugin::LanguageCXX);
+        Plugin::VisitorList* pluginVisitors;
+        Plugin::FACTORY factory = (Plugin::FACTORY) sym;
+        pluginVisitors = factory(Plugin::LanguageCXX, &pluginHelper);
         
         if(pluginVisitors)
         {
-            for(Plugin::PluginVisitorList::const_iterator it = pluginVisitors->begin(); it != pluginVisitors->end(); it++)
+            for(Plugin::VisitorList::const_iterator it = pluginVisitors->begin(); it != pluginVisitors->end(); it++)
             {
-                p->visit(it->get(), true);
+                pluginHelper._visitor = *it;
+                p->visit(&pluginHelper, true);
+                delete *it;
             }
             delete pluginVisitors;
         }
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index e59c185..e4c1bc0 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -1756,11 +1756,34 @@ Slice::Gen::~Gen()
 {
 }
 
-typedef Plugin::PluginVisitorList* (*PLUGIN_FACTORY)(Plugin::Language);
-
 void
 Slice::Gen::generate(const UnitPtr& p, bool stream)
 {
+    class JavaHelper : virtual public JavaVisitor, virtual public ParserVisitor::LanguageHelper
+    {
+    public:
+	JavaHelper(string dir) : JavaVisitor(dir) { }
+        virtual string typeToString(const TypePtr& type, const StringList& metadata)
+        {
+            return JavaGenerator::typeToString(type, JavaGenerator::TypeModeMember, "", metadata, false);
+        }
+
+        virtual string returnTypeToString(const TypePtr& type, const StringList& metadata)
+        {
+            return string();
+        }
+
+        virtual string inputTypeToString(const TypePtr& type, const StringList& metadata)
+        {
+            return string();
+        }
+
+        virtual string outputTypeToString(const TypePtr& type, const StringList& metadata)
+        {
+            return string();
+        }
+    } pluginHelper(_dir);
+
     for(vector<string>::const_iterator plugin = _plugins.begin(); plugin != _plugins.end(); plugin++)
     {
         IceUtil::DynamicLibraryPtr library = new IceUtil::DynamicLibrary();
@@ -1771,15 +1794,16 @@ Slice::Gen::generate(const UnitPtr& p, bool stream)
             cerr << "Unable to find " << *plugin << " = " << msg << endl;
         }
         
-        Plugin::PluginVisitorList* pluginVisitors;
-        PLUGIN_FACTORY factory = (PLUGIN_FACTORY)sym;
-        pluginVisitors = factory(Plugin::LanguageJava);
+        Plugin::VisitorList* pluginVisitors;
+        Plugin::FACTORY factory = (Plugin::FACTORY) sym;
+        pluginVisitors = factory(Plugin::LanguageJava, &pluginHelper);
         
         if(pluginVisitors)
         {
-            for(Plugin::PluginVisitorList::const_iterator it = pluginVisitors->begin(); it != pluginVisitors->end(); it++)
+            for(Plugin::VisitorList::const_iterator it = pluginVisitors->begin(); it != pluginVisitors->end(); it++)
             {
-                p->visit(it->get(), true);
+                p->visit(*it, true);
+                delete *it;
             }
             delete pluginVisitors;
         }

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


-- 
asterisk-scf/release/ice.git



More information about the asterisk-scf-commits mailing list