Author: jbeard
Date: Thu Jun 24 21:17:03 2010
New Revision: 957716
URL: http://svn.apache.org/viewvc?rev=957716&view=rev
Log:
Started working on JIRA task SCXML-137, and subtasks SCXML-138 and SCXML-139,
implementing functionality missing from the core module. This commit does not
break previous tests, but the new functionality it provides has not been tested.
Modified:
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/.gitignore
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/AbstractStatechartGenerator.xsl
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator.xsl
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/test/test_with_xsltproc.sh
Modified:
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/.gitignore
URL:
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/.gitignore?rev=957716&r1=957715&r2=957716&view=diff
==============================================================================
---
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/.gitignore
(original)
+++
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/.gitignore
Thu Jun 24 21:17:03 2010
@@ -14,3 +14,4 @@ build_dbg.sh
tmp*
Session.vim
*.bak
+test/out.js
Modified:
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js
URL:
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js?rev=957716&r1=957715&r2=957716&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js
Thu Jun 24 21:17:03 2010
@@ -55,14 +55,15 @@ require.def("build",
//enums
//we keep backward links of these
var backends = {
- "switch" : true,
- "table" : true,
+ //"switch" : true,
+ //"table" : true,
"state" : true
}
var browsers = {
"FF" : { host:"localhost", port:4444,
browser:"*firefox" , ie:false},
- "Safari" : { host:"localhost", port:4444,
browser:"*safari" , ie: false},
+ //FIXME: latest Safari seems to hang on Windows
now under selenium
+ //"Safari" : { host:"localhost", port:4444,
browser:"*safari" , ie: false},
//FIXME: selenium is unhappy with opera
//"Opera" : { host:"localhost", port:4444,
browser:"*opera" , ie: false},
"IE" : { host:"localhost", port:4444,
browser:"*iexplore", ie:true },
Modified:
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/AbstractStatechartGenerator.xsl
URL:
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/AbstractStatechartGenerator.xsl?rev=957716&r1=957715&r2=957716&view=diff
==============================================================================
---
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/AbstractStatechartGenerator.xsl
(original)
+++
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/AbstractStatechartGenerator.xsl
Thu Jun 24 21:17:03 2010
@@ -59,6 +59,8 @@
<variable name="nonDefaultTransitions" select="//s:transiti...@event]"/>
-->
+ <variable name="abstractStateName" select="'AbstractState'"/>
+
<template match="/s:scxml">
<if test="$noIndexOf">
@@ -124,7 +126,7 @@
<template name="genAbstractState">
<param name="events"/>
- var AbstractState = new function(){
+ var <value-of select="$abstractStateName"/> = new function(){
//triggers are methods
<for-each select="$events">
@@ -142,16 +144,16 @@
<variable name="parentName">
<choose>
- <!-- FIXME: probably want to refine this query,
as we may not be able to assume that all states have ids?-->
<when test="$state/../@id">
<value-of select="$state/../@id"/>
</when>
<otherwise>
- <value-of select="'AbstractState'"/>
+ <value-of select="$abstractStateName"/>
</otherwise>
</choose>
</variable>
+
<variable name="historyState" select="$state/s:history"/>
<variable name="constructorFunctionName"
select="concat($stateName,'Constructor')"/>
@@ -575,7 +577,30 @@
<template name="genTriggerDispatcherContents">
<param name="s"/>
<param name="t"/>
-
+
+ <!-- conditionally wrap contents in an if block for the guard
condition -->
+ <choose>
+ <when test="$t/@cond">
+ if(<value-of select="$t/@cond"/>){
+ <call-template
name="genTriggerDispatcherInnerContents">
+ <with-param name="s"
select="$s"/>
+ <with-param name="t"
select="$t"/>
+ </call-template>
+ }
+ </when>
+ <otherwise>
+ <call-template
name="genTriggerDispatcherInnerContents">
+ <with-param name="s" select="$s"/>
+ <with-param name="t" select="$t"/>
+ </call-template>
+ </otherwise>
+ </choose>
+ </template>
+
+ <template name="genTriggerDispatcherInnerContents">
+ <param name="s"/>
+ <param name="t"/>
+
<if test="not($t/@event)">
hasTakenDefaultTransition = true;
</if>
@@ -628,6 +653,8 @@
<if test="$t/@c:isPreempted">
isPreempted = true;
</if>
+
+ return;
</template>
<template name="genNoForEachArrayPrototypeExtension">
Modified:
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator.xsl
URL:
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator.xsl?rev=957716&r1=957715&r2=957716&view=diff
==============================================================================
---
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator.xsl
(original)
+++
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator.xsl
Thu Jun 24 21:17:03 2010
@@ -33,12 +33,33 @@
<template name="genStateHooks">
<param name="state"/>
- <for-each select="$state/s:transition">
+
+ <!-- iterate through groups of transitions, grouped by event -->
+ <!--FIXME: this is likely to be a bit slow, as we're iterating
through all events -->
+ <for-each select="$eventsEnum/c:name">
+ <variable name="eventName">
+ <value-of select="."/>
+ </variable>
+
+ <variable name="transitionsForEvent"
select="$state/s:transiti...@event = $eventName]"/>
+ <if test="$transitionsForEvent">
+ <call-template
name="genTriggerDispatcherContext">
+ <with-param name="s" select="$state"/>
+ <with-param name="transitions"
select="$transitionsForEvent"/>
+ <with-param name="eventName"
select="$eventName"/>
+ </call-template>
+ </if>
+ </for-each>
+
+ <!-- now do default transitions -->
+ <variable name="defaultTransitionsForState"
select="$state/s:transition[not(@event)]"/>
+ <if test="$defaultTransitionsForState">
<call-template name="genTriggerDispatcherContext">
<with-param name="s" select="$state"/>
- <with-param name="t" select="."/>
+ <with-param name="transitions"
select="$defaultTransitionsForState"/>
+ <with-param name="eventName"
select="'$default'"/>
</call-template>
- </for-each>
+ </if>
</template>
<template name="genExternalTriggerDispatcher">
@@ -93,34 +114,42 @@
<template name="genTriggerDispatcherContext">
<param name="s"/>
- <param name="t"/>
-
- <variable name="eventName">
- <choose>
- <when test="$t/@event">
- <value-of select="$t/@event"/>
- </when>
- <otherwise>
- <value-of select="'$default'"/>
- </otherwise>
- </choose>
- </variable>
+ <param name="transitions"/>
+ <param name="eventName"/>
this.<value-of select="$eventName"/> = function(){
<choose>
<when test="local-name($s) = 'history'">
<call-template
name="genHistoryTriggerDispatcher">
<with-param name="s"
select="$s"/>
- <with-param name="t"
select="$t"/>
+ <with-param name="t"
select="$transitions[1]"/>
</call-template>
</when>
<otherwise>
- <call-template
name="genTriggerDispatcherContents">
- <with-param name="s"
select="$s"/>
- <with-param name="t"
select="$t"/>
- </call-template>
+ <for-each select="$transitions">
+ <call-template
name="genTriggerDispatcherContents">
+ <with-param name="s"
select="$s"/>
+ <with-param name="t"
select="."/>
+ </call-template>
+ </for-each>
</otherwise>
</choose>
+
+ <!-- if by this point he hasn't returned, then none of
the transitions passed,
+ and we need to pass the transition up the
hierarchy chain -->
+
+ <variable name="parentName">
+ <choose>
+ <when test="$s/../@id">
+ <value-of select="$s/../@id"/>
+ </when>
+ <otherwise>
+ <value-of
select="$abstractStateName"/>
+ </otherwise>
+ </choose>
+ </variable>
+
+ <value-of select="$parentName"/>['<value-of
select="$eventName"/>']();
}
</template>
Modified:
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl
URL:
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl?rev=957716&r1=957715&r2=957716&view=diff
==============================================================================
---
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl
(original)
+++
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl
Thu Jun 24 21:17:03 2010
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
+<?xml version="1.0" encoding="UTF-8"?><!--
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -14,29 +13,21 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
---><stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:c="urn://scxml-js" xmlns:s="http://www.w3.org/2005/07/scxml">
- <output method="text"/>
- <param name="log" select="true()"/>
- <param name="noIndexOf" select="false()"/>
- <param name="noMap" select="false()"/>
- <param name="noForEach" select="false()"/>
- <param name="name"/>
- <variable name="allStates" select="//*[(self::s:state or self::s:parallel or
self::s:final or self::s:initial or self::s:scxml or self::s:history)]"/>
- <variable name="states" select="//s:state"/>
- <variable name="transitions" select="//s:transition"/>
- <variable name="basicStates" select="$allStates[not(.//*[(self::s:state or
self::s:parallel or self::s:final or self::s:initial or self::s:scxml or
self::s:history)])]"/>
- <variable name="compositeStates" select="$allStates[.//*[(self::s:state or
self::s:parallel or self::s:final or self::s:initial or self::s:scxml or
self::s:history)]]"/>
- <variable name="eventsEnum" select="/s:scxml/c:eventsEnum/c:event"/>
- <template match="/s:scxml">
- <if test="$noIndexOf">
- <call-template name="genNoIndexOfArrayPrototypeExtension"/>
- </if>
- <if test="$noMap">
- <call-template name="genNoMapArrayPrototypeExtension"/>
- </if>
- <if test="$noForEach">
- <call-template name="genNoForEachArrayPrototypeExtension"/>
- </if>
+--><stylesheet xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://www.w3.org/2005/07/scxml" xmlns:c="urn://scxml-js"
version="1.0">
+
+ <output method="text"/><param name="log" select="true()"/><param
name="noIndexOf" select="false()"/><param name="noMap" select="false()"/><param
name="noForEach" select="false()"/><param name="name"/><variable
name="allStates" select="//*[(self::s:state or self::s:parallel or
self::s:final or self::s:initial or self::s:scxml or
self::s:history)]"/><variable name="states" select="//s:state"/><variable
name="transitions" select="//s:transition"/><variable name="basicStates"
select="$allStates[not(.//*[(self::s:state or self::s:parallel or self::s:final
or self::s:initial or self::s:scxml or self::s:history)])]"/><variable
name="compositeStates" select="$allStates[.//*[(self::s:state or
self::s:parallel or self::s:final or self::s:initial or self::s:scxml or
self::s:history)]]"/><variable name="eventsEnum"
select="/s:scxml/c:eventsEnum/c:event"/><variable name="abstractStateName"
select="'AbstractState'"/><template match="/s:scxml">
+
+ <if test="$noIndexOf">
+ <call-template
name="genNoIndexOfArrayPrototypeExtension"/>
+ </if>
+
+ <if test="$noMap">
+ <call-template name="genNoMapArrayPrototypeExtension"/>
+ </if>
+
+ <if test="$noForEach">
+ <call-template
name="genNoForEachArrayPrototypeExtension"/>
+ </if>
function <value-of select="$name"/>StatechartExecutionContext(){
@@ -44,17 +35,31 @@
//abstract state
- <call-template
name="genAbstractState"><with-param name="events"
select="$eventsEnum"/></call-template>
+ <call-template name="genAbstractState">
+ <with-param name="events"
select="$eventsEnum"/>
+ </call-template>
//states
- <for-each select="$allStates"><call-template
name="genState"><with-param name="state" select="."/></call-template></for-each>
+ <for-each select="$allStates">
+ <call-template name="genState">
+ <with-param name="state"
select="."/>
+ </call-template>
+ </for-each>
//states enum for glass-box unit testing
- <call-template name="genStatesEnum"><with-param
name="states" select="$basicStates"/></call-template>
+ <call-template name="genStatesEnum">
+ <with-param name="states"
select="$basicStates"/>
+ </call-template>
//trigger methods for synchronous interaction
- <for-each select="$eventsEnum"><call-template
name="genExternalTriggerDispatcher"><with-param name="event"
select="."/></call-template></for-each><call-template name="genContextHooks"/>
+ <for-each select="$eventsEnum">
+ <call-template
name="genExternalTriggerDispatcher">
+ <with-param name="event"
select="."/>
+ </call-template>
+ </for-each>
+
+ <call-template name="genContextHooks"/>
//initialization script
<value-of select="s:script"/>
@@ -70,11 +75,10 @@
}
- </template>
- <template name="genAbstractState">
- <param name="events"/>
+ </template><template name="genAbstractState">
+ <param name="events"/>
- var AbstractState = new function(){
+ var <value-of select="$abstractStateName"/> = new function(){
//triggers are methods
<for-each select="$events">
@@ -83,23 +87,26 @@
this.$default = function(){};
}
- </template>
- <template name="genState">
- <param name="state"/>
- <variable name="stateName" select="$state/@id"/>
- <variable name="parentName">
- <choose>
- <!-- FIXME: probably want to refine this query, as we may not be able
to assume that all states have ids?-->
- <when test="$state/../@id">
- <value-of select="$state/../@id"/>
- </when>
- <otherwise>
- <value-of select="'AbstractState'"/>
- </otherwise>
- </choose>
- </variable>
- <variable name="historyState" select="$state/s:history"/>
- <variable name="constructorFunctionName"
select="concat($stateName,'Constructor')"/>
+ </template><template name="genState">
+ <param name="state"/>
+
+ <variable name="stateName" select="$state/@id"/>
+
+ <variable name="parentName">
+ <choose>
+ <when test="$state/../@id">
+ <value-of select="$state/../@id"/>
+ </when>
+ <otherwise>
+ <value-of select="$abstractStateName"/>
+ </otherwise>
+ </choose>
+ </variable>
+
+
+ <variable name="historyState" select="$state/s:history"/>
+
+ <variable name="constructorFunctionName"
select="concat($stateName,'Constructor')"/>
<!--
var stateName = sta...@id;
@@ -122,7 +129,9 @@
<if test="$state/self::s:history">
this.parent.historyState = this; //init
parent's pointer to history state
- </if><if test="$state/self::s:initial">
+ </if>
+
+ <if test="$state/self::s:initial">
this.parent.initial = this; //init
parent's pointer to initial state
</if>
@@ -133,18 +142,26 @@
this.enterAction = function(){
<if test="$log">
console.log("entering <value-of
select="$stateName"/>");
- </if><apply-templates
select="$state/s:onentry/*[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]"/>
+ </if>
+
+ <apply-templates
select="$state/s:onentry/*[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]"/>
}
this.exitAction = function(){
<if test="$log">
console.log("exiting <value-of
select="$stateName"/>" );
- </if><if test="$historyState">
+ </if>
+
+ <if test="$historyState">
this.historyState.lastConfiguration = currentConfiguration.slice();
- </if><apply-templates
select="$state/s:onexit/*[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]"/>
+ </if>
+
+ <apply-templates
select="$state/s:onexit/*[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]"/>
}
- <call-template name="genStateHooks"><with-param
name="state" select="$state"/></call-template>
+ <call-template name="genStateHooks">
+ <with-param name="state"
select="$state"/>
+ </call-template>
}
@@ -152,75 +169,63 @@
return new <value-of
select="$constructorFunctionName"/>();
})();
- </template>
- <template name="genStatesEnum">
- <param name="states"/>
+ </template><template name="genStatesEnum">
+ <param name="states"/>
this._states = {
- <for-each select="$states"><value-of select="@id"/> :
<value-of select="@id"/><if test="not(position() = last())">,</if></for-each>
+ <for-each select="$states">
+ <value-of select="@id"/> : <value-of
select="@id"/>
+ <if test="not(position() = last())">,</if>
+ </for-each>
}
- </template>
- <template match="s:if">
+ </template><template match="s:if">
if (<value-of select="@cond"/>) {
<apply-templates select="c:executableContent/*"/>
}
- <apply-templates select="s:elseif"/><apply-templates
select="s:else"/></template>
- <template match="s:elseif">
+ <apply-templates select="s:elseif"/>
+ <apply-templates select="s:else"/>
+ </template><template match="s:elseif">
else if (<value-of select="@cond"/>) {
<apply-templates select="c:executableContent/*"/>
}
- </template>
- <template match="s:else">
+ </template><template match="s:else">
else {
<apply-templates select="c:executableContent/*"/>
}
- </template>
- <template match="s:log">
- <if test="@label">
+ </template><template match="s:log">
+ <if test="@label">
console.log( ' <value-of select="@label"/> : ' );
</if>
- <if test="@expr">
+ <if test="@expr">
console.log( <value-of select="@expr"/> );
</if>
- </template>
- <template match="s:raise">
+ </template><template match="s:raise">
<!--TODO-->
- </template>
- <template match="s:script">
- <value-of select="."/>
- </template>
- <template match="s:cancel">
+ </template><template match="s:script">
+ <value-of select="."/>
+ </template><template match="s:cancel">
<!--TODO-->
- </template>
- <template match="s:invoke">
+ </template><template match="s:invoke">
<!--TODO-->
- </template>
- <template match="s:finalize">
+ </template><template match="s:finalize">
<!--TODO-->
- </template>
- <template match="s:datamodel">
+ </template><template match="s:datamodel">
<!--TODO-->
- </template>
- <template match="s:data">
+ </template><template match="s:data">
<!--TODO-->
- </template>
- <template match="s:assign">
+ </template><template match="s:assign">
<!--TODO-->
- </template>
- <template match="s:validate">
+ </template><template match="s:validate">
<!--TODO-->
- </template>
- <template match="s:param">
+ </template><template match="s:param">
<!--TODO-->
- </template>
- <template name="genInternalRuntimeFunctions">
+ </template><template name="genInternalRuntimeFunctions">
function sortByDepthDeepToShallow(a,b){
return b.depth - a.depth;
}
- </template>
- <template name="genBoilerplateDispatchCode">
+ </template><template name="genBoilerplateDispatchCode">
//static private member variables
var currentConfiguration = []; //current configuration
var innerEventQueue = []; //inner event queue
@@ -311,53 +316,55 @@
}
//end static boilerplate code
- </template>
- <variable name="deepHistoryEnterAction">
- <text>
+ </template><variable name="deepHistoryEnterAction">
+ <text>
var topState;
while(topState = statesEntered.pop()){
topState.enterAction();
}
</text>
- </variable>
- <variable name="shallowHistoryEnterAction">
- <text>
+ </variable><variable name="shallowHistoryEnterAction">
+ <text>
var topState = statesEntered.pop();
topState.enterAction();
newConfiguration.push(topState.initial ?
topState.initial : topState );
</text>
- </variable>
- <variable name="genNonBasicTriggerDispatcherExitBlockInnerForEach">
- <text>
+ </variable><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>
+ </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">
+ <if test="$log">
+ <choose>
+ <when test="$isDeep">
console.log("return to last
deep configuration");
- </when><otherwise>
+ </when>
+ <otherwise>
console.log("return to last
shallow configuration");
- </otherwise></choose></if>
+ </otherwise>
+ </choose>
+ </if>
<!--gen executable content for t-->
@@ -369,22 +376,31 @@
<if test="not($isDeep)">
var newConfiguration = [];
- </if><value-of
select="$historyStateReference"/>.lastConfiguration.forEach(function(state){
- <call-template
name="genHistoryTriggerDispatcherInnerForEach"><with-param name="isDeep"
select="$isDeep"/></call-template>
+ </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">
+ <choose>
+ <when test="$isDeep">
currentConfiguration = <value-of
select="$historyStateReference"/>.lastConfiguration.slice();
- </when><otherwise>
+ </when>
+ <otherwise>
currentConfiguration = <value-of
select="$genHistoryTriggerDispatcherCurrentConfigurationAssignmentRHS"/>;
- </otherwise></choose>
+ </otherwise>
+ </choose>
}else{
- <call-template
name="genTriggerDispatcherContents"><with-param name="s"
select="$s"/><with-param name="t" select="$t"/></call-template>
+ <call-template name="genTriggerDispatcherContents">
+ <with-param name="s" select="$s"/>
+ <with-param name="t" select="$t"/>
+ </call-template>
}
- </template>
- <template name="genHistoryTriggerDispatcherInnerForEach">
- <param name="isDeep"/>
+ </template><template name="genHistoryTriggerDispatcherInnerForEach">
+ <param name="isDeep"/>
var statesEntered = [<value-of
select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>];
@@ -395,9 +411,16 @@
}
- <choose><when test="$isDeep"><value-of
select="$deepHistoryEnterAction"/></when><otherwise><value-of
select="$shallowHistoryEnterAction"/></otherwise></choose></template>
- <template name="genNonBasicTriggerDispatcherExitBlock">
- <param name="t"/>
+ <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 = <value-of select="$t/c:lca"/>;
@@ -413,17 +436,48 @@
statesExited.forEach(function(state){
state.exitAction();
});
- </template>
- <template name="genTriggerDispatcherContents">
- <param name="s"/>
- <param name="t"/>
- <if test="not($t/@event)">
+ </template><template name="genTriggerDispatcherContents">
+ <param name="s"/>
+ <param name="t"/>
+
+ <!-- conditionally wrap contents in an if block for the guard
condition -->
+ <choose>
+ <when test="$t/@cond">
+ if(<value-of select="$t/@cond"/>){
+ <call-template
name="genTriggerDispatcherInnerContents">
+ <with-param name="s"
select="$s"/>
+ <with-param name="t"
select="$t"/>
+ </call-template>
+ }
+ </when>
+ <otherwise>
+ <call-template
name="genTriggerDispatcherInnerContents">
+ <with-param name="s" select="$s"/>
+ <with-param name="t" select="$t"/>
+ </call-template>
+ </otherwise>
+ </choose>
+ </template><template name="genTriggerDispatcherInnerContents">
+ <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/@c:isBasic and (
not($s/@c:isParallelSubstate) or ($s/@c:isParallelSubstate and
not($t/@c:exitsParallelRegion))))"><for-each
select="$t/c:exitpath/c:state"><value-of select="."/>.exitAction();
- </for-each></when><otherwise><call-template
name="genNonBasicTriggerDispatcherExitBlock"><with-param name="t"
select="$t"/></call-template></otherwise></choose>
+ <choose>
+ <when test="local-name($s) = 'initial' or
local-name($s) = 'history' or ( $s/@c:isBasic and (
not($s/@c:isParallelSubstate) or ($s/@c:isParallelSubstate and
not($t/@c:exitsParallelRegion))))">
+ <for-each select="$t/c:exitpath/c:state">
+ <value-of select="."/>.exitAction();
+ </for-each>
+ </when>
+ <otherwise>
+ <call-template
name="genNonBasicTriggerDispatcherExitBlock">
+ <with-param name="t" select="$t"/>
+ </call-template>
+ </otherwise>
+ </choose>
//transition action
<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]"/>
@@ -431,18 +485,34 @@
//enter states
<for-each select="$t/c:targets/c:target/c:enterpath/c:state">
<!-- iterate in reverse order -->
- <sort data-type="number" order="descending"
select="position()"/><value-of select="."/>.enterAction();
+ <sort select="position()" data-type="number"
order="descending"/>
+ <value-of select="."/>.enterAction();
</for-each>
//update configuration
- <choose><when test="$s/@c:isParallelSubstate and
not($t/@c:exitsParallelRegion)"><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>
+ <choose>
+ <when test="$s/@c:isParallelSubstate and
not($t/@c:exitsParallelRegion)">
+ <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/@c:isPreempted">
isPreempted = true;
- </if></template>
- <template name="genNoForEachArrayPrototypeExtension">
+ </if>
+
+ return;
+ </template><template name="genNoForEachArrayPrototypeExtension">
if(!Array.forEach){
Array.prototype.forEach = function(fn){
for(var i=0; i < this.length; i++){
@@ -451,8 +521,7 @@
return undefined;
}
}
- </template>
- <template name="genNoIndexOfArrayPrototypeExtension">
+ </template><template name="genNoIndexOfArrayPrototypeExtension">
if(!Array.indexOf){
Array.prototype.indexOf = function(obj){
for(var i=0; i < this.length; i++){
@@ -463,8 +532,7 @@
return -1;
}
}
- </template>
- <template name="genNoMapArrayPrototypeExtension">
+ </template><template name="genNoMapArrayPrototypeExtension">
if(!Array.map){
Array.prototype.map = function(fn){
var toReturn = [];
@@ -474,26 +542,50 @@
return toReturn;
}
}
+ </template><template name="genContextHooks"/>
+
+ <!-- these params get overridden by subclasses -->
+ <param name="dispatchInvocation" select="'state[e]();'"/>
+ <param name="defaultEventLiteral" select="'"$default"'"/>
+ <param name="currentConfigurationExpression"
select="'currentConfiguration.slice()'"/>
+
+ <param
name="genHistoryTriggerDispatcherCurrentConfigurationAssignmentRHS"
select="'newConfiguration'"/>
+ <param name="genHistoryTriggerDispatcherInnerForEachStateReference"
select="'state'"/>
+ <param name="genNonBasicTriggerDispatcherExitBlockIteratorExpression"
select="'currentConfiguration'"/>
+
+ <template name="genStateHooks">
+ <param name="state"/>
+
+ <!-- iterate through groups of transitions, grouped by event -->
+ <!--FIXME: this is likely to be a bit slow, as we're iterating
through all events -->
+ <for-each select="$eventsEnum/c:name">
+ <variable name="eventName">
+ <value-of select="."/>
+ </variable>
+
+ <variable name="transitionsForEvent"
select="$state/s:transiti...@event = $eventName]"/>
+ <if test="$transitionsForEvent">
+ <call-template
name="genTriggerDispatcherContext">
+ <with-param name="s" select="$state"/>
+ <with-param name="transitions"
select="$transitionsForEvent"/>
+ <with-param name="eventName"
select="$eventName"/>
+ </call-template>
+ </if>
+ </for-each>
+
+ <!-- now do default transitions -->
+ <variable name="defaultTransitionsForState"
select="$state/s:transition[not(@event)]"/>
+ <if test="$defaultTransitionsForState">
+ <call-template name="genTriggerDispatcherContext">
+ <with-param name="s" select="$state"/>
+ <with-param name="transitions"
select="$defaultTransitionsForState"/>
+ <with-param name="eventName"
select="'$default'"/>
+ </call-template>
+ </if>
</template>
- <template name="genContextHooks"/>
- <!-- these params get overridden by subclasses -->
- <param name="dispatchInvocation" select="'state[e]();'"/>
- <param name="defaultEventLiteral" select="'"$default"'"/>
- <param name="currentConfigurationExpression"
select="'currentConfiguration.slice()'"/>
- <param name="genHistoryTriggerDispatcherCurrentConfigurationAssignmentRHS"
select="'newConfiguration'"/>
- <param name="genHistoryTriggerDispatcherInnerForEachStateReference"
select="'state'"/>
- <param name="genNonBasicTriggerDispatcherExitBlockIteratorExpression"
select="'currentConfiguration'"/>
- <template name="genStateHooks">
- <param name="state"/>
- <for-each select="$state/s:transition">
- <call-template name="genTriggerDispatcherContext">
- <with-param name="s" select="$state"/>
- <with-param name="t" select="."/>
- </call-template>
- </for-each>
- </template>
- <template name="genExternalTriggerDispatcher">
- <param name="event"/>
+
+ <template name="genExternalTriggerDispatcher">
+ <param name="event"/>
this.<value-of select="$event/c:name"/> = function(){
if(isInStableState){
@@ -503,26 +595,36 @@
}
}
</template>
- <template name="genParallelSubstateConfigurationSetString">
- <param name="s"/>
- <param name="t"/>
+
+ <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="."/><if
test="not(position() = last())">,</if></for-each>
+ <for-each select="$t/c:targets/c:target/c:targetState">
+ <value-of select="."/>
+ <if test="not(position() = last())">,</if>
+ </for-each>
);
</template>
- <template name="genNonParallelSubstateConfigurationSetString">
- <param name="t"/>
- <param name="s"/>
+
+ <template name="genNonParallelSubstateConfigurationSetString">
+ <param name="t"/>
+ <param name="s"/>
currentConfiguration = [
- <for-each
select="$t/c:targets/c:target/c:targetState"><value-of select="."/><if
test="not(position() = last())">,</if></for-each>
+ <for-each select="$t/c:targets/c:target/c:targetState">
+ <value-of select="."/>
+ <if test="not(position() = last())">,</if>
+ </for-each>
];
</template>
- <template name="genInitialization">
- <variable name="initialStateName">
- <value-of
select="/s:scxml/s:initial/s:transition/c:targets/c:target/c:targetState"/>
- </variable>
+
+ <template name="genInitialization">
+
+ <variable name="initialStateName">
+ <value-of
select="/s:scxml/s:initial/s:transition/c:targets/c:target/c:targetState"/>
+ </variable>
this.initialize = function(){
currentConfiguration = [<value-of
select="$initialStateName"/>];
@@ -531,38 +633,65 @@
}
</template>
- <template name="genTriggerDispatcherContext">
- <param name="s"/>
- <param name="t"/>
- <variable name="eventName">
- <choose>
- <when test="$t/@event">
- <value-of select="$t/@event"/>
- </when>
- <otherwise>
- <value-of select="'$default'"/>
- </otherwise>
- </choose>
- </variable>
+
+ <template name="genTriggerDispatcherContext">
+ <param name="s"/>
+ <param name="transitions"/>
+ <param name="eventName"/>
this.<value-of select="$eventName"/> = function(){
- <choose><when test="local-name($s) =
'history'"><call-template name="genHistoryTriggerDispatcher"><with-param
name="s" select="$s"/><with-param name="t"
select="$t"/></call-template></when><otherwise><call-template
name="genTriggerDispatcherContents"><with-param name="s"
select="$s"/><with-param name="t"
select="$t"/></call-template></otherwise></choose>
+ <choose>
+ <when test="local-name($s) = 'history'">
+ <call-template
name="genHistoryTriggerDispatcher">
+ <with-param name="s"
select="$s"/>
+ <with-param name="t"
select="$transitions[1]"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <for-each select="$transitions">
+ <call-template
name="genTriggerDispatcherContents">
+ <with-param name="s"
select="$s"/>
+ <with-param name="t"
select="."/>
+ </call-template>
+ </for-each>
+ </otherwise>
+ </choose>
+
+ <!-- if by this point he hasn't returned, then none of
the transitions passed,
+ and we need to pass the transition up the
hierarchy chain -->
+
+ <variable name="parentName">
+ <choose>
+ <when test="$s/../@id">
+ <value-of select="$s/../@id"/>
+ </when>
+ <otherwise>
+ <value-of
select="$abstractStateName"/>
+ </otherwise>
+ </choose>
+ </variable>
+
+ <value-of select="$parentName"/>['<value-of
select="$eventName"/>']();
}
</template>
- <template name="genHistoryTriggerDispatcherHistoryStateReference">
- <param name="s"/>
- <text>this</text>
- </template>
- <template match="s:send">
- <choose>
- <when test="@delay">
+
+ <template name="genHistoryTriggerDispatcherHistoryStateReference">
+ <param name="s"/>
+
+ <text>this</text>
+ </template>
+
+ <template match="s:send">
+ <choose>
+ <when test="@delay">
window.setTimeout(function(){
self.GEN("<value-of select="@event"/>");
},<value-of select="number(@delay)*1000"/>);
</when>
- <otherwise>
+ <otherwise>
innerEventQueue.push("<value-of
select="@event"/>");
</otherwise>
- </choose>
- </template>
-</stylesheet>
+ </choose>
+ </template>
+
+</stylesheet>
\ No newline at end of file
Modified:
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/test/test_with_xsltproc.sh
URL:
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/test/test_with_xsltproc.sh?rev=957716&r1=957715&r2=957716&view=diff
==============================================================================
---
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/test/test_with_xsltproc.sh
(original)
+++
commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/test/test_with_xsltproc.sh
Thu Jun 24 21:17:03 2010
@@ -17,7 +17,7 @@ xsltproc ../src/xslt/ir-compiler/numberS
xmlindent > tmp_IR.xml;
#uncomment to compile IR to js
-#xsltproc ../src/xslt/ir-compiler/StatePatternStatechartGenerator.xsl
tmp_IR.xml > out.js
+xsltproc ../src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl
tmp_IR.xml > out.js
#uncomment to prettify js. need to have beautify.js, beautify-cl.js and
beautify-html.js in this directory
#java -cp ../lib/java/js.jar org.mozilla.javascript.tools.shell.Main -debug
beautify-cl.js -i 4 out.js > out_pretty.js