diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-11-21 15:19:45 +0100 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-11-21 15:19:45 +0100 | 
| commit | 7edbd99775416a32c88acf8e9379518436905f02 (patch) | |
| tree | 6356edb79f846df4aa2f6a8a5ecfeef4e651bcc0 /grammer.cpp | |
| parent | 7250bbe5ae2d2ee6b0334bc462aab73f7d8dac0e (diff) | |
Support gcc 10 and clang 11
Diffstat (limited to 'grammer.cpp')
| -rw-r--r-- | grammer.cpp | 16 | 
1 files changed, 13 insertions, 3 deletions
| 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<index_t>(child_id); +} + +int32_t Gram::ChildIdFromNodeId(index_t node_id) +{ + return static_cast<int32_t>(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<int32_t, size_t>{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"); | 
