mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Use size_t for measuring nested depths
Multiple functions involve tracking the current depth of a nested structure (symbol expansions, interpolations, REPT/FOR blocks, parentheses).
This commit is contained in:
@@ -684,7 +684,7 @@ static void beginExpansion(char const *str, bool owned, char const *name)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
unsigned int depth = 0;
|
size_t depth = 0;
|
||||||
|
|
||||||
for (struct Expansion *exp = lexerState->expansions; exp; exp = exp->parent) {
|
for (struct Expansion *exp = lexerState->expansions; exp; exp = exp->parent) {
|
||||||
if (depth++ >= maxRecursionDepth)
|
if (depth++ >= maxRecursionDepth)
|
||||||
@@ -896,7 +896,7 @@ static int peekInternal(uint8_t distance)
|
|||||||
|
|
||||||
/* forward declarations for peek */
|
/* forward declarations for peek */
|
||||||
static void shiftChar(void);
|
static void shiftChar(void);
|
||||||
static char const *readInterpolation(unsigned int depth);
|
static char const *readInterpolation(size_t depth);
|
||||||
|
|
||||||
static int peek(void)
|
static int peek(void)
|
||||||
{
|
{
|
||||||
@@ -1357,7 +1357,7 @@ static int readIdentifier(char firstChar)
|
|||||||
|
|
||||||
/* Functions to read strings */
|
/* Functions to read strings */
|
||||||
|
|
||||||
static char const *readInterpolation(unsigned int depth)
|
static char const *readInterpolation(size_t depth)
|
||||||
{
|
{
|
||||||
if (depth >= maxRecursionDepth)
|
if (depth >= maxRecursionDepth)
|
||||||
fatalerror("Recursion limit (%zu) exceeded\n", maxRecursionDepth);
|
fatalerror("Recursion limit (%zu) exceeded\n", maxRecursionDepth);
|
||||||
@@ -2056,7 +2056,7 @@ static int yylex_RAW(void)
|
|||||||
lexer_GetLineNo(), lexer_GetColNo());
|
lexer_GetLineNo(), lexer_GetColNo());
|
||||||
|
|
||||||
/* This is essentially a modified `appendStringLiteral` */
|
/* This is essentially a modified `appendStringLiteral` */
|
||||||
unsigned int parenDepth = 0;
|
size_t parenDepth = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@@ -2445,7 +2445,7 @@ bool lexer_CaptureRept(struct CaptureBody *capture)
|
|||||||
capture->lineNo = lexer_GetLineNo();
|
capture->lineNo = lexer_GetLineNo();
|
||||||
|
|
||||||
char *captureStart = startCapture();
|
char *captureStart = startCapture();
|
||||||
unsigned int level = 0;
|
size_t depth = 0;
|
||||||
int c = EOF;
|
int c = EOF;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2465,12 +2465,12 @@ bool lexer_CaptureRept(struct CaptureBody *capture)
|
|||||||
switch (readIdentifier(c)) {
|
switch (readIdentifier(c)) {
|
||||||
case T_POP_REPT:
|
case T_POP_REPT:
|
||||||
case T_POP_FOR:
|
case T_POP_FOR:
|
||||||
level++;
|
depth++;
|
||||||
/* Ignore the rest of that line */
|
/* Ignore the rest of that line */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_POP_ENDR:
|
case T_POP_ENDR:
|
||||||
if (!level) {
|
if (!depth) {
|
||||||
/*
|
/*
|
||||||
* The final ENDR has been captured, but we don't want it!
|
* The final ENDR has been captured, but we don't want it!
|
||||||
* We know we have read exactly "ENDR", not e.g. an EQUS
|
* We know we have read exactly "ENDR", not e.g. an EQUS
|
||||||
@@ -2478,7 +2478,7 @@ bool lexer_CaptureRept(struct CaptureBody *capture)
|
|||||||
lexerState->captureSize -= strlen("ENDR");
|
lexerState->captureSize -= strlen("ENDR");
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
level--;
|
depth--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user