diff options
Diffstat (limited to 'src/uscxml/transform')
-rw-r--r-- | src/uscxml/transform/ChartToFSM.cpp | 86 | ||||
-rw-r--r-- | src/uscxml/transform/ChartToFlatSCXML.cpp | 16 | ||||
-rw-r--r-- | src/uscxml/transform/ChartToMinimalSCXML.cpp | 12 | ||||
-rw-r--r-- | src/uscxml/transform/ChartToPromela.cpp | 92 | ||||
-rw-r--r-- | src/uscxml/transform/ChartToTex.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/transform/ChartToVHDL.cpp | 213 | ||||
-rw-r--r-- | src/uscxml/transform/ChartToVHDL.h | 115 | ||||
-rw-r--r-- | src/uscxml/transform/FlatStateIdentifier.h | 8 |
8 files changed, 394 insertions, 152 deletions
diff --git a/src/uscxml/transform/ChartToFSM.cpp b/src/uscxml/transform/ChartToFSM.cpp index da53c1f..aa9dda8 100644 --- a/src/uscxml/transform/ChartToFSM.cpp +++ b/src/uscxml/transform/ChartToFSM.cpp @@ -73,7 +73,7 @@ if (now - _lastTimeStamp > 1000 || disregardTime) { \ {\ std::cout << std::endl;\ std::cout << "** " << transitions.size() << " ** " << where << std::endl;\ - for (int m = 0; m < transitions.size(); m++) {\ + for (size_t m = 0; m < transitions.size(); m++) {\ std::cout << transitions[m] << std::endl;\ }\ } @@ -88,7 +88,7 @@ using namespace Arabica::XPath; #define DETAIL_EXEC_CONTENT(field, actPtr) \ std::cerr << " " << #field << " / " << TAGNAME_CAST(actPtr->field) << " ("; \ NodeSet<std::string> contents = filterChildType(Node_base::ELEMENT_NODE, actPtr->field, true); \ -for (int i = 0; i < contents.size(); i++) { \ +for (size_t i = 0; i < contents.size(); i++) { \ std::cerr << " " << TAGNAME_CAST(contents[i]); \ } \ std::cerr << ")"; @@ -148,7 +148,7 @@ ChartToFSM::~ChartToFSM() { // tear down caches Arabica::XPath::NodeSet<std::string> allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); - for (int i = 0; i < allTransitions.size(); i++) { + for (size_t i = 0; i < allTransitions.size(); i++) { _transParents.erase(allTransitions[i]); } } @@ -215,14 +215,14 @@ InterpreterState ChartToFSM::interpret() { { Arabica::XPath::NodeSet<std::string> allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); indexedTransitions.reserve(allTransitions.size()); - for (int i = 0; i < allTransitions.size(); i++) { + for (size_t i = 0; i < allTransitions.size(); i++) { _transParents[allTransitions[i]] = InterpreterImpl::getParentState(allTransitions[i]); } } // identify all history elements NodeSet<std::string> histories = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "history", _scxml, true); - for (int i = 0; i < histories.size(); i++) { + for (size_t i = 0; i < histories.size(); i++) { _historyTargets[ATTR_CAST(histories[i], "id")] = Element<std::string>(histories[i]); } @@ -236,7 +236,7 @@ InterpreterState ChartToFSM::interpret() { // set invokeid for all invokers to parent state if none given NodeSet<std::string> invokers = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); - for (int i = 0; i < invokers.size(); i++) { + for (size_t i = 0; i < invokers.size(); i++) { Element<std::string> invokerElem = Element<std::string>(invokers[i]); invokerElem.setAttribute("parent", ATTR_CAST(invokerElem.getParentNode(), "id")); } @@ -255,7 +255,7 @@ InterpreterState ChartToFSM::interpret() { Arabica::XPath::NodeSet<std::string> initialStates; initialStates = getInitialStates(); assert(initialStates.size() > 0); - for (int i = 0; i < initialStates.size(); i++) { + for (size_t i = 0; i < initialStates.size(); i++) { Element<std::string> initialElem = _document.createElementNS(_nsInfo.nsURL, "initial"); _nsInfo.setPrefix(initialElem); initialElem.setAttribute("generated", "true"); @@ -275,19 +275,19 @@ InterpreterState ChartToFSM::interpret() { indexTransitions(); // add initial transitions as least prior - for (int i = 0; i < initialTransitions.size() ; i++) { + for (size_t i = 0; i < initialTransitions.size() ; i++) { indexedTransitions.push_back(Element<std::string>(initialTransitions[i])); } // set index attribute for transitions - for (int i = 0; i < indexedTransitions.size(); i++) { + for (size_t i = 0; i < indexedTransitions.size(); i++) { // std::cerr << toStr(i) << ":" << (HAS_ATTR(indexedTransitions[i], "line_start") ? ATTR(indexedTransitions[i], "line_start") : ""); // std::cerr << "\t" << DOMUtils::xPathForNode(indexedTransitions[i]) << std::endl; indexedTransitions[i].setAttribute("index", toStr(i)); } // int lastTransIndex = indexedTransitions.size(); -// for (int i = 0; i < initialTransitions.size() ; i++, lastTransIndex++) { +// for (size_t i = 0; i < initialTransitions.size() ; i++, lastTransIndex++) { // indexedTransitions[i].setAttribute("index", toStr(indexedTransitions.size() - 1 - i)); // } @@ -296,7 +296,7 @@ InterpreterState ChartToFSM::interpret() { allStates.to_document_order(); indexedStates.resize(allStates.size()); - for (int i = 0; i < allStates.size(); i++) { + for (size_t i = 0; i < allStates.size(); i++) { Element<std::string> state = Element<std::string>(allStates[i]); // while we are iterating, determine deepest nested level @@ -471,7 +471,7 @@ static bool isSuperset(const GlobalTransition* t1, const GlobalTransition* t2) { NodeSet<std::string> t1Trans = t1->getTransitions(); NodeSet<std::string> t2Trans = t2->getTransitions(); - for (int i = 0; i < t1Trans.size(); i++) { + for (size_t i = 0; i < t1Trans.size(); i++) { if (!InterpreterImpl::isMember(t1Trans[i], t2Trans)) { isSuperset = false; } @@ -566,12 +566,12 @@ void ChartToFSM::annotateRaiseAndSend(const Arabica::DOM::Element<std::string>& execContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true)); execContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onentry", _scxml, true)); execContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onexit", _scxml, true)); - for (int i = 0; i < execContent.size(); i++) { + for (size_t i = 0; i < execContent.size(); i++) { Element<std::string> execContentElem(execContent[i]); int nrRaise = 0; NodeSet<std::string> raise = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "raise", execContent[i], true); - for (int j = 0; j < raise.size(); j++) { + for (size_t j = 0; j < raise.size(); j++) { if (hasForeachInBetween(execContent[i], raise[j])) { execContentElem.setAttribute("raise", "-1"); goto DONE_COUNT_RAISE; @@ -585,7 +585,7 @@ DONE_COUNT_RAISE: int nrSend = 0; NodeSet<std::string> sends = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "send", execContent[i], true); - for (int j = 0; j < sends.size(); j++) { + for (size_t j = 0; j < sends.size(); j++) { if (hasForeachInBetween(execContent[i], sends[j])) { execContentElem.setAttribute("send", "-1"); goto DONE_COUNT_SEND; @@ -602,7 +602,7 @@ DONE_COUNT_SEND: void ChartToFSM::annotateDomain() { Arabica::XPath::NodeSet<std::string> allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); - for (int i = 0; i < allTransitions.size(); i++) { + for (size_t i = 0; i < allTransitions.size(); i++) { Element<std::string> transition(allTransitions[i]); Arabica::DOM::Node<std::string> domain = getTransitionDomain(transition); if (domain) { @@ -615,14 +615,14 @@ void ChartToFSM::annotateDomain() { void ChartToFSM::annotateExitSet() { Arabica::XPath::NodeSet<std::string> allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); - for (int i = 0; i < allTransitions.size(); i++) { + for (size_t i = 0; i < allTransitions.size(); i++) { Element<std::string> transition(allTransitions[i]); Arabica::DOM::Node<std::string> domain = getTransitionDomain(transition); Arabica::XPath::NodeSet<std::string> allStates = getAllStates(); std::ostringstream exitSetStr; std::string seperator = ""; - for (int j = 0; j < allStates.size(); j++) { + for (size_t j = 0; j < allStates.size(); j++) { Element<std::string> state(allStates[j]); if (state.getParentNode() == domain) { exitSetStr << seperator << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)); @@ -635,7 +635,7 @@ void ChartToFSM::annotateExitSet() { void ChartToFSM::annotateEntrySet() { Arabica::XPath::NodeSet<std::string> allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); - for (int i = 0; i < allTransitions.size(); i++) { + for (size_t i = 0; i < allTransitions.size(); i++) { Element<std::string> transition(allTransitions[i]); NodeSet<std::string> tmpTransitions; @@ -649,12 +649,12 @@ void ChartToFSM::annotateEntrySet() { std::ostringstream entrySetStr; std::string seperator = ""; - for (int j = 0; j < tmpStatesToEnter.size(); j++) { + for (size_t j = 0; j < tmpStatesToEnter.size(); j++) { Element<std::string> state(tmpStatesToEnter[j]); entrySetStr << seperator << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)); seperator = ", "; } - for (int j = 0; j < tmpStatesForDefaultEntry.size(); j++) { + for (size_t j = 0; j < tmpStatesForDefaultEntry.size(); j++) { Element<std::string> state(tmpStatesForDefaultEntry[j]); entrySetStr << seperator << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)); seperator = ", "; @@ -668,7 +668,7 @@ void ChartToFSM::annotateConflicts() { Arabica::XPath::NodeSet<std::string> allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); Arabica::XPath::NodeSet<std::string> allStates = getAllStates(); - for (int i = 0; i < allTransitions.size(); i++) { + for (size_t i = 0; i < allTransitions.size(); i++) { Element<std::string> t1(allTransitions[i]); if (!isState(Element<std::string>(t1.getParentNode()))) continue; @@ -676,7 +676,7 @@ void ChartToFSM::annotateConflicts() { Arabica::DOM::Node<std::string> d1 = getTransitionDomain(t1); Arabica::XPath::NodeSet<std::string> exitSet1; - for (int k = 0; k < allStates.size(); k++) { + for (size_t k = 0; k < allStates.size(); k++) { Element<std::string> state(allStates[k]); if (isDescendant(state, d1)) { exitSet1.push_back(state); @@ -686,7 +686,7 @@ void ChartToFSM::annotateConflicts() { std::ostringstream preemptionStr; std::string seperator = ""; - for (int j = 0; j < allTransitions.size(); j++) { + for (size_t j = 0; j < allTransitions.size(); j++) { if ( i == j) continue; @@ -697,7 +697,7 @@ void ChartToFSM::annotateConflicts() { Arabica::DOM::Node<std::string> d2 = getTransitionDomain(t2); Arabica::XPath::NodeSet<std::string> exitSet2; - for (int k = 0; k < allStates.size(); k++) { + for (size_t k = 0; k < allStates.size(); k++) { Element<std::string> state(allStates[k]); if (isDescendant(state, d2)) { exitSet2.push_back(state); @@ -764,13 +764,13 @@ void ChartToFSM::indexTransitions(const Arabica::DOM::Element<std::string>& root void ChartToFSM::indexTransitions(const Arabica::DOM::Element<std::string>& root) { // Post-order traversal of transitions Arabica::XPath::NodeSet<std::string> childStates = getChildStates(root); - for (int i = 0; i < childStates.size(); i++) { + for (size_t i = 0; i < childStates.size(); i++) { Element<std::string> childElem(childStates[i]); indexTransitions(childElem); } Arabica::XPath::NodeSet<std::string> levelTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", root); - for (int i = 0; i < levelTransitions.size(); i++) { + for (size_t i = 0; i < levelTransitions.size(); i++) { // push into index starting with least prior indexedTransitions.push_back(Element<std::string>(levelTransitions[i])); } @@ -813,7 +813,7 @@ bool hasUnconditionalSuperset(GlobalTransition* first, GlobalTransition* second) // return false; if (isSuperset(second, first)) { - for (int i = 0; i < firstTransitions.size(); i++) { + for (size_t i = 0; i < firstTransitions.size(); i++) { if (!InterpreterImpl::isMember(firstTransitions[i], secondTransitions)) { if (HAS_ATTR_CAST(firstTransitions[i], "cond")) { return false; // second can't be removed @@ -996,7 +996,7 @@ std::list<GlobalTransition*> redundantMark(std::list<GlobalTransition*> list) { void TransitionTreeNode::dump(int indent) { std::string padding; - for (int i = 0; i + 1 < indent; i++) { + for (size_t i = 0; i + 1 < indent; i++) { padding += "| "; } if (indent > 0) @@ -1052,7 +1052,7 @@ void ChartToFSM::getPotentialTransitionsForConfFromTree(const Arabica::XPath::No // recursion start std::set<TransitionTreeNode*> transLeafs; - for (int i = 0; i < conf.size(); i++) { + for (size_t i = 0; i < conf.size(); i++) { DUMP_STATS(conf.size(), false); Element<std::string> confElem(conf[i]); @@ -1256,7 +1256,7 @@ TransitionTreeNode* ChartToFSM::buildTransTree(const Arabica::DOM::Element<std:: TransitionTreeNode* lastNode = NULL; - for (int i = 0; i < nested.size(); i++) { + for (size_t i = 0; i < nested.size(); i++) { Element<std::string> nestedElem(nested[i]); if (TAGNAME(nestedElem) == _nsInfo.xmlNSPrefix + "transition") { TransitionTreeNode* transNode = new TransitionTreeNode(); @@ -1300,7 +1300,7 @@ void ChartToFSM::getPotentialTransitionsForConfFromPowerSet(const Arabica::XPath { std::string seperator = ""; - for (int i = 0; i < allTransitions.size(); i++) { + for (size_t i = 0; i < allTransitions.size(); i++) { std::cerr << seperator << ATTR_CAST(allTransitions[i], "index"); seperator=", "; } @@ -1344,7 +1344,7 @@ void ChartToFSM::getPotentialTransitionsForConfFromPowerSet(const Arabica::XPath NodeSet<std::string> transitions; // std::cerr << globalState->stateId << " [" << nrElements << "]: " << std::endl; - for (int i = 1; i <= k; i++) { + for (size_t i = 1; i <= k; i++) { // std::cerr << stack[i] - 1 << ", "; transitions.push_back(allTransitions[stack[i] - 1]); } @@ -1742,16 +1742,16 @@ GlobalState::GlobalState(const Arabica::XPath::NodeSet<std::string>& activeState activeIndex = -1; // take references - for (int i = 0; i < activeStates_.size(); i++) { + for (size_t i = 0; i < activeStates_.size(); i++) { activeStatesRefs.insert(strTo<int>(ATTR_CAST(activeStates_[i], "index"))); } - for (int i = 0; i < alreadyEnteredStates_.size(); i++) { + for (size_t i = 0; i < alreadyEnteredStates_.size(); i++) { alreadyEnteredStatesRefs.insert(strTo<int>(ATTR_CAST(alreadyEnteredStates_[i], "index"))); } for (std::map<std::string, Arabica::XPath::NodeSet<std::string> >::const_iterator histIter = historyStates_.begin(); histIter != historyStates_.end(); histIter++) { - for (int i = 0; i < histIter->second.size(); i++) { + for (size_t i = 0; i < histIter->second.size(); i++) { historyStatesRefs[histIter->first].insert(strTo<int>(ATTR_CAST(histIter->second[i], "index"))); } } @@ -1790,7 +1790,7 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& t eventsChainSent = 0; historyBase = NULL; - for (int i = 0; i < transitionSet.size(); i++) { + for (size_t i = 0; i < transitionSet.size(); i++) { transitionRefs.insert(strTo<int>(ATTR_CAST(transitionSet[i], "index"))); } @@ -1808,7 +1808,7 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& t #if 0 std::cerr << "################" << std::endl; - for (int i = 0; i < transitions.size(); i++) { + for (size_t i = 0; i < transitions.size(); i++) { std::cerr << transitions[i] << std::endl; } std::cerr << "################" << std::endl; @@ -1833,7 +1833,7 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& t Arabica::DOM::Element<std::string> withTarget; Arabica::DOM::Element<std::string> noneTarget; - for (int i = 0; i < transitionSet.size(); i++) { + for (size_t i = 0; i < transitionSet.size(); i++) { Arabica::DOM::Element<std::string> transElem = Arabica::DOM::Element<std::string>(transitionSet[i]); if (HAS_ATTR(transElem, "eventexpr")) { ERROR_EXECUTION_THROW("Cannot flatten document with eventexpr attributes"); @@ -1909,7 +1909,7 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& t // extract conditions and history targets std::list<std::string> conditions; - for (int i = 0; i < transitionSet.size(); i++) { + for (size_t i = 0; i < transitionSet.size(); i++) { Arabica::DOM::Element<std::string> transElem = Arabica::DOM::Element<std::string>(transitionSet[i]); // gather conditions while we are iterating anyway if (HAS_ATTR(transElem, "cond")) { @@ -1937,7 +1937,7 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& t members += seperator + ATTR(refTrans, "priority"); } else { members += seperator; - for (int i = 0; i < ATTR(refTrans, "priority").size(); i++) { + for (size_t i = 0; i < ATTR(refTrans, "priority").size(); i++) { members += " "; } } @@ -1982,7 +1982,7 @@ std::list<std::string> GlobalTransition::getCommonEvents(const NodeSet<std::stri std::list<std::string> prefixes; std::list<std::string> longestPrefixes; - for (int i = 0; i < transitions.size(); i++) { + for (size_t i = 0; i < transitions.size(); i++) { // for every transition std::list<std::string> eventNames = tokenize(ATTR_CAST(transitions[i], "event")); @@ -1999,7 +1999,7 @@ std::list<std::string> GlobalTransition::getCommonEvents(const NodeSet<std::stri eventName = eventName.substr(0, eventName.size() - 1); bool isMatching = true; - for (int j = 0; j < transitions.size(); j++) { + for (size_t j = 0; j < transitions.size(); j++) { // check if token would activate all other transitions if (i == j) continue; diff --git a/src/uscxml/transform/ChartToFlatSCXML.cpp b/src/uscxml/transform/ChartToFlatSCXML.cpp index 984c287..ac91681 100644 --- a/src/uscxml/transform/ChartToFlatSCXML.cpp +++ b/src/uscxml/transform/ChartToFlatSCXML.cpp @@ -32,7 +32,7 @@ if (childs.size() > 0) { \ pendingComments.clear(); \ if (stateId.length() > 0) \ transientState.setAttribute("id", stateId); \ - for (int i = 0; i < childs.size(); i++) { \ + for (size_t i = 0; i < childs.size(); i++) { \ Node<std::string> imported = _flatDoc.importNode(childs[i], true); \ transientState.appendChild(imported); \ } \ @@ -64,7 +64,7 @@ void ChartToFlatSCXML::writeTo(std::ostream& stream) { // remove all debug attributes NodeSet<std::string> elementNodes = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); - for (int i = 0; i < elementNodes.size(); i++) { + for (size_t i = 0; i < elementNodes.size(); i++) { Element<std::string> element(elementNodes[i]); if (!envVarIsTrue("USCXML_ANNOTATE_GLOBAL_TRANS_SENDS") && HAS_ATTR(element, "send")) element.removeAttribute("send"); @@ -94,7 +94,7 @@ void ChartToFlatSCXML::createDocument() { { NodeSet<std::string> allElements = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); size_t nrElements = 0; - for (int i = 0; i < allElements.size(); i++) { + for (size_t i = 0; i < allElements.size(); i++) { if (!isInEmbeddedDocument(allElements[i])) nrElements++; } @@ -138,7 +138,7 @@ void ChartToFlatSCXML::createDocument() { // with early binding, copy all datamodel elements into scxml element datas = _xpath.evaluate("//" + _nsInfo.xpathPrefix + "datamodel", _origSCXML).asNodeSet(); } - for (int i = 0; i < datas.size(); i++) { + for (size_t i = 0; i < datas.size(); i++) { if (isInEmbeddedDocument(datas[i])) continue; // nested document Node<std::string> imported = _flatDoc.importNode(datas[i], true); @@ -147,13 +147,13 @@ void ChartToFlatSCXML::createDocument() { NodeSet<std::string> scripts = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _origSCXML); - for (int i = 0; i < scripts.size(); i++) { + for (size_t i = 0; i < scripts.size(); i++) { Node<std::string> imported = _flatDoc.importNode(scripts[i], true); _scxml.appendChild(imported); } NodeSet<std::string> comments = DOMUtils::filterChildType(Node_base::COMMENT_NODE, _origSCXML); - for (int i = 0; i < comments.size(); i++) { + for (size_t i = 0; i < comments.size(); i++) { Node<std::string> imported = _flatDoc.importNode(comments[i], true); _scxml.appendChild(imported); } @@ -185,7 +185,7 @@ void ChartToFlatSCXML::createDocument() { { NodeSet<std::string> allElements = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); size_t nrElements = 0; - for (int i = 0; i < allElements.size(); i++) { + for (size_t i = 0; i < allElements.size(); i++) { if (!isInEmbeddedDocument(allElements[i])) nrElements++; } @@ -385,7 +385,7 @@ Node<std::string> ChartToFlatSCXML::globalTransitionToNode(GlobalTransition* glo if (transientStateChain.size() > 0) { Element<std::string> prevExitTransitionElem; - for (int i = 0; i < transientStateChain.size(); i++) { + for (size_t i = 0; i < transientStateChain.size(); i++) { Element<std::string> transientStateElem = Element<std::string>(transientStateChain[i]); transientStateElem.setAttribute("id", transientStateElem.getAttribute("id") + "-via-" + toStr(_lastTransientStateId++)); diff --git a/src/uscxml/transform/ChartToMinimalSCXML.cpp b/src/uscxml/transform/ChartToMinimalSCXML.cpp index f052b09..80db707 100644 --- a/src/uscxml/transform/ChartToMinimalSCXML.cpp +++ b/src/uscxml/transform/ChartToMinimalSCXML.cpp @@ -51,7 +51,7 @@ void ChartToMinimalSCXML::writeTo(std::ostream& stream) { { NodeSet<std::string> allElements = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); size_t nrElements = 0; - for (int i = 0; i < allElements.size(); i++) { + for (size_t i = 0; i < allElements.size(); i++) { if (!isInEmbeddedDocument(allElements[i])) nrElements++; } @@ -76,7 +76,7 @@ void ChartToMinimalSCXML::writeTo(std::ostream& stream) { while(topMostDatamodel.hasChildNodes()) topMostDatamodel.removeChild(topMostDatamodel.getFirstChild()); - for (int i = 0; i < datas.size(); i++) { + for (size_t i = 0; i < datas.size(); i++) { if (!isInEmbeddedDocument(datas[i])) { topMostDatamodel.appendChild(datas[i]); } @@ -120,7 +120,7 @@ void ChartToMinimalSCXML::writeTo(std::ostream& stream) { { NodeSet<std::string> allElements = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); size_t nrElements = 0; - for (int i = 0; i < allElements.size(); i++) { + for (size_t i = 0; i < allElements.size(); i++) { if (!isInEmbeddedDocument(allElements[i])) nrElements++; } @@ -153,7 +153,7 @@ void ChartToMinimalSCXML::removeUnvisited(Arabica::DOM::Node<std::string>& node) NodeSet<std::string> ifChilds = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, elem, false); Element<std::string> lastConditional = elem; bool hadVisitedChild = false; - for (int j = 0; j < ifChilds.size(); j++) { + for (size_t j = 0; j < ifChilds.size(); j++) { Element<std::string> ifChildElem(ifChilds[j]); if (TAGNAME(ifChildElem) == _nsInfo.xmlNSPrefix + "else" || TAGNAME(ifChildElem) == _nsInfo.xmlNSPrefix + "elseif") { if (!hadVisitedChild && HAS_ATTR(lastConditional, "cond")) { @@ -193,7 +193,7 @@ void ChartToMinimalSCXML::removeUnvisited(Arabica::DOM::Node<std::string>& node) // iterate and remove unvisited children NodeList<std::string> children = node.getChildNodes(); - for (int i = 0; i < children.getLength(); i++) { + for (size_t i = 0; i < children.getLength(); i++) { Node<std::string> child(children.item(i)); removeUnvisited(child); } @@ -225,7 +225,7 @@ void ChartToMinimalSCXML::beforeUninvoking(Interpreter interpreter, const Arabic void ChartToMinimalSCXML::beforeTakingTransition(Interpreter interpreter, const Arabica::DOM::Element<std::string>& transition, bool moreComing) { NodeSet<std::string> targets = getTargetStates(transition); // we need this for history pseudo states - for (int i = 0; i < targets.size(); i++) { + for (size_t i = 0; i < targets.size(); i++) { markAsVisited(Arabica::DOM::Element<std::string>(targets[i])); } markAsVisited(transition); diff --git a/src/uscxml/transform/ChartToPromela.cpp b/src/uscxml/transform/ChartToPromela.cpp index 747fb34..b0c3c79 100644 --- a/src/uscxml/transform/ChartToPromela.cpp +++ b/src/uscxml/transform/ChartToPromela.cpp @@ -52,7 +52,7 @@ } #define INDENT_MIN(stream, start, cols) \ -for (int indentIndex = start; indentIndex < cols; indentIndex++) \ +for (size_t indentIndex = start; indentIndex < cols; indentIndex++) \ stream << " "; #define DIFF_MAPS(base, compare, result) \ @@ -392,7 +392,7 @@ std::string PromelaCodeAnalyzer::getTypeReset(const std::string& var, const Prom while(typeIter != type.types.end()) { const PromelaTypedef& innerType = typeIter->second; if (innerType.arraySize > 0) { - for (int i = 0; i < innerType.arraySize; i++) { + for (size_t i = 0; i < innerType.arraySize; i++) { assignment << padding << var << "." << typeIter->first << "[" << i << "] = 0;" << std::endl; } } else if (innerType.types.size() > 0) { @@ -413,7 +413,7 @@ std::string PromelaCodeAnalyzer::getTypeAssignment(const std::string& varTo, con while(typeIter != type.types.end()) { const PromelaTypedef& innerType = typeIter->second; if (innerType.arraySize > 0) { - for (int i = 0; i < innerType.arraySize; i++) { + for (size_t i = 0; i < innerType.arraySize; i++) { assignment << padding << varTo << "." << typeIter->first << "[" << i << "] = " << varFrom << "." << typeIter->first << "[" << i << "];" << std::endl; } } else if (innerType.types.size() > 0) { @@ -597,7 +597,7 @@ void ChartToPromela::writeStates(std::ostream& stream) { stateIter++; } -// for (int i = 0; i < _globalConf.size(); i++) { +// for (size_t i = 0; i < _globalConf.size(); i++) { // stream << "#define " << "s" << i << " " << i; // stream << " /* from \"" << ATTR_CAST(_globalStates[i], "id") << "\" */" << std::endl; // } @@ -856,7 +856,7 @@ std::string ChartToPromela::conditionalizeForHist(const std::set<GlobalTransitio void ChartToPromela::writeTransition(std::ostream& stream, GlobalTransition* transition, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } std::list<GlobalTransition*>::const_iterator histIter; @@ -1222,7 +1222,7 @@ void ChartToPromela::writeTransition(std::ostream& stream, GlobalTransition* tra void ChartToPromela::writeHistoryAssignments(std::ostream& stream, GlobalTransition* transition, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -1464,7 +1464,7 @@ void HistoryTransitionClass::merge(const HistoryTransitionClass& other) { void ChartToPromela::writeTransitionClosure(std::ostream& stream, GlobalTransition* transition, GlobalState* state, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -1489,7 +1489,7 @@ void ChartToPromela::writeExecutableContent(std::ostream& stream, const Arabica: return; std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -1513,7 +1513,7 @@ void ChartToPromela::writeExecutableContent(std::ostream& stream, const Arabica: } } else if(TAGNAME(nodeElem) == "script") { NodeSet<std::string> scriptText = DOMUtils::filterChildType(Node_base::TEXT_NODE, node, true); - for (int i = 0; i < scriptText.size(); i++) { + for (size_t i = 0; i < scriptText.size(); i++) { stream << ADAPT_SRC(beautifyIndentation(scriptText[i].getNodeValue(), indent)) << std::endl; } @@ -1657,7 +1657,7 @@ void ChartToPromela::writeExecutableContent(std::ostream& stream, const Arabica: NodeSet<std::string> sendContents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", nodeElem); std::string sendNameList = ATTR(nodeElem, "namelist"); if (sendParams.size() > 0) { - for (int i = 0; i < sendParams.size(); i++) { + for (size_t i = 0; i < sendParams.size(); i++) { Element<std::string> paramElem = Element<std::string>(sendParams[i]); typeAssignSS << padding << " tmpE.data." << ATTR(paramElem, "name") << " = " << ADAPT_SRC(ATTR(paramElem, "expr")) << ";" << std::endl; } @@ -1842,11 +1842,11 @@ PromelaInlines::PromelaInlines(const Arabica::DOM::Node<std::string>& node) { PromelaInline* predecessor = NULL; // iterate all nodes at given level - for (int i = 0; i < levelNodes.size(); i++) { + for (size_t i = 0; i < levelNodes.size(); i++) { // get all comments NodeSet<std::string> comments = DOMUtils::filterChildType(Node_base::COMMENT_NODE, levelNodes[i]); - for (int j = 0; j < comments.size(); j++) { + for (size_t j = 0; j < comments.size(); j++) { PromelaInline* tmp = new PromelaInline(comments[j]); if (tmp->type == PromelaInline::PROMELA_NIL) { delete tmp; @@ -1904,7 +1904,7 @@ void ChartToPromela::writeIfBlock(std::ostream& stream, const Arabica::XPath::No return; std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -1957,7 +1957,7 @@ void ChartToPromela::writeIfBlock(std::ostream& stream, const Arabica::XPath::No stream << "{" << std::endl; Arabica::XPath::NodeSet<std::string> cdrCondChain; - for (int i = 1; i < condChain.size(); i++) { + for (size_t i = 1; i < condChain.size(); i++) { cdrCondChain.push_back(condChain[i]); } writeIfBlock(stream, cdrCondChain, indent + 1); @@ -1972,7 +1972,7 @@ void ChartToPromela::writeIfBlock(std::ostream& stream, const Arabica::XPath::No std::string ChartToPromela::beautifyIndentation(const std::string& code, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -2096,7 +2096,7 @@ void ChartToPromela::writeDeclarations(std::ostream& stream) { // automatic types PromelaCodeAnalyzer::PromelaTypedef allTypes = _analyzer->getTypes(); - for (int i = 0; i < datas.size(); i++) { + for (size_t i = 0; i < datas.size(); i++) { Node<std::string> data = datas[i]; if (isInEmbeddedDocument(data)) @@ -2177,7 +2177,7 @@ void ChartToPromela::writeEventSources(std::ostream& stream) { void ChartToPromela::writeStartInvoker(std::ostream& stream, const Arabica::DOM::Node<std::string>& node, ChartToPromela* invoker, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -2193,7 +2193,7 @@ void ChartToPromela::writeStartInvoker(std::ostream& stream, const Arabica::DOM: // set from params NodeSet<std::string> invokeParams = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", node); - for (int i = 0; i < invokeParams.size(); i++) { + for (size_t i = 0; i < invokeParams.size(); i++) { std::string identifier = ATTR_CAST(invokeParams[i], "name"); std::string expression = ATTR_CAST(invokeParams[i], "expr"); if (invoker->_dataModelVars.find(identifier) != invoker->_dataModelVars.end()) { @@ -2225,7 +2225,7 @@ void ChartToPromela::writeFSM(std::ostream& stream) { NodeSet<std::string> scripts = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml, false); if (scripts.size() > 0) { stream << std::endl << "/* global scripts */" << std::endl; - for (int i = 0; i < scripts.size(); i++) { + for (size_t i = 0; i < scripts.size(); i++) { writeExecutableContent(stream, scripts[i], 1); } stream << std::endl; @@ -2339,7 +2339,7 @@ void ChartToPromela::writeFSM(std::ostream& stream) { NodeSet<std::string> transitions = DOMUtils::filterChildElements("transition", es.container, true); std::set<std::string> eventNames; - for (int i = 0; i < transitions.size(); i++) { + for (size_t i = 0; i < transitions.size(); i++) { if (!HAS_ATTR_CAST(transitions[i], "event")) continue; if (HAS_ATTR_CAST(transitions[i], "cond") && ATTR_CAST(transitions[i], "cond").find("_event.") != std::string::npos) @@ -2492,7 +2492,7 @@ void ChartToPromela::writeFSM(std::ostream& stream) { void ChartToPromela::writeRescheduleProcess(std::ostream& stream, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -2536,7 +2536,7 @@ void ChartToPromela::writeRescheduleProcess(std::ostream& stream, int indent) { void ChartToPromela::writeDetermineShortestDelay(std::ostream& stream, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -2557,7 +2557,7 @@ void ChartToPromela::writeDetermineShortestDelay(std::ostream& stream, int inden void ChartToPromela::writeInsertWithDelay(std::ostream& stream, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -2651,7 +2651,7 @@ void ChartToPromela::writeInsertWithDelay(std::ostream& stream, int indent) { void ChartToPromela::writeAdvanceTime(std::ostream& stream, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -2739,7 +2739,7 @@ void ChartToPromela::writeCancelEvents(std::ostream& stream, int indent) { void ChartToPromela::writeScheduleMachines(std::ostream& stream, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -2814,7 +2814,7 @@ void ChartToPromela::writeEventDispatching(std::ostream& stream) { void ChartToPromela::writeDispatchingBlock(std::ostream& stream, std::list<GlobalTransition*> transitions, int indent) { std::string padding; - for (int i = 0; i < indent; i++) { + for (size_t i = 0; i < indent; i++) { padding += " "; } @@ -2976,7 +2976,7 @@ void ChartToPromela::initNodes() { // get all states NodeSet<std::string> states = getAllStates(); - for (int i = 0; i < states.size(); i++) { + for (size_t i = 0; i < states.size(); i++) { if (InterpreterImpl::isInEmbeddedDocument(states[i])) continue; Element<std::string> stateElem(states[i]); @@ -2992,7 +2992,7 @@ void ChartToPromela::initNodes() { invokes.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "uninvoke", _scxml, true)); // make sure all invokers have an id! - for (int i = 0; i < invokes.size(); i++) { + for (size_t i = 0; i < invokes.size(); i++) { if (!HAS_ATTR_CAST(invokes[i], "id")) { Element<std::string> invokeElem(invokes[i]); invokeElem.setAttribute("id", "INV_" + UUID::getUUID().substr(0,5)); @@ -3008,7 +3008,7 @@ void ChartToPromela::initNodes() { // are there nestes SCXML invokers? { NodeSet<std::string> invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); - for (int i = 0; i < invokes.size(); i++) { + for (size_t i = 0; i < invokes.size(); i++) { if (!HAS_ATTR_CAST(invokes[i], "type") || ATTR_CAST(invokes[i], "type") == "scxml" || ATTR_CAST(invokes[i], "type") == "http://www.w3.org/TR/scxml/#SCXMLEventProcessor" || @@ -3075,7 +3075,7 @@ void ChartToPromela::initNodes() { histStatesMembers.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "parallel", histIter->second.getParentNode(), isDeep)); histStatesMembers.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "final", histIter->second.getParentNode(), isDeep)); - for (int i = 0; i < histStatesMembers.size(); i++) { + for (size_t i = 0; i < histStatesMembers.size(); i++) { _historyMembers[histIter->first].insert(std::make_pair(ATTR_CAST(histStatesMembers[i], "id"), i)); } histIter++; @@ -3087,7 +3087,7 @@ void ChartToPromela::initNodes() { internalEventNames.push_back(_xpath.evaluate("//" + _nsInfo.xpathPrefix + "raise", _scxml).asNodeSet()); internalEventNames.push_back(_xpath.evaluate("//" + _nsInfo.xpathPrefix + "send", _scxml).asNodeSet()); - for (int i = 0; i < internalEventNames.size(); i++) { + for (size_t i = 0; i < internalEventNames.size(); i++) { if (HAS_ATTR_CAST(internalEventNames[i], "event")) { std::string eventNames = ATTR_CAST(internalEventNames[i], "event"); std::list<std::string> events = tokenize(eventNames); @@ -3113,7 +3113,7 @@ void ChartToPromela::initNodes() { asgn.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true)); asgn.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); - for (int i = 0; i < asgn.size(); i++) { + for (size_t i = 0; i < asgn.size(); i++) { if (isInEmbeddedDocument(asgn[i])) continue; @@ -3139,7 +3139,7 @@ void ChartToPromela::initNodes() { } else { NodeSet<std::string> textChilds = DOMUtils::filterChildType(Node_base::TEXT_NODE, asgnElem); if (textChilds.size() > 0) { - for (int j = 0; j < textChilds.size(); j++) { + for (size_t j = 0; j < textChilds.size(); j++) { value += textChilds[j].getNodeValue(); } } @@ -3180,7 +3180,7 @@ void ChartToPromela::initNodes() { _analyzer->addCode("_event.invokeid", this); } - for (int i = 0; i < sends.size(); i++) { + for (size_t i = 0; i < sends.size(); i++) { if (HAS_ATTR_CAST(sends[i], "idlocation")) { _analyzer->addCode("_event.sendid", this); } @@ -3191,7 +3191,7 @@ void ChartToPromela::initNodes() { } // do we need delays? - for (int i = 0; i < sends.size(); i++) { + for (size_t i = 0; i < sends.size(); i++) { if (HAS_ATTR_CAST(sends[i], "delay") || HAS_ATTR_CAST(sends[i], "delayexpr")) { _analyzer->addCode("_event.delay", this); #if NEW_DELAY_RESHUFFLE @@ -3208,9 +3208,9 @@ void ChartToPromela::initNodes() { withContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true)); withContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "raise", _scxml, true)); - for (int i = 0; i < withContent.size(); i++) { + for (size_t i = 0; i < withContent.size(); i++) { NodeSet<std::string> content = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", withContent[i], true); - for (int j = 0; j < content.size(); j++) { + for (size_t j = 0; j < content.size(); j++) { Element<std::string> contentElem(content[j]); std::string content = spaceNormalize(contentElem.getFirstChild().getNodeValue()); if (!isNumeric(content.c_str(), 10)) @@ -3243,7 +3243,7 @@ void ChartToPromela::initNodes() { } if (json.array.size() > 0) { - for (int i = 0; i < json.array.size(); i++) { + for (size_t i = 0; i < json.array.size(); i++) { std::string expr = dataToAssignments("_event", json.item(i)); _analyzer->addCode(expr, this); } @@ -3266,7 +3266,7 @@ void ChartToPromela::initNodes() { } NodeSet<std::string> contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", _scxml, true); - for (int i = 0; i < contents.size(); i++) { + for (size_t i = 0; i < contents.size(); i++) { Element<std::string> contentElem = Element<std::string>(contents[i]); if (contentElem.hasChildNodes() && contentElem.getFirstChild().getNodeType() == Node_base::TEXT_NODE && contentElem.getChildNodes().getLength() == 1) { std::string content = contentElem.getFirstChild().getNodeValue(); @@ -3283,7 +3283,7 @@ void ChartToPromela::initNodes() { withCond.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true)); withCond.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "if", _scxml, true)); withCond.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "elseif", _scxml, true)); - for (int i = 0; i < withCond.size(); i++) { + for (size_t i = 0; i < withCond.size(); i++) { Element<std::string> elem = Element<std::string>(withCond[i]); if (HAS_ATTR(elem, "cond")) { std::string code = ATTR(elem, "cond"); @@ -3300,7 +3300,7 @@ void ChartToPromela::initNodes() { withExpr.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); withExpr.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", _scxml, true)); withExpr.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", _scxml, true)); - for (int i = 0; i < withExpr.size(); i++) { + for (size_t i = 0; i < withExpr.size(); i++) { Element<std::string> elem = Element<std::string>(withExpr[i]); if (HAS_ATTR(elem, "expr")) { std::string code = ATTR(elem, "expr"); @@ -3313,7 +3313,7 @@ void ChartToPromela::initNodes() { { NodeSet<std::string> withLocation; withLocation.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); - for (int i = 0; i < withLocation.size(); i++) { + for (size_t i = 0; i < withLocation.size(); i++) { Element<std::string> elem = Element<std::string>(withLocation[i]); if (HAS_ATTR(elem, "location")) { std::string code = ATTR(elem, "location"); @@ -3327,9 +3327,9 @@ void ChartToPromela::initNodes() { NodeSet<std::string> withText; withText.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml, true)); // withText.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true)); - for (int i = 0; i < withText.size(); i++) { + for (size_t i = 0; i < withText.size(); i++) { NodeSet<std::string> texts = DOMUtils::filterChildType(Node_base::TEXT_NODE, withText[i], true); - for (int j = 0; j < texts.size(); j++) { + for (size_t j = 0; j < texts.size(); j++) { if (texts[j].getNodeValue().size() > 0) { Text<std::string> elem = Text<std::string>(texts[j]); std::string code = elem.getNodeValue(); @@ -3342,7 +3342,7 @@ void ChartToPromela::initNodes() { } { NodeSet<std::string> foreachs = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "foreach", _scxml, true); - for (int i = 0; i < foreachs.size(); i++) { + for (size_t i = 0; i < foreachs.size(); i++) { if (HAS_ATTR_CAST(foreachs[i], "index")) { allCode.insert(ATTR_CAST(foreachs[i], "index")); } else { @@ -3362,7 +3362,7 @@ void ChartToPromela::initNodes() { NodeSet<std::string> withNamelist; withNamelist.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true)); withNamelist.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true)); - for (int i = 0; i < withNamelist.size(); i++) { + for (size_t i = 0; i < withNamelist.size(); i++) { if (HAS_ATTR_CAST(withNamelist[i], "namelist")) { std::string namelist = ATTR_CAST(withNamelist[i], "namelist"); std::list<std::string> names = tokenize(namelist); diff --git a/src/uscxml/transform/ChartToTex.cpp b/src/uscxml/transform/ChartToTex.cpp index f38740a..9d30be5 100644 --- a/src/uscxml/transform/ChartToTex.cpp +++ b/src/uscxml/transform/ChartToTex.cpp @@ -109,7 +109,7 @@ void ChartToTex::writeTex(std::ostream& stream) { for (std::list<GlobalTransition*>::iterator transIter = stateIter->second->sortedOutgoing.begin(); transIter != stateIter->second->sortedOutgoing.end(); transIter++) { GlobalTransition* currTrans = *transIter; Arabica::XPath::NodeSet<std::string> members = currTrans->getTransitions(); - for (int i = 0; i < members.size(); i++) { + for (size_t i = 0; i < members.size(); i++) { Element<std::string> transElem(members[i]); if (HAS_ATTR(transElem, "priority")) { origTransitions.insert(ATTR(transElem, "priority")); @@ -149,7 +149,7 @@ void ChartToTex::writeTex(std::ostream& stream) { if (members.size() > 0) { stream << "$\\{ "; seperator = ""; - for (int i = 0; i < members.size(); i++) { + for (size_t i = 0; i < members.size(); i++) { Element<std::string> transElem(members[i]); if (HAS_ATTR(transElem, "priority")) { stream << seperator << "t_{" << ATTR(transElem, "priority") << "}"; diff --git a/src/uscxml/transform/ChartToVHDL.cpp b/src/uscxml/transform/ChartToVHDL.cpp index 52f1a5c..7a139fa 100644 --- a/src/uscxml/transform/ChartToVHDL.cpp +++ b/src/uscxml/transform/ChartToVHDL.cpp @@ -78,7 +78,7 @@ void ChartToVHDL::checkDocument() { std::stringstream ss; if (unsupported.size() > 0) { - for (int i = 0; i < unsupported.size(); i++) { + for (size_t i = 0; i < unsupported.size(); i++) { ss << " " << DOMUtils::xPathForNode(unsupported[i]) << " unsupported" << std::endl; } throw std::runtime_error("Unsupported elements found:\n" + ss.str()); @@ -88,7 +88,7 @@ void ChartToVHDL::checkDocument() { elements.insert(_nsInfo.xmlNSPrefix + "transition"); unsupported = DOMUtils::inDocumentOrder(elements, _scxml); - for (int i = 0; i < unsupported.size(); i++) { + for (size_t i = 0; i < unsupported.size(); i++) { Element<std::string> transition(unsupported[i]); if (HAS_ATTR(transition, "cond")) { ERROR_PLATFORM_THROW("transition with conditions not supported!"); @@ -122,14 +122,9 @@ void ChartToVHDL::writeTo(std::ostream& stream) { // checkDocument(); findEvents(); -// _eventTrie.dump(); - writeTypes(stream); writeFiFo(stream); - writeOptimalTransitionSetSelection(stream); - writeExitSet(stream); - writeEntrySet(stream); writeFSM(stream); } @@ -169,10 +164,16 @@ void ChartToVHDL::writeFSM(std::ostream & stream) { writeModuleInstantiation(stream); // write fsm architecture - writeNextStateLogic(stream); +// writeNextStateLogic(stream); + + writeOptimalTransitionSetSelection(stream); + writeExitSet(stream); + writeEntrySet(stream); + // writeOutputLogic(stream); writeErrorHandler(stream); + stream << std::endl; stream << "end behavioral; " << std::endl; stream << "-- END FSM Logic" << std::endl; @@ -226,15 +227,15 @@ void ChartToVHDL::writeTypes(std::ostream & stream) { stream << std::endl; stream << "package machine" << _md5 << " is" << std::endl; // create state type - stream << " type state_type is std_logic_vector( "; + stream << " subtype state_type is std_logic_vector( "; stream << _states.size() - 1; - stream << " downto 0)" << std::endl; + stream << " downto 0);" << std::endl; //TODO complete // create event type stream << " type event_type is ("; seperator = ""; -// for (int i = 0; i < _events.size(); i++) { +// for (size_t i = 0; i < _events.size(); i++) { // stream << seperator; // stream << _events[i]; // seperator = ", "; @@ -358,16 +359,32 @@ void ChartToVHDL::writeSignals(std::ostream & stream) { stream << "-- system signals" << std::endl; stream << "signal stall : std_logic;" << std::endl; stream << "-- state signals" << std::endl; - stream << "signal next_state : state_type;" << std::endl; - stream << "signal current_state : state_type;" << std::endl; +// stream << "signal next_state : state_type;" << std::endl; +// stream << "signal current_state : state_type;" << std::endl; - for (int i = 0; i < _states.size(); i++) { + for (size_t i = 0; i < _states.size(); i++) { Element<std::string> state(_states[i]); - stream << "signal " << ATTR(state, "id") << "_curr : current_state(" - << toStr(i) << ");" << std::endl; - stream << "signal " << ATTR(state, "id") << "_next : next_state(" - << toStr(i) << ");" << std::endl; + stream << "signal " << DOMUtils::idForNode(state) << "_curr : std_logic;" << std::endl; + stream << "signal " << DOMUtils::idForNode(state) << "_next : std_logic;" << std::endl; } + for (size_t i = 0; i < _states.size(); i++) { + Element<std::string> state(_states[i]); + stream << "signal in_exit_set_" << ATTR(state, "documentOrder") << "_sig : std_logic;" << std::endl; + stream << "signal in_complete_entry_set_up_" << ATTR(state, "documentOrder") << "_sig : std_logic;" << std::endl; + stream << "signal in_complete_entry_set_" << ATTR(state, "documentOrder") << "_sig : std_logic;" << std::endl; + stream << "signal state_active_" << ATTR(state, "documentOrder") << "_sig : std_logic;" << std::endl; + stream << "signal default_completion_" << ATTR(state, "documentOrder") << "_sig : std_logic;" << std::endl; + } + + stream << "-- transition signals" << std::endl; + stream << "signal spontaneous_en : std_logic;" << std::endl; + + for (size_t i = 0; i < _transitions.size(); i++) { + Element<std::string> transition(_transitions[i]); + stream << "signal in_optimal_transition_set_" << ATTR(transition, "postFixOrder") << "_sig : std_logic;" + << std::endl; + } + stream << std::endl; stream << "-- event signals" << std::endl; stream << "signal int_event_write_en : std_logic;" << std::endl; @@ -379,14 +396,13 @@ void ChartToVHDL::writeSignals(std::ostream & stream) { stream << "signal next_event : event_type;" << std::endl; stream << "signal event_consumed : std_logic;" << std::endl; stream << std::endl; - stream << "-- transition signals" << std::endl; - stream << "signal transition_spntaneous_en : std_logic;" << std::endl; - for (int i = 0; i < _transitions.size(); i++) { - Element<std::string> transition(_transitions[i]); - stream << "signal in_optimal_transition_set_" << ATTR(transition, "postFixOrder") << "_sig : std_logic;" - << std::endl; - } + std::list<TrieNode*> eventNames = _eventTrie.getWordsWithPrefix(""); + for (std::list<TrieNode*>::iterator eventIter = eventNames.begin(); eventIter != eventNames.end(); eventIter++) { + stream << "signal event_" << eventNameEscape((*eventIter)->value) << "_sig : std_logic;" << std::endl; + } + // _eventTrie.dump(); + stream << std::endl; stream << "-- error signals" << std::endl; @@ -421,7 +437,7 @@ void ChartToVHDL::writeModuleInstantiation(std::ostream & stream) { stream << "next_event <= int_event_output; " << std::endl; stream << "int_event_write_en <= next_event_en_i; " << std::endl; stream << "int_event_input <= next_event_i; " << std::endl; - stream << "int_event_read_en <= not transition_spontanous_en and not stall; " << std::endl; + stream << "int_event_read_en <= not spontaneous_en and not stall; " << std::endl; stream << std::endl; // instantiate event fifo @@ -466,8 +482,44 @@ void ChartToVHDL::writeOptimalTransitionSetSelection(std::ostream & stream) { Element<std::string> transition(_transitions[i]); std::string conflicts = ATTR(transition, "conflictBools"); + + VContainer nameMatchers = VOR; + if (HAS_ATTR(transition, "event")) { + std::list<std::string> eventDescs = tokenize(ATTR(transition, "event")); + for (std::list<std::string>::iterator descIter = eventDescs.begin(); descIter != eventDescs.end(); descIter++) { + std::list<TrieNode*> eventNames = _eventTrie.getWordsWithPrefix((*descIter) == "*" ? "" : *descIter); + for (std::list<TrieNode*>::iterator eventIter = eventNames.begin(); eventIter != eventNames.end(); eventIter++) { + *nameMatchers += VLINE("event_" + eventNameEscape((*eventIter)->value) + "_sig"); + } + } + } else { + *nameMatchers += VLINE("'1'"); + } + + VContainer conflicters = VOR; + for (size_t j = 0; j < i; 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") , + (VAND , + (HAS_ATTR(transition, "event") + ? ( VNOT , VLINE("spontaneous_en") ) + : ( VNOP , VLINE("spontaneous_en") ) ) , + VLINE("state_active_" + ATTR(transition, "source") + "_sig"), + nameMatchers, + (VNOT , conflicters) ) ); + + tree->print(stream); + stream << ";" << std::endl; + + +#if 0 stream << "in_optimal_transition_set_" << ATTR(transition, "postFixOrder") << "_sig " - << "<= " << (HAS_ATTR(transition, "event") ? "(not spontaneous_sig)" : "spontaneous_sig") << " and " << std::endl + << "<= " << (HAS_ATTR(transition, "event") ? "(not spontaneous_en)" : "spontaneous_en") << " and " << std::endl << " state_active_" << ATTR(transition, "source") << "_sig and not ( '0' " << std::endl; for (size_t j = 0; j < i; j++) { if (conflicts[j] == '1') { @@ -490,8 +542,8 @@ void ChartToVHDL::writeOptimalTransitionSetSelection(std::ostream & stream) { } stream << ";" << std::endl; +#endif } - } void ChartToVHDL::writeExitSet(std::ostream & stream) { @@ -504,8 +556,27 @@ void ChartToVHDL::writeExitSet(std::ostream & stream) { std::string children = ATTR(state, "childBools"); std::string parent = ATTR(state, "parent"); + VContainer exitsetters = VOR; + for (size_t j = 0; j < _transitions.size(); j++) { + Element<std::string> transition(_transitions[j]); + std::string exitSet = ATTR(transition, "exitSetBools"); + if (exitSet[i] == '1') { + *exitsetters += VLINE("in_optimal_transition_set_" + toStr(j) + "_sig "); + } + } + + VBranch* tree = (VASSIGN , + VLINE("in_exit_set_" + toStr(i) + "_sig"), + (VAND, + VLINE("state_active_" + toStr(i) + "_sig"), + exitsetters )); + + tree->print(stream); + stream << ";" << std::endl; + +#if 0 stream << "in_exit_set_" << toStr(i) << "_sig " - << "<= state_active_ " << toStr(i) << "_sig and ('0'" << std::endl; + << "<= state_active_" << toStr(i) << "_sig and ('0'" << std::endl; for (size_t j = 0; j < _transitions.size(); j++) { Element<std::string> transition(_transitions[j]); std::string exitSet = ATTR(transition, "exitSetBools"); @@ -516,7 +587,7 @@ void ChartToVHDL::writeExitSet(std::ostream & stream) { stream << ")"; stream << ";" << std::endl; - +#endif } } @@ -530,6 +601,33 @@ void ChartToVHDL::writeEntrySet(std::ostream & stream) { std::string children = ATTR(state, "childBools"); std::string parent = ATTR(state, "parent"); + VContainer optimalEntrysetters = VOR; + for (size_t j = 0; j < _transitions.size(); j++) { + Element<std::string> transition(_transitions[j]); + std::string targetSet = ATTR(transition, "targetBools"); + if (targetSet[i] == '1') { + *optimalEntrysetters += VLINE("in_optimal_transition_set_" + toStr(j) + "_sig"); + } + } + + VContainer completeEntrysetters = VOR; + if (isCompound(state)) { + for (size_t j = 0; j < _states.size(); j++) { + if (children[j] != '1') + continue; + *completeEntrysetters += VLINE("in_complete_entry_set_up_" + toStr(j) + "_sig"); + } + } + + VBranch* tree = (VASSIGN , + VLINE("in_complete_entry_set_up_" + toStr(i) + "_sig"), + optimalEntrysetters, + completeEntrysetters); + + tree->print(stream); + stream << ";" << std::endl; + +#if 0 stream << "in_complete_entry_set_up_" << toStr(i) << "_sig <= ('0'" << std::endl; for (size_t j = 0; j < _transitions.size(); j++) { @@ -550,7 +648,7 @@ void ChartToVHDL::writeEntrySet(std::ostream & stream) { } stream << ");" << std::endl; - +#endif } for (size_t i = 0; i < _states.size(); i++) { @@ -564,6 +662,35 @@ void ChartToVHDL::writeEntrySet(std::ostream & stream) { continue; // TODO: FixMe <scxml> } + VContainer tmp1 = VAND; + if (isCompound(Element<std::string>(_states[strTo<size_t>(parent)]))) { + *tmp1 += VLINE("default_completion_" + toStr(parent) + "_sig"); + + for (size_t j = 0; j < _states.size(); j++) { + if (children[j] != '1') + continue; + *tmp1 += ( VAND, + ( VNOT, + ( VAND, + VLINE("is_active" + toStr(j) + "_sig"), + ( VNOT, + VLINE("in_exit_set_" + toStr(j) + "_sig") ) ) ) ); + + } + + } + + if (isParallel(Element<std::string>(_states[strTo<size_t>(parent)]))) { + *tmp1 += VLINE("in_complete_entry_set_" + toStr(parent) + "_sig"); + } + + VBranch* tree = (VASSIGN , + VLINE("in_complete_entry_set_" + toStr(i) + "_sig"), tmp1); + + tree->print(stream); + stream << ";" << std::endl; + +#if 0 stream << "in_complete_entry_set_" << toStr(i) << "_sig <= (in_complete_entry_set_up_" << toStr(i) << "_sig or (" << std::endl; if (isParallel(Element<std::string>(_states[strTo<size_t>(parent)]))) { @@ -580,7 +707,7 @@ void ChartToVHDL::writeEntrySet(std::ostream & stream) { } stream << ");" << std::endl; - +#endif } } @@ -595,7 +722,7 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { stream << "begin" << std::endl; std::stringstream nextStateBuffer; - for (int i = 0; i < _states.size(); i++) { + for (size_t i = 0; i < _states.size(); i++) { Element<std::string> state(_states[i]); // calculate event choices @@ -604,7 +731,7 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { // will be written first std::vector< Element<std::string> > choices; std::string spntaneous_trans_sig = ""; - for (int j = 0; j < _transitions.size(); j++) { + for (size_t j = 0; j < _transitions.size(); j++) { Element<std::string> transition(_transitions[j]); if (ATTR_CAST(transition.getParentNode(), "id") == ATTR(state, "id")) { choices.push_back(transition); @@ -618,7 +745,7 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { // calculate incomming transitions (for later use) std::vector< Element<std::string> > incommingTransitions; - for (int j = 0; j < _transitions.size(); j++) { + for (size_t j = 0; j < _transitions.size(); j++) { Element<std::string> transition(_transitions[j]); if (ATTR_CAST(transition, "target") == ATTR(state, "id")) { incommingTransitions.push_back(transition); @@ -630,7 +757,7 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { stream << " if ( " << ATTR(state, "id") << " = '1' ) then" << std::endl; stream << " if ( transition_spntaneous_en = '1' ) then" << std::endl; // enable spntaneous transition (if any) and disable all other - for (int j = 0; j < choices.size(); j++) { + for (size_t j = 0; j < choices.size(); j++) { Element<std::string> transition(choices[j]); if (ATTR(transition, "id") == spntaneous_trans_sig) { stream << " " << ATTR(transition, "id") << "_sig <= '1';" << std::endl; @@ -646,7 +773,7 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { // FIXME hopefully there is just one transition per state and event at a time stream << " case next_event is" << std::endl; bool hasWildcardTransition = false; - for (int j = 0; j < choices.size(); j++) { + for (size_t j = 0; j < choices.size(); j++) { Element<std::string> transition(choices[j]); std::string eventName = ATTR(transition, "event"); if (eventName == CONST_EVENT_ANY) { @@ -655,7 +782,7 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { } stream << " when " << eventName << " =>" << std::endl; // activate transition and deactivete others - for (int k = 0; k < choices.size(); k++) { + for (size_t k = 0; k < choices.size(); k++) { Element<std::string> tmp_t(choices[k]); if (ATTR(tmp_t, "event") == ATTR(transition, "event")) { stream << " " << ATTR(tmp_t, "id") << "_sig <= '1';" << std::endl; @@ -667,7 +794,7 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { if (!hasWildcardTransition) { // if there is no others we create one for deactivating everything stream << " when others =>" << std::endl; - for (int j = 0; j < choices.size(); j++) { + for (size_t j = 0; j < choices.size(); j++) { Element<std::string> tmp_t(choices[j]); stream << " " << ATTR(tmp_t, "id") << "_sig <= '0';" << std::endl; } @@ -679,7 +806,7 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { stream << " else" << std::endl; // no enabled event ? disable all transitions (looks like we have to wait) - for (int j = 0; j < choices.size(); j++) { + for (size_t j = 0; j < choices.size(); j++) { Element<std::string> transition(choices[j]); stream << " " << ATTR(transition, "id") << "_sig <= '0';" << std::endl; } @@ -690,14 +817,14 @@ void ChartToVHDL::writeNextStateLogic(std::ostream & stream) { // write next state calculation in buffer for later use nextStateBuffer << ATTR(state, "id") << "_next <= ( ( '0'"; std::string seperator = " or "; - for (int j = 0; j < incommingTransitions.size(); j++) { + for (size_t j = 0; j < incommingTransitions.size(); j++) { nextStateBuffer << seperator << ATTR(incommingTransitions[j], "id") << "_sig"; } nextStateBuffer << " ) or "; nextStateBuffer << "( ( not ( '0'"; seperator = " or "; - for (int j = 0; j < choices.size(); j++) { + for (size_t j = 0; j < choices.size(); j++) { nextStateBuffer << seperator << ATTR(choices[j], "id") << "_sig"; } @@ -729,7 +856,7 @@ void ChartToVHDL::writeOutputLogic(std::ostream & stream) { stream << "begin" << std::endl; stream << " case current_state is" << std::endl; - for (int i = 0; i < _states.size(); i++) { + for (size_t i = 0; i < _states.size(); i++) { //TODO // if end state set completed and result // on entry events generated here diff --git a/src/uscxml/transform/ChartToVHDL.h b/src/uscxml/transform/ChartToVHDL.h index c2dec15..933faa4 100644 --- a/src/uscxml/transform/ChartToVHDL.h +++ b/src/uscxml/transform/ChartToVHDL.h @@ -30,6 +30,7 @@ #include <DOM/Node.hpp> #include <XPath/XPath.hpp> #include <ostream> +#include <vector> namespace uscxml { @@ -41,6 +42,120 @@ public: void writeTo(std::ostream& stream); + + struct VNode { + virtual void print(std::ostream& stream, const std::string padding = "") = 0; + virtual ~VNode() {}; + }; + struct VBranch : VNode { + std::vector< VNode* > v; + virtual ~VBranch(){ + for(unsigned i = 0; i < v.size(); i++) + delete v[i]; + } + + VBranch& operator +=(VNode* p ) { + v.push_back(p); + return *this; + } + }; + + struct VPointer{ + VNode* ptr; + + operator VNode*() { + return ptr; + } + + VPointer& operator /( VNode* p ){ + ptr = p; + return *this; + } + }; + + struct VContainer { + VBranch* ptr; + + operator VBranch*() { + return ptr; + } + VContainer& operator /( VBranch* p ){ + ptr = p; + return *this; + } + VContainer& operator , ( VPointer p ) { + if(ptr) ptr->v.push_back(p.ptr); + return *this; + } + VContainer& operator , ( VContainer c ) { + if(ptr) ptr->v.push_back(c.ptr); + return *this; + } + }; + + struct VLine : VNode { + VLine(const std::string& name) : name(name) {} + virtual void print(std::ostream& stream, const std::string padding = "") { + stream << " " << name; + } + + std::string name; + }; + + struct VAssign : VBranch { + virtual void print(std::ostream& stream, const std::string padding = "") { + v[0]->print(stream, padding); + stream << padding << " <="; + v[1]->print(stream, padding + " "); + } + }; + + struct VAnd : VBranch { + virtual void print(std::ostream& stream, const std::string padding = "") { + stream << std::endl << padding << "( '1' "; + for(unsigned i = 0; i < v.size(); i++) { + stream << std::endl << padding << " and"; + v[i]->print(stream, padding + " "); + } + stream << padding << ")" << std::endl; + } + }; + + struct VOr : VBranch { + virtual void print(std::ostream& stream, const std::string padding = "") { + stream << std::endl << padding << "( '0' "; + for(unsigned i = 0; i < v.size(); i++) { + stream << std::endl << padding << " or"; + v[i]->print(stream, padding + " "); + } + stream << std::endl << padding << ")" << std::endl; + } + }; + + struct VNot : VBranch { + virtual void print(std::ostream& stream, const std::string padding = "") { + stream << " ( not"; + v[0]->print(stream, padding + " "); + stream << " )"; + } + }; + + struct VNop : VBranch { + virtual void print(std::ostream& stream, const std::string padding = "") { + v[0]->print(stream, padding); + } + }; + + +#define VLINE VPointer()/new VLine +#define VASSIGN VContainer()/new VAssign +#define VOR VContainer()/new VOr +#define VAND VContainer()/new VAnd +#define VNOT VContainer()/new VNot +#define VNOP VContainer()/new VNop + + + protected: ChartToVHDL(const Interpreter& other); diff --git a/src/uscxml/transform/FlatStateIdentifier.h b/src/uscxml/transform/FlatStateIdentifier.h index 99ae084..2d62651 100644 --- a/src/uscxml/transform/FlatStateIdentifier.h +++ b/src/uscxml/transform/FlatStateIdentifier.h @@ -49,14 +49,14 @@ public: FlatStateIdentifier(const Arabica::XPath::NodeSet<std::string>& activeStates, const Arabica::XPath::NodeSet<std::string>& alreadyEnteredStates, const std::map<std::string, Arabica::XPath::NodeSet<std::string> >& historyStates) { - for (int i = 0; i < activeStates.size(); i++) { + for (size_t i = 0; i < activeStates.size(); i++) { active.push_back(ATTR_CAST(activeStates[i], "id")); } - for (int i = 0; i < alreadyEnteredStates.size(); i++) { + for (size_t i = 0; i < alreadyEnteredStates.size(); i++) { const Arabica::DOM::NodeList<std::string>& children = alreadyEnteredStates[i].getChildNodes(); bool isRelevant = false; - for (int j = 0; j < children.getLength(); j++) { + for (size_t j = 0; j < children.getLength(); j++) { if (children.item(j).getNodeType() != Arabica::DOM::Node_base::ELEMENT_NODE) continue; if (iequals(LOCALNAME_CAST(children.item(j)), "data") || iequals(LOCALNAME_CAST(children.item(j)), "datamodel")) { @@ -70,7 +70,7 @@ public: std::map<std::string, Arabica::XPath::NodeSet<std::string> >::const_iterator histIter; for (histIter = historyStates.begin(); histIter != historyStates.end(); histIter++) { - for (int i = 0; i < histIter->second.size(); i++) { + for (size_t i = 0; i < histIter->second.size(); i++) { histories[histIter->first].push_back(ATTR_CAST(histIter->second[i], "id")); } } |