From 72fb2cd0bd89eb40d4a96f86d464d9801ad91f59 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 12 Apr 2013 17:10:36 +0200 Subject: Got prolog datamodel to compile again --- CMakeLists.txt | 11 +++- contrib/cmake/FindSWI.cmake | 8 +++ contrib/ctest/common.ctest.inc | 16 ++--- src/bindings/swig/php/uscxmlNativePHP.php | 4 ++ src/uscxml/Interpreter.cpp | 72 ---------------------- src/uscxml/Message.cpp | 5 +- .../plugins/datamodel/prolog/swi/SWIDataModel.cpp | 37 ++++------- .../plugins/datamodel/prolog/swi/SWIDataModel.h | 29 +++------ .../plugins/datamodel/xpath/XPathDataModel.cpp | 25 +++++++- test/samples/w3c/ecma/test568.scxml | 4 +- 10 files changed, 81 insertions(+), 130 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd72602..9989b38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,7 +178,12 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") # order of arguments of gcc matters again # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") add_definitions(-fPIC) - + add_definitions(-Wunreachable-code) + + # coverage information + add_definitions(-fprofile-arcs) + add_definitions(-ftest-coverage) + # all warnings add_definitions(-Wall) # add_definitions(-Wno-parentheses-equality) @@ -194,8 +199,8 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") # swig will throw a warning with optimization otherwise add_definitions(-fno-strict-aliasing) - add_definitions("-Wno-unused-value -Wno-unused-function -Wno-sign-compare") - + add_definitions("-Wno-unused-value -Wno-sign-compare") +# add_definitions(-Wno-unused-function) if (NOT CMAKE_BUILD_TYPE MATCHES ".*Deb.*") # when not building for debug # add_definitions("-s") #set(CMAKE_CXX_FLAGS "-s") ## Strip binary for everything but debug builds diff --git a/contrib/cmake/FindSWI.cmake b/contrib/cmake/FindSWI.cmake index 1106633..3a10269 100644 --- a/contrib/cmake/FindSWI.cmake +++ b/contrib/cmake/FindSWI.cmake @@ -47,6 +47,8 @@ foreach(SWI_SEARCH_PATH ${SWI_SEARCH_PATHS}) endif() endforeach() +#message("SWI_VERSION: ${SWI_VERSION}") + # -- find prolog headers FIND_PATH(SWI_INCLUDE_DIR SWI-Prolog.h PATH_SUFFIXES @@ -55,6 +57,8 @@ FIND_PATH(SWI_INCLUDE_DIR SWI-Prolog.h PATHS ${SWI_SEARCH_PATHS} ) +#message("SWI_INCLUDE_DIR: ${SWI_INCLUDE_DIR}") + FIND_PATH(SWI_CPP_INCLUDE_DIR SWI-cpp.h PATH_SUFFIXES packages/cpp @@ -62,6 +66,8 @@ FIND_PATH(SWI_CPP_INCLUDE_DIR SWI-cpp.h PATHS ${SWI_SEARCH_PATHS} ) +#message("SWI_CPP_INCLUDE_DIR: ${SWI_CPP_INCLUDE_DIR}") + FIND_PROGRAM(SWI_BINARY swipl PATH_SUFFIXES src @@ -69,6 +75,8 @@ FIND_PROGRAM(SWI_BINARY swipl PATHS ${SWI_SEARCH_PATHS} ) +#message("SWI_BINARY: ${SWI_BINARY}") + FIND_LIBRARY(SWI_LIBRARY_RELEASE NAMES libswipl swipl PATH_SUFFIXES diff --git a/contrib/ctest/common.ctest.inc b/contrib/ctest/common.ctest.inc index 4fa5829..6a6f286 100644 --- a/contrib/ctest/common.ctest.inc +++ b/contrib/ctest/common.ctest.inc @@ -36,8 +36,8 @@ set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 1048576) ### Coverage and Memory checks? (untested) ################################ -#set(WITH_COVERAGE TRUE) -#find_program(CTEST_COVERAGE_COMMAND NAMES gcov) +set(WITH_COVERAGE TRUE) +find_program(CTEST_COVERAGE_COMMAND NAMES gcov) #set(WITH_MEMCHECK TRUE) #find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind) @@ -71,9 +71,9 @@ set(CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"${CTEST_SOURCE_DIRECTO ### Test! ################################################################ # clean build directory for everything but continuous tests -if (NOT ${CTEST_SUBMIT_TYPE} MATCHES ".*Continuous.*") +#if (NOT ${CTEST_SUBMIT_TYPE} MATCHES ".*Continuous.*") ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY}) -endif() +#endif() ctest_start(${CTEST_SUBMIT_TYPE}) # start testing # @@ -106,11 +106,11 @@ endif() ctest_build() # build custom target that depends on all the actual tests ctest_test() # run tests -if (WITH_MEMCHECK AND CTEST_COVERAGE_COMMAND) +if(CTEST_COVERAGE_COMMAND) ctest_coverage() -endif (WITH_MEMCHECK AND CTEST_COVERAGE_COMMAND) -if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND) +endif() +if (WITH_MEMCHECK) ctest_memcheck() -endif (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND) +endif() ctest_submit() # submit diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php index c15f979..eb66b3d 100644 --- a/src/bindings/swig/php/uscxmlNativePHP.php +++ b/src/bindings/swig/php/uscxmlNativePHP.php @@ -769,6 +769,10 @@ class Interpreter { return $r; } + static function spaceNormalize($text) { + return Interpreter_spaceNormalize($text); + } + function isInitial($state) { return Interpreter_isInitial($this->_cPtr,$state); } diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 7fe5cc1..b314d1a 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -471,78 +471,6 @@ void InterpreterImpl::processContentElement(const Arabica::DOM::Node contentChild = content.getFirstChild(); - while(contentChild) { - if (contentChild.getNodeType() == Node_base::TEXT_NODE) { - std::string trimmed = contentChild.getNodeValue(); - boost::trim(trimmed); - if (trimmed.length() > 0) - break; - } - if (contentChild.getNodeType() == Node_base::ELEMENT_NODE) { - presentAsDom = true; - break; - } - contentChild = contentChild.getNextSibling(); - } - - if (contentChild && presentAsDom) { - // use the whole dom - DOMImplementation domFactory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); - dom = domFactory.createDocument(contentChild.getNamespaceURI(), "", 0); - Node newNode = dom.importNode(contentChild, true); - dom.appendChild(newNode); - } else if (contentChild) { - contentToProcess = contentChild.getNodeValue(); - } else { - LOG(ERROR) << "content element has neither text nor element children."; - } - } else { - LOG(ERROR) << "content element does not specify any content."; - } - if (contentToProcess.size() > 0) { - /// try to interpret as JSON - std::string trimmedContent = contentToProcess; - boost::trim(trimmedContent); - if (trimmedContent.find_first_of("{[") == 0) { - data = Data::fromJSON(contentToProcess); - if (data) - return; - } - /// create space normalized string - std::istringstream iss(contentToProcess); - std::stringstream content; - std::string seperator; - do { - std::string token; - iss >> token; - if (token.length() > 0) { - content << seperator << token; - seperator = " "; - } - } while (iss); - text = content.str(); - } - } catch (Event e) { - e.name = "error.execution"; - receiveInternal(e); - } -#endif } void InterpreterImpl::processDOMorText(const Arabica::DOM::Node& node, diff --git a/src/uscxml/Message.cpp b/src/uscxml/Message.cpp index 0898cc7..c3f4281 100644 --- a/src/uscxml/Message.cpp +++ b/src/uscxml/Message.cpp @@ -188,13 +188,16 @@ Data Data::fromJSON(const std::string& jsonString) { if (trimmed.length() == 0) return data; + if (trimmed.find_first_of("{[") != 0) + return data; + jsmn_parser p; jsmntok_t* t = NULL; // we do not know the number of tokens beforehand, start with something sensible and increase int rv; - int frac = 16; // this will get decreased to 16 to first iteration for 1/16 length/token ratio + int frac = 16; // length/token ratio do { jsmn_init(&p); diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index f3af4b6..fcd606d 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -134,38 +134,25 @@ std::string SWIDataModel::evalAsString(const std::string& expr) { return std::string(compound); } -void SWIDataModel::assign(const std::string& location, +void SWIDataModel::assign(const Arabica::DOM::Element& assignElem, const Arabica::DOM::Document& doc, - const Arabica::DOM::Element& assignElem) { - + const std::string& content) { + std::string expr = content; + if (HAS_ATTR(assignElem, "expr")) { + expr = ATTR(assignElem, "expr"); + } + if (expr.length() > 0) + eval(expr); } -void SWIDataModel::assign(const std::string& location, - const std::string& expr, - const Arabica::DOM::Element& assignElem) { - eval(expr); -} -void SWIDataModel::assign(const std::string& location, - const Data& data, - const Arabica::DOM::Element& assignElem) { +void SWIDataModel::assign(const std::string& location, const Data& data) { eval(data.atom); } -void SWIDataModel::init(const std::string& location, +void SWIDataModel::init(const Arabica::DOM::Element& dataElem, const Arabica::DOM::Document& doc, - const Arabica::DOM::Element& dataElem) { - -} -void SWIDataModel::init(const std::string& location, - const std::string& expr, - const Arabica::DOM::Element& dataElem) { - -} -void SWIDataModel::init(const std::string& location, - const Data& data, - const Arabica::DOM::Element& dataElem) { - -} + const std::string& content) {} +void SWIDataModel::init(const std::string& location, const Data& data) {} bool SWIDataModel::isDeclared(const std::string& expr) { return true; diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index 5d95476..a278db8 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -36,6 +36,16 @@ public: virtual void pushContext(); virtual void popContext(); + virtual void assign(const Arabica::DOM::Element& assignElem, + const Arabica::DOM::Document& doc, + const std::string& content); + virtual void assign(const std::string& location, const Data& data); + + virtual void init(const Arabica::DOM::Element& dataElem, + const Arabica::DOM::Document& doc, + const std::string& content); + virtual void init(const std::string& location, const Data& data); + virtual void eval(const std::string& expr); virtual bool isDeclared(const std::string& expr); @@ -44,25 +54,6 @@ public: virtual std::string evalAsString(const std::string& expr); virtual bool evalAsBool(const std::string& expr); - virtual void assign(const std::string& location, - const Arabica::DOM::Document& doc, - const Arabica::DOM::Element& assignElem); - virtual void assign(const std::string& location, - const std::string& expr, - const Arabica::DOM::Element& assignElem); - virtual void assign(const std::string& location, - const Data& data, - const Arabica::DOM::Element& assignElem); - - virtual void init(const std::string& location, - const Arabica::DOM::Document& doc, - const Arabica::DOM::Element& dataElem); - virtual void init(const std::string& location, - const std::string& expr, - const Arabica::DOM::Element& dataElem); - virtual void init(const std::string& location, - const Data& data, - const Arabica::DOM::Element& dataElem); protected: Event _event; diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp index eef8e51..0c649f5 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp @@ -187,7 +187,30 @@ bool XPathDataModel::evalAsBool(const std::string& expr) { std::string XPathDataModel::evalAsString(const std::string& expr) { XPathValue result = _xpath.evaluate_expr(expr, _doc); - return result.asString(); + switch (result.type()) { + case STRING: + return result.asString(); + break; + case BOOL: + return (result.asBool() ? "true" : "false"); + break; + case NUMBER: + return toStr(result.asNumber()); + break; + case NODE_SET: { + NodeSet nodeSet = result.asNodeSet(); + std::stringstream ss; + for (int i = 0; i < nodeSet.size(); i++) { + ss << nodeSet[i] << std::endl; + } + return ss.str(); + break; + } + case ANY: + throw Event("error.execution", Event::PLATFORM); + break; + } + return "undefined"; } double XPathDataModel::evalAsNumber(const std::string& expr) { diff --git a/test/samples/w3c/ecma/test568.scxml b/test/samples/w3c/ecma/test568.scxml index 79d7c92..ebfce36 100644 --- a/test/samples/w3c/ecma/test568.scxml +++ b/test/samples/w3c/ecma/test568.scxml @@ -5,7 +5,9 @@ send events. --> - + + + -- cgit v0.12