diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-11-15 18:39:01 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-11-15 18:39:01 +0100 |
commit | a3b4cd4fdd4340c952eaa00bca9bebf817b901ae (patch) | |
tree | 055d3ae4b9d1e37682c2e49b31a6531f189eebf5 /flowgraph/graph.cpp | |
parent | d07c5bc14edbe071ee7b4f47f174780e95e451aa (diff) |
Fixed unit tests, prepared hierarchical evaluation via stack (WIP)
Diffstat (limited to 'flowgraph/graph.cpp')
-rw-r--r-- | flowgraph/graph.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/flowgraph/graph.cpp b/flowgraph/graph.cpp index e8b6b5e..6398c68 100644 --- a/flowgraph/graph.cpp +++ b/flowgraph/graph.cpp @@ -1 +1,61 @@ #include "graph.h" + +#include "minicc.h" +#include "node.h" + +#include <string> + +using namespace std::string_literals; + +FlowGraph::Graph::Graph() +{ +} + +FlowGraph::Graph::Graph(const std::deque<std::shared_ptr<Node>>& nodes): std::deque<std::shared_ptr<Node>>(nodes) +{ + auto createLocalScope {std::make_shared<FlowGraph::CreateScopeOp>()}; + this->push_front(createLocalScope); + + auto destroyLocalScope {std::make_shared<FlowGraph::DestroyScopeOp>(createLocalScope->scope())}; + this->push_back(destroyLocalScope); +} + +FlowGraph::Graph::~Graph() +{ +} + +// Assume first node of graph to be CreateScopeOp +FlowGraph::LocalScope& FlowGraph::Graph::scope() const +{ + if (this->empty()) + throw std::runtime_error("ICE: FlowGraph expected to be non-empty!"); + + auto& front_deref {*front()}; + + if (typeid(front_deref) != typeid(FlowGraph::CreateScopeOp)) + throw std::runtime_error("ICE: Bad type of first graph element: "s + demangle(typeid(front_deref))); + + FlowGraph::CreateScopeOp& createScope {dynamic_cast<FlowGraph::CreateScopeOp&>(front_deref)}; + + return createScope.scope(); +} + +void FlowGraph::Graph::append(const FlowGraph::Graph& other) +{ + this->insert(this->end() - 1, other.begin() + 1, other.end() - 1); + + this->scope().append(other.scope()); +} + +void FlowGraph::Graph::append(std::shared_ptr<Node> node) +{ + this->insert(this->end() - 1, node); +} + +std::shared_ptr<FlowGraph::Node> FlowGraph::Graph::lastOp() const +{ + if (size() >= 3) + return *(end() - 2); + + throw std::runtime_error("ICE: No last operation found in graph"); +} |