From 1bc525a7992f560735bb7e0de6981e8e6f616246 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 8 May 2015 12:58:28 +0200 Subject: Some fixes for transition preemption with flattening --- apps/uscxml-transform.cpp | 19 ++++-- docs/BUILDING.md | 9 ++- src/uscxml/transform/ChartToFSM.cpp | 5 +- src/uscxml/transform/ChartToPromela.cpp | 111 ++++++++++++++++++-------------- 4 files changed, 85 insertions(+), 59 deletions(-) diff --git a/apps/uscxml-transform.cpp b/apps/uscxml-transform.cpp index 1e9c26d..c2c0215 100644 --- a/apps/uscxml-transform.cpp +++ b/apps/uscxml-transform.cpp @@ -74,13 +74,14 @@ void printUsageAndExit(const char* progName) { printf("\t-t min : minimize SCXML state-chart\n"); printf("\t-t tex : write global state transition table as tex file\n"); printf("\t-a {OPTIONS} : annotate SCXML elements with comma seperated options\n"); - printf("\t 'priority' - transitions with their priority for transition selection\n"); - printf("\t 'step' - global states with their step identifier (-tflat only)\n"); - printf("\t 'members' - global transitions with their member transitions per index (-tflat only)\n"); - printf("\t 'sends' - transititve number of sends to external queue for global transitions (-tflat only)\n"); - printf("\t 'raises' - transititve number of raises to internal queue for global transitions (-tflat only)\n"); - printf("\t 'verbose' - comments detailling state changes and transitions for content selection (-tflat only)\n"); - printf("\t 'progress' - insert comments documenting progress in dociment (-tmin only)\n"); + printf("\t 'priority' - transitions with their priority for transition selection\n"); + printf("\t 'step' - global states with their step identifier (-tflat only)\n"); + printf("\t 'members' - global transitions with their member transitions per index (-tflat only)\n"); + printf("\t 'sends' - transititve number of sends to external queue for global transitions (-tflat only)\n"); + printf("\t 'raises' - transititve number of raises to internal queue for global transitions (-tflat only)\n"); + printf("\t 'verbose' - comments detailling state changes and transitions for content selection (-tflat only)\n"); + printf("\t 'progress' - insert comments documenting progress in dociment (-tmin only)\n"); + printf("\t 'nocomment' - surpress the generation of comments in output\n"); printf("\t-v : be verbose\n"); printf("\t-lN : Set loglevel to N\n"); printf("\t-i URL : Input file (defaults to STDIN)\n"); @@ -185,6 +186,10 @@ int main(int argc, char** argv) { if(ANNOTATE("USCXML_ANNOTATE_PROGRESS", "progress")) setenv("USCXML_ANNOTATE_PROGRESS", "YES", 1); + if(ANNOTATE("USCXML_ANNOTATE_NOCOMMENT", "nocomment")) + setenv("USCXML_ANNOTATE_NOCOMMENT", "YES", 1); + + // if (outType.length() == 0 && outputFile.length() > 0) { // // try to get type from outfile extension // size_t dotPos = outputFile.find_last_of("."); diff --git a/docs/BUILDING.md b/docs/BUILDING.md index abc5839..29721b4 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -147,7 +147,14 @@ The following sections will detail the preparation of the respective platforms t You will have to install CMake via Macports: - sudo port install cmake + # required dependencies + $ sudo port install cmake + + # optional dependencies for language bindings + $ sudo port install apache-ant swig-java swig-php swig-csharp + + # other optional dependencies + $ sudo port install lua swi-prolog-devel ffmpeg-devel libical expect libpurple OpenSceneGraph-devel protobuf-cpp The rest is pre-installed or downloaded at configure-time as pre-compiled libraries. Just download the source and invoke CMake to create Makefiles or a Xcode project. diff --git a/src/uscxml/transform/ChartToFSM.cpp b/src/uscxml/transform/ChartToFSM.cpp index 38262db..971ee10 100644 --- a/src/uscxml/transform/ChartToFSM.cpp +++ b/src/uscxml/transform/ChartToFSM.cpp @@ -820,8 +820,11 @@ template bool PtrComp(const T * const & a, const T * const & b) { bool hasUnconditionalSuperset(GlobalTransition* first, GlobalTransition* second) { NodeSet firstTransitions = first->getTransitions(); - NodeSet secondTransitions = first->getTransitions(); + NodeSet secondTransitions = second->getTransitions(); +// if (first->condition.size() > 0) +// return false; + if (isSuperset(second, first)) { for (int i = 0; i < firstTransitions.size(); i++) { if (!InterpreterImpl::isMember(firstTransitions[i], secondTransitions)) { diff --git a/src/uscxml/transform/ChartToPromela.cpp b/src/uscxml/transform/ChartToPromela.cpp index 59f1d75..806c1f4 100644 --- a/src/uscxml/transform/ChartToPromela.cpp +++ b/src/uscxml/transform/ChartToPromela.cpp @@ -181,7 +181,8 @@ void PromelaCodeAnalyzer::addCode(const std::string& code, ChartToPromela* inter std::list::iterator opIter = node->operands.begin(); if ((*opIter)->type != PML_NAME) { node->dump(); - assert(false); + return; + assert(false); } PromelaTypedef* td = &_typeDefs; @@ -803,34 +804,38 @@ void ChartToPromela::writeTransition(std::ostream& stream, GlobalTransition* tra } std::list::const_iterator histIter; - stream << std::endl << _prefix << "t" << transition->index << ": /* ######################## " << std::endl; - FlatStateIdentifier flatActiveSource(transition->source); - stream << " from state: "; - PRETTY_PRINT_LIST(stream, flatActiveSource.getActive()); - stream << std::endl; -// stream << " with history: " << flatActiveSource.getFlatHistory() << std::endl; - stream << " ----- on event: " << (transition->eventDesc.size() > 0 ? transition->eventDesc : "SPONTANEOUS") << " --" << std::endl; - stream << " to state: "; - std::set destinations; - destinations.insert(FlatStateIdentifier(transition->destination)); - histIter = transition->historyTrans.begin(); - while(histIter != transition->historyTrans.end()) { - destinations.insert(FlatStateIdentifier((*histIter)->destination)); - histIter++; - } - - std::string seperator = ""; - for (std::set::iterator destIter = destinations.begin(); destIter != destinations.end(); destIter++) { - stream << seperator; - PRETTY_PRINT_LIST(stream, destIter->getActive()); - stream << " with " << (destIter->getFlatHistory().size() > 0 ? destIter->getFlatHistory() : "no history"); - seperator = "\n "; - } - stream << std::endl; - - stream << "############################### */" << std::endl; - stream << std::endl; - + if (envVarIsTrue("USCXML_ANNOTATE_NOCOMMENT")) { + stream << std::endl << _prefix << "t" << transition->index << ": /* ######################## */ " << std::endl; + + } else { + + stream << std::endl << _prefix << "t" << transition->index << ": /* ######################## " << std::endl; + FlatStateIdentifier flatActiveSource(transition->source); + stream << " from state: "; + PRETTY_PRINT_LIST(stream, flatActiveSource.getActive()); + stream << std::endl; + // stream << " with history: " << flatActiveSource.getFlatHistory() << std::endl; + stream << " ----- on event: " << (transition->eventDesc.size() > 0 ? transition->eventDesc : "SPONTANEOUS") << " --" << std::endl; + stream << " to state: "; + std::set destinations; + destinations.insert(FlatStateIdentifier(transition->destination)); + histIter = transition->historyTrans.begin(); + while(histIter != transition->historyTrans.end()) { + destinations.insert(FlatStateIdentifier((*histIter)->destination)); + histIter++; + } + std::string seperator = ""; + for (std::set::iterator destIter = destinations.begin(); destIter != destinations.end(); destIter++) { + stream << seperator; + PRETTY_PRINT_LIST(stream, destIter->getActive()); + stream << " with " << (destIter->getFlatHistory().size() > 0 ? destIter->getFlatHistory() : "no history"); + seperator = "\n "; + } + stream << std::endl; + + stream << "############################### */" << std::endl; + } + stream << std::endl; stream << padding << "skip;" << std::endl; stream << padding << "d_step {" << std::endl; if (_writeTransitionPrintfs) @@ -1104,12 +1109,14 @@ void ChartToPromela::writeTransition(std::ostream& stream, GlobalTransition* tra continue; stream << padding << "if" << std::endl; - stream << "/* to state "; - FlatStateIdentifier flatActiveDest(histNewState->activeId); - PRETTY_PRINT_LIST(stream, flatActiveDest.getActive()); - stream << " via history */" << std::endl; + if (!envVarIsTrue("USCXML_ANNOTATE_NOCOMMENT")) { + stream << "/* to state "; + FlatStateIdentifier flatActiveDest(histNewState->activeId); + PRETTY_PRINT_LIST(stream, flatActiveDest.getActive()); + stream << " via history */" << std::endl; + } - stream << padding << ":: " << conditionalizeForHist(histTargetIter->second) << " -> " << _prefix << "s = s" << histNewState->activeIndex << ";" << std::endl; + stream << padding << ":: " << conditionalizeForHist(histTargetIter->second) << " -> " << _prefix << "s = s" << histNewState->activeIndex << ";" << std::endl; // writeTransitionClosure(stream, *histTargetIter->second.begin(), histNewState, indent + 1); // is this correct for everyone in set? @@ -1120,10 +1127,11 @@ void ChartToPromela::writeTransition(std::ostream& stream, GlobalTransition* tra FlatStateIdentifier flatActiveDest(transition->activeDestination); assert(origNewState != NULL); - stream << "/* to state "; - PRETTY_PRINT_LIST(stream, flatActiveDest.getActive()); - stream << " */" << std::endl; - + if (!envVarIsTrue("USCXML_ANNOTATE_NOCOMMENT")) { + stream << "/* to state "; + PRETTY_PRINT_LIST(stream, flatActiveDest.getActive()); + stream << " */" << std::endl; + } if (hasHistoryTarget) { stream << padding << ":: else -> "; padding += " "; @@ -1948,7 +1956,7 @@ void ChartToPromela::writeDeclarations(std::ostream& stream) { if (_prefix.size() == 0 || _prefix == "MAIN_") { if (_analyzer->usesEventField("sendid")) { - stream << "chan sendIdQ = [" << MAX(_externalQueueLength + 1, 1) << "] of {_event_t} /* temporary queue to cancel events per sendidexpr */" << std::endl; +// stream << "chan sendIdQ = [" << MAX(_externalQueueLength + 1, 1) << "] of {_event_t} /* temporary queue to cancel events per sendidexpr */" << std::endl; stream << "hidden int _lastSendId = 0; /* sequential counter for send ids */" << std::endl; } @@ -2243,7 +2251,7 @@ void ChartToPromela::writeFSM(std::ostream& stream) { if (eventNames.size() > 0) { stream << " if " << std::endl; for (std::set::iterator evIter = eventNames.begin(); evIter != eventNames.end(); evIter++) { - stream << " :: true -> { " << _prefix << "_event.name = " << _analyzer->macroForLiteral(*evIter) << " }" << std::endl; + stream << " :: true -> { " << _prefix << "_event" << (_analyzer->usesComplexEventStruct() ? ".name" : "")<< " = " << _analyzer->macroForLiteral(*evIter) << " }" << std::endl; } stream << " fi " << std::endl; } @@ -2671,11 +2679,13 @@ void ChartToPromela::writeDispatchingBlock(std::ostream& stream, std::listhasExecutableContent || currTrans->historyTrans.size() > 0) { stream << " -> { " << std::endl; - stream << "/* transition to "; - FlatStateIdentifier flatActiveSource(currTrans->activeDestination); - PRETTY_PRINT_LIST(stream, flatActiveSource.getActive()); - stream << " */" << std::endl; - + if (!envVarIsTrue("USCXML_ANNOTATE_NOCOMMENT")) { + stream << "/* transition to "; + FlatStateIdentifier flatActiveSource(currTrans->activeDestination); + PRETTY_PRINT_LIST(stream, flatActiveSource.getActive()); + stream << " */" << std::endl; + } + if (_traceTransitions) { for (std::set::iterator transRefIter = currTrans->transitionRefs.begin(); transRefIter != currTrans->transitionRefs.end(); transRefIter++) { stream << padding << " " << _prefix << "transitions[" << *transRefIter << "] = true; " << std::endl; @@ -2691,11 +2701,12 @@ void ChartToPromela::writeDispatchingBlock(std::ostream& stream, std::listactiveDestination]; assert(newState != NULL); - stream << "/* new state "; - FlatStateIdentifier flatActiveDest(currTrans->activeDestination); - PRETTY_PRINT_LIST(stream, flatActiveDest.getActive()); - stream << " */" << std::endl; - + if (!envVarIsTrue("USCXML_ANNOTATE_NOCOMMENT")) { + stream << "/* new state "; + FlatStateIdentifier flatActiveDest(currTrans->activeDestination); + PRETTY_PRINT_LIST(stream, flatActiveDest.getActive()); + stream << " */" << std::endl; + } stream << padding << " " << _prefix << "s = s" << newState->activeIndex << ";" << std::endl; writeTransitionClosure(stream, currTrans, newState, indent + 1); -- cgit v0.12