You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jb...@apache.org on 2010/06/12 21:35:19 UTC

svn commit: r954061 - in /commons/sandbox/gsoc/2010/scxml-js/trunk: run.sh src/scxml/cgf/SCXMLCompiler.js test/xpathEvaluator.js test/xslt/AbstractStatechartGenerator.xsl test/xslt/StatePatternStatechartGenerator.xsl test/xslt/snippets.txt

Author: jbeard
Date: Sat Jun 12 19:35:18 2010
New Revision: 954061

URL: http://svn.apache.org/viewvc?rev=954061&view=rev
Log:
Code gen works for state pattern with xsl. w00t. But for some reason beautify.js is broken. boo. Next steps are to do some automated unit testing, then to hook up the other backends, then to replace the rest of the e4x, then finally to try it in the browser.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/StatePatternStatechartGenerator.xsl
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh?rev=954061&r1=954060&r2=954061&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh Sat Jun 12 19:35:18 2010
@@ -6,4 +6,4 @@
 
 dn=`dirname $0`
 abspath=`cd $dn; pwd`
-java -cp ./lib/java/js.jar:./lib/java/commons-cli.jar org.mozilla.javascript.tools.shell.Main -debug runner.js $abspath src/scxml/cgf/main $*
+java -cp ./lib/java/js.jar:./lib/java/commons-cli.jar:../lib/java/serializer.jar:../lib/java/xalan.jar:../lib/java/xercesImpl.jar:../lib/java/xml-apis.jar org.mozilla.javascript.tools.shell.Main -debug runner.js $abspath src/scxml/cgf/main $*

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js?rev=954061&r1=954060&r2=954061&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js Sat Jun 12 19:35:18 2010
@@ -30,11 +30,14 @@ require.def("src/scxml/cgf/SCXMLCompiler
 	"src/scxml/cgf/js/SwitchyardStatechartGenerator",
 	"src/scxml/cgf/js/StateTableStatechartGenerator",
 	"src/scxml/cgf/js/StatePatternStatechartGenerator",
+	"src/scxml/cgf/util/file",
 	"lib/js/beautify.js"],
