[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 13:04:27 UTC 2011


branch "visitor-generators" has been updated
       via  b8b576837c74d551ee9f349014a18578a291ce30 (commit)
       via  be611f4702c0a4b07859f70a323f36883708b118 (commit)
      from  86e0d94479321d8190143e11b9d9be877d3b84dc (commit)

Summary of changes:
 cpp/include/Slice/Parser.h              |    5 +-
 cpp/src/Slice/Parser.cpp                |  135 +++++++++++++++---
 cpp/src/Slice/VisitorPatternVisitor.cpp |  232 +++++++++++++++---------------
 cpp/src/slice2cpp/Gen.cpp               |   56 ++++----
 4 files changed, 262 insertions(+), 166 deletions(-)


- Log -----------------------------------------------------------------
commit b8b576837c74d551ee9f349014a18578a291ce30
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Mon Jan 3 07:04:19 2011 -0600

    indent-region to match ZeroC formatting style.

diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 9f877fa..b7360ed 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -5371,13 +5371,13 @@ Slice::GeneratedOperation::returnsData() const
 bool
 Slice::GeneratedOperation::isAbstract() const
 {
-	return _abstract;
+    return _abstract;
 }
 
 StringList
 Slice::GeneratedOperation::body() const
 {
-	return _body;
+    return _body;
 }
 
 string
@@ -5404,26 +5404,6 @@ Slice::GeneratedOperation::GeneratedOperation(const ContainerPtr& container,
     _body(body),
     _abstract(abstract)
 {
-    if(_unit->profile() == IceE)
-    {
-        ClassDefPtr cl = ClassDefPtr::dynamicCast(this->container());
-        assert(cl);
-        if(!cl->isLocal())
-        {
-            BuiltinPtr builtin = BuiltinPtr::dynamicCast(returnType);
-            if((builtin && builtin->kind() == Builtin::KindObject))
-            {
-                string msg = "Method `" + name + "' cannot return an object by value.";
-                _unit->error(msg);
-            }
-            ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(returnType);
-            if(classDecl != 0 && !classDecl->isLocal())
-            {
-                string msg = "Method `" + name + "' cannot return an object by value.";
-                _unit->error(msg);
-            }
-        }
-    }
 }
 
 // ----------------------------------------------------------------------
diff --git a/cpp/src/Slice/VisitorPatternVisitor.cpp b/cpp/src/Slice/VisitorPatternVisitor.cpp
index a722edc..d31682d 100644
--- a/cpp/src/Slice/VisitorPatternVisitor.cpp
+++ b/cpp/src/Slice/VisitorPatternVisitor.cpp
@@ -10,129 +10,129 @@ findVisitableBase(const map<string, pair<ClassDefPtr, ClassDefPtr> >& visitableB
 		  const ClassDefPtr& p, ClassDefPtr& baseVisitor,
 		  ClassDefPtr& derivedVisitor)
 {
-	ClassList bases = p->allBases();
-	for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
-	{
-		map<string, pair<ClassDefPtr, ClassDefPtr> >::const_iterator it = visitableBases.find((*q)->scoped());
-		if(it != visitableBases.end())
-		{
-			baseVisitor = it->second.first;
-			derivedVisitor = it->second.second;
-			return *q;
-		}
-	}
-	return 0;
+    ClassList bases = p->allBases();
+    for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
+    {
+        map<string, pair<ClassDefPtr, ClassDefPtr> >::const_iterator it = visitableBases.find((*q)->scoped());
+        if(it != visitableBases.end())
+        {
+            baseVisitor = it->second.first;
+            derivedVisitor = it->second.second;
+            return *q;
+        }
+    }
+    return 0;
 }
 
 bool
 Slice::VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
 {
-	ostringstream ostr;
+    ostringstream ostr;
 
-	StringList metaData = p->getMetaData();
-	for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); q++)
-	{
-		if(*q == "visitor")
-		{
-			if(!p->isLocal())
-			{
-				ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
-				     << "to local interfaces but `" << p->name() << "` is not local";
-				emitWarning(p->file(), p->line(), ostr.str());
-			}
-			else if(p->isInterface())
-			{
-				ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
-				     << "to local classes but `" << p->name() << "` is an interface";
-				emitWarning(p->file(), p->line(), ostr.str());
-			}
-			else
-			{
-				_visitorInterfaces[p->scoped()] = p;
-				return false;
-			}
-		}
-		else if(q->find("visitor:", 0) == 0)
-		{
-			if(p->isInterface())
-			{
-				ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
-				     << "to classes, but `" << p->name() << "` is an interface";
-				emitWarning(p->file(), p->line(), ostr.str());
-			}
-			else if(p->isAbstract())
-			{
-				ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
-				     << "to concrete classes, but `" << p->name() << "` is abstract";
-				emitWarning(p->file(), p->line(), ostr.str());
-			}
-			else
-			{
-				const string visitor = (*q).substr(8);
-				map<string, ClassDefPtr>::const_iterator it = _visitorInterfaces.find(visitor);
-				if(it != _visitorInterfaces.end())
-				{
-					ClassDefPtr baseVisitor = it->second, derivedVisitor;
-					findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
-					_visitableBases[p->scoped()] = make_pair(baseVisitor, it->second);
-					if(it->second->includeLevel() == 0)
-					{
-						GeneratedOperationPtr gop = it->second->createGeneratedOperation("visit" + p->name(), 0, StringList());
-						gop->createParamDecl("item", p->declaration(), false);
-					}
-					if(p->includeLevel() == 0)
-					{
-						GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
-										  generateVisitFunctionBody("visitor", baseVisitor, it->second, "visit" + p->name()));
-						gop->createParamDecl("visitor", baseVisitor->declaration(), false);
-					}
-					return false;
-				}
-				else
-				{
-					ostr << "ignoring invalid `" << *q << "` metadata: directive specified on "
-					     << "class `" << p->name() << "` but specified interface '" << visitor << "` was "
-					     << "not marked with `visitor` metadata directive";
-					emitWarning(p->file(), p->line(), ostr.str());
-				}
-			}
-		}
-	}
+    StringList metaData = p->getMetaData();
+    for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); q++)
+    {
+        if(*q == "visitor")
+        {
+            if(!p->isLocal())
+            {
+                ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
+                     << "to local interfaces but `" << p->name() << "` is not local";
+                emitWarning(p->file(), p->line(), ostr.str());
+            }
+            else if(p->isInterface())
+            {
+                ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
+                     << "to local classes but `" << p->name() << "` is an interface";
+                emitWarning(p->file(), p->line(), ostr.str());
+            }
+            else
+            {
+                _visitorInterfaces[p->scoped()] = p;
+                return false;
+            }
+        }
+        else if(q->find("visitor:", 0) == 0)
+        {
+            if(p->isInterface())
+            {
+                ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
+                     << "to classes, but `" << p->name() << "` is an interface";
+                emitWarning(p->file(), p->line(), ostr.str());
+            }
+            else if(p->isAbstract())
+            {
+                ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
+                     << "to concrete classes, but `" << p->name() << "` is abstract";
+                emitWarning(p->file(), p->line(), ostr.str());
+            }
+            else
+            {
+                const string visitor = (*q).substr(8);
+                map<string, ClassDefPtr>::const_iterator it = _visitorInterfaces.find(visitor);
+                if(it != _visitorInterfaces.end())
+                {
+                    ClassDefPtr baseVisitor = it->second, derivedVisitor;
+                    findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
+                    _visitableBases[p->scoped()] = make_pair(baseVisitor, it->second);
+                    if(it->second->includeLevel() == 0)
+                    {
+                        GeneratedOperationPtr gop = it->second->createGeneratedOperation("visit" + p->name(), 0, StringList());
+                        gop->createParamDecl("item", p->declaration(), false);
+                    }
+                    if(p->includeLevel() == 0)
+                    {
+                        GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
+                                                                                generateVisitFunctionBody("visitor", baseVisitor, it->second, "visit" + p->name()));
+                        gop->createParamDecl("visitor", baseVisitor->declaration(), false);
+                    }
+                    return false;
+                }
+                else
+                {
+                    ostr << "ignoring invalid `" << *q << "` metadata: directive specified on "
+                         << "class `" << p->name() << "` but specified interface '" << visitor << "` was "
+                         << "not marked with `visitor` metadata directive";
+                    emitWarning(p->file(), p->line(), ostr.str());
+                }
+            }
+        }
+    }
 
