[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
Mon Jan 3 18:41:17 UTC 2011


branch "visitor-generators" has been updated
       via  1b9dabf02a87fe69202a1322b061754061183189 (commit)
      from  9e2d376b16a493f6e92f05157705ccd89dde4527 (commit)

Summary of changes:
 cpp/include/Slice/Parser.h              |   25 ++--
 cpp/src/Slice/Parser.cpp                |  331 ++++---------------------------
 cpp/src/Slice/VisitorPatternVisitor.cpp |   12 +-
 3 files changed, 67 insertions(+), 301 deletions(-)


- Log -----------------------------------------------------------------
commit 1b9dabf02a87fe69202a1322b061754061183189
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Mon Jan 3 12:40:18 2011 -0600

    Removed some unnecessary member functions from GeneratedOperation.
    
    Eliminated most of the code duplication between Operation and GeneratedOperation.
    
    Converted GeneratedOperation to having one constructor instead of two.

diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h
index f2a72ef..9a5b99e 100644
--- a/cpp/include/Slice/Parser.h
+++ b/cpp/include/Slice/Parser.h
@@ -457,12 +457,12 @@ public:
     bool checkIntroduced(const std::string&, ContainedPtr = 0);
     bool nameIsLegal(const std::string&, const char *);
     bool checkForGlobalDef(const std::string&, const char *);
+    void checkIdentifier(const std::string&) const;
 
 protected:
 
     Container(const UnitPtr&);
 
-    void checkIdentifier(const std::string&) const;
     bool checkInterfaceAndLocal(const std::string&, bool, bool, bool, bool, bool);
     bool checkGlobalMetaData(const StringList&, const StringList&);
     bool validateConstant(const std::string&, const TypePtr&, const SyntaxTreeBasePtr&, const std::string&, bool);
@@ -610,7 +610,9 @@ protected:
 // concrete (body specified). If the body is specified, it will be a
 // StringList, and each string in the list will be emitted into the
 // function body in a manner specific to the language the translator
-// writes.
+// writes. An empty list will be treated as 'no body', so if you want to
+// have a non-abstract operation generated without any code in the body
+// you'll need to provide a StringList with an empty string in it.
 // ----------------------------------------------------------------------
 
 class SLICE_API GeneratedOperation : virtual public Contained, virtual public Container
@@ -629,23 +631,19 @@ public:
     ParamDeclList parameters() const;
     virtual ContainedType containedType() const;
     virtual bool uses(const ContainedPtr&) const;
-    bool sendsClasses() const;
-    bool returnsClasses() const;
-    bool returnsData() const;
-    bool isAbstract() const;
     StringList body() const;
+    bool isAbstract() const;
     virtual std::string kindOf() const;
     virtual void visit(ParserVisitor*, bool);
 
 protected:
 
-    GeneratedOperation(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, bool, Mode);
+    GeneratedOperation(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, Mode);
     friend class ClassDef;
 
     TypePtr _returnType;
     Mode _mode;
     StringList _body;
-    bool _abstract;
 };
 
 // ----------------------------------------------------------------------
@@ -667,8 +665,6 @@ public:
     OperationPtr createOperation(const std::string&, const TypePtr&, Operation::Mode = Operation::Normal);
     GeneratedOperationPtr createGeneratedOperation(const std::string&, const TypePtr&, const StringList&,
                                                    GeneratedOperation::Mode = GeneratedOperation::Normal);
-    GeneratedOperationPtr createGeneratedOperation(const std::string&, const TypePtr&,
-                                                   GeneratedOperation::Mode = GeneratedOperation::Normal);
     DataMemberPtr createDataMember(const std::string&, const TypePtr&, const SyntaxTreeBasePtr&, const std::string&,
                                    const std::string&);
     ClassDeclPtr declaration() const;
@@ -942,6 +938,10 @@ 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,8 +956,9 @@ public:
 protected:
 
     ParamDecl(const ContainerPtr&, const std::string&, const TypePtr&, bool isOutParam);
