[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 16:28:01 UTC 2011


branch "visitor-generators" has been updated
       via  fb92fe1f171cca24438b3f0db3e0f999bd160923 (commit)
       via  5480a676a4a805fc0c89824276b20c56de43ff6d (commit)
      from  615a1be18e8fe040c50f844deee6353873643611 (commit)

Summary of changes:
 cpp/include/Slice/Parser.h    |   12 +--
 cpp/src/Ice/CommunicatorI.cpp |    1 +
 cpp/src/Ice/CommunicatorI.h   |    2 +-
 cpp/src/IceUtil/Makefile.mak  |    1 +
 cpp/src/Slice/Parser.cpp      |  224 ++++++++++++++++++++--------------------
 cpp/src/slice2java/Gen.cpp    |   33 ++++++-
 cpp/src/slice2java/Gen.h      |    4 +-
 cpp/src/slice2java/Main.cpp   |    6 +-
 8 files changed, 159 insertions(+), 124 deletions(-)


- Log -----------------------------------------------------------------
commit fb92fe1f171cca24438b3f0db3e0f999bd160923
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Wed Jan 5 10:27:42 2011 -0600

    Changes to address Brent's comments on CR-ASTSCF-36.

diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h
index 9a5b99e..3f39d7b 100644
--- a/cpp/include/Slice/Parser.h
+++ b/cpp/include/Slice/Parser.h
@@ -938,10 +938,6 @@ protected:
 // ParamDecl
 // ----------------------------------------------------------------------
 
-ParamDeclPtr createParamDeclCommon(const std::string&, const TypePtr&, bool,
-                                   ContainedList&, const ContainerPtr&, const ContainedPtr&,
-                                   const UnitPtr&, bool);
-
 class SLICE_API ParamDecl : virtual public Contained
 {
 public:
@@ -956,9 +952,11 @@ public:
 protected:
 
     ParamDecl(const ContainerPtr&, const std::string&, const TypePtr&, bool isOutParam);
-    friend ParamDeclPtr createParamDeclCommon(const std::string&, const Slice::TypePtr&, bool,
-                                              Slice::ContainedList&, const Slice::ContainerPtr&, const Slice::ContainedPtr&,
-                                              const Slice::UnitPtr&, bool);
+    static ParamDeclPtr createCommon(const std::string&, const TypePtr&, bool,
+                                     ContainedList&, const ContainerPtr&, const ContainedPtr&,
+                                     const UnitPtr&, bool);
+    friend class Operation;
+    friend class GeneratedOperation;
 
     TypePtr _type;
     bool _isOutParam;
diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp
index eebca14..872b488 100644
--- a/cpp/src/Ice/CommunicatorI.cpp
+++ b/cpp/src/Ice/CommunicatorI.cpp
@@ -8,6 +8,7 @@
 // **********************************************************************
 
 #include <IceUtil/DisableWarnings.h>
+#include <IceUtil/DynamicLibrary.h>
 #include <Ice/CommunicatorI.h>
 #include <Ice/Instance.h>
 #include <Ice/Properties.h>
diff --git a/cpp/src/Ice/CommunicatorI.h b/cpp/src/Ice/CommunicatorI.h
index b056803..bc3d65c 100644
--- a/cpp/src/Ice/CommunicatorI.h
+++ b/cpp/src/Ice/CommunicatorI.h
@@ -12,7 +12,7 @@
 
 #include <IceUtil/RecMutex.h>
 
-#include <IceUtil/DynamicLibrary.h>
+#include <IceUtil/DynamicLibraryF.h>
 #include <Ice/Initialize.h>
 #include <Ice/Communicator.h>
 
diff --git a/cpp/src/IceUtil/Makefile.mak b/cpp/src/IceUtil/Makefile.mak
index b384ecb..d838a84 100644
--- a/cpp/src/IceUtil/Makefile.mak
+++ b/cpp/src/IceUtil/Makefile.mak
@@ -19,6 +19,7 @@ OBJS		= ArgVector.obj \
                   ConvertUTF.obj \
 		  CountDownLatch.obj \
 		  CtrlCHandler.obj \
+		  DynamicLibrary.obj \
 		  Exception.obj \
 		  FileUtil.obj \
 		  InputUtil.obj \
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index a462159..bba65c1 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -4672,119 +4672,9 @@ Slice::Operation::sendMode() const
 }
 
 ParamDeclPtr
-Slice::createParamDeclCommon(const string& name, const TypePtr& type, bool isOutParam,
-                             ContainedList& contents, const ContainerPtr& ctr, const ContainedPtr& cont,
-                             const UnitPtr& unit, bool restrictLocal)
-{
-    ctr->checkIdentifier(name);
-
-    if(unit->profile() == IceE)
-    {
-        ClassDefPtr cl = ClassDefPtr::dynamicCast(cont->container());
-        assert(cl);
-        if(!cl->isLocal())
-        {
-            BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
-            if((builtin && builtin->kind() == Builtin::KindObject))
-            {
-                string msg = "Object `" + name + "' cannot be passed by value.";
-                unit->error(msg);
-                return 0;
-            }
-            ClassDeclPtr classDecl =  ClassDeclPtr::dynamicCast(type);
-            if(classDecl != 0 && !classDecl->isLocal())
-            {
-                string msg = "Object `" + name + "' cannot be passed by value.";
-                unit->error(msg);
-                return 0;
-            }
-        }
-    }
-
-    ContainedList matches = unit->findContents(ctr->thisScope() + name);
-    if(!matches.empty())
-    {
-        ParamDeclPtr p = ParamDeclPtr::dynamicCast(matches.front());
-        if(p)
-        {
-            if(unit->ignRedefs())
-            {
-                p->updateIncludeLevel();
-                return p;
-            }
-        }
-        if(matches.front()->name() != name)
-        {
-            string msg = "parameter `" + name + "' differs only in capitalization from ";
-            msg += "parameter `" + matches.front()->name() + "'";
-            unit->error(msg);
-        }
-        else
-        {
-            string msg = "redefinition of parameter `" + name + "'";
-            unit->error(msg);
-            return 0;
-        }
-    }
-
-    //
-    // Check whether enclosing operation has the same name.
-    //
-    if(name == cont->name())
-    {
-        string msg = "operation name `";
-        msg += name;
-        msg += "' cannot be used as parameter name";
-        unit->error(msg);
-        return 0;
-    }
-
-    string newName = IceUtilInternal::toLower(name);
-    string thisName = IceUtilInternal::toLower(cont->name());
-    if(newName == thisName)
-    {
-        string msg = "parameter `" + name + "' differs only in capitalization from operation name `";
-        msg += cont->name() + "'";
-        unit->error(msg);
-    }
-
-    //
-    // Check that in parameters don't follow out parameters.
-    //
-    if(!contents.empty())
-    {
-        ParamDeclPtr p = ParamDeclPtr::dynamicCast(contents.back());
-        assert(p);
-        if(p->isOutParam() && !isOutParam)
-        {
-            unit->error("`" + name + "': in parameters cannot follow out parameters");
-        }
-    }
-
-    if(restrictLocal)
-    {
-        //
-        // Non-local class/interface cannot have operation with local parameters.
-        //
-        ClassDefPtr cl = ClassDefPtr::dynamicCast(cont->container());
-        assert(cl);
-        if(type->isLocal() && !cl->isLocal())
-        {
-            string msg = "non-local " + cl->kindOf() + " `" + cl->name() + "' cannot have local parameter `";
-            msg += name + "' in operation `" + cont->name() + "'";
-            unit->error(msg);
-        }
-    }
-
-    ParamDeclPtr p = new ParamDecl(ctr, name, type, isOutParam);
-    contents.push_back(p);
-    return p;
-}
-
-ParamDeclPtr
 Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool isOutParam)
 {
-    return createParamDeclCommon(name, type, isOutParam, _contents, this, this, _unit, true);
+    return ParamDecl::createCommon(name, type, isOutParam, _contents, this, this, _unit, true);
 }
 
 ParamDeclList
