From f678b755216a7ea21acec0c8e51a6698719ef776 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Tue, 31 Jan 2017 00:12:06 +0100 Subject: Introduced constants for XML names --- src/bindings/swig/uscxml_beautify.i | 4 +- .../swig/wrapped/WrappedInterpreterMonitor.cpp | 34 +- src/uscxml/Interpreter.cpp | 6 +- src/uscxml/debug/DebugSession.cpp | 6 +- src/uscxml/debug/Debugger.cpp | 16 +- src/uscxml/debug/InterpreterIssue.cpp | 186 +++++----- src/uscxml/interpreter/BasicContentExecutor.cpp | 138 ++++---- src/uscxml/interpreter/FastMicroStep.cpp | 36 +- src/uscxml/interpreter/InterpreterImpl.cpp | 18 +- src/uscxml/transform/ChartToC.cpp | 222 ++++++------ src/uscxml/transform/ChartToPromela.cpp | 228 ++++++------- src/uscxml/transform/ChartToVHDL.cpp | 378 ++++++++++----------- .../transform/promela/PromelaCodeAnalyzer.cpp | 50 +-- src/uscxml/util/DOM.cpp | 10 +- src/uscxml/util/DOM.h | 115 +++++-- src/uscxml/util/Predicates.cpp | 20 +- test/src/test-http-debugger.pl | 2 +- test/src/test-utils.cpp | 12 +- 18 files changed, 764 insertions(+), 717 deletions(-) diff --git a/src/bindings/swig/uscxml_beautify.i b/src/bindings/swig/uscxml_beautify.i index 632f399..6892f95 100644 --- a/src/bindings/swig/uscxml_beautify.i +++ b/src/bindings/swig/uscxml_beautify.i @@ -30,8 +30,8 @@ std::list nativeConfig = self->getConfiguration(); std::vector config; for (auto state : nativeConfig) { - if (HAS_ATTR(state, "id")) - config.push_back(ATTR(state, "id")); + if (HAS_ATTR(state, kXMLCharId)) + config.push_back(ATTR(state, kXMLCharId)); } return config; } diff --git a/src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp b/src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp index f563539..03b52bc 100644 --- a/src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp +++ b/src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp @@ -33,13 +33,13 @@ WrappedInterpreterMonitor::~WrappedInterpreterMonitor() {} void WrappedInterpreterMonitor::beforeExitingState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) { std::stringstream ss; ss << *state; - beforeExitingState(ATTR(state, "id"), DOMUtils::xPathForNode(state), ss.str()); + beforeExitingState(ATTR(state, kXMLCharId), DOMUtils::xPathForNode(state), ss.str()); } void WrappedInterpreterMonitor::afterExitingState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) { std::stringstream ss; ss << *state; - afterExitingState(ATTR(state, "id"), DOMUtils::xPathForNode(state), ss.str()); + afterExitingState(ATTR(state, kXMLCharId), DOMUtils::xPathForNode(state), ss.str()); } void WrappedInterpreterMonitor::beforeExecutingContent(Interpreter& interpreter, const XERCESC_NS::DOMElement* content) { @@ -58,8 +58,8 @@ void WrappedInterpreterMonitor::beforeUninvoking(Interpreter& interpreter, const std::stringstream ss; ss << *invoker; std::string invokeId; - if (invoker->getUserData(X("invokeid")) != NULL) { - invokeId = (char*)invoker->getUserData(X("invokeid")); + if (invoker->getUserData(kXMLCharInvokeId) != NULL) { + invokeId = (char*)invoker->getUserData(kXMLCharInvokeId); } beforeUninvoking(DOMUtils::xPathForNode(invoker), invokeId, ss.str()); @@ -69,8 +69,8 @@ void WrappedInterpreterMonitor::afterUninvoking(Interpreter& interpreter, const std::stringstream ss; ss << *invoker; std::string invokeId; - if (invoker->getUserData(X("invokeid")) != NULL) { - invokeId = (char*)invoker->getUserData(X("invokeid")); + if (invoker->getUserData(kXMLCharInvokeId) != NULL) { + invokeId = (char*)invoker->getUserData(kXMLCharInvokeId); } afterUninvoking(DOMUtils::xPathForNode(invoker), invokeId, ss.str()); @@ -87,10 +87,10 @@ void WrappedInterpreterMonitor::beforeTakingTransition(Interpreter& interpreter, std::list targets; for (auto t : targetStates) { - targets.push_back(ATTR_CAST(t, "id")); + targets.push_back(ATTR_CAST(t, kXMLCharId)); } - beforeTakingTransition(DOMUtils::xPathForNode(transition), ATTR_CAST(sourceState, "id"), targets, ss.str()); + beforeTakingTransition(DOMUtils::xPathForNode(transition), ATTR_CAST(sourceState, kXMLCharId), targets, ss.str()); } void WrappedInterpreterMonitor::afterTakingTransition(Interpreter& interpreter, const XERCESC_NS::DOMElement* transition) { @@ -104,30 +104,30 @@ void WrappedInterpreterMonitor::afterTakingTransition(Interpreter& interpreter, std::list targets; for (auto t : targetStates) { - targets.push_back(ATTR_CAST(t, "id")); + targets.push_back(ATTR_CAST(t, kXMLCharId)); } - afterTakingTransition(DOMUtils::xPathForNode(transition), ATTR_CAST(sourceState, "id"), targets, ss.str()); + afterTakingTransition(DOMUtils::xPathForNode(transition), ATTR_CAST(sourceState, kXMLCharId), targets, ss.str()); } void WrappedInterpreterMonitor::beforeEnteringState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) { std::stringstream ss; ss << *state; - beforeEnteringState(ATTR(state, "id"), DOMUtils::xPathForNode(state), ss.str()); + beforeEnteringState(ATTR(state, kXMLCharId), DOMUtils::xPathForNode(state), ss.str()); } void WrappedInterpreterMonitor::afterEnteringState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) { std::stringstream ss; ss << *state; - afterEnteringState(ATTR(state, "id"), DOMUtils::xPathForNode(state), ss.str()); + afterEnteringState(ATTR(state, kXMLCharId), DOMUtils::xPathForNode(state), ss.str()); } void WrappedInterpreterMonitor::beforeInvoking(Interpreter& interpreter, const XERCESC_NS::DOMElement* invoker, const std::string& invokeid) { std::stringstream ss; ss << *invoker; std::string invokeId; - if (invoker->getUserData(X("invokeid")) != NULL) { - invokeId = (char*)invoker->getUserData(X("invokeid")); + if (invoker->getUserData(kXMLCharInvokeId) != NULL) { + invokeId = (char*)invoker->getUserData(kXMLCharInvokeId); } beforeInvoking(DOMUtils::xPathForNode(invoker), invokeId, ss.str()); @@ -137,11 +137,11 @@ void WrappedInterpreterMonitor::afterInvoking(Interpreter& interpreter, const XE std::stringstream ss; ss << *invoker; std::string invokeId; - if (invoker->getUserData(X("invokeid")) != NULL) { - invokeId = (char*)invoker->getUserData(X("invokeid")); + if (invoker->getUserData(kXMLCharInvokeId) != NULL) { + invokeId = (char*)invoker->getUserData(kXMLCharInvokeId); } afterInvoking(DOMUtils::xPathForNode(invoker), invokeId, ss.str()); } -} \ No newline at end of file +} diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 2c6e80d..7458bce 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -258,7 +258,7 @@ std::list Interpreter::validate() { static void printNodeSet(Logger& logger, const std::list nodes) { std::string seperator; for (auto nIter = nodes.begin(); nIter != nodes.end(); nIter++) { - LOG(logger, USCXML_VERBATIM) << seperator << (HAS_ATTR(*nIter, "id") ? ATTR(*nIter, "id") : DOMUtils::xPathForNode(*nIter)); + LOG(logger, USCXML_VERBATIM) << seperator << (HAS_ATTR(*nIter, kXMLCharId) ? ATTR(*nIter, kXMLCharId) : DOMUtils::xPathForNode(*nIter)); seperator = ", "; } } @@ -300,12 +300,12 @@ void StateTransitionMonitor::beforeExecutingContent(Interpreter& interpreter, co void StateTransitionMonitor::beforeExitingState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) { std::lock_guard lock(_mutex); - LOG(_logger, USCXML_VERBATIM) << "Exiting: " << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)) << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Exiting: " << (HAS_ATTR(state, kXMLCharId) ? ATTR(state, kXMLCharId) : DOMUtils::xPathForNode(state)) << std::endl; } void StateTransitionMonitor::beforeEnteringState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) { std::lock_guard lock(_mutex); - LOG(_logger, USCXML_VERBATIM) << "Entering: " << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)) << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Entering: " << (HAS_ATTR(state, kXMLCharId) ? ATTR(state, kXMLCharId) : DOMUtils::xPathForNode(state)) << std::endl; } diff --git a/src/uscxml/debug/DebugSession.cpp b/src/uscxml/debug/DebugSession.cpp index 0b939d9..6e2f7ef 100644 --- a/src/uscxml/debug/DebugSession.cpp +++ b/src/uscxml/debug/DebugSession.cpp @@ -76,10 +76,10 @@ void DebugSession::breakExecution(Data replyData) { std::list configuration = _interpreter.getConfiguration(); for (auto state : configuration) { - if (HAS_ATTR(state, "id")) { - replyData.compound["activeStates"].array.push_back(Data(ATTR(state, "id"), Data::VERBATIM)); + if (HAS_ATTR(state, kXMLCharId)) { + replyData.compound["activeStates"].array.push_back(Data(ATTR(state, kXMLCharId), Data::VERBATIM)); if (isAtomic(state)) { - replyData.compound["basicStates"].array.push_back(Data(ATTR(state, "id"), Data::VERBATIM)); + replyData.compound["basicStates"].array.push_back(Data(ATTR(state, kXMLCharId), Data::VERBATIM)); } } } diff --git a/src/uscxml/debug/Debugger.cpp b/src/uscxml/debug/Debugger.cpp index 9478927..e1ff74b 100644 --- a/src/uscxml/debug/Debugger.cpp +++ b/src/uscxml/debug/Debugger.cpp @@ -41,7 +41,7 @@ std::list Debugger::getQualifiedStateBreakpoints(InterpreterImpl* im std::list breakpoints; Breakpoint bp = breakpointTemplate; // copy base as template - bp.stateId = ATTR(state, "id"); + bp.stateId = ATTR(state, kXMLCharId); bp.element = state; bp.subject = Breakpoint::STATE; breakpoints.push_back(bp); @@ -57,10 +57,10 @@ std::list Debugger::getQualifiedInvokeBreakpoints(InterpreterImpl* i bp.element = invokeElem; bp.invokeId = invokeId; - if (HAS_ATTR(invokeElem, "type")) { - bp.invokeType = ATTR(invokeElem, "type"); - } else if (HAS_ATTR(invokeElem, "typeexpr")) { - bp.invokeType = impl->evalAsData(ATTR(invokeElem, "typeexpr")).atom; + if (HAS_ATTR(invokeElem, kXMLCharType)) { + bp.invokeType = ATTR(invokeElem, kXMLCharType); + } else if (HAS_ATTR(invokeElem, kXMLCharTypeExpr)) { + bp.invokeType = impl->evalAsData(ATTR(invokeElem, kXMLCharTypeExpr)).atom; } breakpoints.push_back(bp); @@ -78,8 +78,8 @@ std::list Debugger::getQualifiedTransBreakpoints(InterpreterImpl* im Breakpoint bp = breakpointTemplate; // copy base as template bp.element = transition; - bp.transSourceId = ATTR(source, "id"); - bp.transTargetId = ATTR(target, "id"); + bp.transSourceId = ATTR(source, kXMLCharId); + bp.transTargetId = ATTR(target, kXMLCharId); bp.subject = Breakpoint::TRANSITION; breakpoints.push_back(bp); @@ -262,4 +262,4 @@ void Debugger::handleInvoke(Interpreter& interpreter, const XERCESC_NS::DOMEleme } -} \ No newline at end of file +} diff --git a/src/uscxml/debug/InterpreterIssue.cpp b/src/uscxml/debug/InterpreterIssue.cpp index 4f2e31f..a4d8841 100644 --- a/src/uscxml/debug/InterpreterIssue.cpp +++ b/src/uscxml/debug/InterpreterIssue.cpp @@ -332,21 +332,21 @@ std::list InterpreterIssue::forInterpreter(InterpreterImpl* in for (auto stateIter = allStates.begin(); stateIter != allStates.end(); stateIter++) { DOMElement* state = static_cast(*stateIter); - if (DOMUtils::isMember(state, finals) && !HAS_ATTR(state, "id")) // id is not required for finals + if (DOMUtils::isMember(state, finals) && !HAS_ATTR(state, kXMLCharId)) // id is not required for finals continue; // check for existance of id attribute - this not actually required! - if (!HAS_ATTR(state, "id")) { + if (!HAS_ATTR(state, kXMLCharId)) { issues.push_back(InterpreterIssue("State has no 'id' attribute", state, InterpreterIssue::USCXML_ISSUE_FATAL)); continue; } - if (ATTR(state, "id").size() == 0) { + if (ATTR(state, kXMLCharId).size() == 0) { issues.push_back(InterpreterIssue("State has empty 'id' attribute", state, InterpreterIssue::USCXML_ISSUE_FATAL)); continue; } - std::string stateId = ATTR(state, "id"); + std::string stateId = ATTR(state, kXMLCharId); // check for valid transition with history states if (LOCALNAME(state) == "history") { @@ -357,25 +357,25 @@ std::list InterpreterIssue::forInterpreter(InterpreterImpl* in issues.push_back(InterpreterIssue("History pseudo-state with id '" + stateId + "' has no default transition", state, InterpreterIssue::USCXML_ISSUE_FATAL)); } else { DOMElement* transition = static_cast(transitions.front()); - if (HAS_ATTR(transition, "cond")) { + if (HAS_ATTR(transition, kXMLCharCond)) { issues.push_back(InterpreterIssue("Transition in history pseudo-state '" + stateId + "' must not have a condition", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } - if (HAS_ATTR(transition, "event")) { + if (HAS_ATTR(transition, kXMLCharEvent)) { issues.push_back(InterpreterIssue("Transition in history pseudo-state '" + stateId + "' must not have an event attribute", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } - if (!HAS_ATTR(transition, "target")) { + if (!HAS_ATTR(transition, kXMLCharTarget)) { issues.push_back(InterpreterIssue("Transition in history pseudo-state '" + stateId + "' has no target", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } else { std::list targetStates = getTargetStates(transition, _scxml); for (auto tIter = targetStates.begin(); tIter != targetStates.end(); tIter++) { DOMElement* target = *tIter; - if (HAS_ATTR(state, "type") && ATTR(state, "type") == "deep") { + if (HAS_ATTR(state, kXMLCharType) && ATTR(state, kXMLCharType) == "deep") { if (!DOMUtils::isDescendant(target, state->getParentNode())) { - issues.push_back(InterpreterIssue("Transition in deep history pseudo-state '" + stateId + "' has illegal target state '" + ATTR(target, "id") + "'", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); + issues.push_back(InterpreterIssue("Transition in deep history pseudo-state '" + stateId + "' has illegal target state '" + ATTR(target, kXMLCharId) + "'", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } } else { if (target->getParentNode() != state->getParentNode()) { - issues.push_back(InterpreterIssue("Transition in shallow history pseudo-state '" + stateId + "' has illegal target state '" + ATTR(target, "id") + "'", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); + issues.push_back(InterpreterIssue("Transition in shallow history pseudo-state '" + stateId + "' has illegal target state '" + ATTR(target, kXMLCharId) + "'", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } } } @@ -393,15 +393,15 @@ std::list InterpreterIssue::forInterpreter(InterpreterImpl* in issues.push_back(InterpreterIssue("Duplicate state with id '" + stateId + "'", state, InterpreterIssue::USCXML_ISSUE_FATAL)); continue; } - seenStates[ATTR(state, "id")] = state; + seenStates[ATTR(state, kXMLCharId)] = state; } for (auto tIter = transitions.begin(); tIter != transitions.end(); tIter++) { DOMElement* transition = *tIter; // check for valid target - if (HAS_ATTR(transition, "target")) { - std::list targetIds = tokenize(ATTR(transition, "target")); + if (HAS_ATTR(transition, kXMLCharTarget)) { + std::list targetIds = tokenize(ATTR(transition, kXMLCharTarget)); if (targetIds.size() == 0) { issues.push_back(InterpreterIssue("Transition has empty target state list", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } @@ -426,20 +426,20 @@ std::list InterpreterIssue::forInterpreter(InterpreterImpl* in DOMElement* earlierTransition = *t2Iter; // will the earlier transition always be enabled when the later is? - if (!HAS_ATTR(earlierTransition, "cond")) { + if (!HAS_ATTR(earlierTransition, kXMLCharCond)) { // earlier transition has no condition -> check event descriptor - if (!HAS_ATTR(earlierTransition, "event")) { + if (!HAS_ATTR(earlierTransition, kXMLCharEvent)) { // earlier transition is eventless issues.push_back(InterpreterIssue("Transition can never be optimally enabled", transition, InterpreterIssue::USCXML_ISSUE_INFO)); goto NEXT_TRANSITION; - } else if (HAS_ATTR(transition, "event")) { + } else if (HAS_ATTR(transition, kXMLCharEvent)) { // does the earlier transition match all our events? - std::list events = tokenize(ATTR(transition, "event")); + std::list events = tokenize(ATTR(transition, kXMLCharEvent)); bool allMatched = true; for (std::list::iterator eventIter = events.begin(); eventIter != events.end(); eventIter++) { - if (!nameMatch(ATTR(earlierTransition, "event"), *eventIter)) { + if (!nameMatch(ATTR(earlierTransition, kXMLCharEvent), *eventIter)) { allMatched = false; break; } @@ -467,12 +467,12 @@ NEXT_TRANSITION: DOMElement* parent = static_cast(history->getParentNode()); if (isAtomic(parent)) { - issues.push_back(InterpreterIssue("Useless history '" + ATTR(history, "id") + "' in atomic state", history, InterpreterIssue::USCXML_ISSUE_INFO)); + issues.push_back(InterpreterIssue("Useless history '" + ATTR(history, kXMLCharId) + "' in atomic state", history, InterpreterIssue::USCXML_ISSUE_INFO)); continue; } std::list > configs = getAllConfigurations(parent); if (configs.size() <= 1) { - issues.push_back(InterpreterIssue("Useless history '" + ATTR(history, "id") + "' in state with single legal configuration", history, InterpreterIssue::USCXML_ISSUE_INFO)); + issues.push_back(InterpreterIssue("Useless history '" + ATTR(history, kXMLCharId) + "' in state with single legal configuration", history, InterpreterIssue::USCXML_ISSUE_INFO)); continue; } } @@ -487,7 +487,7 @@ NEXT_TRANSITION: for (auto stateIter = withInitialAttr.begin(); stateIter != withInitialAttr.end(); stateIter++) { DOMElement* state = *stateIter; - if (HAS_ATTR(state, "initial")) { + if (HAS_ATTR(state, kXMLCharInitial)) { std::list childs; std::list tmp; tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "state", state, true); @@ -499,7 +499,7 @@ NEXT_TRANSITION: tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "history", state, true); childs.insert(childs.end(), tmp.begin(), tmp.end()); - std::list intials = tokenize(ATTR(state, "initial")); + std::list intials = tokenize(ATTR(state, kXMLCharInitial)); for (std::list::iterator initIter = intials.begin(); initIter != intials.end(); initIter++) { if (seenStates.find(*initIter) == seenStates.end()) { issues.push_back(InterpreterIssue("Initial attribute has invalid target state with id '" + *initIter + "'", state, InterpreterIssue::USCXML_ISSUE_FATAL)); @@ -520,24 +520,24 @@ NEXT_TRANSITION: for (auto iter = transitions.begin(); iter != transitions.end(); iter++) { DOMElement* transition = *iter; - if (HAS_ATTR(transition, "target")) { - targetIdSets[transition] = ATTR(transition, "target"); + if (HAS_ATTR(transition, kXMLCharTarget)) { + targetIdSets[transition] = ATTR(transition, kXMLCharTarget); } } for (auto iter = initials.begin(); iter != initials.end(); iter++) { DOMElement* initial = *iter; - if (HAS_ATTR(initial, "target")) { - targetIdSets[initial] = ATTR(initial, "target"); + if (HAS_ATTR(initial, kXMLCharTarget)) { + targetIdSets[initial] = ATTR(initial, kXMLCharTarget); } } for (auto iter = allStates.begin(); iter != allStates.end(); iter++) { DOMElement* state = *iter; - if (HAS_ATTR(state, "initial")) { - targetIdSets[state] = ATTR(state, "initial"); + if (HAS_ATTR(state, kXMLCharInitial)) { + targetIdSets[state] = ATTR(state, kXMLCharInitial); } } @@ -581,10 +581,10 @@ NEXT_SET: * whose value is a valid state specification consisting solely of descendants of the containing state */ - if (HAS_ATTR(transition, "cond")) { + if (HAS_ATTR(transition, kXMLCharCond)) { issues.push_back(InterpreterIssue("Initial transition cannot have a condition", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } - if (HAS_ATTR(transition, "event")) { + if (HAS_ATTR(transition, kXMLCharEvent)) { issues.push_back(InterpreterIssue("Initial transition cannot be eventful", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } @@ -607,7 +607,7 @@ NEXT_SET: tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "history", state, true); childs.insert(childs.end(), tmp.begin(), tmp.end()); - std::list intials = tokenize(ATTR(transition, "target")); + std::list intials = tokenize(ATTR(transition, kXMLCharTarget)); for (std::list::iterator initIter = intials.begin(); initIter != intials.end(); initIter++) { // the 'target' of a inside an or element: all the states must be descendants of the containing or element if (!DOMUtils::isMember(seenStates[*initIter], childs)) { @@ -622,20 +622,20 @@ NEXT_SET: { for (auto iter = invokes.begin(); iter != invokes.end(); iter++) { DOMElement* invoke = *iter; - if (HAS_ATTR(invoke, "type") && !_factory->hasInvoker(ATTR(invoke, "type"))) { + if (HAS_ATTR(invoke, kXMLCharType) && !_factory->hasInvoker(ATTR(invoke, kXMLCharType))) { // unknown at factory - adhoc extension? - if (HAS_ATTR(invoke, "id") && interpreter->_invokers.find(ATTR(invoke, "id")) != interpreter->_invokers.end()) + if (HAS_ATTR(invoke, kXMLCharId) && interpreter->_invokers.find(ATTR(invoke, kXMLCharId)) != interpreter->_invokers.end()) continue; // not an issue IssueSeverity severity; - if (HAS_ATTR(invoke, "idlocation")) { + if (HAS_ATTR(invoke, kXMLCharIdLocation)) { // we might still resolve at runtime severity = InterpreterIssue::USCXML_ISSUE_WARNING; } else { // fatality! severity = InterpreterIssue::USCXML_ISSUE_FATAL; } - issues.push_back(InterpreterIssue("Invoke with unknown type '" + ATTR(invoke, "type") + "'", invoke, severity)); + issues.push_back(InterpreterIssue("Invoke with unknown type '" + ATTR(invoke, kXMLCharType) + "'", invoke, severity)); continue; } } @@ -645,11 +645,11 @@ NEXT_SET: { for (auto iter = sends.begin(); iter != sends.end(); iter++) { DOMElement* send = *iter; - if (HAS_ATTR(send, "type") && !_factory->hasIOProcessor(ATTR(send, "type"))) { - if (interpreter->_ioProcs.find(ATTR(send, "type")) != interpreter->_ioProcs.end()) + if (HAS_ATTR(send, kXMLCharType) && !_factory->hasIOProcessor(ATTR(send, kXMLCharType))) { + if (interpreter->_ioProcs.find(ATTR(send, kXMLCharType)) != interpreter->_ioProcs.end()) continue; // not an issue, available ad-hoc - issues.push_back(InterpreterIssue("Send to unknown IO Processor '" + ATTR(send, "type") + "'", send, InterpreterIssue::USCXML_ISSUE_FATAL)); + issues.push_back(InterpreterIssue("Send to unknown IO Processor '" + ATTR(send, kXMLCharType) + "'", send, InterpreterIssue::USCXML_ISSUE_FATAL)); continue; } } @@ -690,10 +690,10 @@ NEXT_SET: if (reqAttr.find(localName) != reqAttr.end()) { for (std::set::const_iterator reqIter = reqAttr[localName].begin(); reqIter != reqAttr[localName].end(); reqIter++) { - if (!HAS_ATTR(element, *reqIter)) { + if (!HAS_ATTR(element, X(*reqIter))) { issues.push_back(InterpreterIssue("Element " + localName + " is missing required attribute '" + *reqIter + "'", element, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(element, *reqIter) && ATTR(element, *reqIter).size() == 0) { + if (HAS_ATTR(element, X(*reqIter)) && ATTR(element, X(*reqIter)).size() == 0) { issues.push_back(InterpreterIssue("Required attribute '" + *reqIter + "' of element " + localName + " is empty", element, InterpreterIssue::USCXML_ISSUE_WARNING)); } } @@ -723,7 +723,7 @@ NEXT_SET: DOMElement* initial = *iter; if (initial->getParentNode() && initial->getParentNode()->getNodeType() == DOMNode::ELEMENT_NODE) { DOMElement* state = static_cast(initial->getParentNode()); - if (HAS_ATTR(state, "initial")) { + if (HAS_ATTR(state, kXMLCharInitial)) { issues.push_back(InterpreterIssue("State with initial attribute cannot have child ", state, InterpreterIssue::USCXML_ISSUE_WARNING)); } if (isAtomic(state)) { @@ -733,64 +733,64 @@ NEXT_SET: } for (auto iter = allStates.begin(); iter != allStates.end(); iter++) { DOMElement* state = *iter; - if (isAtomic(state) && HAS_ATTR(state, "initial")) { + if (isAtomic(state) && HAS_ATTR(state, kXMLCharInitial)) { issues.push_back(InterpreterIssue("Atomic state cannot have initial attribute ", state, InterpreterIssue::USCXML_ISSUE_WARNING)); } } for (auto iter = assigns.begin(); iter != assigns.end(); iter++) { DOMElement* assign = *iter; - if (HAS_ATTR(assign, "expr") && assign->getChildNodes()->getLength() > 0) { + if (HAS_ATTR(assign, kXMLCharExpr) && assign->getChildNodes()->getLength() > 0) { issues.push_back(InterpreterIssue("Assign element cannot have expr attribute and children", assign, InterpreterIssue::USCXML_ISSUE_WARNING)); } } for (auto iter = contents.begin(); iter != contents.end(); iter++) { DOMElement* content = *iter; - if (HAS_ATTR(content, "expr") && content->getChildNodes()->getLength() > 0) { + if (HAS_ATTR(content, kXMLCharExpr) && content->getChildNodes()->getLength() > 0) { issues.push_back(InterpreterIssue("Content element cannot have expr attribute and children", content, InterpreterIssue::USCXML_ISSUE_WARNING)); } } for (auto iter = params.begin(); iter != params.end(); iter++) { DOMElement* param = *iter; - if (HAS_ATTR(param, "expr") && HAS_ATTR(param, "location")) { + if (HAS_ATTR(param, kXMLCharExpr) && HAS_ATTR(param, kXMLCharLocation)) { issues.push_back(InterpreterIssue("Param element cannot have both expr and location attribute", param, InterpreterIssue::USCXML_ISSUE_WARNING)); } } for (auto iter = scripts.begin(); iter != scripts.end(); iter++) { DOMElement* script = *iter; - if (HAS_ATTR(script, "src") && script->getChildNodes()->getLength() > 0) { + if (HAS_ATTR(script, kXMLCharSource) && script->getChildNodes()->getLength() > 0) { issues.push_back(InterpreterIssue("Script element cannot have src attribute and children", script, InterpreterIssue::USCXML_ISSUE_WARNING)); } } for (auto iter = sends.begin(); iter != sends.end(); iter++) { DOMElement* send = *iter; - if (HAS_ATTR(send, "event") && HAS_ATTR(send, "eventexpr")) { + if (HAS_ATTR(send, kXMLCharEvent) && HAS_ATTR(send, kXMLCharEventExpr)) { issues.push_back(InterpreterIssue("Send element cannot have both event and eventexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(send, "target") && HAS_ATTR(send, "targetexpr")) { + if (HAS_ATTR(send, kXMLCharTarget) && HAS_ATTR(send, kXMLCharTargetExpr)) { issues.push_back(InterpreterIssue("Send element cannot have both target and targetexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(send, "type") && HAS_ATTR(send, "typeexpr")) { + if (HAS_ATTR(send, kXMLCharType) && HAS_ATTR(send, kXMLCharTypeExpr)) { issues.push_back(InterpreterIssue("Send element cannot have both type and typeexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(send, "id") && HAS_ATTR(send, "idlocation")) { + if (HAS_ATTR(send, kXMLCharId) && HAS_ATTR(send, kXMLCharIdLocation)) { issues.push_back(InterpreterIssue("Send element cannot have both id and idlocation attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(send, "delay") && HAS_ATTR(send, "delayexpr")) { + if (HAS_ATTR(send, kXMLCharDelay) && HAS_ATTR(send, kXMLCharDelayExpr)) { issues.push_back(InterpreterIssue("Send element cannot have both delay and delayexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(send, "delay") && HAS_ATTR(send, "target") && ATTR(send, "target")== "_internal") { + if (HAS_ATTR(send, kXMLCharDelay) && HAS_ATTR(send, kXMLCharTarget) && ATTR(send, kXMLCharTarget)== "_internal") { issues.push_back(InterpreterIssue("Send element cannot have delay with target _internal", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } std::list contentChilds = DOMUtils::filterChildElements(XML_PREFIX(send).str() + "content", send, false); std::list paramChilds = DOMUtils::filterChildElements(XML_PREFIX(send).str() + "param", send, false); - if (HAS_ATTR(send, "namelist") && contentChilds.size() > 0) { + if (HAS_ATTR(send, kXMLCharNameList) && contentChilds.size() > 0) { issues.push_back(InterpreterIssue("Send element cannot have namelist attribute and content child", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } @@ -801,26 +801,26 @@ NEXT_SET: } for (auto iter = cancels.begin(); iter != cancels.end(); iter++) { DOMElement* cancel = *iter; - if (HAS_ATTR(cancel, "sendid") && HAS_ATTR(cancel, "sendidexpr")) { + if (HAS_ATTR(cancel, kXMLCharSendId) && HAS_ATTR(cancel, kXMLCharSendIdExpr)) { issues.push_back(InterpreterIssue("Cancel element cannot have both sendid and eventexpr sendidexpr", cancel, InterpreterIssue::USCXML_ISSUE_WARNING)); } } for (auto iter = invokes.begin(); iter != invokes.end(); iter++) { DOMElement* invoke = *iter; - if (HAS_ATTR(invoke, "type") && HAS_ATTR(invoke, "typeexpr")) { + if (HAS_ATTR(invoke, kXMLCharType) && HAS_ATTR(invoke, kXMLCharTypeExpr)) { issues.push_back(InterpreterIssue("Invoke element cannot have both type and typeexpr attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(invoke, "src") && HAS_ATTR(invoke, "srcexpr")) { + if (HAS_ATTR(invoke, kXMLCharSource) && HAS_ATTR(invoke, kXMLCharSourceExpr)) { issues.push_back(InterpreterIssue("Invoke element cannot have both src and srcexpr attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(invoke, "id") && HAS_ATTR(invoke, "idlocation")) { + if (HAS_ATTR(invoke, kXMLCharId) && HAS_ATTR(invoke, kXMLCharIdLocation)) { issues.push_back(InterpreterIssue("Invoke element cannot have both id and idlocation attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(invoke, "namelist") && DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "param", invoke, false).size() > 0) { + if (HAS_ATTR(invoke, kXMLCharNameList) && DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "param", invoke, false).size() > 0) { issues.push_back(InterpreterIssue("Invoke element cannot have namelist attribute and param child", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(invoke, "src") && DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "content", invoke, false).size() > 0) { + if (HAS_ATTR(invoke, kXMLCharSource) && DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "content", invoke, false).size() > 0) { issues.push_back(InterpreterIssue("Invoke element cannot have src attribute and content child", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); } @@ -837,9 +837,9 @@ NEXT_SET: // check that the datamodel is known if not already instantiated if (!interpreter->_dataModel) { - if (HAS_ATTR(_scxml, "datamodel")) { - if (!_factory->hasDataModel(ATTR(_scxml, "datamodel"))) { - issues.push_back(InterpreterIssue("SCXML document requires unknown datamodel '" + ATTR(_scxml, "datamodel") + "'", _scxml, InterpreterIssue::USCXML_ISSUE_FATAL)); + if (HAS_ATTR(_scxml, kXMLCharDataModel)) { + if (!_factory->hasDataModel(ATTR(_scxml, kXMLCharDataModel))) { + issues.push_back(InterpreterIssue("SCXML document requires unknown datamodel '" + ATTR(_scxml, kXMLCharDataModel) + "'", _scxml, InterpreterIssue::USCXML_ISSUE_FATAL)); // we cannot even check the rest as we require a datamodel return issues; @@ -850,9 +850,9 @@ NEXT_SET: bool instantiatedDataModel = false; // instantiate datamodel if not explicitly set if (!_dataModel) { - if (HAS_ATTR(_scxml, "datamodel")) { + if (HAS_ATTR(_scxml, kXMLCharDataModel)) { // might throw - _dataModel = _factory->createDataModel(ATTR(_scxml, "datamodel"), interpreter); + _dataModel = _factory->createDataModel(ATTR(_scxml, kXMLCharDataModel), interpreter); instantiatedDataModel = true; } else { _dataModel = _factory->createDataModel("null", interpreter); @@ -889,8 +889,8 @@ NEXT_SET: for (auto iter = withCondAttrs.begin(); iter != withCondAttrs.end(); iter++) { DOMElement* condAttr = *iter; - if (HAS_ATTR(condAttr, "cond")) { - if (!_dataModel.isValidSyntax(ATTR(condAttr, "cond"))) { + if (HAS_ATTR(condAttr, kXMLCharCond)) { + if (!_dataModel.isValidSyntax(ATTR(condAttr, kXMLCharCond))) { issues.push_back(InterpreterIssue("Syntax error in cond attribute", condAttr, InterpreterIssue::USCXML_ISSUE_WARNING)); continue; } @@ -908,14 +908,14 @@ NEXT_SET: for (auto iter = withExprAttrs.begin(); iter != withExprAttrs.end(); iter++) { DOMElement* withExprAttr = *iter; - if (HAS_ATTR(withExprAttr, "expr")) { + if (HAS_ATTR(withExprAttr, kXMLCharExpr)) { if (DOMUtils::isMember(withExprAttr, datas) || DOMUtils::isMember(withExprAttr, assigns)) { - if (!_dataModel.isValidSyntax("foo = " + ATTR(withExprAttr, "expr"))) { // TODO: this is ECMAScripty! + if (!_dataModel.isValidSyntax("foo = " + ATTR(withExprAttr, kXMLCharExpr))) { // TODO: this is ECMAScripty! issues.push_back(InterpreterIssue("Syntax error in expr attribute", withExprAttr, InterpreterIssue::USCXML_ISSUE_WARNING)); continue; } } else { - if (!_dataModel.isValidSyntax(ATTR(withExprAttr, "expr"))) { + if (!_dataModel.isValidSyntax(ATTR(withExprAttr, kXMLCharExpr))) { issues.push_back(InterpreterIssue("Syntax error in expr attribute", withExprAttr, InterpreterIssue::USCXML_ISSUE_WARNING)); continue; } @@ -927,18 +927,18 @@ NEXT_SET: { for (auto iter = foreachs.begin(); iter != foreachs.end(); iter++) { DOMElement* foreach = *iter; - if (HAS_ATTR(foreach, "array")) { - if (!_dataModel.isValidSyntax(ATTR(foreach, "array"))) { + if (HAS_ATTR(foreach, kXMLCharArray)) { + if (!_dataModel.isValidSyntax(ATTR(foreach, kXMLCharArray))) { issues.push_back(InterpreterIssue("Syntax error in array attribute", foreach, InterpreterIssue::USCXML_ISSUE_WARNING)); } } - if (HAS_ATTR(foreach, "item")) { - if (!_dataModel.isValidSyntax(ATTR(foreach, "item"))) { + if (HAS_ATTR(foreach, kXMLCharItem)) { + if (!_dataModel.isValidSyntax(ATTR(foreach, kXMLCharItem))) { issues.push_back(InterpreterIssue("Syntax error in item attribute", foreach, InterpreterIssue::USCXML_ISSUE_WARNING)); } } - if (HAS_ATTR(foreach, "index")) { - if (!_dataModel.isValidSyntax(ATTR(foreach, "index"))) { + if (HAS_ATTR(foreach, kXMLCharIndex)) { + if (!_dataModel.isValidSyntax(ATTR(foreach, kXMLCharIndex))) { issues.push_back(InterpreterIssue("Syntax error in index attribute", foreach, InterpreterIssue::USCXML_ISSUE_WARNING)); } } @@ -948,28 +948,28 @@ NEXT_SET: { for (auto iter = sends.begin(); iter != sends.end(); iter++) { DOMElement* send = *iter; - if (HAS_ATTR(send, "eventexpr")) { - if (!_dataModel.isValidSyntax(ATTR(send, "eventexpr"))) { + if (HAS_ATTR(send, kXMLCharEventExpr)) { + if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharEventExpr))) { issues.push_back(InterpreterIssue("Syntax error in eventexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } } - if (HAS_ATTR(send, "targetexpr")) { - if (!_dataModel.isValidSyntax(ATTR(send, "targetexpr"))) { + if (HAS_ATTR(send, kXMLCharTargetExpr)) { + if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharTargetExpr))) { issues.push_back(InterpreterIssue("Syntax error in targetexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } } - if (HAS_ATTR(send, "typeexpr")) { - if (!_dataModel.isValidSyntax(ATTR(send, "typeexpr"))) { + if (HAS_ATTR(send, kXMLCharTypeExpr)) { + if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharTypeExpr))) { issues.push_back(InterpreterIssue("Syntax error in typeexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } } - if (HAS_ATTR(send, "idlocation")) { - if (!_dataModel.isValidSyntax(ATTR(send, "idlocation"))) { + if (HAS_ATTR(send, kXMLCharIdLocation)) { + if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharIdLocation))) { issues.push_back(InterpreterIssue("Syntax error in idlocation attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } } - if (HAS_ATTR(send, "delayexpr")) { - if (!_dataModel.isValidSyntax(ATTR(send, "delayexpr"))) { + if (HAS_ATTR(send, kXMLCharDelayExpr)) { + if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharDelayExpr))) { issues.push_back(InterpreterIssue("Syntax error in delayexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } } @@ -980,20 +980,20 @@ NEXT_SET: { for (auto iter = invokes.begin(); iter != invokes.end(); iter++) { DOMElement* invoke = *iter; - if (HAS_ATTR(invoke, "typeexpr")) { - if (!_dataModel.isValidSyntax(ATTR(invoke, "typeexpr"))) { + if (HAS_ATTR(invoke, kXMLCharTypeExpr)) { + if (!_dataModel.isValidSyntax(ATTR(invoke, kXMLCharTypeExpr))) { issues.push_back(InterpreterIssue("Syntax error in typeexpr attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); continue; } } - if (HAS_ATTR(invoke, "srcexpr")) { - if (!_dataModel.isValidSyntax(ATTR(invoke, "srcexpr"))) { + if (HAS_ATTR(invoke, kXMLCharSourceExpr)) { + if (!_dataModel.isValidSyntax(ATTR(invoke, kXMLCharSourceExpr))) { issues.push_back(InterpreterIssue("Syntax error in srcexpr attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); continue; } } - if (HAS_ATTR(invoke, "idlocation")) { - if (!_dataModel.isValidSyntax(ATTR(invoke, "idlocation"))) { + if (HAS_ATTR(invoke, kXMLCharIdLocation)) { + if (!_dataModel.isValidSyntax(ATTR(invoke, kXMLCharIdLocation))) { issues.push_back(InterpreterIssue("Syntax error in idlocation attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); continue; } @@ -1004,8 +1004,8 @@ NEXT_SET: { for (auto iter = cancels.begin(); iter != cancels.end(); iter++) { DOMElement* cancel = *iter; - if (HAS_ATTR(cancel, "sendidexpr")) { - if (!_dataModel.isValidSyntax(ATTR(cancel, "sendidexpr"))) { + if (HAS_ATTR(cancel, kXMLCharSendIdExpr)) { + if (!_dataModel.isValidSyntax(ATTR(cancel, kXMLCharSendIdExpr))) { issues.push_back(InterpreterIssue("Syntax error in sendidexpr attribute", cancel, InterpreterIssue::USCXML_ISSUE_WARNING)); continue; } diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index b57837f..a801f35 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -40,7 +40,7 @@ std::shared_ptr BasicContentExecutor::create(ContentExecuto } void BasicContentExecutor::processRaise(XERCESC_NS::DOMElement* content) { - Event raised(ATTR(content, "event")); + Event raised(ATTR(content, kXMLCharEvent)); _callbacks->enqueueInternal(raised); } @@ -61,10 +61,10 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { try { // event - if (HAS_ATTR(element, "eventexpr")) { - sendEvent.name = _callbacks->evalAsData(ATTR(element, "eventexpr")).atom; - } else if (HAS_ATTR(element, "event")) { - sendEvent.name = ATTR(element, "event"); + if (HAS_ATTR(element, kXMLCharEventExpr)) { + sendEvent.name = _callbacks->evalAsData(ATTR(element, kXMLCharEventExpr)).atom; + } else if (HAS_ATTR(element, kXMLCharEvent)) { + sendEvent.name = ATTR(element, kXMLCharEvent); } } catch (Event e) { ERROR_EXECUTION_THROW2("Syntax error in send element eventexpr", element); @@ -72,10 +72,10 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { try { // target - if (HAS_ATTR(element, "targetexpr")) { - target = _callbacks->evalAsData(ATTR(element, "targetexpr")).atom; - } else if (HAS_ATTR(element, "target")) { - target = ATTR(element, "target"); + if (HAS_ATTR(element, kXMLCharTargetExpr)) { + target = _callbacks->evalAsData(ATTR(element, kXMLCharTargetExpr)).atom; + } else if (HAS_ATTR(element, kXMLCharTarget)) { + target = ATTR(element, kXMLCharTarget); } } catch (Event e) { ERROR_EXECUTION_THROW2("Syntax error in send element targetexpr", element); @@ -83,10 +83,10 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { try { // type - if (HAS_ATTR(element, "typeexpr")) { - type = _callbacks->evalAsData(ATTR(element, "typeexpr")).atom; - } else if (HAS_ATTR(element, "type")) { - type = ATTR(element, "type"); + if (HAS_ATTR(element, kXMLCharTypeExpr)) { + type = _callbacks->evalAsData(ATTR(element, kXMLCharTypeExpr)).atom; + } else if (HAS_ATTR(element, kXMLCharType)) { + type = ATTR(element, kXMLCharType); } } catch (Event e) { ERROR_EXECUTION_THROW2("Syntax error in send element typeexpr", element); @@ -94,8 +94,8 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { try { // id - if (HAS_ATTR(element, "id")) { - sendEvent.sendid = ATTR(element, "id"); + if (HAS_ATTR(element, kXMLCharId)) { + sendEvent.sendid = ATTR(element, kXMLCharId); } else { /* * The ids for and are subtly different. In a conformant @@ -116,9 +116,9 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { * See 3.14 IDs for details. * */ - sendEvent.sendid = ATTR(getParentState(element), "id") + "." + UUID::getUUID(); - if (HAS_ATTR(element, "idlocation")) { - _callbacks->assign(ATTR(element, "idlocation"), Data(sendEvent.sendid, Data::VERBATIM), std::map()); + sendEvent.sendid = ATTR(getParentState(element), kXMLCharId) + "." + UUID::getUUID(); + if (HAS_ATTR(element, kXMLCharIdLocation)) { + _callbacks->assign(ATTR(element, kXMLCharIdLocation), Data(sendEvent.sendid, Data::VERBATIM), std::map()); } else { sendEvent.hideSendId = true; } @@ -130,10 +130,10 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { try { // delay std::string delay; - if (HAS_ATTR(element, "delayexpr")) { - delay = _callbacks->evalAsData(ATTR(element, "delayexpr")); - } else if (HAS_ATTR(element, "delay")) { - delay = ATTR(element, "delay"); + if (HAS_ATTR(element, kXMLCharDelayExpr)) { + delay = _callbacks->evalAsData(ATTR(element, kXMLCharDelayExpr)); + } else if (HAS_ATTR(element, kXMLCharDelay)) { + delay = ATTR(element, kXMLCharDelay); } if (delay.size() > 0) { NumAttr delayAttr(delay); @@ -200,10 +200,10 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { void BasicContentExecutor::processCancel(XERCESC_NS::DOMElement* content) { std::string sendid; - if (HAS_ATTR(content, "sendid")) { - sendid = ATTR(content, "sendid"); - } else if (HAS_ATTR(content, "sendidexpr")) { - sendid = _callbacks->evalAsData(ATTR(content, "sendidexpr")).atom; + if (HAS_ATTR(content, kXMLCharSendId)) { + sendid = ATTR(content, kXMLCharSendId); + } else if (HAS_ATTR(content, kXMLCharSendIdExpr)) { + sendid = _callbacks->evalAsData(ATTR(content, kXMLCharSendIdExpr)).atom; } else { ERROR_EXECUTION_THROW2("Cancel element has neither sendid nor sendidexpr attribute", content); @@ -212,7 +212,7 @@ void BasicContentExecutor::processCancel(XERCESC_NS::DOMElement* content) { } void BasicContentExecutor::processIf(XERCESC_NS::DOMElement* content) { - bool blockIsTrue = _callbacks->isTrue(ATTR(content, "cond")); + bool blockIsTrue = _callbacks->isTrue(ATTR(content, kXMLCharCond)); for (auto childElem = content->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { if (iequals(TAGNAME(childElem), XML_PREFIX(content).str() + "elseif")) { @@ -220,7 +220,7 @@ void BasicContentExecutor::processIf(XERCESC_NS::DOMElement* content) { // last block was true, break here break; } - blockIsTrue = _callbacks->isTrue(ATTR(childElem, "cond")); + blockIsTrue = _callbacks->isTrue(ATTR(childElem, kXMLCharCond)); continue; } if (iequals(TAGNAME(childElem), XML_PREFIX(content).str() + "else")) { @@ -241,7 +241,7 @@ void BasicContentExecutor::processIf(XERCESC_NS::DOMElement* content) { } void BasicContentExecutor::processAssign(XERCESC_NS::DOMElement* content) { - std::string location = ATTR(content, "location"); + std::string location = ATTR(content, kXMLCharLocation); std::map additionalAttr; auto xmlAttrs = content->getAttributes(); @@ -255,9 +255,9 @@ void BasicContentExecutor::processAssign(XERCESC_NS::DOMElement* content) { } void BasicContentExecutor::processForeach(XERCESC_NS::DOMElement* content) { - std::string array = ATTR(content, "array"); - std::string item = ATTR(content, "item"); - std::string index = (HAS_ATTR(content, "index") ? ATTR(content, "index") : ""); + std::string array = ATTR(content, kXMLCharArray); + std::string item = ATTR(content, kXMLCharItem); + std::string index = (HAS_ATTR(content, kXMLCharIndex) ? ATTR(content, kXMLCharIndex) : ""); uint32_t iterations = 0; iterations = _callbacks->getLength(array); @@ -272,8 +272,8 @@ void BasicContentExecutor::processForeach(XERCESC_NS::DOMElement* content) { } void BasicContentExecutor::processLog(XERCESC_NS::DOMElement* content) { - std::string label = ATTR(content, "label"); - std::string expr = ATTR(content, "expr"); + std::string label = ATTR(content, kXMLCharLabel); + std::string expr = ATTR(content, kXMLCharExpr); Data d = _callbacks->evalAsData(expr); if (label.size() > 0) { @@ -326,7 +326,7 @@ void BasicContentExecutor::process(XERCESC_NS::DOMElement* block, const X& xmlPr // Specification 6.5.2: http://www.w3.org/TR/scxml/#N110EF const Event& event = _callbacks->getCurrentEvent(); - std::list names = tokenize(ATTR(invokeElem, "namelist")); + std::list names = tokenize(ATTR(invokeElem, kXMLCharNameList)); for (std::list::iterator nameIter = names.begin(); nameIter != names.end(); nameIter++) { if (event.namelist.find(*nameIter) != event.namelist.end()) { // scxml i/o proc keeps a dedicated namelist @@ -388,20 +388,20 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { Event invokeEvent; // type - if (HAS_ATTR(element, "typeexpr")) { - type = _callbacks->evalAsData(ATTR(element, "typeexpr")).atom; - } else if (HAS_ATTR(element, "type")) { - type = ATTR(element, "type"); + if (HAS_ATTR(element, kXMLCharTypeExpr)) { + type = _callbacks->evalAsData(ATTR(element, kXMLCharTypeExpr)).atom; + } else if (HAS_ATTR(element, kXMLCharType)) { + type = ATTR(element, kXMLCharType); } else { // test 422 type = "http://www.w3.org/TR/scxml/"; } // src - if (HAS_ATTR(element, "srcexpr")) { - source = _callbacks->evalAsData(ATTR(element, "srcexpr")).atom; - } else if (HAS_ATTR(element, "src")) { - source = ATTR(element, "src"); + if (HAS_ATTR(element, kXMLCharSourceExpr)) { + source = _callbacks->evalAsData(ATTR(element, kXMLCharSourceExpr)).atom; + } else if (HAS_ATTR(element, kXMLCharSource)) { + source = ATTR(element, kXMLCharSource); } if (source.length() > 0) { // absolutize url @@ -409,12 +409,12 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { // id try { - if (HAS_ATTR(element, "id")) { - invokeEvent.invokeid = ATTR(element, "id"); + if (HAS_ATTR(element, kXMLCharId)) { + invokeEvent.invokeid = ATTR(element, kXMLCharId); } else { - invokeEvent.invokeid = ATTR(getParentState(element), "id") + "." + UUID::getUUID(); - if (HAS_ATTR(element, "idlocation")) { - _callbacks->assign(ATTR(element, "idlocation"), Data(invokeEvent.invokeid, Data::VERBATIM), std::map()); + invokeEvent.invokeid = ATTR(getParentState(element), kXMLCharId) + "." + UUID::getUUID(); + if (HAS_ATTR(element, kXMLCharIdLocation)) { + _callbacks->assign(ATTR(element, kXMLCharIdLocation), Data(invokeEvent.invokeid, Data::VERBATIM), std::map()); } } @@ -423,7 +423,7 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { memcpy(invokeId, invokeEvent.invokeid.c_str(), invokeEvent.invokeid.size()); invokeId[invokeEvent.invokeid.size()] = 0; - element->setUserData(X("invokeid"), (void*)invokeId, NULL); + element->setUserData(kXMLCharInvokeId, (void*)invokeId, NULL); } catch (Event e) { ERROR_EXECUTION_THROW2("Syntax error in invoke element idlocation", element); } @@ -465,8 +465,8 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { } // autoforward - if (HAS_ATTR(element, "autoforward")) { - if (iequals(ATTR(element, "autoforward"), "true")) { + if (HAS_ATTR(element, kXMLCharAutoForward)) { + if (iequals(ATTR(element, kXMLCharAutoForward), "true")) { autoForward = true; } } @@ -484,14 +484,14 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { } void BasicContentExecutor::uninvoke(XERCESC_NS::DOMElement* invoke) { - char* invokeId = (char*)invoke->getUserData(X("invokeid")); + char* invokeId = (char*)invoke->getUserData(X(kXMLCharInvokeId)); assert(invokeId != NULL); USCXML_MONITOR_CALLBACK2(_callbacks->getMonitors(), beforeUninvoking, invoke, invokeId); _callbacks->uninvoke(invokeId); USCXML_MONITOR_CALLBACK2(_callbacks->getMonitors(), afterUninvoking, invoke, invokeId); - invoke->setUserData(X("invokeid"), NULL, NULL); + invoke->setUserData(kXMLCharInvokeId, NULL, NULL); free(invokeId); } @@ -499,7 +499,7 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC Event doneEvent; doneEvent.name = "done.state."; - doneEvent.name += HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::idForNode(state); + doneEvent.name += HAS_ATTR(state, kXMLCharId) ? ATTR(state, kXMLCharId) : DOMUtils::idForNode(state); if (doneData != NULL) { try { @@ -544,8 +544,8 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC } void BasicContentExecutor::processNameLists(std::map& nameMap, DOMElement* element) { - if (HAS_ATTR(element, "namelist")) { - std::list names = tokenize(ATTR(element, "namelist")); + if (HAS_ATTR(element, kXMLCharNameList)) { + std::list names = tokenize(ATTR(element, kXMLCharNameList)); for (std::list::const_iterator nameIter = names.begin(); nameIter != names.end(); nameIter++) { nameMap[*nameIter] = _callbacks->evalAsData(*nameIter); } @@ -555,12 +555,12 @@ void BasicContentExecutor::processNameLists(std::map& nameMap void BasicContentExecutor::processParams(std::multimap& paramMap, DOMElement* element) { std::list params = DOMUtils::filterChildElements(XML_PREFIX(element).str() + "param", element); for (auto paramIter = params.begin(); paramIter != params.end(); paramIter++) { - std::string name = ATTR(*paramIter, "name"); + std::string name = ATTR(*paramIter, kXMLCharName); Data d; - if (HAS_ATTR(*paramIter, "expr")) { - d = _callbacks->evalAsData(ATTR(*paramIter, "expr")); - } else if (HAS_ATTR(*paramIter, "location")) { - d = _callbacks->evalAsData(ATTR(*paramIter, "location")); + if (HAS_ATTR(*paramIter, kXMLCharExpr)) { + d = _callbacks->evalAsData(ATTR(*paramIter, kXMLCharExpr)); + } else if (HAS_ATTR(*paramIter, kXMLCharLocation)) { + d = _callbacks->evalAsData(ATTR(*paramIter, kXMLCharLocation)); } else { d = elementAsData(*paramIter); } @@ -569,28 +569,28 @@ void BasicContentExecutor::processParams(std::multimap& param } Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element, bool asExpression) { - if (HAS_ATTR(element, "expr")) { + if (HAS_ATTR(element, kXMLCharExpr)) { // return _callbacks->evalAsData(ATTR(element, "expr")); #if 0 if (LOCALNAME(element) == "content") { // test 528 - return _callbacks->evalAsData(ATTR(element, "expr")); + return _callbacks->evalAsData(ATTR(element, kXMLCharExpr)); } else { // test 326 - return Data(ATTR(element, "expr"), Data::INTERPRETED); + return Data(ATTR(element, kXMLCharExpr), Data::INTERPRETED); } #endif if (asExpression) // test 453 - return Data(ATTR(element, "expr"), Data::INTERPRETED); - return _callbacks->evalAsData(ATTR(element, "expr")); + return Data(ATTR(element, kXMLCharExpr), Data::INTERPRETED); + return _callbacks->evalAsData(ATTR(element, kXMLCharExpr)); } - if (HAS_ATTR(element, "src")) { + if (HAS_ATTR(element, kXMLCharSource)) { // remote content from URL // test 446, test 552, test 558 - std::string src = ATTR(element, "src"); - URL url(ATTR(element, "src")); + std::string src = ATTR(element, kXMLCharSource); + URL url(ATTR(element, kXMLCharSource)); if (!url.isAbsolute()) { url = URL::resolve(url, _callbacks->getBaseURL()); } diff --git a/src/uscxml/interpreter/FastMicroStep.cpp b/src/uscxml/interpreter/FastMicroStep.cpp index 33ffebd..b1197d0 100644 --- a/src/uscxml/interpreter/FastMicroStep.cpp +++ b/src/uscxml/interpreter/FastMicroStep.cpp @@ -155,7 +155,7 @@ void FastMicroStep::resortStates(DOMElement* element, const X& xmlPrefix) { child = element->getFirstElementChild(); while(child) { if (TAGNAME_CAST(child) == xmlPrefix.str() + "history" && - (!HAS_ATTR(element, "type") || iequals(ATTR(element, "type"), "shallow"))) { + (!HAS_ATTR(element, kXMLCharType) || iequals(ATTR(element, kXMLCharType), "shallow"))) { DOMElement* tmp = child->getNextElementSibling(); if (child != element->getFirstChild()) { @@ -172,8 +172,8 @@ void FastMicroStep::resortStates(DOMElement* element, const X& xmlPrefix) { while(child) { if (child->getNodeType() == DOMNode::ELEMENT_NODE && TAGNAME_CAST(child) == xmlPrefix.str() + "history" && - HAS_ATTR(element, "type") && - iequals(ATTR(element, "type"), "deep")) { + HAS_ATTR(element, kXMLCharType) && + iequals(ATTR(element, kXMLCharType), "deep")) { DOMElement* tmp = child->getNextElementSibling(); if (child != element->getFirstChild()) { @@ -230,7 +230,7 @@ bool FastMicroStep::conflictsCached(const DOMElement* t1, const DOMElement* t2, void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { _scxml = scxml; - _binding = (HAS_ATTR(_scxml, "binding") && iequals(ATTR(_scxml, "binding"), "late") ? LATE : EARLY); + _binding = (HAS_ATTR(_scxml, kXMLCharBinding) && iequals(ATTR(_scxml, kXMLCharBinding), "late") ? LATE : EARLY); _xmlPrefix = _scxml->getPrefix(); _xmlNS = _scxml->getNamespaceURI(); if (_xmlPrefix) { @@ -308,8 +308,8 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { } #endif // collect states with an id attribute - if (HAS_ATTR(_states[i]->element, "id")) { - _stateIds[ATTR(_states[i]->element, "id")] = i; + if (HAS_ATTR(_states[i]->element, kXMLCharId)) { + _stateIds[ATTR(_states[i]->element, kXMLCharId)] = i; } // check for executable content and datamodels @@ -343,7 +343,7 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { } else if (isFinal(_states[i]->element)) { _states[i]->type = USCXML_STATE_FINAL; } else if (isHistory(_states[i]->element)) { - if (HAS_ATTR(_states[i]->element, "type") && iequals(ATTR(_states[i]->element, "type"), "deep")) { + if (HAS_ATTR(_states[i]->element, kXMLCharType) && iequals(ATTR(_states[i]->element, kXMLCharType), "deep")) { _states[i]->type = USCXML_STATE_HISTORY_DEEP; } else { _states[i]->type = USCXML_STATE_HISTORY_SHALLOW; @@ -539,7 +539,7 @@ CONFLICTS_ESTABLISHED: } #endif { - std::list targets = tokenize(ATTR(_transitions[i]->element, "target")); + std::list targets = tokenize(ATTR(_transitions[i]->element, kXMLCharTarget)); for (auto tIter = targets.begin(); tIter != targets.end(); tIter++) { if (_stateIds.find(*tIter) != _stateIds.end()) { _transitions[i]->target[_stateIds[*tIter]] = true; @@ -557,15 +557,15 @@ TARGET_SET_ESTABLISHED: // the transition's type - if (!HAS_ATTR(_transitions[i]->element, "target")) { + if (!HAS_ATTR(_transitions[i]->element, kXMLCharTarget)) { _transitions[i]->type |= USCXML_TRANS_TARGETLESS; } - if (HAS_ATTR(_transitions[i]->element, "type") && iequals(ATTR(_transitions[i]->element, "type"), "internal")) { + if (HAS_ATTR(_transitions[i]->element, kXMLCharType) && iequals(ATTR(_transitions[i]->element, kXMLCharType), "internal")) { _transitions[i]->type |= USCXML_TRANS_INTERNAL; } - if (!HAS_ATTR(_transitions[i]->element, "event")) { + if (!HAS_ATTR(_transitions[i]->element, kXMLCharEvent)) { _transitions[i]->type |= USCXML_TRANS_SPONTANEOUS; } @@ -578,10 +578,10 @@ TARGET_SET_ESTABLISHED: } // the transitions event and condition - _transitions[i]->event = (HAS_ATTR(_transitions[i]->element, "event") ? - ATTR(_transitions[i]->element, "event") : ""); - _transitions[i]->cond = (HAS_ATTR(_transitions[i]->element, "cond") ? - ATTR(_transitions[i]->element, "cond") : ""); + _transitions[i]->event = (HAS_ATTR(_transitions[i]->element, kXMLCharEvent) ? + ATTR(_transitions[i]->element, kXMLCharEvent) : ""); + _transitions[i]->cond = (HAS_ATTR(_transitions[i]->element, kXMLCharCond) ? + ATTR(_transitions[i]->element, kXMLCharCond) : ""); // is there executable content? if (_transitions[i]->element->getChildElementCount() > 0) { @@ -1191,7 +1191,7 @@ std::list FastMicroStep::getHistoryCompletion(const DOMElement* his parent = history->getParentNode(); } - bool deep = (HAS_ATTR(history, "type") && iequals(ATTR(history, "type"), "deep")); + bool deep = (HAS_ATTR(history, kXMLCharType) && iequals(ATTR(history, kXMLCharType), "deep")); for (size_t j = 0; j < _states.size(); j++) { if (_states[j]->element == history) @@ -1244,8 +1244,8 @@ std::list FastMicroStep::getCompletion(const DOMElement* state) { } else if (isParallel(state)) { return getChildStates(state); - } else if (HAS_ATTR(state, "initial")) { - return getStates(tokenize(ATTR(state, "initial")), _scxml); + } else if (HAS_ATTR(state, kXMLCharInitial)) { + return getStates(tokenize(ATTR(state, kXMLCharInitial)), _scxml); } else { std::list completion; diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index 812c73b..1693462 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -190,8 +190,8 @@ void InterpreterImpl::deserialize(const std::string& encodedState) { std::list datas = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "data" }, _scxml); for (auto data : datas) { - if (HAS_ATTR(data, "id") && state["datamodel"].hasKey(ATTR(data, "id"))) - _dataModel.init(ATTR(data, "id"), state["datamodel"][ATTR(data, "id")]); + if (HAS_ATTR(data, kXMLCharId) && state["datamodel"].hasKey(ATTR(data, kXMLCharId))) + _dataModel.init(ATTR(data, kXMLCharId), state["datamodel"][ATTR(data, kXMLCharId)]); } _microStepper.deserialize(state["microstepper"]); @@ -232,8 +232,8 @@ std::string InterpreterImpl::serialize() { // SCXML Rec: "the values of all attributes of type "id" must be unique within the session" std::list datas = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "data" }, _scxml); for (auto data : datas) { - if (HAS_ATTR(data, "id")) { - serialized["datamodel"][ATTR(data, "id")] = _dataModel.evalAsData(ATTR(data, "id")); + if (HAS_ATTR(data, kXMLCharId)) { + serialized["datamodel"][ATTR(data, kXMLCharId)] = _dataModel.evalAsData(ATTR(data, kXMLCharId)); } } @@ -289,13 +289,13 @@ SCXML_STOP_SEARCH: if (_xmlPrefix) { _xmlPrefix = std::string(_xmlPrefix) + ":"; } - if (HAS_ATTR(_scxml, "name")) { - _name = ATTR(_scxml, "name"); + if (HAS_ATTR(_scxml, kXMLCharName)) { + _name = ATTR(_scxml, kXMLCharName); } else { _name = _baseURL.pathComponents().back(); } - _binding = (HAS_ATTR(_scxml, "binding") && iequals(ATTR(_scxml, "binding"), "late") ? LATE : EARLY); + _binding = (HAS_ATTR(_scxml, kXMLCharBinding) && iequals(ATTR(_scxml, kXMLCharBinding), "late") ? LATE : EARLY); } } @@ -365,7 +365,7 @@ void InterpreterImpl::init() { _microStepper.init(_scxml); if (!_dataModel) { - _dataModel = _factory->createDataModel(HAS_ATTR(_scxml, "datamodel") ? ATTR(_scxml, "datamodel") : "null", this); + _dataModel = _factory->createDataModel(HAS_ATTR(_scxml, kXMLCharDataModel) ? ATTR(_scxml, kXMLCharDataModel) : "null", this); } if (!_execContent) { _execContent = ContentExecutor(std::shared_ptr(new BasicContentExecutor(this))); @@ -385,7 +385,7 @@ void InterpreterImpl::init() { } void InterpreterImpl::initData(XERCESC_NS::DOMElement* root) { - std::string id = ATTR(root, "id"); + std::string id = ATTR(root, kXMLCharId); Data d; std::map additionalAttr; diff --git a/src/uscxml/transform/ChartToC.cpp b/src/uscxml/transform/ChartToC.cpp index 4cdb3ef..dbd4e8c 100644 --- a/src/uscxml/transform/ChartToC.cpp +++ b/src/uscxml/transform/ChartToC.cpp @@ -84,7 +84,7 @@ void ChartToC::setHistoryCompletion() { parent = history->getParentNode(); } - bool deep = (HAS_ATTR(history, "type") && iequals(ATTR(history, "type"), "deep")); + bool deep = (HAS_ATTR(history, kXMLCharType) && iequals(ATTR(history, kXMLCharType), "deep")); for (auto stateIter = _states.begin(); stateIter != _states.end(); stateIter++) { DOMElement* state = *stateIter; if (state == history) @@ -140,7 +140,7 @@ void ChartToC::resortStates(DOMNode* node) { resortStates(child); if (child->getNodeType() == DOMNode::ELEMENT_NODE && TAGNAME_CAST(child) == XML_PREFIX(node).str() + "history" && - (!HAS_ATTR(element, "type") || iequals(ATTR(element, "type"), "shallow"))) { + (!HAS_ATTR(element, kXMLCharType) || iequals(ATTR(element, kXMLCharType), "shallow"))) { DOMNode* tmp = child->getNextSibling(); if (child != element->getFirstChild()) { element->insertBefore(child, element->getFirstChild()); @@ -157,8 +157,8 @@ void ChartToC::resortStates(DOMNode* node) { resortStates(child); if (child->getNodeType() == DOMNode::ELEMENT_NODE && TAGNAME_CAST(child) == XML_PREFIX(node).str() + "history" && - HAS_ATTR(element, "type") && - iequals(ATTR(element, "type"), "deep")) { + HAS_ATTR(element, kXMLCharType) && + iequals(ATTR(element, kXMLCharType), "deep")) { DOMNode* tmp = child->getNextSibling(); if (child != element->getFirstChild()) { @@ -203,8 +203,8 @@ void ChartToC::setStateCompletion() { if (isParallel(state)) { completion = getChildStates(state); - } else if (HAS_ATTR(state, "initial")) { - completion = getStates(tokenize(ATTR(state, "initial")), _scxml); + } else if (HAS_ATTR(state, kXMLCharInitial)) { + completion = getStates(tokenize(ATTR(state, kXMLCharInitial)), _scxml); } else { std::list initElems = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "initial", state); @@ -259,8 +259,8 @@ void ChartToC::prepare() { DOMElement* state(_states[i]); state->setAttribute(X("documentOrder"), X(toStr(i))); if (state->getParentNode()->getNodeType() == DOMNode::ELEMENT_NODE && - HAS_ATTR_CAST(state->getParentNode(), "documentOrder")) { - state->setAttribute(X("parent"), X(ATTR_CAST(state->getParentNode(), "documentOrder"))); + HAS_ATTR_CAST(state->getParentNode(), X("documentOrder"))) { + state->setAttribute(X("parent"), X(ATTR_CAST(state->getParentNode(), X("documentOrder")))); } // set the states' children and whether it has a history @@ -302,8 +302,8 @@ void ChartToC::prepare() { DOMElement* transition = *transIter; transition->setAttribute(X("documentOrder"), X(toStr(index))); if (transition->getParentNode()->getNodeType() == DOMNode::ELEMENT_NODE && - HAS_ATTR_CAST(transition->getParentNode(), "documentOrder")) { - transition->setAttribute(X("source"), X(ATTR_CAST(transition->getParentNode(), "documentOrder"))); + HAS_ATTR_CAST(transition->getParentNode(), X("documentOrder"))) { + transition->setAttribute(X("source"), X(ATTR_CAST(transition->getParentNode(), X("documentOrder")))); } } @@ -355,15 +355,15 @@ void ChartToC::prepare() { transition->setAttribute(X("conflictBools"), X(conflictBools)); // and target - if (HAS_ATTR(transition, "target")) { - std::list targets = tokenize(ATTR(transition, "target")); + if (HAS_ATTR(transition, kXMLCharTarget)) { + std::list targets = tokenize(ATTR(transition, kXMLCharTarget)); std::string targetBools; for (size_t j = 0; j < _states.size(); j++) { DOMElement* state(_states[j]); - if (HAS_ATTR(state, "id") && - std::find(targets.begin(), targets.end(), escape(ATTR(state, "id"))) != targets.end()) { + if (HAS_ATTR(state, kXMLCharId) && + std::find(targets.begin(), targets.end(), escape(ATTR(state, kXMLCharId))) != targets.end()) { targetBools += "1"; } else { targetBools += "0"; @@ -469,15 +469,15 @@ void ChartToC::findNestedMachines() { if(!areFromSameMachine(invoke, _scxml)) continue; - if (HAS_ATTR(invoke, "type") && - ATTR(invoke, "type") != "scxml" && - ATTR(invoke, "type") != "http://www.w3.org/TR/scxml/") + if (HAS_ATTR(invoke, kXMLCharType) && + ATTR(invoke, kXMLCharType) != "scxml" && + ATTR(invoke, kXMLCharType) != "http://www.w3.org/TR/scxml/") continue; ChartToC* c2c = NULL; - if (HAS_ATTR(invoke, "src")) { + if (HAS_ATTR(invoke, kXMLCharSource)) { - URL srcURL(ATTR(invoke, "src")); + URL srcURL(ATTR(invoke, kXMLCharSource)); if (!srcURL.isAbsolute()) { srcURL = URL::resolve(srcURL, _baseURL); } @@ -1156,7 +1156,7 @@ void ChartToC::writeExecContent(std::ostream& stream) { size_t j = 0; for (auto iter = invokes.begin(); iter != invokes.end(); iter++, j++) { DOMElement* invoke = *iter; - stream << " ctx->invoke(ctx, s, &" << _prefix << "_elem_invokes[" << ATTR(invoke, "documentOrder") << "], uninvoke);" << std::endl; + stream << " ctx->invoke(ctx, s, &" << _prefix << "_elem_invokes[" << ATTR(invoke, X("documentOrder")) << "], uninvoke);" << std::endl; stream << std::endl; } stream << " return USCXML_ERR_OK;" << std::endl; @@ -1169,13 +1169,13 @@ void ChartToC::writeExecContent(std::ostream& stream) { DOMElement* transition(_transitions[i]); std::list execContent = DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition); - if (HAS_ATTR(transition, "cond")) { + if (HAS_ATTR(transition, kXMLCharCond)) { stream << "static int " << _prefix << "_" << DOMUtils::idForNode(transition) << "_is_enabled(const uscxml_ctx* ctx, const uscxml_transition* transition) {" << std::endl; - if (HAS_ATTR(_scxml, "datamodel") && ATTR(_scxml, "datamodel") == "native") { - stream << " return (" << ATTR(transition, "cond") << ");" << std::endl; + if (HAS_ATTR(_scxml, kXMLCharDataModel) && ATTR(_scxml, kXMLCharDataModel) == "native") { + stream << " return (" << ATTR(transition, kXMLCharCond) << ");" << std::endl; } else { stream << " if likely(ctx->is_true != NULL) {" << std::endl; - stream << " return (ctx->is_true(ctx, \"" << escape(ATTR(transition, "cond")) << "\"));" << std::endl; + stream << " return (ctx->is_true(ctx, \"" << escape(ATTR(transition, kXMLCharCond)) << "\"));" << std::endl; stream << " }" << std::endl; stream << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; } @@ -1205,7 +1205,7 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ if (node->getNodeType() == DOMNode::TEXT_NODE) { if (boost::trim_copy(X(node->getNodeValue()).str()).length() > 0) { - if (HAS_ATTR(_scxml, "datamodel") && ATTR(_scxml, "datamodel") == "native") { + if (HAS_ATTR(_scxml, kXMLCharDataModel) && ATTR(_scxml, kXMLCharDataModel) == "native") { stream << node->getNodeValue(); } else { std::string escaped = escape(X(node->getNodeValue()).str()); @@ -1242,7 +1242,7 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << "if likely(ctx->exec_content_script != NULL) {" << std::endl; stream << padding; stream << " if unlikely((err = ctx->exec_content_script(ctx, "; - stream << (HAS_ATTR(elem, "src") ? "\"" + escape(ATTR(elem, "src")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(elem, kXMLCharSource) ? "\"" + escape(ATTR(elem, kXMLCharSource)) + "\"" : "NULL") << ", "; std::list scriptTexts = DOMUtils::filterChildType(DOMNode::TEXT_NODE, elem); if (scriptTexts.size() > 0) { @@ -1263,8 +1263,8 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << "if likely(ctx->exec_content_log != NULL) {" << std::endl; stream << padding; stream << " if unlikely((ctx->exec_content_log(ctx, "; - stream << (HAS_ATTR(elem, "label") ? "\"" + escape(ATTR(elem, "label")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(elem, "expr") ? "\"" + escape(ATTR(elem, "expr")) + "\"" : "NULL"); + stream << (HAS_ATTR(elem, kXMLCharLabel) ? "\"" + escape(ATTR(elem, kXMLCharLabel)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(elem, kXMLCharExpr) ? "\"" + escape(ATTR(elem, kXMLCharExpr)) + "\"" : "NULL"); stream << ")) != USCXML_ERR_OK) return err;" << std::endl; stream << padding << "} else {" << std::endl; stream << padding << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; @@ -1276,15 +1276,15 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << padding << " ctx->exec_content_foreach_done != NULL) {" << std::endl; stream << std::endl; - stream << padding << " if unlikely((ctx->exec_content_foreach_init(ctx, &" << _prefix << "_elem_foreachs[" << ATTR(elem, "documentOrder") << "])) != USCXML_ERR_OK) return err;" << std::endl; - stream << padding << " while (ctx->exec_content_foreach_next(ctx, &" << _prefix << "_elem_foreachs[" << ATTR(elem, "documentOrder") << "]) == USCXML_ERR_OK) {" << std::endl; + stream << padding << " if unlikely((ctx->exec_content_foreach_init(ctx, &" << _prefix << "_elem_foreachs[" << ATTR(elem, X("documentOrder")) << "])) != USCXML_ERR_OK) return err;" << std::endl; + stream << padding << " while (ctx->exec_content_foreach_next(ctx, &" << _prefix << "_elem_foreachs[" << ATTR(elem, X("documentOrder")) << "]) == USCXML_ERR_OK) {" << std::endl; DOMNode* child = node->getFirstChild(); while(child) { writeExecContent(stream, child, indent + 2); child = child->getNextSibling(); } stream << padding << " }" << std::endl; - stream << padding << " if ((ctx->exec_content_foreach_done(ctx, &" << _prefix << "_elem_foreachs[" << ATTR(elem, "documentOrder") << "])) != USCXML_ERR_OK) return err;" << std::endl; + stream << padding << " if ((ctx->exec_content_foreach_done(ctx, &" << _prefix << "_elem_foreachs[" << ATTR(elem, X("documentOrder")) << "])) != USCXML_ERR_OK) return err;" << std::endl; stream << padding << "} else {" << std::endl; stream << padding << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; stream << padding << "}" << std::endl; @@ -1293,12 +1293,12 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << padding; stream << "if likely(ctx->is_true != NULL) {" << std::endl; stream << padding; - stream << " if (ctx->is_true(ctx, " << (HAS_ATTR(elem, "cond") ? "\"" + escape(ATTR(elem, "cond")) + "\"" : "NULL") << ")) {" << std::endl; + stream << " if (ctx->is_true(ctx, " << (HAS_ATTR(elem, kXMLCharCond) ? "\"" + escape(ATTR(elem, kXMLCharCond)) + "\"" : "NULL") << ")) {" << std::endl; DOMNode* child = elem->getFirstChild(); while(child) { if (child->getNodeType() == DOMNode::ELEMENT_NODE && TAGNAME_CAST(child) == "elseif") { stream << padding; - stream << " } else if (ctx->is_true(ctx, " << (HAS_ATTR_CAST(child, "cond") ? "\"" + escape(ATTR_CAST(child, "cond")) + "\"" : "NULL") << ")) {" << std::endl; + stream << " } else if (ctx->is_true(ctx, " << (HAS_ATTR_CAST(child, kXMLCharCond) ? "\"" + escape(ATTR_CAST(child, kXMLCharCond)) + "\"" : "NULL") << ")) {" << std::endl; } else if (child->getNodeType() == DOMNode::ELEMENT_NODE && TAGNAME_CAST(child) == "else") { stream << padding; stream << " } else {" << std::endl; @@ -1316,7 +1316,7 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << padding; stream << "if likely(ctx->exec_content_assign != NULL) {" << std::endl; stream << padding; - stream << " if ((ctx->exec_content_assign(ctx, &" << _prefix << "_elem_assigns[" << ATTR(elem, "documentOrder") << "]"; + stream << " if ((ctx->exec_content_assign(ctx, &" << _prefix << "_elem_assigns[" << ATTR(elem, X("documentOrder")) << "]"; stream << ")) != USCXML_ERR_OK) return err;" << std::endl; stream << padding << "} else {" << std::endl; stream << padding << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; @@ -1328,7 +1328,7 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << "if likely(ctx->exec_content_raise != NULL) {" << std::endl; stream << padding; stream << " if unlikely((ctx->exec_content_raise(ctx, "; - stream << (HAS_ATTR(elem, "event") ? "\"" + escape(ATTR(elem, "event")) + "\"" : "NULL"); + stream << (HAS_ATTR(elem, kXMLCharEvent) ? "\"" + escape(ATTR(elem, kXMLCharEvent)) + "\"" : "NULL"); stream << ")) != USCXML_ERR_OK) return err;" << std::endl; stream << padding << "} else {" << std::endl; stream << padding << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; @@ -1338,7 +1338,7 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << padding; stream << "if likely(ctx->exec_content_send != NULL) {" << std::endl; stream << padding; - stream << " if ((ctx->exec_content_send(ctx, &" << _prefix << "_elem_sends[" << ATTR(elem, "documentOrder") << "]"; + stream << " if ((ctx->exec_content_send(ctx, &" << _prefix << "_elem_sends[" << ATTR(elem, X("documentOrder")) << "]"; stream << ")) != USCXML_ERR_OK) return err;" << std::endl; stream << padding << "} else {" << std::endl; stream << padding << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; @@ -1349,8 +1349,8 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << "if likely(ctx->exec_content_cancel != NULL) {" << std::endl; stream << padding; stream << " if ((ctx->exec_content_cancel(ctx, "; - stream << (HAS_ATTR(elem, "sendid") ? "\"" + escape(ATTR(elem, "sendid")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(elem, "sendidexpr") ? "\"" + escape(ATTR(elem, "sendidexpr")) + "\"" : "NULL"); + stream << (HAS_ATTR(elem, kXMLCharSendId) ? "\"" + escape(ATTR(elem, kXMLCharSendId)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(elem, kXMLCharSendIdExpr) ? "\"" + escape(ATTR(elem, kXMLCharSendIdExpr)) + "\"" : "NULL"); stream << ")) != USCXML_ERR_OK) return err;" << std::endl; stream << padding << "} else {" << std::endl; stream << padding << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; @@ -1398,11 +1398,11 @@ void ChartToC::writeElementInfoInvocation(std::ostream& stream) { stream << " { " << std::endl; stream << " /* machine */ "; - if (HAS_ATTR(invoke, "md5sum")) { + if (HAS_ATTR(invoke, X("md5sum"))) { #if 1 size_t machIdx = 0; for (std::list::iterator machIter = _allMachines.begin(); machIter != _allMachines.end(); machIter++, machIdx++) { - if ((*machIter)->_md5 == ATTR(invoke, "md5sum")) { + if ((*machIter)->_md5 == ATTR(invoke, X("md5sum"))) { stream << "&" << (*machIter)->_prefix << "_machine"; break; } @@ -1422,44 +1422,44 @@ void ChartToC::writeElementInfoInvocation(std::ostream& stream) { stream << ", " << std::endl; stream << " /* type */ "; - stream << (HAS_ATTR(invoke, "type") ? "\"" + escape(ATTR(invoke, "type")) + "\"" : "NULL"); + stream << (HAS_ATTR(invoke, kXMLCharType) ? "\"" + escape(ATTR(invoke, kXMLCharType)) + "\"" : "NULL"); stream << ", " << std::endl; stream << " /* typeexpr */ "; - stream << (HAS_ATTR(invoke, "typeexpr") ? "\"" + escape(ATTR(invoke, "typeexpr")) + "\"" : "NULL"); + stream << (HAS_ATTR(invoke, kXMLCharTypeExpr) ? "\"" + escape(ATTR(invoke, kXMLCharTypeExpr)) + "\"" : "NULL"); stream << ", " << std::endl; stream << " /* src */ "; - stream << (HAS_ATTR(invoke, "src") ? "\"" + escape(ATTR(invoke, "src")) + "\"" : "NULL"); + stream << (HAS_ATTR(invoke, kXMLCharSource) ? "\"" + escape(ATTR(invoke, kXMLCharSource)) + "\"" : "NULL"); stream << ", " << std::endl; stream << " /* srcexpr */ "; - stream << (HAS_ATTR(invoke, "srcexpr") ? "\"" + escape(ATTR(invoke, "srcexpr")) + "\"" : "NULL"); + stream << (HAS_ATTR(invoke, kXMLCharSourceExpr) ? "\"" + escape(ATTR(invoke, kXMLCharSourceExpr)) + "\"" : "NULL"); stream << ", " << std::endl; stream << " /* id */ "; - stream << (HAS_ATTR(invoke, "id") ? "\"" + escape(ATTR(invoke, "id")) + "\"" : "NULL"); + stream << (HAS_ATTR(invoke, kXMLCharId) ? "\"" + escape(ATTR(invoke, kXMLCharId)) + "\"" : "NULL"); stream << ", " << std::endl; stream << " /* idlocation */ "; - stream << (HAS_ATTR(invoke, "idlocation") ? "\"" + escape(ATTR(invoke, "idlocation")) + "\"" : "NULL"); + stream << (HAS_ATTR(invoke, kXMLCharIdLocation) ? "\"" + escape(ATTR(invoke, kXMLCharIdLocation)) + "\"" : "NULL"); stream << ", " << std::endl; stream << " /* sourcename */ "; - stream << (HAS_ATTR_CAST(invoke->getParentNode(), "id") ? "\"" + escape(ATTR_CAST(invoke->getParentNode(), "id")) + "\"" : "NULL"); + stream << (HAS_ATTR_CAST(invoke->getParentNode(), kXMLCharId) ? "\"" + escape(ATTR_CAST(invoke->getParentNode(), kXMLCharId)) + "\"" : "NULL"); stream << ", " << std::endl; stream << " /* namelist */ "; - stream << (HAS_ATTR(invoke, "namelist") ? "\"" + escape(ATTR(invoke, "namelist")) + "\"" : "NULL"); + stream << (HAS_ATTR(invoke, kXMLCharNameList) ? "\"" + escape(ATTR(invoke, kXMLCharNameList)) + "\"" : "NULL"); stream << ", " << std::endl; stream << " /* autoforward */ "; - stream << (HAS_ATTR(invoke, "autoforward") && stringIsTrue(ATTR(invoke, "autoforward")) ? "1" : "0"); + stream << (HAS_ATTR(invoke, kXMLCharAutoForward) && stringIsTrue(ATTR(invoke, kXMLCharAutoForward)) ? "1" : "0"); stream << ", " << std::endl; stream << " /* params */ "; - if (HAS_ATTR(invoke, "paramIndex")) { - stream << "&" << _prefix << "_elem_params[" << escape(ATTR(invoke, "paramIndex")) << "]"; + if (HAS_ATTR(invoke, X("paramIndex"))) { + stream << "&" << _prefix << "_elem_params[" << escape(ATTR(invoke, X("paramIndex"))) << "]"; } else { stream << "NULL"; } @@ -1475,7 +1475,7 @@ void ChartToC::writeElementInfoInvocation(std::ostream& stream) { stream << ", " << std::endl; std::list contents = DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "content", invoke); - if (contents.size() > 0 && !HAS_ATTR(invoke, "md5sum")) { + if (contents.size() > 0 && !HAS_ATTR(invoke, X("md5sum"))) { std::stringstream ss; DOMNodeList* cChilds = contents.front()->getChildNodes(); for (size_t j = 0; j < cChilds->getLength(); j++) { @@ -1484,7 +1484,7 @@ void ChartToC::writeElementInfoInvocation(std::ostream& stream) { stream << " /* content */ "; stream << (ss.str().size() > 0 ? "\"" + escape(ss.str()) + "\", " : "NULL, ") << std::endl; stream << " /* contentexpr */ "; - stream << (HAS_ATTR_CAST(contents.front(), "expr") ? "\"" + ATTR_CAST(contents.front(), "expr") + "\", " : "NULL, ") << std::endl; + stream << (HAS_ATTR_CAST(contents.front(), kXMLCharExpr) ? "\"" + ATTR_CAST(contents.front(), kXMLCharExpr) + "\", " : "NULL, ") << std::endl; } else { stream << " /* content */ NULL," << std::endl; stream << " /* contentexpr */ NULL," << std::endl; @@ -1516,9 +1516,9 @@ void ChartToC::writeElementInfo(std::ostream& stream) { for (auto iter = foreachs.begin(); iter != foreachs.end(); iter++, i++) { DOMElement* foreach = *iter; stream << " { "; - stream << (HAS_ATTR(foreach, "array") ? "\"" + escape(ATTR(foreach, "array")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(foreach, "item") ? "\"" + escape(ATTR(foreach, "item")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(foreach, "index") ? "\"" + escape(ATTR(foreach, "index")) + "\"" : "NULL"); + stream << (HAS_ATTR(foreach, kXMLCharArray) ? "\"" + escape(ATTR(foreach, kXMLCharArray)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(foreach, kXMLCharItem) ? "\"" + escape(ATTR(foreach, kXMLCharItem)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(foreach, kXMLCharIndex) ? "\"" + escape(ATTR(foreach, kXMLCharIndex)) + "\"" : "NULL"); stream << " }" << (i + 1 < foreachs.size() ? ",": "") << std::endl; foreach->setAttribute(X("documentOrder"), X(toStr(i))); } @@ -1537,8 +1537,8 @@ void ChartToC::writeElementInfo(std::ostream& stream) { DOMElement* assign = *iter; stream << " { "; - stream << (HAS_ATTR(assign, "location") ? "\"" + escape(ATTR(assign, "location")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(assign, "expr") ? "\"" + escape(ATTR(assign, "expr")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(assign, kXMLCharLocation) ? "\"" + escape(ATTR(assign, kXMLCharLocation)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(assign, kXMLCharExpr) ? "\"" + escape(ATTR(assign, kXMLCharExpr)) + "\"" : "NULL") << ", "; std::list assignTexts = DOMUtils::filterChildType(DOMNode::TEXT_NODE, assign); if (assignTexts.size() > 0) { @@ -1596,9 +1596,9 @@ void ChartToC::writeElementInfo(std::ostream& stream) { parent = data->getParentNode()->getParentNode(); } stream << " { "; - stream << (HAS_ATTR(data, "id") ? "\"" + escape(ATTR(data, "id")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(data, "src") ? "\"" + escape(ATTR(data, "src")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(data, "expr") ? "\"" + escape(ATTR(data, "expr")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(data, kXMLCharId) ? "\"" + escape(ATTR(data, kXMLCharId)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(data, kXMLCharSource) ? "\"" + escape(ATTR(data, kXMLCharSource)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(data, kXMLCharExpr) ? "\"" + escape(ATTR(data, kXMLCharExpr)) + "\"" : "NULL") << ", "; std::list dataTexts = DOMUtils::filterChildType(DOMNode::TEXT_NODE, data); if (dataTexts.size() > 0) { @@ -1643,9 +1643,9 @@ void ChartToC::writeElementInfo(std::ostream& stream) { parent = param->getParentNode(); } stream << " { "; - stream << (HAS_ATTR(param, "name") ? "\"" + escape(ATTR(param, "name")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(param, "expr") ? "\"" + escape(ATTR(param, "expr")) + "\"" : "NULL") << ", "; - stream << (HAS_ATTR(param, "location") ? "\"" + escape(ATTR(param, "location")) + "\"" : "NULL"); + stream << (HAS_ATTR(param, kXMLCharName) ? "\"" + escape(ATTR(param, kXMLCharName)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(param, kXMLCharExpr) ? "\"" + escape(ATTR(param, kXMLCharExpr)) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(param, kXMLCharLocation) ? "\"" + escape(ATTR(param, kXMLCharLocation)) + "\"" : "NULL"); stream << " }," << std::endl; } @@ -1663,27 +1663,27 @@ void ChartToC::writeElementInfo(std::ostream& stream) { DOMElement* send = *iter; stream << " { "; stream << std::endl << " /* event */ "; - stream << (HAS_ATTR(send, "event") ? "\"" + escape(ATTR(send, "event")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharEvent) ? "\"" + escape(ATTR(send, kXMLCharEvent)) + "\"" : "NULL") << ", "; stream << std::endl << " /* eventexpr */ "; - stream << (HAS_ATTR(send, "eventexpr") ? "\"" + escape(ATTR(send, "eventexpr")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharEventExpr) ? "\"" + escape(ATTR(send, kXMLCharEventExpr)) + "\"" : "NULL") << ", "; stream << std::endl << " /* target */ "; - stream << (HAS_ATTR(send, "target") ? "\"" + escape(ATTR(send, "target")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharTarget) ? "\"" + escape(ATTR(send, kXMLCharTarget)) + "\"" : "NULL") << ", "; stream << std::endl << " /* targetexpr */ "; - stream << (HAS_ATTR(send, "targetexpr") ? "\"" + escape(ATTR(send, "targetexpr")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharTargetExpr) ? "\"" + escape(ATTR(send, kXMLCharTargetExpr)) + "\"" : "NULL") << ", "; stream << std::endl << " /* type */ "; - stream << (HAS_ATTR(send, "type") ? "\"" + escape(ATTR(send, "type")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharType) ? "\"" + escape(ATTR(send, kXMLCharType)) + "\"" : "NULL") << ", "; stream << std::endl << " /* typeexpr */ "; - stream << (HAS_ATTR(send, "typeexpr") ? "\"" + escape(ATTR(send, "typeexpr")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharTypeExpr) ? "\"" + escape(ATTR(send, kXMLCharTypeExpr)) + "\"" : "NULL") << ", "; stream << std::endl << " /* id */ "; - stream << (HAS_ATTR(send, "id") ? "\"" + escape(ATTR(send, "id")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharId) ? "\"" + escape(ATTR(send, kXMLCharId)) + "\"" : "NULL") << ", "; stream << std::endl << " /* idlocation */ "; - stream << (HAS_ATTR(send, "idlocation") ? "\"" + escape(ATTR(send, "idlocation")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharIdLocation) ? "\"" + escape(ATTR(send, kXMLCharIdLocation)) + "\"" : "NULL") << ", "; stream << std::endl << " /* delay */ "; - stream << (HAS_ATTR(send, "delay") ? "\"" + escape(ATTR(send, "delay")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharDelay) ? "\"" + escape(ATTR(send, kXMLCharDelay)) + "\"" : "NULL") << ", "; stream << std::endl << " /* delayexpr */ "; - stream << (HAS_ATTR(send, "delayexpr") ? "\"" + escape(ATTR(send, "delayexpr")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharDelayExpr) ? "\"" + escape(ATTR(send, kXMLCharDelayExpr)) + "\"" : "NULL") << ", "; stream << std::endl << " /* namelist */ "; - stream << (HAS_ATTR(send, "namelist") ? "\"" + escape(ATTR(send, "namelist")) + "\"" : "NULL") << ", "; + stream << (HAS_ATTR(send, kXMLCharNameList) ? "\"" + escape(ATTR(send, kXMLCharNameList)) + "\"" : "NULL") << ", "; std::list contents = DOMUtils::filterChildElements(XML_PREFIX(send).str() + "content", send); if (contents.size() > 0) { @@ -1695,7 +1695,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << std::endl << " /* content */ "; stream << (ss.str().size() > 0 ? "\"" + escape(ss.str()) + "\", " : "NULL, "); stream << std::endl << " /* contentexpr */ "; - stream << (HAS_ATTR_CAST(contents.front(), "expr") ? "\"" + ATTR_CAST(contents.front(), "expr") + "\", " : "NULL, "); + stream << (HAS_ATTR_CAST(contents.front(), kXMLCharExpr) ? "\"" + ATTR_CAST(contents.front(), kXMLCharExpr) + "\", " : "NULL, "); } else { stream << std::endl << " /* content */ "; stream << "NULL,"; @@ -1705,8 +1705,8 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << std::endl << " /* params */ "; - if (HAS_ATTR(send, "paramIndex")) { - stream << "&" << _prefix << "_elem_params[" << escape(ATTR(send, "paramIndex")) << "] "; + if (HAS_ATTR(send, X("paramIndex"))) { + stream << "&" << _prefix << "_elem_params[" << escape(ATTR(send, X("paramIndex"))) << "] "; } else { stream << "NULL "; } @@ -1729,7 +1729,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << " { "; // parent - stream << ATTR_CAST(donedata->getParentNode(), "documentOrder") << ", "; + stream << ATTR_CAST(donedata->getParentNode(), X("documentOrder")) << ", "; std::list contents = DOMUtils::filterChildElements(XML_PREFIX(donedata).str() + "content", donedata); if (contents.size() > 0) { @@ -1739,13 +1739,13 @@ void ChartToC::writeElementInfo(std::ostream& stream) { ss << *(cChilds->item(j)); } stream << (ss.str().size() > 0 ? "\"" + escape(ss.str()) + "\", " : "NULL, "); - stream << (HAS_ATTR_CAST(contents.front(), "expr") ? "\"" + ATTR_CAST(contents.front(), "expr") + "\", " : "NULL, "); + stream << (HAS_ATTR_CAST(contents.front(), kXMLCharExpr) ? "\"" + ATTR_CAST(contents.front(), kXMLCharExpr) + "\", " : "NULL, "); } else { stream << "NULL, NULL, "; } - if (HAS_ATTR(donedata, "paramIndex")) { - stream << "&" << _prefix << "_elem_params[" << escape(ATTR(donedata, "paramIndex")) << "]"; + if (HAS_ATTR(donedata, X("paramIndex"))) { + stream << "&" << _prefix << "_elem_params[" << escape(ATTR(donedata, X("paramIndex"))) << "]"; } else { stream << "NULL"; } @@ -1796,7 +1796,7 @@ void ChartToC::writeMachineInfo(std::ostream& stream) { stream << " /* nr_states */ " << _states.size() << "," << std::endl; stream << " /* nr_transitions */ " << _transitions.size() << "," << std::endl; stream << " /* name */ \"" << escape(_name) << "\"," << std::endl; - stream << " /* datamodel */ \"" << (HAS_ATTR(_scxml, "datamodel") ? ATTR(_scxml, "datamodel") : "null") << "\"," << std::endl; + stream << " /* datamodel */ \"" << (HAS_ATTR(_scxml, kXMLCharDataModel) ? ATTR(_scxml, kXMLCharDataModel) : "null") << "\"," << std::endl; stream << " /* uuid */ \"" << _md5 << "\"," << std::endl; stream << " /* states */ " << "&" << _prefix << "_states[0], " << std::endl; if (_transitions.size() > 0) { @@ -1843,7 +1843,7 @@ void ChartToC::writeMachineInfo(std::ostream& stream) { stream << " /* nr_states */ " << m->_states.size() << "," << std::endl; stream << " /* nr_transitions */ " << m->_transitions.size() << "," << std::endl; stream << " /* name */ \"" << escape(m->_name) << "\"," << std::endl; - stream << " /* datamodel */ \"" << (HAS_ATTR(m->_scxml, "datamodel") ? ATTR(m->_scxml, "datamodel") : "null") << "\"," << std::endl; + stream << " /* datamodel */ \"" << (HAS_ATTR(m->_scxml, kXMLCharDataModel) ? ATTR(m->_scxml, kXMLCharDataModel) : "null") << "\"," << std::endl; stream << " /* uuid */ \"" << m->_md5 << "\"," << std::endl; stream << " /* states */ " << "&" << m->_prefix << "_states[0], " << std::endl; stream << " /* transitions */ " << "&" << m->_prefix << "_transitions[0], " << std::endl; @@ -1894,12 +1894,12 @@ void ChartToC::writeStates(std::ostream& stream) { // name stream << " /* name */ "; - stream << (HAS_ATTR(state, "id") ? "\"" + escape(ATTR(state, "id")) + "\"" : "NULL"); + stream << (HAS_ATTR(state, kXMLCharId) ? "\"" + escape(ATTR(state, kXMLCharId)) + "\"" : "NULL"); stream << "," << std::endl; // parent stream << " /* parent */ "; - stream << (i == 0 ? "0" : ATTR_CAST(state->getParentNode(), "documentOrder")); + stream << (i == 0 ? "0" : ATTR_CAST(state->getParentNode(), X("documentOrder"))); stream << "," << std::endl; // onentry @@ -1919,20 +1919,20 @@ void ChartToC::writeStates(std::ostream& stream) { // children stream << " /* children */ { "; - writeCharArrayInitList(stream, ATTR(state, "childBools")); - stream << " /* " << ATTR(state, "childBools") << " */ }," << std::endl; + writeCharArrayInitList(stream, ATTR(state, X("childBools"))); + stream << " /* " << ATTR(state, X("childBools")) << " */ }," << std::endl; // default completion stream << " /* completion */ { "; - writeCharArrayInitList(stream, ATTR(state, "completionBools")); - stream << " /* " << ATTR(state, "completionBools") << " */ }, \t" << std::endl; + writeCharArrayInitList(stream, ATTR(state, X("completionBools"))); + stream << " /* " << ATTR(state, X("completionBools")) << " */ }, \t" << std::endl; stream << " /* ancestors */ { "; - writeCharArrayInitList(stream, ATTR(state, "ancBools")); - stream << " /* " << ATTR(state, "ancBools") << " */ }," << std::endl; + writeCharArrayInitList(stream, ATTR(state, X("ancBools"))); + stream << " /* " << ATTR(state, X("ancBools")) << " */ }," << std::endl; stream << " /* data */ "; - stream << (HAS_ATTR(state, "dataIndex") ? "&" + _prefix + "_elem_datas[" + escape(ATTR(state, "dataIndex")) + "]" : "NULL"); + stream << (HAS_ATTR(state, X("dataIndex")) ? "&" + _prefix + "_elem_datas[" + escape(ATTR(state, X("dataIndex"))) + "]" : "NULL"); stream << "," << std::endl; stream << " /* type */ "; @@ -1943,7 +1943,7 @@ void ChartToC::writeStates(std::ostream& stream) { } else if (isFinal(state)) { stream << "USCXML_STATE_FINAL"; } else if (isHistory(state)) { - if (HAS_ATTR(state, "type") && iequals(ATTR(state, "type"), "deep")) { + if (HAS_ATTR(state, kXMLCharType) && iequals(ATTR(state, kXMLCharType), "deep")) { stream << "USCXML_STATE_HISTORY_DEEP"; } else { stream << "USCXML_STATE_HISTORY_SHALLOW"; @@ -1957,7 +1957,7 @@ void ChartToC::writeStates(std::ostream& stream) { } else { // stream << "USCXML_STATE_COMPOUND"; } - if (HAS_ATTR(state, "hasHistoryChild")) { + if (HAS_ATTR(state, X("hasHistoryChild"))) { stream << " | USCXML_STATE_HAS_HISTORY"; } @@ -1987,21 +1987,21 @@ void ChartToC::writeTransitions(std::ostream& stream) { for (size_t i = 0; i < _transitions.size(); i++) { DOMElement* transition(_transitions[i]); - stream << " { /* transition number " << ATTR(transition, "documentOrder") << " with priority " << toStr(i) << std::endl; - stream << " target: " << ATTR(transition, "target") << std::endl; + stream << " { /* transition number " << ATTR(transition, X("documentOrder")) << " with priority " << toStr(i) << std::endl; + stream << " target: " << ATTR(transition, kXMLCharTarget) << std::endl; stream << " */" << std::endl; // source stream << " /* source */ "; - stream << ATTR_CAST(transition->getParentNode(), "documentOrder"); + stream << ATTR_CAST(transition->getParentNode(), X("documentOrder")); stream << "," << std::endl; // targets stream << " /* target */ "; - if (HAS_ATTR(transition, "targetBools")) { + if (HAS_ATTR(transition, X("targetBools"))) { stream << "{ "; - writeCharArrayInitList(stream, ATTR(transition, "targetBools")); - stream << " /* " << ATTR(transition, "targetBools") << " */ }"; + writeCharArrayInitList(stream, ATTR(transition, X("targetBools"))); + stream << " /* " << ATTR(transition, X("targetBools")) << " */ }"; } else { stream << "{ 0x00 }"; @@ -2009,17 +2009,17 @@ void ChartToC::writeTransitions(std::ostream& stream) { stream << "," << std::endl; stream << " /* event */ "; - stream << (HAS_ATTR(transition, "event") ? "\"" + escape(ATTR(transition, "event")) + "\"" : "NULL"); + stream << (HAS_ATTR(transition, kXMLCharEvent) ? "\"" + escape(ATTR(transition, kXMLCharEvent)) + "\"" : "NULL"); stream << "," << std::endl; stream << " /* condition */ "; - stream << (HAS_ATTR(transition, "cond") ? "\"" + escape(ATTR(transition, "cond")) + "\"" : "NULL"); + stream << (HAS_ATTR(transition, kXMLCharCond) ? "\"" + escape(ATTR(transition, kXMLCharCond)) + "\"" : "NULL"); stream << "," << std::endl; // is enabled stream << " /* is_enabled */ "; - if (HAS_ATTR(transition, "cond")) { + if (HAS_ATTR(transition, kXMLCharCond)) { stream << _prefix << "_" << DOMUtils::idForNode(transition) << "_is_enabled"; } else { stream << "NULL"; @@ -2038,17 +2038,17 @@ void ChartToC::writeTransitions(std::ostream& stream) { // type stream << " /* type */ "; std::string seperator = ""; - if (!HAS_ATTR(transition, "target")) { + if (!HAS_ATTR(transition, kXMLCharTarget)) { stream << seperator << "USCXML_TRANS_TARGETLESS"; seperator = " | "; } - if (HAS_ATTR(transition, "type") && iequals(ATTR(transition, "type"), "internal")) { + if (HAS_ATTR(transition, kXMLCharType) && iequals(ATTR(transition, kXMLCharType), "internal")) { stream << seperator << "USCXML_TRANS_INTERNAL"; seperator = " | "; } - if (!HAS_ATTR(transition, "event")) { + if (!HAS_ATTR(transition, kXMLCharEvent)) { stream << seperator << "USCXML_TRANS_SPONTANEOUS"; seperator = " | "; } @@ -2070,13 +2070,13 @@ void ChartToC::writeTransitions(std::ostream& stream) { // conflicts stream << " /* conflicts */ { "; - writeCharArrayInitList(stream, ATTR(transition, "conflictBools")); - stream << " /* " << ATTR(transition, "conflictBools") << " */ }, " << std::endl; + writeCharArrayInitList(stream, ATTR(transition, X("conflictBools"))); + stream << " /* " << ATTR(transition, X("conflictBools")) << " */ }, " << std::endl; // exit set stream << " /* exit set */ { "; - writeCharArrayInitList(stream, ATTR(transition, "exitSetBools")); - stream << " /* " << ATTR(transition, "exitSetBools") << " */ }" << std::endl; + writeCharArrayInitList(stream, ATTR(transition, X("exitSetBools"))); + stream << " /* " << ATTR(transition, X("exitSetBools")) << " */ }" << std::endl; stream << " }" << (i + 1 < _transitions.size() ? ",": "") << std::endl; } diff --git a/src/uscxml/transform/ChartToPromela.cpp b/src/uscxml/transform/ChartToPromela.cpp index 6d77a94..2c73e60 100644 --- a/src/uscxml/transform/ChartToPromela.cpp +++ b/src/uscxml/transform/ChartToPromela.cpp @@ -95,25 +95,25 @@ void ChartToPromela::prepare() { std::list invokes = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "invoke" }, _scxml); for (auto invoke : invokes) { - if (!HAS_ATTR(invoke, "id")) { + if (!HAS_ATTR(invoke, kXMLCharId)) { invoke->setAttribute(X("id"), X("INV_" + UUID::getUUID().substr(0,5))); - } else if (HAS_ATTR(invoke, "id") && UUID::isUUID(ATTR(invoke, "id"))) { + } else if (HAS_ATTR(invoke, kXMLCharId) && UUID::isUUID(ATTR(invoke, kXMLCharId))) { // shorten UUIDs - invoke->setAttribute(X("id"), X("INV_" + ATTR(invoke, "id").substr(0,5))); + invoke->setAttribute(X("id"), X("INV_" + ATTR(invoke, kXMLCharId).substr(0,5))); } - if (HAS_ATTR(invoke, "type") && - ATTR(invoke, "type") != "scxml" && - ATTR(invoke, "type") != "http://www.w3.org/TR/scxml/" && - ATTR(invoke, "type") != "http://www.w3.org/TR/scxml/#SCXMLEventProcessor") + if (HAS_ATTR(invoke, kXMLCharType) && + ATTR(invoke, kXMLCharType) != "scxml" && + ATTR(invoke, kXMLCharType) != "http://www.w3.org/TR/scxml/" && + ATTR(invoke, kXMLCharType) != "http://www.w3.org/TR/scxml/#SCXMLEventProcessor") continue; - assert(HAS_ATTR(invoke, "id")); + assert(HAS_ATTR(invoke, kXMLCharId)); invoke->setAttribute(X("name"), invoke->getAttribute(X("id"))); Interpreter nested; - if (HAS_ATTR(invoke, "src")) { - nested = Interpreter::fromURL(URL::resolve(ATTR(invoke, "src"), _baseURL)); + if (HAS_ATTR(invoke, kXMLCharSource)) { + nested = Interpreter::fromURL(URL::resolve(ATTR(invoke, kXMLCharSource), _baseURL)); } else { std::list contents = DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "content", invoke); std::list scxmls = DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "scxml", contents.front()); @@ -131,15 +131,15 @@ void ChartToPromela::prepare() { _machinesNested[invoke]->_machinesAll = _machinesAll; (*_machinesAll)[invoke] = _machinesNested[invoke]; - _machinesNested[invoke]->_invokerid = ATTR(invoke, "id"); + _machinesNested[invoke]->_invokerid = ATTR(invoke, kXMLCharId); _analyzer->createMacroName(_machinesNested[invoke]->_invokerid); _analyzer->addEvent("done.invoke." + _machinesNested[invoke]->_invokerid); - _machinesNested[invoke]->_prefix = _analyzer->macroForLiteral(ATTR(invoke, "id")) + "_"; + _machinesNested[invoke]->_prefix = _analyzer->macroForLiteral(ATTR(invoke, kXMLCharId)) + "_"; - _machinesPerId[ATTR_CAST(invoke, "id")] = invoke; - (*_machinesAllPerId)[ATTR(invoke, "id")] = invoke; + _machinesPerId[ATTR_CAST(invoke, kXMLCharId)] = invoke; + (*_machinesAllPerId)[ATTR(invoke, kXMLCharId)] = invoke; } @@ -155,20 +155,20 @@ void ChartToPromela::prepare() { for (auto element : values) { std::string key; - if (HAS_ATTR(element, "id")) { - key = ATTR(element, "id"); - } else if (HAS_ATTR(element, "location")) { - key = ATTR(element, "location"); + if (HAS_ATTR(element, kXMLCharId)) { + key = ATTR(element, kXMLCharId); + } else if (HAS_ATTR(element, kXMLCharLocation)) { + key = ATTR(element, kXMLCharLocation); } if (key.length() == 0) continue; std::string value; - if (HAS_ATTR(element, "expr")) { - value = ATTR(element, "expr"); - } else if (HAS_ATTR(element, "src")) { - URL absUrl = URL::resolve(ATTR_CAST(element, "src"), _baseURL); + if (HAS_ATTR(element, kXMLCharExpr)) { + value = ATTR(element, kXMLCharExpr); + } else if (HAS_ATTR(element, kXMLCharSource)) { + URL absUrl = URL::resolve(ATTR_CAST(element, kXMLCharSource), _baseURL); value = absUrl.getInContent(); } else { std::list assignTexts = DOMUtils::filterChildType(DOMNode::TEXT_NODE, element, true); @@ -677,8 +677,8 @@ void ChartToPromela::writeVariables(std::ostream& stream) { PromelaCodeAnalyzer::PromelaTypedef allTypes = _analyzer->getTypes(); for (auto data : datas) { - std::string identifier = (HAS_ATTR_CAST(data, "id") ? ATTR_CAST(data, "id") : ""); - std::string type = boost::trim_copy(HAS_ATTR_CAST(data, "type") ? ATTR_CAST(data, "type") : ""); + std::string identifier = (HAS_ATTR_CAST(data, kXMLCharId) ? ATTR_CAST(data, kXMLCharId) : ""); + std::string type = boost::trim_copy(HAS_ATTR_CAST(data, kXMLCharType) ? ATTR_CAST(data, kXMLCharType) : ""); _dataModelVars.insert(identifier); if (processedIdentifiers.find(identifier) != processedIdentifiers.end()) @@ -760,9 +760,9 @@ void ChartToPromela::writeStrings(std::ostream& stream) { { for (size_t i = 0; i < _states.size(); i++) { - if (HAS_ATTR(_states[i], "id")) { - stream << "#define " << _prefix << _analyzer->macroForLiteral(ATTR(_states[i], "id")) << " " << toStr(i); - stream << " /* index for state " << ATTR(_states[i], "id") << " */" << std::endl; + if (HAS_ATTR(_states[i], kXMLCharId)) { + stream << "#define " << _prefix << _analyzer->macroForLiteral(ATTR(_states[i], kXMLCharId)) << " " << toStr(i); + stream << " /* index for state " << ATTR(_states[i], kXMLCharId) << " */" << std::endl; } } } @@ -787,25 +787,25 @@ void ChartToPromela::writeTransitions(std::ostream& stream) { /** source */ stream << " " << _prefix << "transitions[" << toStr(i) << "].source = "; - stream << ATTR_CAST(transition->getParentNode(), "documentOrder") ; + stream << ATTR_CAST(transition->getParentNode(), X("documentOrder")) ; stream << ";" << std::endl; /** target */ - if (HAS_ATTR(transition, "targetBools")) { - std::string targetBools = ATTR(transition, "targetBools"); + if (HAS_ATTR(transition, X("targetBools"))) { + std::string targetBools = ATTR(transition, X("targetBools")); for (size_t j = 0; j < _states.size(); j++) { if (targetBools[j] == '1') stream << " " << _prefix << "transitions[" << toStr(i) << "].target[" << toStr(j) << "] = 1;" << std::endl; } } - if (!HAS_ATTR(transition, "event")) + if (!HAS_ATTR(transition, kXMLCharEvent)) stream << " " << _prefix << "transitions[" << toStr(i) << "].type[USCXML_TRANS_SPONTANEOUS] = 1;" << std::endl; - if (!HAS_ATTR(transition, "target")) + if (!HAS_ATTR(transition, kXMLCharTarget)) stream << " " << _prefix << "transitions[" << toStr(i) << "].type[USCXML_TRANS_TARGETLESS] = 1;" << std::endl; - if (HAS_ATTR(transition, "type") && ATTR(transition, "type") == "internal") + if (HAS_ATTR(transition, kXMLCharType) && ATTR(transition, kXMLCharType) == "internal") stream << " " << _prefix << "transitions[" << toStr(i) << "].type[USCXML_TRANS_INTERNAL] = 1;" << std::endl; if (TAGNAME_CAST(transition->getParentNode()) == XML_PREFIX(transition).str() + "history") @@ -814,16 +814,16 @@ void ChartToPromela::writeTransitions(std::ostream& stream) { if (TAGNAME_CAST(transition->getParentNode()) == XML_PREFIX(transition).str() + "initial") stream << " " << _prefix << "transitions[" << toStr(i) << "].type[USCXML_TRANS_INITIAL] = 1;" << std::endl; - if (HAS_ATTR(transition, "conflictBools")) { - std::string conflicts = ATTR(transition, "conflictBools"); + if (HAS_ATTR(transition, X("conflictBools"))) { + std::string conflicts = ATTR(transition, X("conflictBools")); for (size_t j = 0; j < conflicts.size(); j++) { if (conflicts[j] == '1') stream << " " << _prefix << "transitions[" << toStr(i) << "].conflicts[" << toStr(j) << "] = 1;" << std::endl; } } - if (HAS_ATTR(transition, "exitSetBools")) { - std::string exitSet = ATTR(transition, "exitSetBools"); + if (HAS_ATTR(transition, X("exitSetBools"))) { + std::string exitSet = ATTR(transition, X("exitSetBools")); for (size_t j = 0; j < exitSet.size(); j++) { if (exitSet[j] == '1') stream << " " << _prefix << "transitions[" << toStr(i) << "].exit_set[" << toStr(j) << "] = 1;" << std::endl; @@ -842,28 +842,28 @@ void ChartToPromela::writeStates(std::ostream& stream) { DOMElement* state(_states[i]); stream << " " << _prefix << "states[" << toStr(i) << "].parent = "; - stream << (i == 0 ? "0" : ATTR_CAST(state->getParentNode(), "documentOrder")); + stream << (i == 0 ? "0" : ATTR_CAST(state->getParentNode(), X("documentOrder"))); stream << ";" << std::endl; - if (HAS_ATTR(state, "childBools")) { - std::string childs = ATTR(state, "childBools"); + if (HAS_ATTR(state, X("childBools"))) { + std::string childs = ATTR(state, X("childBools")); for (size_t j = 0; j < childs.size(); j++) { if (childs[j] == '1') stream << " " << _prefix << "states[" << toStr(i) << "].children[" << toStr(j) << "] = 1;" << std::endl; } } - if (HAS_ATTR(state, "completionBools")) { - std::string completions = ATTR(state, "completionBools"); + if (HAS_ATTR(state, X("completionBools"))) { + std::string completions = ATTR(state, X("completionBools")); for (size_t j = 0; j < completions.size(); j++) { if (completions[j] == '1') stream << " " << _prefix << "states[" << toStr(i) << "].completion[" << toStr(j) << "] = 1;" << std::endl; } } - if (HAS_ATTR(state, "ancBools")) { - std::string ancestors = ATTR(state, "ancBools"); + if (HAS_ATTR(state, X("ancBools"))) { + std::string ancestors = ATTR(state, X("ancBools")); for (size_t j = 0; j < ancestors.size(); j++) { if (ancestors[j] == '1') stream << " " << _prefix << "states[" << toStr(i) << "].ancestors[" << toStr(j) << "] = 1;" << std::endl; @@ -875,7 +875,7 @@ void ChartToPromela::writeStates(std::ostream& stream) { } else if (isFinal(state)) { stream << " " << _prefix << "states[" << toStr(i) << "].type[USCXML_STATE_FINAL] = 1;" << std::endl; } else if (isHistory(state)) { - if (HAS_ATTR(state, "type") && iequals(ATTR(state, "type"), "deep")) { + if (HAS_ATTR(state, kXMLCharType) && iequals(ATTR(state, kXMLCharType), "deep")) { stream << " " << _prefix << "states[" << toStr(i) << "].type[USCXML_STATE_HISTORY_DEEP] = 1;" << std::endl; } else { stream << " " << _prefix << "states[" << toStr(i) << "].type[USCXML_STATE_HISTORY_SHALLOW] = 1;" << std::endl; @@ -889,7 +889,7 @@ void ChartToPromela::writeStates(std::ostream& stream) { } else { // stream << " " << _prefix << "states[" << toStr(i) << "].type[USCXML_STATE_COMPOUND] = 1;" << std::endl; } - if (HAS_ATTR(state, "hasHistoryChild")) { + if (HAS_ATTR(state, X("hasHistoryChild"))) { stream << " " << _prefix << "states[" << toStr(i) << "].type[USCXML_STATE_HAS_HISTORY] = 1;" << std::endl; } @@ -909,8 +909,8 @@ void ChartToPromela::writeRaiseDoneDate(std::ostream& stream, const DOMElement* auto& content = contents.front(); // an expression - if (HAS_ATTR(content, "expr")) { - stream << dataToAssignments(_prefix + "_tmpE.data", Data(ADAPT_SRC(ATTR(content, "expr")), Data::INTERPRETED)); + if (HAS_ATTR(content, kXMLCharExpr)) { + stream << dataToAssignments(_prefix + "_tmpE.data", Data(ADAPT_SRC(ATTR(content, kXMLCharExpr)), Data::INTERPRETED)); return; } @@ -941,14 +941,14 @@ void ChartToPromela::writeRaiseDoneDate(std::ostream& stream, const DOMElement* if (params.size() > 0) { Data d; for (auto& param : params) { - if (!HAS_ATTR(param, "name")) + if (!HAS_ATTR(param, kXMLCharName)) continue; - std::string name = ATTR(param, "name"); + std::string name = ATTR(param, kXMLCharName); std::string expr; - if (HAS_ATTR(param, "expr")) { - expr = ATTR(param, "expr"); - } else if (HAS_ATTR(param, "location")) { - expr = ATTR(param, "location"); + if (HAS_ATTR(param, kXMLCharExpr)) { + expr = ATTR(param, kXMLCharExpr); + } else if (HAS_ATTR(param, kXMLCharLocation)) { + expr = ATTR(param, kXMLCharLocation); } d[name] = Data(expr, Data::INTERPRETED); @@ -996,8 +996,8 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO } } else if(TAGNAME(element) == "log") { - std::string label = (HAS_ATTR(element, "label") ? ATTR(element, "label") : ""); - std::string expr = (HAS_ATTR(element, "expr") ? ADAPT_SRC(ATTR(element, "expr")) : ""); + std::string label = (HAS_ATTR(element, kXMLCharLabel) ? ATTR(element, kXMLCharLabel) : ""); + std::string expr = (HAS_ATTR(element, kXMLCharExpr) ? ADAPT_SRC(ATTR(element, kXMLCharExpr)) : ""); std::string trimmedExpr = boost::trim_copy(expr); bool isStringLiteral = (boost::starts_with(trimmedExpr, "\"") || boost::starts_with(trimmedExpr, "'")); @@ -1027,17 +1027,17 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO } } else if(TAGNAME(element) == "foreach") { - stream << padding << "for (" << (HAS_ATTR(element, "index") ? _prefix + ATTR(element, "index") : "_index") << " in " << _prefix << ATTR(element, "array") << ") {" << std::endl; - if (HAS_ATTR(element, "item")) { - stream << padding << " " << _prefix << ATTR(element, "item") << " = " << _prefix << ATTR(element, "array") << "[" << (HAS_ATTR(element, "index") ? _prefix + ATTR(element, "index") : "_index") << "];" << std::endl; + stream << padding << "for (" << (HAS_ATTR(element, kXMLCharIndex) ? _prefix + ATTR(element, kXMLCharIndex) : "_index") << " in " << _prefix << ATTR(element, kXMLCharArray) << ") {" << std::endl; + if (HAS_ATTR(element, kXMLCharItem)) { + stream << padding << " " << _prefix << ATTR(element, kXMLCharItem) << " = " << _prefix << ATTR(element, kXMLCharArray) << "[" << (HAS_ATTR(element, kXMLCharIndex) ? _prefix + ATTR(element, kXMLCharIndex) : "_index") << "];" << std::endl; } const XERCESC_NS::DOMNode* child = element->getFirstChild(); while(child) { writeExecContent(stream, child, indent + 1); child = child->getNextSibling(); } - // if (HAS_ATTR(nodeElem, "index")) - // stream << padding << " " << _prefix << ATTR(nodeElem, "index") << "++;" << std::endl; + // if (HAS_ATTR(nodeElem, kXMLCharIndex)) + // stream << padding << " " << _prefix << ATTR(nodeElem, kXMLCharIndex) << "++;" << std::endl; stream << padding << "}" << std::endl; } else if(TAGNAME(element) == "if") { @@ -1065,27 +1065,27 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO std::string insertOp = "!"; if (TAGNAME(element) == "raise") { targetQueue = _prefix + "iQ"; - } else if (!HAS_ATTR(element, "target")) { + } else if (!HAS_ATTR(element, kXMLCharTarget)) { // if (_allowEventInterleaving) { // targetQueue = _prefix + "tmpQ"; // } else { targetQueue = _prefix + "eQ"; // } - } else if (ATTR(element, "target").compare("#_internal") == 0) { + } else if (ATTR(element, kXMLCharTarget).compare("#_internal") == 0) { targetQueue = _prefix + "iQ"; - } else if (ATTR(element, "target").compare("#_parent") == 0) { + } else if (ATTR(element, kXMLCharTarget).compare("#_parent") == 0) { targetQueue = _parent->_prefix + "eQ"; - } else if (boost::starts_with(ATTR(element, "target"), "#_") && _machinesAllPerId->find(ATTR(element, "target").substr(2)) != _machinesAllPerId->end()) { - targetQueue = (*_machinesAll)[(*_machinesAllPerId)[ATTR(element, "target").substr(2)]]->_prefix + "eQ"; + } else if (boost::starts_with(ATTR(element, kXMLCharTarget), "#_") && _machinesAllPerId->find(ATTR(element, kXMLCharTarget).substr(2)) != _machinesAllPerId->end()) { + targetQueue = (*_machinesAll)[(*_machinesAllPerId)[ATTR(element, kXMLCharTarget).substr(2)]]->_prefix + "eQ"; } if (targetQueue.length() > 0) { // this is for our external queue std::string event; - if (HAS_ATTR(element, "event")) { - event = _analyzer->macroForLiteral(ATTR(element, "event")); - } else if (HAS_ATTR(element, "eventexpr")) { - event = ADAPT_SRC(ATTR(element, "eventexpr")); + if (HAS_ATTR(element, kXMLCharEvent)) { + event = _analyzer->macroForLiteral(ATTR(element, kXMLCharEvent)); + } else if (HAS_ATTR(element, kXMLCharEventExpr)) { + event = ADAPT_SRC(ATTR(element, kXMLCharEventExpr)); } if (_analyzer->usesComplexEventStruct()) { stream << padding << "{" << std::endl; @@ -1093,17 +1093,17 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO std::stringstream typeAssignSS; typeAssignSS << padding << " " << _prefix << "_tmpE.name = " << event << ";" << std::endl; - if (HAS_ATTR(element, "idlocation")) { + if (HAS_ATTR(element, kXMLCharIdLocation)) { typeAssignSS << padding << " /* idlocation */" << std::endl; typeAssignSS << padding << " _lastSendId = _lastSendId + 1;" << std::endl; - typeAssignSS << padding << " " << _prefix << ATTR(element, "idlocation") << " = _lastSendId;" << std::endl; + typeAssignSS << padding << " " << _prefix << ATTR(element, kXMLCharIdLocation) << " = _lastSendId;" << std::endl; typeAssignSS << padding << " " << _prefix << "_tmpE.sendid = _lastSendId;" << std::endl; typeAssignSS << padding << " if" << std::endl; typeAssignSS << padding << " :: _lastSendId == 2147483647 -> _lastSendId = 0;" << std::endl; typeAssignSS << padding << " :: else -> skip;" << std::endl; typeAssignSS << padding << " fi;" << std::endl; - } else if (HAS_ATTR(element, "id")) { - typeAssignSS << padding << " " << _prefix << "_tmpE.sendid = " << _analyzer->macroForLiteral(ATTR(element, "id")) << ";" << std::endl; + } else if (HAS_ATTR(element, kXMLCharId)) { + typeAssignSS << padding << " " << _prefix << "_tmpE.sendid = " << _analyzer->macroForLiteral(ATTR(element, kXMLCharId)) << ";" << std::endl; } if (_analyzer->usesEventField("invokeid") && _parent != NULL) { // do not send invokeid if we send / raise to ourself @@ -1124,10 +1124,10 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO // insertOp += "!"; typeAssignSS << padding << " _lastSeqId = _lastSeqId + 1;" << std::endl; #endif - if (HAS_ATTR_CAST(element, "delay")) { - typeAssignSS << padding << " " << _prefix << "_tmpE.delay = " << ATTR_CAST(element, "delay") << ";" << std::endl; - } else if (HAS_ATTR_CAST(element, "delayexpr")) { - typeAssignSS << padding << " " << _prefix << "_tmpE.delay = " << ADAPT_SRC(ATTR_CAST(element, "delayexpr")) << ";" << std::endl; + if (HAS_ATTR_CAST(element, kXMLCharDelay)) { + typeAssignSS << padding << " " << _prefix << "_tmpE.delay = " << ATTR_CAST(element, kXMLCharDelay) << ";" << std::endl; + } else if (HAS_ATTR_CAST(element, kXMLCharDelayExpr)) { + typeAssignSS << padding << " " << _prefix << "_tmpE.delay = " << ADAPT_SRC(ATTR_CAST(element, kXMLCharDelayExpr)) << ";" << std::endl; } else { typeAssignSS << padding << " " << _prefix << "_tmpE.delay = 0;" << std::endl; } @@ -1144,10 +1144,10 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO std::list sendParams = DOMUtils::filterChildElements(XML_PREFIX(element).str() + "param", element); std::list sendContents = DOMUtils::filterChildElements(XML_PREFIX(element).str() + "content", element); - std::string sendNameList = ATTR(element, "namelist"); + std::string sendNameList = ATTR(element, kXMLCharNameList); if (sendParams.size() > 0) { for (auto sendParam : sendParams) { - typeAssignSS << padding << " " << _prefix << "_tmpE.data." << ATTR(sendParam, "name") << " = " << ADAPT_SRC(ATTR(sendParam, "expr")) << ";" << std::endl; + typeAssignSS << padding << " " << _prefix << "_tmpE.data." << ATTR(sendParam, kXMLCharName) << " = " << ADAPT_SRC(ATTR(sendParam, kXMLCharExpr)) << ";" << std::endl; } } if (sendNameList.size() > 0) { @@ -1168,8 +1168,8 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO } else { typeAssignSS << padding << " " << _prefix << "_tmpE.data = " << content << ";" << std::endl; } - } else if (HAS_ATTR(contentElem, "expr")) { - typeAssignSS << padding << " " << _prefix << "_tmpE.data = " << ADAPT_SRC(ATTR(contentElem, "expr")) << ";" << std::endl; + } else if (HAS_ATTR(contentElem, kXMLCharExpr)) { + typeAssignSS << padding << " " << _prefix << "_tmpE.data = " << ADAPT_SRC(ATTR(contentElem, kXMLCharExpr)) << ";" << std::endl; } } @@ -1227,10 +1227,10 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO stream << padding << "fi" << std::endl; } else if(TAGNAME(element) == "cancel") { - if (HAS_ATTR(element, "sendid")) { - stream << " " << padding << "cancelSendId(" << _analyzer->macroForLiteral(ATTR(element, "sendid")) << "," << _analyzer->macroForLiteral(_invokerid) << ");" << std::endl; - } else if (HAS_ATTR(element, "sendidexpr")) { - stream << " " << padding << "cancelSendId(" << ADAPT_SRC(ATTR(element, "sendidexpr")) << "," << _analyzer->macroForLiteral(_invokerid) << ");" << std::endl; + if (HAS_ATTR(element, kXMLCharSendId)) { + stream << " " << padding << "cancelSendId(" << _analyzer->macroForLiteral(ATTR(element, kXMLCharSendId)) << "," << _analyzer->macroForLiteral(_invokerid) << ");" << std::endl; + } else if (HAS_ATTR(element, kXMLCharSendIdExpr)) { + stream << " " << padding << "cancelSendId(" << ADAPT_SRC(ATTR(element, kXMLCharSendIdExpr)) << "," << _analyzer->macroForLiteral(_invokerid) << ");" << std::endl; } } else { LOGD(USCXML_VERBATIM) << "'" << TAGNAME(element) << "' not supported" << std::endl << element << std::endl; @@ -1419,8 +1419,8 @@ void ChartToPromela::writeFSMMacrostep(std::ostream& stream) { ChartToPromela* invoker = _machinesNested[invokeElem]; // pass variables via namelist - if (HAS_ATTR(invokeElem, "namelist")) { - std::list namelist = tokenize(ATTR_CAST(invokeElem, "namelist")); + if (HAS_ATTR(invokeElem, kXMLCharNameList)) { + std::list namelist = tokenize(ATTR_CAST(invokeElem, kXMLCharNameList)); for (auto name : namelist) { if (invoker->_dataModelVars.find(name) != invoker->_dataModelVars.end()) { stream << " " << invoker->_prefix << name << " = " << _prefix << name << ";" << std::endl; @@ -1431,8 +1431,8 @@ void ChartToPromela::writeFSMMacrostep(std::ostream& stream) { // pass variables via params std::list invokeParams = DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + + "param", invokeElem); for (auto param : invokeParams) { - std::string name = ATTR(param, "name"); - std::string expression = ATTR(param, "expr"); + std::string name = ATTR(param, kXMLCharName); + std::string expression = ATTR(param, kXMLCharExpr); if (invoker->_dataModelVars.find(name) != invoker->_dataModelVars.end()) { stream << " " << invoker->_prefix << name << " = " << ADAPT_SRC(expression) << ";" << std::endl; } @@ -1441,8 +1441,8 @@ void ChartToPromela::writeFSMMacrostep(std::ostream& stream) { TRACE_EXECUTION_V("Invoking in state %d", "i"); stream << " run " << invoker->_prefix << "step() priority 20;" << std::endl; - if (HAS_ATTR(invokeElem, "idlocation")) { - stream << " " << ADAPT_SRC(ATTR(invokeElem, "idlocation")) << " = "; + if (HAS_ATTR(invokeElem, kXMLCharIdLocation)) { + stream << " " << ADAPT_SRC(ATTR(invokeElem, kXMLCharIdLocation)) << " = "; stream << _analyzer->macroForLiteral(invoker->_invokerid) << ";" << std::endl; } @@ -1486,10 +1486,10 @@ void ChartToPromela::writeFSMMacrostep(std::ostream& stream) { for (auto state : _states) { std::list invokers = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "invoke", state, false); if (invokers.size() > 0) { - stream << " :: i == " << ATTR(state, "documentOrder") << " && " << _prefix << "invocations[i] -> { " << std::endl; + stream << " :: i == " << ATTR(state, X("documentOrder")) << " && " << _prefix << "invocations[i] -> { " << std::endl; for (auto invoker : invokers) { assert(_machinesNested.find(invoker) != _machinesNested.end()); - if (HAS_ATTR(invoker, "autoforward") && stringIsTrue(ATTR(invoker, "autoforward"))) { + if (HAS_ATTR(invoker, kXMLCharAutoForward) && stringIsTrue(ATTR(invoker, kXMLCharAutoForward))) { stream << " " << _machinesNested[invoker]->_prefix << "eQ " << insertOp << " " << _prefix << "_event;" << std::endl; if (_analyzer->usesEventField("delay")) { stream << " insertWithDelay(" << _machinesNested[invoker]->_prefix << "eQ);" << std::endl; @@ -1654,8 +1654,8 @@ void ChartToPromela::writeFSMDequeueEvent(std::ostream& stream) { ChartToPromela* invoker = _machinesNested[invokeElem]; // pass variables via namelist - if (HAS_ATTR(invokeElem, "namelist")) { - std::list namelist = tokenize(ATTR_CAST(invokeElem, "namelist")); + if (HAS_ATTR(invokeElem, kXMLCharNameList)) { + std::list namelist = tokenize(ATTR_CAST(invokeElem, kXMLCharNameList)); for (auto name : namelist) { if (invoker->_dataModelVars.find(name) != invoker->_dataModelVars.end()) { stream << " " << invoker->_prefix << name << " = " << _prefix << name << ";" << std::endl; @@ -1666,8 +1666,8 @@ void ChartToPromela::writeFSMDequeueEvent(std::ostream& stream) { // pass variables via params std::list invokeParams = DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + + "param", invokeElem); for (auto param : invokeParams) { - std::string name = ATTR(param, "name"); - std::string expression = ATTR(param, "expr"); + std::string name = ATTR(param, kXMLCharName); + std::string expression = ATTR(param, kXMLCharExpr); if (invoker->_dataModelVars.find(name) != invoker->_dataModelVars.end()) { stream << " " << invoker->_prefix << name << " = " << ADAPT_SRC(expression) << ";" << std::endl; } @@ -1676,8 +1676,8 @@ void ChartToPromela::writeFSMDequeueEvent(std::ostream& stream) { TRACE_EXECUTION_V("Invoking in state %d", "i"); stream << " run " << invoker->_prefix << "step() priority 20;" << std::endl; - if (HAS_ATTR(invokeElem, "idlocation")) { - stream << " " << ADAPT_SRC(ATTR(invokeElem, "idlocation")) << " = "; + if (HAS_ATTR(invokeElem, kXMLCharIdLocation)) { + stream << " " << ADAPT_SRC(ATTR(invokeElem, kXMLCharIdLocation)) << " = "; stream << _analyzer->macroForLiteral(invoker->_invokerid) << ";" << std::endl; } @@ -1737,10 +1737,10 @@ void ChartToPromela::writeFSMDequeueEvent(std::ostream& stream) { for (auto state : _states) { std::list invokers = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "invoke", state, false); if (invokers.size() > 0) { - stream << " :: i == " << ATTR(state, "documentOrder") << " && " << _prefix << "invocations[i] -> { " << std::endl; + stream << " :: i == " << ATTR(state, X("documentOrder")) << " && " << _prefix << "invocations[i] -> { " << std::endl; for (auto invoker : invokers) { assert(_machinesNested.find(invoker) != _machinesNested.end()); - if (HAS_ATTR(invoker, "autoforward") && stringIsTrue(ATTR(invoker, "autoforward"))) { + if (HAS_ATTR(invoker, kXMLCharAutoForward) && stringIsTrue(ATTR(invoker, kXMLCharAutoForward))) { stream << " " << _machinesNested[invoker]->_prefix << "eQ " << insertOp << " " << _prefix << "_event;" << std::endl; if (_analyzer->usesEventField("delay")) { stream << " insertWithDelay(" << _machinesNested[invoker]->_prefix << "eQ);" << std::endl; @@ -1851,9 +1851,9 @@ void ChartToPromela::writeFSMSelectTransitions(std::ostream& stream) { for (size_t i = 0; i < _transitions.size(); i++) { stream << " || (i == " << toStr(i); - if (HAS_ATTR(_transitions[i], "event") && ATTR(_transitions[i], "event") != "*") { + if (HAS_ATTR(_transitions[i], kXMLCharEvent) && ATTR(_transitions[i], kXMLCharEvent) != "*") { stream << " && (false"; - std::list eventLiterals = tokenize(ATTR(_transitions[i], "event")); + std::list eventLiterals = tokenize(ATTR(_transitions[i], kXMLCharEvent)); for (auto eventLiteral : eventLiterals) { if (boost::ends_with(eventLiteral, ".*")) { eventLiteral = eventLiteral.substr(0, eventLiteral.size() - 2); @@ -1868,8 +1868,8 @@ void ChartToPromela::writeFSMSelectTransitions(std::ostream& stream) { } stream << ")"; } - if (HAS_ATTR(_transitions[i], "cond")) { - stream << " && " << ADAPT_SRC(ATTR(_transitions[i], "cond")); + if (HAS_ATTR(_transitions[i], kXMLCharCond)) { + stream << " && " << ADAPT_SRC(ATTR(_transitions[i], kXMLCharCond)); } stream << ")" << std::endl; } @@ -2501,12 +2501,12 @@ void ChartToPromela::writeFSMEnterStates(std::ostream& stream) { continue; DOMElement* parent = static_cast(state->getParentNode()); - if (!HAS_ATTR(parent, "id")) + if (!HAS_ATTR(parent, kXMLCharId)) continue; - std::string doneEvent = _analyzer->macroForLiteral("done.state." + ATTR_CAST(state->getParentNode(), "id")); + std::string doneEvent = _analyzer->macroForLiteral("done.state." + ATTR_CAST(state->getParentNode(), kXMLCharId)); - stream << " :: (i == " << ATTR(state, "documentOrder") << ") -> {" << std::endl; + stream << " :: (i == " << ATTR(state, X("documentOrder")) << ") -> {" << std::endl; if (_analyzer->usesComplexEventStruct()) { std::string typeReset = _analyzer->getTypeReset(_prefix + "_tmpE", _analyzer->getType("_event"), 7); @@ -2573,10 +2573,10 @@ void ChartToPromela::writeFSMEnterStates(std::ostream& stream) { stream << " if" << std::endl; for (auto state : _states) { - if (isParallel(state) && HAS_ATTR(state, "id")) { - stream << " :: j == " << toStr(ATTR(state, "documentOrder")) << " -> {" << std::endl; + if (isParallel(state) && HAS_ATTR(state, kXMLCharId)) { + stream << " :: j == " << toStr(ATTR(state, X("documentOrder"))) << " -> {" << std::endl; - std::string doneEvent = _analyzer->macroForLiteral("done.state." + ATTR(state, "id")); + std::string doneEvent = _analyzer->macroForLiteral("done.state." + ATTR(state, kXMLCharId)); if (_analyzer->usesComplexEventStruct()) { std::string typeReset = _analyzer->getTypeReset(_prefix + "_tmpE", _analyzer->getType("_event"), 10); @@ -2669,7 +2669,7 @@ void ChartToPromela::writeFSMTerminateMachine(std::ostream& stream) { stream << " if" << std::endl; for (auto machine : _machinesNested) { - stream << " :: i == " << ATTR_CAST(machine.first->getParentNode(), "documentOrder") << " -> {" << std::endl; + stream << " :: i == " << ATTR_CAST(machine.first->getParentNode(), X("documentOrder")) << " -> {" << std::endl; stream << " " << machine.second->_prefix << "flags[USCXML_CTX_FINISHED] = true;" << std::endl; stream << " }" << std::endl; } @@ -2752,7 +2752,7 @@ void ChartToPromela::writeIfBlock(std::ostream& stream, std::list& stream << padding << "if" << std::endl; // we need to nest the elseifs to resolve promela if semantics - stream << padding << ":: (" << ADAPT_SRC(ATTR(ifNode, "cond")) << ") -> {" << std::endl; + stream << padding << ":: (" << ADAPT_SRC(ATTR(ifNode, kXMLCharCond)) << ") -> {" << std::endl; DOMNode* child; if (TAGNAME(ifNode) == "if") { diff --git a/src/uscxml/transform/ChartToVHDL.cpp b/src/uscxml/transform/ChartToVHDL.cpp index 1f25bb8..810d823 100644 --- a/src/uscxml/transform/ChartToVHDL.cpp +++ b/src/uscxml/transform/ChartToVHDL.cpp @@ -56,14 +56,14 @@ void ChartToVHDL::findEvents() { }, _scxml); for (auto withEvent : withEvents) { -// if (HAS_ATTR_CAST(withEvent, "event")) { -// if (ATTR_CAST(withEvent, "event") != "*") -// _eventTrie.addWord(ATTR_CAST(withEvent, "event")); +// if (HAS_ATTR_CAST(withEvent, kXMLCharEvent)) { +// if (ATTR_CAST(withEvent, kXMLCharEvent) != "*") +// _eventTrie.addWord(ATTR_CAST(withEvent, kXMLCharEvent)); // } // Tokenized version below - if (HAS_ATTR_CAST(withEvent, "event")) { - std::string eventNames = ATTR_CAST(withEvent, "event"); + if (HAS_ATTR_CAST(withEvent, kXMLCharEvent)) { + std::string eventNames = ATTR_CAST(withEvent, kXMLCharEvent); std::list events = tokenize(eventNames); for (std::list::iterator eventIter = events.begin(); eventIter != events.end(); eventIter++) { @@ -159,8 +159,8 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { stream << " next_event_we_i :in std_logic;" << std::endl; for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { // create enable line if transition has conditions - stream << " transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") << + if (HAS_ATTR(transition, kXMLCharCond)) { // create enable line if transition has conditions + stream << " transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_i : std_logic;" << std::endl; } @@ -170,20 +170,20 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { stream << " error_o :out std_logic;" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " entry_set_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " exit_set_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") << "_o :out std_logic;" + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) << "_o :out std_logic;" << std::endl; } } @@ -201,23 +201,23 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { stream << " rst_i :in std_logic;" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") + stream << " entry_set_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") + stream << " exit_set_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) << "_i :in std_logic;" << std::endl; } } @@ -238,15 +238,15 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { stream << " rst_i :in std_logic;" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; } stream << " --outputs" << std::endl; for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { - stream << " transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") + if (HAS_ATTR(transition, kXMLCharCond)) { + stream << " transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_o :out std_logic;" << std::endl; } } @@ -272,30 +272,30 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { stream << " -- wiring" << std::endl; for (auto state : _states) { - stream << " signal state_active_" << ATTR(state, "documentOrder") + stream << " signal state_active_" << ATTR(state, X("documentOrder")) << "_sig : std_logic;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " signal entry_set_" << ATTR(state, "documentOrder") + stream << " signal entry_set_" << ATTR(state, X("documentOrder")) << "_sig : std_logic;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " signal exit_set_" << ATTR(state, "documentOrder") + stream << " signal exit_set_" << ATTR(state, X("documentOrder")) << "_sig : std_logic;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " signal transition_set_" << ATTR(transition, "postFixOrder") + stream << " signal transition_set_" << ATTR(transition, X("postFixOrder")) << "_sig : std_logic;" << std::endl; } } for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { // create enable line if transition has conditions - stream << " signal transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") << + if (HAS_ATTR(transition, kXMLCharCond)) { // create enable line if transition has conditions + stream << " signal transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_sig : std_logic;" << std::endl; } @@ -323,35 +323,35 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { stream << " error_o => error_o," << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") - << "_o => state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) + << "_o => state_active_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") - << "_o => entry_set_" << ATTR(state, "documentOrder") + stream << " entry_set_" << ATTR(state, X("documentOrder")) + << "_o => entry_set_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") - << "_o => exit_set_" << ATTR(state, "documentOrder") + stream << " exit_set_" << ATTR(state, X("documentOrder")) + << "_o => exit_set_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") - << "_o => transition_set_" << ATTR(transition, "postFixOrder") + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) + << "_o => transition_set_" << ATTR(transition, X("postFixOrder")) << "_sig," << std::endl; } } for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { // create enable line if transition has conditions - stream << " transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") << - "_i => transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") << + if (HAS_ATTR(transition, kXMLCharCond)) { // create enable line if transition has conditions + stream << " transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << + "_i => transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_sig," << std::endl; } } @@ -370,27 +370,27 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { stream << " event_we_o => next_event_we_i," << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") - << "_i => state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) + << "_i => state_active_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") - << "_i => entry_set_" << ATTR(state, "documentOrder") + stream << " entry_set_" << ATTR(state, X("documentOrder")) + << "_i => entry_set_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") - << "_i => exit_set_" << ATTR(state, "documentOrder") + stream << " exit_set_" << ATTR(state, X("documentOrder")) + << "_i => exit_set_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") - << "_i => transition_set_" << ATTR(transition, "postFixOrder") + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) + << "_i => transition_set_" << ATTR(transition, X("postFixOrder")) << "_sig," << std::endl; } } @@ -407,17 +407,17 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { stream << " rst_i => reset," << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") - << "_i => state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) + << "_i => state_active_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } stream << " --outputs" << std::endl; for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { - stream << " transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") - << "_o => transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") << + if (HAS_ATTR(transition, kXMLCharCond)) { + stream << " transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) + << "_o => transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_sig," << std::endl; } } @@ -432,8 +432,8 @@ void ChartToVHDL::writeTestbench(std::ostream &stream) { std::string passStateNo = ""; for (auto final : topLevelFinal) { - if (ATTR(final, "id") == "pass") { - passStateNo = ATTR(final, "documentOrder"); + if (ATTR(final, kXMLCharId) == "pass") { + passStateNo = ATTR(final, X("documentOrder")); } } @@ -486,7 +486,7 @@ void ChartToVHDL::writeTopLevel(std::ostream &stream) { stream << " rst :in std_logic;" << std::endl; stream << " --outputs" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; } stream << " completed_o :out std_logic" << std::endl; @@ -511,20 +511,20 @@ void ChartToVHDL::writeTopLevel(std::ostream &stream) { stream << " error_o :out std_logic;" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " entry_set_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " exit_set_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") << "_o :out std_logic;" + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) << "_o :out std_logic;" << std::endl; } } @@ -541,23 +541,23 @@ void ChartToVHDL::writeTopLevel(std::ostream &stream) { stream << " rst_i :in std_logic;" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") + stream << " entry_set_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") + stream << " exit_set_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) << "_i :in std_logic;" << std::endl; } } @@ -583,23 +583,23 @@ void ChartToVHDL::writeTopLevel(std::ostream &stream) { stream << " -- wiring" << std::endl; for (auto state : _states) { - stream << " signal state_active_" << ATTR(state, "documentOrder") + stream << " signal state_active_" << ATTR(state, X("documentOrder")) << "_sig : std_logic;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " signal entry_set_" << ATTR(state, "documentOrder") + stream << " signal entry_set_" << ATTR(state, X("documentOrder")) << "_sig : std_logic;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " signal exit_set_" << ATTR(state, "documentOrder") + stream << " signal exit_set_" << ATTR(state, X("documentOrder")) << "_sig : std_logic;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " signal transition_set_" << ATTR(transition, "postFixOrder") + stream << " signal transition_set_" << ATTR(transition, X("postFixOrder")) << "_sig : std_logic;" << std::endl; } } @@ -610,8 +610,8 @@ void ChartToVHDL::writeTopLevel(std::ostream &stream) { stream << std::endl; for (auto state : _states) { - stream << "state_active_" << ATTR(state, "documentOrder") - << "_o <= state_active_" << ATTR(state, "documentOrder") + stream << "state_active_" << ATTR(state, X("documentOrder")) + << "_o <= state_active_" << ATTR(state, X("documentOrder")) << "_sig;" << std::endl; } stream << std::endl; @@ -629,27 +629,27 @@ void ChartToVHDL::writeTopLevel(std::ostream &stream) { stream << " error_o => error_o," << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") - << "_o => state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) + << "_o => state_active_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") - << "_o => entry_set_" << ATTR(state, "documentOrder") + stream << " entry_set_" << ATTR(state, X("documentOrder")) + << "_o => entry_set_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") - << "_o => exit_set_" << ATTR(state, "documentOrder") + stream << " exit_set_" << ATTR(state, X("documentOrder")) + << "_o => exit_set_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") - << "_o => transition_set_" << ATTR(transition, "postFixOrder") + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) + << "_o => transition_set_" << ATTR(transition, X("postFixOrder")) << "_sig," << std::endl; } } @@ -668,27 +668,27 @@ void ChartToVHDL::writeTopLevel(std::ostream &stream) { stream << " event_we_o => next_event_we_i," << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") - << "_i => state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) + << "_i => state_active_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") - << "_i => entry_set_" << ATTR(state, "documentOrder") + stream << " entry_set_" << ATTR(state, X("documentOrder")) + << "_i => entry_set_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") - << "_i => exit_set_" << ATTR(state, "documentOrder") + stream << " exit_set_" << ATTR(state, X("documentOrder")) + << "_i => exit_set_" << ATTR(state, X("documentOrder")) << "_sig," << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") - << "_i => transition_set_" << ATTR(transition, "postFixOrder") + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) + << "_i => transition_set_" << ATTR(transition, X("postFixOrder")) << "_sig," << std::endl; } } @@ -704,8 +704,8 @@ void ChartToVHDL::writeTopLevel(std::ostream &stream) { std::string passStateNo = ""; for (auto final : topLevelFinal) { - if (ATTR(final, "id") == "pass") { - passStateNo = ATTR(final, "documentOrder"); + if (ATTR(final, kXMLCharId) == "pass") { + passStateNo = ATTR(final, X("documentOrder")); } } stream << "end architecture;" << std::endl; @@ -724,23 +724,23 @@ void ChartToVHDL::writeEventController(std::ostream &stream) { stream << " rst_i :in std_logic;" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") + stream << " entry_set_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") + stream << " exit_set_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) << "_i :in std_logic;" << std::endl; } } @@ -814,18 +814,18 @@ void ChartToVHDL::writeEventController(std::ostream &stream) { for (auto state : _states) { if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << std::endl << " or entry_set_" << ATTR(state, "documentOrder") + stream << std::endl << " or entry_set_" << ATTR(state, X("documentOrder")) << "_i"; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << std::endl << " or exit_set_" << ATTR(state, "documentOrder") + stream << std::endl << " or exit_set_" << ATTR(state, X("documentOrder")) << "_i"; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << std::endl << " or transition_set_" << ATTR(transition, "postFixOrder") + stream << std::endl << " or transition_set_" << ATTR(transition, X("postFixOrder")) << "_i"; } } @@ -866,7 +866,7 @@ void ChartToVHDL::writeEventController(std::ostream &stream) { size_t jj = 0; for (auto eventIter = _eventNames.begin(); eventIter != _eventNames.end(); eventIter++, jj++) { - if (((*eventIter)->value) == ATTR(exContentElem, "event")) { + if (((*eventIter)->value) == ATTR(exContentElem, kXMLCharEvent)) { break; } } @@ -954,15 +954,15 @@ void ChartToVHDL::writeConditionSolver(std::ostream &stream) { stream << " rst_i :in std_logic;" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_i :in std_logic;" << std::endl; } stream << " --outputs" << std::endl; for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { - stream << " transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") + if (HAS_ATTR(transition, kXMLCharCond)) { + stream << " transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_o :out std_logic;" << std::endl; } } @@ -986,8 +986,8 @@ void ChartToVHDL::writeConditionSolver(std::ostream &stream) { } for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { - stream << "signal transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") + if (HAS_ATTR(transition, kXMLCharCond)) { + stream << "signal transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_sig : std_logic;" << std::endl; } } @@ -1002,9 +1002,9 @@ void ChartToVHDL::writeConditionSolver(std::ostream &stream) { stream << std::endl; for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { - stream << "transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") - << "_o <= transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") + if (HAS_ATTR(transition, kXMLCharCond)) { + stream << "transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) + << "_o <= transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_sig;" << std::endl; } } @@ -1017,10 +1017,10 @@ void ChartToVHDL::writeConditionSolver(std::ostream &stream) { // solve conditions stream << "-- solve conditions" << std::endl; for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { - stream << "-- cond:"<< ATTR(transition, "cond") << std::endl; + if (HAS_ATTR(transition, kXMLCharCond)) { + stream << "-- cond:"<< ATTR(transition, kXMLCharCond) << std::endl; // TODO parse code here and generate hardware from AST - stream << "transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") + stream << "transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_sig <= '0';" << std::endl; } } @@ -1041,15 +1041,15 @@ std::string ChartToVHDL::getLineForExecContent(const DOMNode *elem) { if (ecBlock->getNodeType() == DOMNode::ELEMENT_NODE) { std::string localName = LOCALNAME_CAST(ecBlock); if (localName == XML_PREFIX(_scxml).str() + "transition") { - return "transition_set_" + ATTR_CAST(ecBlock, "postFixOrder") + "_i"; + return "transition_set_" + ATTR_CAST(ecBlock, X("postFixOrder")) + "_i"; } if (localName == XML_PREFIX(_scxml).str() + "onentry") { - return "entry_set_" + ATTR_CAST(ecBlock->getParentNode(), "documentOrder") + "_i"; + return "entry_set_" + ATTR_CAST(ecBlock->getParentNode(), X("documentOrder")) + "_i"; } if (localName == XML_PREFIX(_scxml).str() + "onexit") { - return "exit_set_" + ATTR_CAST(ecBlock->getParentNode(), "documentOrder") + "_i"; + return "exit_set_" + ATTR_CAST(ecBlock->getParentNode(), X("documentOrder")) + "_i"; } } @@ -1073,8 +1073,8 @@ void ChartToVHDL::writeMicroStepper(std::ostream &stream) { stream << " next_event_we_i :in std_logic;" << std::endl; for (auto transition : _transitions) { - if (HAS_ATTR(transition, "cond")) { // create enable line if transition has conditions - stream << "signal transition_condition_fulfilled_" << ATTR(transition, "postFixOrder") << + if (HAS_ATTR(transition, kXMLCharCond)) { // create enable line if transition has conditions + stream << "signal transition_condition_fulfilled_" << ATTR(transition, X("postFixOrder")) << "_i : std_logic;" << std::endl; } @@ -1084,20 +1084,20 @@ void ChartToVHDL::writeMicroStepper(std::ostream &stream) { stream << " error_o :out std_logic;" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << " entry_set_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " entry_set_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << " exit_set_" << ATTR(state, "documentOrder") << "_o :out std_logic;" << std::endl; + stream << " exit_set_" << ATTR(state, X("documentOrder")) << "_o :out std_logic;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << " transition_set_" << ATTR(transition, "postFixOrder") << "_o :out std_logic;" + stream << " transition_set_" << ATTR(transition, X("postFixOrder")) << "_o :out std_logic;" << std::endl; } } @@ -1254,18 +1254,18 @@ void ChartToVHDL::writeSignalsAndComponents(std::ostream &stream) { std::list signalDecls; for (auto state : _states) { - std::string parent = ATTR(state, "parent"); + std::string parent = ATTR(state, X("parent")); - signalDecls.push_back("signal state_active_" + ATTR(state, "documentOrder") + "_sig : std_logic;"); - signalDecls.push_back("signal state_next_" + ATTR(state, "documentOrder") + "_sig : std_logic;"); - signalDecls.push_back("signal in_entry_set_" + ATTR(state, "documentOrder") + "_sig : std_logic;"); - signalDecls.push_back("signal in_exit_set_" + ATTR(state, "documentOrder") + "_sig : std_logic;"); - signalDecls.push_back("signal in_complete_entry_set_" + ATTR(state, "documentOrder") + "_sig : std_logic;"); + signalDecls.push_back("signal state_active_" + ATTR(state, X("documentOrder")) + "_sig : std_logic;"); + signalDecls.push_back("signal state_next_" + ATTR(state, X("documentOrder")) + "_sig : std_logic;"); + signalDecls.push_back("signal in_entry_set_" + ATTR(state, X("documentOrder")) + "_sig : std_logic;"); + signalDecls.push_back("signal in_exit_set_" + ATTR(state, X("documentOrder")) + "_sig : std_logic;"); + signalDecls.push_back("signal in_complete_entry_set_" + ATTR(state, X("documentOrder")) + "_sig : std_logic;"); // not needed for state if (parent.size() != 0) { signalDecls.push_back( - "signal in_complete_entry_set_up_" + ATTR(state, "documentOrder") + "_sig : std_logic;"); + "signal in_complete_entry_set_up_" + ATTR(state, X("documentOrder")) + "_sig : std_logic;"); } } @@ -1282,7 +1282,7 @@ void ChartToVHDL::writeSignalsAndComponents(std::ostream &stream) { stream << "signal optimal_transition_set_combined_sig : std_logic;" << std::endl; for (auto transition : _transitions) { - stream << "signal in_optimal_transition_set_" << ATTR(transition, "postFixOrder") << "_sig : std_logic;" + stream << "signal in_optimal_transition_set_" << ATTR(transition, X("postFixOrder")) << "_sig : std_logic;" << std::endl; } stream << std::endl; @@ -1405,9 +1405,9 @@ void ChartToVHDL::writeInternalEventHandler(std::ostream &stream) { VContainer eventConsumed = VOR; for (auto transition : _transitions) { - if (HAS_ATTR(transition, "event") == true) { + if (HAS_ATTR(transition, kXMLCharEvent) == true) { *eventConsumed += VLINE("in_optimal_transition_set_" - + ATTR(transition, "postFixOrder") + "_sig"); + + ATTR(transition, X("postFixOrder")) + "_sig"); } } @@ -1467,21 +1467,21 @@ void ChartToVHDL::writeActiveStateNplusOne(std::ostream &stream) { stream << "-- active configuration" << std::endl; for (auto state : _states) { - std::string parent = ATTR(state, "parent"); + std::string parent = ATTR(state, X("parent")); // special case for to start the state machine if (parent.size() == 0) { - stream << " state_next_" << ATTR(state, "documentOrder") << "_sig <= " << + stream << " state_next_" << ATTR(state, X("documentOrder")) << "_sig <= " << "not completed_sig;" << std::endl; continue; } VBranch *tree = (VASSIGN, - VLINE("state_next_" + ATTR(state, "documentOrder") + "_sig"), + VLINE("state_next_" + ATTR(state, X("documentOrder")) + "_sig"), (VOR, - VLINE("in_complete_entry_set_" + ATTR(state, "documentOrder") + "_sig"), - (VAND, (VNOT, VLINE("in_exit_set_" + ATTR(state, "documentOrder") + "_sig")), - VLINE("state_active_" + ATTR(state, "documentOrder") + "_sig")) + VLINE("in_complete_entry_set_" + ATTR(state, X("documentOrder")) + "_sig"), + (VAND, (VNOT, VLINE("in_exit_set_" + ATTR(state, X("documentOrder")) + "_sig")), + VLINE("state_active_" + ATTR(state, X("documentOrder")) + "_sig")) )); tree->print(stream); @@ -1497,12 +1497,12 @@ void ChartToVHDL::writeOptimalTransitionSetSelection(std::ostream &stream) { for (auto transIter = _transitions.begin(); transIter != _transitions.end(); transIter++) { DOMElement *transition = *transIter; - std::string conflicts = ATTR(transition, "conflictBools"); + std::string conflicts = ATTR(transition, X("conflictBools")); VContainer nameMatchers = VOR; - if (HAS_ATTR(transition, "event")) { - std::list eventDescs = tokenize(ATTR(transition, "event")); + if (HAS_ATTR(transition, kXMLCharEvent)) { + std::list eventDescs = tokenize(ATTR(transition, kXMLCharEvent)); for (std::list::iterator descIter = eventDescs.begin(); descIter != eventDescs.end(); descIter++) { std::list eventNames = _eventTrie.getWordsWithPrefix( @@ -1517,26 +1517,26 @@ void ChartToVHDL::writeOptimalTransitionSetSelection(std::ostream &stream) { } VContainer conflicters = VOR; - for (size_t j = 0; j < strTo(ATTR(transition, "postFixOrder")); j++) { + for (size_t j = 0; j < strTo(ATTR(transition, X("postFixOrder"))); j++) { if (conflicts[j] == '1') { *conflicters += VLINE("in_optimal_transition_set_" + toStr(j) + "_sig"); } } VBranch *tree = (VASSIGN, - VLINE("in_optimal_transition_set_" + ATTR(transition, "postFixOrder") + "_sig"), + VLINE("in_optimal_transition_set_" + ATTR(transition, X("postFixOrder")) + "_sig"), (VAND, - (HAS_ATTR(transition, "event") + (HAS_ATTR(transition, kXMLCharEvent) ? (VNOT, VLINE("spontaneous_active")) : (VNOP, VLINE("spontaneous_en"))), - HAS_ATTR(transition, "cond") + HAS_ATTR(transition, kXMLCharCond) ? (VNOP, - VLINE("transition_condition_fulfilled_" + ATTR(transition, "postFixOrder") + + VLINE("transition_condition_fulfilled_" + ATTR(transition, X("postFixOrder")) + "_i")) : (VNOP, VLINE("'1'")), - VLINE("state_active_" + ATTR(transition, "source") + "_sig"), + VLINE("state_active_" + ATTR(transition, kXMLCharSource) + "_sig"), nameMatchers, (VNOT, conflicters))); @@ -1544,10 +1544,10 @@ void ChartToVHDL::writeOptimalTransitionSetSelection(std::ostream &stream) { stream << ";" << std::endl; *optimalTransitions += VLINE("in_optimal_transition_set_" - + ATTR(transition, "postFixOrder") + "_sig"); - if (HAS_ATTR(transition, "event") == false) { + + ATTR(transition, X("postFixOrder")) + "_sig"); + if (HAS_ATTR(transition, kXMLCharEvent) == false) { *spontaneoursActive += VLINE("in_optimal_transition_set_" - + ATTR(transition, "postFixOrder") + "_sig"); + + ATTR(transition, X("postFixOrder")) + "_sig"); } } @@ -1570,23 +1570,23 @@ void ChartToVHDL::writeExitSet(std::ostream &stream) { for (auto state : _states) { - std::string completion = ATTR(state, "completionBools"); - std::string ancestors = ATTR(state, "ancBools"); - std::string children = ATTR(state, "childBools"); - std::string parent = ATTR(state, "parent"); + std::string completion = ATTR(state, X("completionBools")); + std::string ancestors = ATTR(state, X("ancBools")); + std::string children = ATTR(state, X("childBools")); + std::string parent = ATTR(state, X("parent")); VContainer exitsetters = VOR; for (auto transition : _transitions) { - std::string exitSet = ATTR(transition, "exitSetBools"); - if (exitSet.at(strTo(ATTR(state, "documentOrder"))) == '1') { - *exitsetters += VLINE("in_optimal_transition_set_" + ATTR(transition, "postFixOrder") + "_sig "); + std::string exitSet = ATTR(transition, X("exitSetBools")); + if (exitSet.at(strTo(ATTR(state, X("documentOrder")))) == '1') { + *exitsetters += VLINE("in_optimal_transition_set_" + ATTR(transition, X("postFixOrder")) + "_sig "); } } VBranch *tree = (VASSIGN, - VLINE("in_exit_set_" + ATTR(state, "documentOrder") + "_sig"), + VLINE("in_exit_set_" + ATTR(state, X("documentOrder")) + "_sig"), (VAND, - VLINE("state_active_" + ATTR(state, "documentOrder") + "_sig"), + VLINE("state_active_" + ATTR(state, X("documentOrder")) + "_sig"), exitsetters)); tree->print(stream); @@ -1600,11 +1600,11 @@ void ChartToVHDL::writeEntrySet(std::ostream &stream) { for (auto state : _states) { VBranch *tree = (VASSIGN, - VLINE("in_entry_set_" + ATTR(state, "documentOrder") + "_sig"), + VLINE("in_entry_set_" + ATTR(state, X("documentOrder")) + "_sig"), (VAND, - VLINE("in_complete_entry_set_" + ATTR(state, "documentOrder") + "_sig"), - (VOR, VLINE("in_exit_set_" + ATTR(state, "documentOrder") + "_sig"), - (VNOT, VLINE("state_active_" + ATTR(state, "documentOrder") + "_sig"))))); + VLINE("in_complete_entry_set_" + ATTR(state, X("documentOrder")) + "_sig"), + (VOR, VLINE("in_exit_set_" + ATTR(state, X("documentOrder")) + "_sig"), + (VNOT, VLINE("state_active_" + ATTR(state, X("documentOrder")) + "_sig"))))); tree->print(stream); stream << ";" << std::endl; @@ -1615,10 +1615,10 @@ void ChartToVHDL::writeCompleteEntrySet(std::ostream &stream) { stream << "-- complete entry set selection" << std::endl; for (auto state : _states) { - std::string completion = ATTR(state, "completionBools"); - std::string ancestors = ATTR(state, "ancBools"); - std::string children = ATTR(state, "childBools"); - std::string parent = ATTR(state, "parent"); + std::string completion = ATTR(state, X("completionBools")); + std::string ancestors = ATTR(state, X("ancBools")); + std::string children = ATTR(state, X("childBools")); + std::string parent = ATTR(state, X("parent")); if (parent.size() == 0) { continue; // skips node @@ -1629,11 +1629,11 @@ void ChartToVHDL::writeCompleteEntrySet(std::ostream &stream) { VContainer optimalEntrysetters = VOR; for (auto transition : _transitions) { // Is this state in TargetSet of the transition? - std::string targetSet = ATTR(transition, "targetBools"); - if (targetSet[strTo(ATTR(state, "documentOrder"))] == '1') { + std::string targetSet = ATTR(transition, X("targetBools")); + if (targetSet[strTo(ATTR(state, X("documentOrder")))] == '1') { //yes? then add the transition to optimal entry set of the state *optimalEntrysetters += - VLINE("in_optimal_transition_set_" + ATTR(transition, "postFixOrder") + "_sig"); + VLINE("in_optimal_transition_set_" + ATTR(transition, X("postFixOrder")) + "_sig"); } } @@ -1642,16 +1642,16 @@ void ChartToVHDL::writeCompleteEntrySet(std::ostream &stream) { if (isCompound(state) || isParallel(state)) { for (auto tmp_state : _states) { // is tmp_state is child of state continue? - if (children[strTo(ATTR(state, "documentOrder"))] == '1') { + if (children[strTo(ATTR(state, X("documentOrder")))] == '1') { // yes? then add its complete_entry_set_up as ancestor completion *completeEntrysetters += - VLINE("in_complete_entry_set_up_" + ATTR(tmp_state, "documentOrder") + "_sig"); + VLINE("in_complete_entry_set_up_" + ATTR(tmp_state, X("documentOrder")) + "_sig"); } } } VBranch *tree = (VASSIGN, - VLINE("in_complete_entry_set_up_" + ATTR(state, "documentOrder") + "_sig"), + VLINE("in_complete_entry_set_up_" + ATTR(state, X("documentOrder")) + "_sig"), (VOR, optimalEntrysetters, completeEntrysetters) ); tree->print(stream); @@ -1661,9 +1661,9 @@ void ChartToVHDL::writeCompleteEntrySet(std::ostream &stream) { // descendant completion for (auto state : _states) { - std::string completion = ATTR(state, "completionBools"); - std::string ancestors = ATTR(state, "ancBools"); - std::string parent = ATTR(state, "parent"); //is it a int ? + std::string completion = ATTR(state, X("completionBools")); + std::string ancestors = ATTR(state, X("ancBools")); + std::string parent = ATTR(state, X("parent")); //is it a int ? if (parent.size() == 0) { continue; // skips node @@ -1674,18 +1674,18 @@ void ChartToVHDL::writeCompleteEntrySet(std::ostream &stream) { if (getParentState(state) != NULL && isCompound(getParentState(state))) { std::string children = ATTR_CAST(_states[strTo(parent)], - "childBools"); + X("childBools")); - std::string parentInit = ATTR(getParentState(state), "initial"); + std::string parentInit = ATTR(getParentState(state), kXMLCharInitial); if (// if parent has init field an this state is inside --> add it as default completion (!parentInit.empty() - && ATTR(state, "id").compare(parentInit) == 0) || + && ATTR(state, kXMLCharId).compare(parentInit) == 0) || // or add this state as default completion when parent has no init field and it is the first in document order (parentInit.empty() && - (strTo(ATTR(getParentState(state), "documentOrder")) + 1) == - strTo(ATTR(state, "documentOrder")))) { + (strTo(ATTR(getParentState(state), X("documentOrder"))) + 1) == + strTo(ATTR(state, X("documentOrder"))))) { *descendantCompletion += - VLINE("in_entry_set_" + ATTR(getParentState(state), "documentOrder") + "_sig"); + VLINE("in_entry_set_" + ATTR(getParentState(state), X("documentOrder")) + "_sig"); // but only if compound parent is not already completed for (auto tmp_state : _states) { @@ -1693,12 +1693,12 @@ void ChartToVHDL::writeCompleteEntrySet(std::ostream &stream) { // skip state itselve continue; } - if (children[strTo(ATTR(tmp_state, "documentOrder"))] == '1') { + if (children[strTo(ATTR(tmp_state, X("documentOrder")))] == '1') { *descendantCompletion += (VNOT, (VAND, - VLINE("state_active_" + ATTR(tmp_state, "documentOrder") + "_sig"), + VLINE("state_active_" + ATTR(tmp_state, X("documentOrder")) + "_sig"), (VNOT, - VLINE("in_exit_set_" + ATTR(tmp_state, "documentOrder") + + VLINE("in_exit_set_" + ATTR(tmp_state, X("documentOrder")) + "_sig")))); } } @@ -1711,13 +1711,13 @@ void ChartToVHDL::writeCompleteEntrySet(std::ostream &stream) { if (getParentState(state) != NULL && isParallel(getParentState(state))) { *descendantCompletion += - VLINE("in_complete_entry_set_" + ATTR(getParentState(state), "documentOrder") + "_sig"); + VLINE("in_complete_entry_set_" + ATTR(getParentState(state), X("documentOrder")) + "_sig"); } VBranch *tree = (VASSIGN, - VLINE("in_complete_entry_set_" + ATTR(state, "documentOrder") + "_sig"), + VLINE("in_complete_entry_set_" + ATTR(state, X("documentOrder")) + "_sig"), (VOR, - VLINE("in_complete_entry_set_up_" + ATTR(state, "documentOrder") + "_sig"), + VLINE("in_complete_entry_set_up_" + ATTR(state, X("documentOrder")) + "_sig"), descendantCompletion)); tree->print(stream); @@ -1734,7 +1734,7 @@ void ChartToVHDL::writeStateHandler(std::ostream &stream) { stream << " if rst = '1' then" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") << "_sig <= " << "'0';" << std::endl; + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_sig <= " << "'0';" << std::endl; } stream << " in_complete_entry_set_0_sig <= '1';" << std::endl; @@ -1742,8 +1742,8 @@ void ChartToVHDL::writeStateHandler(std::ostream &stream) { stream << " in_complete_entry_set_0_sig <= '0';" << std::endl; for (auto state : _states) { - stream << " state_active_" << ATTR(state, "documentOrder") << "_sig <= " << "state_next_" << - ATTR(state, "documentOrder") << "_sig;" << std::endl; + stream << " state_active_" << ATTR(state, X("documentOrder")) << "_sig <= " << "state_next_" << + ATTR(state, X("documentOrder")) << "_sig;" << std::endl; } stream << " end if;" << std::endl; @@ -1758,7 +1758,7 @@ void ChartToVHDL::writeSystemSignalMapping(std::ostream &stream) { VContainer tlf = VOR; for (auto final : topLevelFinal) { - *tlf += VLINE("state_active_" + ATTR(final, "documentOrder") + "_sig"); + *tlf += VLINE("state_active_" + ATTR(final, X("documentOrder")) + "_sig"); } @@ -1785,26 +1785,26 @@ void ChartToVHDL::writeSystemSignalMapping(std::ostream &stream) { // interface signals stream << "-- interface signals" << std::endl; for (auto state : _states) { - stream << "state_active_" << ATTR(state, "documentOrder") - << "_o <= state_active_" << ATTR(state, "documentOrder") + stream << "state_active_" << ATTR(state, X("documentOrder")) + << "_o <= state_active_" << ATTR(state, X("documentOrder")) << "_sig;" << std::endl; if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onexit", state).size() > 0) { - stream << "exit_set_" << ATTR(state, "documentOrder") - << "_o <= in_exit_set_" << ATTR(state, "documentOrder") + stream << "exit_set_" << ATTR(state, X("documentOrder")) + << "_o <= in_exit_set_" << ATTR(state, X("documentOrder")) << "_sig;" << std::endl; } if (DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "onentry", state).size() > 0) { - stream << "entry_set_" << ATTR(state, "documentOrder") - << "_o <= in_entry_set_" << ATTR(state, "documentOrder") + stream << "entry_set_" << ATTR(state, X("documentOrder")) + << "_o <= in_entry_set_" << ATTR(state, X("documentOrder")) << "_sig;" << std::endl; } } for (auto transition : _transitions) { if (DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, transition).size() > 0) { - stream << "transition_set_" << ATTR(transition, "postFixOrder") - << "_o <= in_optimal_transition_set_" << ATTR(transition, "postFixOrder") + stream << "transition_set_" << ATTR(transition, X("postFixOrder")) + << "_o <= in_optimal_transition_set_" << ATTR(transition, X("postFixOrder")) << "_sig;" << std::endl; } } diff --git a/src/uscxml/transform/promela/PromelaCodeAnalyzer.cpp b/src/uscxml/transform/promela/PromelaCodeAnalyzer.cpp index 044e660..f8af351 100644 --- a/src/uscxml/transform/promela/PromelaCodeAnalyzer.cpp +++ b/src/uscxml/transform/promela/PromelaCodeAnalyzer.cpp @@ -40,8 +40,8 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { { for (size_t i = 0; i < interpreter->_states.size(); i++) { DOMElement* state = interpreter->_states[i]; - if (HAS_ATTR(state, "id")) { - createMacroName(ATTR(state, "id")); + if (HAS_ATTR(state, kXMLCharId)) { + createMacroName(ATTR(state, kXMLCharId)); } } } @@ -56,8 +56,8 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { }, interpreter->_scxml); for (auto internalEventName : internalEventNames) { - if (HAS_ATTR_CAST(internalEventName, "event")) { - std::string eventNames = ATTR_CAST(internalEventName, "event"); + if (HAS_ATTR_CAST(internalEventName, kXMLCharEvent)) { + std::string eventNames = ATTR_CAST(internalEventName, kXMLCharEvent); std::list events = tokenize(eventNames); for (std::list::iterator eventIter = events.begin(); eventIter != events.end(); eventIter++) { @@ -73,8 +73,8 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { } for (auto state : interpreter->_states) { - if (HAS_ATTR(state, "id") && (isCompound(state) || isParallel(state))) { - addEvent("done.state." + ATTR(state, "id")); + if (HAS_ATTR(state, kXMLCharId) && (isCompound(state) || isParallel(state))) { + addEvent("done.state." + ATTR(state, kXMLCharId)); } } @@ -82,8 +82,8 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { for (auto invoker : invokers) { addCode("_event.invokeid", interpreter); - if (HAS_ATTR(invoker, "id")) { - addEvent("done.state." + ATTR(invoker, "id")); + if (HAS_ATTR(invoker, kXMLCharId)) { + addEvent("done.state." + ATTR(invoker, kXMLCharId)); } } } @@ -126,8 +126,8 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { }, interpreter->_scxml); for (auto cond : withCond) { - if (HAS_ATTR(cond, "cond")) { - std::string code = ATTR_CAST(cond, "cond"); + if (HAS_ATTR(cond, kXMLCharCond)) { + std::string code = ATTR_CAST(cond, kXMLCharCond); code = sanitizeCode(code); addCode(code, interpreter); cond->setAttribute(X("cond"), X(code)); @@ -143,8 +143,8 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { }, interpreter->_scxml); for (auto expr : withExpr) { - if (HAS_ATTR(expr, "expr")) { - std::string code = ATTR_CAST(expr, "expr"); + if (HAS_ATTR(expr, kXMLCharExpr)) { + std::string code = ATTR_CAST(expr, kXMLCharExpr); code = sanitizeCode(code); addCode(code, interpreter); expr->setAttribute(X("expr"), X(code)); @@ -156,8 +156,8 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { }, interpreter->_scxml); for (auto location : withLocation) { - if (HAS_ATTR(location, "location")) { - std::string code = ATTR_CAST(location, "location"); + if (HAS_ATTR(location, kXMLCharLocation)) { + std::string code = ATTR_CAST(location, kXMLCharLocation); code = sanitizeCode(code); addCode(code, interpreter); location->setAttribute(X("location"), X(code)); @@ -186,13 +186,13 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { }, interpreter->_scxml); for (auto foreach : foreachs) { - if (HAS_ATTR(foreach, "index")) { - addCode(ATTR(foreach, "index"), interpreter); + if (HAS_ATTR(foreach, kXMLCharIndex)) { + addCode(ATTR(foreach, kXMLCharIndex), interpreter); } else { _hasIndexLessLoops = true; } - if (HAS_ATTR(foreach, "item")) { - addCode(ATTR(foreach, "item"), interpreter); + if (HAS_ATTR(foreach, kXMLCharItem)) { + addCode(ATTR(foreach, kXMLCharItem), interpreter); } } @@ -208,17 +208,17 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { } for (auto send : sends) { - if (HAS_ATTR(send, "idlocation")) { + if (HAS_ATTR(send, kXMLCharIdLocation)) { addCode("_event.sendid", interpreter); } - if (HAS_ATTR(send, "id")) { - addLiteral(ATTR(send, "id")); + if (HAS_ATTR(send, kXMLCharId)) { + addLiteral(ATTR(send, kXMLCharId)); addCode("_event.sendid", interpreter); } // do we need delays? - if (HAS_ATTR(send, "delay") || HAS_ATTR(send, "delayexpr")) { - size_t delay = strTo(ATTR(send, "delay")); + if (HAS_ATTR(send, kXMLCharDelay) || HAS_ATTR(send, kXMLCharDelayExpr)) { + size_t delay = strTo(ATTR(send, kXMLCharDelay)); if (delay > largestDelay) largestDelay = delay; addCode("_event.delay", interpreter); @@ -236,8 +236,8 @@ void PromelaCodeAnalyzer::analyze(ChartToPromela* interpreter) { withNamelists.splice(withNamelists.end(), DOMUtils::inDocumentOrder({XML_PREFIX(interpreter->_scxml).str() + "send"}, interpreter->_scxml)); withNamelists.splice(withNamelists.end(), DOMUtils::inDocumentOrder({XML_PREFIX(interpreter->_scxml).str() + "invoke"}, interpreter->_scxml)); for (auto withNamelist : withNamelists) { - if (HAS_ATTR(withNamelist, "namelist")) { - std::string namelist = ATTR(withNamelist, "namelist"); + if (HAS_ATTR(withNamelist, kXMLCharNameList)) { + std::string namelist = ATTR(withNamelist, kXMLCharNameList); std::list names = tokenize(namelist); for (std::list::iterator nameIter = names.begin(); nameIter != names.end(); nameIter++) { addCode("_event.data." + *nameIter + " = 0;", interpreter); // introduce for _event_t typedef diff --git a/src/uscxml/util/DOM.cpp b/src/uscxml/util/DOM.cpp index be6012b..d089807 100644 --- a/src/uscxml/util/DOM.cpp +++ b/src/uscxml/util/DOM.cpp @@ -63,8 +63,8 @@ std::string DOMUtils::idForNode(const DOMNode* node) { switch (curr->getNodeType()) { case DOMNode::ELEMENT_NODE: { const DOMElement* elem = dynamic_cast(curr); - if (HAS_ATTR(elem, "id")) { - std::string elementId = ATTR(elem, "id"); + if (HAS_ATTR(elem, kXMLCharId)) { + std::string elementId = ATTR(elem, kXMLCharId); std::replace( elementId.begin(), elementId.end(), '.', '_'); std::replace( elementId.begin(), elementId.end(), ',', '_'); @@ -114,12 +114,12 @@ std::string DOMUtils::xPathForNode(const DOMNode* node, const std::string& ns) { switch (curr->getNodeType()) { case DOMNode::ELEMENT_NODE: { const DOMElement* elem = dynamic_cast(curr); - if (HAS_ATTR(elem, "id")) { + if (HAS_ATTR(elem, kXMLCharId)) { // we assume ids to be unique and return immediately if (ns == "*") { - xPath.insert(0, "//*[local-name() = \"" + TAGNAME(elem) + "\"][@id=\"" + ATTR(elem, "id") + "\"]"); + xPath.insert(0, "//*[local-name() = \"" + TAGNAME(elem) + "\"][@id=\"" + ATTR(elem, kXMLCharId) + "\"]"); } else { - xPath.insert(0, "//" + nsPrefix + TAGNAME(elem) + "[@id=\"" + ATTR(elem, "id") + "\"]"); + xPath.insert(0, "//" + nsPrefix + TAGNAME(elem) + "[@id=\"" + ATTR(elem, kXMLCharId) + "\"]"); } return xPath; } else { diff --git a/src/uscxml/util/DOM.h b/src/uscxml/util/DOM.h index 49dc4de..9697eb8 100644 --- a/src/uscxml/util/DOM.h +++ b/src/uscxml/util/DOM.h @@ -28,9 +28,9 @@ #include #include -#define HAS_ATTR(elem, attr) (elem)->hasAttribute(X(attr)) +#define HAS_ATTR(elem, attr) (elem)->hasAttribute(attr) #define HAS_ATTR_CAST(elem, attr) HAS_ATTR(static_cast(elem), attr) -#define ATTR(elem, attr) std::string(X((elem)->getAttribute(X(attr)))) +#define ATTR(elem, attr) std::string(X((elem)->getAttribute(attr))) #define ATTR_CAST(elem, attr) ATTR(static_cast(elem), attr) #define TAGNAME(elem) std::string(X((elem)->getTagName())) #define TAGNAME_CAST(elem) TAGNAME(static_cast(elem)) @@ -139,12 +139,6 @@ public : _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm); _deallocOther = true; } - void operator=(X const &other) { // did we maybe leak before? - - _localForm = other._localForm; - _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm); - _deallocOther = true; - } X(const XMLCh* const toTranscode) { @@ -167,6 +161,15 @@ public : } X(const char* const fromTranscode) { + // this is most unfortunate but needed with static XMLChars :( + if (!_xercesIsInit) { + try { + ::xercesc_3_1::XMLPlatformUtils::Initialize(); + _xercesIsInit = true; + } catch (const XERCESC_NS::XMLException& toCatch) { + throw ("Cannot initialize XercesC: " + X(toCatch.getMessage()).str()); + } + } // Call the private transcoding method _localForm = fromTranscode; @@ -198,11 +201,29 @@ public : return _localForm; } - operator const XMLCh* () { + const operator const XMLCh* () const { assert(_unicodeForm != NULL); // constructor with XMLCh return _unicodeForm; } + void operator=(X const &other) { + _localForm = other._localForm; + _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm); + _deallocOther = true; + } + + bool operator==(const X& other) const { + return (_unicodeForm == other._unicodeForm) != 0; + } + + bool operator!=(const X& other) const { + return !(_unicodeForm == other._unicodeForm); + } + + bool operator<(const X& other) const { + return XERCESC_NS::XMLString::compareString(_unicodeForm, other._unicodeForm); + } + operator bool () { return _localForm.size() > 0; } @@ -218,6 +239,7 @@ private: bool _deallocOther; std::string _localForm; XMLCh* _unicodeForm; + bool _xercesIsInit = false; }; #else @@ -293,31 +315,56 @@ private: #endif -#if 0 -static const X kElementScxmlName = X("scxml"); -static const X kElementStateName = X("state"); -static const X kElementParallelName = X("parallel"); -static const X kElementTransitionName = X("transition"); -static const X kElementInitialName = X("initial"); -static const X kElementFinalName = X("final"); -static const X kElementOnEntryName = X("onentry"); -static const X kElementOnExitName = X("onexit"); -static const X kElementHistoryName = X("history"); - -static const X kElementRaiseName = X("raise"); -static const X kElementIfName = X("if"); -static const X kElementElseIfName = X("elseif"); -static const X kElementElseName = X("else"); -static const X kElementForEachName = X("foreach"); -static const X kElementLogName = X("log"); - -static const X kElementDataModelName = X("datamodel"); -static const X kElementDataName = X("data"); -static const X kElementAssignName = X("assign"); -static const X kElementContentName = X("content"); -static const X kElementParamName = X("param"); -static const X kElementScriptName = X("script"); -#endif +static const X kXMLCharScxml = X("scxml"); +static const X kXMLCharState = X("state"); +static const X kXMLCharParallel = X("parallel"); +static const X kXMLCharTransition = X("transition"); +static const X kXMLCharInitial = X("initial"); +static const X kXMLCharFinal = X("final"); +static const X kXMLCharOnEntry = X("onentry"); +static const X kXMLCharOnExit = X("onexit"); +static const X kXMLCharHistory = X("history"); + +static const X kXMLCharRaise = X("raise"); +static const X kXMLCharIf = X("if"); +static const X kXMLCharElseIf = X("elseif"); +static const X kXMLCharElse = X("else"); +static const X kXMLCharForEach = X("foreach"); +static const X kXMLCharLog = X("log"); + +static const X kXMLCharDataModel = X("datamodel"); +static const X kXMLCharData = X("data"); +static const X kXMLCharAssign = X("assign"); +static const X kXMLCharContent = X("content"); +static const X kXMLCharParam = X("param"); +static const X kXMLCharScript = X("script"); + +static const X kXMLCharInvokeId = X("invokeid"); +static const X kXMLCharId = X("id"); +static const X kXMLCharIdLocation = X("idlocation"); +static const X kXMLCharEvent = X("event"); +static const X kXMLCharEventExpr = X("eventexpr"); +static const X kXMLCharTarget = X("target"); +static const X kXMLCharTargetExpr = X("targetexpr"); +static const X kXMLCharSource = X("src"); +static const X kXMLCharSourceExpr = X("srcexpr"); +static const X kXMLCharType = X("type"); +static const X kXMLCharTypeExpr = X("typeexpr"); +static const X kXMLCharDelay = X("delay"); +static const X kXMLCharDelayExpr = X("delayexpr"); +static const X kXMLCharSendId = X("sendid"); +static const X kXMLCharSendIdExpr = X("sendidexpr"); +static const X kXMLCharCond = X("cond"); +static const X kXMLCharLocation = X("location"); +static const X kXMLCharArray = X("array"); +static const X kXMLCharItem = X("item"); +static const X kXMLCharIndex = X("index"); +static const X kXMLCharLabel = X("label"); +static const X kXMLCharExpr = X("expr"); +static const X kXMLCharNameList = X("namelist"); +static const X kXMLCharAutoForward = X("autoforward"); +static const X kXMLCharName = X("name"); +static const X kXMLCharBinding = X("binding"); USCXML_API std::ostream& operator<< (std::ostream& os, const X& xmlString); USCXML_API std::ostream& operator<< (std::ostream& os, const XERCESC_NS::DOMNode& node); diff --git a/src/uscxml/util/Predicates.cpp b/src/uscxml/util/Predicates.cpp index af47c68..c4effdb 100644 --- a/src/uscxml/util/Predicates.cpp +++ b/src/uscxml/util/Predicates.cpp @@ -146,7 +146,7 @@ std::list getProperAncestors(const DOMElement* s1, const DOMElement std::list getExitSet(const DOMElement* transition, const DOMElement* root) { std::list statesToExit; - if (HAS_ATTR(transition, "target")) { + if (HAS_ATTR(transition, kXMLCharTarget)) { DOMElement* domain = getTransitionDomain(transition, root); if (domain == NULL) return statesToExit; @@ -207,7 +207,7 @@ bool isFinal(const DOMElement* state) { std::string localName = LOCALNAME(state); if (iequals("final", localName)) return true; - if (HAS_ATTR(state, "final") && iequals("true", ATTR(state, "final"))) + if (HAS_ATTR(state, kXMLCharFinal) && iequals("true", ATTR(state, kXMLCharFinal))) return true; return false; } @@ -259,8 +259,8 @@ bool isCompound(const DOMElement* state) { std::list getTargetStates(const DOMElement* transition, const DOMElement* root) { std::list targetStates; - std::string targetId = ATTR(transition, "target"); - std::list targetIds = tokenize(ATTR(transition, "target")); +// std::string targetId = ATTR(transition, kXMLCharTarget); + std::list targetIds = tokenize(ATTR(transition, kXMLCharTarget)); for (auto targetIter = targetIds.begin(); targetIter != targetIds.end(); targetIter++) { DOMElement* state = getState(*targetIter, root); @@ -277,7 +277,7 @@ DOMElement* getTransitionDomain(const DOMElement* transition, const DOMElement* if (tStates.size() == 0) { return NULL; } - std::string transitionType = (HAS_ATTR(transition, "type") ? ATTR(transition, "type") : "external"); + std::string transitionType = (HAS_ATTR(transition, kXMLCharType) ? ATTR(transition, kXMLCharType) : "external"); DOMElement* source = getSourceState(transition); if (iequals(transitionType, "internal") && isCompound(source)) { @@ -318,7 +318,7 @@ DOMElement* getState(const std::string& stateId, const DOMElement* root) { // std::cout << *curr; - if (HAS_ATTR(curr, "id") && ATTR(curr, "id") == stateId) + if (HAS_ATTR(curr, kXMLCharId) && ATTR(curr, kXMLCharId) == stateId) return (DOMElement*)curr; std::list children = getChildStates(curr, false); @@ -354,15 +354,15 @@ std::list getInitialStates(const DOMElement* state, const DOMElemen if (isCompound(state)) { // initial attribute at element - if (HAS_ATTR(state, "initial")) { - return getStates(tokenize(ATTR(state, "initial")), root); + if (HAS_ATTR(state, kXMLCharInitial)) { + return getStates(tokenize(ATTR(state, kXMLCharInitial)), root); } // initial element as child std::list initElems = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "initial", state); if(initElems.size() > 0 ) { std::list initTrans = DOMUtils::filterChildElements(XML_PREFIX(initElems.front()).str() + "transition", initElems.front()); - if (initTrans.size() > 0 && HAS_ATTR(initTrans.front(),"target")) { + if (initTrans.size() > 0 && HAS_ATTR(initTrans.front(), kXMLCharTarget)) { return getTargetStates(initTrans.front(), root); } return std::list(); @@ -481,4 +481,4 @@ bool areFromSameMachine(const DOMNode* n1, const DOMNode* n2) { return p1 == p2; } -} \ No newline at end of file +} diff --git a/test/src/test-http-debugger.pl b/test/src/test-http-debugger.pl index fcc675f..a43478c 100755 --- a/test/src/test-http-debugger.pl +++ b/test/src/test-http-debugger.pl @@ -26,7 +26,7 @@ my @breakpointSeq; my $pid = fork; if (!$pid) { - exec("$scxmlBin -t4088 -d"); + # exec("$scxmlBin -t4088 -d"); exit; } diff --git a/test/src/test-utils.cpp b/test/src/test-utils.cpp index 7436015..30caf46 100644 --- a/test/src/test-utils.cpp +++ b/test/src/test-utils.cpp @@ -45,9 +45,9 @@ void testDOMUtils() { DOMUtils::filterElementGeneric({ "state" }, result, scxml, DOMUtils::POSTFIX, true, true); index = 1; for (auto trans : result) { - assert(HAS_ATTR(trans, "post")); - std::cout << "post: " << ATTR(trans, "post") << std::endl; - assert(ATTR(trans, "post") == toStr(index)); + assert(HAS_ATTR(trans, X("post"))); + std::cout << "post: " << ATTR(trans, X("post")) << std::endl; + assert(ATTR(trans, X("post")) == toStr(index)); index++; } } @@ -58,9 +58,9 @@ void testDOMUtils() { DOMUtils::filterElementGeneric({ "state" }, result, scxml, DOMUtils::DOCUMENT, true, true); index = 1; for (auto trans : result) { - assert(HAS_ATTR(trans, "doc")); - std::cout << "doc: " << ATTR(trans, "doc") << std::endl; - assert(ATTR(trans, "doc") == toStr(index)); + assert(HAS_ATTR(trans, X("doc"))); + std::cout << "doc: " << ATTR(trans, X("doc")) << std::endl; + assert(ATTR(trans, X("doc")) == toStr(index)); index++; } } -- cgit v0.12