[asterisk-scf-commits] asterisk-scf/release/slice-plugins.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Mar 11 17:53:22 CST 2011


branch "master" has been updated
       via  7d5aafa84a46257cd2358d84d17df52de2c0a51f (commit)
       via  f6da9883fe4b93b17a609ff7fc92336b601f186b (commit)
       via  107a1a964b3ba8a6780e2ee9b8fb48792de6c980 (commit)
       via  64a412631cc7eb8f62a434885374290e7328f347 (commit)
      from  7fcd8cfe5cd559fe63d98ee97f1c801558149ded (commit)

Summary of changes:
 src/SliceVisitorPattern.cpp |  169 ++++++++++++++++++++++---------------------
 1 files changed, 87 insertions(+), 82 deletions(-)


- Log -----------------------------------------------------------------
commit 7d5aafa84a46257cd2358d84d17df52de2c0a51f
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Mar 11 17:52:07 2011 -0600

    Do not rely on the abstract-ness of classes when deciding whether to search
    for visitable bases or visiting bases; just search for a visitable base, if
    one is found then the process is complete. If one is not found, search
    for a visiting base and handle it if found. A class will never be both a
    visitor and visitable, so there is no need to distinguish between them.

diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 3a43c01..36e9b7b 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -228,44 +228,38 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
 		return false;
 	}
 
-	// For concrete classes that aren't marked with the 'visitor' metadata,
+	// For classes that aren't marked with the 'visitor' metadata,
 	// try to locate a visitable base class that they extend; if one is found,
 	// generate the appropriate operations to support the visitable class.
-	if(!p->isAbstract())
+	ClassDefPtr baseVisitor, derivedVisitor;
+	if (findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor))
 	{
-		ClassDefPtr baseVisitor, derivedVisitor;
-		if (findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor))
+		if(derivedVisitor->includeLevel() == 0)
 		{
-			if(derivedVisitor->includeLevel() == 0)
-			{
-				GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, generateEmptyFunctionBody());
-				gop->createParamDecl("item", p->declaration(), false);
-			}
-			if(p->includeLevel() == 0)
-			{
-				GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
-											generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
-				gop->setOverride(true);
-				gop->createParamDecl("visitor", baseVisitor->declaration(), false);
-			}
+			GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, generateEmptyFunctionBody());
+			gop->createParamDecl("item", p->declaration(), false);
+		}
+		if(p->includeLevel() == 0)
+		{
+			GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
+										generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
+			gop->setOverride(true);
+			gop->createParamDecl("visitor", baseVisitor->declaration(), false);
 		}
 		return false;
 	}
 
-	// For abstract classes that aren't marked with 'visitor' metadata,
+	// For classes that aren't marked with 'visitor' metadata,
 	// try to locate a visiting base class that they extend; if one is found,
 	// remember the derived class as a visiting class.
-	if(p->isAbstract())
+	ClassList bases = p->allBases();
+	for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
 	{
-		ClassList bases = p->allBases();
-		for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
+		map<string, ClassDefPtr>::const_iterator it = _visitorClasses.find((*q)->scoped());
+		if(it != _visitorClasses.end())
 		{
-			map<string, ClassDefPtr>::const_iterator it = _visitorClasses.find((*q)->scoped());
-			if(it != _visitorClasses.end())
-			{
-				_visitorClasses[p->scoped()] = p;
-				return false;
-			}
+			_visitorClasses[p->scoped()] = p;
+			return false;
 		}
 	}
 

commit f6da9883fe4b93b17a609ff7fc92336b601f186b
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Mar 11 17:51:48 2011 -0600

    Eliminate an unnecessary level of indentation.

diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index f3960d4..3a43c01 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -162,64 +162,62 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
 				emitWarning(p->file(), p->line(), ostr.str());
 				return false;
 			}
-			else
+
+			// Attempt to find the specified visiting class in the list of known
+			// visiting classes.
+			const string visitor = (*q).substr(8);
+			map<string, ClassDefPtr>::const_iterator it = _visitorClasses.find(visitor);
+			// If it wasn't found, try prefixing it with the container that this class
+			// is located in
+			if(it == _visitorClasses.end())
+			{
+				it = _visitorClasses.find(p->container()->thisScope() + visitor);
+			}
+			if(it != _visitorClasses.end())
 			{
-				// Attempt to find the specified visiting class in the list of known
-				// visiting classes.
-				const string visitor = (*q).substr(8);
-				map<string, ClassDefPtr>::const_iterator it = _visitorClasses.find(visitor);
-				// If it wasn't found, try prefixing it with the container that this class
-				// is located in
-				if(it == _visitorClasses.end())
+				// Initially, assume the base visitor class will be the specified class.
+				ClassDefPtr baseVisitor = it->second, derivedVisitor;
+				// Note that the return value of this function is ignored; because this
+				// class has been directly marked with the 'visitor' metadata, we already
+				// know it must support a visitor; the function is being called
+				// to determine if there is a different base visitor class that must be
+				// supported.
+				findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
+				// We know our derived visitor class is the one specified in the directive.
+				derivedVisitor = it->second;
+				// Remember this class as a visitable base, so that any classes that extend
+				// it will automatically be visitable as well.
+				_visitableBases[p->scoped()] = make_pair(baseVisitor, derivedVisitor);
+				// There is no need to actually generate operations into the visitor
+				// class if it was defined in an include file, since the translator
+				// won't actually produce output for the include file.
+				if(derivedVisitor->includeLevel() == 0)
 				{
-					it = _visitorClasses.find(p->container()->thisScope() + visitor);
+					GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, generateEmptyFunctionBody());
+					gop->createParamDecl("item", p->declaration(), false);
 				}