-	if(!p->isInterface() && !p->isAbstract())
-	{
-		ClassDefPtr visitableBase, baseVisitor, derivedVisitor;
-		visitableBase = findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
-		if(visitableBase)
-		{
-			if(derivedVisitor->includeLevel() == 0)
-			{
-				GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, StringList());
-				gop->createParamDecl("item", p->declaration(), false);
-			}
-			if(p->includeLevel() == 0)
-			{
-				GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
-											generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
-				gop->createParamDecl("visitor", baseVisitor->declaration(), false);
-			}
-			return false;
-		}
-	}
+    if(!p->isInterface() && !p->isAbstract())
+    {
+        ClassDefPtr visitableBase, baseVisitor, derivedVisitor;
+        visitableBase = findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
+        if(visitableBase)
+        {
+            if(derivedVisitor->includeLevel() == 0)
+            {
+                GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, StringList());
+                gop->createParamDecl("item", p->declaration(), false);
+            }
+            if(p->includeLevel() == 0)
+            {
+                GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
+                                                                        generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
+                gop->createParamDecl("visitor", baseVisitor->declaration(), false);
+            }
+            return false;
+        }
+    }
 
-	if(p->isInterface())
-	{
-		ClassList bases = p->allBases();
-		for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
-		{
-			map<string, ClassDefPtr>::const_iterator it = _visitorInterfaces.find((*q)->scoped());
-			if(it != _visitorInterfaces.end())
-			{
-				_visitorInterfaces[p->scoped()] = p;
-				return false;
-			}
-		}
-	}
+    if(p->isInterface())
+    {
+        ClassList bases = p->allBases();
+        for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
+        {
+            map<string, ClassDefPtr>::const_iterator it = _visitorInterfaces.find((*q)->scoped());
+            if(it != _visitorInterfaces.end())
+            {
+                _visitorInterfaces[p->scoped()] = p;
+                return false;
+            }
+        }
+    }
 
