mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Port some cleanup from the WIP 'strings' branch
This is mostly variable renaming
This commit is contained in:
4
Makefile
4
Makefile
@@ -61,9 +61,9 @@ rgbasm_obj := \
|
||||
src/asm/lexer.o \
|
||||
src/asm/macro.o \
|
||||
src/asm/main.o \
|
||||
src/asm/parser.o \
|
||||
src/asm/opt.o \
|
||||
src/asm/output.o \
|
||||
src/asm/parser.o \
|
||||
src/asm/rpn.o \
|
||||
src/asm/section.o \
|
||||
src/asm/symbol.o \
|
||||
@@ -204,7 +204,7 @@ checkpatch:
|
||||
# compilation and make the continous integration infrastructure return failure.
|
||||
|
||||
develop:
|
||||
$Qenv $(MAKE) -j WARNFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-type-limits \
|
||||
$Qenv $(MAKE) WARNFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-type-limits \
|
||||
-Wno-sign-compare -Wvla -Wformat -Wformat-security -Wformat-overflow=2 \
|
||||
-Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused \
|
||||
-Wuninitialized -Wunknown-pragmas -Wstrict-overflow=4 \
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#ifndef RGBDS_FORMAT_SPEC_H
|
||||
#define RGBDS_FORMAT_SPEC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum FormatState {
|
||||
FORMAT_SIGN, // expects '+' or ' ' (optional)
|
||||
|
||||
@@ -82,8 +82,7 @@ static inline bool sym_IsConstant(struct Symbol const *sym)
|
||||
|
||||
static inline bool sym_IsNumeric(struct Symbol const *sym)
|
||||
{
|
||||
return sym->type == SYM_LABEL || sym->type == SYM_EQU
|
||||
|| sym->type == SYM_SET;
|
||||
return sym->type == SYM_LABEL || sym->type == SYM_EQU || sym->type == SYM_SET;
|
||||
}
|
||||
|
||||
static inline bool sym_IsLabel(struct Symbol const *sym)
|
||||
@@ -124,19 +123,19 @@ struct Symbol *sym_AddEqu(char const *symName, int32_t value);
|
||||
struct Symbol *sym_AddSet(char const *symName, int32_t value);
|
||||
uint32_t sym_GetPCValue(void);
|
||||
uint32_t sym_GetConstantSymValue(struct Symbol const *sym);
|
||||
uint32_t sym_GetConstantValue(char const *s);
|
||||
uint32_t sym_GetConstantValue(char const *symName);
|
||||
/*
|
||||
* Find a symbol by exact name, bypassing expansion checks
|
||||
*/
|
||||
struct Symbol *sym_FindExactSymbol(char const *name);
|
||||
struct Symbol *sym_FindExactSymbol(char const *symName);
|
||||
/*
|
||||
* Find a symbol by exact name; may not be scoped, produces an error if it is
|
||||
*/
|
||||
struct Symbol *sym_FindUnscopedSymbol(char const *name);
|
||||
struct Symbol *sym_FindUnscopedSymbol(char const *symName);
|
||||
/*
|
||||
* Find a symbol, possibly scoped, by name
|
||||
*/
|
||||
struct Symbol *sym_FindScopedSymbol(char const *name);
|
||||
struct Symbol *sym_FindScopedSymbol(char const *symName);
|
||||
struct Symbol const *sym_GetPC(void);
|
||||
struct Symbol *sym_AddMacro(char const *symName, int32_t defLineNo, char *body, size_t size);
|
||||
struct Symbol *sym_Ref(char const *symName);
|
||||
|
||||
@@ -943,10 +943,10 @@ restart:
|
||||
} else if (c == '{' && !lexerState->disableInterpolation) {
|
||||
/* If character is an open brace, do symbol interpolation */
|
||||
shiftChar();
|
||||
char const *ptr = readInterpolation(0);
|
||||
char const *str = readInterpolation(0);
|
||||
|
||||
if (ptr && ptr[0])
|
||||
beginExpansion(ptr, false, ptr);
|
||||
if (str && str[0])
|
||||
beginExpansion(str, false, str);
|
||||
goto restart;
|
||||
}
|
||||
|
||||
@@ -1381,10 +1381,10 @@ static char const *readInterpolation(size_t depth)
|
||||
|
||||
if (c == '{') { /* Nested interpolation */
|
||||
shiftChar();
|
||||
char const *ptr = readInterpolation(depth + 1);
|
||||
char const *str = readInterpolation(depth + 1);
|
||||
|
||||
if (ptr && ptr[0])
|
||||
beginExpansion(ptr, false, ptr);
|
||||
if (str && str[0])
|
||||
beginExpansion(str, false, str);
|
||||
continue; /* Restart, reading from the new buffer */
|
||||
} else if (c == EOF || c == '\r' || c == '\n' || c == '"') {
|
||||
error("Missing }\n");
|
||||
@@ -1490,6 +1490,7 @@ static void readString(void)
|
||||
|
||||
size_t i = 0;
|
||||
bool multiline = false;
|
||||
char const *str;
|
||||
|
||||
// We reach this function after reading a single quote, but we also support triple quotes
|
||||
if (peek() == '"') {
|
||||
@@ -1584,8 +1585,7 @@ static void readString(void)
|
||||
case '9':
|
||||
case '<':
|
||||
shiftChar();
|
||||
char const *str = readMacroArg(c);
|
||||
|
||||
str = readMacroArg(c);
|
||||
if (str) {
|
||||
while (*str)
|
||||
append_yylval_string(*str++);
|
||||
@@ -1608,11 +1608,10 @@ static void readString(void)
|
||||
// We'll be exiting the string scope, so re-enable expansions
|
||||
// (Not interpolations, since they're handled by the function itself...)
|
||||
lexerState->disableMacroArgs = false;
|
||||
char const *ptr = readInterpolation(0);
|
||||
|
||||
if (ptr) {
|
||||
while (*ptr)
|
||||
append_yylval_string(*ptr++);
|
||||
str = readInterpolation(0);
|
||||
if (str) {
|
||||
while (*str)
|
||||
append_yylval_string(*str++);
|
||||
}
|
||||
lexerState->disableMacroArgs = true;
|
||||
continue; // Do not copy an additional character
|
||||
@@ -1642,6 +1641,7 @@ static size_t appendStringLiteral(size_t i)
|
||||
lexerState->disableInterpolation = true;
|
||||
|
||||
bool multiline = false;
|
||||
char const *str;
|
||||
|
||||
// We reach this function after reading a single quote, but we also support triple quotes
|
||||
append_yylval_string('"');
|
||||
@@ -1733,9 +1733,8 @@ static size_t appendStringLiteral(size_t i)
|
||||
case '9':
|
||||
case '<':
|
||||
shiftChar();
|
||||
char const *str = readMacroArg(c);
|
||||
|
||||
if (str)
|
||||
str = readMacroArg(c);
|
||||
if (str && str[0])
|
||||
i = appendEscapedSubstring(str, i);
|
||||
continue; // Do not copy an additional character
|
||||
|
||||
@@ -1761,10 +1760,9 @@ static size_t appendStringLiteral(size_t i)
|
||||
// We'll be exiting the string scope, so re-enable expansions
|
||||
// (Not interpolations, since they're handled by the function itself...)
|
||||
lexerState->disableMacroArgs = false;
|
||||
char const *ptr = readInterpolation(0);
|
||||
|
||||
if (ptr && ptr[0])
|
||||
i = appendEscapedSubstring(ptr, i);
|
||||
str = readInterpolation(0);
|
||||
if (str && str[0])
|
||||
i = appendEscapedSubstring(str, i);
|
||||
lexerState->disableMacroArgs = true;
|
||||
continue; // Do not copy an additional character
|
||||
|
||||
|
||||
110
src/asm/symbol.c
110
src/asm/symbol.c
@@ -179,15 +179,15 @@ static void updateSymbolFilename(struct Symbol *sym)
|
||||
/*
|
||||
* Create a new symbol by name
|
||||
*/
|
||||
static struct Symbol *createsymbol(char const *s)
|
||||
static struct Symbol *createsymbol(char const *symName)
|
||||
{
|
||||
struct Symbol *symbol = malloc(sizeof(*symbol));
|
||||
|
||||
if (!symbol)
|
||||
fatalerror("Failed to create symbol '%s': %s\n", s, strerror(errno));
|
||||
fatalerror("Failed to create symbol '%s': %s\n", symName, strerror(errno));
|
||||
|
||||
if (snprintf(symbol->name, MAXSYMLEN + 1, "%s", s) > MAXSYMLEN)
|
||||
warning(WARNING_LONG_STR, "Symbol name is too long: '%s'\n", s);
|
||||
if (snprintf(symbol->name, MAXSYMLEN + 1, "%s", symName) > MAXSYMLEN)
|
||||
warning(WARNING_LONG_STR, "Symbol name is too long: '%s'\n", symName);
|
||||
|
||||
symbol->isExported = false;
|
||||
symbol->isBuiltin = false;
|
||||
@@ -228,37 +228,37 @@ static void assignStringSymbol(struct Symbol *sym, char const *value)
|
||||
sym->macroSize = strlen(string);
|
||||
}
|
||||
|
||||
struct Symbol *sym_FindExactSymbol(char const *name)
|
||||
struct Symbol *sym_FindExactSymbol(char const *symName)
|
||||
{
|
||||
return hash_GetElement(symbols, name);
|
||||
return hash_GetElement(symbols, symName);
|
||||
}
|
||||
|
||||
struct Symbol *sym_FindUnscopedSymbol(char const *name)
|
||||
struct Symbol *sym_FindUnscopedSymbol(char const *symName)
|
||||
{
|
||||
if (strchr(name, '.')) {
|
||||
error("Expected non-scoped symbol name, not \"%s\"\n", name);
|
||||
if (strchr(symName, '.')) {
|
||||
error("Expected non-scoped symbol name, not \"%s\"\n", symName);
|
||||
return NULL;
|
||||
}
|
||||
return sym_FindExactSymbol(name);
|
||||
return sym_FindExactSymbol(symName);
|
||||
}
|
||||
|
||||
struct Symbol *sym_FindScopedSymbol(char const *name)
|
||||
struct Symbol *sym_FindScopedSymbol(char const *symName)
|
||||
{
|
||||
char const *dotPtr = strchr(name, '.');
|
||||
char const *dotPtr = strchr(symName, '.');
|
||||
|
||||
if (dotPtr) {
|
||||
if (strchr(dotPtr + 1, '.'))
|
||||
fatalerror("'%s' is a nonsensical reference to a nested local symbol\n",
|
||||
name);
|
||||
symName);
|
||||
/* If auto-scoped local label, expand the name */
|
||||
if (dotPtr == name) { /* Meaning, the name begins with the dot */
|
||||
if (dotPtr == symName) { /* Meaning, the name begins with the dot */
|
||||
char fullname[MAXSYMLEN + 1];
|
||||
|
||||
fullSymbolName(fullname, sizeof(fullname), name, labelScope);
|
||||
fullSymbolName(fullname, sizeof(fullname), symName, labelScope);
|
||||
return sym_FindExactSymbol(fullname);
|
||||
}
|
||||
}
|
||||
return sym_FindExactSymbol(name);
|
||||
return sym_FindExactSymbol(symName);
|
||||
}
|
||||
|
||||
struct Symbol const *sym_GetPC(void)
|
||||
@@ -287,7 +287,7 @@ void sym_Purge(char const *symName)
|
||||
} else {
|
||||
/* Do not keep a reference to the label's name after purging it */
|
||||
if (symbol->name == labelScope)
|
||||
labelScope = NULL;
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
|
||||
/*
|
||||
* FIXME: this leaks symbol->macro for SYM_EQUS and SYM_MACRO, but this can't
|
||||
@@ -331,12 +331,12 @@ uint32_t sym_GetConstantSymValue(struct Symbol const *sym)
|
||||
/*
|
||||
* Return a constant symbol's value
|
||||
*/
|
||||
uint32_t sym_GetConstantValue(char const *s)
|
||||
uint32_t sym_GetConstantValue(char const *symName)
|
||||
{
|
||||
struct Symbol const *sym = sym_FindScopedSymbol(s);
|
||||
struct Symbol const *sym = sym_FindScopedSymbol(symName);
|
||||
|
||||
if (sym == NULL)
|
||||
error("'%s' not defined\n", s);
|
||||
error("'%s' not defined\n", symName);
|
||||
else
|
||||
return sym_GetConstantSymValue(sym);
|
||||
|
||||
@@ -357,23 +357,23 @@ void sym_SetCurrentSymbolScope(char const *newScope)
|
||||
* Create a symbol that will be non-relocatable and ensure that it
|
||||
* hasn't already been defined or referenced in a context that would
|
||||
* require that it be relocatable
|
||||
* @param symbolName The name of the symbol to create
|
||||
* @param symName The name of the symbol to create
|
||||
* @param numeric If false, the symbol may not have been referenced earlier
|
||||
*/
|
||||
static struct Symbol *createNonrelocSymbol(char const *symbolName, bool numeric)
|
||||
static struct Symbol *createNonrelocSymbol(char const *symName, bool numeric)
|
||||
{
|
||||
struct Symbol *symbol = sym_FindExactSymbol(symbolName);
|
||||
struct Symbol *symbol = sym_FindExactSymbol(symName);
|
||||
|
||||
if (!symbol) {
|
||||
symbol = createsymbol(symbolName);
|
||||
symbol = createsymbol(symName);
|
||||
} else if (sym_IsDefined(symbol)) {
|
||||
error("'%s' already defined at ", symbolName);
|
||||
error("'%s' already defined at ", symName);
|
||||
dumpFilename(symbol);
|
||||
putc('\n', stderr);
|
||||
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
||||
} else if (!numeric) {
|
||||
// The symbol has already been referenced, but it's not allowed
|
||||
error("'%s' already referenced at ", symbolName);
|
||||
error("'%s' already referenced at ", symName);
|
||||
dumpFilename(symbol);
|
||||
putc('\n', stderr);
|
||||
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
||||
@@ -448,7 +448,7 @@ struct Symbol *sym_RedefString(char const *symName, char const *value)
|
||||
}
|
||||
|
||||
/*
|
||||
* Alter a SET symbols value
|
||||
* Alter a SET symbol's value
|
||||
*/
|
||||
struct Symbol *sym_AddSet(char const *symName, int32_t value)
|
||||
{
|
||||
@@ -474,18 +474,18 @@ struct Symbol *sym_AddSet(char const *symName, int32_t value)
|
||||
|
||||
/*
|
||||
* Add a label (aka "relocatable symbol")
|
||||
* @param name The label's full name (so `.name` is invalid)
|
||||
* @param symName The label's full name (so `.name` is invalid)
|
||||
* @return The created symbol
|
||||
*/
|
||||
static struct Symbol *addLabel(char const *name)
|
||||
static struct Symbol *addLabel(char const *symName)
|
||||
{
|
||||
assert(name[0] != '.'); /* The symbol name must have been expanded prior */
|
||||
struct Symbol *sym = sym_FindExactSymbol(name);
|
||||
assert(symName[0] != '.'); /* The symbol name must have been expanded prior */
|
||||
struct Symbol *sym = sym_FindExactSymbol(symName);
|
||||
|
||||
if (!sym) {
|
||||
sym = createsymbol(name);
|
||||
sym = createsymbol(symName);
|
||||
} else if (sym_IsDefined(sym)) {
|
||||
error("'%s' already defined at ", name);
|
||||
error("'%s' already defined at ", symName);
|
||||
dumpFilename(sym);
|
||||
putc('\n', stderr);
|
||||
return NULL;
|
||||
@@ -500,62 +500,62 @@ static struct Symbol *addLabel(char const *name)
|
||||
sym->section = sect_GetSymbolSection();
|
||||
|
||||
if (sym && !sym->section)
|
||||
error("Label \"%s\" created outside of a SECTION\n", name);
|
||||
error("Label \"%s\" created outside of a SECTION\n", symName);
|
||||
return sym;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a local (.name or Parent.name) relocatable symbol
|
||||
*/
|
||||
struct Symbol *sym_AddLocalLabel(char const *name)
|
||||
struct Symbol *sym_AddLocalLabel(char const *symName)
|
||||
{
|
||||
if (!labelScope) {
|
||||
error("Local label '%s' in main scope\n", name);
|
||||
error("Local label '%s' in main scope\n", symName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char fullname[MAXSYMLEN + 1];
|
||||
|
||||
if (name[0] == '.') {
|
||||
if (symName[0] == '.') {
|
||||
/* If symbol is of the form `.name`, expand to the full `Parent.name` name */
|
||||
fullSymbolName(fullname, sizeof(fullname), name, labelScope);
|
||||
name = fullname; /* Use the expanded name instead */
|
||||
fullSymbolName(fullname, sizeof(fullname), symName, labelScope);
|
||||
symName = fullname; /* Use the expanded name instead */
|
||||
} else {
|
||||
size_t i = 0;
|
||||
|
||||
/* Otherwise, check that `Parent` is in fact the current scope */
|
||||
while (labelScope[i] && name[i] == labelScope[i])
|
||||
while (labelScope[i] && symName[i] == labelScope[i])
|
||||
i++;
|
||||
/* Assuming no dots in `labelScope` */
|
||||
assert(strchr(&name[i], '.')); /* There should be at least one dot, though */
|
||||
size_t parentLen = i + (strchr(&name[i], '.') - name);
|
||||
assert(strchr(&symName[i], '.')); /* There should be at least one dot, though */
|
||||
size_t parentLen = i + (strchr(&symName[i], '.') - symName);
|
||||
|
||||
/*
|
||||
* Check that `labelScope[i]` ended the check, guaranteeing that `name` is at least
|
||||
* as long, and then that this was the entirety of the `Parent` part of `name`.
|
||||
* Check that `labelScope[i]` ended the check, guaranteeing that `symName` is at
|
||||
* least as long, and then that this was the entire `Parent` part of `symName`.
|
||||
*/
|
||||
if (labelScope[i] != '\0' || name[i] != '.') {
|
||||
if (labelScope[i] != '\0' || symName[i] != '.') {
|
||||
assert(parentLen <= INT_MAX);
|
||||
error("Not currently in the scope of '%.*s'\n", (int)parentLen, name);
|
||||
error("Not currently in the scope of '%.*s'\n", (int)parentLen, symName);
|
||||
}
|
||||
if (strchr(&name[parentLen + 1], '.')) /* There will at least be a terminator */
|
||||
if (strchr(&symName[parentLen + 1], '.')) /* There will at least be a terminator */
|
||||
fatalerror("'%s' is a nonsensical reference to a nested local label\n",
|
||||
name);
|
||||
symName);
|
||||
}
|
||||
|
||||
return addLabel(name);
|
||||
return addLabel(symName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a relocatable symbol
|
||||
*/
|
||||
struct Symbol *sym_AddLabel(char const *name)
|
||||
struct Symbol *sym_AddLabel(char const *symName)
|
||||
{
|
||||
struct Symbol *sym = addLabel(name);
|
||||
struct Symbol *sym = addLabel(symName);
|
||||
|
||||
/* Set the symbol as the new scope */
|
||||
if (sym)
|
||||
labelScope = sym->name;
|
||||
sym_SetCurrentSymbolScope(sym->name);
|
||||
return sym;
|
||||
}
|
||||
|
||||
@@ -677,9 +677,9 @@ void sym_SetExportAll(bool set)
|
||||
exportall = set;
|
||||
}
|
||||
|
||||
static struct Symbol *createBuiltinSymbol(char const *name)
|
||||
static struct Symbol *createBuiltinSymbol(char const *symName)
|
||||
{
|
||||
struct Symbol *sym = createsymbol(name);
|
||||
struct Symbol *sym = createsymbol(symName);
|
||||
|
||||
sym->isBuiltin = true;
|
||||
sym->hasCallback = true;
|
||||
@@ -755,7 +755,7 @@ void sym_Init(time_t now)
|
||||
#undef addNumber
|
||||
#undef addString
|
||||
|
||||
labelScope = NULL;
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
anonLabelID = 0;
|
||||
|
||||
/* _PI is deprecated */
|
||||
|
||||
Reference in New Issue
Block a user