diff options
author | Nao Pross <naopross@thearcway.org> | 2017-11-28 15:05:02 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2017-11-28 15:05:02 +0100 |
commit | 12e86e71ca36a58d7e2ed64f0454b65ed6f7eb56 (patch) | |
tree | 466f7d2756b0619921e2d9d061862c8443649ed3 /src/diagram/Statement.hpp | |
parent | Update header ifdefs to match and clean up comments (diff) | |
download | OrbitingYeti-12e86e71ca36a58d7e2ed64f0454b65ed6f7eb56.tar.gz OrbitingYeti-12e86e71ca36a58d7e2ed64f0454b65ed6f7eb56.zip |
New data structure for Structogram and Statements
Diffstat (limited to '')
-rw-r--r-- | src/diagram/Statement.hpp | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/src/diagram/Statement.hpp b/src/diagram/Statement.hpp index 1781a97..4eb3b4d 100644 --- a/src/diagram/Statement.hpp +++ b/src/diagram/Statement.hpp @@ -10,35 +10,28 @@ #include <string> #include <memory> +#include <vector> +#include <map> namespace samb { - /* Possible types of statement, according to the NS diagram paper * - * PROCESS, - * DECISION, - * SWITCH, - * WHILE, - * UNTIL, - * SCOPE, - * PARALLEL, + * PROCESS : a statement that does something + * DECISION : splits the program in 2 branches based on a condition + * SWITCH : splits the program in n branches depending on a value + * WHILE : repeat first loop + * UNTIL : repeat last loop + * SCOPE : simple scope to isolate variables + * PARALLEL : parallel operations */ -/* this struct is a link for linked list that stores the data in a tree-like - * structure, BUT it is not a tree because it allows 2 or more nodes to point - * at a single node - * - * Tree: Statements: - * A - B - C - D A - B - C - D - G - * \ \ / - * E - F E - F - * - * Because a statements can be branching elements. (if / switch) - * - * This class is also a *Factory* to make statements. +/* This struct is a statement (link) of the iterable object Scope + * (linked list), that is also a common interface for the various types of + * statements. */ -struct Statement { +class Statement { +public: using pointer = std::shared_ptr<Statement>; enum Type { @@ -56,20 +49,25 @@ struct Statement { * TODO: think of something more elegant to solve this */ END - } type; + }; - std::string text; + const Type type; - pointer next; - pointer scope; // TODO: make iterator aware of scope + Statement(Type type, const std::string& text, pointer next); + virtual ~Statement(); - static Statement::pointer makeStatement(Type t); + bool operator==(const Statement& other) const; - virtual ~Statement(); - bool operator==(const Statement& other); + /* accessors */ + void next(pointer next) { m_next = next; } + pointer next() const { return m_next; } + + void text(const std::string& text) { m_text = text; } + const std::string& text() const { return m_text; } private: - Statement(Type type, std::string txt, pointer next, pointer scope); + std::string m_text; + pointer m_next; }; } /* namespace samb */ |