@@ -5104,7 +4994,7 @@ Slice::GeneratedOperation::mode() const
 ParamDeclPtr
 Slice::GeneratedOperation::createParamDecl(const string& name, const TypePtr& type, bool isOutParam)
 {
-    return createParamDeclCommon(name, type, isOutParam, _contents, this, this, _unit, false);
+    return ParamDecl::createCommon(name, type, isOutParam, _contents, this, this, _unit, false);
 }
 
 ParamDeclList
@@ -5184,6 +5074,116 @@ Slice::GeneratedOperation::GeneratedOperation(const ContainerPtr& container,
 // ParamDecl
 // ----------------------------------------------------------------------
 
+ParamDeclPtr
+Slice::ParamDecl::createCommon(const string& name, const TypePtr& type, bool isOutParam,
+                               ContainedList& contents, const ContainerPtr& ctr, const ContainedPtr& cont,
+                               const UnitPtr& unit, bool restrictLocal)
+{
+    ctr->checkIdentifier(name);
+
+    if(unit->profile() == IceE)
+    {
+        ClassDefPtr cl = ClassDefPtr::dynamicCast(cont->container());
+        assert(cl);
+        if(!cl->isLocal())
+        {
+            BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
+            if((builtin && builtin->kind() == Builtin::KindObject))
+            {
+                string msg = "Object `" + name + "' cannot be passed by value.";
+                unit->error(msg);
+                return 0;
+            }
+            ClassDeclPtr classDecl =  ClassDeclPtr::dynamicCast(type);
+            if(classDecl != 0 && !classDecl->isLocal())
+            {
+                string msg = "Object `" + name + "' cannot be passed by value.";
+                unit->error(msg);
+                return 0;
+            }
+        }
+    }
+
+    ContainedList matches = unit->findContents(ctr->thisScope() + name);
+    if(!matches.empty())
+    {
+        ParamDeclPtr p = ParamDeclPtr::dynamicCast(matches.front());
+        if(p)
+        {
+            if(unit->ignRedefs())
+            {
+                p->updateIncludeLevel();
+                return p;
+            }
+        }
+        if(matches.front()->name() != name)
+        {
+            string msg = "parameter `" + name + "' differs only in capitalization from ";
+            msg += "parameter `" + matches.front()->name() + "'";
+            unit->error(msg);
+        }
+        else
+        {
+            string msg = "redefinition of parameter `" + name + "'";
+            unit->error(msg);
+            return 0;
+        }
+    }
+
+    //
+    // Check whether enclosing operation has the same name.
+    //
+    if(name == cont->name())
+    {
+        string msg = "operation name `";
+        msg += name;
+        msg += "' cannot be used as parameter name";
+        unit->error(msg);
+        return 0;
+    }
+
+    string newName = IceUtilInternal::toLower(name);
+    string thisName = IceUtilInternal::toLower(cont->name());
+    if(newName == thisName)
+    {
+        string msg = "parameter `" + name + "' differs only in capitalization from operation name `";
+        msg += cont->name() + "'";
+        unit->error(msg);
+    }
+
+    //
+    // Check that in parameters don't follow out parameters.
+    //
+    if(!contents.empty())
+    {
+        ParamDeclPtr p = ParamDeclPtr::dynamicCast(contents.back());
+        assert(p);
+        if(p->isOutParam() && !isOutParam)
+        {
+            unit->error("`" + name + "': in parameters cannot follow out parameters");
+        }
+    }
+
+    if(restrictLocal)
+    {
+        //
+        // Non-local class/interface cannot have operation with local parameters.
+        //
+        ClassDefPtr cl = ClassDefPtr::dynamicCast(cont->container());
+        assert(cl);
+        if(type->isLocal() && !cl->isLocal())
+        {
+            string msg = "non-local " + cl->kindOf() + " `" + cl->name() + "' cannot have local parameter `";
+            msg += name + "' in operation `" + cont->name() + "'";
+            unit->error(msg);
+        }
+    }
+
+    ParamDeclPtr p = new ParamDecl(ctr, name, type, isOutParam);
+    contents.push_back(p);
+    return p;
+}
+
 TypePtr
 Slice::ParamDecl::type() const
 {

commit 5480a676a4a805fc0c89824276b20c56de43ff6d
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Tue Jan 4 07:41:18 2011 -0600

    Add support for plugins in slice2java.

diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 2564f7e..51fdade 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -11,9 +11,11 @@
 #include <Gen.h>
 #include <Slice/Checksum.h>
 #include <Slice/Util.h>
+#include <Slice/Plugin.h>
 #include <IceUtil/Functional.h>
 #include <IceUtil/Iterator.h>
 #include <IceUtil/StringUtil.h>
+#include <IceUtil/DynamicLibrary.h>
 #include <cstring>
 
 #include <limits>
@@ -1721,10 +1723,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, const vector<string>& plugins) :
     _base(base),
     _includePaths(includePaths),
-    _dir(dir)
+    _dir(dir),
+    _plugins(plugins)
 {
 }
 
@@ -1732,9 +1735,35 @@ Slice::Gen::~Gen()
 {
 }
 
+typedef Plugin::PluginVisitorList* (*PLUGIN_FACTORY)(Plugin::Language);
+
 void
 Slice::Gen::generate(const UnitPtr& p, bool stream)
 {
+    for(vector<string>::const_iterator plugin = _plugins.begin(); plugin != _plugins.end(); plugin++)
+    {
+        IceUtil::DynamicLibraryPtr library = new IceUtil::DynamicLibrary();
+        IceUtil::DynamicLibrary::symbol_type sym = library->loadEntryPoint(*plugin, false);
+        if(sym == 0)
+        {
+            string msg = library->getErrorMessage();
+            cerr << "Unable to find " << *plugin << " = " << msg << endl;
+        }
+        
+        Plugin::PluginVisitorList* pluginVisitors;
+        PLUGIN_FACTORY factory = (PLUGIN_FACTORY)sym;
+        pluginVisitors = factory(Plugin::LanguageCXX);
+        
+        if(pluginVisitors)
+        {
+            for(Plugin::PluginVisitorList::const_iterator it = pluginVisitors->begin(); it != pluginVisitors->end(); it++)
+            {
+                p->visit(it->get(), true);
+            }
+            delete pluginVisitors;
+        }
+    }
+
     JavaGenerator::validateMetaData(p);
 
     OpsVisitor opsVisitor(_dir);
diff --git a/cpp/src/slice2java/Gen.h b/cpp/src/slice2java/Gen.h
index 5e3f828..59732d3 100644
--- a/cpp/src/slice2java/Gen.h
+++ b/cpp/src/slice2java/Gen.h
@@ -99,7 +99,8 @@ public:
     Gen(const std::string&,
         const std::string&,
         const std::vector<std::string>&,
-        const std::string&);
+        const std::string&,
+        const std::vector<std::string>&);
     ~Gen();
 
     void generate(const UnitPtr&, bool);
@@ -114,6 +115,7 @@ private:
     std::string _base;
     std::vector<std::string> _includePaths;
     std::string _dir;
+    std::vector<std::string> _plugins;
 
     class OpsVisitor : public JavaVisitor
     {
diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp
index 90978cf..281464d 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"
+        "--plugin PATH            Load and apply plugin before generating output.\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("", "plugin", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
 
     vector<string>args;
     try
@@ -151,6 +153,8 @@ compile(int argc, char* argv[])
         cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i));
     }
 
+    vector<string> plugins = opts.argVec("plugin");
+
     bool preprocess = opts.isSet("E");
 
     string output = opts.optArg("output-dir");
@@ -308,7 +312,7 @@ compile(int argc, char* argv[])
                 {
                     try
                     {
-                        Gen gen(argv[0], icecpp->getBaseName(), includePaths, output);
+                        Gen gen(argv[0], icecpp->getBaseName(), includePaths, output, plugins);
                         gen.generate(p, stream);
                         if(tie)
                         {

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


-- 
asterisk-scf/release/ice.git



More information about the asterisk-scf-commits mailing list