[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
Thu Jan 6 17:38:50 UTC 2011


branch "visitor-generators" has been updated
       via  01d7120ddeba5864f618b930ebe392b9122a4ad7 (commit)
      from  acb595531400e601176d5bcd1b0b4478beade2c7 (commit)

Summary of changes:
 cpp/include/Slice/CsUtil.h   |    3 +-
 cpp/include/Slice/JavaUtil.h |   60 ++++++++--------
 cpp/include/Slice/Parser.h   |   16 -----
 cpp/include/Slice/Plugin.h   |    6 +-
 cpp/src/Slice/JavaUtil.cpp   |   20 +++---
 cpp/src/slice2cpp/Gen.cpp    |  154 +-----------------------------------------
 cpp/src/slice2cs/Gen.cpp     |    2 +-
 cpp/src/slice2java/Gen.cpp   |   27 +-------
 8 files changed, 50 insertions(+), 238 deletions(-)


- Log -----------------------------------------------------------------
commit 01d7120ddeba5864f618b930ebe392b9122a4ad7
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Thu Jan 6 11:36:49 2011 -0600

    Make functions for converting Slice identifiers to mapped identifiers
    for Java and CSharp static, so they can be used from plugin modules.
    
    Remove LanguageHelper mechanism, as it was a much more complicated way
    to solve the problem that the change above solves.

diff --git a/cpp/include/Slice/CsUtil.h b/cpp/include/Slice/CsUtil.h
index eaa767d..2f3b729 100644
--- a/cpp/include/Slice/CsUtil.h
+++ b/cpp/include/Slice/CsUtil.h
@@ -32,10 +32,11 @@ public:
     //
     static void validateMetaData(const UnitPtr&);
 
+    static std::string typeToString(const TypePtr&);
+
 protected:
     static std::string fixId(const std::string&, int = 0, bool = false);
     static std::string fixId(const ContainedPtr&, int = 0, bool = false);
-    static std::string typeToString(const TypePtr&);
     static bool isValueType(const TypePtr&);
 
     //
diff --git a/cpp/include/Slice/JavaUtil.h b/cpp/include/Slice/JavaUtil.h
index c1fdd50..0bbd18f 100644
--- a/cpp/include/Slice/JavaUtil.h
+++ b/cpp/include/Slice/JavaUtil.h
@@ -54,6 +54,20 @@ public:
 
     void close();
 
+    //
+    // Get the Java name for a type. If an optional scope is provided,
+    // the scope will be removed from the result if possible.
+    //
+    enum TypeMode
+    {
+        TypeModeIn,
+        TypeModeOut,
+        TypeModeMember,
+        TypeModeReturn
+    };
+    static std::string typeToString(const TypePtr&, TypeMode, const std::string& = std::string(),
+                             const StringList& = StringList(), bool = true);
+
 protected:
 
     JavaGenerator(const std::string&);
@@ -70,57 +84,43 @@ protected:
     // Check a symbol against any of the Java keywords. If a
     // match is found, return the symbol with a leading underscore.
     //
-    std::string fixKwd(const std::string&) const;
+    static std::string fixKwd(const std::string&);
 
     //
     // Convert a Slice scoped name into a Java name.
     //
-    std::string convertScopedName(const std::string&,
-                                  const std::string& = std::string(),
-                                  const std::string& = std::string()) const;
+    static std::string convertScopedName(const std::string&,
+                                         const std::string& = std::string(),
+                                         const std::string& = std::string());
 
 
     //
     // Returns the package prefix for a give Slice file.
     //
-    std::string getPackagePrefix(const ContainedPtr&) const;
+    static std::string getPackagePrefix(const ContainedPtr&);
 
     //
     // Returns the Java package of a Contained entity.
     //
-    std::string getPackage(const ContainedPtr&) const;
+    static std::string getPackage(const ContainedPtr&);
 
     //
     // Returns the Java name for a Contained entity. If the optional
     // package argument matches the entity's package name, then the
     // package is removed from the result.
     //
-    std::string getAbsolute(const ContainedPtr&,
-                            const std::string& = std::string(),
-                            const std::string& = std::string(),
-                            const std::string& = std::string()) const;
-
-    //
-    // Get the Java name for a type. If an optional scope is provided,
-    // the scope will be removed from the result if possible.
-    //
-    enum TypeMode
-    {
-        TypeModeIn,
-        TypeModeOut,
-        TypeModeMember,
-        TypeModeReturn
-    };
-    std::string typeToString(const TypePtr&, TypeMode, const std::string& = std::string(),
-                             const StringList& = StringList(), bool = true) const;
+    static std::string getAbsolute(const ContainedPtr&,
+                                   const std::string& = std::string(),
+                                   const std::string& = std::string(),
+                                   const std::string& = std::string());
 
     //
     // Get the Java object name for a type. For primitive types, this returns the
     // Java class type (e.g., Integer). For all other types, this function delegates
     // to typeToString.
     //
-    std::string typeToObjectString(const TypePtr&, TypeMode, const std::string& = std::string(),
-                                   const StringList& = StringList(), bool = true) const;
+    static std::string typeToObjectString(const TypePtr&, TypeMode, const std::string& = std::string(),
+                                          const StringList& = StringList(), bool = true);
 
     //
     // Generate code to marshal or unmarshal a type.
@@ -183,9 +183,9 @@ protected:
     // The functions return true if a custom type was defined and false to indicate
     // the default mapping was used.
     //
-    bool getDictionaryTypes(const DictionaryPtr&, const std::string&, const StringList&,
-                            std::string&, std::string&) const;
-    bool getSequenceTypes(const SequencePtr&, const std::string&, const StringList&, std::string&, std::string&) const;
+    static bool getDictionaryTypes(const DictionaryPtr&, const std::string&, const StringList&,
+                            std::string&, std::string&);
+    static bool getSequenceTypes(const SequencePtr&, const std::string&, const StringList&, std::string&, std::string&);
 
     virtual JavaOutput* createOutput();
 
@@ -223,7 +223,7 @@ private:
 
     std::string _dir;
     ::IceUtilInternal::Output* _out;
-    mutable std::map<std::string, std::string> _filePackagePrefix;
+    static std::map<std::string, std::string> _filePackagePrefix;
 };
 
 }
diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h
index afb34a8..3f39d7b 100644
--- a/cpp/include/Slice/Parser.h
+++ b/cpp/include/Slice/Parser.h
@@ -189,15 +189,6 @@ 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&) { }
@@ -218,13 +209,6 @@ 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 22c8eb3..7649d90 100644
--- a/cpp/include/Slice/Plugin.h
+++ b/cpp/include/Slice/Plugin.h
@@ -11,8 +11,8 @@ namespace Plugin
 
     enum Language
     {
-        LanguageCXX,
-        LanguageCS,
+        LanguageCPlusPlus,
+        LanguageCs,
         LanguageJava,
         LanguagePython,
         LanguageRuby,
@@ -21,7 +21,7 @@ namespace Plugin
 
     typedef std::list<ParserVisitor *> VisitorList;
 
-    typedef VisitorList* (*FACTORY)(Plugin::Language, ParserVisitor::LanguageHelper*);
+    typedef VisitorList* (*FACTORY)(Plugin::Language);
 
 }
 
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index 5c06896..51ecce4 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -169,6 +169,8 @@ Slice::JavaOutput::printHeader()
 
 const string Slice::JavaGenerator::_getSetMetaData = "java:getset";
 
+map<string, string> Slice::JavaGenerator::_filePackagePrefix;
+
 Slice::JavaGenerator::JavaGenerator(const string& dir) :
     _dir(dir),
     _out(0)
@@ -292,7 +294,7 @@ splitScopedName(const string& scoped)
 // otherwise, return the name unchanged.
 //
 string
