Skip to content

Commit

Permalink
Fix m_tokenPosition being incompatible with m_token.begin()/end() iters
Browse files Browse the repository at this point in the history
  • Loading branch information
TarCV committed Apr 20, 2019
1 parent 6fa9751 commit b64a469
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
// _________________________________________________________________________________________________
Expand Down
6 changes: 6 additions & 0 deletions src/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b64a469

Please sign in to comment.