summaryrefslogtreecommitdiffhomepage
path: root/cpp.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-11-09 16:41:07 +0100
committerRoland Reichwein <mail@reichwein.it>2020-11-09 16:41:07 +0100
commitfe063834e53e856823b9a42ad3a5e04153446849 (patch)
tree6ea84c1274e52bf5a07d7fcb8dbb64ceb6fc7a47 /cpp.cpp
parentfc1461874a6bcecc919f650d1bfb6bf37161c413 (diff)
Support multiply (WIP)
Diffstat (limited to 'cpp.cpp')
-rw-r--r--cpp.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/cpp.cpp b/cpp.cpp
index e4d935a..ce4a7c5 100644
--- a/cpp.cpp
+++ b/cpp.cpp
@@ -361,6 +361,8 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv
{
if (childTypesOfNodeMatch(index, {"literal"}))
return getValue(index, 0);
+ if (childTypesOfNodeMatch(index, {"(", "expression", ")"}))
+ return getValue(index, 1);
throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO
}
},
@@ -394,21 +396,46 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv
},
{ "multiplicative-expression", [&](index_t index) -> std::any
{
+ if (childTypesOfNodeMatch(index, {"pm-expression", "multiplicative-expression-EXT"})) {
+ if (childTypesOfChildMatch(index, 1, {"*", "", ""})) {
+ FlowGraph::LocalScope scope; // TODO: move to context!
+ FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)};
+ FlowGraph::Data value0 {std::any_cast<FlowGraph::Data>(getValue(index, 0))};
+ FlowGraph::Data value1 {std::any_cast<FlowGraph::Data>(getValue(index, 1))};
+
+ std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(FlowGraph::BinaryOperationType::Multiply, destination, value0, value1)};
+ return node;
+ }
+ }
if (childTypesOfNodeMatch(index, {"pm-expression", ""}) && !getValue(index, 1).has_value())
return getValue(index, 0);
throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO
}
},
+ { "multiplicative-expression-EXT", [&](index_t index) -> std::any
+ {
+ if (childTypesOfNodeMatch(index, {"*", "pm-expression", ""}) && !getValue(index, 2).has_value()) {
+ return getValue(index, 1);
+ } else if (childTypesOfNodeMatch(index, {})) {
+ return {};
+ }
+ throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO
+ }
+ },
{ "additive-expression", [&](index_t index) -> std::any
{
- if (childTypesOfNodeMatch(index, {"multiplicative-expression", "additive-expression-EXT"}) && childTypesOfChildMatch(index, 1, {"+", "", ""})) {
- FlowGraph::LocalScope scope; // TODO: move to context!
- FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)};
- FlowGraph::Data value0 {std::any_cast<FlowGraph::Data>(getValue(index, 0))};
- FlowGraph::Data value1 {std::any_cast<FlowGraph::Data>(getValue(index, 1))};
-
- std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(FlowGraph::BinaryOperationType::Add, destination, value0, value1)};
- return node;
+ if (childTypesOfNodeMatch(index, {"multiplicative-expression", "additive-expression-EXT"})) {
+ if (childTypesOfChildMatch(index, 1, {"+", "", ""})) {
+ FlowGraph::LocalScope scope; // TODO: move to context!
+ FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)};
+ FlowGraph::Data value0 {std::any_cast<FlowGraph::Data>(getValue(index, 0))};
+ FlowGraph::Data value1 {std::any_cast<FlowGraph::Data>(getValue(index, 1))};
+
+ std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(FlowGraph::BinaryOperationType::Add, destination, value0, value1)};
+ return node;
+ } else if (!getValue(index, 1).has_value()) {
+ return getValue(index, 0);
+ }
}
throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO
}