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:34:57 UTC
svn commit: r954058 - in /commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt:
AbstractStatechartGenerator.xsl StatePatternStatechartGenerator.xsl
Author: jbeard
Date: Sat Jun 12 19:34:57 2010
New Revision: 954058
URL: http://svn.apache.org/viewvc?rev=954058&view=rev
Log:
Intermediate commit. May be done porting state pattern generator to xsl.
Modified:
commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl
commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/StatePatternStatechartGenerator.xsl
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=954058&r1=954057&r2=954058&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:34:57 2010
@@ -14,7 +14,7 @@
<param name="dispatchInvocation"/>
<param name="currentConfigurationExpression"/>
<param name="defaultEventLiteral"/>
-
+ <!-- TODO: refactor these names-->
<param name="genHistoryTriggerDispatcherCurrentConfigurationAssignmentRHS"/>
<param name="genHistoryTriggerDispatcherInnerForEachStateReference"/>
<param name="genNonBasicTriggerDispatcherExitBlockIteratorExpression"/>
@@ -439,6 +439,197 @@
//end static boilerplate code
</template>
+
+ <variable name="deepHistoryEnterAction">
+ <text>
+ var topState;
+ while(topState = statesEntered.pop()){
+ topState.enterAction();
+ }
+ </text>
+ </template>
+
+ <variable name="shallowHistoryEnterAction">
+ <text>
+ var topState = statesEntered.pop();
+
+ topState.enterAction();
+
+ newConfiguration.push(topState.initial ? topState.initial : topState );
+ </text>
+ </template>
+
+ <variable name="genNonBasicTriggerDispatcherExitBlockInnerForEach">
+ <text>
+ {
+ do{
+ statesExited.push(state);
+ }while((state = state.parent) &&
+ state != lca &&
+ statesExited.indexOf(state) == -1)
+ }
+ </text>
+ </variable>
+
+ <template name="genHistoryTriggerDispatcher">
+ <param name="s"/>
+ <param name="t"/>
+
+ <variable name="isDeep" select="$s/@type = 'deep'"/>
+ <variable name="historyStateReference">
+ <call-template name="genHistoryTriggerDispatcherHistoryStateReference">
+ <with-param name="s" select="$s"/>
+ </call-template>
+ </variable>
+
+
+ //history state semantics
+ if(<value-of select="$historyStateReference"/>.lastConfiguration){
+
+ //transition action
+ <if test="$log">
+ <choose>
+ <when test="$isDeep">
+ console.log("return to last deep configuration");
+ </when>
+ <otherwise>
+ console.log("return to last shallow configuration");')
+ </otherwise>
+ </choose>
+
+
+ <!--gen executable content for t-->
+ <apply-templates select="$t/*"/>
+
+ var historyState = <value-of select="$historyStateReference"/>;
+
+ <if test="isDeep">
+ var newConfiguration = [];
+ </if>
+
+ <value-of select="$historyStateReference"/>.lastConfiguration.forEach(function(state){
+ <call-template name="genHistoryTriggerDispatcherInnerForEach">
+ <with-param name="isDeep" select="$isDeep"/>
+ </call-template>
+ });
+
+ <choose>
+ <when test="$isDeep">
+ currentConfiguration = <value-of select="$historyStateReference"/>.lastConfiguration.slice();
+ </when>
+ <otherwise>
+ currentConfiguration = <value-of select="$genHistoryTriggerDispatcherCurrentConfigurationAssignmentRHS"/>;
+ </otherwise>
+ </choose>
+
+ }else{
+ <call-template name="genTriggerDispatcherContents">
+ <with-param name="s" select="$s"/>
+ <with-param name="t" select="$t"/>
+ </call-template>
+ }
+ }
+
+ <template name="genHistoryTriggerDispatcherInnerForEach">
+ <param name="isDeep"/>
+
+ var statesEntered = [<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>];
+
+ for(var parent = {<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>.parent;
+ parent != historyState.parent && parent != null;
+ parent = parent.parent){
+ statesEntered.push(parent);
+ }
+
+
+ <choose>
+ <when test="$isDeep">
+ <value-of select="$deepHistoryEnterAction"/>
+ </when>
+ <otherwise>
+ <value-of select="$shallowHistoryEnterAction"/>
+ </otherwise>
+ </choose>
+ </template>
+
+ <template name="genNonBasicTriggerDispatcherExitBlock">
+ <param name="t"/>
+
+ var statesExited = [];
+ var lca = {t.msdl::lca.text()};
+
+ <value-of select="$genNonBasicTriggerDispatcherExitBlockIteratorExpression"/>.forEach(function(state){
+ <value-of select="$genNonBasicTriggerDispatcherExitBlockInnerForEach"/>
+ });
+
+ //sort by depth
+ statesExited.sort(sortByDepthDeepToShallow);
+
+ //execute actions for each of these states
+ statesExited.forEach(function(state){
+ state.exitAction();
+ });
+ </template>
+
+ <template name="genTriggerDispatcherContents">
+ <param name="s"/>
+ <param name="t"/>
+
+ <if test="not($t/@event)>
+ hasTakenDefaultTransition = true;
+ </if>
+
+
+ //exit states
+
+ <choose>
+ <when test="local-name($s) = 'initial' or local-name($s) = 'history' or
+ ( $s/@isBasic and
+ ( not($s/@isParallelSubstate) or
+ $s/@isParallelSubstateAndTransitionDoesNotExitParallelRegion))">
+ <for-each select="$t/c:exitpath/c:state">
+ <value-of select="."/>.exitAction();
+ </for-each>
+ </when>
+ <otherwise>
+ <call-template name="genNonBasicTriggerDispatcherExitBlock">
+ <param name="t" select="$t"/>
+ </call-template>
+ </otherwise>
+ </choose>
+
+ //transition action
+ <apply-templates select="$t/*"/>
+
+ //enter states
+ <for-each select="$t/c:targets/c:target/c:enterpath/c:state">
+ <value-of select="."/>.enterAction();
+ </for-each>
+
+ //update configuration
+ <choose>
+ <when test="$s/@isParallelSubstateAndTransitionDoesNotExitParallelRegion">
+ <call-template name="genParallelSubstateConfigurationSetString">
+ <with-param name="s" select="$s"/>
+ <with-param name="t" select="$t"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <call-template name="genNonParallelSubstateConfigurationSetString">
+ <with-param name="s" select="$s"/>
+ <with-param name="t" select="$t"/>
+ </call-template>
+ </otherwise>
+ </choose>
+
+
+ //set whether preempted
+ <if test="$t/@isPreempted">
+ isPreempted = true;
+ </if>
+ </template>
+
+
<template name="genContextHooks"/>
<template name="genStateHooks"/>
<template name="genExternalTriggerDispatcher"/>
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=954058&r1=954057&r2=954058&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:34:57 2010
@@ -18,9 +18,9 @@
<template name="genStateHooks">
<param name="state"/>
<for-each select="$state/s:transition">
- <call-template name="genStateTriggerDispatcher">
- <with-param name="state" select="$state"/>
- <with-param name="transition" select="."/>
+ <call-template name="genTriggerDispatcherContext">
+ <with-param name="s" select="$state"/>
+ <with-param name="t" select="."/>
</call-template>
</for-each>
</template>