From c699a4057a65a9a09f78310d8e12588f2dc072cd Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Sun, 10 Jan 2016 03:39:24 +0100 Subject: Builds with MSVC again --- CMakeLists.txt | 21 ++ apps/w3c-mmi/MMIEventServlet.cpp | 1 + src/uscxml/Interpreter.cpp | 10 - src/uscxml/Interpreter.h | 32 +++- src/uscxml/concurrency/Timer.cpp | 29 ++- src/uscxml/concurrency/Timer.h | 6 + src/uscxml/debug/Complexity.cpp | 2 + src/uscxml/plugins/DataModel.h | 36 +++- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 29 --- .../ioprocessor/basichttp/BasicHTTPIOProcessor.cpp | 1 + .../plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp | 1 + src/uscxml/server/HTTPServer.cpp | 1 + src/uscxml/transform/ChartToC.cpp | 25 ++- src/uscxml/transform/ChartToPromela.cpp | 2 +- test/src/test-c-machine.cpp | 50 ++--- test/src/test-c-machine.machine.c | 211 ++++++--------------- test/src/test-w3c.cpp | 9 +- 17 files changed, 212 insertions(+), 254 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fe4698..4b65fc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 2.8.4) +# TODO: +# - Have a look at PGO: +# https://mailman.videolan.org/pipermail/x265-devel/2015-April/007399.html + cmake_policy(PUSH) if(POLICY CMP0042) # new behavior defaults to ON for MACOSX_RPATH @@ -384,6 +388,19 @@ OPTION(BUILD_BINDING_JAVA "Build language bindings for Java" ON) OPTION(BUILD_BINDING_CSHARP "Build language bindings for CSharp" ON) OPTION(BUILD_BINDING_PHP "Build language bindings for PHP" OFF) +# ccache: +# http://stackoverflow.com/questions/1815688/how-to-use-ccache-with-cmake +# +# see also: +# http://blogs.s-osg.org/a-conclusion-to-accelerating-your-build-with-clang/ + +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif(CCACHE_FOUND) + + # a dummy target to depend on the targets needed for tests, see: # http://stackoverflow.com/questions/733475/cmake-ctest-make-test-doesnt-build-tests add_custom_target(ALL_TESTS COMMENT "Building all tests when BUILD_TESTS is enabled") @@ -496,6 +513,10 @@ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-plus-int") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-non-literal-null-conversion") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-null-conversion") + + # clang throws these for boost all over the place! + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs") + #SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libstdc++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") diff --git a/apps/w3c-mmi/MMIEventServlet.cpp b/apps/w3c-mmi/MMIEventServlet.cpp index 22b8d91..2d88f1b 100644 --- a/apps/w3c-mmi/MMIEventServlet.cpp +++ b/apps/w3c-mmi/MMIEventServlet.cpp @@ -2,6 +2,7 @@ #include #ifdef _WIN32 +#define NOMINMAX #include #include #endif diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 736a740..4e45599 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -57,12 +57,6 @@ # include "uscxml/interpreter/InterpreterRC.h" #endif -#ifdef BUILD_PROFILING -#define TIME_BLOCK Measurement msm(&timer); -#else -#define TIME_BLOCK (0); -#endif - #define VERBOSE 0 /// valid interpreter state transitions @@ -778,7 +772,6 @@ NodeSet InterpreterImpl::getDocumentInitialTransitions() { } InterpreterState InterpreterImpl::step(int waitForMS) { - TIME_BLOCK try { tthread::lock_guard lock(_mutex); @@ -1369,9 +1362,6 @@ void InterpreterImpl::reset() { _isInitialized = false; _stable = false; -#ifdef BUILD_PROFILING - timer = Timer(); -#endif _dataModel = DataModel(); setInterpreterState(USCXML_INSTANTIATED); } diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index e442585..d857902 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -52,6 +52,9 @@ #ifdef BUILD_PROFILING #include "uscxml/concurrency/Timer.h" +#define TIME_BLOCK Measurement msm(&timer); +#else +#define TIME_BLOCK (0); #endif #define ERROR_PLATFORM_THROW(msg) \ @@ -412,10 +415,6 @@ public: virtual void handleDOMEvent(Arabica::DOM::Events::Event& event); -#ifdef BUILD_PROFILING - Timer timer; -#endif - protected: static void run(void*); // static method for thread to run @@ -593,10 +592,14 @@ public: } virtual void writeTo(std::ostream& stream) { + TIME_BLOCK return _impl->writeTo(stream); } void reset() { +#ifdef BUILD_PROFILING + timer = Timer(); +#endif return _impl->reset(); } @@ -618,16 +621,19 @@ public: }; InterpreterState step(int waitForMS = 0) { + TIME_BLOCK return _impl->step(waitForMS); }; InterpreterState step(bool blocking) { + TIME_BLOCK if (blocking) return _impl->step(-1); return _impl->step(0); }; std::list validate() { + TIME_BLOCK return _impl->validate(); } @@ -714,33 +720,41 @@ public: return _impl->getFactory(); } Arabica::XPath::NodeSet getNodeSetForXPath(const std::string& xpathExpr) { + TIME_BLOCK return _impl->getNodeSetForXPath(xpathExpr); } void inline receiveInternal(const Event& event) { + TIME_BLOCK return _impl->receiveInternal(event); } void receive(const Event& event, bool toFront = false) { + TIME_BLOCK return _impl->receive(event, toFront); } Event getCurrentEvent() { + TIME_BLOCK return _impl->getCurrentEvent(); } bool isInState(const std::string& stateId) { + TIME_BLOCK return _impl->isInState(stateId); } Arabica::XPath::NodeSet getConfiguration() { + TIME_BLOCK return _impl->getConfiguration(); } Arabica::XPath::NodeSet getBasicConfiguration() { + TIME_BLOCK return _impl->getBasicConfiguration(); } void setInitalConfiguration(const std::list& states) { + TIME_BLOCK return _impl->setInitalConfiguration(states); } @@ -777,19 +791,23 @@ public: } bool runOnMainThread(int fps, bool blocking = true) { + TIME_BLOCK return _impl->runOnMainThread(fps, blocking); } bool hasLegalConfiguration() { + TIME_BLOCK return _impl->hasLegalConfiguration(); } bool isLegalConfiguration(const Arabica::XPath::NodeSet& config) { + TIME_BLOCK return _impl->isLegalConfiguration(config); } bool isLegalConfiguration(const std::list& config) { - return _impl->isLegalConfiguration(config); + TIME_BLOCK + return _impl->isLegalConfiguration(config); } boost::shared_ptr getImpl() const { @@ -799,6 +817,10 @@ public: static std::map > getInstances(); static void addInstance(boost::shared_ptr instance); +#ifdef BUILD_PROFILING + Timer timer; +#endif + protected: void setInvokeRequest(const InvokeRequest& req) { diff --git a/src/uscxml/concurrency/Timer.cpp b/src/uscxml/concurrency/Timer.cpp index b05a907..2835173 100644 --- a/src/uscxml/concurrency/Timer.cpp +++ b/src/uscxml/concurrency/Timer.cpp @@ -4,7 +4,10 @@ // see https://github.com/awreece/monotonic_timer +#include "uscxml/config.h" +#ifdef HAS_UNISTD_H #include +#endif #include "Timer.h" #define NANOS_PER_SECF 1000000000.0 @@ -44,29 +47,25 @@ #elif defined(_MSC_VER) // On Windows, use QueryPerformanceCounter and QueryPerformanceFrequency. +#define NOMINMAX #include static double PCFreq = 0.0; +__int64 CounterStart = 0; - // According to http://stackoverflow.com/q/1113409/447288, this will - // make this function a constructor. - // TODO(awreece) Actually attempt to compile on windows. - static void __cdecl init_pcfreq(); - __declspec(allocate(".CRT$XCU")) void (__cdecl*init_pcfreq_)() = init_pcfreq; - static void __cdecl init_pcfreq() { - // Accoring to http://stackoverflow.com/a/1739265/447288, this will - // properly initialize the QueryPerformanceCounter. - LARGE_INTEGER li; - int has_qpc = QueryPerformanceFrequency(&li); - assert(has_qpc); + double uscxml::Timer::monotonic_seconds() { + if (CounterStart == 0) { + // Accoring to http://stackoverflow.com/a/1739265/447288, this will + // properly initialize the QueryPerformanceCounter. - PCFreq = ((double) li.QuadPart) / 1000.0; - } + LARGE_INTEGER li; + int has_qpc = QueryPerformanceFrequency(&li); - double uscxml::Timer::monotonic_seconds() { + PCFreq = ((double) li.QuadPart) / 1000.0; + } LARGE_INTEGER li; QueryPerformanceCounter(&li); - return ((double) li.QuadPart) / PCFreq; + return double(li.QuadPart - CounterStart)/PCFreq; } #else diff --git a/src/uscxml/concurrency/Timer.h b/src/uscxml/concurrency/Timer.h index 60a20a3..217f68f 100644 --- a/src/uscxml/concurrency/Timer.h +++ b/src/uscxml/concurrency/Timer.h @@ -7,6 +7,8 @@ #ifndef MONOTONIC_TIMER_H_ #define MONOTONIC_TIMER_H_ +#include "uscxml/Common.h" + // Returns seconds since some unspecified start time (guaranteed to be // monotonicly increasing). @@ -31,6 +33,10 @@ public: invocations++; } + void reset() { + elapsed = 0; + } + void stop() { if (invocations == 0) return; diff --git a/src/uscxml/debug/Complexity.cpp b/src/uscxml/debug/Complexity.cpp index 8a7d8db..de01831 100644 --- a/src/uscxml/debug/Complexity.cpp +++ b/src/uscxml/debug/Complexity.cpp @@ -20,6 +20,8 @@ #include "Complexity.h" #include "uscxml/DOMUtils.h" +#include + namespace uscxml { using namespace Arabica::DOM; diff --git a/src/uscxml/plugins/DataModel.h b/src/uscxml/plugins/DataModel.h index 097fcfd..74277c8 100644 --- a/src/uscxml/plugins/DataModel.h +++ b/src/uscxml/plugins/DataModel.h @@ -26,6 +26,9 @@ #ifdef BUILD_PROFILING #include "uscxml/concurrency/Timer.h" +#define TIME_BLOCK Measurement msm(&timer); +#else +#define TIME_BLOCK (0); #endif #include @@ -107,10 +110,6 @@ public: return ""; } -#ifdef BUILD_PROFILING - Timer timer; -#endif - protected: InterpreterInfo* _interpreter; }; @@ -141,96 +140,123 @@ public: } virtual std::list getNames() { - return _impl->getNames(); + TIME_BLOCK + return _impl->getNames(); } virtual bool validate(const std::string& location, const std::string& schema) { + TIME_BLOCK return _impl->validate(location, schema); } virtual bool isLocation(const std::string& expr) { + TIME_BLOCK return _impl->isLocation(expr); } virtual bool isValidSyntax(const std::string& expr) { + TIME_BLOCK return _impl->isValidSyntax(expr); } virtual void setEvent(const Event& event) { + TIME_BLOCK return _impl->setEvent(event); } virtual Data getStringAsData(const std::string& content) { + TIME_BLOCK return _impl->getStringAsData(content); } virtual void pushContext() { + TIME_BLOCK return _impl->pushContext(); } virtual void popContext() { + TIME_BLOCK return _impl->popContext(); } virtual void eval(const Arabica::DOM::Element& scriptElem, const std::string& expr) { + TIME_BLOCK return _impl->eval(scriptElem, expr); } virtual std::string evalAsString(const std::string& expr) { + TIME_BLOCK return _impl->evalAsString(expr); } virtual bool evalAsBool(const std::string& expr) { + TIME_BLOCK return _impl->evalAsBool(expr); } virtual bool evalAsBool(const Arabica::DOM::Element& scriptNode, const std::string& expr) { + TIME_BLOCK return _impl->evalAsBool(scriptNode, expr); } virtual uint32_t getLength(const std::string& expr) { + TIME_BLOCK return _impl->getLength(expr); } virtual void setForeach(const std::string& item, const std::string& array, const std::string& index, uint32_t iteration) { + TIME_BLOCK return _impl->setForeach(item, array, index, iteration); } virtual void assign(const Arabica::DOM::Element& assignElem, const Arabica::DOM::Node& node, const std::string& content) { + TIME_BLOCK return _impl->assign(assignElem, node, content); } virtual void assign(const std::string& location, const Data& data) { + TIME_BLOCK return _impl->assign(location, data); } virtual void init(const Arabica::DOM::Element& dataElem, const Arabica::DOM::Node& node, const std::string& content) { + TIME_BLOCK return _impl->init(dataElem, node, content); } virtual void init(const std::string& location, const Data& data) { + TIME_BLOCK return _impl->init(location, data); } virtual bool isDeclared(const std::string& expr) { + TIME_BLOCK return _impl->isDeclared(expr); } size_t replaceExpressions(std::string& content) { + TIME_BLOCK return _impl->replaceExpressions(content); } std::string andExpressions(std::list expressions) { + TIME_BLOCK return _impl->andExpressions(expressions); } virtual void setInterpreter(InterpreterInfo* interpreter) { + TIME_BLOCK _impl->setInterpreter(interpreter); } virtual void addExtension(DataModelExtension* ext) { + TIME_BLOCK _impl->addExtension(ext); } +#ifdef BUILD_PROFILING + Timer timer; +#endif + protected: boost::shared_ptr _impl; }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 9a71ab0..40b6cc2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -44,12 +44,6 @@ #include "uscxml/DOMUtils.h" #include -#ifdef BUILD_PROFILING -#define TIME_BLOCK Measurement msm(&timer); -#else -#define TIME_BLOCK (0); -#endif - #ifdef BUILD_AS_PLUGINS #include #endif @@ -93,7 +87,6 @@ JSCDataModel::~JSCDataModel() { } void JSCDataModel::addExtension(DataModelExtension* ext) { - TIME_BLOCK if (_extensions.find(ext) != _extensions.end()) return; @@ -199,7 +192,6 @@ JSClassDefinition JSCDataModel::jsInvokersClassDef = { 0, 0, "invokers", 0, 0, 0 boost::shared_ptr JSCDataModel::create(InterpreterInfo* interpreter) { boost::shared_ptr dm = boost::shared_ptr(new JSCDataModel()); - TIME_BLOCK dm->_ctx = JSGlobalContextCreate(NULL); dm->_interpreter = interpreter; @@ -284,7 +276,6 @@ void JSCDataModel::popContext() { } void JSCDataModel::setEvent(const Event& event) { - TIME_BLOCK JSCSCXMLEvent::JSCSCXMLEventPrivate* privData = new JSCSCXMLEvent::JSCSCXMLEventPrivate(); privData->nativeObj = new Event(event); privData->dom = _dom; @@ -367,14 +358,12 @@ void JSCDataModel::setEvent(const Event& event) { } Data JSCDataModel::getStringAsData(const std::string& content) { - TIME_BLOCK JSValueRef result = evalAsValue(content); Data data = getValueAsData(result); return data; } JSValueRef JSCDataModel::getDataAsValue(const Data& data) { - TIME_BLOCK JSValueRef exception = NULL; if (data.node) { @@ -440,7 +429,6 @@ JSValueRef JSCDataModel::getDataAsValue(const Data& data) { } Data JSCDataModel::getValueAsData(const JSValueRef value) { - TIME_BLOCK Data data; JSValueRef exception = NULL; switch(JSValueGetType(_ctx, value)) { @@ -529,12 +517,10 @@ Data JSCDataModel::getValueAsData(const JSValueRef value) { } bool JSCDataModel::validate(const std::string& location, const std::string& schema) { - TIME_BLOCK return true; } uint32_t JSCDataModel::getLength(const std::string& expr) { - TIME_BLOCK JSValueRef result; result = evalAsValue("(" + expr + ").length"); @@ -555,7 +541,6 @@ void JSCDataModel::setForeach(const std::string& item, const std::string& array, const std::string& index, uint32_t iteration) { - TIME_BLOCK if (!isDeclared(item)) { assign(item, Data()); } @@ -572,13 +557,11 @@ void JSCDataModel::setForeach(const std::string& item, } bool JSCDataModel::isLocation(const std::string& expr) { - TIME_BLOCK // location needs to be LHS and ++ is only valid for LHS return isValidSyntax(expr + "++"); } bool JSCDataModel::isValidSyntax(const std::string& expr) { - TIME_BLOCK JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; bool valid = JSCheckScriptSyntax(_ctx, scriptJS, NULL, 0, &exception); @@ -591,7 +574,6 @@ bool JSCDataModel::isValidSyntax(const std::string& expr) { } bool JSCDataModel::isDeclared(const std::string& expr) { - TIME_BLOCK JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; JSValueRef result = JSEvaluateScript(_ctx, scriptJS, NULL, NULL, 0, &exception); @@ -605,18 +587,15 @@ bool JSCDataModel::isDeclared(const std::string& expr) { void JSCDataModel::eval(const Element& scriptElem, const std::string& expr) { - TIME_BLOCK evalAsValue(expr); } bool JSCDataModel::evalAsBool(const Arabica::DOM::Element& node, const std::string& expr) { - TIME_BLOCK JSValueRef result = evalAsValue(expr); return JSValueToBoolean(_ctx, result); } std::string JSCDataModel::evalAsString(const std::string& expr) { - TIME_BLOCK JSValueRef result = evalAsValue(expr); JSValueRef exception = NULL; @@ -635,7 +614,6 @@ std::string JSCDataModel::evalAsString(const std::string& expr) { } JSValueRef JSCDataModel::evalAsValue(const std::string& expr, bool dontThrow) { - TIME_BLOCK JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; JSValueRef result = JSEvaluateScript(_ctx, scriptJS, NULL, NULL, 0, &exception); @@ -650,7 +628,6 @@ JSValueRef JSCDataModel::evalAsValue(const std::string& expr, bool dontThrow) { void JSCDataModel::assign(const Element& assignElem, const Node& node, const std::string& content) { - TIME_BLOCK std::string key; JSValueRef exception = NULL; if (HAS_ATTR(assignElem, "id")) { @@ -693,7 +670,6 @@ void JSCDataModel::assign(const Element& assignElem, } JSValueRef JSCDataModel::getNodeAsValue(const Node& node) { - TIME_BLOCK switch (node.getNodeType()) { case Node_base::ELEMENT_NODE: { TO_JSC_DOMVALUE(Element); @@ -714,7 +690,6 @@ JSValueRef JSCDataModel::getNodeAsValue(const Node& node) { } void JSCDataModel::assign(const std::string& location, const Data& data) { - TIME_BLOCK std::stringstream ssJSON; ssJSON << data; evalAsValue(location + " = " + ssJSON.str()); @@ -723,7 +698,6 @@ void JSCDataModel::assign(const std::string& location, const Data& data) { void JSCDataModel::init(const Element& dataElem, const Node& node, const std::string& content) { - TIME_BLOCK try { assign(dataElem, node, content); } catch (Event e) { @@ -740,7 +714,6 @@ void JSCDataModel::init(const Element& dataElem, } void JSCDataModel::init(const std::string& location, const Data& data) { - TIME_BLOCK try { assign(location, data); } catch (Event e) { @@ -751,8 +724,6 @@ void JSCDataModel::init(const std::string& location, const Data& data) { } std::string JSCDataModel::andExpressions(std::list expressions) { - TIME_BLOCK - if (expressions.size() == 0) return ""; diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp index 19d109a..b1fb141 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp @@ -34,6 +34,7 @@ #include #ifdef _WIN32 +#define NOMINMAX #include #include #endif diff --git a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp index 9ba3e63..6905e22 100644 --- a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp @@ -20,6 +20,7 @@ #include #ifdef _WIN32 +#define NOMINMAX #include #include #endif diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index 57c1e4f..90ce242 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -20,6 +20,7 @@ #include "uscxml/config.h" #ifdef _WIN32 +#define NOMINMAX #include #include #endif diff --git a/src/uscxml/transform/ChartToC.cpp b/src/uscxml/transform/ChartToC.cpp index 02c1e91..3944b92 100644 --- a/src/uscxml/transform/ChartToC.cpp +++ b/src/uscxml/transform/ChartToC.cpp @@ -122,8 +122,13 @@ void ChartToC::writeMacros(std::ostream& stream) { stream << "#define CLEARBIT(idx, bitset) bitset[idx >> 3] &= (1 << (idx & 7)) ^ 0xFF;" << std::endl; stream << std::endl; - stream << "#define likely(x) (__builtin_expect (!!(x), 1))" << std::endl; - stream << "#define unlikely(x) (__builtin_expect (!!(x), 0))" << std::endl; + stream << "#ifdef __GNUC__" << std::endl; + stream << "#define likely(x) __builtin_expect(!!(x), 1)" << std::endl; + stream << "#define unlikely(x) __builtin_expect(!!(x), 0)" << std::endl; + stream << "#else" << std::endl; + stream << "#define likely(x) (x)" << std::endl; + stream << "#define unlikely(x) (x)" << std::endl; + stream << "#endif" << std::endl; stream << std::endl; stream << "// error return codes" << std::endl; @@ -666,7 +671,7 @@ void ChartToC::writeExecContent(std::ostream& stream, const Arabica::DOM::Nodeexec_content_raise != NULL) {" << std::endl; stream << padding; - stream << " if ((ctx->exec_content_raise(ctx, "; + stream << " if unlikely((ctx->exec_content_raise(ctx, "; stream << (HAS_ATTR(elem, "event") ? "\"" + escape(ATTR(elem, "event")) + "\"" : "NULL"); stream << ")) != SCXML_ERR_OK) return err;" << std::endl; stream << padding << "} else {" << std::endl; @@ -1231,7 +1236,7 @@ void ChartToC::writeFSM(std::ostream& stream) { stream << "#endif" << std::endl; stream << std::endl; - stream << "MACRO_STEP:" << std::endl; + stream << "// MACRO_STEP:" << std::endl; stream << " ctx->flags &= ~SCXML_CTX_TRANSITION_FOUND;" << std::endl; stream << std::endl; @@ -1321,7 +1326,7 @@ void ChartToC::writeFSM(std::ostream& stream) { stream << "#endif" << std::endl; stream << std::endl; - stream << "REMEMBER_HISTORY:" << std::endl; + stream << "// REMEMBER_HISTORY:" << std::endl; stream << " for (int i = 0; i < SCXML_NUMBER_STATES; i++) {" << std::endl; stream << " if unlikely(scxml_states[i].type == SCXML_STATE_HISTORY_SHALLOW || scxml_states[i].type == SCXML_STATE_HISTORY_DEEP) {" << std::endl; stream << " // a history state whose parent is about to be exited" << std::endl; @@ -1353,7 +1358,7 @@ void ChartToC::writeFSM(std::ostream& stream) { stream << "#endif" << std::endl; stream << std::endl; - stream << "EXIT_STATES:" << std::endl; + stream << "// EXIT_STATES:" << std::endl; stream << " for (int i = SCXML_NUMBER_STATES - 1; i >= 0; i--) {" << std::endl; stream << " if (IS_SET(i, exit_set) && IS_SET(i, ctx->config)) {" << std::endl; stream << " // call all on exit handlers" << std::endl; @@ -1378,7 +1383,7 @@ void ChartToC::writeFSM(std::ostream& stream) { stream << " }" << std::endl; stream << std::endl; - stream << "ADD_DESCENDANTS:" << std::endl; + stream << "// ADD_DESCENDANTS:" << std::endl; stream << " // iterate for descendants" << std::endl; stream << " for (int i = 0; i < SCXML_NUMBER_STATES; i++) {" << std::endl; stream << " if (IS_SET(i, entry_set)) {" << std::endl; @@ -1438,7 +1443,7 @@ void ChartToC::writeFSM(std::ostream& stream) { stream << "#endif" << std::endl; stream << std::endl; - stream << "TAKE_TRANSITIONS:" << std::endl; + stream << "// TAKE_TRANSITIONS:" << std::endl; stream << " for (int i = 0; i < SCXML_NUMBER_TRANSITIONS; i++) {" << std::endl; stream << " if (IS_SET(i, trans_set) && (scxml_transitions[i].type & SCXML_TRANS_HISTORY) == 0) {" << std::endl; stream << " // call executable content in transition" << std::endl; @@ -1458,7 +1463,7 @@ void ChartToC::writeFSM(std::ostream& stream) { stream << "#endif" << std::endl; stream << std::endl; - stream << "ENTER_STATES:" << std::endl; + stream << "// ENTER_STATES:" << std::endl; stream << " for (int i = 0; i < SCXML_NUMBER_STATES; i++) {" << std::endl; stream << " if (IS_SET(i, entry_set) && !IS_SET(i, ctx->config)) {" << std::endl; stream << " // these are no proper states" << std::endl; @@ -1549,7 +1554,7 @@ void ChartToC::writeFSM(std::ostream& stream) { stream << " }" << std::endl; stream << std::endl; - stream << "HISTORY_TRANSITIONS:" << std::endl; + stream << "// HISTORY_TRANSITIONS:" << std::endl; stream << " for (int i = 0; i < SCXML_NUMBER_TRANSITIONS; i++) {" << std::endl; stream << " if unlikely(IS_SET(i, trans_set) && (scxml_transitions[i].type & SCXML_TRANS_HISTORY)) {" << std::endl; stream << " // call executable content in transition" << std::endl; diff --git a/src/uscxml/transform/ChartToPromela.cpp b/src/uscxml/transform/ChartToPromela.cpp index 965eebc..03178f0 100644 --- a/src/uscxml/transform/ChartToPromela.cpp +++ b/src/uscxml/transform/ChartToPromela.cpp @@ -2563,7 +2563,7 @@ void ChartToPromela::writeInsertWithDelay(std::ostream& stream, int indent) { uint32_t maxExternalQueueLength = 1; std::map, ChartToPromela*>::iterator machineIter = _machinesAll->begin(); while(machineIter != _machinesAll->end()) { - maxExternalQueueLength = std::max(maxExternalQueueLength, machineIter->second->_externalQueueLength); + maxExternalQueueLength = MAX(maxExternalQueueLength, machineIter->second->_externalQueueLength); machineIter++; } diff --git a/test/src/test-c-machine.cpp b/test/src/test-c-machine.cpp index 4bbc653..ae967ad 100644 --- a/test/src/test-c-machine.cpp +++ b/test/src/test-c-machine.cpp @@ -79,7 +79,7 @@ public: std::map invokers; Arabica::DOM::Document document; scxml_ctx* ctx; - boost::shared_ptr datamodel; + DataModel datamodel; std::map foreachInfo; std::deque iq; @@ -144,7 +144,7 @@ int exec_content_raise(const scxml_ctx* ctx, const char* event) { int is_true(const scxml_ctx* ctx, const char* expr) { try { - return USER_DATA(ctx)->datamodel->evalAsBool(expr); + return USER_DATA(ctx)->datamodel.evalAsBool(expr); } catch (Event e) { exec_content_raise(ctx, e.name.c_str()); } @@ -183,7 +183,7 @@ int raise_done_event(const scxml_ctx* ctx, const scxml_state* state, const scxml e->data = Data(donedata->content, Data::VERBATIM); } else if (donedata->contentexpr != NULL) { try { - e->data = USER_DATA(ctx)->datamodel->getStringAsData(donedata->contentexpr); + e->data = USER_DATA(ctx)->datamodel.getStringAsData(donedata->contentexpr); } catch (Event e) { exec_content_raise(ctx, e.name.c_str()); } @@ -193,9 +193,9 @@ int raise_done_event(const scxml_ctx* ctx, const scxml_state* state, const scxml while (param && ELEM_PARAM_IS_SET(param)) { Data paramValue; if (param->expr != NULL) { - paramValue = USER_DATA(ctx)->datamodel->getStringAsData(param->expr); + paramValue = USER_DATA(ctx)->datamodel.getStringAsData(param->expr); } else if(param->location) { - paramValue = USER_DATA(ctx)->datamodel->getStringAsData(param->location); + paramValue = USER_DATA(ctx)->datamodel.getStringAsData(param->location); } e->params.insert(std::make_pair(param->name, paramValue)); param++; @@ -238,7 +238,7 @@ int exec_content_cancel(const scxml_ctx* ctx, const char* sendid, const char* se if (sendid != NULL) { eventId = sendid; } else if (sendidexpr != NULL) { - eventId = USER_DATA(ctx)->datamodel->evalAsString(sendidexpr); + eventId = USER_DATA(ctx)->datamodel.evalAsString(sendidexpr); } if (eventId.length() > 0) { @@ -278,7 +278,7 @@ int exec_content_send(const scxml_ctx* ctx, const scxml_elem_send* send) { if (send->target != NULL) { e->target = send->target; } else if (send->targetexpr != NULL) { - e->target = USER_DATA(ctx)->datamodel->evalAsString(send->targetexpr); + e->target = USER_DATA(ctx)->datamodel.evalAsString(send->targetexpr); } else { e->target = "#_external"; } @@ -296,7 +296,7 @@ int exec_content_send(const scxml_ctx* ctx, const scxml_elem_send* send) { if (send->type != NULL) { e->type = send->type; } else if (send->typeexpr != NULL) { - e->type = USER_DATA(ctx)->datamodel->evalAsString(send->typeexpr); + e->type = USER_DATA(ctx)->datamodel.evalAsString(send->typeexpr); } else { e->type = "http://www.w3.org/TR/scxml/#SCXMLEventProcessor"; } @@ -315,7 +315,7 @@ int exec_content_send(const scxml_ctx* ctx, const scxml_elem_send* send) { e->origintype = e->type; if (send->eventexpr != NULL) { - e->name = USER_DATA(ctx)->datamodel->evalAsString(send->eventexpr); + e->name = USER_DATA(ctx)->datamodel.evalAsString(send->eventexpr); } else { e->name = strdup(send->event); } @@ -325,9 +325,9 @@ int exec_content_send(const scxml_ctx* ctx, const scxml_elem_send* send) { while (param && ELEM_PARAM_IS_SET(param)) { Data paramValue; if (param->expr != NULL) { - paramValue = USER_DATA(ctx)->datamodel->getStringAsData(param->expr); + paramValue = USER_DATA(ctx)->datamodel.getStringAsData(param->expr); } else if(param->location) { - paramValue = USER_DATA(ctx)->datamodel->getStringAsData(param->location); + paramValue = USER_DATA(ctx)->datamodel.getStringAsData(param->location); } e->params.insert(std::make_pair(param->name, paramValue)); param++; @@ -345,7 +345,7 @@ int exec_content_send(const scxml_ctx* ctx, const scxml_elem_send* send) { ePtr++; if (*ePtr == ' ' || *ePtr == '\0') { std::string key(bPtr, ePtr - bPtr); - e->params.insert(std::make_pair(key, USER_DATA(ctx)->datamodel->getStringAsData(key))); + e->params.insert(std::make_pair(key, USER_DATA(ctx)->datamodel.getStringAsData(key))); if (*ePtr == '\0') break; bPtr = ++ePtr; @@ -374,7 +374,7 @@ int exec_content_send(const scxml_ctx* ctx, const scxml_elem_send* send) { } else { sendid = strdup(UUID::getUUID().c_str()); if (send->idlocation != NULL) { - USER_DATA(ctx)->datamodel->assign(send->idlocation, Data(sendid, Data::VERBATIM)); + USER_DATA(ctx)->datamodel.assign(send->idlocation, Data(sendid, Data::VERBATIM)); } else { e->hideSendId = true; } @@ -384,7 +384,7 @@ int exec_content_send(const scxml_ctx* ctx, const scxml_elem_send* send) { size_t delayMs = 0; std::string delay; if (send->delayexpr != NULL) { - delay = USER_DATA(ctx)->datamodel->evalAsString(send->delayexpr); + delay = USER_DATA(ctx)->datamodel.evalAsString(send->delayexpr); } else if (send->delay != NULL) { delay = send->delay; } @@ -424,7 +424,7 @@ int exec_content_init(const scxml_ctx* ctx, const scxml_elem_data* data) { d = Data("undefined", Data::INTERPRETED); } try { - USER_DATA(ctx)->datamodel->init(data->id, d); + USER_DATA(ctx)->datamodel.init(data->id, d); } catch (Event e) { exec_content_raise(ctx, e.name.c_str()); } @@ -442,7 +442,7 @@ int exec_content_assign(const scxml_ctx* ctx, const char* location, const char* try { Data d(expr, Data::INTERPRETED); - USER_DATA(ctx)->datamodel->assign(key, d); + USER_DATA(ctx)->datamodel.assign(key, d); } catch (Event e) { exec_content_raise(ctx, e.name.c_str()); return SCXML_ERR_EXEC_CONTENT; @@ -455,7 +455,7 @@ int exec_content_foreach_init(const scxml_ctx* ctx, const scxml_elem_foreach* fo scxml_foreach_info* feInfo = (scxml_foreach_info*)malloc(sizeof(scxml_foreach_info)); USER_DATA(ctx)->foreachInfo[foreach] = feInfo; - feInfo->iterations = USER_DATA(ctx)->datamodel->getLength(foreach->array); + feInfo->iterations = USER_DATA(ctx)->datamodel.getLength(foreach->array); feInfo->currIteration = 0; } catch (Event e) { exec_content_raise(ctx, e.name.c_str()); @@ -468,7 +468,7 @@ int exec_content_foreach_next(const scxml_ctx* ctx, const scxml_elem_foreach* fo try { scxml_foreach_info* feInfo = USER_DATA(ctx)->foreachInfo[foreach]; if (feInfo->currIteration < feInfo->iterations) { - USER_DATA(ctx)->datamodel->setForeach((foreach->item != NULL ? foreach->item : ""), + USER_DATA(ctx)->datamodel.setForeach((foreach->item != NULL ? foreach->item : ""), (foreach->array != NULL ? foreach->array : ""), (foreach->index != NULL ? foreach->index : ""), feInfo->currIteration); @@ -493,9 +493,9 @@ int exec_content_foreach_done(const scxml_ctx* ctx, const scxml_elem_foreach* fo int exec_content_log(const scxml_ctx* ctx, const char* label, const char* expr) { try { if (label != 0) { -// printf("%s: %s\n", label, USER_DATA(ctx)->datamodel->evalAsString(expr).c_str()); +// printf("%s: %s\n", label, USER_DATA(ctx)->datamodel.evalAsString(expr).c_str()); } else { -// printf("%s\n", USER_DATA(ctx)->datamodel->evalAsString(expr).c_str()); +// printf("%s\n", USER_DATA(ctx)->datamodel.evalAsString(expr).c_str()); } } catch (Event e) { exec_content_raise(ctx, e.name.c_str()); @@ -507,7 +507,7 @@ int exec_content_log(const scxml_ctx* ctx, const char* label, const char* expr) int exec_content_script(const scxml_ctx* ctx, const char* src, const char* content) { if (content != NULL) { - USER_DATA(ctx)->datamodel->eval(Arabica::DOM::Element(), content); + USER_DATA(ctx)->datamodel.eval(Arabica::DOM::Element(), content); } else if (src != NULL) { return SCXML_ERR_UNSUPPORTED; } @@ -521,7 +521,7 @@ void* dequeue_external(const scxml_ctx* ctx) { } Event* e = USER_DATA(ctx)->eq.front(); USER_DATA(ctx)->eq.pop_front(); - USER_DATA(ctx)->datamodel->setEvent(*e); + USER_DATA(ctx)->datamodel.setEvent(*e); #ifdef SCXML_VERBOSE printf("Popping External Event: %s\n", e->name.c_str()); #endif @@ -533,7 +533,7 @@ void* dequeue_internal(const scxml_ctx* ctx) { return NULL; Event* e = USER_DATA(ctx)->iq.front(); USER_DATA(ctx)->iq.pop_front(); - USER_DATA(ctx)->datamodel->setEvent(*e); + USER_DATA(ctx)->datamodel.setEvent(*e); #ifdef SCXML_VERBOSE printf("Popping Internal Event: %s\n", e->name.c_str()); #endif @@ -627,8 +627,8 @@ int main(int argc, char** argv) { t.stop(); avg += t.elapsed; #ifdef BUILD_PROFILING - avgDm += interpreterInfo.datamodel.get()->timer.elapsed; - interpreterInfo.datamodel.get()->timer.elapsed = 0; + avgDm += interpreterInfo.datamodel.timer.elapsed; + interpreterInfo.datamodel.timer.elapsed = 0; #endif size_t passIdx = 0; for (int i = 0; i < SCXML_NUMBER_STATES; i++) { diff --git a/test/src/test-c-machine.machine.c b/test/src/test-c-machine.machine.c index 3663eac..be14d3e 100644 --- a/test/src/test-c-machine.machine.c +++ b/test/src/test-c-machine.machine.c @@ -5,8 +5,8 @@ #define SET_BIT(idx, bitset) bitset[idx >> 3] |= (1 << (idx & 7)); #define CLEARBIT(idx, bitset) bitset[idx >> 3] &= (1 << (idx & 7)) ^ 0xFF; -#define likely(x) (__builtin_expect (!!(x), 1)) -#define unlikely(x) (__builtin_expect (!!(x), 0)) +#define likely(x) (x) +#define unlikely(x) (x) // error return codes #define SCXML_ERR_OK 0 @@ -20,8 +20,8 @@ #define SCXML_ERR_UNSUPPORTED 8 #define SCXML_MACHINE_NAME "" -#define SCXML_NUMBER_STATES 14 -#define SCXML_NUMBER_TRANSITIONS 10 +#define SCXML_NUMBER_STATES 5 +#define SCXML_NUMBER_TRANSITIONS 4 #define SCXML_TRANS_SPONTANEOUS 0x01 #define SCXML_TRANS_TARGETLESS 0x02 @@ -91,22 +91,22 @@ struct scxml_state { exec_content_t on_entry; // on entry handlers exec_content_t on_exit; // on exit handlers invoke_t invoke; // invocations - char children[2]; // all children - char completion[2]; // default completion - char ancestors[2]; // all ancestors + char children[1]; // all children + char completion[1]; // default completion + char ancestors[1]; // all ancestors const scxml_elem_data* data; uint8_t type; // atomic, parallel, compound, final, history }; struct scxml_transition { uint16_t source; - char target[2]; + char target[1]; const char* event; const char* condition; exec_content_t on_transition; uint8_t type; - char conflicts[2]; - char exit_set[2]; + char conflicts[1]; + char exit_set[1]; }; struct scxml_elem_foreach { @@ -165,10 +165,10 @@ struct scxml_elem_send { struct scxml_ctx { uint8_t flags; - char config[2]; - char history[2]; - char pending_invokes[2]; - char initialized_data[2]; + char config[1]; + char history[1]; + char pending_invokes[1]; + char initialized_data[1]; void* user_data; @@ -191,87 +191,23 @@ struct scxml_ctx { invoke_t invoke; }; -static scxml_elem_data scxml_elem_datas[2] = { - { "Var1", NULL, "0", NULL }, - { NULL, NULL, NULL, NULL } -}; - -static scxml_elem_send scxml_elem_sends[1] = { - { "timeout", NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2s", NULL, NULL, NULL, NULL, NULL, NULL } -}; - static int s0_on_entry_0(const scxml_ctx* ctx, const scxml_state* state, const void* event) { int err = SCXML_ERR_OK; - if likely(ctx->exec_content_assign != NULL) { - if ((ctx->exec_content_assign(ctx, "Var1", "Var1 + 1")) != SCXML_ERR_OK) return err; - } else { - return SCXML_ERR_MISSING_CALLBACK; - } - return SCXML_ERR_OK; -} - -static int s0_on_entry(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - s0_on_entry_0(ctx, state, event); - return SCXML_ERR_OK; -} - -static int s011_on_entry_0(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - int err = SCXML_ERR_OK; - if likely(ctx->exec_content_raise != NULL) { - if ((ctx->exec_content_raise(ctx, "entering.s011")) != SCXML_ERR_OK) return err; - } else { - return SCXML_ERR_MISSING_CALLBACK; - } - return SCXML_ERR_OK; -} - -static int s011_on_entry(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - s011_on_entry_0(ctx, state, event); - return SCXML_ERR_OK; -} - -static int s012_on_entry_0(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - int err = SCXML_ERR_OK; if likely(ctx->exec_content_raise != NULL) { - if ((ctx->exec_content_raise(ctx, "entering.s012")) != SCXML_ERR_OK) return err; + if ((ctx->exec_content_raise(ctx, "foo")) != SCXML_ERR_OK) return err; } else { return SCXML_ERR_MISSING_CALLBACK; } - return SCXML_ERR_OK; -} - -static int s012_on_entry(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - s012_on_entry_0(ctx, state, event); - return SCXML_ERR_OK; -} - -static int s021_on_entry_0(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - int err = SCXML_ERR_OK; if likely(ctx->exec_content_raise != NULL) { - if ((ctx->exec_content_raise(ctx, "entering.s021")) != SCXML_ERR_OK) return err; + if ((ctx->exec_content_raise(ctx, "bar")) != SCXML_ERR_OK) return err; } else { return SCXML_ERR_MISSING_CALLBACK; } return SCXML_ERR_OK; } -static int s021_on_entry(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - s021_on_entry_0(ctx, state, event); - return SCXML_ERR_OK; -} - -static int s022_on_entry_0(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - int err = SCXML_ERR_OK; - if likely(ctx->exec_content_raise != NULL) { - if ((ctx->exec_content_raise(ctx, "entering.s022")) != SCXML_ERR_OK) return err; - } else { - return SCXML_ERR_MISSING_CALLBACK; - } - return SCXML_ERR_OK; -} - -static int s022_on_entry(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - s022_on_entry_0(ctx, state, event); +static int s0_on_entry(const scxml_ctx* ctx, const scxml_state* state, const void* event) { + s0_on_entry_0(ctx, state, event); return SCXML_ERR_OK; } @@ -305,44 +241,19 @@ static int fail_on_entry(const scxml_ctx* ctx, const scxml_state* state, const v return SCXML_ERR_OK; } -static int s0_transition0_on_trans(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - int err = SCXML_ERR_OK; - if likely(ctx->exec_content_send != NULL) { - if ((ctx->exec_content_send(ctx, &scxml_elem_sends[0])) != SCXML_ERR_OK) return err; - } else { - return SCXML_ERR_MISSING_CALLBACK; - } - return SCXML_ERR_OK; -} - -static scxml_state scxml_states[14] = { - { NULL, 0, NULL, NULL, NULL, { 0x02, 0x3c /* 01000000001111, 1 10 11 12 13 */ }, { 0x40, 0x00 /* 00000010000000, 6 */ }, { 0x00, 0x00 /* 00000000000000, */ }, (const scxml_elem_data*)&scxml_elem_datas[0], SCXML_STATE_COMPOUND }, - { "s0", 0, s0_on_entry, NULL, NULL, { 0x9c, 0x00 /* 00111001000000, 2 3 4 7 */ }, { 0x10, 0x00 /* 00001000000000, 4 */ }, { 0x01, 0x00 /* 10000000000000, 0 */ }, NULL, SCXML_STATE_COMPOUND }, - { "s0HistShallow", 1, NULL, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x90, 0x00 /* 00001001000000, 4 7 */ }, { 0x03, 0x00 /* 11000000000000, 0 1 */ }, NULL, SCXML_STATE_HISTORY_SHALLOW }, - { "s0HistDeep", 1, NULL, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0xf0, 0x03 /* 00001111110000, 4 5 6 7 8 9 */ }, { 0x03, 0x00 /* 11000000000000, 0 1 */ }, NULL, SCXML_STATE_HISTORY_DEEP }, - { "s01", 1, NULL, NULL, NULL, { 0x60, 0x00 /* 00000110000000, 5 6 */ }, { 0x20, 0x00 /* 00000100000000, 5 */ }, { 0x03, 0x00 /* 11000000000000, 0 1 */ }, NULL, SCXML_STATE_COMPOUND }, - { "s011", 4, s011_on_entry, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x00, 0x00 /* 00000000000000, */ }, { 0x13, 0x00 /* 11001000000000, 0 1 4 */ }, NULL, SCXML_STATE_ATOMIC }, - { "s012", 4, s012_on_entry, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x00, 0x00 /* 00000000000000, */ }, { 0x13, 0x00 /* 11001000000000, 0 1 4 */ }, NULL, SCXML_STATE_ATOMIC }, - { "s02", 1, NULL, NULL, NULL, { 0x00, 0x03 /* 00000000110000, 8 9 */ }, { 0x00, 0x01 /* 00000000100000, 8 */ }, { 0x03, 0x00 /* 11000000000000, 0 1 */ }, NULL, SCXML_STATE_COMPOUND }, - { "s021", 7, s021_on_entry, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x00, 0x00 /* 00000000000000, */ }, { 0x83, 0x00 /* 11000001000000, 0 1 7 */ }, NULL, SCXML_STATE_ATOMIC }, - { "s022", 7, s022_on_entry, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x00, 0x00 /* 00000000000000, */ }, { 0x83, 0x00 /* 11000001000000, 0 1 7 */ }, NULL, SCXML_STATE_ATOMIC }, - { "s1", 0, NULL, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x00, 0x00 /* 00000000000000, */ }, { 0x01, 0x00 /* 10000000000000, 0 */ }, NULL, SCXML_STATE_ATOMIC }, - { "s2", 0, NULL, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x00, 0x00 /* 00000000000000, */ }, { 0x01, 0x00 /* 10000000000000, 0 */ }, NULL, SCXML_STATE_ATOMIC }, - { "pass", 0, pass_on_entry, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x00, 0x00 /* 00000000000000, */ }, { 0x01, 0x00 /* 10000000000000, 0 */ }, NULL, SCXML_STATE_FINAL }, - { "fail", 0, fail_on_entry, NULL, NULL, { 0x00, 0x00 /* 00000000000000, */ }, { 0x00, 0x00 /* 00000000000000, */ }, { 0x01, 0x00 /* 10000000000000, 0 */ }, NULL, SCXML_STATE_FINAL } +static scxml_state scxml_states[5] = { + { NULL, 0, NULL, NULL, NULL, { 0x1e /* 01111, 1 2 3 4 */ }, { 0x02 /* 01000, 1 */ }, { 0x00 /* 00000, */ }, NULL, SCXML_STATE_COMPOUND }, + { "s0", 0, s0_on_entry, NULL, NULL, { 0x00 /* 00000, */ }, { 0x00 /* 00000, */ }, { 0x01 /* 10000, 0 */ }, NULL, SCXML_STATE_ATOMIC }, + { "s1", 0, NULL, NULL, NULL, { 0x00 /* 00000, */ }, { 0x00 /* 00000, */ }, { 0x01 /* 10000, 0 */ }, NULL, SCXML_STATE_ATOMIC }, + { "pass", 0, pass_on_entry, NULL, NULL, { 0x00 /* 00000, */ }, { 0x00 /* 00000, */ }, { 0x01 /* 10000, 0 */ }, NULL, SCXML_STATE_FINAL }, + { "fail", 0, fail_on_entry, NULL, NULL, { 0x00 /* 00000, */ }, { 0x00 /* 00000, */ }, { 0x01 /* 10000, 0 */ }, NULL, SCXML_STATE_FINAL } }; -static scxml_transition scxml_transitions[10] = { - { 2, { 0x80, 0x00 /* 00000001000000 */ }, NULL, NULL, NULL, SCXML_TRANS_SPONTANEOUS | SCXML_TRANS_HISTORY, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 3, { 0x00, 0x02 /* 00000000010000 */ }, NULL, NULL, NULL, SCXML_TRANS_SPONTANEOUS | SCXML_TRANS_HISTORY, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 1, { 0x00, 0x04 /* 00000000001000 */ }, "entering.s012", "Var1==1", s0_transition0_on_trans, 0, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 1, { 0x00, 0x08 /* 00000000000100 */ }, "entering.s012", "Var1==2", NULL, 0, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 1, { 0x00, 0x20 /* 00000000000001 */ }, "entering", "Var1==2", NULL, 0, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 1, { 0x00, 0x10 /* 00000000000010 */ }, "entering.s011", "Var1==3", NULL, 0, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 1, { 0x00, 0x20 /* 00000000000001 */ }, "entering", "Var1==3", NULL, 0, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 1, { 0x00, 0x20 /* 00000000000001 */ }, "timeout", NULL, NULL, 0, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 10, { 0x08, 0x00 /* 00010000000000 */ }, NULL, NULL, NULL, SCXML_TRANS_SPONTANEOUS, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } }, - { 11, { 0x04, 0x00 /* 00100000000000 */ }, NULL, NULL, NULL, SCXML_TRANS_SPONTANEOUS, { 0xff, 0x03 /* 1111111111 */ }, { 0xfe, 0x3f /* 01111111111111 */ } } +static scxml_transition scxml_transitions[4] = { + { 1, { 0x04 /* 00100 */ }, "foo", NULL, NULL, 0, { 0x0f /* 1111 */ }, { 0x1e /* 01111 */ } }, + { 1, { 0x10 /* 00001 */ }, "*", NULL, NULL, 0, { 0x0f /* 1111 */ }, { 0x1e /* 01111 */ } }, + { 2, { 0x08 /* 00010 */ }, "bar", NULL, NULL, 0, { 0x0f /* 1111 */ }, { 0x1e /* 01111 */ } }, + { 2, { 0x10 /* 00001 */ }, "*", NULL, NULL, 0, { 0x0f /* 1111 */ }, { 0x1e /* 01111 */ } } }; #ifdef SCXML_VERBOSE @@ -423,15 +334,15 @@ MACRO_STEP: return SCXML_ERR_DONE; int err = SCXML_ERR_OK; - char conflicts[2] = {0, 0}; - char target_set[2] = {0, 0}; - char exit_set[2] = {0, 0}; - char trans_set[2] = {0, 0}; - char entry_set[2] = {0, 0}; + char conflicts[1] = {0}; + char target_set[1] = {0}; + char exit_set[1] = {0}; + char trans_set[1] = {0}; + char entry_set[1] = {0}; void* event; if unlikely(ctx->flags == SCXML_CTX_PRISTINE) { - bit_or(target_set, scxml_states[0].completion, 2); + bit_or(target_set, scxml_states[0].completion, 1); ctx->flags |= SCXML_CTX_SPONTANEOUS | SCXML_CTX_INITIALIZED; goto COMPLETE_CONFIG; } @@ -463,20 +374,20 @@ SELECT_TRANSITIONS: ctx->flags |= SCXML_CTX_TRANSITION_FOUND; // transitions that are pre-empted - bit_or(conflicts, scxml_transitions[i].conflicts, 2); + bit_or(conflicts, scxml_transitions[i].conflicts, 1); // states that are directly targeted (resolve as entry-set later) - bit_or(target_set, scxml_transitions[i].target, 2); + bit_or(target_set, scxml_transitions[i].target, 1); // states that will be left - bit_or(exit_set, scxml_transitions[i].exit_set, 2); + bit_or(exit_set, scxml_transitions[i].exit_set, 1); SET_BIT(i, trans_set); } } } } - bit_and(exit_set, ctx->config, 2); + bit_and(exit_set, ctx->config, 1); if (ctx->flags & SCXML_CTX_TRANSITION_FOUND) { ctx->flags |= SCXML_CTX_SPONTANEOUS; @@ -496,17 +407,17 @@ REMEMBER_HISTORY: if unlikely(scxml_states[i].type == SCXML_STATE_HISTORY_SHALLOW || scxml_states[i].type == SCXML_STATE_HISTORY_DEEP) { // a history state whose parent is about to be exited if unlikely(IS_SET(scxml_states[i].source, exit_set)) { - char history[2] = {0, 0}; - bit_copy(history, scxml_states[i].completion, 2); + char history[1] = {0}; + bit_copy(history, scxml_states[i].completion, 1); // set those states who were enabled - bit_and(history, ctx->config, 2); + bit_and(history, ctx->config, 1); // clear current history with completion mask - bit_and_not(ctx->history, scxml_states[i].completion, 2); + bit_and_not(ctx->history, scxml_states[i].completion, 1); // set history - bit_or(ctx->history, history, 2); + bit_or(ctx->history, history, 1); } } } @@ -534,12 +445,12 @@ EXIT_STATES: COMPLETE_CONFIG: // calculate new entry set - bit_copy(entry_set, target_set, 2); + bit_copy(entry_set, target_set, 1); // iterate for ancestors for (int i = 0; i < SCXML_NUMBER_STATES; i++) { if (IS_SET(i, entry_set)) { - bit_or(entry_set, scxml_states[i].ancestors, 2); + bit_or(entry_set, scxml_states[i].ancestors, 1); } } @@ -549,26 +460,26 @@ ADD_DESCENDANTS: if (IS_SET(i, entry_set)) { switch (scxml_states[i].type) { case SCXML_STATE_PARALLEL: { - bit_or(entry_set, scxml_states[i].completion, 2); + bit_or(entry_set, scxml_states[i].completion, 1); break; } case SCXML_STATE_HISTORY_SHALLOW: case SCXML_STATE_HISTORY_DEEP: { - char history_targets[2] = {0, 0}; - if (!bit_has_and(scxml_states[i].completion, ctx->history, 2)) { + char history_targets[1] = {0}; + if (!bit_has_and(scxml_states[i].completion, ctx->history, 1)) { // nothing set for history, look for a default transition or enter parents completion for (int j = 0; j < SCXML_NUMBER_TRANSITIONS; j++) { if unlikely(scxml_transitions[j].source == i) { - bit_or(entry_set, scxml_transitions[j].target, 2); + bit_or(entry_set, scxml_transitions[j].target, 1); SET_BIT(j, trans_set); break; } } // TODO: enter parents default completion here } else { - bit_copy(history_targets, scxml_states[i].completion, 2); - bit_and(history_targets, ctx->history, 2); - bit_or(entry_set, history_targets, 2); + bit_copy(history_targets, scxml_states[i].completion, 1); + bit_and(history_targets, ctx->history, 1); + bit_or(entry_set, history_targets, 1); } break; } @@ -577,7 +488,7 @@ ADD_DESCENDANTS: if (scxml_transitions[j].source == i) { SET_BIT(j, trans_set); CLEARBIT(i, entry_set); - bit_or(entry_set, scxml_transitions[j].target, 2); + bit_or(entry_set, scxml_transitions[j].target, 1); // one target may have been above, reestablish completion // goto ADD_DESCENDANTS; // initial will have to be first! } @@ -585,10 +496,10 @@ ADD_DESCENDANTS: break; } case SCXML_STATE_COMPOUND: { // we need to check whether one child is already in entry_set - if (!bit_has_and(entry_set, scxml_states[i].children, 2) && - !bit_has_and(ctx->config, scxml_states[i].children, 2)) + if (!bit_has_and(entry_set, scxml_states[i].children, 1) && + !bit_has_and(ctx->config, scxml_states[i].children, 1)) { - bit_or(entry_set, scxml_states[i].completion, 2); + bit_or(entry_set, scxml_states[i].completion, 1); } break; } @@ -598,7 +509,7 @@ ADD_DESCENDANTS: #ifdef SCXML_VERBOSE printf("Transitions: "); - printBitsetIndices(trans_set, sizeof(char) * 8 * 2); + printBitsetIndices(trans_set, sizeof(char) * 8 * 1); #endif TAKE_TRANSITIONS: @@ -670,18 +581,18 @@ ENTER_STATES: */ for (int j = 0; j < SCXML_NUMBER_STATES; j++) { if unlikely(scxml_states[j].type == SCXML_STATE_PARALLEL) { - char parallel_children[2] = {0, 0}; + char parallel_children[1] = {0}; size_t parallel = j; for (int k = 0; k < SCXML_NUMBER_STATES; k++) { if unlikely(IS_SET(parallel, scxml_states[k].ancestors) && IS_SET(k, ctx->config)) { if (scxml_states[k].type == SCXML_STATE_FINAL) { - bit_and_not(parallel_children, scxml_states[k].ancestors, 2); + bit_and_not(parallel_children, scxml_states[k].ancestors, 1); } else { SET_BIT(k, parallel_children); } } } - if unlikely(!bit_any_set(parallel_children, 2)) { + if unlikely(!bit_any_set(parallel_children, 1)) { ctx->raise_done_event(ctx, &scxml_states[parallel], NULL); } } diff --git a/test/src/test-w3c.cpp b/test/src/test-w3c.cpp index a44fb57..2c2f4da 100644 --- a/test/src/test-w3c.cpp +++ b/test/src/test-w3c.cpp @@ -1,7 +1,8 @@ // I feel dirty, but we need to access the datamodel timer -#define protected public +// #define protected public #include "uscxml/config.h" +#include "uscxml/Common.h" #include "uscxml/Convenience.h" #include "uscxml/Interpreter.h" #include "uscxml/DOMUtils.h" @@ -181,9 +182,9 @@ int main(int argc, char** argv) { state = interpreter.step(true); if (state == USCXML_FINISHED) { #ifdef BUILD_PROFILING - avgDm += interpreter.getDataModel()._impl.get()->timer.elapsed; - interpreter.getDataModel()._impl.get()->timer.elapsed = 0; - avgStep += interpreter.getImpl()->timer.elapsed; + avgDm += interpreter.getDataModel().timer.elapsed; + interpreter.getDataModel().timer.reset(); + avgStep += interpreter.timer.elapsed; #endif } if (state < 0) -- cgit v0.12