From 6fa97514f1b76a710886d49b33424ed0954ce1c3 Mon Sep 17 00:00:00 2001 From: TarCV Date: Sun, 21 Apr 2019 01:42:05 +0300 Subject: [PATCH 1/2] Fix reading a whole file (must be "rb", otherwise fseek+ftell is wrong) --- src/lexer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lexer.cpp b/src/lexer.cpp index d1ede1f..d3c7e11 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -72,7 +72,7 @@ void Lexer::processFile(String fileName) void Lexer::processFileInternal(String fileName) { FileNameStack << fileName; - FILE* fp = fopen (fileName, "r"); + FILE* fp = fopen (fileName, "rb"); if (fp == null) error ("couldn't open %1 for reading: %2", fileName, strerror (errno)); From b64a4698edd45adea48de01400052bd20e03c952 Mon Sep 17 00:00:00 2001 From: TarCV Date: Sun, 21 Apr 2019 02:32:15 +0300 Subject: [PATCH 2/2] Fix m_tokenPosition being incompatible with m_token.begin()/end() iters --- src/lexer.cpp | 26 ++++++++++++++------------ src/lexer.h | 6 ++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/lexer.cpp b/src/lexer.cpp index d3c7e11..9c787c1 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -39,6 +39,20 @@ static Lexer* MainLexer = null; Lexer::Lexer() { ASSERT_EQ (MainLexer, null); + + // Dummy token in the beginning to set m_tokenPosition to a pos before the first actual token + { + assert(m_tokens.isEmpty()); + TokenInfo nulltok; + nulltok.type = Token::Any; + nulltok.file = ""; + nulltok.line = -1; + nulltok.column = -1; + nulltok.text = ""; + m_tokens << nulltok; + } + m_tokenPosition = m_tokens.begin(); + MainLexer = this; } @@ -53,18 +67,6 @@ Lexer::~Lexer() // void Lexer::processFile(String fileName) { - assert(m_tokens.isEmpty()); - - // Dummy token in the beginning to set m_tokenPosition to a pos before the first actual token - TokenInfo nulltok; - nulltok.type = Token::Any; - nulltok.file = fileName; - nulltok.line = -1; - nulltok.column = -1; - nulltok.text = ""; - - m_tokens << nulltok; - processFileInternal(fileName); } // _________________________________________________________________________________________________ diff --git a/src/lexer.h b/src/lexer.h index fb4c43a..b31fce5 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -51,6 +51,12 @@ class Lexer Lexer(); ~Lexer(); + // Disable copying and moving to keep m_tokenPosition iteration valid + Lexer(const Lexer&) = delete; + Lexer& operator= (const Lexer&) = delete; + Lexer(const Lexer&&) = delete; + Lexer& operator=(const Lexer&& other) = delete; + void processFile (String fileName); bool next (Token req = Token::Any); void mustGetNext (Token tok);