mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Refactor cases for simplicity, and remove redundant comments
This commit is contained in:
@@ -838,7 +838,8 @@ void lexer_DumpStringExpansions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discards a block comment
|
// Functions to discard non-tokenized characters
|
||||||
|
|
||||||
static void discardBlockComment() {
|
static void discardBlockComment() {
|
||||||
lexerState->disableMacroArgs = true;
|
lexerState->disableMacroArgs = true;
|
||||||
lexerState->disableInterpolation = true;
|
lexerState->disableInterpolation = true;
|
||||||
@@ -877,8 +878,6 @@ finish:
|
|||||||
lexerState->disableInterpolation = false;
|
lexerState->disableInterpolation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to discard all of a line's comments
|
|
||||||
|
|
||||||
static void discardComment() {
|
static void discardComment() {
|
||||||
lexerState->disableMacroArgs = true;
|
lexerState->disableMacroArgs = true;
|
||||||
lexerState->disableInterpolation = true;
|
lexerState->disableInterpolation = true;
|
||||||
@@ -892,9 +891,7 @@ static void discardComment() {
|
|||||||
lexerState->disableInterpolation = false;
|
lexerState->disableInterpolation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to read a line continuation
|
static void discardLineContinuation() {
|
||||||
|
|
||||||
static void readLineContinuation() {
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = peek();
|
int c = peek();
|
||||||
|
|
||||||
@@ -916,7 +913,7 @@ static void readLineContinuation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to read an anonymous label ref
|
// Functions to read tokenizable values
|
||||||
|
|
||||||
static void readAnonLabelRef(char c) {
|
static void readAnonLabelRef(char c) {
|
||||||
uint32_t n = 0;
|
uint32_t n = 0;
|
||||||
@@ -930,8 +927,6 @@ static void readAnonLabelRef(char c) {
|
|||||||
sym_WriteAnonLabelName(yylval.symName, n, c == '-');
|
sym_WriteAnonLabelName(yylval.symName, n, c == '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions to lex numbers of various radixes
|
|
||||||
|
|
||||||
static uint32_t readNumber(int radix, uint32_t baseValue) {
|
static uint32_t readNumber(int radix, uint32_t baseValue) {
|
||||||
uint32_t value = baseValue;
|
uint32_t value = baseValue;
|
||||||
|
|
||||||
@@ -1356,7 +1351,7 @@ static void readString(bool raw) {
|
|||||||
case ' ':
|
case ' ':
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n':
|
case '\n':
|
||||||
readLineContinuation();
|
discardLineContinuation();
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Macro arg
|
// Macro arg
|
||||||
@@ -1505,7 +1500,7 @@ static size_t appendStringLiteral(size_t i, bool raw) {
|
|||||||
case ' ':
|
case ' ':
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n':
|
case '\n':
|
||||||
readLineContinuation();
|
discardLineContinuation();
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Macro arg
|
// Macro arg
|
||||||
@@ -1815,7 +1810,7 @@ static int yylex_NORMAL() {
|
|||||||
case '\\':
|
case '\\':
|
||||||
// Macro args were handled by `peek`, and character escapes do not exist
|
// Macro args were handled by `peek`, and character escapes do not exist
|
||||||
// outside of string literals, so this must be a line continuation.
|
// outside of string literals, so this must be a line continuation.
|
||||||
readLineContinuation();
|
discardLineContinuation();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Handle raw strings... or fall through if '#' is not followed by '"'
|
// Handle raw strings... or fall through if '#' is not followed by '"'
|
||||||
@@ -1849,11 +1844,11 @@ static int yylex_NORMAL() {
|
|||||||
Symbol const *sym = sym_FindExactSymbol(yylval.symName);
|
Symbol const *sym = sym_FindExactSymbol(yylval.symName);
|
||||||
|
|
||||||
if (sym && sym->type == SYM_EQUS) {
|
if (sym && sym->type == SYM_EQUS) {
|
||||||
char const *s = sym->getEqus()->c_str();
|
char const *str = sym->getEqus()->c_str();
|
||||||
|
|
||||||
assert(s);
|
assert(str);
|
||||||
if (s[0])
|
if (str[0])
|
||||||
beginExpansion(s, false, sym->name);
|
beginExpansion(str, false, sym->name);
|
||||||
continue; // Restart, reading from the new buffer
|
continue; // Restart, reading from the new buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1892,7 +1887,7 @@ static int yylex_RAW() {
|
|||||||
if (!isWhitespace(c) && c != '\n' && c != '\r')
|
if (!isWhitespace(c) && c != '\n' && c != '\r')
|
||||||
goto backslash;
|
goto backslash;
|
||||||
// Line continuations count as "whitespace"
|
// Line continuations count as "whitespace"
|
||||||
readLineContinuation();
|
discardLineContinuation();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1978,7 +1973,7 @@ backslash:
|
|||||||
case ' ':
|
case ' ':
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n':
|
case '\n':
|
||||||
readLineContinuation();
|
discardLineContinuation();
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case EOF: // Can't really print that one
|
case EOF: // Can't really print that one
|
||||||
@@ -2079,22 +2074,22 @@ static int skipIfBlock(bool toEndc) {
|
|||||||
case T_POP_ELIF:
|
case T_POP_ELIF:
|
||||||
if (lexer_ReachedELSEBlock())
|
if (lexer_ReachedELSEBlock())
|
||||||
fatalerror("Found ELIF after an ELSE block\n");
|
fatalerror("Found ELIF after an ELSE block\n");
|
||||||
goto maybeFinish;
|
if (!toEndc && lexer_GetIFDepth() == startingDepth)
|
||||||
|
goto finish;
|
||||||
|
break;
|
||||||
|
|
||||||
case T_POP_ELSE:
|
case T_POP_ELSE:
|
||||||
if (lexer_ReachedELSEBlock())
|
if (lexer_ReachedELSEBlock())
|
||||||
fatalerror("Found ELSE after an ELSE block\n");
|
fatalerror("Found ELSE after an ELSE block\n");
|
||||||
lexer_ReachELSEBlock();
|
lexer_ReachELSEBlock();
|
||||||
// fallthrough
|
if (!toEndc && lexer_GetIFDepth() == startingDepth)
|
||||||
maybeFinish:
|
goto finish;
|
||||||
if (toEndc) // Ignore ELIF and ELSE, go to ENDC
|
break;
|
||||||
break;
|
|
||||||
// fallthrough
|
|
||||||
case T_POP_ENDC:
|
case T_POP_ENDC:
|
||||||
if (lexer_GetIFDepth() == startingDepth)
|
if (lexer_GetIFDepth() == startingDepth)
|
||||||
goto finish;
|
goto finish;
|
||||||
if (token == T_POP_ENDC)
|
lexer_DecIFDepth();
|
||||||
lexer_DecIFDepth();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
atLineStart = false;
|
atLineStart = false;
|
||||||
@@ -2108,7 +2103,7 @@ maybeFinish:
|
|||||||
token = T_EOF;
|
token = T_EOF;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (c == '\\') {
|
} else if (c == '\\') {
|
||||||
// Unconditionally skip the next char, including line conts
|
// Unconditionally skip the next char, including line continuations
|
||||||
c = nextChar();
|
c = nextChar();
|
||||||
} else if (c == '\r' || c == '\n') {
|
} else if (c == '\r' || c == '\n') {
|
||||||
atLineStart = true;
|
atLineStart = true;
|
||||||
@@ -2191,7 +2186,7 @@ static int yylex_SKIP_TO_ENDR() {
|
|||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (c == '\\') {
|
} else if (c == '\\') {
|
||||||
// Unconditionally skip the next char, including line conts
|
// Unconditionally skip the next char, including line continuations
|
||||||
c = nextChar();
|
c = nextChar();
|
||||||
} else if (c == '\r' || c == '\n') {
|
} else if (c == '\r' || c == '\n') {
|
||||||
atLineStart = true;
|
atLineStart = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user