From af64d3fffa7bf1d9355ded92ef7c6652b4f23878 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 4 Mar 2014 18:28:28 -0800 Subject: [PATCH] Build with all warnings enabled Fix resulting warnings --- src/compiler/generate_code/c_code.cpp | 4 ++-- src/compiler/rules/pattern.cpp | 2 +- src/runtime/tree.cpp | 10 +++++----- tree_sitter.gyp | 10 ++++++++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/compiler/generate_code/c_code.cpp b/src/compiler/generate_code/c_code.cpp index e3322199..3d9017d9 100644 --- a/src/compiler/generate_code/c_code.cpp +++ b/src/compiler/generate_code/c_code.cpp @@ -184,7 +184,7 @@ namespace tree_sitter { string switch_on_parse_state() { string body = ""; - for (int i = 0; i < parse_table.states.size(); i++) + for (size_t i = 0; i < parse_table.states.size(); i++) body += _case(std::to_string(i), code_for_parse_state(parse_table.states[i])); body += _default("PARSE_PANIC();"); return _switch("PARSE_STATE()", body); @@ -192,7 +192,7 @@ namespace tree_sitter { string switch_on_lex_state() { string body = ""; - for (int i = 0; i < lex_table.states.size(); i++) + for (size_t i = 0; i < lex_table.states.size(); i++) body += _case(std::to_string(i), switch_on_lookahead_char(lex_table.states[i])); body += _case("ts_lex_state_error", switch_on_lookahead_char(lex_table.error_state)); body += _default("LEX_PANIC();"); diff --git a/src/compiler/rules/pattern.cpp b/src/compiler/rules/pattern.cpp index a5c3a910..06d07e9d 100644 --- a/src/compiler/rules/pattern.cpp +++ b/src/compiler/rules/pattern.cpp @@ -148,7 +148,7 @@ namespace tree_sitter { string error; const string input; const size_t length; - int position; + size_t position; }; Pattern::Pattern(const string &string) : value(string) {}; diff --git a/src/runtime/tree.cpp b/src/runtime/tree.cpp index 44143283..a8d31264 100644 --- a/src/runtime/tree.cpp +++ b/src/runtime/tree.cpp @@ -21,7 +21,7 @@ ts_tree * ts_tree_make_leaf(ts_symbol symbol, size_t size, size_t offset) { } ts_tree * ts_tree_make_node(ts_symbol symbol, size_t child_count, ts_tree **children, size_t size, size_t offset) { - for (int i = 0; i < child_count; i++) + for (size_t i = 0; i < child_count; i++) ts_tree_retain(children[i]); ts_tree *result = ts_tree_make(symbol, size, offset); result->data.children = { .count = child_count, .contents = children }; @@ -47,7 +47,7 @@ void ts_tree_release(ts_tree *tree) { if (tree->ref_count == 0) { ts_tree **children = ts_tree_children(tree); if (children) { - for (int i = 0; i < ts_tree_child_count(tree); i++) + for (size_t i = 0; i < ts_tree_child_count(tree); i++) ts_tree_release(children[i]); free(children); } @@ -62,7 +62,7 @@ int ts_tree_equals(const ts_tree *node1, const ts_tree *node2) { } else { if (node1->data.children.count != node2->data.children.count) return 0; - for (int i = 0; i < node1->data.children.count; i++) { + for (size_t i = 0; i < node1->data.children.count; i++) { ts_tree *child1 = node1->data.children.contents[i]; ts_tree *child2 = node2->data.children.contents[i]; if (!ts_tree_equals(child1, child2)) @@ -86,7 +86,7 @@ static string __tree_to_string(const ts_tree *tree, const char **symbol_names) { if (!tree) return "#"; if (tree->symbol == ts_builtin_sym_error) return "(ERROR)"; string result = string("(") + symbol_names[tree->symbol]; - for (int i = 0; i < tree->data.children.count; i++) + for (size_t i = 0; i < tree->data.children.count; i++) result += " " + __tree_to_string(tree->data.children.contents[i], symbol_names); return result + ")"; } @@ -100,7 +100,7 @@ char * ts_tree_string(const ts_tree *tree, const char **symbol_names) { char * ts_tree_error_string(const ts_tree *tree, const char **symbol_names) { string result = string("Unexpected character '") + tree->data.error.lookahead_char + "'. Expected:"; - for (int i = 0; i < tree->data.error.expected_input_count; i++) { + for (size_t i = 0; i < tree->data.error.expected_input_count; i++) { ts_symbol symbol = tree->data.error.expected_inputs[i]; result += string(" ") + symbol_names[symbol]; } diff --git a/tree_sitter.gyp b/tree_sitter.gyp index a056d5b7..f6d58a0e 100644 --- a/tree_sitter.gyp +++ b/tree_sitter.gyp @@ -11,6 +11,10 @@ 'sources': [ '