Skip to content

Commit

Permalink
Merge pull request #5 from TarCV/fixes2
Browse files Browse the repository at this point in the history
More cross platform compat fixes
  • Loading branch information
TarCV authored Apr 20, 2019
2 parents 27868d0 + b64a469 commit 99dbd44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
28 changes: 15 additions & 13 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,26 +67,14 @@ 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);
}
// _________________________________________________________________________________________________
//
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));
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 99dbd44

Please sign in to comment.