diff --git a/src/Lexer.cpp b/src/Lexer.cpp index e32dd09..c571f8f 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -7,7 +7,7 @@ #define IDENTIFIERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ_0123456789" #define DIGITS "0123456789" -Lexer::Lexer(const std::string& fname) : location(1, 0, fname), index(-1), previous_location(1, 0, fname) +Lexer::Lexer(const std::string& fname) : location(1, 0, fname), previous_location(1, 0, fname), index(-1) { } @@ -17,10 +17,10 @@ Lexer::~Lexer() int Lexer::advance() { - previous_location = location; + previous_location = Location{ location }; ++index; location.advance(); - if (index >= current_lexed_text.size()) return 0; + if (index >= (ssize_t)current_lexed_text.size()) return 0; current_char = current_lexed_text[index]; location.pos_from_char(current_char); if (current_char == '\n') @@ -46,10 +46,10 @@ int Lexer::rewind() std::string Lexer::recalculate_current_line(const std::string& text) { - int idx = index; + ssize_t idx = index; std::string final_str; ++idx; - while (idx != text.size() && text[idx] != '\n') + while (idx != (ssize_t)text.size() && text[idx] != '\n') { final_str += text[idx]; ++idx; @@ -106,7 +106,7 @@ TokenStream Lexer::lex(const std::string& text) switch (current_char) { case '/': - if (index + 1 != current_lexed_text.size()) + if (index + 1 != (ssize_t)current_lexed_text.size()) { if (current_lexed_text[index + 1] == '/') { @@ -172,7 +172,7 @@ TokenStream Lexer::lex(const std::string& text) break; case '\377': result.push_back(Token(TT_EOF, location)); - return std::move(result); + return result; default: Error::throw_error(location, current_line_text, "unknown character"); } @@ -180,7 +180,7 @@ TokenStream Lexer::lex(const std::string& text) result.push_back(Token(TT_EOF, location)); - return std::move(result); + return result; } Token Lexer::create_identifier() @@ -303,7 +303,7 @@ Token Lexer::create_string() } if (current_char == '\\') { - if (index + 1 == current_lexed_text.size()) + if (index + 1 == (ssize_t)current_lexed_text.size()) { Error::throw_error(location, current_line_text, "unfinished escape sequence"); } diff --git a/src/Lexer.h b/src/Lexer.h index 32848ff..5e44844 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -19,7 +19,7 @@ class Lexer int advance(); int rewind(); char current_char; - int index; + ssize_t index; Lexer(const std::string& filename); diff --git a/src/Parser.cpp b/src/Parser.cpp index ab61b63..a019e4d 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -37,7 +37,7 @@ std::shared_ptr Parser::parse() int Parser::advance() { ++index; - if (index < tokens.size()) + if (index < (ssize_t)tokens.size()) { current_token = &tokens[index]; } @@ -136,7 +136,7 @@ Result Parser::function() { proto.returnType = m_type_map.at(current_token->string_value.value()); } - catch (std::out_of_range) + catch (const std::out_of_range&) { return Err("Expected type name", current_token); } diff --git a/src/Parser.h b/src/Parser.h index 5b8acd2..c71db3c 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -14,7 +14,7 @@ class Parser private: Parser(const TokenStream& tokens); TokenStream tokens; - int index = -1; + ssize_t index = -1; int advance(); Token* current_token;