Skip to content

[TableGen] Remove explicit recursion in LexToken #143697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions llvm/lib/TableGen/TGLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ int TGLexer::peekNextChar(int Index) const {
}

tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) {
restart:
TokStart = CurPtr;
// This always consumes at least one character.
int CurChar = getNextChar();
Expand All @@ -188,12 +189,12 @@ tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) {
return ReturnError(TokStart, "unexpected character");
case EOF:
// Lex next token, if we just left an include file.
// Note that leaving an include file means that the next
// symbol is located at the end of the 'include "..."'
// construct, so LexToken() is called with default
// false parameter.
if (processEOF())
return LexToken();
if (processEOF()) {
// Leaving an include file means that the next symbol is located at the
// end of the 'include "..."' construct.
FileOrLineStart = false;
goto restart;
}

// Return EOF denoting the end of lexing.
return tgtok::Eof;
Expand Down Expand Up @@ -238,10 +239,11 @@ tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) {
case ' ':
case '\t':
// Ignore whitespace.
return LexToken(FileOrLineStart);
goto restart;
case '\n':
// Ignore whitespace, and identify the new line.
return LexToken(true);
FileOrLineStart = true;
goto restart;
case '/':
// If this is the start of a // comment, skip until the end of the line or
// the end of the buffer.
Expand All @@ -252,7 +254,7 @@ tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) {
return tgtok::Error;
} else // Otherwise, this is an error.
return ReturnError(TokStart, "unexpected character");
return LexToken(FileOrLineStart);
goto restart;
case '-': case '+':
case '0': case '1': case '2': case '3': case '4': case '5': case '6':
case '7': case '8': case '9': {
Expand Down
Loading