diff options
Diffstat (limited to 'cpp.cpp')
-rw-r--r-- | cpp.cpp | 86 |
1 files changed, 31 insertions, 55 deletions
@@ -368,7 +368,7 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv }, { "postfix-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"primary-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"primary-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } @@ -389,126 +389,102 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv }, { "pm-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"cast-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"cast-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "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, {"multiplicative-expression", "*", "pm-expression"})) { + 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, 2))}; + + 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()) + if (childTypesOfNodeMatch(index, {"pm-expression"})) 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"})) { - 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 - } - }, - { "additive-expression-EXT", [&](index_t index) -> std::any - { - if (childTypesOfNodeMatch(index, {"+", "multiplicative-expression", ""}) && !getValue(index, 2).has_value()) { - return getValue(index, 1); - } else if (childTypesOfNodeMatch(index, {})) { - return {}; + if (childTypesOfNodeMatch(index, {"additive-expression", "+", "multiplicative-expression"})) { + 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, 2))}; + + std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(FlowGraph::BinaryOperationType::Add, destination, value0, value1)}; + return node; } + if (childTypesOfNodeMatch(index, {"multiplicative-expression"})) + return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "shift-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"additive-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"additive-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "compare-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"shift-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"shift-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "relational-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"compare-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"compare-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "equality-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"relational-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"relational-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "and-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"equality-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"equality-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "exclusive-or-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"and-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"and-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "inclusive-or-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"exclusive-or-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"exclusive-or-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "logical-and-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"inclusive-or-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"inclusive-or-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, { "logical-or-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"logical-and-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"logical-and-expression"})) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } @@ -529,7 +505,7 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv }, { "expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"assignment-expression", ""}) && !getValue(index, 1).has_value()) { + if (childTypesOfNodeMatch(index, {"assignment-expression"})) { 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); |