From 7212d5a3dbbd2845d09df96b2c345132c8a24931 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Tue, 23 Feb 2016 12:28:18 +0100 Subject: Some refactoring for improved compile times --- apps/uscxml-analyze.cpp | 4 +- apps/uscxml-browser.cpp | 2 +- apps/uscxml-dot.cpp | 2 +- apps/uscxml-transform.cpp | 6 +- src/bindings/swig/uscxml_beautify.i | 2 + .../swig/wrapped/WrappedInterpreterMonitor.h | 2 +- src/uscxml/CMakeLists.txt | 9 + src/uscxml/DOMUtils.cpp | 270 ------------------- src/uscxml/DOMUtils.h | 123 --------- src/uscxml/Interpreter.cpp | 271 +++---------------- src/uscxml/Interpreter.h | 33 +-- src/uscxml/Message.cpp | 57 ---- src/uscxml/concurrency/tinythread.h | 2 +- src/uscxml/debug/Breakpoint.cpp | 4 +- src/uscxml/debug/Breakpoint.h | 2 +- src/uscxml/debug/Complexity.cpp | 4 +- src/uscxml/debug/Debugger.cpp | 2 +- src/uscxml/debug/InterpreterIssue.cpp | 52 ++-- src/uscxml/debug/InterpreterIssue.h | 1 + src/uscxml/debug/SCXMLDotWriter.cpp | 12 +- src/uscxml/dom/DOMUtils.cpp | 288 +++++++++++++++++++++ src/uscxml/dom/DOMUtils.h | 111 ++++++++ src/uscxml/dom/NameSpacingParser.cpp | 71 +++++ src/uscxml/dom/NameSpacingParser.h | 67 +++++ src/uscxml/interpreter/InterpreterDraft6.cpp | 24 +- src/uscxml/interpreter/InterpreterFast.cpp | 2 +- src/uscxml/interpreter/InterpreterRC.cpp | 28 +- src/uscxml/messages/Data.cpp | 7 +- src/uscxml/messages/Event.cpp | 5 +- src/uscxml/messages/MMIMessages.cpp | 2 +- src/uscxml/messages/MMIMessages.h | 1 + src/uscxml/plugins/DataModel.h | 13 +- .../datamodel/ecmascript/JavaScriptCore/JSCDOM.h | 2 +- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 10 +- .../ecmascript/JavaScriptCore/JSCDataModel.h | 3 +- .../plugins/datamodel/ecmascript/Storage.cpp | 2 + src/uscxml/plugins/datamodel/ecmascript/Storage.h | 2 - .../plugins/datamodel/ecmascript/TypedArray.h | 2 +- .../datamodel/ecmascript/v8/V8DataModel.cpp | 8 +- .../plugins/datamodel/ecmascript/v8/V8DataModel.h | 2 +- src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 9 +- src/uscxml/plugins/datamodel/lua/LuaDataModel.h | 3 +- .../plugins/datamodel/null/NULLDataModel.cpp | 2 +- src/uscxml/plugins/datamodel/null/NULLDataModel.h | 3 +- .../plugins/datamodel/prolog/swi/SWIDataModel.cpp | 6 +- .../plugins/datamodel/prolog/swi/SWIDataModel.h | 3 +- .../plugins/datamodel/promela/PromelaDataModel.cpp | 5 +- .../plugins/datamodel/promela/PromelaDataModel.h | 3 +- .../plugins/datamodel/xpath/XPathDataModel.cpp | 12 +- .../plugins/datamodel/xpath/XPathDataModel.h | 4 +- src/uscxml/plugins/element/fetch/FetchElement.cpp | 2 +- src/uscxml/plugins/element/file/FileElement.cpp | 3 +- src/uscxml/plugins/element/mmi/MMIEvents.h | 4 +- .../plugins/element/postpone/PostponeElement.cpp | 2 +- .../plugins/element/respond/RespondElement.cpp | 6 +- .../plugins/invoker/heartbeat/HeartbeatInvoker.cpp | 2 +- src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp | 5 +- src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp | 2 +- .../ioprocessor/basichttp/BasicHTTPIOProcessor.cpp | 4 +- src/uscxml/server/HTTPServer.cpp | 3 +- src/uscxml/transform/ChartAnnotator.cpp | 24 ++ src/uscxml/transform/ChartAnnotator.h | 27 ++ src/uscxml/transform/ChartToC.cpp | 209 +++++++-------- src/uscxml/transform/ChartToC.h | 2 +- src/uscxml/transform/ChartToFSM.cpp | 59 ++--- src/uscxml/transform/ChartToFSM.h | 2 +- src/uscxml/transform/ChartToFlatSCXML.cpp | 16 +- src/uscxml/transform/ChartToMinimalSCXML.cpp | 10 +- src/uscxml/transform/ChartToMinimalSCXML.h | 2 +- src/uscxml/transform/ChartToPromela.cpp | 119 ++++----- src/uscxml/transform/ChartToPromela.h | 2 +- src/uscxml/transform/ChartToTex.h | 2 +- src/uscxml/transform/ChartToVHDL.cpp | 10 +- src/uscxml/transform/ChartToVHDL.h | 2 +- src/uscxml/transform/FlatStateIdentifier.h | 2 +- src/uscxml/util/String.cpp | 176 +++++++++++++ src/uscxml/util/String.h | 34 +++ test/CMakeLists.txt | 38 ++- test/ctest/CTestCustom.ctest.in | 9 + test/src/test-arabica-namespaces.cpp | 13 +- test/src/test-arabica-xpath.cpp | 2 +- test/src/test-c-inline.c | 3 +- test/src/test-c-inline.c.scxml.c | 26 +- test/src/test-c-machine.cpp | 2 +- test/src/test-predicates.cpp | 37 +-- test/src/test-promela-parser.cpp | 1 + test/src/test-w3c.cpp | 4 +- 87 files changed, 1334 insertions(+), 1092 deletions(-) delete mode 100644 src/uscxml/DOMUtils.cpp delete mode 100644 src/uscxml/DOMUtils.h delete mode 100644 src/uscxml/Message.cpp create mode 100644 src/uscxml/dom/DOMUtils.cpp create mode 100644 src/uscxml/dom/DOMUtils.h create mode 100644 src/uscxml/dom/NameSpacingParser.cpp create mode 100644 src/uscxml/dom/NameSpacingParser.h create mode 100644 src/uscxml/transform/ChartAnnotator.cpp create mode 100644 src/uscxml/transform/ChartAnnotator.h create mode 100644 src/uscxml/util/String.cpp create mode 100644 src/uscxml/util/String.h diff --git a/apps/uscxml-analyze.cpp b/apps/uscxml-analyze.cpp index 69e403a..33a536a 100644 --- a/apps/uscxml-analyze.cpp +++ b/apps/uscxml-analyze.cpp @@ -2,7 +2,7 @@ #include "uscxml/Interpreter.h" #include "uscxml/debug/Complexity.h" #include "uscxml/transform/ChartToFSM.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #include #include @@ -95,7 +95,7 @@ int main(int argc, char** argv) { pluginPath = optarg; break; case 'a': - aspects = InterpreterImpl::tokenize(optarg, ','); + aspects = tokenize(optarg, ','); break; case 'l': break; diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index 10f52cc..2f416bb 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -1,6 +1,6 @@ #include "uscxml/config.h" #include "uscxml/Interpreter.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #ifndef BUILD_MINIMAL # include "uscxml/debug/DebuggerServlet.h" diff --git a/apps/uscxml-dot.cpp b/apps/uscxml-dot.cpp index e72b2d4..0fcd548 100644 --- a/apps/uscxml-dot.cpp +++ b/apps/uscxml-dot.cpp @@ -1,6 +1,6 @@ #include "uscxml/config.h" #include "uscxml/Interpreter.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/debug/SCXMLDotWriter.h" #include #include "getopt.h" diff --git a/apps/uscxml-transform.cpp b/apps/uscxml-transform.cpp index a5aa9ec..3ef7a83 100644 --- a/apps/uscxml-transform.cpp +++ b/apps/uscxml-transform.cpp @@ -6,7 +6,7 @@ #include "uscxml/transform/ChartToTex.h" #include "uscxml/transform/ChartToMinimalSCXML.h" #include "uscxml/transform/ChartToPromela.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #include @@ -165,10 +165,10 @@ int main(int argc, char** argv) { inputFile = optarg; break; case 'a': - options = InterpreterImpl::tokenize(optarg, ','); + options = tokenize(optarg, ','); break; case 'X': { - std::list extension = InterpreterImpl::tokenize(optarg, '='); + std::list extension = tokenize(optarg, '='); if (extension.size() != 2) printUsageAndExit(argv[0]); std::string key = boost::trim_copy(*(extension.begin())); diff --git a/src/bindings/swig/uscxml_beautify.i b/src/bindings/swig/uscxml_beautify.i index 0350426..eb37fb1 100644 --- a/src/bindings/swig/uscxml_beautify.i +++ b/src/bindings/swig/uscxml_beautify.i @@ -118,6 +118,8 @@ %{ #include + #include "uscxml/dom/NameSpacingParser.h" + %} %extend uscxml::Data { diff --git a/src/bindings/swig/wrapped/WrappedInterpreterMonitor.h b/src/bindings/swig/wrapped/WrappedInterpreterMonitor.h index a63bad5..ed67f7b 100644 --- a/src/bindings/swig/wrapped/WrappedInterpreterMonitor.h +++ b/src/bindings/swig/wrapped/WrappedInterpreterMonitor.h @@ -31,7 +31,7 @@ #include "../../../uscxml/Message.h" #include "../../../uscxml/Factory.h" #include "../../../uscxml/Interpreter.h" -#include "../../../uscxml/DOMUtils.h" +#include "../../../uscxml/dom/DOMUtils.h" namespace uscxml { diff --git a/src/uscxml/CMakeLists.txt b/src/uscxml/CMakeLists.txt index 8e27980..4e76148 100644 --- a/src/uscxml/CMakeLists.txt +++ b/src/uscxml/CMakeLists.txt @@ -18,6 +18,15 @@ file(GLOB_RECURSE USCXML_UTIL source_group("Interpreter" FILES ${USCXML_UTIL}) list (APPEND USCXML_FILES ${USCXML_UTIL}) +file(GLOB_RECURSE USCXML_DOM + dom/*.cpp + dom/*.hpp + dom/*.c + dom/*.h +) +source_group("Interpreter" FILES ${USCXML_DOM}) +list (APPEND USCXML_FILES ${USCXML_DOM}) + file(GLOB_RECURSE USCXML_CONCURRENCY concurrency/*.cpp concurrency/*.h diff --git a/src/uscxml/DOMUtils.cpp b/src/uscxml/DOMUtils.cpp deleted file mode 100644 index 414b5e7..0000000 --- a/src/uscxml/DOMUtils.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/** - * @file - * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) - * @copyright Simplified BSD - * - * @cond - * This program is free software: you can redistribute it and/or modify - * it under the terms of the FreeBSD license as published by the FreeBSD - * project. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the FreeBSD license along with this - * program. If not, see . - * @endcond - */ - -#include -#include "uscxml/UUID.h" -#include "uscxml/DOMUtils.h" -#include -#include -#include - -namespace uscxml { - -using namespace Arabica::XPath; -using namespace Arabica::DOM; - -bool DOMUtils::attributeIsTrue(const::std::string& value) { - return stringIsTrue(value.c_str()); -} - -std::string DOMUtils::idForNode(const Arabica::DOM::Node& node) { - std::string nodeId; - std::string seperator; - Arabica::DOM::Node curr = node; - while(curr) { - switch (curr.getNodeType()) { - case Arabica::DOM::Node_base::ELEMENT_NODE: { - Arabica::DOM::Element elem = Arabica::DOM::Element(curr); - if (HAS_ATTR(elem, "id") && !UUID::isUUID(ATTR(elem, "id"))) { - std::string elementId = ATTR(elem, "id"); - boost::replace_all(elementId, ".", "_"); - boost::replace_all(elementId, ",", "_"); - nodeId.insert(0, elementId + seperator); - seperator = "_"; - return nodeId; - } else { - Arabica::DOM::Node sibling = curr.getPreviousSibling(); - int index = 0; - while(sibling) { - if (sibling.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) { - if (iequals(TAGNAME_CAST(sibling), TAGNAME(elem))) { - index++; - } - } - sibling = sibling.getPreviousSibling(); - } - nodeId.insert(0, TAGNAME(elem) + toStr(index) + seperator); - seperator = "_"; - } - break; - } - case Arabica::DOM::Node_base::DOCUMENT_NODE: - return nodeId; - } - - curr = curr.getParentNode(); - } - return nodeId; -} - -std::string DOMUtils::xPathForNode(const Arabica::DOM::Node& node, const std::string& ns) { - std::string xPath; - std::string nsPrefix; - - if (ns.size() > 0) { - nsPrefix = ns + ":"; - } - - if (!node || node.getNodeType() != Arabica::DOM::Node_base::ELEMENT_NODE) - return xPath; - - Arabica::DOM::Node curr = node; - while(curr) { - switch (curr.getNodeType()) { - case Arabica::DOM::Node_base::ELEMENT_NODE: { - Arabica::DOM::Element elem = Arabica::DOM::Element(curr); - if (HAS_ATTR(elem, "id") && !UUID::isUUID(ATTR(elem, "id"))) { - // we assume ids to be unique and return immediately - if (ns == "*") { - xPath.insert(0, "//*[local-name() = \"" + TAGNAME(elem) + "\"][@id=\"" + ATTR(elem, "id") + "\"]"); - } else { - xPath.insert(0, "//" + nsPrefix + TAGNAME(elem) + "[@id=\"" + ATTR(elem, "id") + "\"]"); - } - return xPath; - } else { - // check previous siblings to count our index - Arabica::DOM::Node sibling = curr.getPreviousSibling(); - int index = 1; // xpath indices start at 1 - while(sibling) { - if (sibling.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) { - if (iequals(TAGNAME_CAST(sibling), TAGNAME(elem))) { - index++; - } - } - sibling = sibling.getPreviousSibling(); - } - if (ns == "*") { - xPath.insert(0, "/*[local-name() = \"" + TAGNAME(elem) + "\"][" + toStr(index) + "]"); - } else { - xPath.insert(0, "/" + nsPrefix + TAGNAME(elem) + "[" + toStr(index) + "]"); - } - } - break; - } - case Arabica::DOM::Node_base::DOCUMENT_NODE: - return xPath; - default: - LOG(ERROR) << "Only nodes of type element supported for now"; - return ""; - break; - } - curr = curr.getParentNode(); - } - return xPath; -} - -NodeSet DOMUtils::inPostFixOrder(const std::set& elements, - const Element& root, - const bool includeEmbeddedDoc) { - NodeSet nodes; - inPostFixOrder(elements, root, includeEmbeddedDoc, nodes); - return nodes; -} - -void DOMUtils::inPostFixOrder(const std::set& elements, - const Element& root, - const bool includeEmbeddedDoc, - NodeSet& nodes) { - NodeList children = root.getChildNodes(); - for (size_t i = 0; i < children.getLength(); i++) { - if (children.item(i).getNodeType() != Node_base::ELEMENT_NODE) - continue; - Arabica::DOM::Element childElem(children.item(i)); - if (!includeEmbeddedDoc && LOCALNAME(childElem) == "scxml") - continue; - inPostFixOrder(elements, childElem, includeEmbeddedDoc, nodes); - - } - for (size_t i = 0; i < children.getLength(); i++) { - if (children.item(i).getNodeType() != Node_base::ELEMENT_NODE) - continue; - Arabica::DOM::Element childElem(children.item(i)); - if (!includeEmbeddedDoc && LOCALNAME(childElem) == "scxml") - continue; - - if (elements.find(TAGNAME(childElem)) != elements.end()) { - nodes.push_back(childElem); - } - } -} - -NodeSet DOMUtils::inDocumentOrder(const std::set& elements, - const Element& root, - const bool includeEmbeddedDoc) { - NodeSet nodes; - inDocumentOrder(elements, root, includeEmbeddedDoc, nodes); - return nodes; -} - -void DOMUtils::inDocumentOrder(const std::set& elements, - const Element& root, - const bool includeEmbeddedDoc, - NodeSet& nodes) { - if (elements.find(TAGNAME(root)) != elements.end()) { - nodes.push_back(root); - } - - NodeList children = root.getChildNodes(); - for (size_t i = 0; i < children.getLength(); i++) { - if (children.item(i).getNodeType() != Node_base::ELEMENT_NODE) - continue; - if (!includeEmbeddedDoc && LOCALNAME_CAST(children.item(i)) == "scxml") - continue; - Arabica::DOM::Element childElem(children.item(i)); - inDocumentOrder(elements, childElem, includeEmbeddedDoc, nodes); - } -} - -std::list > DOMUtils::getElementsByType(const Arabica::DOM::Node& root, Arabica::DOM::Node_base::Type type) { - std::list > result; - std::list > stack; - std::list >::iterator stackIter; - - if (!root) - return result; - - stack.push_back(root); - while(stack.size() > 0) { -// for(stackIter = stack.begin(); stackIter != stack.end(); stackIter++) { -// std::cout << stackIter->getNodeType() << " " << stackIter->getLocalName() << " " << stackIter->getNodeValue() << std::endl; -// } -// std::cout << std::endl; - - Arabica::DOM::Node currNode = stack.back(); - if (currNode.hasChildNodes()) { - stack.push_back(currNode.getFirstChild()); - continue; - } - - // roll back stack and pop everyone without next sibling - do { - currNode = stack.back(); - if (currNode.getNodeType() == type) - result.push_back(currNode); - stack.pop_back(); - if (currNode.getNextSibling()) { - stack.push_back(currNode.getNextSibling()); - break; - } - } while(stack.size() > 0); - } - return result; -} - -NameSpacingParser NameSpacingParser::fromFile(const std::string& file) { - Arabica::SAX::InputSource inputSource; - inputSource.setSystemId(file); - return fromInputSource(inputSource); -} - -NameSpacingParser NameSpacingParser::fromXML(const std::string& xml) { - std::stringstream* ss = new std::stringstream(); - (*ss) << xml; - // we need an auto_ptr for arabica to assume ownership - std::auto_ptr ssPtr(ss); - Arabica::SAX::InputSource inputSource; - inputSource.setByteStream(ssPtr); - return fromInputSource(inputSource); -} - -NameSpacingParser NameSpacingParser::fromInputSource(Arabica::SAX::InputSource& source) { - NameSpacingParser parser; - if(!parser.parse(source) || !parser.getDocument().hasChildNodes()) { - if(parser._errorHandler.errorsReported()) { -// LOG(ERROR) << "could not parse input:"; -// LOG(ERROR) << parser._errorHandler.errors() << std::endl; - } else { - Arabica::SAX::InputSourceResolver resolver(source, Arabica::default_string_adaptor()); - if (!resolver.resolve()) { - LOG(ERROR) << source.getSystemId() << ": no such file"; - } - } - } - return parser; -} - -NameSpacingParser::NameSpacingParser() { - setErrorHandler(_errorHandler); -} - -void NameSpacingParser::startPrefixMapping(const std::string& prefix, const std::string& uri) { - nameSpace.insert(std::make_pair(uri, prefix)); -} - -} \ No newline at end of file diff --git a/src/uscxml/DOMUtils.h b/src/uscxml/DOMUtils.h deleted file mode 100644 index ab99759..0000000 --- a/src/uscxml/DOMUtils.h +++ /dev/null @@ -1,123 +0,0 @@ -/** - * @file - * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) - * @copyright Simplified BSD - * - * @cond - * This program is free software: you can redistribute it and/or modify - * it under the terms of the FreeBSD license as published by the FreeBSD - * project. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the FreeBSD license along with this - * program. If not, see . - * @endcond - */ - -#ifndef DOMUTILS_H_WK0WAEA7 -#define DOMUTILS_H_WK0WAEA7 - -#include "uscxml/Common.h" -#include -#include -#include -#include // operator<< for nodes -#include - -#define TAGNAME_CAST(elem) ((Arabica::DOM::Element)elem).getTagName() -#define LOCALNAME_CAST(elem) ((Arabica::DOM::Element)elem).getLocalName() -#define ATTR_CAST(elem, attr) ((Arabica::DOM::Element)elem).getAttribute(attr) -#define ATTR_NODE_CAST(elem, attr) ((Arabica::DOM::Element)elem).getAttributeNode(attr) -#define HAS_ATTR_CAST(elem, attr) ((Arabica::DOM::Element)elem).hasAttribute(attr) - -#define TAGNAME(elem) elem.getTagName() -#define LOCALNAME(elem) elem.getLocalName() -#define ATTR(elem, attr) elem.getAttribute(attr) -#define ATTR_NODE(elem, attr) elem.getAttributeNode(attr) -#define HAS_ATTR(elem, attr) elem.hasAttribute(attr) - -namespace uscxml { - -class USCXML_API DOMUtils { -public: - - static std::string xPathForNode(const Arabica::DOM::Node& node, const std::string& ns = ""); - static std::list > getElementsByType(const Arabica::DOM::Node& root, Arabica::DOM::Node_base::Type type); - static std::string idForNode(const Arabica::DOM::Node& node); - // deprecated, use stringIsTrue from Convenience.h instead - DEPRECATED static bool attributeIsTrue(const::std::string& value); - - static Arabica::XPath::NodeSet inPostFixOrder(const std::string& element, - const Arabica::DOM::Element& root, - const bool includeEmbeddedDoc = false) { - std::set elements; - elements.insert(element); - return inPostFixOrder(elements, root, includeEmbeddedDoc); - } - - static Arabica::XPath::NodeSet inPostFixOrder(const std::set& elements, - const Arabica::DOM::Element& root, - const bool includeEmbeddedDoc = false); - - static Arabica::XPath::NodeSet inDocumentOrder(const std::string& element, - const Arabica::DOM::Element& root, - const bool includeEmbeddedDoc = false) { - std::set elements; - elements.insert(element); - return inDocumentOrder(elements, root, includeEmbeddedDoc); - } - - static Arabica::XPath::NodeSet inDocumentOrder(const std::set& elements, - const Arabica::DOM::Element& root, - const bool includeEmbeddedDoc = false); -protected: - static void inPostFixOrder(const std::set& elements, - const Arabica::DOM::Element& root, - const bool includeEmbeddedDoc, - Arabica::XPath::NodeSet& nodes); - - static void inDocumentOrder(const std::set& elements, - const Arabica::DOM::Element& root, - const bool includeEmbeddedDoc, - Arabica::XPath::NodeSet& nodes); - -}; - -class ScriptEntityResolver : public Arabica::SAX::EntityResolver { - virtual InputSourceT resolveEntity(const std::string& publicId, const std::string& systemId) { - Arabica::SAX::InputSource is; - return is; - } -}; - -class USCXML_API NameSpacingParser : public Arabica::SAX2DOM::Parser { -public: - NameSpacingParser(); - NameSpacingParser(const NameSpacingParser& other) {} - static NameSpacingParser fromFile(const std::string& file); - static NameSpacingParser fromXML(const std::string& xml); - static NameSpacingParser fromInputSource(Arabica::SAX::InputSource& source); - - void startPrefixMapping(const std::string& prefix, const std::string& uri); - - std::map nameSpace; - - virtual bool errorsReported() { - return _errorHandler.errorsReported(); - } - - virtual const std::string& errors() { - return _errorHandler.errors(); - } - -private: - Arabica::SAX::CatchErrorHandler _errorHandler; -}; - -} - - -#endif /* end of include guard: DOMUTILS_H_WK0WAEA7 */ diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 2510ef4..7353104 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -22,7 +22,8 @@ #include "uscxml/Interpreter.h" #include "uscxml/URL.h" #include "uscxml/UUID.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" +#include "uscxml/dom/NameSpacingParser.h" #include "uscxml/transform/FlatStateIdentifier.h" #include "uscxml/transform/ChartToFSM.h" // only for testing @@ -485,7 +486,7 @@ Interpreter Interpreter::fromXML(const std::string& xml, const std::string& sour std::auto_ptr ssPtr(ss); Arabica::SAX::InputSource inputSource; inputSource.setByteStream(ssPtr); - return fromInputSource(inputSource, sourceURL); + return fromInputSource(&inputSource, sourceURL); } @@ -502,7 +503,7 @@ Interpreter Interpreter::fromURL(const std::string& url) { if (iequals(absUrl.scheme(), "file")) { Arabica::SAX::InputSource inputSource; inputSource.setSystemId(absUrl.asString()); - interpreter = fromInputSource(inputSource, absUrl); + interpreter = fromInputSource(&inputSource, absUrl); } else { // use curl for everything !file - even for http as arabica won't follow redirects std::stringstream ss; @@ -520,9 +521,10 @@ Interpreter Interpreter::fromURL(const std::string& url) { return interpreter; } -Interpreter Interpreter::fromInputSource(Arabica::SAX::InputSource& source, const std::string& sourceURL) { +Interpreter Interpreter::fromInputSource(void* source, const std::string& sourceURL) { tthread::lock_guard lock(_instanceMutex); + Arabica::SAX::InputSource sourceRef = *(Arabica::SAX::InputSource*)source; // remove old instances std::map >::iterator instIter = _instances.begin(); while(instIter != _instances.end()) { @@ -538,7 +540,7 @@ Interpreter Interpreter::fromInputSource(Arabica::SAX::InputSource& _instances[interpreterImpl->getSessionId()] = interpreterImpl; NameSpacingParser parser; - if (parser.parse(source) && parser.getDocument() && parser.getDocument().hasChildNodes()) { + if (parser.parse(sourceRef) && parser.getDocument() && parser.getDocument().hasChildNodes()) { interpreterImpl->setNameSpaceInfo(parser.nameSpace); interpreterImpl->_document = parser.getDocument(); interpreterImpl->_sourceURL = sourceURL; @@ -680,11 +682,11 @@ void InterpreterImpl::exitInterpreter() { statesToExit.sort(); for (int i = 0; i < statesToExit.size(); i++) { - Arabica::XPath::NodeSet onExitElems = filterChildElements(_nsInfo.xmlNSPrefix + "onexit", statesToExit[i]); + Arabica::XPath::NodeSet onExitElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onexit", statesToExit[i]); for (int j = 0; j < onExitElems.size(); j++) { executeContent(Element(onExitElems[j])); } - Arabica::XPath::NodeSet invokeElems = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]); + Arabica::XPath::NodeSet invokeElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]); // TODO: we ought to cancel all remaining invokers just to be sure with the persist extension for (int j = 0; j < invokeElems.size(); j++) { cancelInvoke(Element(invokeElems[j])); @@ -888,7 +890,7 @@ InterpreterState InterpreterImpl::step(int waitForMS) { // when we reach a stable configuration, invoke for (unsigned int i = 0; i < _statesToInvoke.size(); i++) { - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); for (unsigned int j = 0; j < invokes.size(); j++) { Element invokeElem = Element(invokes[j]); if (!HAS_ATTR(invokeElem, "persist") || !stringIsTrue(ATTR(invokeElem, "persist"))) { @@ -1066,7 +1068,7 @@ void InterpreterImpl::stabilize() { // when we reach a stable configuration, invoke for (unsigned int i = 0; i < _statesToInvoke.size(); i++) { - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); for (unsigned int j = 0; j < invokes.size(); j++) { Element invokeElem = Element(invokes[j]); if (!HAS_ATTR(invokeElem, "persist") || !stringIsTrue(ATTR(invokeElem, "persist"))) { @@ -1091,7 +1093,7 @@ Arabica::XPath::NodeSet InterpreterImpl::selectTransitions(const st unsigned int index = 0; while(states.size() > index) { - NodeSet transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", states[index]); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", states[index]); for (unsigned int k = 0; k < transitions.size(); k++) { if (isEnabledTransition(Element(transitions[k]), event)) { enabledTransitions.push_back(transitions[k]); @@ -1126,7 +1128,7 @@ Arabica::XPath::NodeSet InterpreterImpl::selectEventlessTransitions unsigned int index = 0; while(states.size() > index) { bool foundTransition = false; - NodeSet transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", states[index]); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", states[index]); for (unsigned int k = 0; k < transitions.size(); k++) { Element transElem(transitions[k]); if (!HAS_ATTR(transElem, "event") && hasConditionMatch(transElem)) { @@ -1172,7 +1174,7 @@ Arabica::XPath::NodeSet InterpreterImpl::selectTransitions(const st for (unsigned int i = 0; i < atomicStates.size(); i++) { Element state(atomicStates[i]); while(true) { - NodeSet transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", state); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state); for (unsigned int k = 0; k < transitions.size(); k++) { if (isEnabledTransition(Element(transitions[k]), event)) { enabledTransitions.push_back(transitions[k]); @@ -1225,7 +1227,7 @@ Arabica::XPath::NodeSet InterpreterImpl::selectEventlessTransitions for (unsigned int i = 0; i < atomicStates.size(); i++) { Element state(atomicStates[i]); while(true) { - NodeSet transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", state); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state); for (unsigned int k = 0; k < transitions.size(); k++) { Element transElem(transitions[k]); if (!HAS_ATTR(transElem, "event") && hasConditionMatch(transElem)) { @@ -1273,7 +1275,7 @@ bool InterpreterImpl::isEnabledTransition(const Element& transition return false; } - std::list eventNames = tokenizeIdRefs(eventName); + std::list eventNames = tokenize(eventName); std::list::iterator eventIter = eventNames.begin(); while(eventIter != eventNames.end()) { if(nameMatch(*eventIter, event) && hasConditionMatch(transition)) { @@ -1612,7 +1614,7 @@ void InterpreterImpl::resolveXIncludes(std::list includeChain, goto TRY_WITH_FALLBACK; } TRY_WITH_FALLBACK: { - NodeSet fallbacks = filterChildElements(xIncludeNS + "fallback", xinclude); + NodeSet fallbacks = DOMUtils::filterChildElements(xIncludeNS + "fallback", xinclude); if (fallbacks.size() > 0) { LOG(WARNING) << "Using xi:fallback for '" << DOMUtils::xPathForNode(xinclude) << "'"; // move the fallbacks children in place @@ -1629,7 +1631,7 @@ REMOVE_AND_RECURSE: xinclude.getParentNode().removeChild(xinclude); for (int i = 0; i < newNodes.size(); i++) { _baseURL[newNodes[i]] = URL::asBaseURL(src); - Arabica::XPath::NodeSet xincludes = filterChildElements(xIncludeNS + "include", newNodes[i], true); + Arabica::XPath::NodeSet xincludes = DOMUtils::filterChildElements(xIncludeNS + "include", newNodes[i], true); for (int j = 0; j < xincludes.size(); j++) { resolveXIncludes(includeChain, mergedNS, xIncludeNS, URL::asBaseURL(src), Element(xincludes[j])); } @@ -1689,7 +1691,7 @@ void InterpreterImpl::init() { } } else { // initialize current data elements - NodeSet topDataElems = filterChildElements(_nsInfo.xmlNSPrefix + "data", filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", _scxml)); + NodeSet topDataElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", _scxml)); for (unsigned int i = 0; i < topDataElems.size(); i++) { if (topDataElems[i].getNodeType() == Node_base::ELEMENT_NODE) initializeData(Element(topDataElems[i])); @@ -1697,7 +1699,7 @@ void InterpreterImpl::init() { } // executeGlobalScriptElements - NodeSet globalScriptElems = filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml); + NodeSet globalScriptElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml); for (unsigned int i = 0; i < globalScriptElems.size(); i++) { executeContent(Element(globalScriptElems[i])); } @@ -1774,7 +1776,7 @@ void InterpreterImpl::internalDoneSend(const Arabica::DOM::Element& if (doneData) { processParamChilds(doneData, event.params); - Arabica::XPath::NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", doneData); + Arabica::XPath::NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", doneData); if (contents.size() > 1) LOG(ERROR) << "Only a single content element is allowed for send elements - using first one"; if (contents.size() > 0) { @@ -1907,7 +1909,7 @@ void InterpreterImpl::processDOMorText(const Arabica::DOM::Element& } void InterpreterImpl::processParamChilds(const Arabica::DOM::Element& element, std::multimap& params) { - NodeSet paramElems = filterChildElements(_nsInfo.xmlNSPrefix + "param", element); + NodeSet paramElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", element); for (int i = 0; i < paramElems.size(); i++) { try { Element paramElem = Element(paramElems[i]); @@ -2045,7 +2047,7 @@ void InterpreterImpl::send(const Arabica::DOM::Element& element) { try { // namelist if (HAS_ATTR(element, "namelist")) { - std::list names = tokenizeIdRefs(ATTR(element, "namelist")); + std::list names = tokenize(ATTR(element, "namelist")); for (std::list::const_iterator nameIter = names.begin(); nameIter != names.end(); nameIter++) { if (!_dataModel.isLocation(*nameIter)) { LOG(ERROR) << "Error in send element " << DOMUtils::xPathForNode(element) << " namelist:" << std::endl << "'" << *nameIter << "' is not a location expression" << std::endl; @@ -2072,7 +2074,7 @@ void InterpreterImpl::send(const Arabica::DOM::Element& element) { } try { // content - NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", element); + NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", element); if (contents.size() > 1) LOG(ERROR) << "Only a single content element is allowed for send elements " << DOMUtils::xPathForNode(element) << " - using first one"; if (contents.size() > 0) { @@ -2201,7 +2203,7 @@ void InterpreterImpl::invoke(const Arabica::DOM::Element& element) // namelist if (HAS_ATTR(element, "namelist")) { - std::list names = tokenizeIdRefs(ATTR(element, "namelist")); + std::list names = tokenize(ATTR(element, "namelist")); for (std::list::const_iterator nameIter = names.begin(); nameIter != names.end(); nameIter++) { if (!_dataModel.isLocation(*nameIter)) { LOG(ERROR) << "Error in send element " << DOMUtils::xPathForNode(element) << " namelist:" << std::endl << "'" << *nameIter << "' is not a location expression" << std::endl; @@ -2229,7 +2231,7 @@ void InterpreterImpl::invoke(const Arabica::DOM::Element& element) // content try { - NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", element); + NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", element); if (contents.size() > 1) LOG(ERROR) << "Only a single content element is allowed for send elements - using first one"; if (contents.size() > 0) { @@ -2372,92 +2374,6 @@ void InterpreterImpl::cancelInvoke(const Arabica::DOM::Element& ele //receiveInternal(Event("done.invoke." + invokeId, Event::PLATFORM)); } -// see: http://www.w3.org/TR/scxml/#EventDescriptors -bool InterpreterImpl::nameMatch(const std::string& eventDescs, const std::string& eventName) { -#if 1 - if(eventDescs.length() == 0 || eventName.length() == 0) - return false; - - // naive case of single descriptor and exact match - if (iequals(eventDescs, eventName)) - return true; - - size_t start = 0; - std::string eventDesc; - for (int i = 0; i < eventDescs.size(); i++) { - if (isspace(eventDescs[i])) { - if (i > 0 && start < i - 1) { - eventDesc = eventDescs.substr(start, i - start); - } - while(isspace(eventDescs[++i])); // skip whitespaces - start = i; - } else if (i + 1 == eventDescs.size()) { - eventDesc = eventDescs.substr(start, i + 1 - start); - } - - if (eventDesc.size() > 0) { - // remove optional trailing .* for CCXML compatibility - if (eventDesc.find("*", eventDesc.size() - 1) != std::string::npos) - eventDesc = eventDesc.substr(0, eventDesc.size() - 1); - if (eventDesc.find(".", eventDesc.size() - 1) != std::string::npos) - eventDesc = eventDesc.substr(0, eventDesc.size() - 1); - - // was eventDesc the * wildcard - if (eventDesc.size() == 0) - return true; - - // eventDesc has to be a real prefix of event now and therefore shorter - if (eventDesc.size() > eventName.size()) - goto NEXT_DESC; - - // are they already equal? - if (iequals(eventDesc, eventName)) - return true; - - if (eventName.find(eventDesc) == 0) { - if (eventName.find(".", eventDesc.size()) == eventDesc.size()) - return true; - } -NEXT_DESC: - eventDesc = ""; - } - } - return false; -#else - const char* dPtr = eventDescs.c_str(); - const char* ePtr = eventName.c_str(); - while(*dPtr != 0) { - - if (*dPtr == '*' && *ePtr != 0) // something following - return true; - - // descriptor differs from event name - if (*dPtr != *ePtr) { - // move to next descriptor - while(*dPtr != ' ' && *dPtr != 0) { - dPtr++; - } - if (*dPtr == 0) - return false; - dPtr++; - ePtr = eventName.c_str(); - } else { - // move both pointers one character - dPtr++; - ePtr++; - - } - - // descriptor is done, return match - if (((*dPtr == 0 || *dPtr == ' ') && (*ePtr == 0 || *ePtr == ' ')) || // exact match, end of string - (*dPtr == ' ' && *ePtr == '.') || (*dPtr == 0 && *ePtr == '.')) // prefix match - return true; - } - return false; -#endif -} - - bool InterpreterImpl::hasConditionMatch(const Arabica::DOM::Element& conditional) { if (HAS_ATTR(conditional, "cond") && ATTR(conditional, "cond").length() > 0) { try { @@ -2530,7 +2446,7 @@ void InterpreterImpl::executeContent(const Arabica::DOM::Element& c try { // content processParamChilds(content, raised.params); - NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", content); + NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", content); if (contents.size() > 1) LOG(ERROR) << "Only a single content element is allowed for raise elements " << DOMUtils::xPathForNode(content) << " - using first one"; if (contents.size() > 0) { @@ -2772,7 +2688,7 @@ void InterpreterImpl::finalizeAndAutoForwardCurrentEvent() { invokeIter != _invokers.end(); invokeIter++) { if (iequals(invokeIter->first, _currEvent.invokeid)) { - Arabica::XPath::NodeSet finalizes = filterChildElements(_nsInfo.xmlNSPrefix + "finalize", invokeIter->second.getElement()); + Arabica::XPath::NodeSet finalizes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "finalize", invokeIter->second.getElement()); for (int k = 0; k < finalizes.size(); k++) { Element finalizeElem = Element(finalizes[k]); executeContent(finalizeElem); @@ -3024,13 +2940,13 @@ Arabica::XPath::NodeSet InterpreterImpl::getInitialStates(Arabica:: // initial attribute at element Arabica::DOM::Element stateElem = (Arabica::DOM::Element)state; if (stateElem.hasAttribute("initial")) { - return getStates(tokenizeIdRefs(stateElem.getAttribute("initial"))); + return getStates(tokenize(stateElem.getAttribute("initial"))); } // initial element as child - but not the implicit generated one - NodeSet initElems = filterChildElements(_nsInfo.xmlNSPrefix + "initial", state); + NodeSet initElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "initial", state); if(initElems.size() > 0 && !iequals(ATTR_CAST(initElems[0], "generated"), "true")) { - NodeSet initTrans = filterChildElements(_nsInfo.xmlNSPrefix + "transition", initElems[0]); + NodeSet initTrans = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", initElems[0]); if (initTrans.size() > 0) { return getTargetStates(Element(initTrans[0])); } @@ -3084,7 +3000,7 @@ NodeSet InterpreterImpl::getReachableStates() { // reachable per target attribute in transitions for (int i = 0; i < reachable.size(); i++) { Element state = Element(reachable[i]); - NodeSet transitions = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state, false); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state, false); for (int j = 0; j < transitions.size(); j++) { Element transition = Element(transitions[j]); try { @@ -3151,7 +3067,7 @@ NodeSet InterpreterImpl::getTargetStates(const Arabica::DOM::Elemen } std::string targetId = ((Arabica::DOM::Element)transition).getAttribute("target"); - std::list targetIds = InterpreterImpl::tokenizeIdRefs(ATTR(transition, "target")); + std::list targetIds = tokenize(ATTR(transition, "target")); for (std::list::const_iterator targetIter = targetIds.begin(); targetIter != targetIds.end(); targetIter++) { Arabica::DOM::Node state = getState(*targetIter); if (state) { @@ -3171,125 +3087,6 @@ NodeSet InterpreterImpl::getTargetStates(const Arabica::XPath::Node return targets; } -#define ISWHITESPACE(char) (isspace(char)) - -std::list InterpreterImpl::tokenize(const std::string& line, const char sep, bool trimWhiteSpace) { - std::list tokens; - - // appr. 3x faster than stringstream - size_t start = 0; - for (int i = 0; i < line.size(); i++) { - if (line[i] == sep || (trimWhiteSpace && ISWHITESPACE(line[i]))) { - if (i > 0 && start < i) { - tokens.push_back(line.substr(start, i - start)); - } - while(line[i] == sep || (trimWhiteSpace && ISWHITESPACE(line[i]))) { - i++; // skip multiple occurences of seperator and whitespaces - } - start = i; - } else if (i + 1 == line.size()) { - tokens.push_back(line.substr(start, i + 1 - start)); - } - } - - return tokens; -} - -std::string InterpreterImpl::spaceNormalize(const std::string& text) { - std::stringstream content; - -#if 1 - // 195ms with test-performance-events.scml - std::string seperator; - - size_t start = 0; - for (int i = 0; i < text.size(); i++) { - if (isspace(text[i])) { - if (i > 0 && start < i) { - content << seperator << text.substr(start, i - start); - seperator = " "; - } - while(isspace(text[++i])); // skip whitespaces - start = i; - } else if (i + 1 == text.size()) { - content << seperator << text.substr(start, i + 1 - start); - } - } -// std::cerr << ">>" << content.str() << "<<" << std::endl; - -#else - -// 291ms with test-performance-events.scml - std::istringstream iss(text); - std::string seperator; - do { - std::string token; - iss >> token; - if (token.length() > 0) { - content << seperator << token; - seperator = " "; - } - } while (iss); - -#endif - return content.str(); -} - - -NodeSet InterpreterImpl::filterChildElements(const std::string& tagName, const NodeSet& nodeSet, bool recurse) { - NodeSet filteredChildElems; - for (unsigned int i = 0; i < nodeSet.size(); i++) { - filteredChildElems.push_back(filterChildElements(tagName, nodeSet[i], recurse)); - } - return filteredChildElems; -} - -NodeSet InterpreterImpl::filterChildElements(const std::string& tagName, const Node& node, bool recurse) { - NodeSet filteredChildElems; - - if (!node) - return filteredChildElems; - - NodeList childs = node.getChildNodes(); - for (unsigned int i = 0; i < childs.getLength(); i++) { - if (childs.item(i).getNodeType() != Node_base::ELEMENT_NODE) - continue; -// std::cerr << TAGNAME(childs.item(i)) << std::endl; - if(iequals(TAGNAME_CAST(childs.item(i)), tagName)) { - filteredChildElems.push_back(childs.item(i)); - } - if (recurse) { - filteredChildElems.push_back(filterChildElements(tagName, childs.item(i), recurse)); - } - } - return filteredChildElems; -} - - -NodeSet InterpreterImpl::filterChildType(const Node_base::Type type, const NodeSet& nodeSet, bool recurse) { - NodeSet filteredChildType; - for (unsigned int i = 0; i < nodeSet.size(); i++) { - filteredChildType.push_back(filterChildType(type, nodeSet[i], recurse)); - } - return filteredChildType; -} - -NodeSet InterpreterImpl::filterChildType(const Node_base::Type type, const Node& node, bool recurse) { - NodeSet filteredChildTypes; - - if (!node) - return filteredChildTypes; - - NodeList childs = node.getChildNodes(); - for (unsigned int i = 0; i < childs.getLength(); i++) { - if (childs.item(i).getNodeType() == type) - filteredChildTypes.push_back(childs.item(i)); - if (recurse) { - filteredChildTypes.push_back(filterChildType(type, childs.item(i), recurse)); - } - } - return filteredChildTypes; -} /* * If state2 is null, returns the set of all ancestors of state1 in ancestry order @@ -3724,7 +3521,7 @@ void InterpreterImpl::handleDOMEvent(Arabica::DOM::Events::Event& e // remove modified states from cache Node target = Arabica::DOM::Node(event.getTarget()); - NodeSet childs = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "state", target); + NodeSet childs = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "state", target); for (int i = 0; i < childs.size(); i++) { if (HAS_ATTR_CAST(childs[i], "id")) { _cachedStates.erase(ATTR_CAST(childs[i], "id")); diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index ce9354a..c3395d0 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -23,6 +23,7 @@ // this has to be the first include or MSVC will run amok #include "uscxml/config.h" #include "uscxml/Common.h" +#include "uscxml/util/String.h" #include // arabica xpath uses cerr without iostream #include @@ -34,11 +35,6 @@ #include #include -#include -#include -#include -#include - #include "uscxml/concurrency/BlockingQueue.h" #include "uscxml/messages/Data.h" #include "uscxml/messages/SendRequest.h" @@ -50,11 +46,13 @@ #include "uscxml/plugins/Invoker.h" #include "uscxml/plugins/ExecutableContent.h" -#ifdef BUILD_PROFILING -#include "uscxml/concurrency/Timer.h" -#define TIME_BLOCK Measurement msm(&timer); -#else -#define TIME_BLOCK (0); +#ifndef TIME_BLOCK +# ifdef BUILD_PROFILING +# include "uscxml/concurrency/Timer.h" +# define TIME_BLOCK Measurement msm(&timer); +# else +# define TIME_BLOCK +# endif #endif #define ERROR_PLATFORM_THROW(msg) \ @@ -399,18 +397,6 @@ public: virtual Arabica::XPath::NodeSet getTargetStates(const Arabica::XPath::NodeSet& transitions); virtual Arabica::DOM::Node getSourceState(const Arabica::DOM::Element& transition); - static Arabica::XPath::NodeSet filterChildElements(const std::string& tagname, const Arabica::DOM::Node& node, bool recurse = false); - static Arabica::XPath::NodeSet filterChildElements(const std::string& tagName, const Arabica::XPath::NodeSet& nodeSet, bool recurse = false); - static Arabica::XPath::NodeSet filterChildType(const Arabica::DOM::Node_base::Type type, const Arabica::DOM::Node& node, bool recurse = false); - static Arabica::XPath::NodeSet filterChildType(const Arabica::DOM::Node_base::Type type, const Arabica::XPath::NodeSet& nodeSet, bool recurse = false); - - static std::list tokenizeIdRefs(const std::string& idRefs) { - return tokenize(idRefs, ' ', true); - } - static std::list tokenize(const std::string& line, const char seperator = ' ', bool trimWhiteSpace = false); - - static std::string spaceNormalize(const std::string& text); - static bool nameMatch(const std::string& eventDescs, const std::string& event); Arabica::DOM::Node findLCCA(const Arabica::XPath::NodeSet& states); virtual Arabica::XPath::NodeSet getProperAncestors(const Arabica::DOM::Node& s1, const Arabica::DOM::Node& s2); @@ -827,7 +813,8 @@ protected: return _impl->setInvokeRequest(req); } - static Interpreter fromInputSource(Arabica::SAX::InputSource& source, const std::string& sourceURL); + // we use a void ptr here as Arabica::SAX::InputSource complicates includes + static Interpreter fromInputSource(void* source, const std::string& sourceURL); boost::shared_ptr _impl; static std::map > _instances; diff --git a/src/uscxml/Message.cpp b/src/uscxml/Message.cpp deleted file mode 100644 index 465b4ba..0000000 --- a/src/uscxml/Message.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file - * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) - * @copyright Simplified BSD - * - * @cond - * This program is free software: you can redistribute it and/or modify - * it under the terms of the FreeBSD license as published by the FreeBSD - * project. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the FreeBSD license along with this - * program. If not, see . - * @endcond - */ - -#include "uscxml/config.h" - -#include "uscxml/Common.h" -#include "uscxml/Message.h" -#include "uscxml/DOMUtils.h" -#include -#include -#include - -#include - - -namespace uscxml { - - - - - - - - - - -#ifndef SWIGJAVA -#endif - - -#ifndef SWIGJAVA -#endif - -#ifndef SWIGJAVA -#endif - -#ifndef SWIGJAVA -#endif - - -} \ No newline at end of file diff --git a/src/uscxml/concurrency/tinythread.h b/src/uscxml/concurrency/tinythread.h index cf313d5..e5e5e25 100644 --- a/src/uscxml/concurrency/tinythread.h +++ b/src/uscxml/concurrency/tinythread.h @@ -25,7 +25,7 @@ freely, subject to the following restrictions: #define _TINYTHREAD_H_ #include "uscxml/Common.h" -#include +//#include /// @file /// @mainpage TinyThread++ API Reference diff --git a/src/uscxml/debug/Breakpoint.cpp b/src/uscxml/debug/Breakpoint.cpp index e66e0fb..d7eb2af 100644 --- a/src/uscxml/debug/Breakpoint.cpp +++ b/src/uscxml/debug/Breakpoint.cpp @@ -19,7 +19,7 @@ #include "uscxml/debug/Breakpoint.h" #include "uscxml/Interpreter.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" namespace uscxml { @@ -223,7 +223,7 @@ bool Breakpoint::matches(Interpreter interpreter, const Breakpoint& other) const return false; } - if(eventName.length() > 0 && !InterpreterImpl::nameMatch(eventName, other.eventName)) { + if(eventName.length() > 0 && !nameMatch(eventName, other.eventName)) { return false; } diff --git a/src/uscxml/debug/Breakpoint.h b/src/uscxml/debug/Breakpoint.h index 71308aa..d7df03d 100644 --- a/src/uscxml/debug/Breakpoint.h +++ b/src/uscxml/debug/Breakpoint.h @@ -21,9 +21,9 @@ #define BREAKPOINT_H_VR7K7T1X #include // for string +#include "uscxml/Common.h" // for USCXML_API #include "uscxml/Interpreter.h" #include "DOM/Element.hpp" // for Element -#include "uscxml/Common.h" // for USCXML_API #include "uscxml/messages/Data.h" // for Data namespace uscxml { diff --git a/src/uscxml/debug/Complexity.cpp b/src/uscxml/debug/Complexity.cpp index 29d7706..a7f9f93 100644 --- a/src/uscxml/debug/Complexity.cpp +++ b/src/uscxml/debug/Complexity.cpp @@ -18,7 +18,7 @@ */ #include "Complexity.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include @@ -97,7 +97,7 @@ std::map Complexity::getTransitionHistogramm(const Arabica::DOM: if (nameSpace.size() == 0 && elemIter->getPrefix().size() > 0) nameSpace = elemIter->getPrefix() + ":"; } - NodeSet transitions = InterpreterImpl::filterChildElements(nameSpace + "transition", configNodeSet); + NodeSet transitions = DOMUtils::filterChildElements(nameSpace + "transition", configNodeSet); histogram[transitions.size()]++; } diff --git a/src/uscxml/debug/Debugger.cpp b/src/uscxml/debug/Debugger.cpp index cb4d522..1a7d977 100644 --- a/src/uscxml/debug/Debugger.cpp +++ b/src/uscxml/debug/Debugger.cpp @@ -18,7 +18,7 @@ */ #include "uscxml/debug/Debugger.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/debug/DebugSession.h" namespace uscxml { diff --git a/src/uscxml/debug/InterpreterIssue.cpp b/src/uscxml/debug/InterpreterIssue.cpp index 6b97182..1fcfc00 100644 --- a/src/uscxml/debug/InterpreterIssue.cpp +++ b/src/uscxml/debug/InterpreterIssue.cpp @@ -20,7 +20,7 @@ #include #include "InterpreterIssue.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/debug/Complexity.h" #include "uscxml/Interpreter.h" #include "uscxml/Factory.h" @@ -299,7 +299,7 @@ std::list InterpreterIssue::forInterpreter(InterpreterImpl* in // check for valid transition with history states if (LOCALNAME(state) == "history") { - NodeSet transitions = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state, false); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state, false); if (transitions.size() > 1) { issues.push_back(InterpreterIssue("History pseudo-state with id '" + stateId + "' has multiple transitions", state, InterpreterIssue::USCXML_ISSUE_FATAL)); } else if (transitions.size() == 0) { @@ -350,7 +350,7 @@ std::list InterpreterIssue::forInterpreter(InterpreterImpl* in // check for valid target if (HAS_ATTR(transition, "target")) { - std::list targetIds = InterpreterImpl::tokenizeIdRefs(ATTR(transition, "target")); + std::list targetIds = tokenize(ATTR(transition, "target")); if (targetIds.size() == 0) { issues.push_back(InterpreterIssue("Transition has empty target state list", transition, InterpreterIssue::USCXML_ISSUE_FATAL)); } @@ -367,7 +367,7 @@ std::list InterpreterIssue::forInterpreter(InterpreterImpl* in // check for redundancy of transition for (int i = 0; i < allStates.size(); i++) { Element state = Element(allStates[i]); - NodeSet transitions = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state, false); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state, false); transitions.to_document_order(); @@ -386,11 +386,11 @@ std::list InterpreterIssue::forInterpreter(InterpreterImpl* in } else if (HAS_ATTR(transition, "event")) { // does the earlier transition match all our events? - std::list events = InterpreterImpl::tokenizeIdRefs(ATTR(transition, "event")); + std::list events = tokenize(ATTR(transition, "event")); bool allMatched = true; for (std::list::iterator eventIter = events.begin(); eventIter != events.end(); eventIter++) { - if (!InterpreterImpl::nameMatch(ATTR(earlierTransition, "event"), *eventIter)) { + if (!nameMatch(ATTR(earlierTransition, "event"), *eventIter)) { allMatched = false; break; } @@ -438,12 +438,12 @@ NEXT_TRANSITION: if (HAS_ATTR(state, "initial")) { NodeSet childs; - childs.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "state", state, true)); - childs.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "parallel", state, true)); - childs.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "final", state, true)); - childs.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "history", state, true)); + childs.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "state", state, true)); + childs.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "parallel", state, true)); + childs.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "final", state, true)); + childs.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "history", state, true)); - std::list intials = InterpreterImpl::tokenizeIdRefs(ATTR(state, "initial")); + std::list intials = tokenize(ATTR(state, "initial")); for (std::list::iterator initIter = intials.begin(); initIter != intials.end(); initIter++) { if (seenStates.find(*initIter) == seenStates.end()) { issues.push_back(InterpreterIssue("Initial attribute has invalid target state with id '" + *initIter + "'", state, InterpreterIssue::USCXML_ISSUE_FATAL)); @@ -489,7 +489,7 @@ NEXT_TRANSITION: setIter != targetIdSets.end(); setIter++) { NodeSet targets; - std::list targetIds = InterpreterImpl::tokenizeIdRefs(setIter->second); + std::list targetIds = tokenize(setIter->second); for (std::list::iterator tgtIter = targetIds.begin(); tgtIter != targetIds.end(); tgtIter++) { if (seenStates.find(*tgtIter) == seenStates.end()) goto NEXT_SET; @@ -506,11 +506,11 @@ NEXT_SET: // check for valid initial transition { NodeSet initTrans; -// initTrans.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "transition", histories, true)); +// initTrans.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", histories, true)); for (int i = 0; i < initials.size(); i++) { Element initial = Element(initials[i]); - NodeSet initTransitions = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "transition", initial, true); + NodeSet initTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", initial, true); if (initTransitions.size() != 1) { issues.push_back(InterpreterIssue("Initial element must define exactly one transition", initial, InterpreterIssue::USCXML_ISSUE_FATAL)); } @@ -539,12 +539,12 @@ NEXT_SET: continue; // syntax will catch this one NodeSet childs; - childs.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "state", state, true)); - childs.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "parallel", state, true)); - childs.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "final", state, true)); - childs.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "history", state, true)); + childs.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "state", state, true)); + childs.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "parallel", state, true)); + childs.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "final", state, true)); + childs.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "history", state, true)); - std::list intials = InterpreterImpl::tokenizeIdRefs(ATTR(transition, "target")); + std::list intials = tokenize(ATTR(transition, "target")); for (std::list::iterator initIter = intials.begin(); initIter != intials.end(); initIter++) { // the 'target' of a inside an or element: all the states must be descendants of the containing or element if (!InterpreterImpl::isMember(seenStates[*initIter], childs)) { @@ -602,7 +602,7 @@ NEXT_SET: for (int i = 0; i < allExecContentContainers.size(); i++) { Element block = Element(allExecContentContainers[i]); - NodeSet execContents = InterpreterImpl::filterChildType(Node_base::ELEMENT_NODE, block); + NodeSet execContents = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, block); for (int j = 0; j < execContents.size(); j++) { Element execContent = Element(execContents[j]); // SCXML specific executable content, always available @@ -723,8 +723,8 @@ NEXT_SET: issues.push_back(InterpreterIssue("Send element cannot have delay with target _internal", send, InterpreterIssue::USCXML_ISSUE_WARNING)); } - NodeSet contentChilds = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "content", send, false); - NodeSet paramChilds = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "param", send, false); + NodeSet contentChilds = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", send, false); + NodeSet paramChilds = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", send, false); if (HAS_ATTR(send, "namelist") && contentChilds.size() > 0) { issues.push_back(InterpreterIssue("Send element cannot have namelist attribute and content child", send, InterpreterIssue::USCXML_ISSUE_WARNING)); @@ -753,18 +753,18 @@ NEXT_SET: if (HAS_ATTR(invoke, "id") && HAS_ATTR(invoke, "idlocation")) { issues.push_back(InterpreterIssue("Invoke element cannot have both id and idlocation attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(invoke, "namelist") && InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "param", invoke, false).size() > 0) { + if (HAS_ATTR(invoke, "namelist") && DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", invoke, false).size() > 0) { issues.push_back(InterpreterIssue("Invoke element cannot have namelist attribute and param child", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); } - if (HAS_ATTR(invoke, "src") && InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "content", invoke, false).size() > 0) { + if (HAS_ATTR(invoke, "src") && DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", invoke, false).size() > 0) { issues.push_back(InterpreterIssue("Invoke element cannot have src attribute and content child", invoke, InterpreterIssue::USCXML_ISSUE_WARNING)); } } for (int i = 0; i < doneDatas.size(); i++) { Element donedata = Element(doneDatas[i]); - if (InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "content", donedata, false).size() > 0 && - InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "param", donedata, false).size() > 0) { + if (DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", donedata, false).size() > 0 && + DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", donedata, false).size() > 0) { issues.push_back(InterpreterIssue("Donedata element cannot have param child and content child", donedata, InterpreterIssue::USCXML_ISSUE_WARNING)); } diff --git a/src/uscxml/debug/InterpreterIssue.h b/src/uscxml/debug/InterpreterIssue.h index 5959d07..61b3b6a 100644 --- a/src/uscxml/debug/InterpreterIssue.h +++ b/src/uscxml/debug/InterpreterIssue.h @@ -22,6 +22,7 @@ #include "uscxml/Common.h" #include +#include #include namespace uscxml { diff --git a/src/uscxml/debug/SCXMLDotWriter.cpp b/src/uscxml/debug/SCXMLDotWriter.cpp index 82faaa4..a6ec0b6 100644 --- a/src/uscxml/debug/SCXMLDotWriter.cpp +++ b/src/uscxml/debug/SCXMLDotWriter.cpp @@ -21,7 +21,7 @@ #include "uscxml/UUID.h" #include "SCXMLDotWriter.h" #include "../transform/FlatStateIdentifier.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include // replace_all #include @@ -199,7 +199,7 @@ void SCXMLDotWriter::assembleGraph(const Element& state, int32_t ch } - NodeSet childElems = InterpreterImpl::filterChildType(Node_base::ELEMENT_NODE, state); + NodeSet childElems = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, state); for (int i = 0; i < childElems.size(); i++) { Element childElem(childElems[i]); @@ -225,7 +225,7 @@ void SCXMLDotWriter::assembleGraph(const Element& state, int32_t ch std::list eventNames; if (HAS_ATTR(childElem, "event")) - eventNames = InterpreterImpl::tokenizeIdRefs(ATTR(childElem, "event")); + eventNames = tokenize(ATTR(childElem, "event")); if (eventNames.size() == 0) _graph[nodeId].events.insert(std::make_pair("", childElem)); for (std::list::iterator evIter = eventNames.begin(); evIter != eventNames.end(); evIter++) { @@ -399,7 +399,7 @@ void SCXMLDotWriter::writeStateElement(std::ostream& os, const Element histories = InterpreterImpl::filterChildElements(_xmlNSPrefix + "history", stateElem); + NodeSet histories = DOMUtils::filterChildElements(_xmlNSPrefix + "history", stateElem); for (int i = 0; i < histories.size(); i++) { os << " history: " << ATTR_CAST(histories[i], "id") << "" << std::endl; @@ -421,7 +421,7 @@ void SCXMLDotWriter::writeStateElement(std::ostream& os, const Element childElems = InterpreterImpl::filterChildType(Node_base::ELEMENT_NODE, stateElem); + NodeSet childElems = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, stateElem); for (int i = 0; i < childElems.size(); i++) { Element childElem(childElems[i]); if (InterpreterImpl::isState(Element(childElem))) { @@ -538,7 +538,7 @@ void SCXMLDotWriter::writePerTargetPorts(std::ostream& os, const DotState& dotSt for (iter_t::const_iterator transIter = targetKeyRange.first; transIter != targetKeyRange.second; ++transIter) { const Element& transElem = transIter->second; - std::list events = InterpreterImpl::tokenizeIdRefs(ATTR(transElem, "event")); + std::list events = tokenize(ATTR(transElem, "event")); eventNames.insert(events.begin(), events.end()); if (events.size() == 0) { diff --git a/src/uscxml/dom/DOMUtils.cpp b/src/uscxml/dom/DOMUtils.cpp new file mode 100644 index 0000000..137d0ef --- /dev/null +++ b/src/uscxml/dom/DOMUtils.cpp @@ -0,0 +1,288 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#include "uscxml/Common.h" +#include "uscxml/UUID.h" +#include "uscxml/dom/DOMUtils.h" +#include "uscxml/Convenience.h" + +#include +#include + +namespace uscxml { + +using namespace Arabica::XPath; +using namespace Arabica::DOM; + +bool DOMUtils::attributeIsTrue(const::std::string& value) { + return stringIsTrue(value.c_str()); +} + +std::string DOMUtils::idForNode(const Arabica::DOM::Node& node) { + std::string nodeId; + std::string seperator; + Arabica::DOM::Node curr = node; + while(curr) { + switch (curr.getNodeType()) { + case Arabica::DOM::Node_base::ELEMENT_NODE: { + Arabica::DOM::Element elem = Arabica::DOM::Element(curr); + if (HAS_ATTR(elem, "id") && !UUID::isUUID(ATTR(elem, "id"))) { + std::string elementId = ATTR(elem, "id"); + boost::replace_all(elementId, ".", "_"); + boost::replace_all(elementId, ",", "_"); + nodeId.insert(0, elementId + seperator); + seperator = "_"; + return nodeId; + } else { + Arabica::DOM::Node sibling = curr.getPreviousSibling(); + int index = 0; + while(sibling) { + if (sibling.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) { + if (iequals(TAGNAME_CAST(sibling), TAGNAME(elem))) { + index++; + } + } + sibling = sibling.getPreviousSibling(); + } + nodeId.insert(0, TAGNAME(elem) + toStr(index) + seperator); + seperator = "_"; + } + break; + } + case Arabica::DOM::Node_base::DOCUMENT_NODE: + return nodeId; + } + + curr = curr.getParentNode(); + } + return nodeId; +} + +std::string DOMUtils::xPathForNode(const Arabica::DOM::Node& node, const std::string& ns) { + std::string xPath; + std::string nsPrefix; + + if (ns.size() > 0) { + nsPrefix = ns + ":"; + } + + if (!node || node.getNodeType() != Arabica::DOM::Node_base::ELEMENT_NODE) + return xPath; + + Arabica::DOM::Node curr = node; + while(curr) { + switch (curr.getNodeType()) { + case Arabica::DOM::Node_base::ELEMENT_NODE: { + Arabica::DOM::Element elem = Arabica::DOM::Element(curr); + if (HAS_ATTR(elem, "id") && !UUID::isUUID(ATTR(elem, "id"))) { + // we assume ids to be unique and return immediately + if (ns == "*") { + xPath.insert(0, "//*[local-name() = \"" + TAGNAME(elem) + "\"][@id=\"" + ATTR(elem, "id") + "\"]"); + } else { + xPath.insert(0, "//" + nsPrefix + TAGNAME(elem) + "[@id=\"" + ATTR(elem, "id") + "\"]"); + } + return xPath; + } else { + // check previous siblings to count our index + Arabica::DOM::Node sibling = curr.getPreviousSibling(); + int index = 1; // xpath indices start at 1 + while(sibling) { + if (sibling.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) { + if (iequals(TAGNAME_CAST(sibling), TAGNAME(elem))) { + index++; + } + } + sibling = sibling.getPreviousSibling(); + } + if (ns == "*") { + xPath.insert(0, "/*[local-name() = \"" + TAGNAME(elem) + "\"][" + toStr(index) + "]"); + } else { + xPath.insert(0, "/" + nsPrefix + TAGNAME(elem) + "[" + toStr(index) + "]"); + } + } + break; + } + case Arabica::DOM::Node_base::DOCUMENT_NODE: + return xPath; + default: + LOG(ERROR) << "Only nodes of type element supported for now"; + return ""; + break; + } + curr = curr.getParentNode(); + } + return xPath; +} + +NodeSet DOMUtils::inPostFixOrder(const std::set& elements, + const Element& root, + const bool includeEmbeddedDoc) { + NodeSet nodes; + inPostFixOrder(elements, root, includeEmbeddedDoc, nodes); + return nodes; +} + +void DOMUtils::inPostFixOrder(const std::set& elements, + const Element& root, + const bool includeEmbeddedDoc, + NodeSet& nodes) { + NodeList children = root.getChildNodes(); + for (size_t i = 0; i < children.getLength(); i++) { + if (children.item(i).getNodeType() != Node_base::ELEMENT_NODE) + continue; + Arabica::DOM::Element childElem(children.item(i)); + if (!includeEmbeddedDoc && LOCALNAME(childElem) == "scxml") + continue; + inPostFixOrder(elements, childElem, includeEmbeddedDoc, nodes); + + } + for (size_t i = 0; i < children.getLength(); i++) { + if (children.item(i).getNodeType() != Node_base::ELEMENT_NODE) + continue; + Arabica::DOM::Element childElem(children.item(i)); + if (!includeEmbeddedDoc && LOCALNAME(childElem) == "scxml") + continue; + + if (elements.find(TAGNAME(childElem)) != elements.end()) { + nodes.push_back(childElem); + } + } +} + +NodeSet DOMUtils::inDocumentOrder(const std::set& elements, + const Element& root, + const bool includeEmbeddedDoc) { + NodeSet nodes; + inDocumentOrder(elements, root, includeEmbeddedDoc, nodes); + return nodes; +} + +void DOMUtils::inDocumentOrder(const std::set& elements, + const Element& root, + const bool includeEmbeddedDoc, + NodeSet& nodes) { + if (elements.find(TAGNAME(root)) != elements.end()) { + nodes.push_back(root); + } + + NodeList children = root.getChildNodes(); + for (size_t i = 0; i < children.getLength(); i++) { + if (children.item(i).getNodeType() != Node_base::ELEMENT_NODE) + continue; + if (!includeEmbeddedDoc && LOCALNAME_CAST(children.item(i)) == "scxml") + continue; + Arabica::DOM::Element childElem(children.item(i)); + inDocumentOrder(elements, childElem, includeEmbeddedDoc, nodes); + } +} + +std::list > DOMUtils::getElementsByType(const Arabica::DOM::Node& root, Arabica::DOM::Node_base::Type type) { + std::list > result; + std::list > stack; + std::list >::iterator stackIter; + + if (!root) + return result; + + stack.push_back(root); + while(stack.size() > 0) { +// for(stackIter = stack.begin(); stackIter != stack.end(); stackIter++) { +// std::cout << stackIter->getNodeType() << " " << stackIter->getLocalName() << " " << stackIter->getNodeValue() << std::endl; +// } +// std::cout << std::endl; + + Arabica::DOM::Node currNode = stack.back(); + if (currNode.hasChildNodes()) { + stack.push_back(currNode.getFirstChild()); + continue; + } + + // roll back stack and pop everyone without next sibling + do { + currNode = stack.back(); + if (currNode.getNodeType() == type) + result.push_back(currNode); + stack.pop_back(); + if (currNode.getNextSibling()) { + stack.push_back(currNode.getNextSibling()); + break; + } + } while(stack.size() > 0); + } + return result; +} + + +NodeSet DOMUtils::filterChildElements(const std::string& tagName, const NodeSet& nodeSet, bool recurse) { + NodeSet filteredChildElems; + for (unsigned int i = 0; i < nodeSet.size(); i++) { + filteredChildElems.push_back(filterChildElements(tagName, nodeSet[i], recurse)); + } + return filteredChildElems; +} + +NodeSet DOMUtils::filterChildElements(const std::string& tagName, const Node& node, bool recurse) { + NodeSet filteredChildElems; + + if (!node) + return filteredChildElems; + + NodeList childs = node.getChildNodes(); + for (unsigned int i = 0; i < childs.getLength(); i++) { + if (childs.item(i).getNodeType() != Node_base::ELEMENT_NODE) + continue; + // std::cerr << TAGNAME(childs.item(i)) << std::endl; + if(iequals(TAGNAME_CAST(childs.item(i)), tagName)) { + filteredChildElems.push_back(childs.item(i)); + } + if (recurse) { + filteredChildElems.push_back(filterChildElements(tagName, childs.item(i), recurse)); + } + } + return filteredChildElems; +} + + +NodeSet DOMUtils::filterChildType(const Node_base::Type type, const NodeSet& nodeSet, bool recurse) { + NodeSet filteredChildType; + for (unsigned int i = 0; i < nodeSet.size(); i++) { + filteredChildType.push_back(filterChildType(type, nodeSet[i], recurse)); + } + return filteredChildType; +} + +NodeSet DOMUtils::filterChildType(const Node_base::Type type, const Node& node, bool recurse) { + NodeSet filteredChildTypes; + + if (!node) + return filteredChildTypes; + + NodeList childs = node.getChildNodes(); + for (unsigned int i = 0; i < childs.getLength(); i++) { + if (childs.item(i).getNodeType() == type) + filteredChildTypes.push_back(childs.item(i)); + if (recurse) { + filteredChildTypes.push_back(filterChildType(type, childs.item(i), recurse)); + } + } + return filteredChildTypes; +} + + +} \ No newline at end of file diff --git a/src/uscxml/dom/DOMUtils.h b/src/uscxml/dom/DOMUtils.h new file mode 100644 index 0000000..5c61f6d --- /dev/null +++ b/src/uscxml/dom/DOMUtils.h @@ -0,0 +1,111 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#ifndef DOMUTILS_H_WK0WAEA7 +#define DOMUTILS_H_WK0WAEA7 + +#include "uscxml/Common.h" +#include +#include +#include +#include // operator<< for nodes +#include + +#define TAGNAME_CAST(elem) ((Arabica::DOM::Element)elem).getTagName() +#define LOCALNAME_CAST(elem) ((Arabica::DOM::Element)elem).getLocalName() +#define ATTR_CAST(elem, attr) ((Arabica::DOM::Element)elem).getAttribute(attr) +#define ATTR_NODE_CAST(elem, attr) ((Arabica::DOM::Element)elem).getAttributeNode(attr) +#define HAS_ATTR_CAST(elem, attr) ((Arabica::DOM::Element)elem).hasAttribute(attr) + +#define TAGNAME(elem) elem.getTagName() +#define LOCALNAME(elem) elem.getLocalName() +#define ATTR(elem, attr) elem.getAttribute(attr) +#define ATTR_NODE(elem, attr) elem.getAttributeNode(attr) +#define HAS_ATTR(elem, attr) elem.hasAttribute(attr) + +namespace uscxml { + +class USCXML_API DOMUtils { +public: + + static std::string xPathForNode(const Arabica::DOM::Node& node, const std::string& ns = ""); + static std::list > getElementsByType(const Arabica::DOM::Node& root, Arabica::DOM::Node_base::Type type); + static std::string idForNode(const Arabica::DOM::Node& node); + // deprecated, use stringIsTrue from Convenience.h instead + DEPRECATED static bool attributeIsTrue(const::std::string& value); + + static Arabica::XPath::NodeSet inPostFixOrder(const std::string& element, + const Arabica::DOM::Element& root, + const bool includeEmbeddedDoc = false) { + std::set elements; + elements.insert(element); + return inPostFixOrder(elements, root, includeEmbeddedDoc); + } + + static Arabica::XPath::NodeSet inPostFixOrder(const std::set& elements, + const Arabica::DOM::Element& root, + const bool includeEmbeddedDoc = false); + + static Arabica::XPath::NodeSet inDocumentOrder(const std::string& element, + const Arabica::DOM::Element& root, + const bool includeEmbeddedDoc = false) { + std::set elements; + elements.insert(element); + return inDocumentOrder(elements, root, includeEmbeddedDoc); + } + + static Arabica::XPath::NodeSet inDocumentOrder(const std::set& elements, + const Arabica::DOM::Element& root, + const bool includeEmbeddedDoc = false); + + static Arabica::XPath::NodeSet filterChildElements(const std::string& tagname, + const Arabica::DOM::Node& node, + bool recurse = false); + + static Arabica::XPath::NodeSet filterChildElements(const std::string& tagName, + const Arabica::XPath::NodeSet& nodeSet, + bool recurse = false); + + static Arabica::XPath::NodeSet filterChildType(const Arabica::DOM::Node_base::Type type, + const Arabica::DOM::Node& node, + bool recurse = false); + + static Arabica::XPath::NodeSet filterChildType(const Arabica::DOM::Node_base::Type type, + const Arabica::XPath::NodeSet& nodeSet, + bool recurse = false); + +protected: + static void inPostFixOrder(const std::set& elements, + const Arabica::DOM::Element& root, + const bool includeEmbeddedDoc, + Arabica::XPath::NodeSet& nodes); + + static void inDocumentOrder(const std::set& elements, + const Arabica::DOM::Element& root, + const bool includeEmbeddedDoc, + Arabica::XPath::NodeSet& nodes); + + +}; + + +} + + +#endif /* end of include guard: DOMUTILS_H_WK0WAEA7 */ diff --git a/src/uscxml/dom/NameSpacingParser.cpp b/src/uscxml/dom/NameSpacingParser.cpp new file mode 100644 index 0000000..0e26b55 --- /dev/null +++ b/src/uscxml/dom/NameSpacingParser.cpp @@ -0,0 +1,71 @@ +/** + * @file + * @author 2016 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#include "uscxml/dom/NameSpacingParser.h" +#include +#include +#include + +namespace uscxml { + +using namespace Arabica::XPath; +using namespace Arabica::DOM; + +NameSpacingParser NameSpacingParser::fromFile(const std::string& file) { + Arabica::SAX::InputSource inputSource; + inputSource.setSystemId(file); + return fromInputSource(inputSource); +} + +NameSpacingParser NameSpacingParser::fromXML(const std::string& xml) { + std::stringstream* ss = new std::stringstream(); + (*ss) << xml; + // we need an auto_ptr for arabica to assume ownership + std::auto_ptr ssPtr(ss); + Arabica::SAX::InputSource inputSource; + inputSource.setByteStream(ssPtr); + return fromInputSource(inputSource); +} + +NameSpacingParser NameSpacingParser::fromInputSource(Arabica::SAX::InputSource& source) { + NameSpacingParser parser; + if(!parser.parse(source) || !parser.getDocument().hasChildNodes()) { + if(parser._errorHandler.errorsReported()) { +// LOG(ERROR) << "could not parse input:"; +// LOG(ERROR) << parser._errorHandler.errors() << std::endl; + } else { + Arabica::SAX::InputSourceResolver resolver(source, Arabica::default_string_adaptor()); + if (!resolver.resolve()) { + LOG(ERROR) << source.getSystemId() << ": no such file"; + } + } + } + return parser; +} + +NameSpacingParser::NameSpacingParser() { + setErrorHandler(_errorHandler); +} + +void NameSpacingParser::startPrefixMapping(const std::string& prefix, const std::string& uri) { + nameSpace.insert(std::make_pair(uri, prefix)); +} + + +} \ No newline at end of file diff --git a/src/uscxml/dom/NameSpacingParser.h b/src/uscxml/dom/NameSpacingParser.h new file mode 100644 index 0000000..1aa85a2 --- /dev/null +++ b/src/uscxml/dom/NameSpacingParser.h @@ -0,0 +1,67 @@ +/** + * @file + * @author 2016 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#ifndef NAMESPACINGPARSER_H_BD6902F6 +#define NAMESPACINGPARSER_H_BD6902F6 + +#include "uscxml/Common.h" +#include +#include +#include // operator<< for nodes +#include +#include +#include + +namespace uscxml { + +class ScriptEntityResolver : public Arabica::SAX::EntityResolver { + virtual InputSourceT resolveEntity(const std::string& publicId, const std::string& systemId) { + Arabica::SAX::InputSource is; + return is; + } +}; + +class USCXML_API NameSpacingParser : public Arabica::SAX2DOM::Parser { +public: + NameSpacingParser(); + NameSpacingParser(const NameSpacingParser& other) {} + static NameSpacingParser fromFile(const std::string& file); + static NameSpacingParser fromXML(const std::string& xml); + static NameSpacingParser fromInputSource(Arabica::SAX::InputSource& source); + + void startPrefixMapping(const std::string& prefix, const std::string& uri); + + std::map nameSpace; + + virtual bool errorsReported() { + return _errorHandler.errorsReported(); + } + + virtual const std::string& errors() { + return _errorHandler.errors(); + } + +private: + Arabica::SAX::CatchErrorHandler _errorHandler; +}; + +} + + +#endif /* end of include guard: NAMESPACINGPARSER_H_BD6902F6 */ diff --git a/src/uscxml/interpreter/InterpreterDraft6.cpp b/src/uscxml/interpreter/InterpreterDraft6.cpp index f79049d..a8bf97b 100644 --- a/src/uscxml/interpreter/InterpreterDraft6.cpp +++ b/src/uscxml/interpreter/InterpreterDraft6.cpp @@ -22,7 +22,7 @@ #include #include "uscxml/UUID.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #define VERBOSE 0 @@ -208,7 +208,7 @@ void InterpreterDraft6::exitStates(const Arabica::XPath::NodeSet& e #endif for (int i = 0; i < statesToExit.size(); i++) { - NodeSet histories = filterChildElements(_nsInfo.xmlNSPrefix + "history", statesToExit[i]); + NodeSet histories = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "history", statesToExit[i]); for (int j = 0; j < histories.size(); j++) { Element historyElem = (Element)histories[j]; std::string historyType = (historyElem.hasAttribute("type") ? historyElem.getAttribute("type") : "shallow"); @@ -237,7 +237,7 @@ void InterpreterDraft6::exitStates(const Arabica::XPath::NodeSet& e for (int i = 0; i < statesToExit.size(); i++) { USCXML_MONITOR_CALLBACK3(beforeExitingState, Element(statesToExit[i]), (i + 1 < statesToExit.size())) - NodeSet onExits = filterChildElements(_nsInfo.xmlNSPrefix + "onExit", statesToExit[i]); + NodeSet onExits = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onExit", statesToExit[i]); for (int j = 0; j < onExits.size(); j++) { Element onExitElem = (Element)onExits[j]; executeContent(onExitElem); @@ -245,7 +245,7 @@ void InterpreterDraft6::exitStates(const Arabica::XPath::NodeSet& e USCXML_MONITOR_CALLBACK3(afterExitingState, Element(statesToExit[i]), (i + 1 < statesToExit.size())) - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]); for (int j = 0; j < invokes.size(); j++) { Element invokeElem = (Element)invokes[j]; if (HAS_ATTR(invokeElem, "persist") && stringIsTrue(ATTR(invokeElem, "persist"))) { @@ -384,7 +384,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet& // extension for flattened interpreters for (unsigned int k = 0; k < statesToEnter.size(); k++) { - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToEnter[k]); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToEnter[k]); for (unsigned int j = 0; j < invokes.size(); j++) { Element invokeElem = Element(invokes[j]); if (HAS_ATTR(invokeElem, "persist") && stringIsTrue(ATTR(invokeElem, "persist"))) { @@ -396,7 +396,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet& USCXML_MONITOR_CALLBACK3(beforeEnteringState, stateElem, (i + 1 < statesToEnter.size())) // extension for flattened SCXML documents, we will need an explicit uninvoke element - NodeSet uninvokes = filterChildElements(_nsInfo.xmlNSPrefix + "uninvoke", statesToEnter[i]); + NodeSet uninvokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "uninvoke", statesToEnter[i]); for (int j = 0; j < uninvokes.size(); j++) { Element uninvokeElem = (Element)uninvokes[j]; cancelInvoke(uninvokeElem); @@ -406,9 +406,9 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet& _statesToInvoke.push_back(stateElem); if (_binding == LATE && !isMember(stateElem, _alreadyEntered)) { - NodeSet dataModelElems = filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", stateElem); + NodeSet dataModelElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", stateElem); if(dataModelElems.size() > 0 && _dataModel) { - Arabica::XPath::NodeSet dataElems = filterChildElements(_nsInfo.xmlNSPrefix + "data", dataModelElems[0]); + Arabica::XPath::NodeSet dataElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", dataModelElems[0]); for (int j = 0; j < dataElems.size(); j++) { if (dataElems[j].getNodeType() == Node_base::ELEMENT_NODE) initializeData(Element(dataElems[j])); @@ -417,7 +417,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet& _alreadyEntered.push_back(stateElem); } // execute onentry executable content - NodeSet onEntryElems = filterChildElements(_nsInfo.xmlNSPrefix + "onEntry", stateElem); + NodeSet onEntryElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onEntry", stateElem); executeContent(onEntryElems, false); USCXML_MONITOR_CALLBACK3(afterEnteringState, stateElem, (i + 1 < statesToEnter.size())) @@ -443,7 +443,7 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet& if (isFinal(stateElem)) { Arabica::DOM::Element doneData; - Arabica::XPath::NodeSet doneDatas = filterChildElements(_nsInfo.xmlNSPrefix + "donedata", stateElem); + Arabica::XPath::NodeSet doneDatas = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "donedata", stateElem); if (doneDatas.size() > 0) { // only process first donedata element doneData = Element(doneDatas[0]); @@ -518,7 +518,7 @@ void InterpreterDraft6::addStatesToEnter(const Element& state, } } else { defaultHistoryContent.push_back(getParentState(state)); - NodeSet transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", state); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state); for (int i = 0; i < transitions.size(); i++) { NodeSet targets = getTargetStates(Element(transitions[i])); for (int j = 0; j < targets.size(); j++) { @@ -561,7 +561,7 @@ void InterpreterDraft6::handleDOMEvent(Arabica::DOM::Events::Event& if (event.getType().compare("DOMAttrModified") == 0) // we do not care about attributes return; Node target = Arabica::DOM::Node(event.getTarget()); - NodeSet transitions = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "transition", target, true); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", target, true); for (int i = 0; i < transitions.size(); i++) { const Element transElem = Element(transitions[i]); if (_transWithinParallel.find(transElem) != _transWithinParallel.end()) diff --git a/src/uscxml/interpreter/InterpreterFast.cpp b/src/uscxml/interpreter/InterpreterFast.cpp index 94fcdce..ab5dce0 100644 --- a/src/uscxml/interpreter/InterpreterFast.cpp +++ b/src/uscxml/interpreter/InterpreterFast.cpp @@ -24,7 +24,7 @@ #include #include "uscxml/UUID.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" namespace uscxml { diff --git a/src/uscxml/interpreter/InterpreterRC.cpp b/src/uscxml/interpreter/InterpreterRC.cpp index e1f4ada..d959e3d 100644 --- a/src/uscxml/interpreter/InterpreterRC.cpp +++ b/src/uscxml/interpreter/InterpreterRC.cpp @@ -24,7 +24,7 @@ #include #include "uscxml/UUID.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #define VERBOSE 0 #define VERBOSE_STATE_SELECTION 0 @@ -66,7 +66,7 @@ Arabica::XPath::NodeSet InterpreterRC::removeConflictingTransitions } if (!t1Preempted) { - // remove transitionsToRemove from filteredTransitions + // remove transitionsToRemove from DOMUtils::filteredTransitions std::list > tmp; for (int i = 0; i < filteredTransitions.size(); i++) { if (!isMember(filteredTransitions[i], transitionsToRemove)) { @@ -119,7 +119,7 @@ void InterpreterRC::exitStates(const Arabica::XPath::NodeSet& enabl for (int i = 0; i < statesToExit.size(); i++) { - NodeSet histories = filterChildElements(_nsInfo.xmlNSPrefix + "history", statesToExit[i]); + NodeSet histories = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "history", statesToExit[i]); for (int j = 0; j < histories.size(); j++) { Element historyElem = (Element)histories[j]; std::string historyType = (historyElem.hasAttribute("type") ? historyElem.getAttribute("type") : "shallow"); @@ -140,7 +140,7 @@ void InterpreterRC::exitStates(const Arabica::XPath::NodeSet& enabl for (int i = 0; i < statesToExit.size(); i++) { USCXML_MONITOR_CALLBACK3(beforeExitingState, Element(statesToExit[i]), (i + 1 < statesToExit.size())) - NodeSet onExits = filterChildElements(_nsInfo.xmlNSPrefix + "onExit", statesToExit[i]); + NodeSet onExits = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onExit", statesToExit[i]); for (int j = 0; j < onExits.size(); j++) { Element onExitElem = (Element)onExits[j]; executeContent(onExitElem); @@ -148,7 +148,7 @@ void InterpreterRC::exitStates(const Arabica::XPath::NodeSet& enabl USCXML_MONITOR_CALLBACK3(afterExitingState, Element(statesToExit[i]), (i + 1 < statesToExit.size())) - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]); for (int j = 0; j < invokes.size(); j++) { Element invokeElem = (Element)invokes[j]; if (HAS_ATTR(invokeElem, "persist") && stringIsTrue(ATTR(invokeElem, "persist"))) { @@ -254,9 +254,9 @@ void InterpreterRC::enterStates(const Arabica::XPath::NodeSet& enab _statesToInvoke.push_back(s); if (_binding == LATE && !isMember(s, _alreadyEntered)) { - NodeSet dataModelElems = filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", s); + NodeSet dataModelElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", s); if(dataModelElems.size() > 0 && _dataModel) { - Arabica::XPath::NodeSet dataElems = filterChildElements(_nsInfo.xmlNSPrefix + "data", dataModelElems[0]); + Arabica::XPath::NodeSet dataElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", dataModelElems[0]); for (int j = 0; j < dataElems.size(); j++) { if (dataElems[j].getNodeType() == Node_base::ELEMENT_NODE) initializeData(Element(dataElems[j])); @@ -265,7 +265,7 @@ void InterpreterRC::enterStates(const Arabica::XPath::NodeSet& enab _alreadyEntered.push_back(s); } // execute onentry executable content - NodeSet onEntryElems = filterChildElements(_nsInfo.xmlNSPrefix + "onEntry", s); + NodeSet onEntryElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onEntry", s); executeContent(onEntryElems, false); if (isMember(s, statesForDefaultEntry)) { @@ -280,7 +280,7 @@ void InterpreterRC::enterStates(const Arabica::XPath::NodeSet& enab if (HAS_ATTR(_scxml, "flat") && stringIsTrue(ATTR(_scxml, "flat"))) { // extension for flattened interpreters - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", s); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", s); for (unsigned int j = 0; j < invokes.size(); j++) { Element invokeElem = Element(invokes[j]); if (HAS_ATTR(invokeElem, "persist") && stringIsTrue(ATTR(invokeElem, "persist"))) { @@ -289,7 +289,7 @@ void InterpreterRC::enterStates(const Arabica::XPath::NodeSet& enab } // extension for flattened SCXML documents, we will need an explicit uninvoke element - NodeSet uninvokes = filterChildElements(_nsInfo.xmlNSPrefix + "uninvoke", s); + NodeSet uninvokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "uninvoke", s); for (int j = 0; j < uninvokes.size(); j++) { Element uninvokeElem = (Element)uninvokes[j]; cancelInvoke(uninvokeElem); @@ -305,7 +305,7 @@ void InterpreterRC::enterStates(const Arabica::XPath::NodeSet& enab Element parent = (Element)s.getParentNode(); Arabica::DOM::Element doneData; - Arabica::XPath::NodeSet doneDatas = filterChildElements(_nsInfo.xmlNSPrefix + "donedata", s); + Arabica::XPath::NodeSet doneDatas = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "donedata", s); if (doneDatas.size() > 0) { // only process first donedata element doneData = Element(doneDatas[0]); @@ -408,7 +408,7 @@ Arabica::XPath::NodeSet InterpreterRC::getEffectiveTargetStates(con if (_historyValue.find(ATTR(s, "id")) != _historyValue.end()) { targets.push_back(_historyValue[ATTR(s, "id")]); } else { - NodeSet histTrans = filterChildElements(_nsInfo.xmlNSPrefix + "transition", s); + NodeSet histTrans = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", s); // TODO: what if there are many history transitions? if (histTrans.size() > 0) targets.push_back(getEffectiveTargetStates(Element(histTrans[0]))); @@ -489,7 +489,7 @@ void InterpreterRC::addDescendantStatesToEnter(const Arabica::DOM::Element transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", state); + NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", state); if (transitions.size() > 0) { // TODO: what if there are many history transitions? // std::cout << "HIST: " << ATTR_CAST(getParentState(state), "id") << std::endl; @@ -653,7 +653,7 @@ void InterpreterRC::handleDOMEvent(Arabica::DOM::Events::Event& eve return; // Node target = Arabica::DOM::Node(event.getTarget()); -// NodeSet transitions = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "transition", target, true); +// NodeSet transitions = DOMUtils::DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", target, true); // if (transitions.size() > 0) _exitSet.clear(); diff --git a/src/uscxml/messages/Data.cpp b/src/uscxml/messages/Data.cpp index 7afad43..53d4571 100644 --- a/src/uscxml/messages/Data.cpp +++ b/src/uscxml/messages/Data.cpp @@ -22,7 +22,12 @@ #include -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" +#include "uscxml/dom/NameSpacingParser.h" +#include +#include +#include + #include "glog/logging.h" #ifdef HAS_STRING_H diff --git a/src/uscxml/messages/Event.cpp b/src/uscxml/messages/Event.cpp index fda24dd..072c1b9 100644 --- a/src/uscxml/messages/Event.cpp +++ b/src/uscxml/messages/Event.cpp @@ -18,7 +18,10 @@ */ #include "uscxml/messages/Event.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" +#include +#include +#include namespace uscxml { diff --git a/src/uscxml/messages/MMIMessages.cpp b/src/uscxml/messages/MMIMessages.cpp index 35e8b66..1c6cc7d 100644 --- a/src/uscxml/messages/MMIMessages.cpp +++ b/src/uscxml/messages/MMIMessages.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include diff --git a/src/uscxml/messages/MMIMessages.h b/src/uscxml/messages/MMIMessages.h index 4f3947e..3538816 100644 --- a/src/uscxml/messages/MMIMessages.h +++ b/src/uscxml/messages/MMIMessages.h @@ -22,6 +22,7 @@ #define MMI_WITH_OPERATOR_EVENT 1 +#include #include #include #include diff --git a/src/uscxml/plugins/DataModel.h b/src/uscxml/plugins/DataModel.h index f229a94..1a64d28 100644 --- a/src/uscxml/plugins/DataModel.h +++ b/src/uscxml/plugins/DataModel.h @@ -22,13 +22,16 @@ #include "uscxml/config.h" #include "uscxml/Common.h" +#include "uscxml/InterpreterInfo.h" #include "uscxml/plugins/EventHandler.h" -#ifdef BUILD_PROFILING -#include "uscxml/concurrency/Timer.h" -#define TIME_BLOCK Measurement msm(&timer); -#else -#define TIME_BLOCK (0); +#ifndef TIME_BLOCK +# ifdef BUILD_PROFILING +# include "uscxml/concurrency/Timer.h" +# define TIME_BLOCK Measurement msm(&timer); +# else +# define TIME_BLOCK +# endif #endif #include diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h index cb196ff..0b49c92 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h @@ -20,7 +20,7 @@ #ifndef JSCDOM_H_1RC5LCG8 #define JSCDOM_H_1RC5LCG8 -#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterInfo.h" #include #include #include "../Storage.h" diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 86bafd3..d3eb0ef 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -19,6 +19,8 @@ #include "uscxml/Common.h" #include "uscxml/config.h" +#include "uscxml/URL.h" +#include "uscxml/util/String.h" #include "JSCDataModel.h" #include "JSCDOM.h" @@ -41,7 +43,7 @@ #include "dom/JSCDataView.h" #include "uscxml/Message.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #ifdef BUILD_AS_PLUGINS @@ -94,7 +96,7 @@ void JSCDataModel::addExtension(DataModelExtension* ext) { _extensions.insert(ext); JSObjectRef currScope = JSContextGetGlobalObject(_ctx); - std::list locPath = InterpreterImpl::tokenize(ext->provides(), '.'); + std::list locPath = tokenize(ext->provides(), '.'); std::list::iterator locIter = locPath.begin(); while(true) { std::string pathComp = *locIter; @@ -309,7 +311,7 @@ void JSCDataModel::setEvent(const Event& event) { handleException(exception); } else { JSStringRef propName = JSStringCreateWithUTF8CString("data"); - JSStringRef contentStr = JSStringCreateWithUTF8CString(InterpreterImpl::spaceNormalize(event.content).c_str()); + JSStringRef contentStr = JSStringCreateWithUTF8CString(spaceNormalize(event.content).c_str()); JSObjectSetProperty(_ctx, eventObj, propName, JSValueMakeString(_ctx, contentStr), 0, &exception); JSStringRelease(propName); JSStringRelease(contentStr); @@ -701,7 +703,7 @@ void JSCDataModel::assign(const Element& assignElem, throw Event(); assign(key, Data(d, Data::INTERPRETED)); } catch (Event e) { - assign(key, Data("\"" + InterpreterImpl::spaceNormalize(content) + "\"", Data::INTERPRETED)); + assign(key, Data("\"" + spaceNormalize(content) + "\"", Data::INTERPRETED)); } } else { JSValueRef exception = NULL; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 2a2b1cc..ccadc79 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -20,7 +20,8 @@ #ifndef JSCDATAMODEL_H_KN8TWG0V #define JSCDATAMODEL_H_KN8TWG0V -#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterInfo.h" +#include "uscxml/plugins/DataModel.h" #include #include #include "JSCDOM.h" diff --git a/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp b/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp index edab33c..980fc5d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp @@ -19,6 +19,8 @@ #include "Storage.h" #include +#include +#include namespace uscxml { diff --git a/src/uscxml/plugins/datamodel/ecmascript/Storage.h b/src/uscxml/plugins/datamodel/ecmascript/Storage.h index 6ec62dd..35bde86 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/Storage.h +++ b/src/uscxml/plugins/datamodel/ecmascript/Storage.h @@ -22,8 +22,6 @@ #include #include -#include -#include namespace uscxml { diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h index 7509390..a49410c 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h +++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h @@ -21,7 +21,7 @@ #define TYPEDARRAY_H_99815BLY #include "uscxml/Common.h" -#include "uscxml/Message.h" +#include "uscxml/messages/Blob.h" #include #include diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 3004b91..85ae0cd 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -46,7 +46,7 @@ #include "dom/V8DataView.h" #include "uscxml/Message.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #ifdef BUILD_AS_PLUGINS @@ -102,7 +102,7 @@ void V8DataModel::addExtension(DataModelExtension* ext) { v8::Context::Scope contextScope(_contexts.front()); v8::Handle currScope = _contexts.front()->Global(); - std::list locPath = InterpreterImpl::tokenize(ext->provides(), '.'); + std::list locPath = tokenize(ext->provides(), '.'); std::list::iterator locIter = locPath.begin(); while(true) { std::string pathComp = *locIter; @@ -317,7 +317,7 @@ void V8DataModel::setEvent(const Event& event) { if (!json.empty()) { eventObj->Set(v8::String::New("data"), getDataAsValue(json)); } else { - eventObj->Set(v8::String::New("data"), v8::String::New(InterpreterImpl::spaceNormalize(event.content).c_str())); + eventObj->Set(v8::String::New("data"), v8::String::New(spaceNormalize(event.content).c_str())); } } else { // _event.data is KVP @@ -716,7 +716,7 @@ void V8DataModel::assign(const Element& assignElem, try { evalAsValue(key + " = " + content); } catch (...) { - evalAsValue(key + " = " + "\"" + InterpreterImpl::spaceNormalize(content) + "\""); + evalAsValue(key + " = " + "\"" + spaceNormalize(content) + "\""); } } else { global->Set(v8::String::New(key.c_str()), v8::Undefined()); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index 35cc12d..8e665b7 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -20,7 +20,7 @@ #ifndef V8DATAMODEL_H_KN8TWG0V #define V8DATAMODEL_H_KN8TWG0V -#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterInfo.h" #include #include #include "V8DOM.h" diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index c204946..c23b483 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -20,6 +20,7 @@ #include #include "uscxml/Common.h" +#include "uscxml/util/String.h" #include "LuaDataModel.h" // disable forcing to bool performance warning @@ -28,7 +29,7 @@ #include "LuaBridge.h" #pragma warning(pop) -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/Message.h" #include @@ -123,7 +124,7 @@ LuaDataModel::LuaDataModel() { static int luaInFunction(lua_State * l) { luabridge::LuaRef ref = luabridge::getGlobal(l, "__interpreter"); - InterpreterImpl* interpreter = ref.cast(); + InterpreterInfo* interpreter = ref.cast(); int stackSize = lua_gettop(l); for (int i = 0; i < stackSize; i++) { @@ -278,7 +279,7 @@ void LuaDataModel::setEvent(const Event& event) { std::string trimmed = boost::trim_copy(event.content); if ((boost::starts_with(trimmed, "'") && boost::ends_with(trimmed, "'")) || (boost::starts_with(trimmed, "\"") && boost::ends_with(trimmed, "\""))) { - luaEvent["data"] = InterpreterImpl::spaceNormalize(event.content); + luaEvent["data"] = spaceNormalize(event.content); } else { Data tmp(event.content, Data::INTERPRETED); luaEvent["data"] = getDataAsLua(_luaState, tmp); @@ -464,7 +465,7 @@ void LuaDataModel::assign(const Arabica::DOM::Element& assignElem, try { eval(Arabica::DOM::Element(), key + " = " + content + ";"); } catch (...) { - eval(Arabica::DOM::Element(), key + " = " + "\"" + InterpreterImpl::spaceNormalize(content) + "\";"); + eval(Arabica::DOM::Element(), key + " = " + "\"" + spaceNormalize(content) + "\";"); } } else { eval(Arabica::DOM::Element(), key + " = " + "nil;"); diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index bce1d62..eb23815 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -20,7 +20,8 @@ #ifndef LUADATAMODEL_H_113E014C #define LUADATAMODEL_H_113E014C -#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterInfo.h" +#include "uscxml/plugins/DataModel.h" #include #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp index c9f0d5a..7211dc5 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp @@ -21,7 +21,7 @@ #include "uscxml/Common.h" #include "NULLDataModel.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/Message.h" #include diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.h b/src/uscxml/plugins/datamodel/null/NULLDataModel.h index db5fa28..f813ae1 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.h +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.h @@ -20,7 +20,8 @@ #ifndef NULLDATAMODEL_H_KN8TWG0V #define NULLDATAMODEL_H_KN8TWG0V -#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterInfo.h" +#include "uscxml/plugins/DataModel.h" #include #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index fc41901..9a59a20 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -21,8 +21,10 @@ #include "uscxml/Common.h" #include "uscxml/config.h" +#include "uscxml/util/String.h" +#include "uscxml/URL.h" #include "SWIDataModel.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/Message.h" #include @@ -272,7 +274,7 @@ void SWIDataModel::setEvent(const Event& event) { dataInitStr << "load_xml_file('" << domUrl.asLocalFile(".pl") << "', XML), copy_term(XML,DATA), assert(event(data(DATA)))"; PlCall(dataInitStr.str().c_str()); } else if (event.content.size() > 0) { - PlCall("assert", PlCompound("event", PlCompound("data", PlString(InterpreterImpl::spaceNormalize(event.content).c_str())))); + PlCall("assert", PlCompound("event", PlCompound("data", PlString(spaceNormalize(event.content).c_str())))); } else if (!event.data.empty()) { assertFromData(event.data, "event(data(", 2); } diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index 398e24c..e968b61 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -20,7 +20,8 @@ #ifndef SWIDATAMODEL_H_KN8TWG0V #define SWIDATAMODEL_H_KN8TWG0V -#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterInfo.h" +#include "uscxml/plugins/DataModel.h" #include "uscxml/SWIConfig.h" #include diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp index d9f50cf..02df56d 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp @@ -21,8 +21,9 @@ #include "uscxml/Common.h" #include "uscxml/config.h" +#include "uscxml/util/String.h" #include "PromelaDataModel.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/Message.h" #include #include @@ -138,7 +139,7 @@ void PromelaDataModel::setEvent(const Event& event) { if (isNumeric(event.content.c_str(), 10)) { variable.compound["value"].compound["data"] = Data(event.content, Data::INTERPRETED); } else { - variable.compound["value"].compound["data"] = Data(InterpreterImpl::spaceNormalize(event.content), Data::VERBATIM); + variable.compound["value"].compound["data"] = Data(spaceNormalize(event.content), Data::VERBATIM); } } } else { diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h index 060560d..0778ecf 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h @@ -20,7 +20,8 @@ #ifndef PROMELADATAMODEL_H_4VG0TDMU #define PROMELADATAMODEL_H_4VG0TDMU -#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterInfo.h" +#include "uscxml/plugins/DataModel.h" #include #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp index de8eecb..3bb22cc 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp @@ -22,10 +22,16 @@ #include "XPathDataModel.h" #include "uscxml/Message.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/util/String.h" +#include "uscxml/dom/DOMUtils.h" #include #include +#include +//#include +//#include +//#include + #ifdef BUILD_AS_PLUGINS #include #endif @@ -195,7 +201,7 @@ void XPathDataModel::setEvent(const Event& event) { } if (event.content.size() > 0) { - Text textNode = _doc.createTextNode(InterpreterImpl::spaceNormalize(event.content).c_str()); + Text textNode = _doc.createTextNode(spaceNormalize(event.content).c_str()); eventDataElem.appendChild(textNode); } if (event.dom) { @@ -503,7 +509,7 @@ void XPathDataModel::assign(const Element& assignElem, } assign(key, nodeSet, assignElem); } else if (content.length() > 0) { - Text textNode = _doc.createTextNode(InterpreterImpl::spaceNormalize(content)); + Text textNode = _doc.createTextNode(spaceNormalize(content)); nodeSet.push_back(textNode); assign(key, nodeSet, assignElem); } else if (HAS_ATTR(assignElem, "expr")) { diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h index 9a71b79..7a085d2 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h @@ -20,7 +20,9 @@ #ifndef XPATHDATAMODEL_H_KN8TWG0V #define XPATHDATAMODEL_H_KN8TWG0V -#include "uscxml/Interpreter.h" +#include "uscxml/InterpreterInfo.h" +#include "uscxml/plugins/DataModel.h" + #include #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/plugins/element/fetch/FetchElement.cpp b/src/uscxml/plugins/element/fetch/FetchElement.cpp index 595c913..bf3129b 100644 --- a/src/uscxml/plugins/element/fetch/FetchElement.cpp +++ b/src/uscxml/plugins/element/fetch/FetchElement.cpp @@ -20,7 +20,7 @@ #include #include "FetchElement.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #include diff --git a/src/uscxml/plugins/element/file/FileElement.cpp b/src/uscxml/plugins/element/file/FileElement.cpp index decd5ca..c2e4f55 100644 --- a/src/uscxml/plugins/element/file/FileElement.cpp +++ b/src/uscxml/plugins/element/file/FileElement.cpp @@ -24,7 +24,8 @@ #include #include "uscxml/messages/Blob.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" +#include "uscxml/dom/NameSpacingParser.h" #ifdef BUILD_AS_PLUGINS #include diff --git a/src/uscxml/plugins/element/mmi/MMIEvents.h b/src/uscxml/plugins/element/mmi/MMIEvents.h index 82d0b22..74c66c0 100644 --- a/src/uscxml/plugins/element/mmi/MMIEvents.h +++ b/src/uscxml/plugins/element/mmi/MMIEvents.h @@ -42,8 +42,8 @@ public:\ std::string getLocalName() { return "elementName"; }\ std::string getNamespace() { return "http://www.w3.org/2008/04/mmi-arch"; }\ bool processChildren() { return false; }\ - void enterElement(const Arabica::DOM::Node& node);\ - void exitElement(const Arabica::DOM::Node& node) {}\ + void enterElement(const Arabica::DOM::Element& node) {}\ + void exitElement(const Arabica::DOM::Element& node) {}\ }; namespace uscxml { diff --git a/src/uscxml/plugins/element/postpone/PostponeElement.cpp b/src/uscxml/plugins/element/postpone/PostponeElement.cpp index a041a9e..460cc88 100644 --- a/src/uscxml/plugins/element/postpone/PostponeElement.cpp +++ b/src/uscxml/plugins/element/postpone/PostponeElement.cpp @@ -21,7 +21,7 @@ #include "PostponeElement.h" #include "uscxml/plugins/invoker/http/HTTPServletInvoker.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/plugins/element/respond/RespondElement.cpp b/src/uscxml/plugins/element/respond/RespondElement.cpp index a62f934..65babd7 100644 --- a/src/uscxml/plugins/element/respond/RespondElement.cpp +++ b/src/uscxml/plugins/element/respond/RespondElement.cpp @@ -20,7 +20,7 @@ #include "RespondElement.h" #include "uscxml/plugins/invoker/http/HTTPServletInvoker.h" #include "uscxml/server/InterpreterServlet.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #ifdef BUILD_AS_PLUGINS @@ -79,7 +79,7 @@ void RespondElement::enterElement(const Arabica::DOM::Element& node httpReply.status = strTo(statusStr);; // extract the content - Arabica::XPath::NodeSet contents = InterpreterImpl::filterChildElements(_interpreter->getNameSpaceInfo().getXMLPrefixForNS(getNamespace()) + "content", node); + Arabica::XPath::NodeSet contents = DOMUtils::filterChildElements(_interpreter->getNameSpaceInfo().getXMLPrefixForNS(getNamespace()) + "content", node); if (contents.size() > 0) { Arabica::DOM::Element contentElem = Arabica::DOM::Element(contents[0]); if (HAS_ATTR(contentElem, "expr")) { // -- content is evaluated string from datamodel ------ @@ -143,7 +143,7 @@ void RespondElement::enterElement(const Arabica::DOM::Element& node } // process headers - Arabica::XPath::NodeSet headers = InterpreterImpl::filterChildElements(_interpreter->getNameSpaceInfo().getXMLPrefixForNS(getNamespace()) + "header", node); + Arabica::XPath::NodeSet headers = DOMUtils::filterChildElements(_interpreter->getNameSpaceInfo().getXMLPrefixForNS(getNamespace()) + "header", node); for (int i = 0; i < headers.size(); i++) { Arabica::DOM::Element headerElem = Arabica::DOM::Element(headers[i]); diff --git a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp index f8b4904..0b54228 100644 --- a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp +++ b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp @@ -20,7 +20,7 @@ #include #include "HeartbeatInvoker.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index 7bd40d9..62f7a1e 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -19,7 +19,8 @@ #include "USCXMLInvoker.h" #include -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" +#include #ifdef BUILD_AS_PLUGINS #include @@ -91,7 +92,7 @@ void USCXMLInvoker::invoke(const InvokeRequest& req) { } if (_invokedInterpreter) { if (req.elem && HAS_ATTR(req.elem, "initial")) { - _invokedInterpreter.setInitalConfiguration(InterpreterImpl::tokenize(ATTR(req.elem, "initial"))); + _invokedInterpreter.setInitalConfiguration(tokenize(ATTR(req.elem, "initial"))); } DataModel dataModel(_invokedInterpreter.getImpl()->getDataModel()); diff --git a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp index 196d6d2..9c85f37 100644 --- a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp @@ -22,7 +22,7 @@ #include #include "XHTMLInvoker.h" #include -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #include diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp index 49aa8dc..1bced48 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp @@ -21,7 +21,9 @@ #include "uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h" #include "uscxml/Message.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" +#include "uscxml/dom/NameSpacingParser.h" + #include #include #include diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index 90ce242..6f2347c 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -26,7 +26,8 @@ #endif #include "uscxml/server/HTTPServer.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" +#include "uscxml/dom/NameSpacingParser.h" #include #include diff --git a/src/uscxml/transform/ChartAnnotator.cpp b/src/uscxml/transform/ChartAnnotator.cpp new file mode 100644 index 0000000..5bab391 --- /dev/null +++ b/src/uscxml/transform/ChartAnnotator.cpp @@ -0,0 +1,24 @@ +/** + * @file + * @author 2012-2015 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#include "ChartAnnotator.h" + +namespace uscxml { + +} \ No newline at end of file diff --git a/src/uscxml/transform/ChartAnnotator.h b/src/uscxml/transform/ChartAnnotator.h new file mode 100644 index 0000000..3ce8f4a --- /dev/null +++ b/src/uscxml/transform/ChartAnnotator.h @@ -0,0 +1,27 @@ +/** + * @file + * @author 2012-2016 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#ifndef CHARTANNOTATOR_H_2AC11ECB +#define CHARTANNOTATOR_H_2AC11ECB + +namespace uscxml { + +} + +#endif /* end of include guard: CHARTANNOTATOR_H_2AC11ECB */ diff --git a/src/uscxml/transform/ChartToC.cpp b/src/uscxml/transform/ChartToC.cpp index 7cc50fc..ee0b431 100644 --- a/src/uscxml/transform/ChartToC.cpp +++ b/src/uscxml/transform/ChartToC.cpp @@ -21,10 +21,11 @@ #include "uscxml/transform/ChartToC.h" #include "uscxml/debug/Complexity.h" #include +#include #include #include "uscxml/UUID.h" #include "uscxml/util/MD5.hpp" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #include #include @@ -205,10 +206,10 @@ void ChartToC::setStateCompletion() { completion = getChildStates(state); } else if (state.hasAttribute("initial")) { - completion = getStates(tokenizeIdRefs(state.getAttribute("initial"))); + completion = getStates(tokenize(state.getAttribute("initial"))); } else { - NodeSet initElems = filterChildElements(_nsInfo.xmlNSPrefix + "initial", state); + NodeSet initElems = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "initial", state); if(initElems.size() > 0 && !iequals(ATTR_CAST(initElems[0], "generated"), "true")) { // initial element is first child completion.push_back(initElems[0]); @@ -450,7 +451,7 @@ void ChartToC::writeForwardDeclarations(std::ostream& stream) { } void ChartToC::findNestedMachines() { - NodeSet invokes = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); for (size_t i = 0; i < invokes.size(); i++) { if(isInEmbeddedDocument(invokes[i])) @@ -472,10 +473,10 @@ void ChartToC::findNestedMachines() { c2c = new ChartToC(Interpreter::fromURL(srcURL.asString())); } else { // is there a nested scxml machine inside? - NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", invoke); + NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", invoke); if (contents.size() == 0) continue; - NodeSet scxmls = filterChildElements(_nsInfo.xmlNSPrefix + "scxml", contents[0]); + NodeSet scxmls = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "scxml", contents[0]); if (scxmls.size() == 0) continue; @@ -555,7 +556,7 @@ void ChartToC::writeMacros(std::ostream& stream) { stream << std::endl; stream << "#ifndef USCXML_MAX_NR_STATES_BYTES " << std::endl; - stream << "# define USCXML_MAX_NR_STATES_BYTES " << _stateCharArraySize << std::endl; + stream << "# define USCXML_MAX_NR_STATES_BYTES " << (std::max)((size_t)1, _stateCharArraySize) << std::endl; stream << "#endif " << std::endl; stream << std::endl; @@ -566,7 +567,7 @@ void ChartToC::writeMacros(std::ostream& stream) { stream << std::endl; stream << "#ifndef USCXML_MAX_NR_TRANS_BYTES " << std::endl; - stream << "# define USCXML_MAX_NR_TRANS_BYTES " << _transCharArraySize << std::endl; + stream << "# define USCXML_MAX_NR_TRANS_BYTES " << (std::max)((size_t)1, _transCharArraySize) << std::endl; stream << "#endif " << std::endl; stream << std::endl; @@ -1037,7 +1038,7 @@ void ChartToC::writeExecContentFinalize(std::ostream& stream) { for (size_t i = 0; i < finalizes.size(); i++) { Element finalize(finalizes[i]); - NodeSet execContent = filterChildType(Node_base::ELEMENT_NODE, finalize); + NodeSet execContent = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, finalize); if (execContent.size() > 0) { stream << "static int " << _prefix << "_" << DOMUtils::idForNode(finalize) << "(const uscxml_ctx* ctx, const uscxml_elem_invoke* invocation, const void* event) {" << std::endl; @@ -1066,7 +1067,7 @@ void ChartToC::writeExecContent(std::ostream& stream) { if (i == 0) { // root state - we need to perform some initialization here - NodeSet globalScripts = filterChildElements(_nsInfo.xmlNSPrefix + "script", state); + NodeSet globalScripts = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", state); if (globalScripts.size() > 0) { for (size_t j = 0; j < globalScripts.size(); j++) { stream << "static int " << _prefix << "_global_script_" << toStr(j) << "(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {" << std::endl; @@ -1086,7 +1087,7 @@ void ChartToC::writeExecContent(std::ostream& stream) { } } - NodeSet onexit = filterChildElements(_nsInfo.xmlNSPrefix + "onexit", state); + NodeSet onexit = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onexit", state); for (size_t j = 0; j < onexit.size(); j++) { stream << "static int " << _prefix << "_" << DOMUtils::idForNode(state) << "_on_exit_" << toStr(j) << "(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {" << std::endl; stream << " int err = USCXML_ERR_OK;" << std::endl; @@ -1107,7 +1108,7 @@ void ChartToC::writeExecContent(std::ostream& stream) { } - NodeSet onentry = filterChildElements(_nsInfo.xmlNSPrefix + "onentry", state); + NodeSet onentry = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onentry", state); for (size_t j = 0; j < onentry.size(); j++) { stream << "static int " << _prefix << "_" << DOMUtils::idForNode(state) << "_on_entry_" << toStr(j) << "(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {" << std::endl; stream << " int err = USCXML_ERR_OK;" << std::endl; @@ -1129,7 +1130,7 @@ void ChartToC::writeExecContent(std::ostream& stream) { } - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", state); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", state); if (invokes.size() > 0) { stream << "static int " << _prefix << "_" << DOMUtils::idForNode(state) << "_invoke(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke) {" << std::endl; for (size_t j = 0; j < invokes.size(); j++) { @@ -1144,7 +1145,7 @@ void ChartToC::writeExecContent(std::ostream& stream) { for (size_t i = 0; i < _transitions.size(); i++) { Element transition(_transitions[i]); - NodeSet execContent = filterChildType(Node_base::ELEMENT_NODE, transition); + NodeSet execContent = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, transition); if (execContent.size() > 0) { stream << "static int " << _prefix << "_" << DOMUtils::idForNode(transition) << "_on_trans(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) {" << std::endl; @@ -1205,7 +1206,7 @@ void ChartToC::writeExecContent(std::ostream& stream, const Arabica::DOM::Nodeexec_content_script(ctx, "; stream << (HAS_ATTR(elem, "src") ? "\"" + escape(ATTR(elem, "src")) + "\"" : "NULL") << ", "; - NodeSet scriptTexts = filterChildType(Node_base::TEXT_NODE, elem); + NodeSet scriptTexts = DOMUtils::filterChildType(Node_base::TEXT_NODE, elem); if (scriptTexts.size() > 0) { stream << "\""; writeExecContent(stream, scriptTexts[0], 0); @@ -1329,7 +1330,7 @@ void ChartToC::writeElementInfoInvocation(std::ostream& stream) { stream << "#ifndef USCXML_NO_ELEM_INFO" << std::endl; stream << std::endl; - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); if (invokes.size() > 0) { _hasElement.insert("invoke"); stream << "static const uscxml_elem_invoke " << _prefix << "_elem_invokes[" << invokes.size() << "] = {" << std::endl; @@ -1426,7 +1427,7 @@ void ChartToC::writeElementInfoInvocation(std::ostream& stream) { stream << ", " << std::endl; stream << " /* finalize */ "; - NodeSet finalizes = filterChildElements(_nsInfo.xmlNSPrefix + "finalize", invoke); + NodeSet finalizes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "finalize", invoke); if (finalizes.size() > 0) { stream << _prefix << "_" << DOMUtils::idForNode(finalizes[0]); } else { @@ -1434,7 +1435,7 @@ void ChartToC::writeElementInfoInvocation(std::ostream& stream) { } stream << ", " << std::endl; - NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", invoke); + NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", invoke); if (contents.size() > 0 && !HAS_ATTR(invoke, "md5sum")) { std::stringstream ss; NodeList cChilds = contents[0].getChildNodes(); @@ -1498,7 +1499,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << (HAS_ATTR(assign, "location") ? "\"" + escape(ATTR(assign, "location")) + "\"" : "NULL") << ", "; stream << (HAS_ATTR(assign, "expr") ? "\"" + escape(ATTR(assign, "expr")) + "\"" : "NULL") << ", "; - NodeSet assignTexts = filterChildType(Node_base::TEXT_NODE, assign); + NodeSet assignTexts = DOMUtils::filterChildType(Node_base::TEXT_NODE, assign); if (assignTexts.size() > 0) { if (boost::trim_copy(assignTexts[0].getNodeValue()).length() > 0) { std::string escaped = escape(assignTexts[0].getNodeValue()); @@ -1557,7 +1558,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << (HAS_ATTR(data, "src") ? "\"" + escape(ATTR(data, "src")) + "\"" : "NULL") << ", "; stream << (HAS_ATTR(data, "expr") ? "\"" + escape(ATTR(data, "expr")) + "\"" : "NULL") << ", "; - NodeSet dataTexts = filterChildType(Node_base::TEXT_NODE, data); + NodeSet dataTexts = DOMUtils::filterChildType(Node_base::TEXT_NODE, data); if (dataTexts.size() > 0) { if (boost::trim_copy(dataTexts[0].getNodeValue()).length() > 0) { std::string escaped = escape(dataTexts[0].getNodeValue()); @@ -1640,7 +1641,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << std::endl << " /* namelist */ "; stream << (HAS_ATTR(send, "namelist") ? "\"" + escape(ATTR(send, "namelist")) + "\"" : "NULL") << ", "; - NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", send); + NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", send); if (contents.size() > 0) { std::stringstream ss; NodeList cChilds = contents[0].getChildNodes(); @@ -1684,7 +1685,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { // parent stream << ATTR_CAST(donedata.getParentNode(), "documentOrder") << ", "; - NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", donedata); + NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", donedata); if (contents.size() > 0) { std::stringstream ss; NodeList cChilds = contents[0].getChildNodes(); @@ -1751,7 +1752,11 @@ void ChartToC::writeMachineInfo(std::ostream& stream) { stream << " /* datamodel */ \"" << (HAS_ATTR(_scxml, "datamodel") ? ATTR(_scxml, "datamodel") : "null") << "\"," << std::endl; stream << " /* uuid */ \"" << _md5 << "\"," << std::endl; stream << " /* states */ " << "&" << _prefix << "_states[0], " << std::endl; - stream << " /* transitions */ " << "&" << _prefix << "_transitions[0], " << std::endl; + if (_transitions.size() > 0) { + stream << " /* transitions */ " << "&" << _prefix << "_transitions[0], " << std::endl; + } else { + stream << " /* transitions */ " << "NULL, " << std::endl; + } stream << " /* parent */ "; if (_parentMachine != NULL) { size_t parentIndex = 0; @@ -1769,7 +1774,7 @@ void ChartToC::writeMachineInfo(std::ostream& stream) { stream << " /* donedata */ " << "&" << _prefix << "_elem_donedatas[0], " << std::endl; stream << " /* script */ "; - if (filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml).size() > 0) { + if (DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml).size() > 0) { stream << _prefix << "_global_script" << std::endl; } else { stream << "NULL"; @@ -1810,7 +1815,7 @@ void ChartToC::writeMachineInfo(std::ostream& stream) { stream << " /* donedata */ " << "&" << m->_prefix << "_elem_donedatas[0], " << std::endl; stream << " /* script */ "; - if (filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml).size() > 0) { + if (DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml).size() > 0) { stream << m->_prefix << "_global_script" << std::endl; } else { stream << "NULL"; @@ -1852,17 +1857,17 @@ void ChartToC::writeStates(std::ostream& stream) { // onentry stream << " /* onentry */ "; - stream << (filterChildElements(_nsInfo.xmlNSPrefix + "onentry", state).size() > 0 ? _prefix + "_" + DOMUtils::idForNode(state) + "_on_entry" : "NULL"); + stream << (DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onentry", state).size() > 0 ? _prefix + "_" + DOMUtils::idForNode(state) + "_on_entry" : "NULL"); stream << "," << std::endl; // onexit stream << " /* onexit */ "; - stream << (filterChildElements(_nsInfo.xmlNSPrefix + "onexit", state).size() > 0 ? _prefix + "_" + DOMUtils::idForNode(state) + "_on_exit" : "NULL"); + stream << (DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onexit", state).size() > 0 ? _prefix + "_" + DOMUtils::idForNode(state) + "_on_exit" : "NULL"); stream << "," << std::endl; // invokers stream << " /* invoke */ "; - stream << (filterChildElements(_nsInfo.xmlNSPrefix + "invoke", state).size() > 0 ? _prefix + "_" + DOMUtils::idForNode(state) + "_invoke" : "NULL"); + stream << (DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", state).size() > 0 ? _prefix + "_" + DOMUtils::idForNode(state) + "_invoke" : "NULL"); stream << "," << std::endl; // children @@ -1932,95 +1937,97 @@ void ChartToC::writeTransitions(std::ostream& stream) { elements.insert(_nsInfo.xmlNSPrefix + "transition"); NodeSet transDocOrder = DOMUtils::inDocumentOrder(elements, _scxml); - stream << "static const uscxml_transition " << _prefix << "_transitions[" << toStr(_transitions.size()) << "] = {" << std::endl; - for (size_t i = 0; i < _transitions.size(); i++) { - Element transition(_transitions[i]); - - stream << " { /* transition number " << ATTR(transition, "documentOrder") << " with priority " << toStr(i) << std::endl; - stream << " target: " << ATTR(transition, "target") << std::endl; - stream << " */" << std::endl; + if (_transitions.size() > 0) { + stream << "static const uscxml_transition " << _prefix << "_transitions[" << toStr(_transitions.size()) << "] = {" << std::endl; + for (size_t i = 0; i < _transitions.size(); i++) { + Element transition(_transitions[i]); - // source - stream << " /* source */ "; - stream << ATTR_CAST(transition.getParentNode(), "documentOrder"); - stream << "," << std::endl; + stream << " { /* transition number " << ATTR(transition, "documentOrder") << " with priority " << toStr(i) << std::endl; + stream << " target: " << ATTR(transition, "target") << std::endl; + stream << " */" << std::endl; - // targets - stream << " /* target */ "; - if (HAS_ATTR(transition, "targetBools")) { - stream << "{ "; - writeCharArrayInitList(stream, ATTR(transition, "targetBools")); - stream << " /* " << ATTR(transition, "targetBools") << " */ }"; + // source + stream << " /* source */ "; + stream << ATTR_CAST(transition.getParentNode(), "documentOrder"); + stream << "," << std::endl; - } else { - stream << "{ NULL }"; - } - stream << "," << std::endl; + // targets + stream << " /* target */ "; + if (HAS_ATTR(transition, "targetBools")) { + stream << "{ "; + writeCharArrayInitList(stream, ATTR(transition, "targetBools")); + stream << " /* " << ATTR(transition, "targetBools") << " */ }"; - stream << " /* event */ "; - stream << (HAS_ATTR(transition, "event") ? "\"" + escape(ATTR(transition, "event")) + "\"" : "NULL"); - stream << "," << std::endl; + } else { + stream << "{ NULL }"; + } + stream << "," << std::endl; - stream << " /* condition */ "; - stream << (HAS_ATTR(transition, "cond") ? "\"" + escape(ATTR(transition, "cond")) + "\"" : "NULL"); - stream << "," << std::endl; + stream << " /* event */ "; + stream << (HAS_ATTR(transition, "event") ? "\"" + escape(ATTR(transition, "event")) + "\"" : "NULL"); + stream << "," << std::endl; - // on transition handlers - stream << " /* ontrans */ "; - if (filterChildType(Arabica::DOM::Node_base::ELEMENT_NODE, transition).size() > 0) { - stream << _prefix << "_" << DOMUtils::idForNode(transition) + "_on_trans"; - } else { - stream << "NULL"; - } - stream << "," << std::endl; + stream << " /* condition */ "; + stream << (HAS_ATTR(transition, "cond") ? "\"" + escape(ATTR(transition, "cond")) + "\"" : "NULL"); + stream << "," << std::endl; - // type - stream << " /* type */ "; - std::string seperator = ""; - if (!HAS_ATTR(transition, "target")) { - stream << seperator << "USCXML_TRANS_TARGETLESS"; - seperator = " | "; - } + // on transition handlers + stream << " /* ontrans */ "; + if (DOMUtils::filterChildType(Arabica::DOM::Node_base::ELEMENT_NODE, transition).size() > 0) { + stream << _prefix << "_" << DOMUtils::idForNode(transition) + "_on_trans"; + } else { + stream << "NULL"; + } + stream << "," << std::endl; + + // type + stream << " /* type */ "; + std::string seperator = ""; + if (!HAS_ATTR(transition, "target")) { + stream << seperator << "USCXML_TRANS_TARGETLESS"; + seperator = " | "; + } - if (HAS_ATTR(transition, "type") && iequals(ATTR(transition, "type"), "internal")) { - stream << seperator << "USCXML_TRANS_INTERNAL"; - seperator = " | "; - } + if (HAS_ATTR(transition, "type") && iequals(ATTR(transition, "type"), "internal")) { + stream << seperator << "USCXML_TRANS_INTERNAL"; + seperator = " | "; + } - if (!HAS_ATTR(transition, "event")) { - stream << seperator << "USCXML_TRANS_SPONTANEOUS"; - seperator = " | "; - } + if (!HAS_ATTR(transition, "event")) { + stream << seperator << "USCXML_TRANS_SPONTANEOUS"; + seperator = " | "; + } - if (iequals(TAGNAME_CAST(transition.getParentNode()), "history")) { - stream << seperator << "USCXML_TRANS_HISTORY"; - seperator = " | "; - } + if (iequals(TAGNAME_CAST(transition.getParentNode()), "history")) { + stream << seperator << "USCXML_TRANS_HISTORY"; + seperator = " | "; + } - if (iequals(TAGNAME_CAST(transition.getParentNode()), "initial")) { - stream << seperator << "USCXML_TRANS_INITIAL"; - seperator = " | "; - } + if (iequals(TAGNAME_CAST(transition.getParentNode()), "initial")) { + stream << seperator << "USCXML_TRANS_INITIAL"; + seperator = " | "; + } - if (seperator.size() == 0) { - stream << "0"; - } - stream << "," << std::endl; + if (seperator.size() == 0) { + stream << "0"; + } + stream << "," << std::endl; - // conflicts - stream << " /* conflicts */ { "; - writeCharArrayInitList(stream, ATTR(transition, "conflictBools")); - stream << " /* " << ATTR(transition, "conflictBools") << " */ }, " << std::endl; + // conflicts + stream << " /* conflicts */ { "; + writeCharArrayInitList(stream, ATTR(transition, "conflictBools")); + stream << " /* " << ATTR(transition, "conflictBools") << " */ }, " << std::endl; - // exit set - stream << " /* exit set */ { "; - writeCharArrayInitList(stream, ATTR(transition, "exitSetBools")); - stream << " /* " << ATTR(transition, "exitSetBools") << " */ }" << std::endl; + // exit set + stream << " /* exit set */ { "; + writeCharArrayInitList(stream, ATTR(transition, "exitSetBools")); + stream << " /* " << ATTR(transition, "exitSetBools") << " */ }" << std::endl; - stream << " }" << (i + 1 < _transitions.size() ? ",": "") << std::endl; + stream << " }" << (i + 1 < _transitions.size() ? ",": "") << std::endl; + } + stream << "};" << std::endl; + stream << std::endl; } - stream << "};" << std::endl; - stream << std::endl; stream << "#endif" << std::endl; stream << std::endl; diff --git a/src/uscxml/transform/ChartToC.h b/src/uscxml/transform/ChartToC.h index bb17102..0c9c2e5 100644 --- a/src/uscxml/transform/ChartToC.h +++ b/src/uscxml/transform/ChartToC.h @@ -21,7 +21,7 @@ #define FSMTOCPP_H_201672B0 #include "uscxml/interpreter/InterpreterRC.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/util/Trie.h" #include "Transformer.h" diff --git a/src/uscxml/transform/ChartToFSM.cpp b/src/uscxml/transform/ChartToFSM.cpp index b78a2dd..da53c1f 100644 --- a/src/uscxml/transform/ChartToFSM.cpp +++ b/src/uscxml/transform/ChartToFSM.cpp @@ -23,6 +23,7 @@ #include "uscxml/Factory.h" #include "uscxml/debug/Complexity.h" +#include #include #include @@ -146,7 +147,7 @@ ChartToFSM::~ChartToFSM() { } // tear down caches - Arabica::XPath::NodeSet allTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); + Arabica::XPath::NodeSet allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); for (int i = 0; i < allTransitions.size(); i++) { _transParents.erase(allTransitions[i]); } @@ -212,7 +213,7 @@ InterpreterState ChartToFSM::interpret() { // setup caches { - Arabica::XPath::NodeSet allTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); + Arabica::XPath::NodeSet allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); indexedTransitions.reserve(allTransitions.size()); for (int i = 0; i < allTransitions.size(); i++) { _transParents[allTransitions[i]] = InterpreterImpl::getParentState(allTransitions[i]); @@ -220,7 +221,7 @@ InterpreterState ChartToFSM::interpret() { } // identify all history elements - NodeSet histories = filterChildElements(_nsInfo.xmlNSPrefix + "history", _scxml, true); + NodeSet histories = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "history", _scxml, true); for (int i = 0; i < histories.size(); i++) { _historyTargets[ATTR_CAST(histories[i], "id")] = Element(histories[i]); } @@ -234,7 +235,7 @@ InterpreterState ChartToFSM::interpret() { } // set invokeid for all invokers to parent state if none given - NodeSet invokers = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); + NodeSet invokers = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); for (int i = 0; i < invokers.size(); i++) { Element invokerElem = Element(invokers[i]); invokerElem.setAttribute("parent", ATTR_CAST(invokerElem.getParentNode(), "id")); @@ -435,12 +436,12 @@ void ChartToFSM::internalDoneSend(const Arabica::DOM::Element& stat onentry.appendChild(raise); if (doneData) { - Arabica::XPath::NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", doneData); + Arabica::XPath::NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", doneData); if (contents.size() > 0) { Node imported = _flatDoc.importNode(contents[0], true); raise.appendChild(imported); } - Arabica::XPath::NodeSet params = filterChildElements(_nsInfo.xmlNSPrefix + "param", doneData); + Arabica::XPath::NodeSet params = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", doneData); if (params.size() > 0) { Node imported = _flatDoc.importNode(params[0], true); raise.appendChild(imported); @@ -532,7 +533,7 @@ static bool filterChildEnabled(const NodeSet& transitions) { if (p1 == p2) { std::string eventDesc1 = ATTR_CAST(t1, "event"); std::string eventDesc2 = ATTR_CAST(t2, "event"); - if (InterpreterImpl::nameMatch(eventDesc1, eventDesc2)) { + if (nameMatch(eventDesc1, eventDesc2)) { return false; } } @@ -562,14 +563,14 @@ bool ChartToFSM::hasForeachInBetween(const Arabica::DOM::Node& ance void ChartToFSM::annotateRaiseAndSend(const Arabica::DOM::Element& root) { NodeSet execContent; - execContent.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true)); - execContent.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "onentry", _scxml, true)); - execContent.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "onexit", _scxml, true)); + execContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true)); + execContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onentry", _scxml, true)); + execContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onexit", _scxml, true)); for (int i = 0; i < execContent.size(); i++) { Element execContentElem(execContent[i]); int nrRaise = 0; - NodeSet raise = filterChildElements(_nsInfo.xmlNSPrefix + "raise", execContent[i], true); + NodeSet raise = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "raise", execContent[i], true); for (int j = 0; j < raise.size(); j++) { if (hasForeachInBetween(execContent[i], raise[j])) { execContentElem.setAttribute("raise", "-1"); @@ -583,7 +584,7 @@ void ChartToFSM::annotateRaiseAndSend(const Arabica::DOM::Element& DONE_COUNT_RAISE: int nrSend = 0; - NodeSet sends = filterChildElements(_nsInfo.xmlNSPrefix + "send", execContent[i], true); + NodeSet sends = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "send", execContent[i], true); for (int j = 0; j < sends.size(); j++) { if (hasForeachInBetween(execContent[i], sends[j])) { execContentElem.setAttribute("send", "-1"); @@ -600,7 +601,7 @@ DONE_COUNT_SEND: } void ChartToFSM::annotateDomain() { - Arabica::XPath::NodeSet allTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); + Arabica::XPath::NodeSet allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); for (int i = 0; i < allTransitions.size(); i++) { Element transition(allTransitions[i]); Arabica::DOM::Node domain = getTransitionDomain(transition); @@ -613,7 +614,7 @@ void ChartToFSM::annotateDomain() { } void ChartToFSM::annotateExitSet() { - Arabica::XPath::NodeSet allTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); + Arabica::XPath::NodeSet allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); for (int i = 0; i < allTransitions.size(); i++) { Element transition(allTransitions[i]); Arabica::DOM::Node domain = getTransitionDomain(transition); @@ -633,7 +634,7 @@ void ChartToFSM::annotateExitSet() { } void ChartToFSM::annotateEntrySet() { - Arabica::XPath::NodeSet allTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); + Arabica::XPath::NodeSet allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); for (int i = 0; i < allTransitions.size(); i++) { Element transition(allTransitions[i]); @@ -664,7 +665,7 @@ void ChartToFSM::annotateEntrySet() { } void ChartToFSM::annotateConflicts() { - Arabica::XPath::NodeSet allTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); + Arabica::XPath::NodeSet allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true); Arabica::XPath::NodeSet allStates = getAllStates(); for (int i = 0; i < allTransitions.size(); i++) { @@ -744,7 +745,7 @@ void ChartToFSM::indexTransitions() { #if 0 void ChartToFSM::indexTransitions(const Arabica::DOM::Element& root) { // breadth first traversal of transitions - Arabica::XPath::NodeSet levelTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", root); + Arabica::XPath::NodeSet levelTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", root); for (int i = levelTransitions.size() - 1; i >= 0; i--) { // push into index starting with least prior indexedTransitions.push_back(Element(levelTransitions[i])); @@ -768,7 +769,7 @@ void ChartToFSM::indexTransitions(const Arabica::DOM::Element& root indexTransitions(childElem); } - Arabica::XPath::NodeSet levelTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", root); + Arabica::XPath::NodeSet levelTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", root); for (int i = 0; i < levelTransitions.size(); i++) { // push into index starting with least prior indexedTransitions.push_back(Element(levelTransitions[i])); @@ -1247,10 +1248,10 @@ TransitionTreeNode* ChartToFSM::buildTransTree(const Arabica::DOM::Element nested; - nested.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "transition", root)); - nested.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "state", root)); - nested.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "final", root)); - nested.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "parallel", root)); + nested.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", root)); + nested.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "state", root)); + nested.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "final", root)); + nested.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "parallel", root)); nested.to_document_order(); TransitionTreeNode* lastNode = NULL; @@ -1295,7 +1296,7 @@ TransitionTreeNode* ChartToFSM::buildTransTree(const Arabica::DOM::Element& conf, std::map& outMap) { // get all transition elements from states in the current configuration - NodeSet allTransitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", conf); + NodeSet allTransitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", conf); { std::string seperator = ""; @@ -1445,7 +1446,7 @@ void ChartToFSM::explode() { // add all invokers for initial transition for (unsigned int i = 0; i < _statesToInvoke.size(); i++) { - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); for (unsigned int j = 0; j < invokes.size(); j++) { invoke(Element(invokes[j])); } @@ -1592,7 +1593,7 @@ void ChartToFSM::explode() { // add all invokers for (unsigned int i = 0; i < _statesToInvoke.size(); i++) { - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _statesToInvoke[i]); for (unsigned int j = 0; j < invokes.size(); j++) { invoke(Element(invokes[j])); } @@ -1915,7 +1916,7 @@ GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet& t conditions.push_back(boost::trim_copy(ATTR(transElem, "cond"))); } - std::list targets = InterpreterImpl::tokenizeIdRefs(ATTR(transElem, "target")); + std::list targets = tokenize(ATTR(transElem, "target")); std::list::iterator targetIter = targets.begin(); while(targetIter != targets.end()) { // std::cout << "// " << *targetIter << std::endl; @@ -1983,7 +1984,7 @@ std::list GlobalTransition::getCommonEvents(const NodeSet eventNames = InterpreterImpl::tokenizeIdRefs(ATTR_CAST(transitions[i], "event")); + std::list eventNames = tokenize(ATTR_CAST(transitions[i], "event")); for (std::list::iterator eventNameIter = eventNames.begin(); eventNameIter != eventNames.end(); @@ -2002,7 +2003,7 @@ std::list GlobalTransition::getCommonEvents(const NodeSet GlobalTransition::getCommonEvents(const NodeSet::iterator innerEventNameIter = prefixes.begin(); innerEventNameIter != prefixes.end(); innerEventNameIter++) { - if (!iequals(*outerEventNameIter, *innerEventNameIter) && InterpreterImpl::nameMatch(*outerEventNameIter, *innerEventNameIter)) { + if (!iequals(*outerEventNameIter, *innerEventNameIter) && nameMatch(*outerEventNameIter, *innerEventNameIter)) { goto IS_PREFIX; } } diff --git a/src/uscxml/transform/ChartToFSM.h b/src/uscxml/transform/ChartToFSM.h index ab4aed4..fa76f3a 100644 --- a/src/uscxml/transform/ChartToFSM.h +++ b/src/uscxml/transform/ChartToFSM.h @@ -20,8 +20,8 @@ #ifndef CHARTTOFSM_H_IOKPYEBY #define CHARTTOFSM_H_IOKPYEBY -#include "uscxml/DOMUtils.h" #include "uscxml/interpreter/InterpreterRC.h" +#include "uscxml/dom/DOMUtils.h" #include #include #include diff --git a/src/uscxml/transform/ChartToFlatSCXML.cpp b/src/uscxml/transform/ChartToFlatSCXML.cpp index 2905444..984c287 100644 --- a/src/uscxml/transform/ChartToFlatSCXML.cpp +++ b/src/uscxml/transform/ChartToFlatSCXML.cpp @@ -63,7 +63,7 @@ void ChartToFlatSCXML::writeTo(std::ostream& stream) { } // remove all debug attributes - NodeSet elementNodes = filterChildType(Node_base::ELEMENT_NODE, _scxml, true); + NodeSet elementNodes = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); for (int i = 0; i < elementNodes.size(); i++) { Element element(elementNodes[i]); if (!envVarIsTrue("USCXML_ANNOTATE_GLOBAL_TRANS_SENDS") && HAS_ATTR(element, "send")) @@ -92,7 +92,7 @@ void ChartToFlatSCXML::createDocument() { return; { - NodeSet allElements = filterChildType(Node_base::ELEMENT_NODE, _scxml, true); + NodeSet allElements = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); size_t nrElements = 0; for (int i = 0; i < allElements.size(); i++) { if (!isInEmbeddedDocument(allElements[i])) @@ -133,7 +133,7 @@ void ChartToFlatSCXML::createDocument() { NodeSet datas; if (_binding == InterpreterImpl::LATE) { // with late binding, just copy direct datamodel childs - datas = filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", _origSCXML); + datas = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", _origSCXML); } else { // with early binding, copy all datamodel elements into scxml element datas = _xpath.evaluate("//" + _nsInfo.xpathPrefix + "datamodel", _origSCXML).asNodeSet(); @@ -146,13 +146,13 @@ void ChartToFlatSCXML::createDocument() { } - NodeSet scripts = filterChildElements(_nsInfo.xmlNSPrefix + "script", _origSCXML); + NodeSet scripts = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _origSCXML); for (int i = 0; i < scripts.size(); i++) { Node imported = _flatDoc.importNode(scripts[i], true); _scxml.appendChild(imported); } - NodeSet comments = filterChildType(Node_base::COMMENT_NODE, _origSCXML); + NodeSet comments = DOMUtils::filterChildType(Node_base::COMMENT_NODE, _origSCXML); for (int i = 0; i < comments.size(); i++) { Node imported = _flatDoc.importNode(comments[i], true); _scxml.appendChild(imported); @@ -177,13 +177,13 @@ void ChartToFlatSCXML::createDocument() { _document = _flatDoc; - NodeSet scxmls = filterChildElements(_nsInfo.xmlNSPrefix + "scxml", _document); + NodeSet scxmls = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "scxml", _document); if (scxmls.size() > 0) { _scxml = Element(scxmls[0]); } { - NodeSet allElements = filterChildType(Node_base::ELEMENT_NODE, _scxml, true); + NodeSet allElements = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); size_t nrElements = 0; for (int i = 0; i < allElements.size(); i++) { if (!isInEmbeddedDocument(allElements[i])) @@ -372,7 +372,7 @@ Node ChartToFlatSCXML::globalTransitionToNode(GlobalTransition* glo // we entered a new child - check if it has a datamodel and we entered for the first time if (_binding == InterpreterImpl::LATE) { - NodeSet datamodel = filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", actionIter->entered); + NodeSet datamodel = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", actionIter->entered); if (datamodel.size() > 0 && !isMember(actionIter->entered, _globalConf[globalTransition->source]->getAlreadyEnteredStates())) { childs.push_back(datamodel); } diff --git a/src/uscxml/transform/ChartToMinimalSCXML.cpp b/src/uscxml/transform/ChartToMinimalSCXML.cpp index 69ac9cb..f052b09 100644 --- a/src/uscxml/transform/ChartToMinimalSCXML.cpp +++ b/src/uscxml/transform/ChartToMinimalSCXML.cpp @@ -49,7 +49,7 @@ void ChartToMinimalSCXML::writeTo(std::ostream& stream) { addMonitor(this); { - NodeSet allElements = filterChildType(Node_base::ELEMENT_NODE, _scxml, true); + NodeSet allElements = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); size_t nrElements = 0; for (int i = 0; i < allElements.size(); i++) { if (!isInEmbeddedDocument(allElements[i])) @@ -61,11 +61,11 @@ void ChartToMinimalSCXML::writeTo(std::ostream& stream) { // test 278 - move embedded datas to topmost datamodel if (_binding == EARLY) { // move all data elements into topmost datamodel element - NodeSet datas = filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true); + NodeSet datas = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true); if (datas.size() > 0) { Node topMostDatamodel; - NodeSet datamodels = filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", _scxml, false); + NodeSet datamodels = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", _scxml, false); if (datamodels.size() > 0) { topMostDatamodel = datamodels[0]; } else { @@ -118,7 +118,7 @@ void ChartToMinimalSCXML::writeTo(std::ostream& stream) { removeUnvisited(_scxml); { - NodeSet allElements = filterChildType(Node_base::ELEMENT_NODE, _scxml, true); + NodeSet allElements = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, _scxml, true); size_t nrElements = 0; for (int i = 0; i < allElements.size(); i++) { if (!isInEmbeddedDocument(allElements[i])) @@ -150,7 +150,7 @@ void ChartToMinimalSCXML::removeUnvisited(Arabica::DOM::Node& node) // special handling for conditional blocks with if if (TAGNAME(elem) == _nsInfo.xmlNSPrefix + "if") { - NodeSet ifChilds = filterChildType(Node_base::ELEMENT_NODE, elem, false); + NodeSet ifChilds = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, elem, false); Element lastConditional = elem; bool hadVisitedChild = false; for (int j = 0; j < ifChilds.size(); j++) { diff --git a/src/uscxml/transform/ChartToMinimalSCXML.h b/src/uscxml/transform/ChartToMinimalSCXML.h index 0260ee1..4eb0b92 100644 --- a/src/uscxml/transform/ChartToMinimalSCXML.h +++ b/src/uscxml/transform/ChartToMinimalSCXML.h @@ -20,8 +20,8 @@ #ifndef CHARTTOMINIMALSCXML_H_7B97677A #define CHARTTOMINIMALSCXML_H_7B97677A -#include "uscxml/DOMUtils.h" #include "uscxml/interpreter/InterpreterRC.h" +#include "uscxml/dom/DOMUtils.h" #include #include #include diff --git a/src/uscxml/transform/ChartToPromela.cpp b/src/uscxml/transform/ChartToPromela.cpp index 4e3a990..747fb34 100644 --- a/src/uscxml/transform/ChartToPromela.cpp +++ b/src/uscxml/transform/ChartToPromela.cpp @@ -26,6 +26,7 @@ #include "uscxml/plugins/datamodel/promela/parser/promela.tab.hpp" #include +#include #include #include "uscxml/UUID.h" #include @@ -843,10 +844,10 @@ std::string ChartToPromela::conditionalizeForHist(const std::set transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", currState); +// content.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", currState)); +// content.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onentry", currState)); +// content.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "onexit", currState)); +// NodeSet transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", currState); // currState = _globalConf[ATTR_CAST(transitions[0], "target")]; // } // @@ -1511,7 +1512,7 @@ void ChartToPromela::writeExecutableContent(std::ostream& stream, const Arabica: child = child.getNextSibling(); } } else if(TAGNAME(nodeElem) == "script") { - NodeSet scriptText = filterChildType(Node_base::TEXT_NODE, node, true); + NodeSet scriptText = DOMUtils::filterChildType(Node_base::TEXT_NODE, node, true); for (int i = 0; i < scriptText.size(); i++) { stream << ADAPT_SRC(beautifyIndentation(scriptText[i].getNodeValue(), indent)) << std::endl; } @@ -1564,13 +1565,13 @@ void ChartToPromela::writeExecutableContent(std::ostream& stream, const Arabica: } else if(TAGNAME(nodeElem) == "if") { NodeSet condChain; condChain.push_back(node); - condChain.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "elseif", node)); - condChain.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "else", node)); + condChain.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "elseif", node)); + condChain.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "else", node)); writeIfBlock(stream, condChain, indent); } else if(TAGNAME(nodeElem) == "assign") { - NodeSet assignTexts = filterChildType(Node_base::TEXT_NODE, nodeElem, true); + NodeSet assignTexts = DOMUtils::filterChildType(Node_base::TEXT_NODE, nodeElem, true); assert(assignTexts.size() > 0); stream << beautifyIndentation(ADAPT_SRC(boost::trim_copy(assignTexts[0].getNodeValue())), indent) << std::endl; @@ -1652,8 +1653,8 @@ void ChartToPromela::writeExecutableContent(std::ostream& stream, const Arabica: typeAssignSS << padding << " tmpE.type = " << eventType << ";" << std::endl; } - NodeSet sendParams = filterChildElements(_nsInfo.xmlNSPrefix + "param", nodeElem); - NodeSet sendContents = filterChildElements(_nsInfo.xmlNSPrefix + "content", nodeElem); + NodeSet sendParams = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", nodeElem); + NodeSet sendContents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", nodeElem); std::string sendNameList = ATTR(nodeElem, "namelist"); if (sendParams.size() > 0) { for (int i = 0; i < sendParams.size(); i++) { @@ -1662,7 +1663,7 @@ void ChartToPromela::writeExecutableContent(std::ostream& stream, const Arabica: } } if (sendNameList.size() > 0) { - std::list nameListIds = tokenizeIdRefs(sendNameList); + std::list nameListIds = tokenize(sendNameList); std::list::iterator nameIter = nameListIds.begin(); while(nameIter != nameListIds.end()) { typeAssignSS << padding << " tmpE.data." << *nameIter << " = " << ADAPT_SRC(*nameIter) << ";" << std::endl; @@ -1844,7 +1845,7 @@ PromelaInlines::PromelaInlines(const Arabica::DOM::Node& node) { for (int i = 0; i < levelNodes.size(); i++) { // get all comments - NodeSet comments = InterpreterImpl::filterChildType(Node_base::COMMENT_NODE, levelNodes[i]); + NodeSet comments = DOMUtils::filterChildType(Node_base::COMMENT_NODE, levelNodes[i]); for (int j = 0; j < comments.size(); j++) { PromelaInline* tmp = new PromelaInline(comments[j]); if (tmp->type == PromelaInline::PROMELA_NIL) { @@ -1864,7 +1865,7 @@ PromelaInlines::PromelaInlines(const Arabica::DOM::Node& node) { } } - levelNodes = InterpreterImpl::filterChildType(Node_base::ELEMENT_NODE, levelNodes); + levelNodes = DOMUtils::filterChildType(Node_base::ELEMENT_NODE, levelNodes); level++; } } @@ -2191,7 +2192,7 @@ void ChartToPromela::writeStartInvoker(std::ostream& stream, const Arabica::DOM: } // set from params - NodeSet invokeParams = filterChildElements(_nsInfo.xmlNSPrefix + "param", node); + NodeSet invokeParams = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", node); for (int i = 0; i < invokeParams.size(); i++) { std::string identifier = ATTR_CAST(invokeParams[i], "name"); std::string expression = ATTR_CAST(invokeParams[i], "expr"); @@ -2218,10 +2219,10 @@ void ChartToPromela::writeFSM(std::ostream& stream) { stream << " " << _prefix << "procid = _pid;" << std::endl; stream << " }" << std::endl; // write initial transition -// transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", _startState); +// transitions = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _startState); // assert(transitions.size() == 1); - NodeSet scripts = filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml, false); + NodeSet scripts = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml, false); if (scripts.size() > 0) { stream << std::endl << "/* global scripts */" << std::endl; for (int i = 0; i < scripts.size(); i++) { @@ -2336,14 +2337,14 @@ void ChartToPromela::writeFSM(std::ostream& stream) { excludeEventDescs += " " + evIter->atom; } - NodeSet transitions = filterChildElements("transition", es.container, true); + NodeSet transitions = DOMUtils::filterChildElements("transition", es.container, true); std::set eventNames; for (int i = 0; i < transitions.size(); i++) { if (!HAS_ATTR_CAST(transitions[i], "event")) continue; if (HAS_ATTR_CAST(transitions[i], "cond") && ATTR_CAST(transitions[i], "cond").find("_event.") != std::string::npos) continue; - std::list events = InterpreterImpl::tokenizeIdRefs(ATTR_CAST(transitions[i], "event")); + std::list events = tokenize(ATTR_CAST(transitions[i], "event")); for (std::list::iterator evIter = events.begin(); evIter != events.end(); evIter++) { std::string eventName = *evIter; if (boost::ends_with(eventName, "*")) @@ -2352,7 +2353,7 @@ void ChartToPromela::writeFSM(std::ostream& stream) { eventName = eventName.substr(0, eventName.size() - 1); // is this event excluded? - if (!InterpreterImpl::nameMatch(excludeEventDescs, eventName)) { + if (!nameMatch(excludeEventDescs, eventName)) { eventNames.insert(eventName); } } @@ -2404,7 +2405,7 @@ void ChartToPromela::writeFSM(std::ostream& stream) { { bool finalizeFound = false; for (std::map, ChartToPromela*>::iterator invIter = _machines.begin(); invIter != _machines.end(); invIter++) { - NodeSet finalizes = filterChildElements(_nsInfo.xmlNSPrefix + "finalize", invIter->first, false); + NodeSet finalizes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "finalize", invIter->first, false); if (finalizes.size() > 0) { finalizeFound = true; break; @@ -2414,7 +2415,7 @@ void ChartToPromela::writeFSM(std::ostream& stream) { stream << "/* event */" << std::endl; stream << " if" << std::endl; for (std::map, ChartToPromela*>::iterator invIter = _machines.begin(); invIter != _machines.end(); invIter++) { - NodeSet finalizes = filterChildElements(_nsInfo.xmlNSPrefix + "finalize", invIter->first, false); + NodeSet finalizes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "finalize", invIter->first, false); if (finalizes.size() > 0) { stream << " :: " << _prefix << "_event.invokeid == " << _analyzer->macroForLiteral(invIter->second->_invokerid) << " -> {" << std::endl; writeExecutableContent(stream, finalizes[0], 3); @@ -2841,7 +2842,7 @@ void ChartToPromela::writeDispatchingBlock(std::ostream& stream, std::listeventDesc; - std::list eventNames = tokenizeIdRefs(eventDescs); + std::list eventNames = tokenize(eventDescs); std::set eventPrefixes; std::list::iterator eventNameIter = eventNames.begin(); while(eventNameIter != eventNames.end()) { @@ -2987,8 +2988,8 @@ void ChartToPromela::initNodes() { { // shorten UUID ids at invokers for readability - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); - invokes.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "uninvoke", _scxml, true)); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); + invokes.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "uninvoke", _scxml, true)); // make sure all invokers have an id! for (int i = 0; i < invokes.size(); i++) { @@ -3006,7 +3007,7 @@ void ChartToPromela::initNodes() { // are there nestes SCXML invokers? { - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); for (int i = 0; i < invokes.size(); i++) { if (!HAS_ATTR_CAST(invokes[i], "type") || ATTR_CAST(invokes[i], "type") == "scxml" || @@ -3023,9 +3024,9 @@ void ChartToPromela::initNodes() { nested = Interpreter::fromURL(absUrl); } else { - NodeSet nestedContent = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "content", invokes[i]); + NodeSet nestedContent = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", invokes[i]); assert(nestedContent.size() == 1); - NodeSet nestedRoot = InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "scxml", nestedContent[0]); + NodeSet nestedRoot = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "scxml", nestedContent[0]); assert(nestedRoot.size() == 1); DOMImplementation domFactory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); @@ -3070,9 +3071,9 @@ void ChartToPromela::initNodes() { while(histIter != _historyTargets.end()) { NodeSet histStatesMembers; bool isDeep = (HAS_ATTR_CAST(histIter->second, "type") && ATTR_CAST(histIter->second, "type") == "deep"); - histStatesMembers.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "state", histIter->second.getParentNode(), isDeep)); - histStatesMembers.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "parallel", histIter->second.getParentNode(), isDeep)); - histStatesMembers.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "final", histIter->second.getParentNode(), isDeep)); + histStatesMembers.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "state", histIter->second.getParentNode(), isDeep)); + histStatesMembers.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "parallel", histIter->second.getParentNode(), isDeep)); + histStatesMembers.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "final", histIter->second.getParentNode(), isDeep)); for (int i = 0; i < histStatesMembers.size(); i++) { _historyMembers[histIter->first].insert(std::make_pair(ATTR_CAST(histStatesMembers[i], "id"), i)); @@ -3089,7 +3090,7 @@ void ChartToPromela::initNodes() { for (int i = 0; i < internalEventNames.size(); i++) { if (HAS_ATTR_CAST(internalEventNames[i], "event")) { std::string eventNames = ATTR_CAST(internalEventNames[i], "event"); - std::list events = tokenizeIdRefs(eventNames); + std::list events = tokenize(eventNames); for (std::list::iterator eventIter = events.begin(); eventIter != events.end(); eventIter++) { std::string eventName = *eventIter; @@ -3109,8 +3110,8 @@ void ChartToPromela::initNodes() { // transform data / assign json into PROMELA statements { NodeSet asgn; - asgn.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true)); - asgn.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); + asgn.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true)); + asgn.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); for (int i = 0; i < asgn.size(); i++) { if (isInEmbeddedDocument(asgn[i])) @@ -3136,7 +3137,7 @@ void ChartToPromela::initNodes() { absUrl.toAbsolute(_baseURL[_scxml]); value = absUrl.getInContent(); } else { - NodeSet textChilds = filterChildType(Node_base::TEXT_NODE, asgnElem); + NodeSet textChilds = DOMUtils::filterChildType(Node_base::TEXT_NODE, asgnElem); if (textChilds.size() > 0) { for (int j = 0; j < textChilds.size(); j++) { value += textChilds[j].getNodeValue(); @@ -3171,9 +3172,9 @@ void ChartToPromela::initNodes() { // do we need sendid / invokeid? { - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); - NodeSet sends = filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true); - NodeSet cancels = filterChildElements(_nsInfo.xmlNSPrefix + "cancel", _scxml, true); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); + NodeSet sends = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true); + NodeSet cancels = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "cancel", _scxml, true); if (cancels.size() > 0) { _analyzer->addCode("_event.invokeid", this); @@ -3204,11 +3205,11 @@ void ChartToPromela::initNodes() { { // string literals for raise / send content NodeSet withContent; - withContent.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true)); - withContent.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "raise", _scxml, true)); + withContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true)); + withContent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "raise", _scxml, true)); for (int i = 0; i < withContent.size(); i++) { - NodeSet content = filterChildElements(_nsInfo.xmlNSPrefix + "content", withContent[i], true); + NodeSet content = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", withContent[i], true); for (int j = 0; j < content.size(); j++) { Element contentElem(content[j]); std::string content = spaceNormalize(contentElem.getFirstChild().getNodeValue()); @@ -3264,7 +3265,7 @@ void ChartToPromela::initNodes() { _analyzer->addLiteral(ATTR(_scxml, "name"), _analyzer->indexForLiteral(_prefix + "_sessionid")); } - NodeSet contents = filterChildElements(_nsInfo.xmlNSPrefix + "content", _scxml, true); + NodeSet contents = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", _scxml, true); for (int i = 0; i < contents.size(); i++) { Element contentElem = Element(contents[i]); if (contentElem.hasChildNodes() && contentElem.getFirstChild().getNodeType() == Node_base::TEXT_NODE && contentElem.getChildNodes().getLength() == 1) { @@ -3279,9 +3280,9 @@ void ChartToPromela::initNodes() { std::set allStrings; { NodeSet withCond; - withCond.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true)); - withCond.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "if", _scxml, true)); - withCond.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "elseif", _scxml, true)); + withCond.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true)); + withCond.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "if", _scxml, true)); + withCond.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "elseif", _scxml, true)); for (int i = 0; i < withCond.size(); i++) { Element elem = Element(withCond[i]); if (HAS_ATTR(elem, "cond")) { @@ -3294,11 +3295,11 @@ void ChartToPromela::initNodes() { } { NodeSet withExpr; - withExpr.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "log", _scxml, true)); - withExpr.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true)); - withExpr.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); - withExpr.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "content", _scxml, true)); - withExpr.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "param", _scxml, true)); + withExpr.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "log", _scxml, true)); + withExpr.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true)); + withExpr.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); + withExpr.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "content", _scxml, true)); + withExpr.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "param", _scxml, true)); for (int i = 0; i < withExpr.size(); i++) { Element elem = Element(withExpr[i]); if (HAS_ATTR(elem, "expr")) { @@ -3311,7 +3312,7 @@ void ChartToPromela::initNodes() { } { NodeSet withLocation; - withLocation.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); + withLocation.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "assign", _scxml, true)); for (int i = 0; i < withLocation.size(); i++) { Element elem = Element(withLocation[i]); if (HAS_ATTR(elem, "location")) { @@ -3324,10 +3325,10 @@ void ChartToPromela::initNodes() { } { NodeSet withText; - withText.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml, true)); -// withText.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true)); + withText.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "script", _scxml, true)); +// withText.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "data", _scxml, true)); for (int i = 0; i < withText.size(); i++) { - NodeSet texts = filterChildType(Node_base::TEXT_NODE, withText[i], true); + NodeSet texts = DOMUtils::filterChildType(Node_base::TEXT_NODE, withText[i], true); for (int j = 0; j < texts.size(); j++) { if (texts[j].getNodeValue().size() > 0) { Text elem = Text(texts[j]); @@ -3340,7 +3341,7 @@ void ChartToPromela::initNodes() { } } { - NodeSet foreachs = filterChildElements(_nsInfo.xmlNSPrefix + "foreach", _scxml, true); + NodeSet foreachs = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "foreach", _scxml, true); for (int i = 0; i < foreachs.size(); i++) { if (HAS_ATTR_CAST(foreachs[i], "index")) { allCode.insert(ATTR_CAST(foreachs[i], "index")); @@ -3359,12 +3360,12 @@ void ChartToPromela::initNodes() { // add all namelist entries to the _event structure { NodeSet withNamelist; - withNamelist.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true)); - withNamelist.push_back(filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true)); + withNamelist.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true)); + withNamelist.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true)); for (int i = 0; i < withNamelist.size(); i++) { if (HAS_ATTR_CAST(withNamelist[i], "namelist")) { std::string namelist = ATTR_CAST(withNamelist[i], "namelist"); - std::list names = tokenizeIdRefs(namelist); + std::list names = tokenize(namelist); for (std::list::iterator nameIter = names.begin(); nameIter != names.end(); nameIter++) { _analyzer->addCode("_event.data." + *nameIter + " = 0;", this); // introduce for _event_t typedef } @@ -3531,14 +3532,14 @@ void ChartToPromela::writeProgram(std::ostream& stream) { } { - NodeSet cancels = filterChildElements(_nsInfo.xmlNSPrefix + "cancel", _scxml, true); + NodeSet cancels = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "cancel", _scxml, true); if (cancels.size() > 0) { writeCancelEvents(stream); stream << std::endl; } } { - NodeSet invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); + NodeSet invokes = DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "invoke", _scxml, true); if (invokes.size() > 0 && _analyzer->usesEventField("delay")) { writeRemovePendingEventsFromInvoker(stream); stream << std::endl; diff --git a/src/uscxml/transform/ChartToPromela.h b/src/uscxml/transform/ChartToPromela.h index d289436..82c4e5d 100644 --- a/src/uscxml/transform/ChartToPromela.h +++ b/src/uscxml/transform/ChartToPromela.h @@ -23,7 +23,7 @@ #include "Transformer.h" #include "ChartToFSM.h" #include "uscxml/interpreter/InterpreterDraft6.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/util/Trie.h" #include diff --git a/src/uscxml/transform/ChartToTex.h b/src/uscxml/transform/ChartToTex.h index 037b55c..de3743e 100644 --- a/src/uscxml/transform/ChartToTex.h +++ b/src/uscxml/transform/ChartToTex.h @@ -24,7 +24,7 @@ #include "Transformer.h" #include "ChartToFSM.h" #include "uscxml/Interpreter.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/util/Trie.h" #include diff --git a/src/uscxml/transform/ChartToVHDL.cpp b/src/uscxml/transform/ChartToVHDL.cpp index f37ad7e..52f1a5c 100644 --- a/src/uscxml/transform/ChartToVHDL.cpp +++ b/src/uscxml/transform/ChartToVHDL.cpp @@ -22,7 +22,7 @@ #include #include #include "uscxml/UUID.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include #include #include @@ -103,9 +103,9 @@ void ChartToVHDL::checkDocument() { void ChartToVHDL::findEvents() { // elements with an event attribute NodeSet withEvent; - withEvent.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "raise", _scxml, true)); - withEvent.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true)); - withEvent.push_back(InterpreterImpl::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true)); + withEvent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "raise", _scxml, true)); + withEvent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "send", _scxml, true)); + withEvent.push_back(DOMUtils::filterChildElements(_nsInfo.xmlNSPrefix + "transition", _scxml, true)); for (size_t i = 0; i < withEvent.size(); i++) { if (HAS_ATTR_CAST(withEvent[i], "event")) { @@ -479,7 +479,7 @@ void ChartToVHDL::writeOptimalTransitionSetSelection(std::ostream & stream) { stream << " and ( '0' " << std::endl;; // find all matching event literals - std::list eventDescs = tokenizeIdRefs(ATTR(transition, "event")); + std::list eventDescs = tokenize(ATTR(transition, "event")); for (std::list::iterator descIter = eventDescs.begin(); descIter != eventDescs.end(); descIter++) { std::list eventNames = _eventTrie.getWordsWithPrefix((*descIter) == "*" ? "" : *descIter); for (std::list::iterator eventIter = eventNames.begin(); eventIter != eventNames.end(); eventIter++) { diff --git a/src/uscxml/transform/ChartToVHDL.h b/src/uscxml/transform/ChartToVHDL.h index abcb477..c2dec15 100644 --- a/src/uscxml/transform/ChartToVHDL.h +++ b/src/uscxml/transform/ChartToVHDL.h @@ -21,7 +21,7 @@ #define CHARTOVHDL_H #include "uscxml/interpreter/InterpreterDraft6.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/util/Trie.h" #include "Transformer.h" #include "ChartToC.h" diff --git a/src/uscxml/transform/FlatStateIdentifier.h b/src/uscxml/transform/FlatStateIdentifier.h index 4afd956..99ae084 100644 --- a/src/uscxml/transform/FlatStateIdentifier.h +++ b/src/uscxml/transform/FlatStateIdentifier.h @@ -22,7 +22,7 @@ #include "uscxml/Common.h" #include "uscxml/Convenience.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include diff --git a/src/uscxml/util/String.cpp b/src/uscxml/util/String.cpp new file mode 100644 index 0000000..dc5a765 --- /dev/null +++ b/src/uscxml/util/String.cpp @@ -0,0 +1,176 @@ +/** + * @file + * @author 2016 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#include "String.h" +#include +#include + +namespace uscxml { + +#define ISWHITESPACE(char) (isspace(char)) + +std::list tokenize(const std::string& line, const char sep, bool trimWhiteSpace) { + std::list tokens; + + // appr. 3x faster than stringstream + size_t start = 0; + for (int i = 0; i < line.size(); i++) { + if (line[i] == sep || (trimWhiteSpace && ISWHITESPACE(line[i]))) { + if (i > 0 && start < i) { + tokens.push_back(line.substr(start, i - start)); + } + while(line[i] == sep || (trimWhiteSpace && ISWHITESPACE(line[i]))) { + i++; // skip multiple occurences of seperator and whitespaces + } + start = i; + } else if (i + 1 == line.size()) { + tokens.push_back(line.substr(start, i + 1 - start)); + } + } + + return tokens; +} + +std::string spaceNormalize(const std::string& text) { + std::stringstream content; + +#if 1 + // 195ms with test-performance-events.scml + std::string seperator; + + size_t start = 0; + for (int i = 0; i < text.size(); i++) { + if (isspace(text[i])) { + if (i > 0 && start < i) { + content << seperator << text.substr(start, i - start); + seperator = " "; + } + while(isspace(text[++i])); // skip whitespaces + start = i; + } else if (i + 1 == text.size()) { + content << seperator << text.substr(start, i + 1 - start); + } + } +// std::cerr << ">>" << content.str() << "<<" << std::endl; + +#else + +// 291ms with test-performance-events.scml + std::istringstream iss(text); + std::string seperator; + do { + std::string token; + iss >> token; + if (token.length() > 0) { + content << seperator << token; + seperator = " "; + } + } while (iss); + +#endif + return content.str(); +} + +// see: http://www.w3.org/TR/scxml/#EventDescriptors +bool nameMatch(const std::string& eventDescs, const std::string& eventName) { +#if 1 + if(eventDescs.length() == 0 || eventName.length() == 0) + return false; + + // naive case of single descriptor and exact match + if (boost::iequals(eventDescs, eventName)) + return true; + + size_t start = 0; + std::string eventDesc; + for (int i = 0; i < eventDescs.size(); i++) { + if (isspace(eventDescs[i])) { + if (i > 0 && start < i - 1) { + eventDesc = eventDescs.substr(start, i - start); + } + while(isspace(eventDescs[++i])); // skip whitespaces + start = i; + } else if (i + 1 == eventDescs.size()) { + eventDesc = eventDescs.substr(start, i + 1 - start); + } + + if (eventDesc.size() > 0) { + // remove optional trailing .* for CCXML compatibility + if (eventDesc.find("*", eventDesc.size() - 1) != std::string::npos) + eventDesc = eventDesc.substr(0, eventDesc.size() - 1); + if (eventDesc.find(".", eventDesc.size() - 1) != std::string::npos) + eventDesc = eventDesc.substr(0, eventDesc.size() - 1); + + // was eventDesc the * wildcard + if (eventDesc.size() == 0) + return true; + + // eventDesc has to be a real prefix of event now and therefore shorter + if (eventDesc.size() > eventName.size()) + goto NEXT_DESC; + + // are they already equal? + if (boost::iequals(eventDesc, eventName)) + return true; + + if (eventName.find(eventDesc) == 0) { + if (eventName.find(".", eventDesc.size()) == eventDesc.size()) + return true; + } +NEXT_DESC: + eventDesc = ""; + } + } + return false; +#else + const char* dPtr = eventDescs.c_str(); + const char* ePtr = eventName.c_str(); + while(*dPtr != 0) { + + if (*dPtr == '*' && *ePtr != 0) // something following + return true; + + // descriptor differs from event name + if (*dPtr != *ePtr) { + // move to next descriptor + while(*dPtr != ' ' && *dPtr != 0) { + dPtr++; + } + if (*dPtr == 0) + return false; + dPtr++; + ePtr = eventName.c_str(); + } else { + // move both pointers one character + dPtr++; + ePtr++; + + } + + // descriptor is done, return match + if (((*dPtr == 0 || *dPtr == ' ') && (*ePtr == 0 || *ePtr == ' ')) || // exact match, end of string + (*dPtr == ' ' && *ePtr == '.') || (*dPtr == 0 && *ePtr == '.')) // prefix match + return true; + } + return false; +#endif +} + + +} \ No newline at end of file diff --git a/src/uscxml/util/String.h b/src/uscxml/util/String.h new file mode 100644 index 0000000..5344245 --- /dev/null +++ b/src/uscxml/util/String.h @@ -0,0 +1,34 @@ +/** + * @file + * @author 2016 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#ifndef STRING_H_FD462039 +#define STRING_H_FD462039 + +#include +#include + +namespace uscxml { + +std::list tokenize(const std::string& line, const char seperator = ' ', bool trimWhiteSpace = true); +std::string spaceNormalize(const std::string& text); +bool nameMatch(const std::string& eventDescs, const std::string& event); + +} + +#endif /* end of include guard: STRING_H_FD462039 */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1c1223e..b5b0906 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,10 @@ set(TEST_TIMEOUT 15) set(TEST_BENCHMARK_ITERATIONS 1000) +find_program(SPIN spin) +find_program(CC gcc) +find_program(CXX g++) + function(USCXML_TEST_COMPILE) set(options BUILD_ONLY) set(oneValueArgs LABEL NAME) @@ -82,6 +86,36 @@ add_test(test-execution ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/uscxml-browser ${CMAKE add_test(test-communication ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/uscxml-browser -t5493 ${CMAKE_SOURCE_DIR}/test/uscxml/test-communication.scxml) add_test(test-done-data ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/uscxml-browser ${CMAKE_SOURCE_DIR}/test/uscxml/test-donedata.scxml) +# make sure all headers are self-reliant +file(GLOB_RECURSE USCXML_HEADERS + ../src/*.h + ../src/*.hpp +) + +foreach(USCXML_HEADER ${USCXML_HEADERS} ) + STRING(REGEX REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/../src/" "" USCXML_REL_HEADER ${USCXML_HEADER}) + + set(HEADER_TEST) + set(HEADER_TEST "${HEADER_TEST}#include \"${USCXML_HEADER}\"\n") + set(HEADER_TEST "${HEADER_TEST}int main(int argc, char** argv) {}") + FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/headers/${USCXML_REL_HEADER}.cpp ${HEADER_TEST}) + + add_test(NAME "header/${USCXML_REL_HEADER}" + COMMAND ${CMAKE_COMMAND} + -DTESTFILE:FILEPATH=${CMAKE_CURRENT_BINARY_DIR}/headers/${USCXML_REL_HEADER}.cpp + -DCC_BIN:FILEPATH=${CC} + -DCXX_BIN:FILEPATH=${CXX} + -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} + -DUSCXML_PLATFORM_ID=${USCXML_PLATFORM_ID} + -DCMAKE_BINARY_DIR=${CMAKE_BINARY_DIR} + -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} + -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + -P ${CMAKE_CURRENT_SOURCE_DIR}/ctest/scripts/run_header_compiles.cmake) + set_property(TEST "header/${USCXML_REL_HEADER}" PROPERTY LABELS "header/${USCXML_REL_HEADER}") + +endforeach() + + # tests for inline SCXML with generated C add_executable(test-c-inline src/test-c-inline.c) @@ -107,10 +141,6 @@ set_property(TEST "gen/c/inline" PROPERTY LABELS "gen/c/inline") # declare W3C tests -find_program(SPIN spin) -find_program(CC gcc) -find_program(CXX g++) - if (NOT BUILD_MINIMAL) # compile and add all reported issues tests diff --git a/test/ctest/CTestCustom.ctest.in b/test/ctest/CTestCustom.ctest.in index a9a96ad..9dfd5b2 100644 --- a/test/ctest/CTestCustom.ctest.in +++ b/test/ctest/CTestCustom.ctest.in @@ -251,6 +251,15 @@ set(CTEST_CUSTOM_TESTS_IGNORE "perf/ecma/test553.scxml" "perf/ecma/test579.scxml" + ### Ignore some Header self-sufficient tests + "header/bindings/swig/msvc/inttypes.h" + "header/bindings/swig/wrapped/WrappedDataModel.h" + "header/bindings/swig/wrapped/WrappedExecutableContent.h" + "header/bindings/swig/wrapped/WrappedInterpreterMonitor.h" + "header/bindings/swig/wrapped/WrappedInvoker.h" + "header/bindings/swig/wrapped/WrappedIOProcessor.h" + + ) # unset(CTEST_CUSTOM_TESTS_IGNORE) diff --git a/test/src/test-arabica-namespaces.cpp b/test/src/test-arabica-namespaces.cpp index 3214d9f..ced9578 100644 --- a/test/src/test-arabica-namespaces.cpp +++ b/test/src/test-arabica-namespaces.cpp @@ -7,7 +7,8 @@ #include #include #include "uscxml/Interpreter.h" -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" +#include "uscxml/dom/NameSpacingParser.h" using namespace Arabica::DOM; using namespace Arabica::XPath; @@ -25,8 +26,8 @@ parsed = cloneDocument(parsed);\ insertBaz(parsed);\ std::cout << parsed.first << std::endl;\ validateRootFooBarBaz(parsed);\ -assert(InterpreterImpl::filterChildElements(origNS.xmlNSPrefix + "bar", origDoc.getDocumentElement()).size() == 3);\ -assert(InterpreterImpl::filterChildElements(origNS.xmlNSPrefix + "baz", origDoc.getDocumentElement()).size() == 0); +assert(DOMUtils::filterChildElements(origNS.xmlNSPrefix + "bar", origDoc.getDocumentElement()).size() == 3);\ +assert(DOMUtils::filterChildElements(origNS.xmlNSPrefix + "baz", origDoc.getDocumentElement()).size() == 0); /** @@ -96,7 +97,7 @@ static void validateRootFoo(std::pair, NameSpaceInfo>& par assert(TAGNAME_CAST(root) == nsInfo.xmlNSPrefix + "root"); assert(LOCALNAME_CAST(root) == "root"); - NodeSet foosFiltered = InterpreterImpl::filterChildElements(nsInfo.xmlNSPrefix + "foo", root); + NodeSet foosFiltered = DOMUtils::filterChildElements(nsInfo.xmlNSPrefix + "foo", root); assert(foosFiltered.size() == 3); NodeSet foosXPath = _xpath.evaluate("//" + nsInfo.xpathPrefix + "foo", root).asNodeSet(); assert(foosXPath.size() == 3); @@ -118,7 +119,7 @@ static void validateRootFooBar(std::pair, NameSpaceInfo>& Node root = document.getDocumentElement(); _xpath.setNamespaceContext(*nsInfo.getNSContext()); - NodeSet barsFiltered = InterpreterImpl::filterChildElements(nsInfo.xmlNSPrefix + "bar", root); + NodeSet barsFiltered = DOMUtils::filterChildElements(nsInfo.xmlNSPrefix + "bar", root); assert(barsFiltered.size() == 3); NodeSet barsXPath = _xpath.evaluate("//" + nsInfo.xpathPrefix + "bar", root).asNodeSet(); assert(barsXPath.size() == 3); @@ -143,7 +144,7 @@ static void validateRootFooBarBaz(std::pair, NameSpaceInfo assert(TAGNAME_CAST(root) == nsInfo.xmlNSPrefix + "root"); assert(LOCALNAME_CAST(root) == "root"); - NodeSet bazsFiltered = InterpreterImpl::filterChildElements(nsInfo.xmlNSPrefix + "baz", root); + NodeSet bazsFiltered = DOMUtils::filterChildElements(nsInfo.xmlNSPrefix + "baz", root); assert(bazsFiltered.size() == 3); NodeSet bazsXPath = _xpath.evaluate("//" + nsInfo.xpathPrefix + "baz", root).asNodeSet(); assert(bazsXPath.size() == 3); diff --git a/test/src/test-arabica-xpath.cpp b/test/src/test-arabica-xpath.cpp index 998f4aa..9e21624 100644 --- a/test/src/test-arabica-xpath.cpp +++ b/test/src/test-arabica-xpath.cpp @@ -5,7 +5,7 @@ #include #include #include -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #define string_type std::string #define string_adaptor Arabica::default_string_adaptor diff --git a/test/src/test-c-inline.c b/test/src/test-c-inline.c index c12ac73..a4b237c 100644 --- a/test/src/test-c-inline.c +++ b/test/src/test-c-inline.c @@ -28,10 +28,11 @@ void enteredFoo() { int main(int argc, char** argv) { uscxml_ctx ctx; + int err = USCXML_ERR_OK; + memset(&ctx, 0, sizeof(uscxml_ctx)); ctx.machine = &USCXML_MACHINE_TEST_INLINE; - int err = USCXML_ERR_OK; while(err != USCXML_ERR_DONE) { err = uscxml_step(&ctx); } diff --git a/test/src/test-c-inline.c.scxml.c b/test/src/test-c-inline.c.scxml.c index d586bb3..740d030 100644 --- a/test/src/test-c-inline.c.scxml.c +++ b/test/src/test-c-inline.c.scxml.c @@ -60,7 +60,7 @@ */ #ifndef USCXML_MAX_NR_TRANS_BYTES -# define USCXML_MAX_NR_TRANS_BYTES 0 +# define USCXML_MAX_NR_TRANS_BYTES 1 #endif /** @@ -165,12 +165,14 @@ typedef struct uscxml_elem_invoke uscxml_elem_invoke; typedef struct uscxml_elem_send uscxml_elem_send; typedef struct uscxml_elem_param uscxml_elem_param; typedef struct uscxml_elem_data uscxml_elem_data; +typedef struct uscxml_elem_assign uscxml_elem_assign; typedef struct uscxml_elem_donedata uscxml_elem_donedata; typedef struct uscxml_elem_foreach uscxml_elem_foreach; typedef void* (*dequeue_internal_t)(const uscxml_ctx* ctx); typedef void* (*dequeue_external_t)(const uscxml_ctx* ctx); -typedef int (*is_enabled_t)(const uscxml_ctx* ctx, const uscxml_transition* transition, const void* event); +typedef int (*is_enabled_t)(const uscxml_ctx* ctx, const uscxml_transition* transition); +typedef int (*is_matched_t)(const uscxml_ctx* ctx, const uscxml_transition* transition, const void* event); typedef int (*is_true_t)(const uscxml_ctx* ctx, const char* expr); typedef int (*exec_content_t)(const uscxml_ctx* ctx, const uscxml_state* state, const void* event); typedef int (*raise_done_event_t)(const uscxml_ctx* ctx, const uscxml_state* state, const uscxml_elem_donedata* donedata); @@ -182,7 +184,7 @@ typedef int (*exec_content_send_t)(const uscxml_ctx* ctx, const uscxml_elem_send typedef int (*exec_content_foreach_init_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); typedef int (*exec_content_foreach_next_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); typedef int (*exec_content_foreach_done_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); -typedef int (*exec_content_assign_t)(const uscxml_ctx* ctx, const char* location, const char* expr); +typedef int (*exec_content_assign_t)(const uscxml_ctx* ctx, const uscxml_elem_assign* assign); typedef int (*exec_content_init_t)(const uscxml_ctx* ctx, const uscxml_elem_data* data); typedef int (*exec_content_cancel_t)(const uscxml_ctx* ctx, const char* sendid, const char* sendidexpr); typedef int (*exec_content_finalize_t)(const uscxml_ctx* ctx, const uscxml_elem_invoke* invoker, const void* event); @@ -218,6 +220,15 @@ struct uscxml_elem_data { }; /** + * All information pertaining to an element. + */ +struct uscxml_elem_assign { + const char* location; + const char* expr; + const char* content; +}; + +/** * All information pertaining to any state element. */ struct uscxml_state { @@ -335,6 +346,7 @@ struct uscxml_ctx { dequeue_internal_t dequeue_internal; dequeue_external_t dequeue_external; is_enabled_t is_enabled; + is_matched_t is_matched; is_true_t is_true; raise_done_event_t raise_done_event; @@ -420,9 +432,6 @@ static const uscxml_state _uscxml_9FAC9BE9_states[2] = { #ifndef USCXML_NO_ELEM_INFO -static const uscxml_transition _uscxml_9FAC9BE9_transitions[0] = { -}; - #endif #ifndef USCXML_NO_ELEM_INFO @@ -441,7 +450,7 @@ const uscxml_machine _uscxml_9FAC9BE9_machine = { /* datamodel */ "native", /* uuid */ "9FAC9BE9A82F66AFD36A205557064B27", /* states */ &_uscxml_9FAC9BE9_states[0], - /* transitions */ &_uscxml_9FAC9BE9_transitions[0], + /* transitions */ NULL, /* parent */ NULL, /* donedata */ &_uscxml_9FAC9BE9_elem_donedatas[0], /* script */ NULL @@ -656,7 +665,8 @@ SELECT_TRANSITIONS: if ((USCXML_GET_TRANS(i).event == NULL && ctx->event == NULL) || (USCXML_GET_TRANS(i).event != NULL && ctx->event != NULL)) { /* is it enabled? */ - if (ctx->is_enabled(ctx, &USCXML_GET_TRANS(i), ctx->event) > 0) { + if ((ctx->event == NULL || ctx->is_matched(ctx, &USCXML_GET_TRANS(i), ctx->event) > 0) && + (USCXML_GET_TRANS(i).condition == NULL || ctx->is_enabled(ctx, &USCXML_GET_TRANS(i)) > 0)) { /* remember that we found a transition */ ctx->flags |= USCXML_CTX_TRANSITION_FOUND; diff --git a/test/src/test-c-machine.cpp b/test/src/test-c-machine.cpp index b4864e2..815993e 100644 --- a/test/src/test-c-machine.cpp +++ b/test/src/test-c-machine.cpp @@ -23,7 +23,7 @@ #include "uscxml/Convenience.h" #include "uscxml/URL.h" #include "uscxml/concurrency/Timer.h" -//#include "uscxml/DOMUtils.h" +//#include "uscxml/dom/DOMUtils.h" #include "uscxml/Factory.h" //#include "uscxml/Interpreter.h" #include "uscxml/UUID.h" diff --git a/test/src/test-predicates.cpp b/test/src/test-predicates.cpp index 7ba9225..0aff104 100644 --- a/test/src/test-predicates.cpp +++ b/test/src/test-predicates.cpp @@ -1,5 +1,6 @@ #define protected public #include "uscxml/Interpreter.h" +#include "uscxml/util/String.h" #undef protected #include @@ -54,35 +55,35 @@ int main(int argc, char** argv) { { std::string idrefs("id1"); - std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + std::list tokenizedIdrefs = tokenize(idrefs); assert(tokenizedIdrefs.size() == 1); assert(tokenizedIdrefs.front().compare("id1") == 0); } { std::string idrefs(" id1"); - std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + std::list tokenizedIdrefs = tokenize(idrefs); assert(tokenizedIdrefs.size() == 1); assert(tokenizedIdrefs.front().compare("id1") == 0); } { std::string idrefs(" id1 "); - std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + std::list tokenizedIdrefs = tokenize(idrefs); assert(tokenizedIdrefs.size() == 1); assert(tokenizedIdrefs.front().compare("id1") == 0); } { std::string idrefs(" \tid1\n "); - std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + std::list tokenizedIdrefs = tokenize(idrefs); assert(tokenizedIdrefs.size() == 1); assert(tokenizedIdrefs.front().compare("id1") == 0); } { std::string idrefs("id1 id2 id3"); - std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + std::list tokenizedIdrefs = tokenize(idrefs); assert(tokenizedIdrefs.size() == 3); assert(tokenizedIdrefs.front().compare("id1") == 0); tokenizedIdrefs.pop_front(); @@ -93,7 +94,7 @@ int main(int argc, char** argv) { { std::string idrefs("\t id1 \nid2\n\n id3\t"); - std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + std::list tokenizedIdrefs = tokenize(idrefs); assert(tokenizedIdrefs.size() == 3); assert(tokenizedIdrefs.front().compare("id1") == 0); tokenizedIdrefs.pop_front(); @@ -104,7 +105,7 @@ int main(int argc, char** argv) { { std::string idrefs("id1 \nid2 \tid3"); - std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + std::list tokenizedIdrefs = tokenize(idrefs); assert(tokenizedIdrefs.size() == 3); assert(tokenizedIdrefs.front().compare("id1") == 0); tokenizedIdrefs.pop_front(); @@ -115,20 +116,20 @@ int main(int argc, char** argv) { std::string transEvents; transEvents = "error"; - assert(InterpreterImpl::nameMatch(transEvents, "error")); - assert(!InterpreterImpl::nameMatch(transEvents, "foo")); + assert(nameMatch(transEvents, "error")); + assert(!nameMatch(transEvents, "foo")); transEvents = " error foo"; - assert(InterpreterImpl::nameMatch(transEvents, "error")); - assert(InterpreterImpl::nameMatch(transEvents, "error.send")); - assert(InterpreterImpl::nameMatch(transEvents, "error.send.failed")); - assert(InterpreterImpl::nameMatch(transEvents, "foo")); - assert(InterpreterImpl::nameMatch(transEvents, "foo.bar")); - assert(!InterpreterImpl::nameMatch(transEvents, "errors.my.custom")); - assert(!InterpreterImpl::nameMatch(transEvents, "errorhandler.mistake")); + assert(nameMatch(transEvents, "error")); + assert(nameMatch(transEvents, "error.send")); + assert(nameMatch(transEvents, "error.send.failed")); + assert(nameMatch(transEvents, "foo")); + assert(nameMatch(transEvents, "foo.bar")); + assert(!nameMatch(transEvents, "errors.my.custom")); + assert(!nameMatch(transEvents, "errorhandler.mistake")); // is the event name case sensitive? - // assert(!InterpreterImpl::nameMatch(transEvents, "errOr.send")); - assert(!InterpreterImpl::nameMatch(transEvents, "foobar")); + // assert(!nameMatch(transEvents, "errOr.send")); + assert(!nameMatch(transEvents, "foobar")); } catch(std::exception e) { std::cout << e.what(); return false; diff --git a/test/src/test-promela-parser.cpp b/test/src/test-promela-parser.cpp index cab19ab..f3ac4cc 100644 --- a/test/src/test-promela-parser.cpp +++ b/test/src/test-promela-parser.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include using namespace uscxml; diff --git a/test/src/test-w3c.cpp b/test/src/test-w3c.cpp index 0ac33a7..669db30 100644 --- a/test/src/test-w3c.cpp +++ b/test/src/test-w3c.cpp @@ -21,7 +21,7 @@ # endif -#include "uscxml/DOMUtils.h" +#include "uscxml/dom/DOMUtils.h" #include "uscxml/concurrency/Timer.h" #include "uscxml/Factory.h" @@ -178,7 +178,7 @@ int main(int argc, char** argv) { if (delayFactor != 1) { Arabica::DOM::Document document = interpreter.getDocument(); Arabica::DOM::Element root = document.getDocumentElement(); - Arabica::XPath::NodeSet sends = InterpreterImpl::filterChildElements(interpreter.getNameSpaceInfo().xmlNSPrefix + "send", root, true); + Arabica::XPath::NodeSet sends = DOMUtils::filterChildElements(interpreter.getNameSpaceInfo().xmlNSPrefix + "send", root, true); for (int i = 0; i < sends.size(); i++) { Arabica::DOM::Element send = Arabica::DOM::Element(sends[i]); -- cgit v0.12