From 7edbd99775416a32c88acf8e9379518436905f02 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 21 Nov 2020 15:19:45 +0100 Subject: Support gcc 10 and clang 11 --- grammer.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'grammer.cpp') diff --git a/grammer.cpp b/grammer.cpp index 4af1fd4..f949e2a 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -46,6 +46,16 @@ int32_t Gram::ChildIdFromTokenId(index_t token_id) return -1 - int32_t(token_id); } +index_t Gram::NodeIdFromChildId(int32_t child_id) +{ + return static_cast(child_id); +} + +int32_t Gram::ChildIdFromNodeId(index_t node_id) +{ + return static_cast(node_id); +} + void Compiler::DumpTree() { Debug("= Dump ======================================="); @@ -73,7 +83,7 @@ void Compiler::DumpTree() todo.pop_front(); std::string line; - for (int i = 0; i < indent; i++) + for (size_t i = 0; i < indent; i++) line += "| "; if (ChildIdIsToken(current_index)) { index_t token_id {TokenIdFromChildId(current_index)}; @@ -85,7 +95,7 @@ void Compiler::DumpTree() line += "Node("s + std::to_string(current_index) + "): "s + node.type + "/" + std::to_string(node.variant); auto child_ids{node.child_ids}; - for (int i = 0; i < child_ids.size(); i++) { + for (size_t i = 0; i < child_ids.size(); i++) { todo.insert(todo.begin() + i, std::pair{child_ids[i], indent + 1}); } } @@ -405,7 +415,7 @@ namespace { if (ChildIdIsToken(child_id)) // token can't be ext node return false; - if (child_id >= nodes.size()) + if (NodeIdFromChildId(child_id) >= nodes.size()) throw std::runtime_error("Child node out of range at ext node detection: "s + std::to_string(child_id) + " vs. "s + std::to_string(nodes.size())); return nodes[child_id].type.ends_with("-EXT"); -- cgit v1.2.3