-Slice::JavaGenerator::fixKwd(const string& name) const
+Slice::JavaGenerator::fixKwd(const string& name)
 {
     if(name.empty())
     {
@@ -313,7 +315,7 @@ Slice::JavaGenerator::fixKwd(const string& name) const
 }
 
 string
-Slice::JavaGenerator::convertScopedName(const string& scoped, const string& prefix, const string& suffix) const
+Slice::JavaGenerator::convertScopedName(const string& scoped, const string& prefix, const string& suffix)
 {
     string result;
     string::size_type start = 0;
@@ -363,7 +365,7 @@ Slice::JavaGenerator::convertScopedName(const string& scoped, const string& pref
 }
 
 string
-Slice::JavaGenerator::getPackagePrefix(const ContainedPtr& cont) const
+Slice::JavaGenerator::getPackagePrefix(const ContainedPtr& cont)
 {
     UnitPtr unit = cont->container()->unit();
     string file = cont->file();
@@ -388,7 +390,7 @@ Slice::JavaGenerator::getPackagePrefix(const ContainedPtr& cont) const
 }
 
 string
-Slice::JavaGenerator::getPackage(const ContainedPtr& cont) const
+Slice::JavaGenerator::getPackage(const ContainedPtr& cont)
 {
     string scope = convertScopedName(cont->scope());
     string prefix = getPackagePrefix(cont);
@@ -411,7 +413,7 @@ string
 Slice::JavaGenerator::getAbsolute(const ContainedPtr& cont,
                                   const string& package,
                                   const string& prefix,
-                                  const string& suffix) const
+                                  const string& suffix)
 {
     string name = cont->name();
     if(prefix == "" && suffix == "")
@@ -438,7 +440,7 @@ Slice::JavaGenerator::typeToString(const TypePtr& type,
                                    TypeMode mode,
                                    const string& package,
                                    const StringList& metaData,
-                                   bool formal) const
+                                   bool formal)
 {
     static const char* builtinTable[] =
     {
@@ -619,7 +621,7 @@ Slice::JavaGenerator::typeToObjectString(const TypePtr& type,
                                          TypeMode mode,
                                          const string& package,
                                          const StringList& metaData,
-                                         bool formal) const
+                                         bool formal)
 {
     static const char* builtinTable[] =
     {
@@ -2458,7 +2460,7 @@ Slice::JavaGenerator::getDictionaryTypes(const DictionaryPtr& dict,
                                          const string& package,
                                          const StringList& metaData,
                                          string& instanceType,
-                                         string& formalType) const
+                                         string& formalType)
 {
     bool customType = false;
 
@@ -2516,7 +2518,7 @@ Slice::JavaGenerator::getSequenceTypes(const SequencePtr& seq,
                                        const string& package,
                                        const StringList& metaData,
                                        string& instanceType,
-                                       string& formalType) const
+                                       string& formalType)
 {
     bool customType = false;
 
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 8c17f76..21476de 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -175,155 +175,6 @@ 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();
@@ -336,14 +187,13 @@ Slice::Gen::generate(const UnitPtr& p)
         
         Plugin::VisitorList* pluginVisitors;
         Plugin::FACTORY factory = (Plugin::FACTORY) sym;
-        pluginVisitors = factory(Plugin::LanguageCXX, &pluginHelper);
+        pluginVisitors = factory(Plugin::LanguageCPlusPlus);
         
         if(pluginVisitors)
         {
             for(Plugin::VisitorList::const_iterator it = pluginVisitors->begin(); it != pluginVisitors->end(); it++)
             {
-                pluginHelper._visitor = *it;
-                p->visit(&pluginHelper, true);
+                p->visit(*it, true);
                 delete *it;
             }
             delete pluginVisitors;
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 7e3a229..275c405 100644
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -1939,7 +1939,7 @@ Slice::Gen::generate(const UnitPtr& p)
         
         Plugin::VisitorList* pluginVisitors;
         Plugin::FACTORY factory = (Plugin::FACTORY) sym;
-        pluginVisitors = factory(Plugin::LanguageCS, 0);
+        pluginVisitors = factory(Plugin::LanguageCs);
         
         if(pluginVisitors)
         {
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 44f5274..3f49ed2 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -1759,31 +1759,6 @@ Slice::Gen::~Gen()
 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 JavaGenerator::typeToString(type, JavaGenerator::TypeModeReturn, "", metadata, false);
-        }
-
-        virtual string inputTypeToString(const TypePtr& type, const StringList& metadata)
-        {
-            return JavaGenerator::typeToString(type, JavaGenerator::TypeModeIn, "", metadata, false);
-        }
-
-        virtual string outputTypeToString(const TypePtr& type, const StringList& metadata)
-        {
-            return JavaGenerator::typeToString(type, JavaGenerator::TypeModeOut, "", metadata, false);
-        }
-    } pluginHelper(_dir);
-
     for(vector<string>::const_iterator plugin = _plugins.begin(); plugin != _plugins.end(); plugin++)
     {
         IceUtil::DynamicLibraryPtr library = new IceUtil::DynamicLibrary();
@@ -1796,7 +1771,7 @@ Slice::Gen::generate(const UnitPtr& p, bool stream)
         
         Plugin::VisitorList* pluginVisitors;
         Plugin::FACTORY factory = (Plugin::FACTORY) sym;
-        pluginVisitors = factory(Plugin::LanguageJava, &pluginHelper);
+        pluginVisitors = factory(Plugin::LanguageJava);
         
         if(pluginVisitors)
         {

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


-- 
asterisk-scf/release/ice.git



More information about the asterisk-scf-commits mailing list