From 7b6fc865d9871a63c7377ca8d9ebc57dd854d15c Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 7 Nov 2020 22:11:56 +0100 Subject: Handle nodes up to expression --- cpp.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'cpp.cpp') diff --git a/cpp.cpp b/cpp.cpp index 52cd5f2..afd6c52 100644 --- a/cpp.cpp +++ b/cpp.cpp @@ -420,6 +420,90 @@ std::unordered_map> CPP::getNodeEv 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()) + 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()) + 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()) + 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()) + 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()) + 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()) + 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()) + 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()) + 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()) + return getValue(index, 0); + throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO + } + }, + { "conditional-expression", [&](index_t index) -> std::any + { + if (childTypesOfNodeMatch(index, {"logical-or-expression"})) + return getValue(index, 0); + throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO + } + }, + { "assignment-expression", [&](index_t index) -> std::any + { + if (childTypesOfNodeMatch(index, {"conditional-expression"})) + return getValue(index, 0); + throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO + } + }, + { "expression", [&](index_t index) -> std::any + { + if (childTypesOfNodeMatch(index, {"assignment-expression", ""}) && !getValue(index, 1).has_value()) + return getValue(index, 0); + throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO + } + }, }; } -- cgit v1.2.3