diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-04-24 08:36:14 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-04-24 08:36:14 (GMT) |
commit | 6b53548ae32336db822d6e6af0e14413c82c74dd (patch) | |
tree | 8f2ecf59b1713a9c3ff8720a01ac53c5fca7aa8e /src/uscxml/transform/FSMToPromela.h | |
parent | b54d9c61b6c29c973168f33f683a49051f0ed3cc (diff) | |
download | uscxml-6b53548ae32336db822d6e6af0e14413c82c74dd.zip uscxml-6b53548ae32336db822d6e6af0e14413c82c74dd.tar.gz uscxml-6b53548ae32336db822d6e6af0e14413c82c74dd.tar.bz2 |
Support for custom event sources with promela
Diffstat (limited to 'src/uscxml/transform/FSMToPromela.h')
-rw-r--r-- | src/uscxml/transform/FSMToPromela.h | 80 |
1 files changed, 65 insertions, 15 deletions
diff --git a/src/uscxml/transform/FSMToPromela.h b/src/uscxml/transform/FSMToPromela.h index 37c2b67..7872997 100644 --- a/src/uscxml/transform/FSMToPromela.h +++ b/src/uscxml/transform/FSMToPromela.h @@ -20,6 +20,7 @@ #ifndef FSMTOPROMELA_H_RP48RFDJ #define FSMTOPROMELA_H_RP48RFDJ +#include "uscxml/interpreter/InterpreterDraft6.h" #include "uscxml/DOMUtils.h" #include "uscxml/util/Trie.h" @@ -32,42 +33,92 @@ namespace uscxml { class PromelaInline { public: + PromelaInline() : type(PROMELA_NIL) {} + + operator bool() { + return (type != PROMELA_NIL); + } + + void dump(); + enum PromelaInlineType { + PROMELA_NIL, PROMELA_CODE, PROMELA_EVENT_SOURCE, + PROMELA_EVENT_SOURCE_CUSTOM, PROMELA_PROGRESS_LABEL, PROMELA_ACCEPT_LABEL, PROMELA_END_LABEL }; std::string content; + std::list<std::list<std::string> > sequences; + PromelaInlineType type; }; class PromelaInlines { public: - PromelaInlines() : hasProgressLabel(false), hasAcceptLabel(false), hasEndLabel(false), hasEventSource(false), hasCode(false) {} + PromelaInlines() : progressLabels(0), acceptLabels(0), endLabels(0), eventSources(0), customEventSources(0), codes(0) {} + + void merge(const PromelaInlines& other) { + inlines.insert(inlines.end(), other.inlines.begin(), other.inlines.end()); + progressLabels += other.progressLabels; + acceptLabels += other.acceptLabels; + endLabels += other.endLabels; + eventSources += other.eventSources; + customEventSources += other.customEventSources; + codes += other.codes; + } + + operator bool() { + return inlines.size() > 0; + } std::list<PromelaInline> inlines; - bool hasProgressLabel; - bool hasAcceptLabel; - bool hasEndLabel; - bool hasEventSource; - bool hasCode; + int progressLabels; + int acceptLabels; + int endLabels; + int eventSources; + int customEventSources; + int codes; }; -struct PromelaEventSource { - std::list<std::list<std::string> > sequences; - void dump(); +class PromelaEventSource { +public: + + enum PromelaEventSourceType { + PROMELA_EVENT_SOURCE_INVALID, + PROMELA_EVENT_SOURCE_INVOKER, + PROMELA_EVENT_SOURCE_GLOBAL, + }; + + PromelaEventSource(); + PromelaEventSource(const PromelaInlines& sources, const Arabica::DOM::Node<std::string>& parent); + + void writeStartEventSources(std::ostream& stream, int indent = 0); + void writeStopEventSources(std::ostream& stream, int indent = 0); + void writeDeclarations(std::ostream& stream, int indent = 0); + void writeEventSource(std::ostream& stream); + operator bool() { - return sequences.size() > 0; + return type != PROMELA_EVENT_SOURCE_INVALID; } + + std::string name; + PromelaInlines eventSources; + Arabica::DOM::Node<std::string> container; + PromelaEventSourceType type; + Trie* trie; }; class FSMToPromela : public InterpreterDraft6 { public: static void writeProgram(std::ostream& stream, const Interpreter& interpreter); + + static std::string beautifyIndentation(const std::string& code, int indent = 0); + protected: FSMToPromela(); void writeProgram(std::ostream& stream); @@ -78,22 +129,21 @@ protected: void writeStates(std::ostream& stream); void writeDeclarations(std::ostream& stream); void writeEventSources(std::ostream& stream); - void writeEventSource(std::ostream& stream, const std::string& name, const PromelaEventSource& source); void writeExecutableContent(std::ostream& stream, const Arabica::DOM::Node<std::string>& node, int indent = 0); void writeInlineComment(std::ostream& stream, const Arabica::DOM::Node<std::string>& node); void writeFSM(std::ostream& stream); void writeEventDispatching(std::ostream& stream); void writeMain(std::ostream& stream); - void writeIfBlock(std::ostream& stream, const Arabica::XPath::NodeSet<std::string>& condChain, int indent = 0); void writeDispatchingBlock(std::ostream& stream, const Arabica::XPath::NodeSet<std::string>& transChain, int indent = 0); - std::string beautifyIndentation(const std::string& code, int indent = 0); - Arabica::XPath::NodeSet<std::string> getTransientContent(const Arabica::DOM::Node<std::string>& state); Arabica::DOM::Node<std::string> getUltimateTarget(const Arabica::DOM::Node<std::string>& transition); - PromelaInlines getInlinePromela(const Arabica::XPath::NodeSet<std::string>& elements, bool recurse = false); + + static PromelaInlines getInlinePromela(const std::string&); + static PromelaInlines getInlinePromela(const Arabica::XPath::NodeSet<std::string>& elements, bool recurse = false); + static PromelaInlines getInlinePromela(const Arabica::DOM::Node<std::string>& elements); Trie _eventTrie; Arabica::XPath::NodeSet<std::string> _globalStates; |