summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/uscxml/DOMUtils.cpp49
-rw-r--r--src/uscxml/DOMUtils.h15
-rw-r--r--src/uscxml/Interpreter.cpp7
-rw-r--r--src/uscxml/Interpreter.h1
-rw-r--r--src/uscxml/interpreter/InterpreterFast.cpp42
-rw-r--r--src/uscxml/interpreter/InterpreterFast.h47
-rw-r--r--src/uscxml/transform/ChartToC.cpp83
-rw-r--r--src/uscxml/transform/ChartToC.h18
-rw-r--r--src/uscxml/transform/ChartToVHDL.cpp6
-rw-r--r--src/uscxml/transform/Transformer.h16
10 files changed, 208 insertions, 76 deletions
diff --git a/src/uscxml/DOMUtils.cpp b/src/uscxml/DOMUtils.cpp
index 9703432..97b84c8 100644
--- a/src/uscxml/DOMUtils.cpp
+++ b/src/uscxml/DOMUtils.cpp
@@ -26,6 +26,9 @@
namespace uscxml {
+using namespace Arabica::XPath;
+using namespace Arabica::DOM;
+
bool DOMUtils::attributeIsTrue(const::std::string& value) {
return stringIsTrue(value.c_str());
}
@@ -126,6 +129,52 @@ std::string DOMUtils::xPathForNode(const Arabica::DOM::Node<std::string>& node,
return xPath;
}
+NodeSet<std::string> DOMUtils::inPostFixOrder(const std::set<std::string>& elements, const Element<std::string>& root) {
+ NodeSet<std::string> nodes;
+ inPostFixOrder(elements, root, nodes);
+ return nodes;
+}
+
+void DOMUtils::inPostFixOrder(const std::set<std::string>& elements, const Element<std::string>& root, NodeSet<std::string>& nodes) {
+ NodeList<std::string> 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<std::string> childElem(children.item(i));
+ inPostFixOrder(elements, childElem, nodes);
+
+ }
+ for (size_t i = 0; i < children.getLength(); i++) {
+ if (children.item(i).getNodeType() != Node_base::ELEMENT_NODE)
+ continue;
+ Arabica::DOM::Element<std::string> childElem(children.item(i));
+
+ if (elements.find(TAGNAME(childElem)) != elements.end()) {
+ nodes.push_back(childElem);
+ }
+ }
+}
+
+NodeSet<std::string> DOMUtils::inDocumentOrder(const std::set<std::string>& elements, const Element<std::string>& root) {
+ NodeSet<std::string> nodes;
+ inDocumentOrder(elements, root, nodes);
+ return nodes;
+}
+
+void DOMUtils::inDocumentOrder(const std::set<std::string>& elements, const Element<std::string>& root, NodeSet<std::string>& nodes) {
+ if (elements.find(TAGNAME(root)) != elements.end()) {
+ nodes.push_back(root);
+ }
+
+ NodeList<std::string> 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<std::string> childElem(children.item(i));
+ inDocumentOrder(elements, childElem, nodes);
+ }
+}
+
std::list<Arabica::DOM::Node<std::string> > DOMUtils::getElementsByType(const Arabica::DOM::Node<std::string>& root, Arabica::DOM::Node_base::Type type) {
std::list<Arabica::DOM::Node<std::string> > result;
std::list<Arabica::DOM::Node<std::string> > stack;
diff --git a/src/uscxml/DOMUtils.h b/src/uscxml/DOMUtils.h
index 426d797..a94bd90 100644
--- a/src/uscxml/DOMUtils.h
+++ b/src/uscxml/DOMUtils.h
@@ -25,6 +25,7 @@
#include <SAX/helpers/DefaultHandler.hpp>
#include <SAX/helpers/CatchErrorHandler.hpp>
#include <DOM/io/Stream.hpp> // operator<< for nodes
+#include <XPath/XPath.hpp>
#define TAGNAME_CAST(elem) ((Arabica::DOM::Element<std::string>)elem).getTagName()
#define LOCALNAME_CAST(elem) ((Arabica::DOM::Element<std::string>)elem).getLocalName()
@@ -47,6 +48,20 @@ public:
static std::string idForNode(const Arabica::DOM::Node<std::string>& node);
// deprecated, use stringIsTrue from Convenience.h instead
DEPRECATED static bool attributeIsTrue(const::std::string& value);
+
+ static Arabica::XPath::NodeSet<std::string> inPostFixOrder(const std::set<std::string>& elements,
+ const Arabica::DOM::Element<std::string>& root);
+ static Arabica::XPath::NodeSet<std::string> inDocumentOrder(const std::set<std::string>& elements,
+ const Arabica::DOM::Element<std::string>& root);
+protected:
+ static void inPostFixOrder(const std::set<std::string>& elements,
+ const Arabica::DOM::Element<std::string>& root,
+ Arabica::XPath::NodeSet<std::string>& nodes);
+
+ static void inDocumentOrder(const std::set<std::string>& elements,
+ const Arabica::DOM::Element<std::string>& root,
+ Arabica::XPath::NodeSet<std::string>& nodes);
+
};
class ScriptEntityResolver : public Arabica::SAX::EntityResolver<std::string> {
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp
index f1490d4..a05fe39 100644
--- a/src/uscxml/Interpreter.cpp
+++ b/src/uscxml/Interpreter.cpp
@@ -52,9 +52,12 @@
#if 0
# define INTERPRETER_IMPL InterpreterDraft6
# include "uscxml/interpreter/InterpreterDraft6.h"
-#else
+#elif 1
# define INTERPRETER_IMPL InterpreterRC
# include "uscxml/interpreter/InterpreterRC.h"
+#else
+# define INTERPRETER_IMPL InterpreterFast
+# include "uscxml/interpreter/InterpreterFast.h"
#endif
#define VERBOSE 0
@@ -776,7 +779,7 @@ NodeSet<std::string> InterpreterImpl::getDocumentInitialTransitions() {
}
return initialTransitions;
}
-
+
InterpreterState InterpreterImpl::step(int waitForMS) {
try {
tthread::lock_guard<tthread::recursive_mutex> lock(_mutex);
diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h
index c996c78..ce9354a 100644
--- a/src/uscxml/Interpreter.h
+++ b/src/uscxml/Interpreter.h
@@ -417,7 +417,6 @@ public:
virtual void handleDOMEvent(Arabica::DOM::Events::Event<std::string>& event);
protected:
-
static void run(void*); // static method for thread to run
class DOMEventListener : public Arabica::DOM::Events::EventListener<std::string> {
diff --git a/src/uscxml/interpreter/InterpreterFast.cpp b/src/uscxml/interpreter/InterpreterFast.cpp
new file mode 100644
index 0000000..0958c61
--- /dev/null
+++ b/src/uscxml/interpreter/InterpreterFast.cpp
@@ -0,0 +1,42 @@
+/**
+ * @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 <http://www.opensource.org/licenses/bsd-license>.
+ * @endcond
+ */
+
+#include "InterpreterFast.h"
+
+#include "uscxml/Factory.h"
+#include "uscxml/concurrency/DelayedEventQueue.h"
+
+#include <glog/logging.h>
+#include "uscxml/UUID.h"
+#include "uscxml/DOMUtils.h"
+
+namespace uscxml {
+
+using namespace Arabica::XPath;
+using namespace Arabica::DOM;
+
+
+void InterpreterFast::handleDOMEvent(Arabica::DOM::Events::Event<std::string>& event) {
+ InterpreterImpl::handleDOMEvent(event);
+
+ if (event.getType().compare("DOMAttrModified") == 0) // we do not care about attributes
+ return;
+
+}
+} \ No newline at end of file
diff --git a/src/uscxml/interpreter/InterpreterFast.h b/src/uscxml/interpreter/InterpreterFast.h
new file mode 100644
index 0000000..589e899
--- /dev/null
+++ b/src/uscxml/interpreter/InterpreterFast.h
@@ -0,0 +1,47 @@
+/**
+ * @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 <http://www.opensource.org/licenses/bsd-license>.
+ * @endcond
+ */
+
+#ifndef INTERPRETERFAST_H_224A5F07
+#define INTERPRETERFAST_H_224A5F07
+
+#include "uscxml/Interpreter.h"
+
+namespace uscxml {
+
+class InterpreterFast : public InterpreterImpl {
+protected:
+ virtual void setupSets();
+ virtual void handleDOMEvent(Arabica::DOM::Events::Event<std::string>& event);
+
+private:
+
+ /* TODO: use post-order and document-order per STL comparator (sorted std::set?) */
+
+ std::vector<Arabica::XPath::NodeSet<std::string> > _states;
+ std::vector<Arabica::XPath::NodeSet<std::string> > _transitions;
+
+ std::vector<std::vector<bool> > _conflictingTransitions;
+ std::vector<std::vector<bool> > _exitSets;
+ std::vector<std::vector<bool> > _targetSets;
+
+};
+
+}
+
+#endif /* end of include guard: INTERPRETERFAST_H_224A5F07 */
diff --git a/src/uscxml/transform/ChartToC.cpp b/src/uscxml/transform/ChartToC.cpp
index a105f93..710a2de 100644
--- a/src/uscxml/transform/ChartToC.cpp
+++ b/src/uscxml/transform/ChartToC.cpp
@@ -51,7 +51,7 @@ ChartToC::ChartToC(const Interpreter& other) : TransformerImpl() {
void ChartToC::setHistoryCompletion() {
std::set<std::string> elements;
elements.insert(_nsInfo.xmlNSPrefix + "history");
- Arabica::XPath::NodeSet<std::string> histories = inPostFixOrder(elements, _scxml);
+ Arabica::XPath::NodeSet<std::string> histories = DOMUtils::inPostFixOrder(elements, _scxml);
NodeSet<std::string> covered;
NodeSet<std::string> perParentcovered;
@@ -235,7 +235,7 @@ void ChartToC::prepare() {
elements.insert(_nsInfo.xmlNSPrefix + "history");
elements.insert(_nsInfo.xmlNSPrefix + "initial");
elements.insert(_nsInfo.xmlNSPrefix + "parallel");
- _states = inDocumentOrder(elements, _scxml);
+ _states = DOMUtils::inDocumentOrder(elements, _scxml);
// set states' document order and parent attribute
for (size_t i = 0; i < _states.size(); i++) {
@@ -280,7 +280,7 @@ void ChartToC::prepare() {
// set transitions' document order and source attribute
elements.clear();
elements.insert(_nsInfo.xmlNSPrefix + "transition");
- _transitions = inDocumentOrder(elements, _scxml);
+ _transitions = DOMUtils::inDocumentOrder(elements, _scxml);
for (size_t i = 0; i < _transitions.size(); i++) {
Element<std::string> transition(_transitions[i]);
transition.setAttribute("documentOrder", toStr(i));
@@ -291,7 +291,7 @@ void ChartToC::prepare() {
}
// set transitions' postfix order attribute
- _transitions = inPostFixOrder(elements, _scxml);
+ _transitions = DOMUtils::inPostFixOrder(elements, _scxml);
for (size_t i = 0; i < _transitions.size(); i++) {
Element<std::string> transition(_transitions[i]);
transition.setAttribute("postFixOrder", toStr(i));
@@ -482,11 +482,11 @@ void ChartToC::writeMacros(std::ostream& stream) {
void ChartToC::writeTypes(std::ostream& stream) {
stream << std::endl;
- stream << "typedef struct scxml_transition scxml_transition;" << std::endl;
+ stream << "typedef struct scxml_machine scxml_machine;" << std::endl;
+ stream << "typedef struct scxml_transition scxml_transition;" << std::endl;
stream << "typedef struct scxml_state scxml_state;" << std::endl;
stream << "typedef struct scxml_ctx scxml_ctx;" << std::endl;
stream << "typedef struct scxml_invoke scxml_invoke;" << std::endl;
-
stream << std::endl;
stream << "typedef struct scxml_elem_send scxml_elem_send;" << std::endl;
@@ -518,6 +518,26 @@ void ChartToC::writeTypes(std::ostream& stream) {
stream << "typedef int (*exec_content_script_t)(const scxml_ctx* ctx, const char* src, const char* content);" << std::endl;
stream << std::endl;
+#if 0
+ stream << "struct scxml_machine {" << std::endl;
+ stream << " uint8_t flags;" << std::endl;
+ stream << " uint32_t nr_states;" << std::endl;
+ stream << " uint32_t nr_transitions;" << std::endl;
+ stream << " const char* name;" << std::endl;
+ stream << " const char* datamodel;" << std::endl;
+ stream << " const char* uuid;" << std::endl;
+ stream << " const scxml_elem_data* datas;" << std::endl;
+ stream << " const scxml_state* states;" << std::endl;
+ stream << " const scxml_transition* transitions;" << std::endl;
+ stream << " const scxml_foreach* foreachs;" << std::endl;
+ stream << " const scxml_elem_param* params;" << std::endl;
+ stream << " const scxml_elem_donedata* donedatas;" << std::endl;
+ stream << " const scxml_elem_invoke* invokes;" << std::endl;
+ stream << " const scxml_elem_send* sends;" << std::endl;
+ stream << "};" << std::endl;
+ stream << std::endl;
+#endif
+
stream << "struct scxml_elem_data {" << std::endl;
stream << " const char* id;" << std::endl;
stream << " const char* src;" << std::endl;
@@ -575,7 +595,8 @@ void ChartToC::writeTypes(std::ostream& stream) {
stream << std::endl;
stream << "struct scxml_elem_invoke {" << std::endl;
- stream << " const char* type;" << std::endl;
+ stream << " const char* uuid;" << std::endl;
+ stream << " const char* type;" << std::endl;
stream << " const char* typeexpr;" << std::endl;
stream << " const char* src;" << std::endl;
stream << " const char* srcexpr;" << std::endl;
@@ -1305,7 +1326,7 @@ void ChartToC::writeTransitions(std::ostream& stream) {
// cross reference transition by document order - is this really needed?!
std::set<std::string> elements;
elements.insert(_nsInfo.xmlNSPrefix + "transition");
- NodeSet<std::string> transDocOrder = inDocumentOrder(elements, _scxml);
+ NodeSet<std::string> transDocOrder = DOMUtils::inDocumentOrder(elements, _scxml);
stream << "static const scxml_transition scxml_transitions[" << toStr(_transitions.size()) << "] = {" << std::endl;
for (size_t i = 0; i < _transitions.size(); i++) {
@@ -1839,52 +1860,6 @@ void ChartToC::writeFSM(std::ostream& stream) {
stream << std::endl;
}
-NodeSet<std::string> ChartToC::inPostFixOrder(const std::set<std::string>& elements, const Element<std::string>& root) {
- NodeSet<std::string> nodes;
- inPostFixOrder(elements, root, nodes);
- return nodes;
-}
-
-void ChartToC::inPostFixOrder(const std::set<std::string>& elements, const Element<std::string>& root, NodeSet<std::string>& nodes) {
- NodeList<std::string> 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<std::string> childElem(children.item(i));
- inPostFixOrder(elements, childElem, nodes);
-
- }
- for (size_t i = 0; i < children.getLength(); i++) {
- if (children.item(i).getNodeType() != Node_base::ELEMENT_NODE)
- continue;
- Arabica::DOM::Element<std::string> childElem(children.item(i));
-
- if (elements.find(TAGNAME(childElem)) != elements.end()) {
- nodes.push_back(childElem);
- }
- }
-}
-
-NodeSet<std::string> ChartToC::inDocumentOrder(const std::set<std::string>& elements, const Element<std::string>& root) {
- NodeSet<std::string> nodes;
- inDocumentOrder(elements, root, nodes);
- return nodes;
-}
-
-void ChartToC::inDocumentOrder(const std::set<std::string>& elements, const Element<std::string>& root, NodeSet<std::string>& nodes) {
- if (elements.find(TAGNAME(root)) != elements.end()) {
- nodes.push_back(root);
- }
-
- NodeList<std::string> 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<std::string> childElem(children.item(i));
- inDocumentOrder(elements, childElem, nodes);
- }
-}
-
ChartToC::~ChartToC() {
}
diff --git a/src/uscxml/transform/ChartToC.h b/src/uscxml/transform/ChartToC.h
index 039e8a4..1ac59f3 100644
--- a/src/uscxml/transform/ChartToC.h
+++ b/src/uscxml/transform/ChartToC.h
@@ -20,7 +20,7 @@
#ifndef FSMTOCPP_H_201672B0
#define FSMTOCPP_H_201672B0
-#include "uscxml/interpreter/InterpreterDraft6.h"
+#include "uscxml/interpreter/InterpreterRC.h"
#include "uscxml/DOMUtils.h"
#include "uscxml/util/Trie.h"
#include "Transformer.h"
@@ -40,20 +40,8 @@ public:
void writeTo(std::ostream& stream);
- static Arabica::XPath::NodeSet<std::string> inPostFixOrder(const std::set<std::string>& elements,
- const Arabica::DOM::Element<std::string>& root);
- static Arabica::XPath::NodeSet<std::string> inDocumentOrder(const std::set<std::string>& elements,
- const Arabica::DOM::Element<std::string>& root);
protected:
ChartToC(const Interpreter& other);
-
- static void inPostFixOrder(const std::set<std::string>& elements,
- const Arabica::DOM::Element<std::string>& root,
- Arabica::XPath::NodeSet<std::string>& nodes);
-
- static void inDocumentOrder(const std::set<std::string>& elements,
- const Arabica::DOM::Element<std::string>& root,
- Arabica::XPath::NodeSet<std::string>& nodes);
void writeIncludes(std::ostream& stream);
void writeMacros(std::ostream& stream);
@@ -81,8 +69,8 @@ protected:
Arabica::XPath::NodeSet<std::string> _states;
Arabica::XPath::NodeSet<std::string> _transitions;
- bool _hasGlobalScripts;
-
+// std::string md5sum;
+
size_t _transCharArraySize;
std::string _transCharArrayInit;
std::string _transDataType;
diff --git a/src/uscxml/transform/ChartToVHDL.cpp b/src/uscxml/transform/ChartToVHDL.cpp
index d5bbac3..7631619 100644
--- a/src/uscxml/transform/ChartToVHDL.cpp
+++ b/src/uscxml/transform/ChartToVHDL.cpp
@@ -74,7 +74,7 @@ void ChartToVHDL::checkDocument() {
elements.insert(_nsInfo.xmlNSPrefix + "cancel");
elements.insert(_nsInfo.xmlNSPrefix + "invoke");
elements.insert(_nsInfo.xmlNSPrefix + "finalize");
- unsupported = ChartToC::inDocumentOrder(elements, _scxml);
+ unsupported = DOMUtils::inDocumentOrder(elements, _scxml);
std::stringstream ss;
if (unsupported.size() > 0) {
@@ -86,7 +86,7 @@ void ChartToVHDL::checkDocument() {
elements.clear();
elements.insert(_nsInfo.xmlNSPrefix + "transition");
- unsupported = inDocumentOrder(elements, _scxml);
+ unsupported = DOMUtils::inDocumentOrder(elements, _scxml);
for (int i = 0; i < unsupported.size(); i++) {
Element<std::string> transition(unsupported[i]);
@@ -116,7 +116,7 @@ void ChartToVHDL::findEvents() {
void ChartToVHDL::writeTo(std::ostream& stream) {
// same preparations as the C transformation
- prepare();
+ prepare();
// checkDocument();
findEvents();
diff --git a/src/uscxml/transform/Transformer.h b/src/uscxml/transform/Transformer.h
index 16d0a94..c88015b 100644
--- a/src/uscxml/transform/Transformer.h
+++ b/src/uscxml/transform/Transformer.h
@@ -21,7 +21,8 @@
#define TRANSFORMER_H_32113356
#include <iostream>
-#include "uscxml/interpreter/InterpreterRC.h"
+#include <map>
+#include "uscxml/Interpreter.h"
namespace uscxml {
@@ -34,6 +35,11 @@ public:
throw std::runtime_error("Transformer cannot be interpreted as an Interpreter again");
}
+protected:
+ std::multimap<std::string, std::string> _extensions;
+ std::list<std::string> _options;
+
+ friend class Transformer;
};
class USCXML_API Transformer : public boost::enable_shared_from_this<Transformer> {
@@ -73,6 +79,14 @@ public:
return _impl;
}
+ void setExtensions(const std::multimap<std::string, std::string>& extensions) {
+ _impl->_extensions = extensions;
+ }
+
+ void setOptions(const std::list<std::string>& options) {
+ _impl->_options = options;
+ }
+
protected:
boost::shared_ptr<TransformerImpl> _impl;