+	
 	function(util,
 		SwitchyardStatechartGenerator,
 		StateTableStatechartGenerator,
-		StatePatternStatechartGenerator){
+		StatePatternStatechartGenerator,
+		fileUtil){
 
 		//set the default xml namespace
 		msdlNs = "http://msdl.cs.mcgill.ca/";
@@ -322,7 +325,7 @@ require.def("src/scxml/cgf/SCXMLCompiler
 					var transitionTarget = conf.allStates.(@id == targetId);
 
 					//we use these funky-looking variables to avoid namespace collisions in the below query
-					var $s = state, $t = transitionTarget;
+					var $s = sourceState, $t = transitionTarget;
 					transition.@doesNotExitParallelRegion = conf.parallelRegions.( 
 								descendants($s.localName()).contains($s) &&
 									descendants($t.localName()).contains($t)).length();
@@ -332,41 +335,36 @@ require.def("src/scxml/cgf/SCXMLCompiler
 						conf.parallelsAndDescendantStates.contains(sourceState) && 
 							!conf.parallelsAndDescendantStates.contains(transitionTarget);
 
-					toReturn = self.genTriggerDispatcherContext(transitionParams,state,transition);
-
 				});
 				
-				
-				self.genStateTriggerDispatcher = function(state,transition){
-					//so, this will vary depending on whether he is a basic state in a non-parallel region, a non-basic state, or a history state. 
-					//so, we do a check, and then delegate to the proper method
-					
-					//we also need to know the lca here.
-					var toReturn;
 
-					var transitionParams = {};
+				//return scxmlRoot;
 
+				//do transforms
+				debugger;
+				importPackage(javax.xml.transform);
+				importPackage(javax.xml.transform.stream);
+				importClass(java.io.StringWriter);
 
-					transitionParams.isInitial = (state.localName() == "initial");
+				var outWriter = new StringWriter();  
 
-					//is he a history state?
-					transitionParams.isHistory = (state.localName() == "history");
-					
-					//conf.statesDescendedFromParallelRegions.contains(transitionTarget))
-					//conf.statesDescendedFromParallelRegions.contains(state) && 
+				//this stuff needs to get seriously cleaned up
 
-					//TODO: get his corresponding parallel region, and check if target state is a descendant of the parallel region
-					//is basic, and is a descendant of a parallel state
+				//write to temp file
+				fileUtil.writeFile(scxmlRoot.toString(),"build/tmp.xml");
 
-					transitionParams.isParallelSubstate = conf.parallelRegions..*.contains(state);
+				var tFactory = TransformerFactory.newInstance();
+				var transformer = tFactory.newTransformer(new StreamSource("./test/xslt/StatePatternStatechartGenerator.xsl"));
+				transformer.transform(new StreamSource("build/tmp.xml"), new StreamResult(outWriter));
+				var transformedJs = outWriter.toString();
 
-					//we use these funky-looking variables to avoid namespace collisions in the below query
-					return toReturn;
+				/*
+				if(options.beautify){
+					transformedJs = js_beautify(transformedJs,{});
 				}
+				*/
 
-
-				return scxmlRoot;
-
+				return transformedJs; 
 
 				/*
 				var generatorConstructor;
@@ -387,10 +385,6 @@ require.def("src/scxml/cgf/SCXMLCompiler
 				var scg = new generatorConstructor(conf);
 				var sc = scg.genStatechart(conf);
 
-				if(options.beautify){
-					sc = js_beautify(sc.toString().replace(/^\s+/, ''),{});
-				}
-
 				//print(conf.scxml);
 				if(options.verbose) print(sc);
 

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js?rev=954061&r1=954060&r2=954061&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xpathEvaluator.js Sat Jun 12 19:35:18 2010
@@ -38,7 +38,9 @@ function isTextNode(n) {
 
 
 var filename = arguments[0];
-var xpath = arguments[1];
+//var xpath = arguments[1];
+var xpath = "//*[(self::state or self::parallel or self::final or self::initial or self::scxml or self::history) and not(.//*[(self::state or self::parallel or self::final or self::initial or self::scxml or self::history)])]"
+//[]
 
 if ((filename != null) && (filename.length > 0)
 	&& (xpath != null) && (xpath.length > 0))

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl?rev=954061&r1=954060&r2=954061&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl Sat Jun 12 19:35:18 2010
@@ -180,13 +180,9 @@
 						this.historyState.lastConfiguration = currentConfiguration.slice();
 					</if>
 
-					}
-				}
-
 					<for-each select="$state/onexit/*">
 						<apply-templates select="s:if | s:raise | s:log | s:script | s:send | s:cancel | s:invoke | s:finalize | s:datamodel | s:data | s:assign | s:validate | s:param"/>
 					</for-each>
-
 				}
 
 				<call-template name="genStateHooks">
@@ -493,14 +489,16 @@
 						console.log("return to last deep configuration");
 					</when>
 					<otherwise>
-						console.log("return to last shallow configuration");')
+						console.log("return to last shallow configuration");
 					</otherwise>
 				</choose>
 			</if>
 					
 				
 			<!--gen executable content for t-->
-			<apply-templates select="$t/*"/>
+			<apply-templates select="$t/*[self::s:if or self::s:raise or self::s:log or self::s:script or self::s:send or self::s:cancel or self::s:invoke or self::s:finalize or self::s:datamodel or self::s:data or self::s:assign or self::s:validate or self::s:param]"/>
+
+
 
 			var historyState = <value-of select="$historyStateReference"/>;
 
@@ -536,7 +534,7 @@
 
 		var statesEntered = [<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>]; 
 
-		for(var parent = {<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>.parent; 
+		for(var parent = <value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>.parent; 
 			parent != historyState.parent &amp;&amp; parent != null; 
 			parent = parent.parent){
 			statesEntered.push(parent);
@@ -600,7 +598,7 @@
 		</choose>
 
 		//transition action
-		<apply-templates select="$t/*"/>
+		<apply-templates select="$t/*[self::s:if or self::s:raise or self::s:log or self::s:script or self::s:send or self::s:cancel or self::s:invoke or self::s:finalize or self::s:datamodel or self::s:data or self::s:assign or self::s:validate or self::s:param]"/>
 
 		//enter states
 		<for-each select="$t/c:targets/c:target/c:enterpath/c:state"> 

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/StatePatternStatechartGenerator.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/StatePatternStatechartGenerator.xsl?rev=954061&r1=954060&r2=954061&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/StatePatternStatechartGenerator.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/StatePatternStatechartGenerator.xsl Sat Jun 12 19:35:18 2010
@@ -38,6 +38,9 @@
 	</template>
 
 	<template name="genParallelSubstateConfigurationSetString">
+		<param name="s"/>
+		<param name="t"/>
+
 		currentConfiguration.splice(currentConfiguration.indexOf(this),1,
 			<for-each select="$t/c:targets/c:target/c:targetState">
 				<value-of select="."/>

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt?rev=954061&r1=954060&r2=954061&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt Sat Jun 12 19:35:18 2010
@@ -4,3 +4,72 @@
 					</call-template>
 				</for-each>
 
+
+				self.genIfNode = function(ifNode){
+
+					var toReturn = "";
+
+					//break him up into partitions
+					var ifBlock = {
+						cond : ifNode.@cond,
+						statements : []
+					};
+					var elseIfBlocks = [];
+					var elseBlock = null;
+
+					var ifNodeChildren = ifNode.children();
+
+					var currentPartition = ifBlock;
+					
+					for(var i = 0; i < ifNodeChildren.length(); i++){
+						var node = ifNodeChildren[i];
+
+						switch(node.localName()){
+							case "elseif":
+								currentPartition = {
+									cond : node.@cond,
+									statements : []
+								};
+								elseIfBlocks.push(currentPartition); 
+								break;
+							case "else":
+								currentPartition = {
+									cond : node.@cond,
+									statements : []
+								};
+								elseBlock.push(currentPartition); 
+								break;
+							default:
+								currentPartition.statements.push(node);
+						}
+					} 
+
+					function genIfBlockCode(type,block){
+						return <>
+							{type} ({block.cond}) &#x7B;
+								{block.statements.map(self.genExecutableContent).join("\n")} 
+							&#x7D;
+						</>
+
+					}
+
+					toReturn += genIfBlockCode("if",ifBlock);
+					toReturn += elseIfBlocks.map(function(elseIfBlock){
+							return genIfBlockCode("else if",elseIfBlock);
+					}); 
+					if(elseBlock){
+						toReturn += genIfBlockCode("else",elseBlock);
+					}
+	
+					return toReturn;
+				}
+
+				//private and not changable by subclasses
+				self.computeDepth = function(state){
+					var depthToReturn = 0;
+					var currentNode = state;
+					while(currentNode = currentNode.parent()){
+						depthToReturn++;
+					}
+					return depthToReturn;
+				}