summaryrefslogtreecommitdiffhomepage
path: root/cpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp.cpp')
-rw-r--r--cpp.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/cpp.cpp b/cpp.cpp
index 837eae9..61fdc0e 100644
--- a/cpp.cpp
+++ b/cpp.cpp
@@ -10,9 +10,6 @@
#include "grammer.h"
#include "minicc.h"
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
-
#include <boost/core/demangle.hpp>
#include <functional>
@@ -399,7 +396,7 @@ 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 (childTypesOfNodeMatch(index, {"multiplicative-expression", "", "pm-expression"})) {
if (getValue(index, 0).type() != typeid(FlowGraph::Graph))
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::Graph))
@@ -416,7 +413,17 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv
FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(result.scope())};
- std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(FlowGraph::BinaryOperationType::Multiply,
+ FlowGraph::BinaryOperationType type{};
+ if (getType(index, 1) == "*")
+ type = FlowGraph::BinaryOperationType::Multiply;
+ else if (getType(index, 1) == "/")
+ type = FlowGraph::BinaryOperationType::Divide;
+ else if (getType(index, 1) == "%")
+ type = FlowGraph::BinaryOperationType::Modulo;
+ else
+ throw std::runtime_error("ICE: multiplicative-expression: Unknown operand: "s + getType(index, 1));
+
+ std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(type,
destination,
lastOp0->destination(), lastOp1->destination())};