-	return false;
+    return false;
 }
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 49dc716..7f9a9c6 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -571,21 +571,21 @@ Slice::Gen::CPPVisitorPatternVisitor::generateVisitFunctionBody(const string& pa
 								const ClassDefPtr& derivedVisitor,
 								const string& operationName)
 {
-	ostringstream ostr;
-	StringList body;
+    ostringstream ostr;
+    StringList body;
 
-	if(baseVisitor != derivedVisitor)
-	{
-		ostr << derivedVisitor->scoped() << "Ptr::dynamicCast(" << paramName << ")";
-	}
-	else
-	{
-		ostr << paramName;
-	}
-	ostr << "->" << operationName << "(this);";
-	body.push_back(ostr.str());
+    if(baseVisitor != derivedVisitor)
+    {
+        ostr << derivedVisitor->scoped() << "Ptr::dynamicCast(" << paramName << ")";
+    }
+    else
+    {
+        ostr << paramName;
+    }
+    ostr << "->" << operationName << "(this);";
+    body.push_back(ostr.str());
 
-	return body;
+    return body;
 }
 
 Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport, bool stream) :
@@ -4892,20 +4892,20 @@ Slice::Gen::ObjectVisitor::visitGeneratedOperation(const GeneratedOperationPtr&
 
     if(!p->isAbstract())
     {
-	    H << ";";
+        H << ";";
 
-	    StringList body = p->body();
-	    C << sp;
-	    C << nl << retS << nl << scoped << paramsDecl << nl << "{" << nl;
-	    for(StringList::const_iterator it = body.begin(); it != body.end(); it++)
-	    {
-		    C << *it << nl;
-	    }
-	    C << "}";
+        StringList body = p->body();
+        C << sp;
+        C << nl << retS << nl << scoped << paramsDecl << nl << "{" << nl;
+        for(StringList::const_iterator it = body.begin(); it != body.end(); it++)
+        {
+            C << *it << nl;
+        }
+        C << "}";
     }
     else
     {
-	    H << " = 0;";
+        H << " = 0;";
     }
 }
 

