summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-07-07 00:38:46 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-07-07 00:38:46 (GMT)
commitd5e1f6397c52513018cd59972cf5ca8740de18eb (patch)
tree80448f6b414373f799273ed777ed0b7260605bdb
parent41312059e5d25539d3cd071829a505ebb7293393 (diff)
downloaduscxml-d5e1f6397c52513018cd59972cf5ca8740de18eb.zip
uscxml-d5e1f6397c52513018cd59972cf5ca8740de18eb.tar.gz
uscxml-d5e1f6397c52513018cd59972cf5ca8740de18eb.tar.bz2
Appr. 15% performance boost by avoiding dynamic_cast in DOM
-rw-r--r--README.md8
-rw-r--r--src/uscxml/Interpreter.cpp157
-rw-r--r--src/uscxml/Interpreter.h44
-rw-r--r--src/uscxml/debug/SCXMLDotWriter.cpp4
-rw-r--r--src/uscxml/interpreter/InterpreterDraft6.cpp66
-rw-r--r--src/uscxml/interpreter/InterpreterDraft6.h10
-rw-r--r--src/uscxml/interpreter/InterpreterRC.cpp68
-rw-r--r--src/uscxml/interpreter/InterpreterRC.h6
-rw-r--r--src/uscxml/transform/ChartToFSM.cpp21
-rw-r--r--src/uscxml/transform/ChartToFSM.h6
-rw-r--r--src/uscxml/transform/FSMToPromela.cpp2
11 files changed, 198 insertions, 194 deletions
diff --git a/README.md b/README.md
index 039720c..527509a 100644
--- a/README.md
+++ b/README.md
@@ -67,10 +67,10 @@ uSCXML still fails the following ecmascript tests:
<table>
<tr><th>Test#</th><th>Status</th><th>Description</th><th>Comment</th></tr>
<tr>
- <td><tt>
- <a href="https://github.com/tklab-tud/uscxml/blob/master/test/w3c/ecma/test326.scxml">326</a> /
- <a href="https://github.com/tklab-tud/uscxml/blob/master/test/w3c/ecma/test326.scxml">329</a>
- </tt></td>
+ <td>
+ <tt><a href="https://github.com/tklab-tud/uscxml/blob/master/test/w3c/ecma/test326.scxml">326</a></tt> /
+ <tt><a href="https://github.com/tklab-tud/uscxml/blob/master/test/w3c/ecma/test326.scxml">329</a></tt>
+ </td>
<td><tt>Failed for v8</tt></td>
<td>"test that _ioprocessors stays bound till the session ends" / "test that none of the system variables can be modified"</td>
<td>The v8 implementation will return a new <tt>_ioprocessor</tt> object for each access.</td>
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp
index 7ae34f2..e6fc8fa 100644
--- a/src/uscxml/Interpreter.cpp
+++ b/src/uscxml/Interpreter.cpp
@@ -813,7 +813,7 @@ void InterpreterImpl::init() {
NodeSet<std::string> globalScriptElems = filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml);
for (unsigned int i = 0; i < globalScriptElems.size(); i++) {
if (_dataModel) {
- executeContent(globalScriptElems[i]);
+ executeContent(Element<std::string>(globalScriptElems[i]));
}
}
@@ -881,15 +881,14 @@ void InterpreterImpl::receive(const Event& event, bool toFront) {
_condVar.notify_all();
}
-void InterpreterImpl::internalDoneSend(const Arabica::DOM::Node<std::string>& state) {
+void InterpreterImpl::internalDoneSend(const Arabica::DOM::Element<std::string>& state) {
if (!isState(state))
return;
- Arabica::DOM::Element<std::string> stateElem = (Arabica::DOM::Element<std::string>)state;
- Arabica::DOM::Element<std::string> parent = (Arabica::DOM::Element<std::string>)stateElem.getParentNode();
+ Arabica::DOM::Element<std::string> parent = (Arabica::DOM::Element<std::string>)state.getParentNode();
Event event;
- Arabica::XPath::NodeSet<std::string> doneDatas = filterChildElements(_nsInfo.xmlNSPrefix + "donedata", stateElem);
+ Arabica::XPath::NodeSet<std::string> doneDatas = filterChildElements(_nsInfo.xmlNSPrefix + "donedata", state);
if (doneDatas.size() > 0) {
// only process first donedata element
Arabica::DOM::Node<std::string> doneData = doneDatas[0];
@@ -912,7 +911,7 @@ void InterpreterImpl::internalDoneSend(const Arabica::DOM::Node<std::string>& st
}
}
- event.name = "done.state." + ATTR(stateElem.getParentNode(), "id"); // parent?!
+ event.name = "done.state." + ATTR(state.getParentNode(), "id"); // parent?!
receiveInternal(event);
}
@@ -1502,8 +1501,7 @@ bool InterpreterImpl::nameMatch(const std::string& transitionEvent, const std::s
}
-bool InterpreterImpl::hasConditionMatch(const Arabica::DOM::Node<std::string>& conditional) {
-
+bool InterpreterImpl::hasConditionMatch(const Arabica::DOM::Element<std::string>& conditional) {
if (HAS_ATTR(conditional, "cond") && ATTR(conditional, "cond").length() > 0) {
try {
return _dataModel.evalAsBool(ATTR_NODE(conditional, "cond"), ATTR(conditional, "cond"));
@@ -1524,7 +1522,7 @@ void InterpreterImpl::executeContent(const NodeList<std::string>& content, bool
if (node.getNodeType() != Node_base::ELEMENT_NODE)
continue;
try {
- executeContent(node, true);
+ executeContent(Element<std::string>(node), true);
}
CATCH_AND_DISTRIBUTE2("Error when executing content", content.item(i));
}
@@ -1536,13 +1534,13 @@ void InterpreterImpl::executeContent(const NodeSet<std::string>& content, bool r
if (node.getNodeType() != Node_base::ELEMENT_NODE)
continue;
try {
- executeContent(node, true);
+ executeContent(Element<std::string>(node), true);
}
CATCH_AND_DISTRIBUTE2("Error when executing content", content[i]);
}
}
-void InterpreterImpl::executeContent(const Arabica::DOM::Node<std::string>& content, bool rethrow) {
+void InterpreterImpl::executeContent(const Arabica::DOM::Element<std::string>& content, bool rethrow) {
if (content.getNodeType() != Node_base::ELEMENT_NODE)
return;
@@ -1553,7 +1551,9 @@ void InterpreterImpl::executeContent(const Arabica::DOM::Node<std::string>& cont
// --- CONVENIENCE LOOP --------------------------
NodeList<std::string> executable = content.getChildNodes();
for (int i = 0; i < executable.getLength(); i++) {
- executeContent(executable.item(i), rethrow);
+ if (executable.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+ executeContent(Element<std::string>(executable.item(i)), rethrow);
}
return;
}
@@ -1626,6 +1626,7 @@ void InterpreterImpl::executeContent(const Arabica::DOM::Node<std::string>& cont
for (unsigned int i = 0; i < childs.getLength(); i++) {
if (childs.item(i).getNodeType() != Node_base::ELEMENT_NODE)
continue;
+ Element<std::string> childElem(childs.item(i));
if (iequals(TAGNAME(childs.item(i)), _nsInfo.xmlNSPrefix + "elseif") ||
iequals(TAGNAME(childs.item(i)), _nsInfo.xmlNSPrefix + "else")) {
if (blockIsTrue) {
@@ -1633,11 +1634,11 @@ void InterpreterImpl::executeContent(const Arabica::DOM::Node<std::string>& cont
break;
} else {
// is this block the one to execute?
- blockIsTrue = hasConditionMatch(childs.item(i));
+ blockIsTrue = hasConditionMatch(childElem);
}
} else {
if (blockIsTrue) {
- executeContent(childs.item(i), rethrow);
+ executeContent(childElem, rethrow);
}
}
}
@@ -1805,7 +1806,9 @@ void InterpreterImpl::executeContent(const Arabica::DOM::Node<std::string>& cont
if (execContent.processChildren()) {
NodeList<std::string> executable = content.getChildNodes();
for (int i = 0; i < executable.getLength(); i++) {
- executeContent(executable.item(i), rethrow);
+ if (executable.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+ executeContent(Element<std::string>(executable.item(i)), rethrow);
}
}
execContent.exitElement(content);
@@ -1848,25 +1851,24 @@ void InterpreterImpl::returnDoneEvent(const Arabica::DOM::Node<std::string>& sta
}
}
-bool InterpreterImpl::parentIsScxmlState(const Arabica::DOM::Node<std::string>& state) {
- Arabica::DOM::Element<std::string> stateElem = (Arabica::DOM::Element<std::string>)state;
+bool InterpreterImpl::parentIsScxmlState(const Arabica::DOM::Element<std::string>& state) {
Arabica::DOM::Element<std::string> parentElem = (Arabica::DOM::Element<std::string>)state.getParentNode();
if (iequals(TAGNAME(parentElem), _nsInfo.xmlNSPrefix + "scxml"))
return true;
return false;
}
-bool InterpreterImpl::isInFinalState(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isInFinalState(const Arabica::DOM::Element<std::string>& state) {
if (isCompound(state)) {
Arabica::XPath::NodeSet<std::string> childs = getChildStates(state);
for (int i = 0; i < childs.size(); i++) {
- if (isFinal(childs[i]) && isMember(childs[i], _configuration))
+ if (isFinal(Element<std::string>(childs[i])) && isMember(childs[i], _configuration))
return true;
}
} else if (isParallel(state)) {
Arabica::XPath::NodeSet<std::string> childs = getChildStates(state);
for (int i = 0; i < childs.size(); i++) {
- if (!isInFinalState(childs[i]))
+ if (!isInFinalState(Element<std::string>(childs[i])))
return false;
}
return true;
@@ -1887,7 +1889,9 @@ Arabica::XPath::NodeSet<std::string> InterpreterImpl::getChildStates(const Arabi
Arabica::DOM::NodeList<std::string> childElems = state.getChildNodes();
for (int i = 0; i < childElems.getLength(); i++) {
- if (isState(childElems.item(i))) {
+ if (childElems.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+ if (isState(Element<std::string>(childElems.item(i)))) {
childs.push_back(childElems.item(i));
}
}
@@ -1902,12 +1906,12 @@ Arabica::XPath::NodeSet<std::string> InterpreterImpl::getChildStates(const Arabi
return childs;
}
-Arabica::DOM::Node<std::string> InterpreterImpl::getParentState(const Arabica::DOM::Node<std::string>& element) {
+Arabica::DOM::Element<std::string> InterpreterImpl::getParentState(const Arabica::DOM::Node<std::string>& element) {
Arabica::DOM::Node<std::string> parent = element.getParentNode();
- while(parent && !isState(parent)) {
+ while(parent && !isState(Element<std::string>(parent))) {
parent = parent.getParentNode();
}
- return parent;
+ return Element<std::string>(parent);
}
Arabica::DOM::Node<std::string> InterpreterImpl::getAncestorElement(const Arabica::DOM::Node<std::string>& node, const std::string tagName) {
@@ -1943,7 +1947,7 @@ Arabica::DOM::Node<std::string> InterpreterImpl::findLCCA(const Arabica::XPath::
// ancestors.push_back(states[0]); // state[0] may already be the ancestor - bug in W3C spec?
Arabica::DOM::Node<std::string> ancestor;
for (int i = 0; i < ancestors.size(); i++) {
- if (!isCompound(ancestors[i]))
+ if (!isCompound(Element<std::string>(ancestors[i])))
continue;
for (int j = 0; j < states.size(); j++) {
#if 0
@@ -1978,7 +1982,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterImpl::getStates(const std::list<
return states;
}
-Arabica::DOM::Node<std::string> InterpreterImpl::getState(const std::string& stateId) {
+Arabica::DOM::Element<std::string> InterpreterImpl::getState(const std::string& stateId) {
if (_cachedStates.find(stateId) != _cachedStates.end()) {
return _cachedStates[stateId];
@@ -2010,14 +2014,15 @@ Arabica::DOM::Node<std::string> InterpreterImpl::getState(const std::string& sta
FOUND:
if (target.size() > 0) {
for (int i = 0; i < target.size(); i++) {
- if (!isInEmbeddedDocument(target[i])) {
- _cachedStates[stateId] = target[i];
- return target[i];
+ Element<std::string> targetElem(target[i]);
+ if (!isInEmbeddedDocument(targetElem)) {
+ _cachedStates[stateId] = targetElem;
+ return targetElem;
}
}
}
// return the empty node
- return Arabica::DOM::Node<std::string>();
+ return Arabica::DOM::Element<std::string>();
}
Arabica::XPath::NodeSet<std::string> InterpreterImpl::getAllStates() {
@@ -2029,7 +2034,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterImpl::getAllStates() {
return states;
}
-Arabica::DOM::Node<std::string> InterpreterImpl::getSourceState(const Arabica::DOM::Node<std::string>& transition) {
+Arabica::DOM::Node<std::string> InterpreterImpl::getSourceState(const Arabica::DOM::Element<std::string>& transition) {
if (iequals(TAGNAME(transition.getParentNode()), _nsInfo.xmlNSPrefix + "initial"))
return transition.getParentNode().getParentNode();
return transition.getParentNode();
@@ -2042,7 +2047,7 @@ Arabica::DOM::Node<std::string> InterpreterImpl::getSourceState(const Arabica::D
* attribute nor an <initial> element is specified, the SCXML Processor must use
* the first child state in document order as the default initial state.
*/
-Arabica::XPath::NodeSet<std::string> InterpreterImpl::getInitialStates(Arabica::DOM::Node<std::string> state) {
+Arabica::XPath::NodeSet<std::string> InterpreterImpl::getInitialStates(Arabica::DOM::Element<std::string> state) {
if (!state) {
state = _scxml;
}
@@ -2063,14 +2068,16 @@ Arabica::XPath::NodeSet<std::string> InterpreterImpl::getInitialStates(Arabica::
NodeSet<std::string> initElems = filterChildElements(_nsInfo.xmlNSPrefix + "initial", state);
if(initElems.size() == 1 && !iequals(ATTR(initElems[0], "generated"), "true")) {
NodeSet<std::string> initTrans = filterChildElements(_nsInfo.xmlNSPrefix + "transition", initElems[0]);
- return getTargetStates(initTrans[0]);
+ return getTargetStates(Element<std::string>(initTrans[0]));
}
// first child state
Arabica::XPath::NodeSet<std::string> initStates;
NodeList<std::string> childs = state.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) {
- if (isState(childs.item(i))) {
+ if (childs.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+ if (isState(Element<std::string>(childs.item(i)))) {
initStates.push_back(childs.item(i));
return initStates;
}
@@ -2080,7 +2087,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterImpl::getInitialStates(Arabica::
return Arabica::XPath::NodeSet<std::string>();
}
-NodeSet<std::string> InterpreterImpl::getTargetStates(const Arabica::DOM::Node<std::string>& transition) {
+NodeSet<std::string> InterpreterImpl::getTargetStates(const Arabica::DOM::Element<std::string>& transition) {
NodeSet<std::string> targetStates;
assert(boost::ends_with(TAGNAME(transition), "transition"));
@@ -2089,8 +2096,10 @@ NodeSet<std::string> InterpreterImpl::getTargetStates(const Arabica::DOM::Node<s
if (isState(transition) || (transition.getNodeType() == Node_base::ELEMENT_NODE && iequals(_nsInfo.xmlNSPrefix + "initial", TAGNAME(transition)))) {
NodeList<std::string> childs = transition.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) {
- if (childs.item(i).getNodeType() == Node_base::ELEMENT_NODE && iequals(TAGNAME(childs.item(i)), _nsInfo.xmlNSPrefix + "transition")) {
- targetStates.push_back(getTargetStates(childs.item(i)));
+ if (childs.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+ if (iequals(TAGNAME(childs.item(i)), _nsInfo.xmlNSPrefix + "transition")) {
+ targetStates.push_back(getTargetStates(Element<std::string>(childs.item(i))));
}
}
return targetStates;
@@ -2111,7 +2120,7 @@ NodeSet<std::string> InterpreterImpl::getTargetStates(const Arabica::DOM::Node<s
NodeSet<std::string> InterpreterImpl::getTargetStates(const Arabica::XPath::NodeSet<std::string>& transitions) {
NodeSet<std::string> targets;
for (unsigned int i = 0; i < transitions.size(); i++) {
- targets.push_back(getTargetStates(transitions[i]));
+ targets.push_back(getTargetStates(Element<std::string>(transitions[i])));
}
return targets;
}
@@ -2187,11 +2196,11 @@ NodeSet<std::string> InterpreterImpl::filterChildElements(const std::string& tag
NodeList<std::string> childs = node.getChildNodes();
for (unsigned int i = 0; i < childs.getLength(); i++) {
- if (childs.item(i).getNodeType() == Node_base::ELEMENT_NODE) {
+ if (childs.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
// std::cout << TAGNAME(childs.item(i)) << std::endl;
- if(iequals(TAGNAME(childs.item(i)), tagName)) {
- filteredChildElems.push_back(childs.item(i));
- }
+ if(iequals(TAGNAME(childs.item(i)), tagName)) {
+ filteredChildElems.push_back(childs.item(i));
}
if (recurse) {
filteredChildElems.push_back(filterChildElements(tagName, childs.item(i), recurse));
@@ -2229,16 +2238,20 @@ NodeSet<std::string> InterpreterImpl::filterChildType(const Node_base::Type type
NodeSet<std::string> InterpreterImpl::getProperAncestors(const Arabica::DOM::Node<std::string>& s1,
const Arabica::DOM::Node<std::string>& s2) {
NodeSet<std::string> ancestors;
- if (isState(s1)) {
+ if (isState(Element<std::string>(s1))) {
Arabica::DOM::Node<std::string> node = s1;
while((node = node.getParentNode())) {
- if (!isState(node))
+ if (node.getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+
+ Element<std::string> nodeElem(node);
+ if (!isState(nodeElem))
break;
- if (iequals(TAGNAME(node), _nsInfo.xmlNSPrefix + "scxml")) // do not return scxml root itself - this is somewhat ill-defined
+ if (iequals(TAGNAME(nodeElem), _nsInfo.xmlNSPrefix + "scxml")) // do not return scxml root itself - this is somewhat ill-defined
break;
- if (!iequals(TAGNAME(node), _nsInfo.xmlNSPrefix + "parallel") &&
- !iequals(TAGNAME(node), _nsInfo.xmlNSPrefix + "state") &&
- !iequals(TAGNAME(node), _nsInfo.xmlNSPrefix + "scxml"))
+ if (!iequals(TAGNAME(nodeElem), _nsInfo.xmlNSPrefix + "parallel") &&
+ !iequals(TAGNAME(nodeElem), _nsInfo.xmlNSPrefix + "state") &&
+ !iequals(TAGNAME(nodeElem), _nsInfo.xmlNSPrefix + "scxml"))
break;
if (node == s2)
break;
@@ -2259,7 +2272,7 @@ bool InterpreterImpl::isDescendant(const Arabica::DOM::Node<std::string>& s1,
return false;
}
-bool InterpreterImpl::isTargetless(const Arabica::DOM::Node<std::string>& transition) {
+bool InterpreterImpl::isTargetless(const Arabica::DOM::Element<std::string>& transition) {
if (transition.hasAttributes()) {
if (((Arabica::DOM::Element<std::string>)transition).hasAttribute("target"))
return false;
@@ -2267,11 +2280,9 @@ bool InterpreterImpl::isTargetless(const Arabica::DOM::Node<std::string>& transi
return true;
}
-bool InterpreterImpl::isState(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isState(const Arabica::DOM::Element<std::string>& state) {
if (!state)
return false;
- if (state.getNodeType() != Arabica::DOM::Node_base::ELEMENT_NODE)
- return false;
std::string tagName = LOCALNAME(state);
if (iequals("state", tagName))
@@ -2287,7 +2298,7 @@ bool InterpreterImpl::isState(const Arabica::DOM::Node<std::string>& state) {
return false;
}
-bool InterpreterImpl::isFinal(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isFinal(const Arabica::DOM::Element<std::string>& state) {
std::string tagName = LOCALNAME(state);
if (iequals("final", tagName))
return true;
@@ -2311,11 +2322,11 @@ bool InterpreterImpl::isInEmbeddedDocument(const Node<std::string>& node) {
return false;
}
-bool InterpreterImpl::isInitial(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isInitial(const Arabica::DOM::Element<std::string>& state) {
if (!isState(state))
return false;
- Arabica::DOM::Node<std::string> parent = state.getParentNode();
+ Arabica::DOM::Element<std::string> parent = (Element<std::string>)state.getParentNode();
if (!isState(parent))
return true; // scxml element
@@ -2325,7 +2336,7 @@ bool InterpreterImpl::isInitial(const Arabica::DOM::Node<std::string>& state) {
return false;
}
-bool InterpreterImpl::isPseudoState(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isPseudoState(const Arabica::DOM::Element<std::string>& state) {
std::string tagName = LOCALNAME(state);
if (iequals("initial", tagName))
return true;
@@ -2334,11 +2345,11 @@ bool InterpreterImpl::isPseudoState(const Arabica::DOM::Node<std::string>& state
return false;
}
-bool InterpreterImpl::isTransitionTarget(const Arabica::DOM::Node<std::string>& elem) {
+bool InterpreterImpl::isTransitionTarget(const Arabica::DOM::Element<std::string>& elem) {
return (isState(elem) || iequals(LOCALNAME(elem), "history"));
}
-bool InterpreterImpl::isAtomic(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isAtomic(const Arabica::DOM::Element<std::string>& state) {
if (iequals("final", LOCALNAME(state)))
return true;
@@ -2347,19 +2358,22 @@ bool InterpreterImpl::isAtomic(const Arabica::DOM::Node<std::string>& state) {
Arabica::DOM::NodeList<std::string> childs = state.getChildNodes();
for (unsigned int i = 0; i < childs.getLength(); i++) {
- if (isState(childs.item(i)))
+ if (childs.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+
+ if (isState(Element<std::string>(childs.item(i))))
return false;
}
return true;
}
-bool InterpreterImpl::isHistory(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isHistory(const Arabica::DOM::Element<std::string>& state) {
if (iequals("history", LOCALNAME(state)))
return true;
return false;
}
-bool InterpreterImpl::isParallel(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isParallel(const Arabica::DOM::Element<std::string>& state) {
if (!isState(state))
return false;
if (iequals("parallel", LOCALNAME(state)))
@@ -2368,7 +2382,7 @@ bool InterpreterImpl::isParallel(const Arabica::DOM::Node<std::string>& state) {
}
-bool InterpreterImpl::isCompound(const Arabica::DOM::Node<std::string>& state) {
+bool InterpreterImpl::isCompound(const Arabica::DOM::Element<std::string>& state) {
if (!isState(state))
return false;
@@ -2377,7 +2391,9 @@ bool InterpreterImpl::isCompound(const Arabica::DOM::Node<std::string>& state) {
Arabica::DOM::NodeList<std::string> childs = state.getChildNodes();
for (unsigned int i = 0; i < childs.getLength(); i++) {
- if (isState(childs.item(i)))
+ if (childs.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+ if (isState(Element<std::string>(childs.item(i))))
return true;
}
return false;
@@ -2463,7 +2479,7 @@ bool InterpreterImpl::hasLegalConfiguration() {
bool InterpreterImpl::isLegalConfiguration(const std::list<std::string>& config) {
NodeSet<std::string> states;
for (std::list<std::string>::const_iterator confIter = config.begin(); confIter != config.end(); confIter++) {
- Node<std::string> state = getState(*confIter);
+ Element<std::string> state = getState(*confIter);
if (!state) {
LOG(INFO) << "No state with id '" << *confIter << "'";
return false;
@@ -2507,7 +2523,7 @@ bool InterpreterImpl::isLegalConfiguration(const NodeSet<std::string>& config) {
// The configuration contains one or more atomic states.
bool foundAtomicState = false;
for (int i = 0; i < config.size(); i++) {
- if (isAtomic(config[i])) {
+ if (isAtomic(Element<std::string>(config[i]))) {
foundAtomicState = true;
break;
}
@@ -2517,10 +2533,10 @@ bool InterpreterImpl::isLegalConfiguration(const NodeSet<std::string>& config) {
// When the configuration contains an atomic state, it contains all of its <state> and <parallel> ancestors.
for (int i = 0; i < config.size(); i++) {
- if (isAtomic(config[i])) {
+ if (isAtomic(Element<std::string>(config[i]))) {
Node<std::string> parent = config[i];
while((parent = parent.getParentNode())) {
- if (isState(parent) &&
+ if (isState(Element<std::string>(parent)) &&
(iequals(LOCALNAME(parent), "state") ||
iequals(LOCALNAME(parent), "parallel"))) {
if (!isMember(parent, config))
@@ -2532,7 +2548,8 @@ bool InterpreterImpl::isLegalConfiguration(const NodeSet<std::string>& config) {
// When the configuration contains a non-atomic <state>, it contains one and only one of the state's children
for (int i = 0; i < config.size(); i++) {
- if (!isAtomic(config[i]) && !isParallel(config[i])) {
+ Element<std::string> configElem(config[i]);
+ if (!isAtomic(configElem) && !isParallel(configElem)) {
bool foundChildState = false;
//std::cout << config[i] << std::endl;
NodeSet<std::string> childs = getChildStates(config[i]);
@@ -2551,10 +2568,10 @@ bool InterpreterImpl::isLegalConfiguration(const NodeSet<std::string>& config) {
// If the configuration contains a <parallel> state, it contains all of its children
for (int i = 0; i < config.size(); i++) {
- if (isParallel(config[i])) {
+ if (isParallel(Element<std::string>(config[i]))) {
NodeSet<std::string> childs = getChildStates(config[i]);
for (int j = 0; j < childs.size(); j++) {
- if (!isMember(childs[j], config) && !isHistory(childs[j])) {
+ if (!isMember(childs[j], config) && !isHistory(Element<std::string>(childs[j]))) {
return false;
}
}
diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h
index 2ad1039..1bdae5c 100644
--- a/src/uscxml/Interpreter.h
+++ b/src/uscxml/Interpreter.h
@@ -323,7 +323,7 @@ public:
tthread::lock_guard<tthread::recursive_mutex> lock(_mutex);
Arabica::XPath::NodeSet<std::string> basicConfig;
for (int i = 0; i < _configuration.size(); i++) {
- if (isAtomic(_configuration[i]))
+ if (isAtomic(Arabica::DOM::Element<std::string>(_configuration[i])))
basicConfig.push_back(_configuration[i]);
}
return basicConfig;
@@ -372,33 +372,33 @@ public:
bool isLegalConfiguration(const Arabica::XPath::NodeSet<std::string>&);
bool isLegalConfiguration(const std::list<std::string>&);
- static bool isState(const Arabica::DOM::Node<std::string>& state);
- static bool isPseudoState(const Arabica::DOM::Node<std::string>& state);
- static bool isTransitionTarget(const Arabica::DOM::Node<std::string>& elem);
- static bool isTargetless(const Arabica::DOM::Node<std::string>& transition);
- static bool isAtomic(const Arabica::DOM::Node<std::string>& state);
- static bool isFinal(const Arabica::DOM::Node<std::string>& state);
- static bool isHistory(const Arabica::DOM::Node<std::string>& state);
- static bool isParallel(const Arabica::DOM::Node<std::string>& state);
- static bool isCompound(const Arabica::DOM::Node<std::string>& state);
+ static bool isState(const Arabica::DOM::Element<std::string>& state);
+ static bool isPseudoState(const Arabica::DOM::Element<std::string>& state);
+ static bool isTransitionTarget(const Arabica::DOM::Element<std::string>& elem);
+ static bool isTargetless(const Arabica::DOM::Element<std::string>& transition);
+ static bool isAtomic(const Arabica::DOM::Element<std::string>& state);
+ static bool isFinal(const Arabica::DOM::Element<std::string>& state);
+ static bool isHistory(const Arabica::DOM::Element<std::string>& state);
+ static bool isParallel(const Arabica::DOM::Element<std::string>& state);
+ static bool isCompound(const Arabica::DOM::Element<std::string>& state);
static bool isDescendant(const Arabica::DOM::Node<std::string>& s1, const Arabica::DOM::Node<std::string>& s2);
bool isInEmbeddedDocument(const Arabica::DOM::Node<std::string>& node);
- bool isInitial(const Arabica::DOM::Node<std::string>& state);
+ bool isInitial(const Arabica::DOM::Element<std::string>& state);
static std::string stateToString(InterpreterState state);
- Arabica::DOM::Node<std::string> getState(const std::string& stateId);
+ Arabica::DOM::Element<std::string> getState(const std::string& stateId);
Arabica::XPath::NodeSet<std::string> getStates(const std::list<std::string>& stateIds);
Arabica::XPath::NodeSet<std::string> getAllStates();
- Arabica::XPath::NodeSet<std::string> getInitialStates(Arabica::DOM::Node<std::string> state = Arabica::DOM::Node<std::string>());
+ Arabica::XPath::NodeSet<std::string> getInitialStates(Arabica::DOM::Element<std::string> state = Arabica::DOM::Element<std::string>());
static Arabica::XPath::NodeSet<std::string> getChildStates(const Arabica::DOM::Node<std::string>& state);
static Arabica::XPath::NodeSet<std::string> getChildStates(const Arabica::XPath::NodeSet<std::string>& state);
- static Arabica::DOM::Node<std::string> getParentState(const Arabica::DOM::Node<std::string>& element);
+ static Arabica::DOM::Element<std::string> getParentState(const Arabica::DOM::Node<std::string>& element);
static Arabica::DOM::Node<std::string> getAncestorElement(const Arabica::DOM::Node<std::string>& node, const std::string tagName);
- virtual Arabica::XPath::NodeSet<std::string> getTargetStates(const Arabica::DOM::Node<std::string>& transition);
+ virtual Arabica::XPath::NodeSet<std::string> getTargetStates(const Arabica::DOM::Element<std::string>& transition);
virtual Arabica::XPath::NodeSet<std::string> getTargetStates(const Arabica::XPath::NodeSet<std::string>& transitions);
- virtual Arabica::DOM::Node<std::string> getSourceState(const Arabica::DOM::Node<std::string>& transition);
+ virtual Arabica::DOM::Node<std::string> getSourceState(const Arabica::DOM::Element<std::string>& transition);
static Arabica::XPath::NodeSet<std::string> filterChildElements(const std::string& tagname, const Arabica::DOM::Node<std::string>& node, bool recurse = false);
static Arabica::XPath::NodeSet<std::string> filterChildElements(const std::string& tagName, const Arabica::XPath::NodeSet<std::string>& nodeSet, bool recurse = false);
@@ -482,7 +482,7 @@ protected:
Data _cmdLineOptions;
- virtual void executeContent(const Arabica::DOM::Node<std::string>& content, bool rethrow = false);
+ virtual void executeContent(const Arabica::DOM::Element<std::string>& content, bool rethrow = false);
virtual void executeContent(const Arabica::DOM::NodeList<std::string>& content, bool rethrow = false);
virtual void executeContent(const Arabica::XPath::NodeSet<std::string>& content, bool rethrow = false);
@@ -499,13 +499,13 @@ protected:
virtual void send(const Arabica::DOM::Node<std::string>& element);
virtual void invoke(const Arabica::DOM::Node<std::string>& element);
virtual void cancelInvoke(const Arabica::DOM::Node<std::string>& element);
- virtual void internalDoneSend(const Arabica::DOM::Node<std::string>& state);
+ virtual void internalDoneSend(const Arabica::DOM::Element<std::string>& state);
static void delayedSend(void* userdata, std::string eventName);
void returnDoneEvent(const Arabica::DOM::Node<std::string>& state);
- bool hasConditionMatch(const Arabica::DOM::Node<std::string>& conditional);
- bool isInFinalState(const Arabica::DOM::Node<std::string>& state);
- bool parentIsScxmlState(const Arabica::DOM::Node<std::string>& state);
+ bool hasConditionMatch(const Arabica::DOM::Element<std::string>& conditional);
+ bool isInFinalState(const Arabica::DOM::Element<std::string>& state);
+ bool parentIsScxmlState(const Arabica::DOM::Element<std::string>& state);
IOProcessor getIOProcessor(const std::string& type);
@@ -515,7 +515,7 @@ protected:
std::map<Arabica::DOM::Node<std::string>, ExecutableContent> _executableContent;
/// TODO: We need to adapt them when the DOM is operated upon
- std::map<std::string, Arabica::DOM::Node<std::string> > _cachedStates;
+ std::map<std::string, Arabica::DOM::Element<std::string> > _cachedStates;
std::map<std::string, URL> _cachedURLs;
friend class USCXMLInvoker;
diff --git a/src/uscxml/debug/SCXMLDotWriter.cpp b/src/uscxml/debug/SCXMLDotWriter.cpp
index 2bccb14..d5471de 100644
--- a/src/uscxml/debug/SCXMLDotWriter.cpp
+++ b/src/uscxml/debug/SCXMLDotWriter.cpp
@@ -176,7 +176,7 @@ void SCXMLDotWriter::writeStateElement(std::ostream& os, const Arabica::DOM::Ele
os << "]" << std::endl;
}
}
- if (InterpreterImpl::isState(childElems.item(i))) {
+ if (InterpreterImpl::isState(Element<std::string>(childElems.item(i)))) {
writeStateElement(os, (Arabica::DOM::Element<std::string>)childElems.item(i));
}
if (childElems.item(i).getNodeType() == Node_base::ELEMENT_NODE && iequals(TAGNAME(childElems.item(i)), "initial")) {
@@ -256,7 +256,7 @@ std::string SCXMLDotWriter::getDetailedLabel(const Arabica::DOM::Element<std::st
if (childElems.item(i).getNodeType() != Node_base::ELEMENT_NODE)
continue;
- if (InterpreterImpl::isState(childElems.item(i)) ||
+ if (InterpreterImpl::isState(Element<std::string>(childElems.item(i))) ||
iequals(TAGNAME(childElems.item(i)), "transition") ||
iequals(TAGNAME(childElems.item(i)), "initial") ||
false)
diff --git a/src/uscxml/interpreter/InterpreterDraft6.cpp b/src/uscxml/interpreter/InterpreterDraft6.cpp
index fdbd21b..20f89d2 100644
--- a/src/uscxml/interpreter/InterpreterDraft6.cpp
+++ b/src/uscxml/interpreter/InterpreterDraft6.cpp
@@ -360,7 +360,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterDraft6::selectTransitions(const
NodeSet<std::string> states;
for (unsigned int i = 0; i < _configuration.size(); i++) {
- if (isAtomic(_configuration[i]))
+ if (isAtomic(Element<std::string>(_configuration[i])))
states.push_back(_configuration[i]);
}
states.to_document_order();
@@ -378,7 +378,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterDraft6::selectTransitions(const
bool foundTransition = false;
NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", states[index]);
for (unsigned int k = 0; k < transitions.size(); k++) {
- if (isEnabledTransition(transitions[k], event)) {
+ if (isEnabledTransition(Element<std::string>(transitions[k]), event)) {
enabledTransitions.push_back(transitions[k]);
foundTransition = true;
goto LOOP;
@@ -407,7 +407,7 @@ LOOP:
return enabledTransitions;
}
-bool InterpreterDraft6::isEnabledTransition(const Node<std::string>& transition, const std::string& event) {
+bool InterpreterDraft6::isEnabledTransition(const Element<std::string>& transition, const std::string& event) {
std::string eventName;
if (HAS_ATTR(transition, "event")) {
eventName = ATTR(transition, "event");
@@ -438,7 +438,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterDraft6::selectEventlessTransitio
NodeSet<std::string> states;
for (unsigned int i = 0; i < _configuration.size(); i++) {
- if (isAtomic(_configuration[i]))
+ if (isAtomic(Element<std::string>(_configuration[i])))
states.push_back(_configuration[i]);
}
states.to_document_order();
@@ -456,7 +456,8 @@ Arabica::XPath::NodeSet<std::string> InterpreterDraft6::selectEventlessTransitio
bool foundTransition = false;
NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", states[index]);
for (unsigned int k = 0; k < transitions.size(); k++) {
- if (!HAS_ATTR(transitions[k], "event") && hasConditionMatch(transitions[k])) {
+ Element<std::string> transElem(transitions[k]);
+ if (!HAS_ATTR(transElem, "event") && hasConditionMatch(transElem)) {
enabledTransitions.push_back(transitions[k]);
foundTransition = true;
goto LOOP;
@@ -487,12 +488,12 @@ LOOP:
Arabica::XPath::NodeSet<std::string> InterpreterDraft6::filterPreempted(const Arabica::XPath::NodeSet<std::string>& enabledTransitions) {
Arabica::XPath::NodeSet<std::string> filteredTransitions;
for (unsigned int i = 0; i < enabledTransitions.size(); i++) {
- Node<std::string> t = enabledTransitions[i];
+ Element<std::string> t(enabledTransitions[i]);
if (!isTargetless(t)) {
for (unsigned int j = 0; j < filteredTransitions.size(); j++) {
if (j == i)
continue;
- Node<std::string> t2 = filteredTransitions[j];
+ Element<std::string> t2(filteredTransitions[j]);
if (isPreemptingTransition(t2, t)) {
#if 0
std::cout << "#####" << std::endl << "Transition " << std::endl
@@ -518,7 +519,7 @@ LOOP:
/**
* Is t1 preempting t2?
*/
-bool InterpreterDraft6::isPreemptingTransition(const Node<std::string>& t1, const Node<std::string>& t2) {
+bool InterpreterDraft6::isPreemptingTransition(const Element<std::string>& t1, const Element<std::string>& t2) {
assert(t1);
assert(t2);
@@ -538,13 +539,13 @@ bool InterpreterDraft6::isPreemptingTransition(const Node<std::string>& t1, cons
return false;
}
-bool InterpreterDraft6::isCrossingBounds(const Node<std::string>& transition) {
+bool InterpreterDraft6::isCrossingBounds(const Element<std::string>& transition) {
if (!isTargetless(transition) && !isWithinParallel(transition))
return true;
return false;
}
-bool InterpreterDraft6::isWithinParallel(const Node<std::string>& transition) {
+bool InterpreterDraft6::isWithinParallel(const Element<std::string>& transition) {
if (isTargetless(transition))
return false;
@@ -565,7 +566,7 @@ Node<std::string> InterpreterDraft6::findLCPA(const Arabica::XPath::NodeSet<std:
Arabica::XPath::NodeSet<std::string> ancestors = getProperAncestors(states[0], Node<std::string>());
Node<std::string> ancestor;
for (int i = 0; i < ancestors.size(); i++) {
- if (!isParallel(ancestors[i]))
+ if (!isParallel(Element<std::string>(ancestors[i])))
continue;
for (int j = 0; j < states.size(); j++) {
if (!isDescendant(states[j], ancestors[i]) && (states[j] != ancestors[i]))
@@ -623,14 +624,15 @@ void InterpreterDraft6::exitInterpreter() {
for (int i = 0; i < statesToExit.size(); i++) {
Arabica::XPath::NodeSet<std::string> onExitElems = filterChildElements(_nsInfo.xmlNSPrefix + "onexit", statesToExit[i]);
for (int j = 0; j < onExitElems.size(); j++) {
- executeContent(onExitElems[j]);
+ executeContent(Element<std::string>(onExitElems[j]));
}
Arabica::XPath::NodeSet<std::string> invokeElems = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]);
// TODO: we ought to cancel all remaining invokers just to be sure with the persist extension
for (int j = 0; j < invokeElems.size(); j++) {
cancelInvoke(invokeElems[j]);
}
- if (isFinal(statesToExit[i]) && parentIsScxmlState(statesToExit[i])) {
+ Element<std::string> stateElem(statesToExit[i]);
+ if (isFinal(stateElem) && parentIsScxmlState(stateElem)) {
returnDoneEvent(statesToExit[i]);
}
}
@@ -664,7 +666,7 @@ void InterpreterDraft6::exitStates(const Arabica::XPath::NodeSet<std::string>& e
break;
}
}
- if (isInternal && allDescendants && isCompound(source)) {
+ if (isInternal && allDescendants && isCompound(Element<std::string>(source))) {
ancestor = source;
} else {
NodeSet<std::string> tmpStates;
@@ -717,7 +719,7 @@ void InterpreterDraft6::exitStates(const Arabica::XPath::NodeSet<std::string>& e
NodeSet<std::string> historyNodes;
for (int k = 0; k < _configuration.size(); k++) {
if (iequals(historyType, "deep")) {
- if (isAtomic(_configuration[k]) && isDescendant(_configuration[k], statesToExit[i]))
+ if (isAtomic(Element<std::string>(_configuration[k])) && isDescendant(_configuration[k], statesToExit[i]))
historyNodes.push_back(_configuration[k]);
} else {
if (_configuration[k].getParentNode() == statesToExit[i])
@@ -812,7 +814,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet<std::string>&
}
}
if (iequals(transitionType, "internal") &&
- isCompound(source) &&
+ isCompound(Element<std::string>(source)) &&
allDescendants) {
ancestor = source;
} else {
@@ -828,7 +830,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet<std::string>&
#endif
for (int j = 0; j < tStates.size(); j++) {
- addStatesToEnter(tStates[j], statesToEnter, statesForDefaultEntry, defaultHistoryContent);
+ addStatesToEnter(Element<std::string>(tStates[j]), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
#if VERBOSE
@@ -852,7 +854,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet<std::string>&
for (int k = 0; k < ancestors.size(); k++) {
statesToEnter.push_back(ancestors[k]);
- if(isParallel(ancestors[k])) {
+ if(isParallel(Element<std::string>(ancestors[k]))) {
NodeSet<std::string> childs = getChildStates(ancestors[k]);
for (int l = 0; l < childs.size(); l++) {
bool someIsDescendant = false;
@@ -863,7 +865,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet<std::string>&
}
}
if (!someIsDescendant) {
- addStatesToEnter(childs[l], statesToEnter, statesForDefaultEntry, defaultHistoryContent);
+ addStatesToEnter(Element<std::string>(childs[l]), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
}
}
@@ -929,7 +931,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet<std::string>&
// execute initial transition content for compound states
Arabica::XPath::NodeSet<std::string> transitions = _xpath.evaluate("" + _nsInfo.xpathPrefix + "initial/" + _nsInfo.xpathPrefix + "transition", stateElem).asNodeSet();
for (int j = 0; j < transitions.size(); j++) {
- executeContent(transitions[j]);
+ executeContent(Element<std::string>(transitions[j]));
}
}
@@ -945,21 +947,23 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet<std::string>&
#endif
if (isFinal(stateElem)) {
internalDoneSend(stateElem);
- Element<std::string> parent = (Element<std::string>)stateElem.getParentNode();
-
- if (isParallel(parent.getParentNode())) {
+ Node<std::string> parent = stateElem.getParentNode();
+
+ if (parent.getNodeType() == Node_base::ELEMENT_NODE &&
+ parent.getParentNode().getNodeType() == Node_base::ELEMENT_NODE &&
+ isParallel(Element<std::string>(parent.getParentNode()))) {
Element<std::string> grandParent = (Element<std::string>)parent.getParentNode();
Arabica::XPath::NodeSet<std::string> childs = getChildStates(grandParent);
bool inFinalState = true;
for (int j = 0; j < childs.size(); j++) {
- if (!isInFinalState(childs[j])) {
+ if (!isInFinalState(Element<std::string>(childs[j]))) {
inFinalState = false;
break;
}
}
if (inFinalState) {
- internalDoneSend(parent);
+ internalDoneSend(Element<std::string>(parent));
}
}
}
@@ -972,7 +976,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet<std::string>&
}
}
-void InterpreterDraft6::addStatesToEnter(const Node<std::string>& state,
+void InterpreterDraft6::addStatesToEnter(const Element<std::string>& state,
Arabica::XPath::NodeSet<std::string>& statesToEnter,
Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry,
Arabica::XPath::NodeSet<std::string>& defaultHistoryContent) {
@@ -994,7 +998,7 @@ void InterpreterDraft6::addStatesToEnter(const Node<std::string>& state,
#endif
for (int i = 0; i < historyValue.size(); i++) {
- addStatesToEnter(historyValue[i], statesToEnter, statesForDefaultEntry, defaultHistoryContent);
+ addStatesToEnter(Element<std::string>(historyValue[i]), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
NodeSet<std::string> ancestors = getProperAncestors(historyValue[i], state);
#if VERBOSE
@@ -1013,9 +1017,9 @@ void InterpreterDraft6::addStatesToEnter(const Node<std::string>& state,
defaultHistoryContent.push_back(getParentState(state));
NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", state);
for (int i = 0; i < transitions.size(); i++) {
- NodeSet<std::string> targets = getTargetStates(transitions[i]);
+ NodeSet<std::string> targets = getTargetStates(Element<std::string>(transitions[i]));
for (int j = 0; j < targets.size(); j++) {
- addStatesToEnter(targets[j], statesToEnter, statesForDefaultEntry, defaultHistoryContent);
+ addStatesToEnter(Element<std::string>(targets[j]), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
// Modifications from chris nuernberger
NodeSet<std::string> ancestors = getProperAncestors(targets[j], state);
@@ -1032,7 +1036,7 @@ void InterpreterDraft6::addStatesToEnter(const Node<std::string>& state,
NodeSet<std::string> tStates = getInitialStates(state);
for (int i = 0; i < tStates.size(); i++) {
- addStatesToEnter(tStates[i], statesToEnter, statesForDefaultEntry, defaultHistoryContent);
+ addStatesToEnter(Element<std::string>(tStates[i]), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
// addStatesToEnter(getInitialState(state), statesToEnter, statesForDefaultEntry);
@@ -1041,7 +1045,7 @@ void InterpreterDraft6::addStatesToEnter(const Node<std::string>& state,
} else if(isParallel(state)) {
NodeSet<std::string> childStates = getChildStates(state);
for (int i = 0; i < childStates.size(); i++) {
- addStatesToEnter(childStates[i], statesToEnter, statesForDefaultEntry, defaultHistoryContent);
+ addStatesToEnter(Element<std::string>(childStates[i]), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
}
}
diff --git a/src/uscxml/interpreter/InterpreterDraft6.h b/src/uscxml/interpreter/InterpreterDraft6.h
index cf73d4b..297434f 100644
--- a/src/uscxml/interpreter/InterpreterDraft6.h
+++ b/src/uscxml/interpreter/InterpreterDraft6.h
@@ -35,7 +35,7 @@ protected:
void microstep(const Arabica::XPath::NodeSet<std::string>& enabledTransitions);
void enterStates(const Arabica::XPath::NodeSet<std::string>& enabledTransitions);
- void addStatesToEnter(const Arabica::DOM::Node<std::string>& state,
+ void addStatesToEnter(const Arabica::DOM::Element<std::string>& state,
Arabica::XPath::NodeSet<std::string>& statesToEnter,
Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry,
Arabica::XPath::NodeSet<std::string>& defaultHistoryContent);
@@ -46,13 +46,13 @@ protected:
Arabica::XPath::NodeSet<std::string> selectEventlessTransitions();
Arabica::XPath::NodeSet<std::string> selectTransitions(const std::string& event);
Arabica::XPath::NodeSet<std::string> filterPreempted(const Arabica::XPath::NodeSet<std::string>& enabledTransitions);
- bool isPreemptingTransition(const Arabica::DOM::Node<std::string>& t1, const Arabica::DOM::Node<std::string>& t2);
- bool isEnabledTransition(const Arabica::DOM::Node<std::string>& transition, const std::string& event);
+ bool isPreemptingTransition(const Arabica::DOM::Element<std::string>& t1, const Arabica::DOM::Element<std::string>& t2);
+ bool isEnabledTransition(const Arabica::DOM::Element<std::string>& transition, const std::string& event);
Arabica::XPath::NodeSet<std::string> getDocumentInitialTransitions();
- bool isCrossingBounds(const Arabica::DOM::Node<std::string>& transition);
- bool isWithinParallel(const Arabica::DOM::Node<std::string>& transition);
+ bool isCrossingBounds(const Arabica::DOM::Element<std::string>& transition);
+ bool isWithinParallel(const Arabica::DOM::Element<std::string>& transition);
Arabica::DOM::Node<std::string> findLCPA(const Arabica::XPath::NodeSet<std::string>& states);
};
diff --git a/src/uscxml/interpreter/InterpreterRC.cpp b/src/uscxml/interpreter/InterpreterRC.cpp
index 53feae8..3d17c87 100644
--- a/src/uscxml/interpreter/InterpreterRC.cpp
+++ b/src/uscxml/interpreter/InterpreterRC.cpp
@@ -111,7 +111,7 @@ InterpreterState InterpreterRC::interpret() {
NodeSet<std::string> globalScriptElems = filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml);
for (unsigned int i = 0; i < globalScriptElems.size(); i++) {
if (_dataModel) {
- executeContent(globalScriptElems[i]);
+ executeContent(Element<std::string>(globalScriptElems[i]));
}
}
@@ -414,14 +414,15 @@ void InterpreterRC::exitInterpreter() {
for (int i = 0; i < statesToExit.size(); i++) {
Arabica::XPath::NodeSet<std::string> onExitElems = filterChildElements(_nsInfo.xmlNSPrefix + "onexit", statesToExit[i]);
for (int j = 0; j < onExitElems.size(); j++) {
- executeContent(onExitElems[j]);
+ executeContent(Element<std::string>(onExitElems[j]));
}
Arabica::XPath::NodeSet<std::string> invokeElems = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]);
for (int j = 0; j < invokeElems.size(); j++) {
cancelInvoke(invokeElems[j]);
}
- if (isFinal(statesToExit[i]) && parentIsScxmlState(statesToExit[i])) {
- returnDoneEvent(statesToExit[i]);
+ Element<std::string> stateElem(statesToExit[i]);
+ if (isFinal(stateElem) && parentIsScxmlState(stateElem)) {
+ returnDoneEvent(stateElem);
}
}
_configuration = NodeSet<std::string>();
@@ -445,7 +446,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterRC::selectEventlessTransitions()
NodeSet<std::string> atomicStates;
for (unsigned int i = 0; i < _configuration.size(); i++) {
- if (isAtomic(_configuration[i]))
+ if (isAtomic(Element<std::string>(_configuration[i])))
atomicStates.push_back(_configuration[i]);
}
atomicStates.to_document_order();
@@ -459,7 +460,8 @@ Arabica::XPath::NodeSet<std::string> InterpreterRC::selectEventlessTransitions()
const Node<std::string>& ancestor = withAncestors[i];
NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", ancestor);
for (unsigned int k = 0; k < transitions.size(); k++) {
- if (!HAS_ATTR(transitions[k], "event") && hasConditionMatch(transitions[k])) {
+ Element<std::string> transElem(transitions[k]);
+ if (!HAS_ATTR(transElem, "event") && hasConditionMatch(transElem)) {
enabledTransitions.push_back(transitions[k]);
goto BREAK_LOOP;
}
@@ -491,7 +493,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterRC::selectTransitions(const std:
NodeSet<std::string> atomicStates;
for (unsigned int i = 0; i < _configuration.size(); i++) {
- if (isAtomic(_configuration[i]))
+ if (isAtomic(Element<std::string>(_configuration[i])))
atomicStates.push_back(_configuration[i]);
}
atomicStates.to_document_order();
@@ -512,7 +514,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterRC::selectTransitions(const std:
const Node<std::string>& ancestor = withAncestors[j];
NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", ancestor);
for (unsigned int k = 0; k < transitions.size(); k++) {
- if (isEnabledTransition(transitions[k], event)) {
+ if (isEnabledTransition(Element<std::string>(transitions[k]), event)) {
enabledTransitions.push_back(transitions[k]);
goto BREAK_LOOP;
}
@@ -535,7 +537,7 @@ BREAK_LOOP:
return enabledTransitions;
}
-bool InterpreterRC::isEnabledTransition(const Node<std::string>& transition, const std::string& event) {
+bool InterpreterRC::isEnabledTransition(const Element<std::string>& transition, const std::string& event) {
std::string eventName;
if (HAS_ATTR(transition, "event")) {
eventName = ATTR(transition, "event");
@@ -587,12 +589,12 @@ Arabica::XPath::NodeSet<std::string> InterpreterRC::removeConflictingTransitions
Arabica::XPath::NodeSet<std::string> filteredTransitions;
for (unsigned int i = 0; i < enabledTransitions.size(); i++) {
- const Node<std::string>& t1 = enabledTransitions[i];
+ Element<std::string> t1(enabledTransitions[i]);
bool t1Preempted = false;
Arabica::XPath::NodeSet<std::string> transitionsToRemove;
for (unsigned int j = 0; j < filteredTransitions.size(); j++) {
- const Node<std::string>& t2 = enabledTransitions[j];
+ Element<std::string> t2(enabledTransitions[j]);
if (hasIntersection(computeExitSet(t1), computeExitSet(t2))) {
if (isDescendant(getSourceState(t1), getSourceState(t2))) {
transitionsToRemove.push_back(t2);
@@ -702,7 +704,7 @@ void InterpreterRC::exitStates(const Arabica::XPath::NodeSet<std::string>& enabl
NodeSet<std::string> historyNodes;
for (int k = 0; k < _configuration.size(); k++) {
if (iequals(historyType, "deep")) {
- if (isAtomic(_configuration[k]) && isDescendant(_configuration[k], statesToExit[i]))
+ if (isAtomic(Element<std::string>(_configuration[k])) && isDescendant(_configuration[k], statesToExit[i]))
historyNodes.push_back(_configuration[k]);
} else {
if (_configuration[k].getParentNode() == statesToExit[i])
@@ -757,7 +759,7 @@ function computeExitSet(transitions)
Arabica::XPath::NodeSet<std::string> InterpreterRC::computeExitSet(const Arabica::XPath::NodeSet<std::string>& transitions) {
NodeSet<std::string> statesToExit;
for (unsigned int i = 0; i < transitions.size(); i++) {
- const Node<std::string>& t = transitions[i];
+ Element<std::string> t(transitions[i]);
if (isTargetless(t))
continue;
Arabica::DOM::Node<std::string> domain = getTransitionDomain(t);
@@ -852,12 +854,10 @@ void InterpreterRC::enterStates(const Arabica::XPath::NodeSet<std::string>& enab
if (isMember(s, statesForDefaultEntry)) {
// execute initial transition content for compound states
Arabica::XPath::NodeSet<std::string> transitions = _xpath.evaluate("" + _nsInfo.xpathPrefix + "initial/" + _nsInfo.xpathPrefix + "transition", s).asNodeSet();
- for (int j = 0; j < transitions.size(); j++) {
- executeContent(transitions[j]);
- }
+ executeContent(transitions);
}
if (defaultHistoryContent.find(ATTR(s, "id")) != defaultHistoryContent.end()) {
- executeContent(defaultHistoryContent[ATTR(s, "id")]);
+ executeContent(Element<std::string>(defaultHistoryContent[ATTR(s, "id")]));
}
/**
@@ -920,7 +920,7 @@ void InterpreterRC::computeEntrySet(const Arabica::XPath::NodeSet<std::string>&
NodeSet<std::string>& statesForDefaultEntry,
std::map<std::string, Arabica::DOM::Node<std::string> > defaultHistoryContent) {
for (int i = 0; i < transitions.size(); i++) {
- const Node<std::string>& t = transitions[i];
+ Element<std::string> t(transitions[i]);
NodeSet<std::string> targets = getTargetStates(t);
for (int j = 0; j < targets.size(); j++) {
@@ -1010,7 +1010,7 @@ void InterpreterRC::addDescendantStatesToEnter(const Arabica::DOM::Node<std::str
Arabica::XPath::NodeSet<std::string>& statesToEnter,
Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry,
std::map<std::string, Arabica::DOM::Node<std::string> > defaultHistoryContent) {
- if (isHistory(state)) {
+ if (isHistory(Element<std::string>(state))) {
std::string stateId = ATTR(state, "id");
if (_historyValue.find(stateId) != _historyValue.end()) {
const Arabica::XPath::NodeSet<std::string>& historyValue = _historyValue[stateId];
@@ -1028,7 +1028,7 @@ void InterpreterRC::addDescendantStatesToEnter(const Arabica::DOM::Node<std::str
LOG(ERROR) << "Only one transition allowed in history";
}
for (int i = 0; i < transitions.size(); i++) {
- NodeSet<std::string> targets = getTargetStates(transitions[i]);
+ NodeSet<std::string> targets = getTargetStates(Element<std::string>(transitions[i]));
for (int j = 0; j < targets.size(); j++) {
const Node<std::string>& s = targets[i];
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent);
@@ -1040,15 +1040,15 @@ void InterpreterRC::addDescendantStatesToEnter(const Arabica::DOM::Node<std::str
if (!isMember(state, statesToEnter)) // adding an existing element invalidates old reference
statesToEnter.push_back(state);
- if (isCompound(state)) {
+ if (isCompound(Element<std::string>(state))) {
statesForDefaultEntry.push_back(state);
- NodeSet<std::string> targets = getInitialStates(state);
+ NodeSet<std::string> targets = getInitialStates(Element<std::string>(state));
for (int i = 0; i < targets.size(); i++) {
const Node<std::string>& s = targets[i];
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent);
addAncestorStatesToEnter(s, getParentState(s), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
- } else if(isParallel(state)) {
+ } else if(isParallel(Element<std::string>(state))) {
// if state is a parallel state, recursively call addStatesToEnter on any of its child
// states that don't already have a descendant on statesToEnter.
NodeSet<std::string> childStates = getChildStates(state);
@@ -1087,7 +1087,7 @@ void InterpreterRC::addAncestorStatesToEnter(const Arabica::DOM::Node<std::strin
for (int i = 0; i < ancestors.size(); i++) {
const Node<std::string>& anc = ancestors[i];
statesToEnter.push_back(anc);
- if (isParallel(anc)) {
+ if (isParallel(Element<std::string>(anc))) {
NodeSet<std::string> childStates = getChildStates(anc);
for (int j = 0; j < childStates.size(); j++) {
const Node<std::string>& child = childStates[j];
@@ -1115,13 +1115,13 @@ function isInFinalState(s):
return false
*/
bool InterpreterRC::isInFinalState(const Arabica::DOM::Node<std::string>& state) {
- if (isCompound(state)) {
+ if (isCompound(Element<std::string>(state))) {
Arabica::XPath::NodeSet<std::string> childs = getChildStates(state);
for (int i = 0; i < childs.size(); i++) {
- if (isFinal(childs[i]) && isMember(childs[i], _configuration))
+ if (isFinal(Element<std::string>(childs[i])) && isMember(childs[i], _configuration))
return true;
}
- } else if (isParallel(state)) {
+ } else if (isParallel(Element<std::string>(state))) {
Arabica::XPath::NodeSet<std::string> childs = getChildStates(state);
for (int i = 0; i < childs.size(); i++) {
if (!isInFinalState(childs[i]))
@@ -1143,7 +1143,7 @@ function getTransitionDomain(t)
else:
return findLCCA([t.source].append(tstates))
*/
-Arabica::DOM::Node<std::string> InterpreterRC::getTransitionDomain(const Arabica::DOM::Node<std::string>& transition) {
+Arabica::DOM::Node<std::string> InterpreterRC::getTransitionDomain(const Arabica::DOM::Element<std::string>& transition) {
NodeSet<std::string> tStates = getTargetStates(transition);
Node<std::string> source = getSourceState(transition);
@@ -1156,7 +1156,7 @@ Arabica::DOM::Node<std::string> InterpreterRC::getTransitionDomain(const Arabica
}
std::string transitionType = (HAS_ATTR(transition, "type") ? ATTR(transition, "type") : "external");
- if (iequals(transitionType, "internal") && isCompound(source)) {
+ if (iequals(transitionType, "internal") && isCompound(Element<std::string>(source))) {
for (int i = 0; i < tStates.size(); i++) {
const Node<std::string>& s = tStates[i];
if (!isDescendant(s, source))
@@ -1184,7 +1184,7 @@ Arabica::DOM::Node<std::string> InterpreterRC::findLCCA(const Arabica::XPath::No
// ancestors.push_back(states[0]); // state[0] may already be the ancestor - bug in W3C spec?
Arabica::DOM::Node<std::string> ancestor;
for (int i = 0; i < ancestors.size(); i++) {
- if (!isCompound(ancestors[i]))
+ if (!isCompound(Element<std::string>(ancestors[i])))
continue;
for (int j = 0; j < states.size(); j++) {
if (!isDescendant(states[j], ancestors[i]) && (states[j] != ancestors[i]))
@@ -1215,7 +1215,7 @@ NEXT_ANCESTOR:
Arabica::XPath::NodeSet<std::string> InterpreterRC::getProperAncestors(const Arabica::DOM::Node<std::string>& state1, const Arabica::DOM::Node<std::string>& state2) {
NodeSet<std::string> ancestors;
- if (!state1 || !isState(state1))
+ if (!state1 || !isState(Element<std::string>(state1)))
return ancestors;
if (!state2) {
@@ -1225,7 +1225,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterRC::getProperAncestors(const Ara
including the <scxml> element).
*/
Arabica::DOM::Node<std::string> parent = state1.getParentNode();
- while(parent && isState(parent)) {
+ while(parent && isState(Element<std::string>(parent))) {
ancestors.push_back(parent);
parent = parent.getParentNode();
}
@@ -1245,14 +1245,14 @@ Arabica::XPath::NodeSet<std::string> InterpreterRC::getProperAncestors(const Ara
of state1, up to but not including state2.
*/
Arabica::DOM::Node<std::string> parent = state1.getParentNode();
- while(parent && isState(parent) && parent != state2) {
+ while(parent && isState(Element<std::string>(parent)) && parent != state2) {
ancestors.push_back(parent);
parent = parent.getParentNode();
}
return ancestors;
}
-NodeSet<std::string> InterpreterRC::getTargetStates(const Arabica::DOM::Node<std::string>& transition) {
+NodeSet<std::string> InterpreterRC::getTargetStates(const Arabica::DOM::Element<std::string>& transition) {
NodeSet<std::string> targetStates;
std::string targetId = ((Arabica::DOM::Element<std::string>)transition).getAttribute("target");
diff --git a/src/uscxml/interpreter/InterpreterRC.h b/src/uscxml/interpreter/InterpreterRC.h
index 2cd2662..9afc2e6 100644
--- a/src/uscxml/interpreter/InterpreterRC.h
+++ b/src/uscxml/interpreter/InterpreterRC.h
@@ -33,7 +33,7 @@ class InterpreterRC : public InterpreterImpl {
Arabica::XPath::NodeSet<std::string> selectEventlessTransitions();
Arabica::XPath::NodeSet<std::string> selectTransitions(const std::string& event);
- bool isEnabledTransition(const Arabica::DOM::Node<std::string>& transition, const std::string& event);
+ bool isEnabledTransition(const Arabica::DOM::Element<std::string>& transition, const std::string& event);
bool hasIntersection(const Arabica::XPath::NodeSet<std::string>& nodeSet1, const Arabica::XPath::NodeSet<std::string>& nodeSet2);
void enterStates(const Arabica::XPath::NodeSet<std::string>& enabledTransitions);
@@ -52,7 +52,7 @@ class InterpreterRC : public InterpreterImpl {
std::map<std::string, Arabica::DOM::Node<std::string> > defaultHistoryContent);
Arabica::XPath::NodeSet<std::string> removeConflictingTransitions(const Arabica::XPath::NodeSet<std::string>& enabledTransitions);
- Arabica::DOM::Node<std::string> getTransitionDomain(const Arabica::DOM::Node<std::string>& transition);
+ Arabica::DOM::Node<std::string> getTransitionDomain(const Arabica::DOM::Element<std::string>& transition);
void addDescendantStatesToEnter(const Arabica::DOM::Node<std::string>& state,
Arabica::XPath::NodeSet<std::string>& statesToEnter,
@@ -71,7 +71,7 @@ class InterpreterRC : public InterpreterImpl {
Arabica::XPath::NodeSet<std::string> getProperAncestors(const Arabica::DOM::Node<std::string>& s1,
const Arabica::DOM::Node<std::string>& s2);
- Arabica::XPath::NodeSet<std::string> getTargetStates(const Arabica::DOM::Node<std::string>& transition);
+ Arabica::XPath::NodeSet<std::string> getTargetStates(const Arabica::DOM::Element<std::string>& transition);
#if 0
bool isDescendant(const Arabica::DOM::Node<std::string>& state1, const Arabica::DOM::Node<std::string>& state2);
diff --git a/src/uscxml/transform/ChartToFSM.cpp b/src/uscxml/transform/ChartToFSM.cpp
index fea97d8..cc94434 100644
--- a/src/uscxml/transform/ChartToFSM.cpp
+++ b/src/uscxml/transform/ChartToFSM.cpp
@@ -182,7 +182,7 @@ InterpreterState FlatteningInterpreter::interpret() {
return _state;
}
-void FlatteningInterpreter::executeContent(const Arabica::DOM::Node<std::string>& content, bool rethrow) {
+void FlatteningInterpreter::executeContent(const Arabica::DOM::Element<std::string>& content, bool rethrow) {
// std::cout << content << std::endl;
GlobalTransition::Action action;
@@ -199,19 +199,6 @@ void FlatteningInterpreter::executeContent(const Arabica::DOM::Node<std::string>
_currGlobalTransition->actions.push_back(action);
}
-void FlatteningInterpreter::executeContent(const Arabica::DOM::NodeList<std::string>& content, bool rethrow) {
- for (int i = 0; i < content.getLength(); i++) {
- executeContent(content.item(i));
- }
- assert(false);
-}
-
-void FlatteningInterpreter::executeContent(const Arabica::XPath::NodeSet<std::string>& content, bool rethrow) {
- for (int i = 0; i < content.size(); i++) {
- executeContent(content[i]);
- }
-}
-
void FlatteningInterpreter::invoke(const Arabica::DOM::Node<std::string>& element) {
GlobalTransition::Action action;
action.invoke = element;
@@ -226,10 +213,8 @@ void FlatteningInterpreter::cancelInvoke(const Arabica::DOM::Node<std::string>&
_currGlobalTransition->uninvoke.push_back(element);
}
-void FlatteningInterpreter::internalDoneSend(const Arabica::DOM::Node<std::string>& state) {
+void FlatteningInterpreter::internalDoneSend(const Arabica::DOM::Element<std::string>& state) {
- if (!isState(state))
- return;
Arabica::DOM::Element<std::string> stateElem = (Arabica::DOM::Element<std::string>)state;
// if (parentIsScxmlState(state))
@@ -906,7 +891,7 @@ GlobalState::GlobalState(const Arabica::XPath::NodeSet<std::string>& activeState
std::ostringstream idSS;
idSS << "active-";
for (int i = 0; i < activeStates.size(); i++) {
- if (!InterpreterImpl::isFinal(activeStates[i]))
+ if (!InterpreterImpl::isFinal(Element<std::string>(activeStates[i])))
isFinal = false;
idSS << ATTR(activeStates[i], "id") << "-";
}
diff --git a/src/uscxml/transform/ChartToFSM.h b/src/uscxml/transform/ChartToFSM.h
index 07531e2..dba8d4d 100644
--- a/src/uscxml/transform/ChartToFSM.h
+++ b/src/uscxml/transform/ChartToFSM.h
@@ -109,9 +109,7 @@ public:
protected:
// gather executable content per microstep
- void executeContent(const Arabica::DOM::Node<std::string>& content, bool rethrow = false);
- void executeContent(const Arabica::DOM::NodeList<std::string>& content, bool rethrow = false);
- void executeContent(const Arabica::XPath::NodeSet<std::string>& content, bool rethrow = false);
+ void executeContent(const Arabica::DOM::Element<std::string>& content, bool rethrow = false);
// invoke and uninvoke
virtual void invoke(const Arabica::DOM::Node<std::string>& element);
@@ -119,7 +117,7 @@ protected:
// override to do nothing
void send(const Arabica::DOM::Node<std::string>& element) {}
- void internalDoneSend(const Arabica::DOM::Node<std::string>& state);
+ void internalDoneSend(const Arabica::DOM::Element<std::string>& state);
// InterpreterMonitor
virtual void beforeMicroStep(Interpreter interpreter);
diff --git a/src/uscxml/transform/FSMToPromela.cpp b/src/uscxml/transform/FSMToPromela.cpp
index d72dccb..3607071 100644
--- a/src/uscxml/transform/FSMToPromela.cpp
+++ b/src/uscxml/transform/FSMToPromela.cpp
@@ -317,7 +317,7 @@ void FSMToPromela::writeExecutableContent(std::ostream& stream, const Arabica::D
}
stream << padding << "}" << std::endl;
- if (isFinal(newState)) {
+ if (isFinal(Element<std::string>(newState))) {
stream << padding << "goto terminate;" << std::endl;
} else {
stream << padding << "goto nextStep;" << std::endl;