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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Jan 6 22:22:32 UTC 2011


branch "master" has been updated
       via  d94bbeb493eff3ab76ec63a233c9960935492f15 (commit)
      from  6db266d8b484f5bc4562f8d091065b56fb71a900 (commit)

Summary of changes:
 src/SliceVisitorPattern.cpp |   75 ++++++++++++++++++++++++++++++++----------
 1 files changed, 57 insertions(+), 18 deletions(-)


- Log -----------------------------------------------------------------
commit d94bbeb493eff3ab76ec63a233c9960935492f15
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Thu Jan 6 16:21:59 2011 -0600

    Add support for Python (which required knowing how to generate an
    'empty' function body).
    
    Change some names to be consistent with names in the Ice code.

diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 0114368..86b245b 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -46,6 +46,7 @@ protected:
 	// The function returns a StringList; each string in the list will be placed into the
 	// function body in a language-appropriate manner.
 	virtual StringList generateVisitFunctionBody(const string&, const ClassDefPtr&, const ClassDefPtr&, const string&) = 0;
+	virtual StringList generateEmptyFunctionBody() = 0;
 
 private:
 	// This map contains the list of classes known to be visitors;
@@ -163,11 +164,7 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
 					// won't actually produce output for the include file.
 					if(derivedVisitor->includeLevel() == 0)
 					{
-						// 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);
+						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
@@ -213,11 +210,7 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
 		{
 			if(derivedVisitor->includeLevel() == 0)
 			{
-				// 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);
+				GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, generateEmptyFunctionBody());
 				gop->createParamDecl("item", p->declaration(), false);
 			}
 			if(p->includeLevel() == 0)
@@ -251,10 +244,10 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
 	return false;
 }
 
-class ICE_DECLSPEC_EXPORT CPPVisitor : public VisitorPatternVisitor
+class ICE_DECLSPEC_EXPORT CPlusPlusVisitor : public VisitorPatternVisitor
 {
 public:
-	CPPVisitor()
+	CPlusPlusVisitor()
 	{
 		_useWstring.push(0);
 	}
@@ -306,6 +299,7 @@ public:
 
 protected:
         StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+	StringList generateEmptyFunctionBody();
 
 private:
 	stack<int> _useWstring;
@@ -333,26 +327,29 @@ private:
 	}
 };
 
-class ICE_DECLSPEC_EXPORT CSVisitor : public VisitorPatternVisitor
+class ICE_DECLSPEC_EXPORT CsVisitor : public VisitorPatternVisitor
 {
 protected:
         StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+	StringList generateEmptyFunctionBody();
 };
 
 class ICE_DECLSPEC_EXPORT JavaVisitor : public VisitorPatternVisitor
 {
 protected:
         StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+	StringList generateEmptyFunctionBody();
 };
 
 class ICE_DECLSPEC_EXPORT PythonVisitor : public VisitorPatternVisitor
 {
 protected:
         StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+	StringList generateEmptyFunctionBody();
 };
 
 StringList
-CPPVisitor::generateVisitFunctionBody(const string& paramName,
+CPlusPlusVisitor::generateVisitFunctionBody(const string& paramName,
 				      const ClassDefPtr& baseVisitor,
 				      const ClassDefPtr& derivedVisitor,
 				      const string& operationName)
@@ -387,6 +384,15 @@ CPPVisitor::generateVisitFunctionBody(const string& paramName,
 }
 
 StringList
+CPlusPlusVisitor::generateEmptyFunctionBody()
+{
+	StringList body;
+
+	body.push_back("");
+	return body;
+}
+
+StringList
 JavaVisitor::generateVisitFunctionBody(const string& paramName,
 				       const ClassDefPtr& baseVisitor,
 				       const ClassDefPtr& derivedVisitor,
@@ -415,7 +421,16 @@ JavaVisitor::generateVisitFunctionBody(const string& paramName,
 }
 
 StringList
-CSVisitor::generateVisitFunctionBody(const string& paramName,
+JavaVisitor::generateEmptyFunctionBody()
+{
+	StringList body;
+
+	body.push_back("");
+	return body;
+}
+
+StringList
+CsVisitor::generateVisitFunctionBody(const string& paramName,
 				     const ClassDefPtr& baseVisitor,
 				     const ClassDefPtr& derivedVisitor,
 				     const string& operationName)
@@ -442,12 +457,36 @@ CSVisitor::generateVisitFunctionBody(const string& paramName,
 }
 
 StringList
+CsVisitor::generateEmptyFunctionBody()
+{
+	StringList body;
+
+	body.push_back("");
+	return body;
+}
+
+StringList
 PythonVisitor::generateVisitFunctionBody(const string& paramName,
 					 const ClassDefPtr& baseVisitor,
 					 const ClassDefPtr& derivedVisitor,
 					 const string& operationName)
 {
-	return StringList();
+    ostringstream ostr;
+    StringList body;
+
+    ostr << paramName << "." << operationName << "(self);";
+    body.push_back(ostr.str());
+
+    return body;
+}
+
+StringList
+PythonVisitor::generateEmptyFunctionBody()
+{
+	StringList body;
+
+	body.push_back("pass");
+	return body;
 }
 
 extern "C"
@@ -459,10 +498,10 @@ extern "C"
 		switch(language)
 		{
 		case LanguageCPlusPlus:
-			result->push_back(new CPPVisitor());
+			result->push_back(new CPlusPlusVisitor());
 			break;
 		case LanguageCs:
-			result->push_back(new CSVisitor());
+			result->push_back(new CsVisitor());
 			break;
 		case LanguageJava:
 			result->push_back(new JavaVisitor());

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


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



More information about the asterisk-scf-commits mailing list