-				if(it != _visitorClasses.end())
+				// There is no need to actually generate operations into the visited
+				// class if it was defined in an include file, since the translator
+				// won't actually produce output for the include file.
+				if(p->includeLevel() == 0)
 				{
-					// Initially, assume the base visitor class will be the specified class.
-					ClassDefPtr baseVisitor = it->second, derivedVisitor;
-					// Note that the return value of this function is ignored; because this
-					// class has been directly marked with the 'visitor' metadata, we already
-					// know it must support a visitor; the function is being called
-					// to determine if there is a different base visitor class that must be
-					// supported.
-					findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
-					// We know our derived visitor class is the one specified in the directive.
-					derivedVisitor = it->second;
-					// Remember this class as a visitable base, so that any classes that extend
-					// it will automatically be visitable as well.
-					_visitableBases[p->scoped()] = make_pair(baseVisitor, derivedVisitor);
-					// There is no need to actually generate operations into the visitor
-					// class if it was defined in an include file, since the translator
-					// won't actually produce output for the include file.
-					if(derivedVisitor->includeLevel() == 0)
-					{
-						GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, generateEmptyFunctionBody());
-						gop->createParamDecl("item", p->declaration(), false);
-					}
-					// There is no need to actually generate operations into the visited
-					// class if it was defined in an include file, since the translator
-					// won't actually produce output for the include file.
-					if(p->includeLevel() == 0)
+					GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
+												generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
+					if(baseVisitor != derivedVisitor)
 					{
-						GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
-													generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
-						if(baseVisitor != derivedVisitor)
-						{
-							gop->setOverride(true);
-						}
-						gop->createParamDecl("visitor", baseVisitor->declaration(), false);
+						gop->setOverride(true);
 					}
-					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());
-					return false;
+					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());
+				return false;
 			}
 		}
 	}

commit 107a1a964b3ba8a6780e2ee9b8fb48792de6c980
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Mar 11 17:50:35 2011 -0600

    Emit a warning when 'visitor' metadata is applied to a class which extends
    a class that is already known to be a visitor; this is not necessary and
    could potentially cause the plugin to generate incorrect code in the
    future.

diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 36af4a3..f3960d4 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -126,12 +126,25 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
 				emitWarning(p->file(), p->line(), ostr.str());
 				return false;
 			}
-			else
+			else if(!p->bases().empty())
 			{
-				// Remember this class as a visiting class.
-				_visitorClasses[p->scoped()] = p;
-				return false;
+				ClassList bases = p->bases();
+				for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
+				{
+					if(_visitorClasses.find((*q)->scoped()) != _visitorClasses.end())
+					{
+						ostr << "ignoring invalid metadata `visitor`: directive applied"
+						     << "to " << p->name() << " but it inherits from " << (*q)->name()
+						     << " which is already a visitor";
+						emitWarning(p->file(), p->line(), ostr.str());
+						break;
+					}
+				}
 			}
+
+			// Remember this class as a visiting class.
+			_visitorClasses[p->scoped()] = p;
+			return false;
 		}
 		else if(q->find("visitor:", 0) == 0)
 		{

commit 64a412631cc7eb8f62a434885374290e7328f347
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Mar 11 17:38:46 2011 -0600

    When searching for a visitable base class of a class, only look at its
    immediate bases, not all of its bases. If any of its bases are visitable,
    at least one of its immediate bases will be too, and by searching this way
    we'll be sure to find the *most* derived visitable base of the class in
    question, not one farther up the tree.

diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 2998f04..36af4a3 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -85,7 +85,7 @@ findVisitableBase(const map<string, pair<ClassDefPtr, ClassDefPtr> >& visitableB
 		  const ClassDefPtr& p, ClassDefPtr& baseVisitor,
 		  ClassDefPtr& derivedVisitor)
 {
-	ClassList bases = p->allBases();
+	ClassList bases = p->bases();
 	for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
 	{
 		map<string, pair<ClassDefPtr, ClassDefPtr> >::const_iterator it = visitableBases.find((*q)->scoped());

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


-- 
asterisk-scf/release/slice-plugins.git



More information about the asterisk-scf-commits mailing list