commit be611f4702c0a4b07859f70a323f36883708b118
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Mon Jan 3 06:54:47 2011 -0600

    Allow GeneratedOperation objects to represent abstract operations.

diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h
index 27a4693..d7f957c 100644
--- a/cpp/include/Slice/Parser.h
+++ b/cpp/include/Slice/Parser.h
@@ -614,17 +614,19 @@ public:
     bool sendsClasses() const;
     bool returnsClasses() const;
     bool returnsData() const;
+    bool isAbstract() const;
     StringList body() const;
     virtual std::string kindOf() const;
     virtual void visit(ParserVisitor*, bool);
 
 protected:
 
-    GeneratedOperation(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&);
+    GeneratedOperation(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, bool);
     friend class ClassDef;
 
     TypePtr _returnType;
     StringList _body;
+    bool _abstract;
 };
 
 // ----------------------------------------------------------------------
@@ -645,6 +647,7 @@ public:
     virtual void destroy();
     OperationPtr createOperation(const std::string&, const TypePtr&, Operation::Mode = Operation::Normal);
     GeneratedOperationPtr createGeneratedOperation(const std::string&, const TypePtr&, const StringList&);
+    GeneratedOperationPtr createGeneratedOperation(const std::string&, const TypePtr&);
     DataMemberPtr createDataMember(const std::string&, const TypePtr&, const SyntaxTreeBasePtr&, const std::string&,
                                    const std::string&);
     ClassDeclPtr declaration() const;
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 3257d2f..9f877fa 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -3050,7 +3050,106 @@ Slice::ClassDef::createGeneratedOperation(const string& name,
 #endif
 
     _hasGeneratedOperations = true;
-    GeneratedOperationPtr gop = new GeneratedOperation(this, name, returnType, body);
+    GeneratedOperationPtr gop = new GeneratedOperation(this, name, returnType, body, false);
+    _contents.push_back(gop);
+    return gop;
+}
+
+GeneratedOperationPtr
+Slice::ClassDef::createGeneratedOperation(const string& name,
+					  const TypePtr& returnType)
+{
+    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, StringList(), false);
     _contents.push_back(gop);
     return gop;
 }
@@ -5269,6 +5368,12 @@ Slice::GeneratedOperation::returnsData() const
     return false;
 }
 
+bool
+Slice::GeneratedOperation::isAbstract() const
+{
+	return _abstract;
+}
+
 StringList
 Slice::GeneratedOperation::body() const
 {
@@ -5290,12 +5395,14 @@ Slice::GeneratedOperation::visit(ParserVisitor* visitor, bool)
 Slice::GeneratedOperation::GeneratedOperation(const ContainerPtr& container,
 					      const string& name,
 					      const TypePtr& returnType,
-					      const StringList& body) :
+					      const StringList& body,
+					      bool abstract) :
     SyntaxTreeBase(container->unit()),
     Contained(container, name),
     Container(container->unit()),
     _returnType(returnType),
-    _body(body)
+    _body(body),
+    _abstract(abstract)
 {
     if(_unit->profile() == IceE)
     {
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index ff7680f..49dc716 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -4888,11 +4888,13 @@ Slice::Gen::ObjectVisitor::visitGeneratedOperation(const GeneratedOperationPtr&
 
     H << sp;
     H << nl << deprecateSymbol << "virtual " << retS << ' ' << fixKwd(name) << params
-      << (isConst ? " const" : "") << ";";
+      << (isConst ? " const" : "");
 
-    StringList body = p->body();
-    if(!body.empty())
+    if(!p->isAbstract())
     {
+	    H << ";";
+
+	    StringList body = p->body();
 	    C << sp;
 	    C << nl << retS << nl << scoped << paramsDecl << nl << "{" << nl;
 	    for(StringList::const_iterator it = body.begin(); it != body.end(); it++)
@@ -4901,6 +4903,10 @@ Slice::Gen::ObjectVisitor::visitGeneratedOperation(const GeneratedOperationPtr&
 	    }
 	    C << "}";
     }
+    else
+    {
+	    H << " = 0;";
+    }
 }
 
 void

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


-- 
asterisk-scf/release/ice.git



More information about the asterisk-scf-commits mailing list