From aa341b878e6d4a2be8890ca5f890e46b87cf2d7d Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Wed, 19 Jul 2017 16:41:34 +0200 Subject: Beautified code --- src/apps/uscxml-browser.cpp | 124 ++--- src/apps/uscxml-transform.cpp | 102 ++-- src/uscxml/Interpreter.cpp | 2 +- src/uscxml/Interpreter.h | 6 +- src/uscxml/interpreter/BasicContentExecutor.cpp | 160 +++--- src/uscxml/interpreter/ContentExecutorImpl.h | 2 +- src/uscxml/interpreter/FastMicroStep.cpp | 150 +++--- src/uscxml/interpreter/InterpreterImpl.cpp | 14 +- src/uscxml/interpreter/InterpreterImpl.h | 16 +- src/uscxml/interpreter/InterpreterMonitor.h | 574 ++++++++++----------- src/uscxml/plugins/DataModel.cpp | 2 +- src/uscxml/plugins/DataModel.h | 4 +- src/uscxml/plugins/DataModelImpl.h | 22 +- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 4 +- .../ecmascript/JavaScriptCore/JSCDataModel.h | 2 +- src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 58 +-- src/uscxml/plugins/datamodel/lua/LuaDataModel.h | 2 +- .../plugins/datamodel/promela/PromelaDataModel.cpp | 4 +- test/src/test-snippets.cpp | 28 +- 19 files changed, 638 insertions(+), 638 deletions(-) diff --git a/src/apps/uscxml-browser.cpp b/src/apps/uscxml-browser.cpp index dd0633b..bda1efe 100644 --- a/src/apps/uscxml-browser.cpp +++ b/src/apps/uscxml-browser.cpp @@ -25,32 +25,32 @@ int main(int argc, char** argv) { InterpreterOptions::printUsageAndExit(argv[0]); } - if (!options.validate) { - // setup HTTP server - HTTPServer::SSLConfig* sslConf = NULL; - if (options.certificate.length() > 0) { - sslConf = new HTTPServer::SSLConfig(); - sslConf->privateKey = options.certificate; - sslConf->publicKey = options.certificate; - sslConf->port = options.httpsPort; - - } else if (options.privateKey.length() > 0 && options.publicKey.length() > 0) { - sslConf = new HTTPServer::SSLConfig(); - sslConf->privateKey = options.privateKey; - sslConf->publicKey = options.publicKey; - sslConf->port = options.httpsPort; - - } - HTTPServer::getInstance(options.httpPort, options.wsPort, sslConf); - } - - if (options.pluginPath.length() > 0) { - Factory::setDefaultPluginPath(options.pluginPath); - } - - if (options.verbose) { - Factory::getInstance()->listComponents(); - } + if (!options.validate) { + // setup HTTP server + HTTPServer::SSLConfig* sslConf = NULL; + if (options.certificate.length() > 0) { + sslConf = new HTTPServer::SSLConfig(); + sslConf->privateKey = options.certificate; + sslConf->publicKey = options.certificate; + sslConf->port = options.httpsPort; + + } else if (options.privateKey.length() > 0 && options.publicKey.length() > 0) { + sslConf = new HTTPServer::SSLConfig(); + sslConf->privateKey = options.privateKey; + sslConf->publicKey = options.publicKey; + sslConf->port = options.httpsPort; + + } + HTTPServer::getInstance(options.httpPort, options.wsPort, sslConf); + } + + if (options.pluginPath.length() > 0) { + Factory::setDefaultPluginPath(options.pluginPath); + } + + if (options.verbose) { + Factory::getInstance()->listComponents(); + } // instantiate and configure interpreters std::list interpreters; @@ -73,7 +73,7 @@ int main(int argc, char** argv) { if (issues.size() == 0) { LOGD(USCXML_DEBUG) << "No issues found" << std::endl; } - + } if (options.verbose) { @@ -92,41 +92,41 @@ int main(int argc, char** argv) { } } - if (options.validate) { - return EXIT_SUCCESS; - } - - if (options.withDebugger) { - DebuggerServlet* debugger; - debugger = new DebuggerServlet(); - debugger->copyToInvokers(true); - HTTPServer::getInstance()->registerServlet("/debug", debugger); - for (auto interpreter : interpreters) { - interpreter.addMonitor(debugger); - } - } - + if (options.validate) { + return EXIT_SUCCESS; + } + + if (options.withDebugger) { + DebuggerServlet* debugger; + debugger = new DebuggerServlet(); + debugger->copyToInvokers(true); + HTTPServer::getInstance()->registerServlet("/debug", debugger); + for (auto interpreter : interpreters) { + interpreter.addMonitor(debugger); + } + } + // run interpreters - if (interpreters.size() > 0) { - try { - std::list::iterator interpreterIter = interpreters.begin(); - while (interpreters.size() > 0) { - while(interpreterIter != interpreters.end()) { - InterpreterState state = interpreterIter->step(); - if (state == USCXML_FINISHED) { - interpreterIter = interpreters.erase(interpreterIter); - } else { - interpreterIter++; - } - } - interpreterIter = interpreters.begin(); - } - } catch (Event e) { - LOGD(USCXML_ERROR) << e << std::endl; - } - } else if (options.withDebugger) { - while(true) - std::this_thread::sleep_for(std::chrono::seconds(1)); - } + if (interpreters.size() > 0) { + try { + std::list::iterator interpreterIter = interpreters.begin(); + while (interpreters.size() > 0) { + while(interpreterIter != interpreters.end()) { + InterpreterState state = interpreterIter->step(); + if (state == USCXML_FINISHED) { + interpreterIter = interpreters.erase(interpreterIter); + } else { + interpreterIter++; + } + } + interpreterIter = interpreters.begin(); + } + } catch (Event e) { + LOGD(USCXML_ERROR) << e << std::endl; + } + } else if (options.withDebugger) { + while(true) + std::this_thread::sleep_for(std::chrono::seconds(1)); + } return EXIT_SUCCESS; } diff --git a/src/apps/uscxml-transform.cpp b/src/apps/uscxml-transform.cpp index e99ed68..572fb27 100644 --- a/src/apps/uscxml-transform.cpp +++ b/src/apps/uscxml-transform.cpp @@ -40,8 +40,8 @@ void printUsageAndExit(const char* progName) { printf("Options\n"); printf("\t-t c : convert to C program\n"); printf("\t-t pml : convert to spin/promela program\n"); - printf("\t-t vhdl : convert to VHDL hardware description\n"); - printf("\t-t java : convert to Java classes\n"); + printf("\t-t vhdl : convert to VHDL hardware description\n"); + printf("\t-t java : convert to Java classes\n"); printf("\t-t flat : flatten to SCXML state-machine\n"); printf("\t-a FILE : write annotated SCXML document for transformation\n"); printf("\t-X {PARAMETER} : pass additional parameters to the transformation\n"); @@ -60,8 +60,8 @@ int main(int argc, char** argv) { bool verbose = false; std::string outType; std::string pluginPath; - std::string inputFile; - std::string annotatedFile; + std::string inputFile; + std::string annotatedFile; std::string outputFile; std::list options; std::multimap extensions; @@ -112,7 +112,7 @@ int main(int argc, char** argv) { inputFile = optarg; break; case 'a': - annotatedFile = optarg; + annotatedFile = optarg; break; case 'X': { std::list extension = tokenize(optarg, '='); @@ -125,7 +125,7 @@ int main(int argc, char** argv) { break; case 'o': outputFile = optarg; - extensions.insert(std::pair("outputFile", outputFile)); + extensions.insert(std::pair("outputFile", outputFile)); break; case 'l': break; @@ -190,8 +190,8 @@ int main(int argc, char** argv) { outType != "scxml" && outType != "pml" && outType != "c" && - outType != "vhdl" && - outType != "java" && + outType != "vhdl" && + outType != "java" && outType != "min" && std::find(options.begin(), options.end(), "priority") == options.end() && std::find(options.begin(), options.end(), "domain") == options.end() && @@ -218,7 +218,7 @@ int main(int argc, char** argv) { ss << line; } URL tmp("anonymous.scxml"); - tmp = URL::resolveWithCWD(tmp); + tmp = URL::resolveWithCWD(tmp); interpreter = Interpreter::fromXML(ss.str(), tmp); } else { interpreter = Interpreter::fromURL(inputFile); @@ -231,8 +231,8 @@ int main(int argc, char** argv) { if (!interpreter) { URL tmp(inputFile); - tmp = URL::resolveWithCWD(tmp); - std::string content = tmp.getInContent(); + tmp = URL::resolveWithCWD(tmp); + std::string content = tmp.getInContent(); std::string inlineBeginMarker = "INLINE SCXML BEGIN\n"; std::string inlineEndMarker = "\nINLINE SCXML END"; @@ -267,12 +267,12 @@ int main(int argc, char** argv) { } } - Transformer transformer; + Transformer transformer; if (outType == "c") { transformer = ChartToC::transform(interpreter); transformer.setExtensions(extensions); transformer.setOptions(options); - + if (outputFile.size() == 0 || outputFile == "-") { transformer.writeTo(std::cout); } else { @@ -283,25 +283,25 @@ int main(int argc, char** argv) { } } - if (outType == "java") { - transformer = ChartToJava::transform(interpreter); - transformer.setExtensions(extensions); - transformer.setOptions(options); - - if (outputFile.size() == 0 || outputFile == "-") { - transformer.writeTo(std::cout); - } else { - std::ofstream outStream; - outStream.open(outputFile.c_str()); - transformer.writeTo(outStream); - outStream.close(); - } - } + if (outType == "java") { + transformer = ChartToJava::transform(interpreter); + transformer.setExtensions(extensions); + transformer.setOptions(options); + + if (outputFile.size() == 0 || outputFile == "-") { + transformer.writeTo(std::cout); + } else { + std::ofstream outStream; + outStream.open(outputFile.c_str()); + transformer.writeTo(outStream); + outStream.close(); + } + } if (outType == "vhdl") { - transformer = ChartToVHDL::transform(interpreter); - transformer.setExtensions(extensions); - transformer.setOptions(options); + transformer = ChartToVHDL::transform(interpreter); + transformer.setExtensions(extensions); + transformer.setOptions(options); if (outputFile.size() == 0 || outputFile == "-") { transformer.writeTo(std::cout); @@ -314,18 +314,18 @@ int main(int argc, char** argv) { } if (outType == "pml") { - transformer = ChartToPromela::transform(interpreter); - transformer.setExtensions(extensions); - transformer.setOptions(options); - - if (outputFile.size() == 0 || outputFile == "-") { - transformer.writeTo(std::cout); - } else { - std::ofstream outStream; - outStream.open(outputFile.c_str()); - transformer.writeTo(outStream); - outStream.close(); - } + transformer = ChartToPromela::transform(interpreter); + transformer.setExtensions(extensions); + transformer.setOptions(options); + + if (outputFile.size() == 0 || outputFile == "-") { + transformer.writeTo(std::cout); + } else { + std::ofstream outStream; + outStream.open(outputFile.c_str()); + transformer.writeTo(outStream); + outStream.close(); + } } // if (outType == "tex") { @@ -364,22 +364,22 @@ int main(int argc, char** argv) { // exit(EXIT_SUCCESS); // } - if (annotatedFile.size() > 0) { - std::ofstream outStream; - outStream.open(annotatedFile.c_str()); - outStream << (*transformer.getImpl()->getDocument()); - outStream.close(); + if (annotatedFile.size() > 0) { + std::ofstream outStream; + outStream.open(annotatedFile.c_str()); + outStream << (*transformer.getImpl()->getDocument()); + outStream.close(); - } + } } catch (Event e) { std::cout << e << std::endl; - return EXIT_FAILURE; + return EXIT_FAILURE; } catch (const std::exception &e) { std::cout << e.what() << std::endl; - return EXIT_FAILURE; + return EXIT_FAILURE; } - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index f3aedee..6146546 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -272,7 +272,7 @@ std::list Interpreter::validate() { } LambdaMonitor& Interpreter::on() { - return _impl->on(); + return _impl->on(); } #if 1 diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index aff77a2..7cf8a0e 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -236,9 +236,9 @@ public: std::shared_ptr getImpl() const { return _impl; } - - LambdaMonitor& on(); - + + LambdaMonitor& on(); + #if 0 // "Ambiguous user-defined-conversion" with operator bool() on MSVC from Visual Studio 12 explicit operator MicroStepCallbacks*() { diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 9ea2b6a..87c2180 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -593,89 +593,89 @@ void BasicContentExecutor::processParams(std::multimap& param paramMap.insert(make_pair(name, d)); } } - + Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element, bool asExpression) { - // element with expr - if (HAS_ATTR(element, kXMLCharExpr)) { - std::string expr = ATTR(element, kXMLCharExpr); - if (_callbacks->isLegalDataValue(expr)) { - return Data(expr, Data::INTERPRETED); - } else { - ERROR_EXECUTION_THROW2("Expression '" + expr + "' is not a legal data value", element); - } - } - - // element with external src - this ought to behave just as with child nodes below - if (HAS_ATTR(element, kXMLCharSource)) { - - // remove any old child elements - while(element->getFirstElementChild() != NULL) { - element->removeChild(element->getFirstElementChild()); - } - - std::string src = ATTR(element, kXMLCharSource); - URL url(ATTR(element, kXMLCharSource)); - if (!url.isAbsolute()) { - url = URL::resolve(url, _callbacks->getBaseURL()); - } - std::string content = url.getInContent(); - - // append as XML? - try { - std::unique_ptr parser(new XERCESC_NS::XercesDOMParser()); - parser->setValidationScheme(XERCESC_NS::XercesDOMParser::Val_Always); - parser->setDoNamespaces(true); - parser->useScanner(XERCESC_NS::XMLUni::fgWFXMLScanner); - - std::unique_ptr errHandler(new XERCESC_NS::HandlerBase()); - parser->setErrorHandler(errHandler.get()); - - XERCESC_NS::MemBufInputSource is((XMLByte*)content.c_str(), content.size(), X("fake")); - is.setPublicId(X(url)); - - parser->parse(is); - XERCESC_NS::DOMNode* newNode = element->getOwnerDocument()->importNode(parser->getDocument()->getDocumentElement(), true); - - // we need to save the DOM somewhere .. Data::adoptedDoc was not good enough - element->appendChild(newNode); - goto SOURCE_APPEND_DONE; - } catch (...) { - } - - // append as text (are we leaking?) - XERCESC_NS::DOMText* textNode = element->getOwnerDocument()->createTextNode(X(content)); - element->appendChild(textNode); - } + // element with expr + if (HAS_ATTR(element, kXMLCharExpr)) { + std::string expr = ATTR(element, kXMLCharExpr); + if (_callbacks->isLegalDataValue(expr)) { + return Data(expr, Data::INTERPRETED); + } else { + ERROR_EXECUTION_THROW2("Expression '" + expr + "' is not a legal data value", element); + } + } + + // element with external src - this ought to behave just as with child nodes below + if (HAS_ATTR(element, kXMLCharSource)) { + + // remove any old child elements + while(element->getFirstElementChild() != NULL) { + element->removeChild(element->getFirstElementChild()); + } + + std::string src = ATTR(element, kXMLCharSource); + URL url(ATTR(element, kXMLCharSource)); + if (!url.isAbsolute()) { + url = URL::resolve(url, _callbacks->getBaseURL()); + } + std::string content = url.getInContent(); + + // append as XML? + try { + std::unique_ptr parser(new XERCESC_NS::XercesDOMParser()); + parser->setValidationScheme(XERCESC_NS::XercesDOMParser::Val_Always); + parser->setDoNamespaces(true); + parser->useScanner(XERCESC_NS::XMLUni::fgWFXMLScanner); + + std::unique_ptr errHandler(new XERCESC_NS::HandlerBase()); + parser->setErrorHandler(errHandler.get()); + + XERCESC_NS::MemBufInputSource is((XMLByte*)content.c_str(), content.size(), X("fake")); + is.setPublicId(X(url)); + + parser->parse(is); + XERCESC_NS::DOMNode* newNode = element->getOwnerDocument()->importNode(parser->getDocument()->getDocumentElement(), true); + + // we need to save the DOM somewhere .. Data::adoptedDoc was not good enough + element->appendChild(newNode); + goto SOURCE_APPEND_DONE; + } catch (...) { + } + + // append as text (are we leaking?) + XERCESC_NS::DOMText* textNode = element->getOwnerDocument()->createTextNode(X(content)); + element->appendChild(textNode); + } SOURCE_APPEND_DONE: - if (element->hasChildNodes()) { - // XML elements e.g. for content with invoke - std::list elementChildren = DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, element); - if (elementChildren.size() > 0) { - // always return parent element, even with a single child node - return Data(static_cast(element)); - } - - // expression in text element - std::list textChildren = DOMUtils::filterChildType(DOMNode::TEXT_NODE, element); - if (textChildren.size() > 0) { - std::stringstream contentSS; - for (auto textIter = textChildren.begin(); textIter != textChildren.end(); textIter++) { - contentSS << X((*textIter)->getNodeValue()); - } - - try { - Data d = _callbacks->getAsData(contentSS.str()); - if (!d.empty()) - return d; - } catch(...) {} - - // anything else is considered verbatim - space normalize? - return Data(spaceNormalize(contentSS.str()), Data::VERBATIM); - } - } - - return Data(); + if (element->hasChildNodes()) { + // XML elements e.g. for content with invoke + std::list elementChildren = DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, element); + if (elementChildren.size() > 0) { + // always return parent element, even with a single child node + return Data(static_cast(element)); + } + + // expression in text element + std::list textChildren = DOMUtils::filterChildType(DOMNode::TEXT_NODE, element); + if (textChildren.size() > 0) { + std::stringstream contentSS; + for (auto textIter = textChildren.begin(); textIter != textChildren.end(); textIter++) { + contentSS << X((*textIter)->getNodeValue()); + } + + try { + Data d = _callbacks->getAsData(contentSS.str()); + if (!d.empty()) + return d; + } catch(...) {} + + // anything else is considered verbatim - space normalize? + return Data(spaceNormalize(contentSS.str()), Data::VERBATIM); + } + } + + return Data(); } } diff --git a/src/uscxml/interpreter/ContentExecutorImpl.h b/src/uscxml/interpreter/ContentExecutorImpl.h index 0c080ca..8221591 100644 --- a/src/uscxml/interpreter/ContentExecutorImpl.h +++ b/src/uscxml/interpreter/ContentExecutorImpl.h @@ -62,7 +62,7 @@ public: virtual Data evalAsData(const std::string& expr) = 0; virtual void eval(const std::string& expr) = 0; virtual Data getAsData(const std::string& expr) = 0; - virtual bool isLegalDataValue(const std::string& expr) = 0; + virtual bool isLegalDataValue(const std::string& expr) = 0; virtual void assign(const std::string& location, const Data& data, const std::map& attrs) = 0; diff --git a/src/uscxml/interpreter/FastMicroStep.cpp b/src/uscxml/interpreter/FastMicroStep.cpp index 1258279..78aada9 100644 --- a/src/uscxml/interpreter/FastMicroStep.cpp +++ b/src/uscxml/interpreter/FastMicroStep.cpp @@ -511,7 +511,7 @@ COMPLETION_STABLISHED: // std::list transSpontaneous; // std::list transEventful; - + for (i = 0; i < _transitions.size(); i++) { _transitions[i] = new Transition(i); _transitions[i]->element = tmp.front(); @@ -583,9 +583,9 @@ TARGET_SET_ESTABLISHED: if (!HAS_ATTR(_transitions[i]->element, kXMLCharEvent)) { _transitions[i]->type |= USCXML_TRANS_SPONTANEOUS; // transSpontaneous.push_back(_transitions[i]); - } else { + } else { // transEventful.push_back(_transitions[i]); - } + } if (iequals(TAGNAME_CAST(_transitions[i]->element->getParentNode()), _xmlPrefix.str() + "history")) { _transitions[i]->type |= USCXML_TRANS_HISTORY; @@ -618,81 +618,81 @@ TARGET_SET_ESTABLISHED: * This bound by cache locality! * Before you change anything, do benchmark! */ - + #if 0 #define exit1 _exitSets[t1->postFixOrder] #define exit2 _exitSets[t2->postFixOrder] - for (size_t set = 0; set < 2; set++) { - std::list::const_iterator transBegin; - std::list::const_iterator transEnd; - if (set == 0) { - transBegin = transEventful.begin(); - transEnd = transEventful.end(); - } else { - transBegin = transSpontaneous.begin(); - transEnd = transSpontaneous.end(); - } - - for (auto t1Iter = transBegin; t1Iter != transEnd; t1Iter++) { - Transition* t1 = *t1Iter; - auto anc1 = _states[t1->source]->ancestors; - const uint32_t source1 = t1->source; - - for (auto t2Iter = t1Iter; t2Iter != transEnd; t2Iter++) { - Transition* t2 = *t2Iter; - - if (exit1.first == 0 && exit2.first == 0) { - goto COMPATIBLE_TRANS; - } - - if (exit1.first <= exit2.first && exit1.second >= exit2.first) { - goto CONFLICTING_TRANS; - } - - if (exit2.first <= exit1.first && exit2.second >= exit1.first) { - goto CONFLICTING_TRANS; - } - - COMPATIBLE_TRANS: - if (t2->source == source1) { - goto CONFLICTING_TRANS; - } - - if (anc1[t2->source]) { - goto CONFLICTING_TRANS; - } - - if (_states[t2->source]->ancestors[source1]) { - goto CONFLICTING_TRANS; - } - - t1->conflicts[t2->postFixOrder] = false; - // _transitions[j]->conflicts[i] = false; - continue; - - CONFLICTING_TRANS: - t1->conflicts[t2->postFixOrder] = true; - // _transitions[j]->conflicts[i] = true; - - continue; - - } - } - - for (auto t1Iter = transBegin; t1Iter != transEnd; t1Iter++) { - Transition* t1 = *t1Iter; - // conflicts matrix is symmetric - for (auto t2Iter = transBegin; t2Iter != t1Iter; t2Iter++) { - Transition* t2 = *t2Iter; - - t1->conflicts[t2->postFixOrder] = t2->conflicts[t1->postFixOrder]; - } - } - - } - - + for (size_t set = 0; set < 2; set++) { + std::list::const_iterator transBegin; + std::list::const_iterator transEnd; + if (set == 0) { + transBegin = transEventful.begin(); + transEnd = transEventful.end(); + } else { + transBegin = transSpontaneous.begin(); + transEnd = transSpontaneous.end(); + } + + for (auto t1Iter = transBegin; t1Iter != transEnd; t1Iter++) { + Transition* t1 = *t1Iter; + auto anc1 = _states[t1->source]->ancestors; + const uint32_t source1 = t1->source; + + for (auto t2Iter = t1Iter; t2Iter != transEnd; t2Iter++) { + Transition* t2 = *t2Iter; + + if (exit1.first == 0 && exit2.first == 0) { + goto COMPATIBLE_TRANS; + } + + if (exit1.first <= exit2.first && exit1.second >= exit2.first) { + goto CONFLICTING_TRANS; + } + + if (exit2.first <= exit1.first && exit2.second >= exit1.first) { + goto CONFLICTING_TRANS; + } + +COMPATIBLE_TRANS: + if (t2->source == source1) { + goto CONFLICTING_TRANS; + } + + if (anc1[t2->source]) { + goto CONFLICTING_TRANS; + } + + if (_states[t2->source]->ancestors[source1]) { + goto CONFLICTING_TRANS; + } + + t1->conflicts[t2->postFixOrder] = false; + // _transitions[j]->conflicts[i] = false; + continue; + +CONFLICTING_TRANS: + t1->conflicts[t2->postFixOrder] = true; + // _transitions[j]->conflicts[i] = true; + + continue; + + } + } + + for (auto t1Iter = transBegin; t1Iter != transEnd; t1Iter++) { + Transition* t1 = *t1Iter; + // conflicts matrix is symmetric + for (auto t2Iter = transBegin; t2Iter != t1Iter; t2Iter++) { + Transition* t2 = *t2Iter; + + t1->conflicts[t2->postFixOrder] = t2->conflicts[t1->postFixOrder]; + } + } + + } + + #else #define anc1 _states[_transitions[i]->source]->ancestors #define exit1 _exitSets[i] @@ -748,7 +748,7 @@ CONFLICTING_TRANS: } } #endif - + // initialize bitarrays for step() _exitSet = boost::dynamic_bitset(_states.size(), false); _entrySet = boost::dynamic_bitset(_states.size(), false); diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index 1caa3f0..185ad75 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -103,8 +103,8 @@ InterpreterImpl::~InterpreterImpl() { if (_document) delete _document; - if (_lambdaMonitor) - delete _lambdaMonitor; + if (_lambdaMonitor) + delete _lambdaMonitor; { std::lock_guard lock(_instanceMutex); @@ -626,11 +626,11 @@ void InterpreterImpl::enqueueAtParent(const Event& event) { } LambdaMonitor& InterpreterImpl::on() { - if (_lambdaMonitor == NULL) { - _lambdaMonitor = new LambdaMonitor(); - addMonitor(_lambdaMonitor); - } - return *_lambdaMonitor; + if (_lambdaMonitor == NULL) { + _lambdaMonitor = new LambdaMonitor(); + addMonitor(_lambdaMonitor); + } + return *_lambdaMonitor; } } diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h index 1f87fd2..cb31988 100644 --- a/src/uscxml/interpreter/InterpreterImpl.h +++ b/src/uscxml/interpreter/InterpreterImpl.h @@ -196,9 +196,9 @@ public: return _dataModel.getAsData(expr); } - virtual bool isLegalDataValue(const std::string& expr) { - return _dataModel.isLegalDataValue(expr); - } + virtual bool isLegalDataValue(const std::string& expr) { + return _dataModel.isLegalDataValue(expr); + } virtual void assign(const std::string& location, const Data& data, const std::map& attrs); @@ -273,13 +273,13 @@ public: return _document; } - LambdaMonitor& on(); - + LambdaMonitor& on(); + protected: static void addInstance(std::shared_ptr instance); - - LambdaMonitor* _lambdaMonitor = NULL; - + + LambdaMonitor* _lambdaMonitor = NULL; + Binding _binding; ActionLanguage _al; diff --git a/src/uscxml/interpreter/InterpreterMonitor.h b/src/uscxml/interpreter/InterpreterMonitor.h index ed62675..64c281c 100644 --- a/src/uscxml/interpreter/InterpreterMonitor.h +++ b/src/uscxml/interpreter/InterpreterMonitor.h @@ -66,46 +66,46 @@ public: virtual ~InterpreterMonitor() {} virtual void beforeProcessingEvent(const std::string& sessionId, - const Event& event) {} + const Event& event) {} virtual void beforeMicroStep(const std::string& sessionId) {} virtual void beforeExitingState(const std::string& sessionId, - const std::string& stateName, - const XERCESC_NS::DOMElement* state) {} + const std::string& stateName, + const XERCESC_NS::DOMElement* state) {} virtual void afterExitingState(const std::string& sessionId, - const std::string& stateName, - const XERCESC_NS::DOMElement* state) {} + const std::string& stateName, + const XERCESC_NS::DOMElement* state) {} virtual void beforeExecutingContent(const std::string& sessionId, - const XERCESC_NS::DOMElement* execContent) {} + const XERCESC_NS::DOMElement* execContent) {} virtual void afterExecutingContent(const std::string& sessionId, - const XERCESC_NS::DOMElement* execContent) {} + const XERCESC_NS::DOMElement* execContent) {} virtual void beforeUninvoking(const std::string& sessionId, - const XERCESC_NS::DOMElement* invokeElem, - const std::string& invokeid) {} + const XERCESC_NS::DOMElement* invokeElem, + const std::string& invokeid) {} virtual void afterUninvoking(const std::string& sessionId, - const XERCESC_NS::DOMElement* invokeElem, - const std::string& invokeid) {} + const XERCESC_NS::DOMElement* invokeElem, + const std::string& invokeid) {} virtual void beforeTakingTransition(const std::string& sessionId, - const XERCESC_NS::DOMElement* transition) {} + const XERCESC_NS::DOMElement* transition) {} virtual void afterTakingTransition(const std::string& sessionId, - const XERCESC_NS::DOMElement* transition) {} + const XERCESC_NS::DOMElement* transition) {} virtual void beforeEnteringState(const std::string& sessionId, - const std::string& stateName, - const XERCESC_NS::DOMElement* state) {} + const std::string& stateName, + const XERCESC_NS::DOMElement* state) {} virtual void afterEnteringState(const std::string& sessionId, - const std::string& stateName, - const XERCESC_NS::DOMElement* state) {} + const std::string& stateName, + const XERCESC_NS::DOMElement* state) {} virtual void beforeInvoking(const std::string& sessionId, - const XERCESC_NS::DOMElement* invokeElem, - const std::string& invokeid) {} + const XERCESC_NS::DOMElement* invokeElem, + const std::string& invokeid) {} virtual void afterInvoking(const std::string& sessionId, - const XERCESC_NS::DOMElement* invokeElem, - const std::string& invokeid) {} + const XERCESC_NS::DOMElement* invokeElem, + const std::string& invokeid) {} virtual void afterMicroStep(const std::string& sessionId) {} virtual void onStableConfiguration(const std::string& sessionId) {} @@ -114,7 +114,7 @@ public: virtual void afterCompletion(const std::string& sessionId) {} virtual void reportIssue(const std::string& sessionId, - const InterpreterIssue& issue) {} + const InterpreterIssue& issue) {} void copyToInvokers(bool copy) { _copyToInvokers = copy; @@ -149,273 +149,273 @@ protected: class USCXML_API LambdaMonitor : public InterpreterMonitor { public: - void processEvent(std::function callback) { - _beforeProcessingEvent = callback; - } - - - void microStep(std::function callback, - bool after = false) { - if (after) { - _afterMicroStep = callback; - } else { - _beforeMicroStep = callback; - } - - } - - void exitState(std::function callback, - bool after = false) { - if (after) { - _afterExitingState = callback; - } else { - _beforeExitingState = callback; - } - } - - void executeContent(std::function callback, - bool after = false) { - if (after) { - _afterExecutingContent = callback; - } else { - _beforeExecutingContent = callback; - } - } - - void uninvoke(std::function callback, - bool after = false) { - if (after) { - _afterUninvoking = callback; - } else { - _beforeUninvoking = callback; - } - } - - void transition(std::function callback, - bool after = false) { - if (after) { - _afterTakingTransition = callback; - } else { - _beforeTakingTransition = callback; - } - } - - void enterState(std::function callback, - bool after = false) { - _beforeEnteringState = callback; - if (after) { - _afterEnteringState = callback; - } else { - _beforeEnteringState = callback; - } - - } - - void invoke(std::function callback, - bool after = false) { - if (after) { - _afterInvoking = callback; - } else { - _beforeInvoking = callback; - } - } - - void stableConfiguration(std::function callback) { - _onStableConfiguration = callback; - } - - void completion(std::function callback, - bool after = false) { - if (after) { - _afterCompletion = callback; - } else { - _beforeCompletion = callback; - } - - } - - void reportIssue(std::function callback) { - _reportIssue = callback; - } + void processEvent(std::function callback) { + _beforeProcessingEvent = callback; + } + + + void microStep(std::function callback, + bool after = false) { + if (after) { + _afterMicroStep = callback; + } else { + _beforeMicroStep = callback; + } + + } + + void exitState(std::function callback, + bool after = false) { + if (after) { + _afterExitingState = callback; + } else { + _beforeExitingState = callback; + } + } + + void executeContent(std::function callback, + bool after = false) { + if (after) { + _afterExecutingContent = callback; + } else { + _beforeExecutingContent = callback; + } + } + + void uninvoke(std::function callback, + bool after = false) { + if (after) { + _afterUninvoking = callback; + } else { + _beforeUninvoking = callback; + } + } + + void transition(std::function callback, + bool after = false) { + if (after) { + _afterTakingTransition = callback; + } else { + _beforeTakingTransition = callback; + } + } + + void enterState(std::function callback, + bool after = false) { + _beforeEnteringState = callback; + if (after) { + _afterEnteringState = callback; + } else { + _beforeEnteringState = callback; + } + + } + + void invoke(std::function callback, + bool after = false) { + if (after) { + _afterInvoking = callback; + } else { + _beforeInvoking = callback; + } + } + + void stableConfiguration(std::function callback) { + _onStableConfiguration = callback; + } + + void completion(std::function callback, + bool after = false) { + if (after) { + _afterCompletion = callback; + } else { + _beforeCompletion = callback; + } + + } + + void reportIssue(std::function callback) { + _reportIssue = callback; + } protected: - - std::function _beforeProcessingEvent; - - std::function _beforeMicroStep; - - std::function _beforeExitingState; - - std::function _afterExitingState; - - std::function _beforeExecutingContent; - std::function _afterExecutingContent; - - std::function _beforeUninvoking; - std::function _afterUninvoking; - - std::function _beforeTakingTransition; - std::function _afterTakingTransition; - - std::function _beforeEnteringState; - std::function _afterEnteringState; - - std::function _beforeInvoking; - std::function _afterInvoking; - - std::function _afterMicroStep; - std::function _onStableConfiguration; - - std::function _beforeCompletion; - std::function _afterCompletion; - - std::function _reportIssue; - - - - void beforeProcessingEvent(const std::string& sessionId, - const Event& event) { - if (_beforeProcessingEvent) - _beforeProcessingEvent(sessionId, event); - } - void beforeMicroStep(const std::string& sessionId) { - if (_beforeMicroStep) - _beforeMicroStep(sessionId); - } - - void beforeExitingState(const std::string& sessionId, - const std::string& stateName, - const XERCESC_NS::DOMElement* state) { - if (_beforeExitingState) - _beforeExitingState(sessionId, stateName, state); - } - - void afterExitingState(const std::string& sessionId, - const std::string& stateName, - const XERCESC_NS::DOMElement* state) { - if (_afterExitingState) - _afterExitingState(sessionId, stateName, state); - } - - void beforeExecutingContent(const std::string& sessionId, - const XERCESC_NS::DOMElement* execContent) { - if (_beforeExecutingContent) - _beforeExecutingContent(sessionId, execContent); - } - void afterExecutingContent(const std::string& sessionId, - const XERCESC_NS::DOMElement* execContent) { - if (_afterExecutingContent) - _afterExecutingContent(sessionId, execContent); - - } - - void beforeUninvoking(const std::string& sessionId, - const XERCESC_NS::DOMElement* invokeElem, - const std::string& invokeid) { - if (_beforeUninvoking) - _beforeUninvoking(sessionId, invokeElem, invokeid); - } - void afterUninvoking(const std::string& sessionId, - const XERCESC_NS::DOMElement* invokeElem, - const std::string& invokeid) { - if (_afterUninvoking) - _afterUninvoking(sessionId, invokeElem, invokeid); - } - - void beforeTakingTransition(const std::string& sessionId, - const XERCESC_NS::DOMElement* transition) { - if (_beforeTakingTransition) - _beforeTakingTransition(sessionId, transition); - } - void afterTakingTransition(const std::string& sessionId, - const XERCESC_NS::DOMElement* transition) { - if (_afterTakingTransition) - _afterTakingTransition(sessionId, transition); - } - - void beforeEnteringState(const std::string& sessionId, - const std::string& stateName, - const XERCESC_NS::DOMElement* state) { - if (_beforeEnteringState) - _beforeEnteringState(sessionId, stateName, state); - } - void afterEnteringState(const std::string& sessionId, - const std::string& stateName, - const XERCESC_NS::DOMElement* state) { - if (_afterEnteringState) - _afterEnteringState(sessionId, stateName, state); - } - - void beforeInvoking(const std::string& sessionId, - const XERCESC_NS::DOMElement* invokeElem, - const std::string& invokeid) { - if (_beforeInvoking) - _beforeInvoking(sessionId, invokeElem, invokeid); - } - void afterInvoking(const std::string& sessionId, - const XERCESC_NS::DOMElement* invokeElem, - const std::string& invokeid) { - if (_afterInvoking) - _afterInvoking(sessionId, invokeElem, invokeid); - } - - void afterMicroStep(const std::string& sessionId) { - if (_afterMicroStep) - _afterMicroStep(sessionId); - } - void onStableConfiguration(const std::string& sessionId) { - if (_onStableConfiguration) - _onStableConfiguration(sessionId); - } - - void beforeCompletion(const std::string& sessionId) { - if (_beforeCompletion) - _beforeCompletion(sessionId); - } - void afterCompletion(const std::string& sessionId) { - if (_afterCompletion) - _afterCompletion(sessionId); - } - - void reportIssue(const std::string& sessionId, - const InterpreterIssue& issue) { - if (_reportIssue) - _reportIssue(sessionId, issue); - } + + std::function _beforeProcessingEvent; + + std::function _beforeMicroStep; + + std::function _beforeExitingState; + + std::function _afterExitingState; + + std::function _beforeExecutingContent; + std::function _afterExecutingContent; + + std::function _beforeUninvoking; + std::function _afterUninvoking; + + std::function _beforeTakingTransition; + std::function _afterTakingTransition; + + std::function _beforeEnteringState; + std::function _afterEnteringState; + + std::function _beforeInvoking; + std::function _afterInvoking; + + std::function _afterMicroStep; + std::function _onStableConfiguration; + + std::function _beforeCompletion; + std::function _afterCompletion; + + std::function _reportIssue; + + + + void beforeProcessingEvent(const std::string& sessionId, + const Event& event) { + if (_beforeProcessingEvent) + _beforeProcessingEvent(sessionId, event); + } + void beforeMicroStep(const std::string& sessionId) { + if (_beforeMicroStep) + _beforeMicroStep(sessionId); + } + + void beforeExitingState(const std::string& sessionId, + const std::string& stateName, + const XERCESC_NS::DOMElement* state) { + if (_beforeExitingState) + _beforeExitingState(sessionId, stateName, state); + } + + void afterExitingState(const std::string& sessionId, + const std::string& stateName, + const XERCESC_NS::DOMElement* state) { + if (_afterExitingState) + _afterExitingState(sessionId, stateName, state); + } + + void beforeExecutingContent(const std::string& sessionId, + const XERCESC_NS::DOMElement* execContent) { + if (_beforeExecutingContent) + _beforeExecutingContent(sessionId, execContent); + } + void afterExecutingContent(const std::string& sessionId, + const XERCESC_NS::DOMElement* execContent) { + if (_afterExecutingContent) + _afterExecutingContent(sessionId, execContent); + + } + + void beforeUninvoking(const std::string& sessionId, + const XERCESC_NS::DOMElement* invokeElem, + const std::string& invokeid) { + if (_beforeUninvoking) + _beforeUninvoking(sessionId, invokeElem, invokeid); + } + void afterUninvoking(const std::string& sessionId, + const XERCESC_NS::DOMElement* invokeElem, + const std::string& invokeid) { + if (_afterUninvoking) + _afterUninvoking(sessionId, invokeElem, invokeid); + } + + void beforeTakingTransition(const std::string& sessionId, + const XERCESC_NS::DOMElement* transition) { + if (_beforeTakingTransition) + _beforeTakingTransition(sessionId, transition); + } + void afterTakingTransition(const std::string& sessionId, + const XERCESC_NS::DOMElement* transition) { + if (_afterTakingTransition) + _afterTakingTransition(sessionId, transition); + } + + void beforeEnteringState(const std::string& sessionId, + const std::string& stateName, + const XERCESC_NS::DOMElement* state) { + if (_beforeEnteringState) + _beforeEnteringState(sessionId, stateName, state); + } + void afterEnteringState(const std::string& sessionId, + const std::string& stateName, + const XERCESC_NS::DOMElement* state) { + if (_afterEnteringState) + _afterEnteringState(sessionId, stateName, state); + } + + void beforeInvoking(const std::string& sessionId, + const XERCESC_NS::DOMElement* invokeElem, + const std::string& invokeid) { + if (_beforeInvoking) + _beforeInvoking(sessionId, invokeElem, invokeid); + } + void afterInvoking(const std::string& sessionId, + const XERCESC_NS::DOMElement* invokeElem, + const std::string& invokeid) { + if (_afterInvoking) + _afterInvoking(sessionId, invokeElem, invokeid); + } + + void afterMicroStep(const std::string& sessionId) { + if (_afterMicroStep) + _afterMicroStep(sessionId); + } + void onStableConfiguration(const std::string& sessionId) { + if (_onStableConfiguration) + _onStableConfiguration(sessionId); + } + + void beforeCompletion(const std::string& sessionId) { + if (_beforeCompletion) + _beforeCompletion(sessionId); + } + void afterCompletion(const std::string& sessionId) { + if (_afterCompletion) + _afterCompletion(sessionId); + } + + void reportIssue(const std::string& sessionId, + const InterpreterIssue& issue) { + if (_reportIssue) + _reportIssue(sessionId, issue); + } }; } diff --git a/src/uscxml/plugins/DataModel.cpp b/src/uscxml/plugins/DataModel.cpp index 19a01c9..1b12e88 100644 --- a/src/uscxml/plugins/DataModel.cpp +++ b/src/uscxml/plugins/DataModel.cpp @@ -31,7 +31,7 @@ bool DataModel::isValidSyntax(const std::string& expr) { } bool DataModel::isLegalDataValue(const std::string& expr) { - return _impl->isLegalDataValue(expr); + return _impl->isLegalDataValue(expr); } void DataModel::setEvent(const Event& event) { diff --git a/src/uscxml/plugins/DataModel.h b/src/uscxml/plugins/DataModel.h index 6812553..b5ab31c 100644 --- a/src/uscxml/plugins/DataModel.h +++ b/src/uscxml/plugins/DataModel.h @@ -46,8 +46,8 @@ public: virtual std::list getNames(); /// @copydoc DataModelImpl::isValidSyntax() virtual bool isValidSyntax(const std::string& expr); - /// @copydoc DataModelImpl::isLegalDataValue() - virtual bool isLegalDataValue(const std::string& expr); + /// @copydoc DataModelImpl::isLegalDataValue() + virtual bool isLegalDataValue(const std::string& expr); /// @copydoc DataModelImpl::setEvent() virtual void setEvent(const Event& event); diff --git a/src/uscxml/plugins/DataModelImpl.h b/src/uscxml/plugins/DataModelImpl.h index b378a96..afb41bc 100644 --- a/src/uscxml/plugins/DataModelImpl.h +++ b/src/uscxml/plugins/DataModelImpl.h @@ -117,7 +117,7 @@ public: /** * Determine whether a given string constitutes valid syntax in the * data-model's language. This is only used to identify InterpreterIssues - * but may be useful to implement isLegalDataValue() as well. + * but may be useful to implement isLegalDataValue() as well. * @param expr A string, supposedly containing an expression of the data-model. * @return Whether expr is in L(DM). */ @@ -125,16 +125,16 @@ public: return true; // overwrite when datamodel supports it } - /** - * Determine whether a given string constitutes a legal data value that can appear - * at the right-hand side of an assignment. - * - * @param expr A string, supposedly containing a legal data value. - * @return Whether expr is a legal data value. - */ - virtual bool isLegalDataValue(const std::string& expr) { - return true; // overwrite when datamodel supports it - } + /** + * Determine whether a given string constitutes a legal data value that can appear + * at the right-hand side of an assignment. + * + * @param expr A string, supposedly containing a legal data value. + * @return Whether expr is a legal data value. + */ + virtual bool isLegalDataValue(const std::string& expr) { + return true; // overwrite when datamodel supports it + } /** * Set the given event as `_event` in the data-model's global scope. diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 3932961..69ed632 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -669,9 +669,9 @@ bool JSCDataModel::isValidSyntax(const std::string& expr) { } bool JSCDataModel::isLegalDataValue(const std::string& expr) { - return isValidSyntax("var __tmp = " + expr); + return isValidSyntax("var __tmp = " + expr); } - + bool JSCDataModel::isDeclared(const std::string& expr) { JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 38b0ca5..dbe37e6 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -64,7 +64,7 @@ public: return names; } - virtual bool isLegalDataValue(const std::string& expr); + virtual bool isLegalDataValue(const std::string& expr); virtual bool isValidSyntax(const std::string& expr); virtual void setEvent(const Event& event); diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index 15cbf9d..ad4fb40 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -63,17 +63,17 @@ using namespace XERCESC_NS; #else #include "LuaEvent.cpp.inc" #endif - + namespace uscxml { - + #ifdef BUILD_AS_PLUGINS - PLUMA_CONNECTOR - bool pluginConnect(pluma::Host& host) { - host.add( new LuaDataModelProvider() ); - return true; - } +PLUMA_CONNECTOR +bool pluginConnect(pluma::Host& host) { + host.add( new LuaDataModelProvider() ); + return true; +} #endif - + static int luaEval(lua_State* luaState, const std::string& expr) { int preStack = lua_gettop(luaState); int error = luaL_loadstring(luaState, expr.c_str()) || lua_pcall(luaState, 0, LUA_MULTRET, 0); @@ -97,12 +97,12 @@ static Data getLuaAsData(lua_State* _luaState, const luabridge::LuaRef& lua) { data.type = Data::INTERPRETED; } else if(lua.isLightUserdata() || lua.isUserdata()) { #ifndef NO_XERCESC - int err = SWIG_Lua_ConvertPtr(_luaState, 0, (void**)&(data.node), SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_POINTER_DISOWN); - if (err == SWIG_ERROR) - data.node = NULL; + int err = SWIG_Lua_ConvertPtr(_luaState, 0, (void**)&(data.node), SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_POINTER_DISOWN); + if (err == SWIG_ERROR) + data.node = NULL; #endif - - } else if(lua.isThread()) { + + } else if(lua.isThread()) { // not sure what to do } else if(lua.type() == LUA_TBOOLEAN) { // why is there no isBoolean in luabridge? @@ -121,7 +121,7 @@ static Data getLuaAsData(lua_State* _luaState, const luabridge::LuaRef& lua) { } else if(lua.isString()) { data.atom = lua.cast(); data.type = Data::VERBATIM; - } else if(lua.isTable()) { + } else if(lua.isTable()) { // check whether it is to be interpreted as a map or an array bool isArray = true; std::map luaItems; @@ -161,13 +161,13 @@ static luabridge::LuaRef getDataAsLua(lua_State* _luaState, const Data& data) { if (data.node) { #ifndef NO_XERCESC - SWIG_Lua_NewPointerObj(_luaState, data.node, SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_POINTER_DISOWN); - luaData = luabridge::LuaRef::fromStack(_luaState, 1); - return luaData; + SWIG_Lua_NewPointerObj(_luaState, data.node, SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_POINTER_DISOWN); + luaData = luabridge::LuaRef::fromStack(_luaState, 1); + return luaData; #else - ERROR_EXECUTION_THROW("No DOM support in Lua datamodel"); + ERROR_EXECUTION_THROW("No DOM support in Lua datamodel"); #endif - } + } if (data.compound.size() > 0) { luaData = luabridge::newTable(_luaState); std::map::const_iterator compoundIter = data.compound.begin(); @@ -257,8 +257,8 @@ void LuaDataModel::setup() { _luaState = luaL_newstate(); luaL_openlibs(_luaState); - SWIG_init(_luaState); - + SWIG_init(_luaState); + #if 0 try { const luabridge::LuaRef& requireFunc = luabridge::getGlobal(_luaState, "require"); @@ -277,7 +277,7 @@ void LuaDataModel::setup() { LOG(_callbacks->getLogger(), USCXML_INFO) << e.what() << std::endl; } #endif - + luabridge::getGlobalNamespace(_luaState).beginClass("DataModel").endClass(); luabridge::setGlobal(_luaState, this, "__datamodel"); @@ -351,10 +351,10 @@ void LuaDataModel::setEvent(const Event& event) { if (event.data.node) { #ifndef NO_XERCESC - SWIG_Lua_NewPointerObj(_luaState, event.data.node, SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_POINTER_DISOWN); - luaEvent["data"] = luabridge::LuaRef::fromStack(_luaState, 1); + SWIG_Lua_NewPointerObj(_luaState, event.data.node, SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_POINTER_DISOWN); + luaEvent["data"] = luabridge::LuaRef::fromStack(_luaState, 1); #else - ERROR_EXECUTION_THROW("No DOM support in Lua datamodel"); + ERROR_EXECUTION_THROW("No DOM support in Lua datamodel"); #endif } else { // _event.data is KVP @@ -409,7 +409,7 @@ void LuaDataModel::eval(const std::string& content) { } bool LuaDataModel::isLegalDataValue(const std::string& expr) { - return isValidSyntax("local __tmp = " + expr); + return isValidSyntax("local __tmp = " + expr); } bool LuaDataModel::isValidSyntax(const std::string& expr) { @@ -510,9 +510,9 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s if (data.node) { #ifndef NO_XERCESC - SWIG_Lua_NewPointerObj(_luaState, data.node, SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_POINTER_DISOWN); - lua_setglobal(_luaState, "__tmpAssign"); - eval(location + "= __tmpAssign"); + SWIG_Lua_NewPointerObj(_luaState, data.node, SWIGTYPE_p_XERCES_CPP_NAMESPACE__DOMNode, SWIG_POINTER_DISOWN); + lua_setglobal(_luaState, "__tmpAssign"); + eval(location + "= __tmpAssign"); #else ERROR_EXECUTION_THROW("Cannot assign xml nodes in lua datamodel"); #endif diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index 84633f1..9b4917b 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -62,7 +62,7 @@ public: } virtual bool isValidSyntax(const std::string& expr); - virtual bool isLegalDataValue(const std::string& expr); + virtual bool isLegalDataValue(const std::string& expr); virtual void setEvent(const Event& event); diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp index 9f4f22f..c12491b 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp @@ -707,8 +707,8 @@ void PromelaDataModel::setEvent(const Event& event) { void PromelaDataModel::assign(const std::string& location, const Data& data, const std::map& attr) { PromelaParser parser(location); if (data.atom.size() > 0 && data.type == Data::INTERPRETED) { - // e.g. Var1 = Var1 + 1 - setVariable(parser.ast, evalAsData(data.atom)); + // e.g. Var1 = Var1 + 1 + setVariable(parser.ast, evalAsData(data.atom)); } else { setVariable(parser.ast, data); } diff --git a/test/src/test-snippets.cpp b/test/src/test-snippets.cpp index 5eb680f..4f67734 100644 --- a/test/src/test-snippets.cpp +++ b/test/src/test-snippets.cpp @@ -34,29 +34,29 @@ void microstep_snippet() { } void lambda_snippet() { - InterpreterState state = uscxml::USCXML_UNDEF; - Interpreter scxml = Interpreter::fromURL("https://raw.githubusercontent.com/tklab-tud/uscxml/master/test/w3c/null/test436.scxml"); + InterpreterState state = uscxml::USCXML_UNDEF; + Interpreter scxml = Interpreter::fromURL("https://raw.githubusercontent.com/tklab-tud/uscxml/master/test/w3c/null/test436.scxml"); - scxml.on().enterState([](const std::string& sessionId, - const std::string& stateName, - const xercesc_3_1::DOMElement* state) { - std::cout << "Entered " << stateName << std::endl; - }); + scxml.on().enterState([](const std::string& sessionId, + const std::string& stateName, + const xercesc_3_1::DOMElement* state) { + std::cout << "Entered " << stateName << std::endl; + }); - scxml.on().exitState([](const std::string& sessionId, - const std::string& stateName, - const xercesc_3_1::DOMElement* state) { - std::cout << "Exited " << stateName << std::endl; - }); + scxml.on().exitState([](const std::string& sessionId, + const std::string& stateName, + const xercesc_3_1::DOMElement* state) { + std::cout << "Exited " << stateName << std::endl; + }); - while((state = scxml.step()) != uscxml::USCXML_FINISHED) {} + while((state = scxml.step()) != uscxml::USCXML_FINISHED) {} } int main(int argc, char** argv) { try { - lambda_snippet(); + lambda_snippet(); microstep_snippet(); } catch (...) { exit(EXIT_FAILURE); -- cgit v0.12