diff --git a/lib/parser.cpp b/lib/parser.cpp index 7df18a1..35afa57 100644 --- a/lib/parser.cpp +++ b/lib/parser.cpp @@ -79,7 +79,7 @@ typedef struct { typedef struct { std::vector tokens; - int current; + size_t current; std::map, Frame> frames; std::stack> frame_stack; std::map> functions; @@ -159,7 +159,7 @@ bool match_sequence(Parser& parser, const std::vector>& type if (parser.current + types.size() >= parser.tokens.size()) { return false; } - for (int i = 0; i < types.size(); i++) { + for (size_t i = 0; i < types.size(); i++) { if (types[i].find(parser.tokens[parser.current + i].type) == types[i].end()) { return false; } @@ -301,7 +301,7 @@ std::shared_ptr binary_expression( Parser& parser, const std::vector>& types, TokenType expected_type, - const int& index = 0 + const size_t& index = 0 ) { if (index == types.size()) { return unary_expression(parser, expected_type); @@ -440,7 +440,7 @@ void check_native_function( bool same_parameters_type = expected_types.size() == actual_types.size(); if (same_parameters_type) { - for (int i = 0; i < expected_types.size(); i++) { + for (size_t i = 0; i < expected_types.size(); i++) { if (C_TYPE_TO_AST_TYPE.at(expected_types.at(i)) != actual_types.at(i)->get_type()) { same_parameters_type = false; break; @@ -454,7 +454,7 @@ void check_native_function( } std::cout << "Expected following function signature: " << C_TYPE_NAME.at(fun->get_return_type()) << " " << id << "("; - for (int i = 0; i < expected_types.size(); i++) { + for (size_t i = 0; i < expected_types.size(); i++) { std::cout << C_TYPE_NAME.at(expected_types.at(i)); if (i + 1 < expected_types.size()) { std::cout << ", "; @@ -463,7 +463,7 @@ void check_native_function( std::cout << ");"; std::cout << std::endl << "But got this instead: " << AST_TYPE_NAME.at(node->get_return_type()) << " " << id << "("; - for (int i = 0; i < node->get_parameters_count(); i++) { + for (size_t i = 0; i < node->get_parameters_count(); i++) { std::cout << AST_TYPE_NAME.at(actual_types.at(i)->get_type()); if (i + 1 < node->get_parameters_count()) { std::cout << ", "; @@ -656,7 +656,7 @@ std::shared_ptr block(Parser& parser) { std::shared_ptr block(new BlockNode()); push_scope(parser, block); const Frame& frame = parser.frames.at(current_frame(parser)); - const int nest_level = frame.scope_stack.size(); + const size_t nest_level = frame.scope_stack.size(); while ( !eof(parser) && ( frame.scope_stack.size() != nest_level || diff --git a/lib/scanner.cpp b/lib/scanner.cpp index 4fe3ccd..195469b 100644 --- a/lib/scanner.cpp +++ b/lib/scanner.cpp @@ -4,9 +4,9 @@ namespace scanner { struct Scanner { std::string code; - int start; - int current; - int line; + size_t start; + size_t current; + size_t line; }; Token create_token(const TokenType& type, const Scanner& scanner) { @@ -26,7 +26,7 @@ bool is_character(const char& c) { } bool match_string(const Scanner& scanner, const std::string& str, const bool& keyword = false) { - for (int i = 0; i < str.size(); i++) { + for (size_t i = 0; i < str.size(); i++) { const char p = scanner.code[scanner.current + i]; if (p == '\0' || p != str[i]) { return false; @@ -39,7 +39,7 @@ bool match_string(const Scanner& scanner, const std::string& str, const bool& ke } int match_quote(const Scanner& scanner) { - int p = scanner.current + 1; + size_t p = scanner.current + 1; while (p < scanner.code.size() && scanner.code[p] != '\n') { if (scanner.code[p] == '\\') { p += 2; @@ -70,7 +70,7 @@ int match_identifier(const Scanner& scanner) { } int next_line(const Scanner& scanner) { - int p = scanner.current; + size_t p = scanner.current; while (p < scanner.code.size() && scanner.code[p] != '\n') { p++; }