Reduce nesting depth in some functions (#1739)

This commit is contained in:
Rangi
2025-07-09 16:20:33 -04:00
committed by GitHub
parent 41ab5dff5a
commit 44f5b47bf0

View File

@@ -2287,10 +2287,28 @@ static Token skipIfBlock(bool toEndc) {
Defer reenableExpansions = scopedDisableExpansions(); Defer reenableExpansions = scopedDisableExpansions();
for (;;) { for (int c;; atLineStart = false) {
if (atLineStart) { // Read chars until EOL
int c; while (!atLineStart) {
c = nextChar();
if (c == EOF) {
return Token(T_(YYEOF));
} else if (c == '\\') {
// Unconditionally skip the next char, including line continuations
c = nextChar();
} else if (c == '\r' || c == '\n') {
atLineStart = true;
}
if (c == '\r' || c == '\n') {
handleCRLF(c);
// Do this both on line continuations and plain EOLs
nextLine();
}
}
// Skip leading whitespace
for (;; shiftChar()) { for (;; shiftChar()) {
c = peek(); c = peek();
if (!isWhitespace(c)) { if (!isWhitespace(c)) {
@@ -2298,7 +2316,9 @@ static Token skipIfBlock(bool toEndc) {
} }
} }
if (startsIdentifier(c)) { if (!startsIdentifier(c)) {
continue;
}
shiftChar(); shiftChar();
switch (Token token = readIdentifier(c, false); token.type) { switch (Token token = readIdentifier(c, false); token.type) {
case T_(POP_IF): case T_(POP_IF):
@@ -2336,29 +2356,6 @@ static Token skipIfBlock(bool toEndc) {
break; break;
} }
} }
atLineStart = false;
}
// Read chars until EOL
do {
int c = nextChar();
if (c == EOF) {
return Token(T_(YYEOF));
} else if (c == '\\') {
// Unconditionally skip the next char, including line continuations
c = nextChar();
} else if (c == '\r' || c == '\n') {
atLineStart = true;
}
if (c == '\r' || c == '\n') {
handleCRLF(c);
// Do this both on line continuations and plain EOLs
nextLine();
}
} while (!atLineStart);
}
} }
static Token yylex_SKIP_TO_ELIF() { static Token yylex_SKIP_TO_ELIF() {
@@ -2378,10 +2375,28 @@ static Token yylex_SKIP_TO_ENDR() {
Defer reenableExpansions = scopedDisableExpansions(); Defer reenableExpansions = scopedDisableExpansions();
for (;;) { for (int c;; atLineStart = false) {
if (atLineStart) { // Read chars until EOL
int c; while (!atLineStart) {
c = nextChar();
if (c == EOF) {
return Token(T_(YYEOF));
} else if (c == '\\') {
// Unconditionally skip the next char, including line continuations
c = nextChar();
} else if (c == '\r' || c == '\n') {
atLineStart = true;
}
if (c == '\r' || c == '\n') {
handleCRLF(c);
// Do this both on line continuations and plain EOLs
nextLine();
}
}
// Skip whitespace
for (;;) { for (;;) {
c = peek(); c = peek();
if (!isWhitespace(c)) { if (!isWhitespace(c)) {
@@ -2390,7 +2405,9 @@ static Token yylex_SKIP_TO_ENDR() {
shiftChar(); shiftChar();
} }
if (startsIdentifier(c)) { if (!startsIdentifier(c)) {
continue;
}
shiftChar(); shiftChar();
switch (readIdentifier(c, false).type) { switch (readIdentifier(c, false).type) {
case T_(POP_FOR): case T_(POP_FOR):
@@ -2416,29 +2433,6 @@ static Token yylex_SKIP_TO_ENDR() {
break; break;
} }
} }
atLineStart = false;
}
// Read chars until EOL
do {
int c = nextChar();
if (c == EOF) {
return Token(T_(YYEOF));
} else if (c == '\\') {
// Unconditionally skip the next char, including line continuations
c = nextChar();
} else if (c == '\r' || c == '\n') {
atLineStart = true;
}
if (c == '\r' || c == '\n') {
handleCRLF(c);
// Do this both on line continuations and plain EOLs
nextLine();
}
} while (!atLineStart);
}
} }
yy::parser::symbol_type yylex() { yy::parser::symbol_type yylex() {