-    friend class Operation;
-    friend class GeneratedOperation;
+    friend ParamDeclPtr createParamDeclCommon(const std::string&, const Slice::TypePtr&, bool,
+                                              Slice::ContainedList&, const Slice::ContainerPtr&, const Slice::ContainedPtr&,
+                                              const Slice::UnitPtr&, bool);
 
     TypePtr _type;
     bool _isOutParam;
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index aba72c9..a462159 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -2963,119 +2963,9 @@ Slice::ClassDef::createGeneratedOperation(const string& name,
 {
     checkIdentifier(name);
 
-#if 0
     ContainedList matches = _unit->findContents(thisScope() + name);
     if(!matches.empty())
     {
-        OperationPtr p = OperationPtr::dynamicCast(matches.front());
-        if(p)
-        {
-            if(_unit->ignRedefs())
-            {
-                p->updateIncludeLevel();
-                return p;
-            }
-        }
-        if(matches.front()->name() != name)
-        {
-            string msg = "operation `" + name + "' differs only in capitalization from ";
-            msg += matches.front()->kindOf() + " `" + matches.front()->name() + "'";
-            _unit->error(msg);
-        }
-        string msg = "redefinition of " + matches.front()->kindOf() + " `" + matches.front()->name();
-        msg += "' as operation `" + name + "'";
-        _unit->error(msg);
-        return 0;
-    }
-#endif
-
-    //
-    // Check whether enclosing interface/class has the same name.
-    //
-    if(name == this->name())
-    {
-        string msg = isInterface() ? "interface" : "class";
-        msg += " name `" + name + "' cannot be used as operation name";
-        _unit->error(msg);
-        return 0;
-    }
-
-    string newName = IceUtilInternal::toLower(name);
-    string thisName = IceUtilInternal::toLower(this->name());
-    if(newName == thisName)
-    {
-        string msg = "operation `" + name + "' differs only in capitalization from enclosing ";
-        msg += isInterface() ? "interface" : "class";
-        msg += " name `" + this->name() + "'";
-        _unit->error(msg);
-    }
-
-#if 0
-    //
-    // Check whether any bases have defined something with the same name already.
-    //
-    for(ClassList::const_iterator p = _bases.begin(); p != _bases.end(); ++p)
-    {
-        ContainedList cl;
-        OperationList ol = (*p)->allOperations();
-        copy(ol.begin(), ol.end(), back_inserter(cl));
-        DataMemberList dml = (*p)->allDataMembers();
-        copy(dml.begin(), dml.end(), back_inserter(cl));
-        for(ContainedList::const_iterator q = cl.begin(); q != cl.end(); ++q)
-        {
-            if((*q)->name() == name)
-            {
-                string msg = "operation `" + name;
-                msg += "' is already defined as a";
-                static const string vowels = "aeiou";
-                string kindOf = (*q)->kindOf();
-                if(vowels.find_first_of(kindOf[0]) != string::npos)
-                {
-                    msg += "n";
-                }
-                msg += " " + kindOf + " in a base interface or class";
-                _unit->error(msg);
-                return 0;
-            }
-
-            string baseName = IceUtilInternal::toLower((*q)->name());
-            string newName = IceUtilInternal::toLower(name);
-            if(baseName == newName)
-            {
-                string msg = "operation `" + name + "' differs only in capitalization from " + (*q)->kindOf();
-                msg += " `" + (*q)->name() + "', which is defined in a base interface or class";
-                _unit->error(msg);
-            }
-        }
-    }
-#endif
-
-    _hasGeneratedOperations = true;
-    GeneratedOperationPtr gop = new GeneratedOperation(this, name, returnType, body, false, mode);
-    _contents.push_back(gop);
-    return gop;
-}
-
-GeneratedOperationPtr
-Slice::ClassDef::createGeneratedOperation(const string& name,
-					  const TypePtr& returnType,
-                                          GeneratedOperation::Mode mode)
-{
-    checkIdentifier(name);
-
-#if 0
-    ContainedList matches = _unit->findContents(thisScope() + name);
-    if(!matches.empty())
-    {
-        OperationPtr p = OperationPtr::dynamicCast(matches.front());
-        if(p)
-        {
-            if(_unit->ignRedefs())
-            {
-                p->updateIncludeLevel();
-                return p;
-            }
-        }
         if(matches.front()->name() != name)
         {
             string msg = "operation `" + name + "' differs only in capitalization from ";
@@ -3087,7 +2977,6 @@ Slice::ClassDef::createGeneratedOperation(const string& name,
         _unit->error(msg);
         return 0;
     }
-#endif
 
     //
     // Check whether enclosing interface/class has the same name.
@@ -3110,7 +2999,6 @@ Slice::ClassDef::createGeneratedOperation(const string& name,
         _unit->error(msg);
     }
 
-#if 0
     //
     // Check whether any bases have defined something with the same name already.
     //
@@ -3148,10 +3036,9 @@ Slice::ClassDef::createGeneratedOperation(const string& name,
             }
         }
     }
-#endif
 
     _hasGeneratedOperations = true;
-    GeneratedOperationPtr gop = new GeneratedOperation(this, name, returnType, StringList(), false, mode);
+    GeneratedOperationPtr gop = new GeneratedOperation(this, name, returnType, body, mode);
     _contents.push_back(gop);
     return gop;
 }
@@ -4785,13 +4672,15 @@ Slice::Operation::sendMode() const
 }
 
 ParamDeclPtr
-Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool isOutParam)
+Slice::createParamDeclCommon(const string& name, const TypePtr& type, bool isOutParam,
+                             ContainedList& contents, const ContainerPtr& ctr, const ContainedPtr& cont,
+                             const UnitPtr& unit, bool restrictLocal)
 {
-    checkIdentifier(name);
+    ctr->checkIdentifier(name);
 
-    if(_unit->profile() == IceE)
+    if(unit->profile() == IceE)
     {
-        ClassDefPtr cl = ClassDefPtr::dynamicCast(this->container());
+        ClassDefPtr cl = ClassDefPtr::dynamicCast(cont->container());
         assert(cl);
         if(!cl->isLocal())
         {
@@ -4799,26 +4688,26 @@ Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool
             if((builtin && builtin->kind() == Builtin::KindObject))
             {
                 string msg = "Object `" + name + "' cannot be passed by value.";
-                _unit->error(msg);
+                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);
+                unit->error(msg);
                 return 0;
             }
         }
     }
 
-    ContainedList matches = _unit->findContents(thisScope() + name);
+    ContainedList matches = unit->findContents(ctr->thisScope() + name);
     if(!matches.empty())
     {
         ParamDeclPtr p = ParamDeclPtr::dynamicCast(matches.front());
         if(p)
         {
-            if(_unit->ignRedefs())
+            if(unit->ignRedefs())
             {
                 p->updateIncludeLevel();
                 return p;
@@ -4828,12 +4717,12 @@ Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool
         {
             string msg = "parameter `" + name + "' differs only in capitalization from ";
             msg += "parameter `" + matches.front()->name() + "'";
-            _unit->error(msg);
+            unit->error(msg);
         }
         else
         {
             string msg = "redefinition of parameter `" + name + "'";
-            _unit->error(msg);
+            unit->error(msg);
             return 0;
         }
     }
@@ -4841,54 +4730,63 @@ Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool
     //
     // Check whether enclosing operation has the same name.
     //
-    if(name == this->name())
+    if(name == cont->name())
     {
         string msg = "operation name `";
         msg += name;
         msg += "' cannot be used as parameter name";
-        _unit->error(msg);
+        unit->error(msg);
         return 0;
     }
 
     string newName = IceUtilInternal::toLower(name);
-    string thisName = IceUtilInternal::toLower(this->name());
+    string thisName = IceUtilInternal::toLower(cont->name());
     if(newName == thisName)
     {
         string msg = "parameter `" + name + "' differs only in capitalization from operation name `";
-        msg += this->name() + "'";
-        _unit->error(msg);
+        msg += cont->name() + "'";
+        unit->error(msg);
     }
 
     //
     // Check that in parameters don't follow out parameters.
     //
-    if(!_contents.empty())
+    if(!contents.empty())
     {
-        ParamDeclPtr p = ParamDeclPtr::dynamicCast(_contents.back());
+        ParamDeclPtr p = ParamDeclPtr::dynamicCast(contents.back());
         assert(p);
         if(p->isOutParam() && !isOutParam)
         {
-            _unit->error("`" + name + "': in parameters cannot follow out parameters");
+            unit->error("`" + name + "': in parameters cannot follow out parameters");
         }
     }
 
-    //
-    // Non-local class/interface cannot have operation with local parameters.
-    //
-    ClassDefPtr cl = ClassDefPtr::dynamicCast(this->container());
-    assert(cl);
-    if(type->isLocal() && !cl->isLocal())
+    if(restrictLocal)
     {
-        string msg = "non-local " + cl->kindOf() + " `" + cl->name() + "' cannot have local parameter `";
-        msg += name + "' in operation `" + this->name() + "'";
-        _unit->error(msg);
+        //
+        // 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(this, name, type, isOutParam);
-    _contents.push_back(p);
+    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);
+}
+
 ParamDeclList
 Slice::Operation::parameters() const
 {
@@ -5206,94 +5104,7 @@ Slice::GeneratedOperation::mode() const
 ParamDeclPtr
 Slice::GeneratedOperation::createParamDecl(const string& name, const TypePtr& type, bool isOutParam)
 {
-    checkIdentifier(name);
-
-    if(_unit->profile() == IceE)
-    {
-        ClassDefPtr cl = ClassDefPtr::dynamicCast(this->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(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 == this->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(this->name());
-    if(newName == thisName)
-    {
-        string msg = "parameter `" + name + "' differs only in capitalization from operation name `";
-        msg += this->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");
-        }
-    }
-
-    ParamDeclPtr p = new ParamDecl(this, name, type, isOutParam);
-    _contents.push_back(p);
-    return p;
+    return createParamDeclCommon(name, type, isOutParam, _contents, this, this, _unit, false);
 }
 
 ParamDeclList
@@ -5332,61 +5143,9 @@ Slice::GeneratedOperation::uses(const ContainedPtr& contained) const
 }
 
 bool
-Slice::GeneratedOperation::sendsClasses() const
-{
-    ParamDeclList pdl = parameters();
-    for(ParamDeclList::const_iterator i = pdl.begin(); i != pdl.end(); ++i)
-    {
-        if(!(*i)->isOutParam() && (*i)->type()->usesClasses())
-        {
-            return true;
-        }
-    }
-    return false;
-}
-
-bool
-Slice::GeneratedOperation::returnsClasses() const
-{
-    TypePtr t = returnType();
-    if(t && t->usesClasses())
-    {
-        return true;
-    }
-    ParamDeclList pdl = parameters();
-    for(ParamDeclList::const_iterator i = pdl.begin(); i != pdl.end(); ++i)
-    {
-        if((*i)->isOutParam() && (*i)->type()->usesClasses())
-        {
-            return true;
-        }
-    }
-    return false;
-}
-
-bool
-Slice::GeneratedOperation::returnsData() const
-{
-    TypePtr t = returnType();
-    if(t)
-    {
-        return true;
-    }
-    ParamDeclList pdl = parameters();
-    for(ParamDeclList::const_iterator i = pdl.begin(); i != pdl.end(); ++i)
-    {
-        if((*i)->isOutParam())
-        {
-            return true;
-        }
-    }
-    return false;
-}
-
-bool
 Slice::GeneratedOperation::isAbstract() const
 {
-    return _abstract;
+    return _body.empty();
 }
 
 StringList
@@ -5411,15 +5170,13 @@ Slice::GeneratedOperation::GeneratedOperation(const ContainerPtr& container,
 					      const string& name,
 					      const TypePtr& returnType,
 					      const StringList& body,
-					      bool abstract,
                                               Mode mode) :
     SyntaxTreeBase(container->unit()),
     Contained(container, name),
     Container(container->unit()),
     _returnType(returnType),
     _mode(mode),
-    _body(body),
-    _abstract(abstract)
+    _body(body)
 {
 }
 
diff --git a/cpp/src/Slice/VisitorPatternVisitor.cpp b/cpp/src/Slice/VisitorPatternVisitor.cpp
index 67faf73..6259b68 100644
--- a/cpp/src/Slice/VisitorPatternVisitor.cpp
+++ b/cpp/src/Slice/VisitorPatternVisitor.cpp
@@ -104,7 +104,11 @@ Slice::VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
                     // won't actually produce output for the include file.
                     if(derivedVisitor->includeLevel() == 0)
                     {
-                        GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, StringList());
+                        // it is necessary to provide a non-empty body for the operation
+                        // to keep it from being abstract
+                        StringList body;
+                        body.push_back("");
+                        GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, body);
                         gop->createParamDecl("item", p->declaration(), false);
                     }
                     // There is no need to actually generate operations into the visited
@@ -146,7 +150,11 @@ Slice::VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
         {
             if(derivedVisitor->includeLevel() == 0)
             {
-                GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, StringList());
+                // it is necessary to provide a non-empty body for the operation
+                // to keep it from being abstract
+                StringList body;
+                body.push_back("");
+                GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, body);
                 gop->createParamDecl("item", p->declaration(), false);
             }
             if(p->includeLevel() == 0)

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


-- 
asterisk-scf/release/ice.git



More information about the asterisk-scf-commits mailing list