From 673ca411b1953fbc25967ae23eb29e9082a864d5 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sat, 19 Sep 2015 13:19:49 -0700 Subject: [PATCH] Fix lint errors --- script/lint.sh | 2 +- src/compiler/build_tables/build_lex_table.cc | 1 + src/compiler/build_tables/build_parse_table.cc | 6 ++++-- src/compiler/build_tables/build_tables.cc | 2 ++ src/compiler/build_tables/build_tables.h | 2 +- src/compiler/build_tables/lex_conflict_manager.cc | 2 +- src/compiler/build_tables/lex_conflict_manager.h | 2 +- src/compiler/build_tables/parse_conflict_manager.cc | 13 +++++++------ src/compiler/build_tables/parse_conflict_manager.h | 2 +- src/compiler/build_tables/parse_item.cc | 1 + src/compiler/prepare_grammar/expand_repeats.cc | 2 +- src/compiler/prepare_grammar/expand_tokens.cc | 4 ++-- src/compiler/prepare_grammar/extract_tokens.cc | 1 + src/compiler/prepare_grammar/extract_tokens.h | 2 +- src/compiler/prepare_grammar/is_token.cc | 4 +++- src/compiler/prepare_grammar/prepare_grammar.cc | 4 ++-- src/compiler/prepare_grammar/prepare_grammar.h | 2 +- src/compiler/rule.h | 8 ++++---- src/compiler/rules/character_range.cc | 2 +- src/runtime/parser.c | 3 +-- 20 files changed, 37 insertions(+), 28 deletions(-) diff --git a/script/lint.sh b/script/lint.sh index 08d37634..3d6a03dc 100755 --- a/script/lint.sh +++ b/script/lint.sh @@ -8,7 +8,7 @@ if [[ ! -f $CPPLINT ]]; then chmod +x $CPPLINT fi -FILTERS='--filter=-legal/copyright,-readability/todo' +FILTERS='--filter=-legal/copyright,-readability/todo,-build/c++11' $CPPLINT --linelength=90 --root=include $FILTERS include/tree_sitter/compiler.h 2>&1 $CPPLINT --linelength=90 --root=src $FILTERS $(find src/compiler -type f) 2>&1 diff --git a/src/compiler/build_tables/build_lex_table.cc b/src/compiler/build_tables/build_lex_table.cc index bab0497f..b7a52ba4 100644 --- a/src/compiler/build_tables/build_lex_table.cc +++ b/src/compiler/build_tables/build_lex_table.cc @@ -1,3 +1,4 @@ +#include "compiler/build_tables/build_lex_table.h" #include #include #include diff --git a/src/compiler/build_tables/build_parse_table.cc b/src/compiler/build_tables/build_parse_table.cc index 9d6c42f0..842fa88f 100644 --- a/src/compiler/build_tables/build_parse_table.cc +++ b/src/compiler/build_tables/build_parse_table.cc @@ -1,3 +1,4 @@ +#include "compiler/build_tables/build_parse_table.h" #include #include #include @@ -258,10 +259,11 @@ class ParseTableBuilder { return "END_OF_INPUT"; else return ""; - } else if (symbol.is_token) + } else if (symbol.is_token) { return lexical_grammar.rules[symbol.index].name; - else + } else { return grammar.rules[symbol.index].name; + } } string action_description(const ParseAction &action) const { diff --git a/src/compiler/build_tables/build_tables.cc b/src/compiler/build_tables/build_tables.cc index cbb1220e..f4f85f54 100644 --- a/src/compiler/build_tables/build_tables.cc +++ b/src/compiler/build_tables/build_tables.cc @@ -1,3 +1,5 @@ +#include "compiler/build_tables/build_tables.h" +#include #include "compiler/build_tables/build_lex_table.h" #include "compiler/build_tables/build_parse_table.h" #include "compiler/prepared_grammar.h" diff --git a/src/compiler/build_tables/build_tables.h b/src/compiler/build_tables/build_tables.h index af796d71..1df7456f 100644 --- a/src/compiler/build_tables/build_tables.h +++ b/src/compiler/build_tables/build_tables.h @@ -2,7 +2,7 @@ #define COMPILER_BUILD_TABLES_BUILD_TABLES_H_ #include -#include +#include #include #include "tree_sitter/compiler.h" #include "compiler/parse_table.h" diff --git a/src/compiler/build_tables/lex_conflict_manager.cc b/src/compiler/build_tables/lex_conflict_manager.cc index 30201d37..473edb4e 100644 --- a/src/compiler/build_tables/lex_conflict_manager.cc +++ b/src/compiler/build_tables/lex_conflict_manager.cc @@ -1,7 +1,7 @@ #include "compiler/build_tables/lex_conflict_manager.h" +#include #include "compiler/parse_table.h" #include "compiler/rules/built_in_symbols.h" -#include namespace tree_sitter { namespace build_tables { diff --git a/src/compiler/build_tables/lex_conflict_manager.h b/src/compiler/build_tables/lex_conflict_manager.h index 6f35c967..0dd9fca7 100644 --- a/src/compiler/build_tables/lex_conflict_manager.h +++ b/src/compiler/build_tables/lex_conflict_manager.h @@ -14,7 +14,7 @@ class LexConflictManager { const LexicalGrammar grammar; public: - LexConflictManager(const LexicalGrammar &); + explicit LexConflictManager(const LexicalGrammar &); bool resolve(const LexAction &, const LexAction &) const; }; diff --git a/src/compiler/build_tables/parse_conflict_manager.cc b/src/compiler/build_tables/parse_conflict_manager.cc index 7209e980..5e18dd78 100644 --- a/src/compiler/build_tables/parse_conflict_manager.cc +++ b/src/compiler/build_tables/parse_conflict_manager.cc @@ -1,7 +1,7 @@ #include "compiler/build_tables/parse_conflict_manager.h" +#include #include "compiler/parse_table.h" #include "compiler/rules/built_in_symbols.h" -#include namespace tree_sitter { namespace build_tables { @@ -32,13 +32,14 @@ pair ParseConflictManager::resolve( int max_precedence = *old_action.precedence_values.rbegin(); int new_precedence = *new_action.precedence_values.rbegin(); if (new_precedence < min_precedence || - (new_precedence == min_precedence && min_precedence < max_precedence)) + (new_precedence == min_precedence && + min_precedence < max_precedence)) { return { false, ConflictTypeResolved }; - else if (new_precedence > max_precedence || - (new_precedence == max_precedence && - min_precedence < max_precedence)) + } else if (new_precedence > max_precedence || + (new_precedence == max_precedence && + min_precedence < max_precedence)) { return { true, ConflictTypeResolved }; - else if (min_precedence == max_precedence) { + } else if (min_precedence == max_precedence) { switch (new_action.associativity) { case AssociativityLeft: return { true, ConflictTypeResolved }; diff --git a/src/compiler/build_tables/parse_conflict_manager.h b/src/compiler/build_tables/parse_conflict_manager.h index 04f7e01c..a95f2b31 100644 --- a/src/compiler/build_tables/parse_conflict_manager.h +++ b/src/compiler/build_tables/parse_conflict_manager.h @@ -25,7 +25,7 @@ class ParseConflictManager { const SyntaxGrammar syntax_grammar; public: - ParseConflictManager(const SyntaxGrammar &); + explicit ParseConflictManager(const SyntaxGrammar &); std::pair resolve(const ParseAction &, const ParseAction &, const rules::Symbol &) const; }; diff --git a/src/compiler/build_tables/parse_item.cc b/src/compiler/build_tables/parse_item.cc index 7c215b0a..67c42ff1 100644 --- a/src/compiler/build_tables/parse_item.cc +++ b/src/compiler/build_tables/parse_item.cc @@ -1,4 +1,5 @@ #include "compiler/build_tables/parse_item.h" +#include #include "tree_sitter/compiler.h" namespace tree_sitter { diff --git a/src/compiler/prepare_grammar/expand_repeats.cc b/src/compiler/prepare_grammar/expand_repeats.cc index 06625087..1a40dc39 100644 --- a/src/compiler/prepare_grammar/expand_repeats.cc +++ b/src/compiler/prepare_grammar/expand_repeats.cc @@ -56,7 +56,7 @@ class ExpandRepeats : public rules::IdentityRuleFn { } public: - ExpandRepeats(size_t offset) : offset(offset) {} + explicit ExpandRepeats(size_t offset) : offset(offset) {} rule_ptr expand(const rule_ptr &rule, const string &name) { rule_name = name; diff --git a/src/compiler/prepare_grammar/expand_tokens.cc b/src/compiler/prepare_grammar/expand_tokens.cc index 88251d8a..70b62781 100644 --- a/src/compiler/prepare_grammar/expand_tokens.cc +++ b/src/compiler/prepare_grammar/expand_tokens.cc @@ -31,8 +31,8 @@ class ExpandTokens : public rules::IdentityRuleFn { rule_ptr apply_to(const String *rule) { vector elements; - uint8_t *iter = (uint8_t *)rule->value.data(); - uint8_t *end = iter + rule->value.size(); + const uint8_t *iter = reinterpret_cast(rule->value.data()); + const uint8_t *end = iter + rule->value.size(); while (iter < end) { int32_t el; diff --git a/src/compiler/prepare_grammar/extract_tokens.cc b/src/compiler/prepare_grammar/extract_tokens.cc index 883e6f59..e914aaca 100644 --- a/src/compiler/prepare_grammar/extract_tokens.cc +++ b/src/compiler/prepare_grammar/extract_tokens.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include "tree_sitter/compiler.h" #include "compiler/prepared_grammar.h" #include "compiler/rules/visitor.h" diff --git a/src/compiler/prepare_grammar/extract_tokens.h b/src/compiler/prepare_grammar/extract_tokens.h index 1aee7e88..1a621d4d 100644 --- a/src/compiler/prepare_grammar/extract_tokens.h +++ b/src/compiler/prepare_grammar/extract_tokens.h @@ -1,7 +1,7 @@ #ifndef COMPILER_PREPARE_GRAMMAR_EXTRACT_TOKENS_H_ #define COMPILER_PREPARE_GRAMMAR_EXTRACT_TOKENS_H_ -#include +#include #include "tree_sitter/compiler.h" #include "compiler/prepare_grammar/interned_grammar.h" diff --git a/src/compiler/prepare_grammar/is_token.cc b/src/compiler/prepare_grammar/is_token.cc index 37bb4399..eb1628e3 100644 --- a/src/compiler/prepare_grammar/is_token.cc +++ b/src/compiler/prepare_grammar/is_token.cc @@ -1,6 +1,6 @@ +#include "compiler/prepare_grammar/is_token.h" #include "tree_sitter/compiler.h" #include "compiler/rules/visitor.h" -#include "compiler/rules/symbol.h" #include "compiler/rules/string.h" #include "compiler/rules/metadata.h" #include "compiler/rules/pattern.h" @@ -12,9 +12,11 @@ class IsToken : public rules::RuleFn { bool apply_to(const rules::String *rule) { return true; } + bool apply_to(const rules::Pattern *rule) { return true; } + bool apply_to(const rules::Metadata *rule) { return rule->value_for(rules::IS_TOKEN); } diff --git a/src/compiler/prepare_grammar/prepare_grammar.cc b/src/compiler/prepare_grammar/prepare_grammar.cc index e4b1d77d..fb881179 100644 --- a/src/compiler/prepare_grammar/prepare_grammar.cc +++ b/src/compiler/prepare_grammar/prepare_grammar.cc @@ -1,8 +1,9 @@ +#include "compiler/prepare_grammar/prepare_grammar.h" +#include #include "compiler/prepare_grammar/expand_repeats.h" #include "compiler/prepare_grammar/expand_tokens.h" #include "compiler/prepare_grammar/extract_tokens.h" #include "compiler/prepare_grammar/intern_symbols.h" -#include "compiler/prepare_grammar/prepare_grammar.h" #include "compiler/prepared_grammar.h" namespace tree_sitter { @@ -14,7 +15,6 @@ using std::make_tuple; tuple prepare_grammar( const Grammar &input_grammar) { - // Convert all string-based `NamedSymbols` into numerical `Symbols` auto intern_result = intern_symbols(input_grammar); const GrammarError *error = intern_result.second; diff --git a/src/compiler/prepare_grammar/prepare_grammar.h b/src/compiler/prepare_grammar/prepare_grammar.h index 471a4420..afa38bbc 100644 --- a/src/compiler/prepare_grammar/prepare_grammar.h +++ b/src/compiler/prepare_grammar/prepare_grammar.h @@ -1,7 +1,7 @@ #ifndef COMPILER_PREPARE_GRAMMAR_PREPARE_GRAMMAR_H_ #define COMPILER_PREPARE_GRAMMAR_PREPARE_GRAMMAR_H_ -#include +#include #include "compiler/prepared_grammar.h" namespace tree_sitter { diff --git a/src/compiler/rule.h b/src/compiler/rule.h index 1eb06c1a..55cf09e8 100644 --- a/src/compiler/rule.h +++ b/src/compiler/rule.h @@ -1,5 +1,5 @@ -#ifndef COMPILER_RULES_RULE_H_ -#define COMPILER_RULES_RULE_H_ +#ifndef COMPILER_RULE_H_ +#define COMPILER_RULE_H_ #include #include @@ -31,10 +31,10 @@ namespace std { template <> struct hash { size_t operator()(const tree_sitter::rule_ptr &rule) const { - return typeid(*rule).hash_code() ^ rule->hash_code(); + return rule->hash_code(); } }; } // namespace std -#endif // COMPILER_RULES_RULE_H_ +#endif // COMPILER_RULE_H_ diff --git a/src/compiler/rules/character_range.cc b/src/compiler/rules/character_range.cc index 0b6ab7cc..e1d92087 100644 --- a/src/compiler/rules/character_range.cc +++ b/src/compiler/rules/character_range.cc @@ -1,7 +1,7 @@ #include "compiler/rules/character_range.h" -#include "compiler/util/string_helpers.h" #include #include +#include "compiler/util/string_helpers.h" namespace tree_sitter { namespace rules { diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 3e51aeb1..171cba2c 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -1,12 +1,11 @@ +#include "runtime/parser.h" #include #include #include "tree_sitter/runtime.h" #include "tree_sitter/parser.h" #include "runtime/tree.h" #include "runtime/lexer.h" -#include "runtime/parser.h" #include "runtime/length.h" -#include "runtime/debugger.h" /* * Debugging