diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-08-03 12:10:57 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-08-03 12:10:57 (GMT) |
commit | 6e1a4a67d5b17e92135cd3f5daf51bf044d76e40 (patch) | |
tree | 63d8de9a5ba99dbcd16c6bd867241a7e7466c559 /src/uscxml/transform | |
parent | 37f8735a66aadd0e3f019f5edbb9356cf4a7b974 (diff) | |
download | uscxml-6e1a4a67d5b17e92135cd3f5daf51bf044d76e40.zip uscxml-6e1a4a67d5b17e92135cd3f5daf51bf044d76e40.tar.gz uscxml-6e1a4a67d5b17e92135cd3f5daf51bf044d76e40.tar.bz2 |
Got rid of more dynamic_casts
Diffstat (limited to 'src/uscxml/transform')
-rw-r--r-- | src/uscxml/transform/ChartToFSM.cpp | 53 | ||||
-rw-r--r-- | src/uscxml/transform/ChartToFSM.h | 20 | ||||
-rw-r--r-- | src/uscxml/transform/FSMToCPP.cpp | 59 | ||||
-rw-r--r-- | src/uscxml/transform/FSMToCPP.h | 14 | ||||
-rw-r--r-- | src/uscxml/transform/FSMToPromela.cpp | 64 | ||||
-rw-r--r-- | src/uscxml/transform/FSMToPromela.h | 10 |
6 files changed, 112 insertions, 108 deletions
diff --git a/src/uscxml/transform/ChartToFSM.cpp b/src/uscxml/transform/ChartToFSM.cpp index 820e3bc..83b8195 100644 --- a/src/uscxml/transform/ChartToFSM.cpp +++ b/src/uscxml/transform/ChartToFSM.cpp @@ -216,7 +216,7 @@ InterpreterState FlatteningInterpreter::interpret() { initialElem.setAttribute("generated", "true"); Element<std::string> transitionElem = _document.createElementNS(_nsInfo.nsURL, "transition"); _nsInfo.setPrefix(transitionElem); - transitionElem.setAttribute("target", ATTR(initialStates[i], "id")); + transitionElem.setAttribute("target", ATTR_CAST(initialStates[i], "id")); initialElem.appendChild(transitionElem); _scxml.appendChild(initialElem); initialTransitions.push_back(transitionElem); @@ -277,14 +277,14 @@ void FlatteningInterpreter::executeContent(const Arabica::DOM::Element<std::stri _currGlobalTransition->actions.push_back(action); } -void FlatteningInterpreter::invoke(const Arabica::DOM::Node<std::string>& element) { +void FlatteningInterpreter::invoke(const Arabica::DOM::Element<std::string>& element) { GlobalTransition::Action action; action.invoke = element; _currGlobalTransition->actions.push_back(action); _currGlobalTransition->invoke.push_back(element); } -void FlatteningInterpreter::cancelInvoke(const Arabica::DOM::Node<std::string>& element) { +void FlatteningInterpreter::cancelInvoke(const Arabica::DOM::Element<std::string>& element) { GlobalTransition::Action action; action.uninvoke = element; _currGlobalTransition->actions.push_back(action); @@ -323,7 +323,7 @@ void FlatteningInterpreter::internalDoneSend(const Arabica::DOM::Element<std::st } } - raise.setAttribute("event", "done.state." + ATTR(stateElem.getParentNode(), "id")); // parent?! + raise.setAttribute("event", "done.state." + ATTR_CAST(stateElem.getParentNode(), "id")); // parent?! GlobalTransition::Action action; action.onEntry = onentry; @@ -379,8 +379,8 @@ static bool filterChildEnabled(const NodeSet<std::string>& transitions) { p2 = p2.getParentNode(); // TODO: think about again! while(p2) { if (p1 == p2) { - std::string eventDesc1 = ATTR(t1, "event"); - std::string eventDesc2 = ATTR(t2, "event"); + std::string eventDesc1 = ATTR_CAST(t1, "event"); + std::string eventDesc2 = ATTR_CAST(t2, "event"); if (InterpreterImpl::nameMatch(eventDesc1, eventDesc2)) { return false; } @@ -453,7 +453,7 @@ void FlatteningInterpreter::explode() { for (unsigned int i = 0; i < _statesToInvoke.size(); i++) { NodeSet<std::string> invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); for (unsigned int j = 0; j < invokes.size(); j++) { - invoke(invokes[j]); + invoke(Element<std::string>(invokes[j])); } } _statesToInvoke = NodeSet<std::string>(); @@ -595,11 +595,11 @@ void FlatteningInterpreter::explode() { int nrDepth = 0; int prioPerLevel = 0; for (int i = 0; i < transitions.size(); i++) { - int depth = strTo<int>(ATTR(transitions[i], "depth")); + int depth = strTo<int>(ATTR_CAST(transitions[i], "depth")); if (depth != currDepth) continue; nrDepth++; - int order = strTo<int>(ATTR(transitions[i], "order")); + int order = strTo<int>(ATTR_CAST(transitions[i], "order")); if (order < lowestOrder) lowestOrder = order; prioPerLevel += pow(static_cast<double>(maxOrder), maxOrder - order); @@ -673,7 +673,7 @@ NEXT_DEPTH: } void FlatteningInterpreter::createDocument() { - Node<std::string> _origSCXML = _scxml; + Element<std::string> _origSCXML = _scxml; _scxml = _flatDoc.createElementNS(_nsInfo.nsURL, "scxml"); _nsInfo.setPrefix(_scxml); @@ -952,10 +952,11 @@ void FlatteningInterpreter::labelTransitions() { Arabica::XPath::NodeSet<std::string> states = getAllStates(); states.push_back(_scxml); for (int i = 0; i < states.size(); i++) { - std::string stateId = ATTR(states[i], "id"); - NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", states[i]); + Arabica::DOM::Element<std::string> stateElem = Arabica::DOM::Element<std::string>(states[i]); + std::string stateId = ATTR(stateElem, "id"); + NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", stateElem); // some transitions are in the inital elements - NodeSet<std::string> initials = filterChildElements(_nsInfo.xmlNSPrefix + "initial", states[i]); + NodeSet<std::string> initials = filterChildElements(_nsInfo.xmlNSPrefix + "initial", stateElem); transitions.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "transition", initials)); for (int j = 0; j < transitions.size(); j++) { Element<std::string> transition = Element<std::string>(transitions[j]); @@ -1014,12 +1015,12 @@ GlobalState::GlobalState(const Arabica::XPath::NodeSet<std::string>& activeState for (int i = 0; i < activeStates.size(); i++) { if (!InterpreterImpl::isFinal(Element<std::string>(activeStates[i]))) isFinal = false; - idSS << ATTR(activeStates[i], "id") << "-"; + idSS << ATTR_CAST(activeStates[i], "id") << "-"; } idSS << ";"; idSS << "entered-"; for (int i = 0; i < alreadyEnteredStates.size(); i++) { - idSS << ATTR(alreadyEnteredStates[i], "id") << "-"; + idSS << ATTR_CAST(alreadyEnteredStates[i], "id") << "-"; } idSS << ";"; @@ -1030,7 +1031,7 @@ GlobalState::GlobalState(const Arabica::XPath::NodeSet<std::string>& activeState idSS << "history--"; idSS << histIter->first << "-"; for (int i = 0; i < histStates.size(); i++) { - idSS << ATTR(histStates[i], "id") << "-"; + idSS << ATTR_CAST(histStates[i], "id") << "-"; } } @@ -1053,13 +1054,14 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& t std::list<std::string> conditions; std::ostringstream setId; // also build id for subset for (int i = 0; i < transitions.size(); i++) { + Arabica::DOM::Element<std::string> transElem = Arabica::DOM::Element<std::string>(transitions[i]); // get a unique string for the transition - we assume it is sorted - assert(HAS_ATTR(transitions[i], "id")); - setId << ATTR(transitions[i], "id") << "-"; + assert(HAS_ATTR(transElem, "id")); + setId << ATTR(transElem, "id") << "-"; // gather conditions while we are iterating anyway - if (HAS_ATTR(transitions[i], "cond")) { - conditions.push_back(ATTR(transitions[i], "cond")); + if (HAS_ATTR(transElem, "cond")) { + conditions.push_back(ATTR(transElem, "cond")); } } transitionId = setId.str(); @@ -1077,10 +1079,11 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& t bool foundTargetLess = false; for (int i = 0; i < transitions.size(); i++) { - if (HAS_ATTR(transitions[i], "eventexpr")) { + Arabica::DOM::Element<std::string> transElem = Arabica::DOM::Element<std::string>(transitions[i]); + if (HAS_ATTR(transElem, "eventexpr")) { ERROR_EXECUTION_THROW("Cannot flatten document with eventexpr attributes"); } - if (HAS_ATTR(transitions[i], "event")) { + if (HAS_ATTR(transElem, "event")) { foundWithEvent = true; if (foundEventLess) break; @@ -1089,7 +1092,7 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& t if (foundWithEvent) break; } - if (HAS_ATTR(transitions[i], "target")) { + if (HAS_ATTR(transElem, "target")) { foundWithTarget = true; if (foundTargetLess) break; @@ -1151,7 +1154,7 @@ std::list<std::string> GlobalTransition::getCommonEvents(const NodeSet<std::stri for (int i = 0; i < transitions.size(); i++) { // for every transition - std::list<std::string> eventNames = InterpreterImpl::tokenizeIdRefs(ATTR(transitions[i], "event")); + std::list<std::string> eventNames = InterpreterImpl::tokenizeIdRefs(ATTR_CAST(transitions[i], "event")); for (std::list<std::string>::iterator eventNameIter = eventNames.begin(); eventNameIter != eventNames.end(); @@ -1170,7 +1173,7 @@ std::list<std::string> GlobalTransition::getCommonEvents(const NodeSet<std::stri // check if token would activate all other transitions if (i == j) continue; - if (!InterpreterImpl::nameMatch(ATTR(transitions[j], "event"), eventName)) { + if (!InterpreterImpl::nameMatch(ATTR_CAST(transitions[j], "event"), eventName)) { isMatching = false; break; } diff --git a/src/uscxml/transform/ChartToFSM.h b/src/uscxml/transform/ChartToFSM.h index 0808a40..aeeb058 100644 --- a/src/uscxml/transform/ChartToFSM.h +++ b/src/uscxml/transform/ChartToFSM.h @@ -56,13 +56,13 @@ class USCXML_API GlobalTransition { public: class Action { public: - Arabica::DOM::Node<std::string> onEntry; - Arabica::DOM::Node<std::string> onExit; - Arabica::DOM::Node<std::string> transition; - Arabica::DOM::Node<std::string> entered; - Arabica::DOM::Node<std::string> exited; - Arabica::DOM::Node<std::string> invoke; - Arabica::DOM::Node<std::string> uninvoke; + Arabica::DOM::Element<std::string> onEntry; + Arabica::DOM::Element<std::string> onExit; + Arabica::DOM::Element<std::string> transition; + Arabica::DOM::Element<std::string> entered; + Arabica::DOM::Element<std::string> exited; + Arabica::DOM::Element<std::string> invoke; + Arabica::DOM::Element<std::string> uninvoke; }; GlobalTransition(const Arabica::XPath::NodeSet<std::string>& transitions, DataModel dataModel); @@ -112,11 +112,11 @@ protected: 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); - virtual void cancelInvoke(const Arabica::DOM::Node<std::string>& element); + virtual void invoke(const Arabica::DOM::Element<std::string>& element); + virtual void cancelInvoke(const Arabica::DOM::Element<std::string>& element); // override to do nothing - void send(const Arabica::DOM::Node<std::string>& element) {} + void send(const Arabica::DOM::Element<std::string>& element) {} void internalDoneSend(const Arabica::DOM::Element<std::string>& state); // InterpreterMonitor diff --git a/src/uscxml/transform/FSMToCPP.cpp b/src/uscxml/transform/FSMToCPP.cpp index 6bf4535..980c389 100644 --- a/src/uscxml/transform/FSMToCPP.cpp +++ b/src/uscxml/transform/FSMToCPP.cpp @@ -56,14 +56,14 @@ void FSMToCPP::writeStates(std::ostream& stream) { stream << "// state name identifiers" << std::endl; for (int i = 0; i < _globalStates.size(); i++) { stream << "#define " << "s" << i << " " << i; - stream << " // from \"" << ATTR(_globalStates[i], "id") << "\"" << std::endl; + stream << " // from \"" << ATTR_CAST(_globalStates[i], "id") << "\"" << std::endl; } } -Arabica::XPath::NodeSet<std::string> FSMToCPP::getTransientContent(const Arabica::DOM::Node<std::string>& state) { +Arabica::XPath::NodeSet<std::string> FSMToCPP::getTransientContent(const Arabica::DOM::Element<std::string>& state) { Arabica::XPath::NodeSet<std::string> content; - Arabica::DOM::Node<std::string> currState = state; + Arabica::DOM::Element<std::string> currState = state; for (;;) { if (!HAS_ATTR(currState, "transient") || !DOMUtils::attributeIsTrue(ATTR(currState, "transient"))) break; @@ -71,24 +71,24 @@ Arabica::XPath::NodeSet<std::string> FSMToCPP::getTransientContent(const Arabica content.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "onentry", currState)); content.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "onexit", currState)); NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", currState); - currState = _states[ATTR(transitions[0], "target")]; + currState = _states[ATTR_CAST(transitions[0], "target")]; } return content; } -Node<std::string> FSMToCPP::getUltimateTarget(const Arabica::DOM::Node<std::string>& transition) { - Arabica::DOM::Node<std::string> currState = _states[ATTR(transition, "target")]; +Node<std::string> FSMToCPP::getUltimateTarget(const Arabica::DOM::Element<std::string>& transition) { + Arabica::DOM::Element<std::string> currState = _states[ATTR(transition, "target")]; for (;;) { if (!HAS_ATTR(currState, "transient") || !DOMUtils::attributeIsTrue(ATTR(currState, "transient"))) return currState; NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", currState); - currState = _states[ATTR(transitions[0], "target")]; + currState = _states[ATTR_CAST(transitions[0], "target")]; } } -void FSMToCPP::writeInlineComment(std::ostream& stream, const Arabica::DOM::Node<std::string>& node) { +void FSMToCPP::writeInlineComment(std::ostream& stream, const Arabica::DOM::Element<std::string>& node) { if (node.getNodeType() != Node_base::COMMENT_NODE) return; @@ -107,7 +107,7 @@ void FSMToCPP::writeInlineComment(std::ostream& stream, const Arabica::DOM::Node } } -void FSMToCPP::writeExecutableContent(std::ostream& stream, const Arabica::DOM::Node<std::string>& node, int indent) { +void FSMToCPP::writeExecutableContent(std::ostream& stream, const Arabica::DOM::Element<std::string>& node, int indent) { std::string padding; for (int i = 0; i < indent; i++) { @@ -140,12 +140,12 @@ void FSMToCPP::writeExecutableContent(std::ostream& stream, const Arabica::DOM:: if (HAS_ATTR(node, "transient") && DOMUtils::attributeIsTrue(ATTR(node, "transient"))) { Arabica::XPath::NodeSet<std::string> execContent = getTransientContent(node); for (int i = 0; i < execContent.size(); i++) { - writeExecutableContent(stream, execContent[i], indent); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(execContent[i]), indent); } } else { Arabica::DOM::Node<std::string> child = node.getFirstChild(); while(child) { - writeExecutableContent(stream, child, indent); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(child), indent); child = child.getNextSibling(); } } @@ -173,7 +173,7 @@ void FSMToCPP::writeExecutableContent(std::ostream& stream, const Arabica::DOM:: } else if(TAGNAME(node) == "onentry" || TAGNAME(node) == "onexit") { Arabica::DOM::Node<std::string> child = node.getFirstChild(); while(child) { - writeExecutableContent(stream, child, indent); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(child), indent); child = child.getNextSibling(); } @@ -192,7 +192,7 @@ void FSMToCPP::writeExecutableContent(std::ostream& stream, const Arabica::DOM:: stream << padding << "for (" << ATTR(node, "item") << " in " << ATTR(node, "array") << ") {" << std::endl; Arabica::DOM::Node<std::string> child = node.getFirstChild(); while(child) { - writeExecutableContent(stream, child, indent + 1); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(child), indent + 1); child = child.getNextSibling(); } if (HAS_ATTR(node, "index")) @@ -239,7 +239,7 @@ void FSMToCPP::writeIfBlock(std::ostream& stream, const Arabica::XPath::NodeSet< bool noNext = condChain.size() == 1; bool nextIsElse = false; if (condChain.size() > 1) { - if (TAGNAME(condChain[1]) == "else") { + if (TAGNAME_CAST(condChain[1]) == "else") { nextIsElse = true; } } @@ -248,20 +248,20 @@ void FSMToCPP::writeIfBlock(std::ostream& stream, const Arabica::XPath::NodeSet< stream << padding << "if" << std::endl; // we need to nest the elseifs to resolve promela if semantics - stream << padding << ":: (" << ATTR(ifNode, "cond") << ") -> {" << std::endl; + stream << padding << ":: (" << ATTR_CAST(ifNode, "cond") << ") -> {" << std::endl; Arabica::DOM::Node<std::string> child; - if (TAGNAME(ifNode) == "if") { + if (TAGNAME_CAST(ifNode) == "if") { child = ifNode.getFirstChild(); } else { child = ifNode.getNextSibling(); } while(child) { if (child.getNodeType() == Node_base::ELEMENT_NODE) { - if (TAGNAME(child) == "elseif" || TAGNAME(child) == "else") + if (TAGNAME_CAST(child) == "elseif" || TAGNAME_CAST(child) == "else") break; } - writeExecutableContent(stream, child, indent + 1); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(child), indent + 1); child = child.getNextSibling(); } stream << padding << "}" << std::endl; @@ -271,7 +271,7 @@ void FSMToCPP::writeIfBlock(std::ostream& stream, const Arabica::XPath::NodeSet< child = condChain[1].getNextSibling(); stream << "{" << std::endl; while(child) { - writeExecutableContent(stream, child, indent + 1); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(child), indent + 1); child = child.getNextSibling(); } stream << padding << "}" << std::endl; @@ -360,14 +360,14 @@ void FSMToCPP::writeFSM(std::ostream& stream) { transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _startState); assert(transitions.size() == 1); stream << " // transition's executable content" << std::endl; - writeExecutableContent(stream, transitions[0], 1); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(transitions[0]), 1); for (int i = 0; i < _globalStates.size(); i++) { if (_globalStates[i] == _startState) continue; NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _globalStates[i]); for (int j = 0; j < transitions.size(); j++) { - writeExecutableContent(stream, transitions[j], 1); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(transitions[j]), 1); } } @@ -424,7 +424,7 @@ void FSMToCPP::writeDispatchingBlock(std::ostream& stream, const Arabica::XPath: stream << padding << ":: ((0"; Node<std::string> currTrans = transChain[0]; - std::string eventDesc = ATTR(currTrans, "event"); + std::string eventDesc = ATTR_CAST(currTrans, "event"); if (boost::ends_with(eventDesc, "*")) eventDesc = eventDesc.substr(0, eventDesc.size() - 1); if (boost::ends_with(eventDesc, ".")) @@ -443,8 +443,8 @@ void FSMToCPP::writeDispatchingBlock(std::ostream& stream, const Arabica::XPath: } stream << ") && "; - stream << (HAS_ATTR(currTrans, "cond") ? ATTR(currTrans, "cond") : "1"); - stream << ") -> goto t" << _transitions[currTrans] << ";" << std::endl; + stream << (HAS_ATTR_CAST(currTrans, "cond") ? ATTR_CAST(currTrans, "cond") : "1"); + stream << ") -> goto t" << _transitions[Arabica::DOM::Element<std::string>(currTrans)] << ";" << std::endl; ; stream << padding << ":: else {" << std::endl; @@ -473,8 +473,9 @@ void FSMToCPP::initNodes() { // get all states NodeSet<std::string> states = filterChildElements(_nsInfo.xmlNSPrefix + "state", _scxml); for (int i = 0; i < states.size(); i++) { - _states[ATTR(states[i], "id")] = states[i]; - if (HAS_ATTR(states[i], "transient") && DOMUtils::attributeIsTrue(ATTR(states[i], "transient"))) + Arabica::DOM::Element<std::string> stateElem = Arabica::DOM::Element<std::string>(states[i]); + _states[ATTR(stateElem, "id")] = stateElem; + if (HAS_ATTR(stateElem, "transient") && DOMUtils::attributeIsTrue(ATTR(stateElem, "transient"))) continue; _globalStates.push_back(states[i]); } @@ -487,8 +488,8 @@ void FSMToCPP::initNodes() { internalEventNames.push_back(_xpath.evaluate("//" + _nsInfo.xpathPrefix + "send", _scxml).asNodeSet()); for (int i = 0; i < internalEventNames.size(); i++) { - if (HAS_ATTR(internalEventNames[i], "event")) { - std::string eventNames = ATTR(internalEventNames[i], "event"); + if (HAS_ATTR_CAST(internalEventNames[i], "event")) { + std::string eventNames = ATTR_CAST(internalEventNames[i], "event"); std::list<std::string> events = tokenizeIdRefs(eventNames); for (std::list<std::string>::iterator eventIter = events.begin(); eventIter != events.end(); eventIter++) { @@ -506,7 +507,7 @@ void FSMToCPP::initNodes() { NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); int index = 0; for (int i = 0; i < transitions.size(); i++) { - _transitions[transitions[i]] = index++; + _transitions[Arabica::DOM::Element<std::string>(transitions[i])] = index++; } } diff --git a/src/uscxml/transform/FSMToCPP.h b/src/uscxml/transform/FSMToCPP.h index 59231b0..18df7c1 100644 --- a/src/uscxml/transform/FSMToCPP.h +++ b/src/uscxml/transform/FSMToCPP.h @@ -47,8 +47,8 @@ protected: void writeEvents(std::ostream& stream); void writeStates(std::ostream& stream); void writeDeclarations(std::ostream& stream); - void writeExecutableContent(std::ostream& stream, const Arabica::DOM::Node<std::string>& node, int indent = 0); - void writeInlineComment(std::ostream& stream, const Arabica::DOM::Node<std::string>& node); + void writeExecutableContent(std::ostream& stream, const Arabica::DOM::Element<std::string>& node, int indent = 0); + void writeInlineComment(std::ostream& stream, const Arabica::DOM::Element<std::string>& node); void writeFSM(std::ostream& stream); void writeEventDispatching(std::ostream& stream); void writeMain(std::ostream& stream); @@ -56,14 +56,14 @@ protected: void writeIfBlock(std::ostream& stream, const Arabica::XPath::NodeSet<std::string>& condChain, int indent = 0); void writeDispatchingBlock(std::ostream& stream, const Arabica::XPath::NodeSet<std::string>& transChain, int indent = 0); - Arabica::XPath::NodeSet<std::string> getTransientContent(const Arabica::DOM::Node<std::string>& state); - Arabica::DOM::Node<std::string> getUltimateTarget(const Arabica::DOM::Node<std::string>& transition); + Arabica::XPath::NodeSet<std::string> getTransientContent(const Arabica::DOM::Element<std::string>& state); + Arabica::DOM::Node<std::string> getUltimateTarget(const Arabica::DOM::Element<std::string>& transition); Trie _eventTrie; Arabica::XPath::NodeSet<std::string> _globalStates; - Arabica::DOM::Node<std::string> _startState; - std::map<std::string, Arabica::DOM::Node<std::string> > _states; - std::map<Arabica::DOM::Node<std::string>, int> _transitions; + Arabica::DOM::Element<std::string> _startState; + std::map<std::string, Arabica::DOM::Element<std::string> > _states; + std::map<Arabica::DOM::Element<std::string>, int> _transitions; }; diff --git a/src/uscxml/transform/FSMToPromela.cpp b/src/uscxml/transform/FSMToPromela.cpp index 3607071..238e40f 100644 --- a/src/uscxml/transform/FSMToPromela.cpp +++ b/src/uscxml/transform/FSMToPromela.cpp @@ -199,14 +199,14 @@ void FSMToPromela::writeStates(std::ostream& stream) { stream << "// state name identifiers" << std::endl; for (int i = 0; i < _globalStates.size(); i++) { stream << "#define " << "s" << i << " " << i; - stream << " // from \"" << ATTR(_globalStates[i], "id") << "\"" << std::endl; + stream << " // from \"" << ATTR_CAST(_globalStates[i], "id") << "\"" << std::endl; } } -Arabica::XPath::NodeSet<std::string> FSMToPromela::getTransientContent(const Arabica::DOM::Node<std::string>& state) { +Arabica::XPath::NodeSet<std::string> FSMToPromela::getTransientContent(const Arabica::DOM::Element<std::string>& state) { Arabica::XPath::NodeSet<std::string> content; - Arabica::DOM::Node<std::string> currState = state; + Arabica::DOM::Element<std::string> currState = state; for (;;) { if (!HAS_ATTR(currState, "transient") || !DOMUtils::attributeIsTrue(ATTR(currState, "transient"))) break; @@ -214,20 +214,20 @@ Arabica::XPath::NodeSet<std::string> FSMToPromela::getTransientContent(const Ara content.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "onentry", currState)); content.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "onexit", currState)); NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", currState); - currState = _states[ATTR(transitions[0], "target")]; + currState = _states[ATTR_CAST(transitions[0], "target")]; } return content; } -Node<std::string> FSMToPromela::getUltimateTarget(const Arabica::DOM::Node<std::string>& transition) { - Arabica::DOM::Node<std::string> currState = _states[ATTR(transition, "target")]; +Node<std::string> FSMToPromela::getUltimateTarget(const Arabica::DOM::Element<std::string>& transition) { + Arabica::DOM::Element<std::string> currState = _states[ATTR_CAST(transition, "target")]; for (;;) { if (!HAS_ATTR(currState, "transient") || !DOMUtils::attributeIsTrue(ATTR(currState, "transient"))) return currState; NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", currState); - currState = _states[ATTR(transitions[0], "target")]; + currState = _states[ATTR_CAST(transitions[0], "target")]; } } @@ -250,7 +250,7 @@ void FSMToPromela::writeInlineComment(std::ostream& stream, const Arabica::DOM:: } } -void FSMToPromela::writeExecutableContent(std::ostream& stream, const Arabica::DOM::Node<std::string>& node, int indent) { +void FSMToPromela::writeExecutableContent(std::ostream& stream, const Arabica::DOM::Element<std::string>& node, int indent) { std::string padding; for (int i = 0; i < indent; i++) { @@ -283,12 +283,12 @@ void FSMToPromela::writeExecutableContent(std::ostream& stream, const Arabica::D if (HAS_ATTR(node, "transient") && DOMUtils::attributeIsTrue(ATTR(node, "transient"))) { Arabica::XPath::NodeSet<std::string> execContent = getTransientContent(node); for (int i = 0; i < execContent.size(); i++) { - writeExecutableContent(stream, execContent[i], indent); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(execContent[i]), indent); } } else { Arabica::DOM::Node<std::string> child = node.getFirstChild(); while(child) { - writeExecutableContent(stream, child, indent); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(child), indent); child = child.getNextSibling(); } } @@ -326,7 +326,7 @@ void FSMToPromela::writeExecutableContent(std::ostream& stream, const Arabica::D } else if(TAGNAME(node) == "onentry" || TAGNAME(node) == "onexit") { Arabica::DOM::Node<std::string> child = node.getFirstChild(); while(child) { - writeExecutableContent(stream, child, indent); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(child), indent); child = child.getNextSibling(); } @@ -345,7 +345,7 @@ void FSMToPromela::writeExecutableContent(std::ostream& stream, const Arabica::D stream << padding << "for (" << ATTR(node, "item") << " in " << ATTR(node, "array") << ") {" << std::endl; Arabica::DOM::Node<std::string> child = node.getFirstChild(); while(child) { - writeExecutableContent(stream, child, indent + 1); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(child), indent + 1); child = child.getNextSibling(); } if (HAS_ATTR(node, "index")) @@ -483,22 +483,22 @@ void FSMToPromela::writeIfBlock(std::ostream& stream, const Arabica::XPath::Node bool noNext = condChain.size() == 1; bool nextIsElse = false; if (condChain.size() > 1) { - if (TAGNAME(condChain[1]) == "else") { + if (TAGNAME_CAST(condChain[1]) == "else") { nextIsElse = true; } } - Node<std::string> ifNode = condChain[0]; + Element<std::string> ifNode = Element<std::string>(condChain[0]); stream << padding << "if" << std::endl; // we need to nest the elseifs to resolve promela if semantics stream << padding << ":: (" << ATTR(ifNode, "cond") << ") -> {" << std::endl; - Arabica::DOM::Node<std::string> child; + Arabica::DOM::Element<std::string> child; if (TAGNAME(ifNode) == "if") { - child = ifNode.getFirstChild(); + child = Arabica::DOM::Element<std::string>(ifNode.getFirstChild()); } else { - child = ifNode.getNextSibling(); + child = Arabica::DOM::Element<std::string>(ifNode.getNextSibling()); } while(child) { if (child.getNodeType() == Node_base::ELEMENT_NODE) { @@ -506,17 +506,17 @@ void FSMToPromela::writeIfBlock(std::ostream& stream, const Arabica::XPath::Node break; } writeExecutableContent(stream, child, indent + 1); - child = child.getNextSibling(); + child = Arabica::DOM::Element<std::string>(child.getNextSibling()); } stream << padding << "}" << std::endl; stream << padding << ":: else -> "; if (nextIsElse) { - child = condChain[1].getNextSibling(); + child = Arabica::DOM::Element<std::string>(condChain[1].getNextSibling()); stream << "{" << std::endl; while(child) { writeExecutableContent(stream, child, indent + 1); - child = child.getNextSibling(); + child = Arabica::DOM::Element<std::string>(child.getNextSibling()); } stream << padding << "}" << std::endl; @@ -630,14 +630,14 @@ void FSMToPromela::writeFSM(std::ostream& stream) { transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _startState); assert(transitions.size() == 1); stream << " // transition's executable content" << std::endl; - writeExecutableContent(stream, transitions[0], 1); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(transitions[0]), 1); for (int i = 0; i < _globalStates.size(); i++) { if (_globalStates[i] == _startState) continue; NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _globalStates[i]); for (int j = 0; j < transitions.size(); j++) { - writeExecutableContent(stream, transitions[j], 1); + writeExecutableContent(stream, Arabica::DOM::Element<std::string>(transitions[j]), 1); } } @@ -702,7 +702,7 @@ void FSMToPromela::writeDispatchingBlock(std::ostream& stream, const Arabica::XP stream << padding << "if" << std::endl; stream << padding << ":: ((0"; - Node<std::string> currTrans = transChain[0]; + Element<std::string> currTrans = Element<std::string>(transChain[0]); std::string eventDesc = ATTR(currTrans, "event"); if (boost::ends_with(eventDesc, "*")) eventDesc = eventDesc.substr(0, eventDesc.size() - 1); @@ -754,8 +754,8 @@ void FSMToPromela::initNodes() { // get all states NodeSet<std::string> states = filterChildElements(_nsInfo.xmlNSPrefix + "state", _scxml); for (int i = 0; i < states.size(); i++) { - _states[ATTR(states[i], "id")] = states[i]; - if (HAS_ATTR(states[i], "transient") && DOMUtils::attributeIsTrue(ATTR(states[i], "transient"))) + _states[ATTR_CAST(states[i], "id")] = Element<std::string>(states[i]); + if (HAS_ATTR_CAST(states[i], "transient") && DOMUtils::attributeIsTrue(ATTR_CAST(states[i], "transient"))) continue; _globalStates.push_back(states[i]); } @@ -768,8 +768,8 @@ void FSMToPromela::initNodes() { internalEventNames.push_back(_xpath.evaluate("//" + _nsInfo.xpathPrefix + "send", _scxml).asNodeSet()); for (int i = 0; i < internalEventNames.size(); i++) { - if (HAS_ATTR(internalEventNames[i], "event")) { - std::string eventNames = ATTR(internalEventNames[i], "event"); + if (HAS_ATTR_CAST(internalEventNames[i], "event")) { + std::string eventNames = ATTR_CAST(internalEventNames[i], "event"); std::list<std::string> events = tokenizeIdRefs(eventNames); for (std::list<std::string>::iterator eventIter = events.begin(); eventIter != events.end(); eventIter++) { @@ -793,17 +793,17 @@ void FSMToPromela::initNodes() { PromelaInlines promInls = getInlinePromela(promelaEventSourceComments[i]); PromelaEventSource promES(promInls, promelaEventSourceComments[i].getParentNode()); - if (TAGNAME(promelaEventSourceComments[i].getParentNode()) == "scxml") { + if (TAGNAME_CAST(promelaEventSourceComments[i].getParentNode()) == "scxml") { promES.type = PromelaEventSource::PROMELA_EVENT_SOURCE_GLOBAL; promES.trie = &_eventTrie; promES.name = "global"; _globalEventSource = promES; - } else if (TAGNAME(promelaEventSourceComments[i].getParentNode()) == "invoke") { - if (!HAS_ATTR(promelaEventSourceComments[i].getParentNode(), "invokeid")) { + } else if (TAGNAME_CAST(promelaEventSourceComments[i].getParentNode()) == "invoke") { + if (!HAS_ATTR_CAST(promelaEventSourceComments[i].getParentNode(), "invokeid")) { Element<std::string> invoker = Element<std::string>(promelaEventSourceComments[i].getParentNode()); invoker.setAttribute("invokeid", "invoker" + toStr(_invokers.size())); } - std::string invokeId = ATTR(promelaEventSourceComments[i].getParentNode(), "invokeid"); + std::string invokeId = ATTR_CAST(promelaEventSourceComments[i].getParentNode(), "invokeid"); promES.type = PromelaEventSource::PROMELA_EVENT_SOURCE_INVOKER; promES.trie = &_eventTrie; promES.name = invokeId; @@ -815,7 +815,7 @@ void FSMToPromela::initNodes() { NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); int index = 0; for (int i = 0; i < transitions.size(); i++) { - _transitions[transitions[i]] = index++; + _transitions[Element<std::string>(transitions[i])] = index++; } } diff --git a/src/uscxml/transform/FSMToPromela.h b/src/uscxml/transform/FSMToPromela.h index e507fdc..62381cd 100644 --- a/src/uscxml/transform/FSMToPromela.h +++ b/src/uscxml/transform/FSMToPromela.h @@ -129,7 +129,7 @@ protected: void writeStates(std::ostream& stream); void writeDeclarations(std::ostream& stream); void writeEventSources(std::ostream& stream); - void writeExecutableContent(std::ostream& stream, const Arabica::DOM::Node<std::string>& node, int indent = 0); + void writeExecutableContent(std::ostream& stream, const Arabica::DOM::Element<std::string>& node, int indent = 0); void writeInlineComment(std::ostream& stream, const Arabica::DOM::Node<std::string>& node); void writeFSM(std::ostream& stream); void writeEventDispatching(std::ostream& stream); @@ -138,8 +138,8 @@ protected: void writeIfBlock(std::ostream& stream, const Arabica::XPath::NodeSet<std::string>& condChain, int indent = 0); void writeDispatchingBlock(std::ostream& stream, const Arabica::XPath::NodeSet<std::string>& transChain, int indent = 0); - Arabica::XPath::NodeSet<std::string> getTransientContent(const Arabica::DOM::Node<std::string>& state); - Arabica::DOM::Node<std::string> getUltimateTarget(const Arabica::DOM::Node<std::string>& transition); + Arabica::XPath::NodeSet<std::string> getTransientContent(const Arabica::DOM::Element<std::string>& state); + Arabica::DOM::Node<std::string> getUltimateTarget(const Arabica::DOM::Element<std::string>& transition); static PromelaInlines getInlinePromela(const std::string&); static PromelaInlines getInlinePromela(const Arabica::XPath::NodeSet<std::string>& elements, bool recurse = false); @@ -148,8 +148,8 @@ protected: Trie _eventTrie; Arabica::XPath::NodeSet<std::string> _globalStates; Arabica::DOM::Node<std::string> _startState; - std::map<std::string, Arabica::DOM::Node<std::string> > _states; - std::map<Arabica::DOM::Node<std::string>, int> _transitions; + std::map<std::string, Arabica::DOM::Element<std::string> > _states; + std::map<Arabica::DOM::Element<std::string>, int> _transitions; std::map<std::string, PromelaEventSource> _invokers; PromelaEventSource _globalEventSource; |