summaryrefslogtreecommitdiffhomepage
path: root/cpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp.cpp')
-rw-r--r--cpp.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/cpp.cpp b/cpp.cpp
index 887dbbd..4bb8a01 100644
--- a/cpp.cpp
+++ b/cpp.cpp
@@ -13,6 +13,8 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
+#include <boost/core/demangle.hpp>
+
#include <functional>
#include <optional>
#include <unordered_set>
@@ -398,6 +400,11 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv
{ "multiplicative-expression", [&](index_t index) -> std::any
{
if (childTypesOfNodeMatch(index, {"multiplicative-expression", "*", "pm-expression"})) {
+ if (getValue(index, 0).type() != typeid(FlowGraph::Data))
+ throw std::runtime_error("ICE: multiplicative-expression: Bad data type for argument 1: "s + demangle(getValue(index, 0).type()));
+ if (getValue(index, 2).type() != typeid(FlowGraph::Data))
+ throw std::runtime_error("ICE: multiplicative-expression: Bad data type for argument 3: "s + demangle(getValue(index, 2).type()));
+
FlowGraph::LocalScope scope; // TODO: move to context!
FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)};
FlowGraph::Data value0 {std::any_cast<FlowGraph::Data>(getValue(index, 0))};
@@ -414,6 +421,11 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv
{ "additive-expression", [&](index_t index) -> std::any
{
if (childTypesOfNodeMatch(index, {"additive-expression", "+", "multiplicative-expression"})) {
+ if (getValue(index, 0).type() != typeid(FlowGraph::Data))
+ throw std::runtime_error("ICE: additive-expression: Bad data type for argument 1: "s + demangle(getValue(index, 0).type()));
+ if (getValue(index, 2).type() != typeid(FlowGraph::Data))
+ throw std::runtime_error("ICE: additive-expression: Bad data type for argument 3: "s + demangle(getValue(index, 2).type()));
+
FlowGraph::LocalScope scope; // TODO: move to context!
FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)};
FlowGraph::Data value0 {std::any_cast<FlowGraph::Data>(getValue(index, 0))};
@@ -507,19 +519,27 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv
{ "expression", [&](index_t index) -> std::any
{
if (childTypesOfNodeMatch(index, {"assignment-expression"})) {
+ std::shared_ptr<FlowGraph::CreateScopeOp> scope_node {std::make_shared<FlowGraph::CreateScopeOp>()};
+ mCPPContext.graph.push_back(scope_node);
+
+ FlowGraph::LocalScope& scope{scope_node->scope()};
+
if (getValue(index, 0).type() == typeid(FlowGraph::Data)) { // got Data -> make trivial Node out of it and return it
- FlowGraph::LocalScope scope; // TODO: move to context!
+
FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)};
FlowGraph::Data source {std::any_cast<FlowGraph::Data>(getValue(index, 0))};
std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::UnaryOperation>(FlowGraph::UnaryOperationType::Store, destination, source)};
mCPPContext.graph.push_back(node);
return node;
- } else {
+ } else if (getValue(index, 0).type() == typeid(std::shared_ptr<FlowGraph::Node>)) {
std::shared_ptr<FlowGraph::Node> node {std::any_cast<std::shared_ptr<FlowGraph::Node>>(getValue(index, 0))};
mCPPContext.graph.push_back(node);
return getValue(index, 0);
+ } else {
+ throw std::runtime_error("ICE: expression: Unsupported argument type: "s + demangle(getValue(index, 0).type()));
}
+ mCPPContext.graph.push_back(std::make_shared<FlowGraph::DestroyScopeOp>(scope));
}
throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO
}