mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 18:52:07 +00:00
Replace NULL with nullptr (#1321)
This commit is contained in:
@@ -40,9 +40,9 @@ std::stack<Charmap *> charmapStack;
|
||||
|
||||
void charmap_New(char const *name, char const *baseName)
|
||||
{
|
||||
Charmap *base = NULL;
|
||||
Charmap *base = nullptr;
|
||||
|
||||
if (baseName != NULL) {
|
||||
if (baseName != nullptr) {
|
||||
auto search = charmaps.find(baseName);
|
||||
|
||||
if (search == charmaps.end())
|
||||
|
||||
@@ -104,7 +104,7 @@ void fstk_DumpCurrent(void)
|
||||
FileStackNode *fstk_GetFileStack(void)
|
||||
{
|
||||
if (contextStack.empty())
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
FileStackNode *topNode = contextStack.top().fileInfo;
|
||||
|
||||
@@ -185,7 +185,7 @@ std::string *fstk_FindFile(char const *path)
|
||||
errno = ENOENT;
|
||||
if (generatedMissingIncludes)
|
||||
printDep(path);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool yywrap(void)
|
||||
@@ -255,7 +255,7 @@ bool yywrap(void)
|
||||
|
||||
// Make sure not to switch the lexer state before calling this, so the saved line no is correct.
|
||||
// BE CAREFUL! This modifies the file stack directly, you should have set up the file info first.
|
||||
// Callers should set `contextStack.top().lexerState` after this so it is not NULL.
|
||||
// Callers should set `contextStack.top().lexerState` after this so it is not `nullptr`.
|
||||
static Context &newContext(FileStackNode *fileInfo)
|
||||
{
|
||||
if (contextStack.size() > maxRecursionDepth)
|
||||
@@ -518,7 +518,7 @@ void fstk_Init(char const *mainPath, size_t maxDepth)
|
||||
fileInfo->type = NODE_FILE;
|
||||
fileInfo->data = lexer_GetFileName();
|
||||
// lineNo and nbReptIters are unused on the top-level context
|
||||
fileInfo->parent = NULL;
|
||||
fileInfo->parent = nullptr;
|
||||
fileInfo->lineNo = 0; // This still gets written to the object file, so init it
|
||||
fileInfo->referenced = false;
|
||||
|
||||
|
||||
@@ -42,16 +42,16 @@
|
||||
# include <winbase.h> // CreateFileMappingA
|
||||
# include <memoryapi.h> // MapViewOfFile
|
||||
# include <handleapi.h> // CloseHandle
|
||||
# define MAP_FAILED NULL
|
||||
# define MAP_FAILED nullptr
|
||||
# define mapFile(ptr, fd, path, size) do { \
|
||||
(ptr) = MAP_FAILED; \
|
||||
HANDLE file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
|
||||
FILE_FLAG_POSIX_SEMANTICS | FILE_FLAG_RANDOM_ACCESS, NULL); \
|
||||
HANDLE file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, \
|
||||
FILE_FLAG_POSIX_SEMANTICS | FILE_FLAG_RANDOM_ACCESS, nullptr); \
|
||||
HANDLE mappingObj; \
|
||||
\
|
||||
if (file == INVALID_HANDLE_VALUE) \
|
||||
break; \
|
||||
mappingObj = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL); \
|
||||
mappingObj = CreateFileMappingA(file, nullptr, PAGE_READONLY, 0, 0, nullptr); \
|
||||
if (mappingObj != INVALID_HANDLE_VALUE) \
|
||||
(ptr) = MapViewOfFile(mappingObj, FILE_MAP_READ, 0, 0, 0); \
|
||||
CloseHandle(mappingObj); \
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
# include <sys/mman.h>
|
||||
# define mapFile(ptr, fd, path, size) do { \
|
||||
(ptr) = mmap(NULL, (size), PROT_READ, MAP_PRIVATE, (fd), 0); \
|
||||
(ptr) = mmap(nullptr, (size), PROT_READ, MAP_PRIVATE, (fd), 0); \
|
||||
\
|
||||
if ((ptr) == MAP_FAILED && errno == ENOTSUP) { \
|
||||
/*
|
||||
@@ -73,7 +73,7 @@
|
||||
*/ \
|
||||
if (verbose) \
|
||||
printf("mmap(%s, MAP_PRIVATE) failed, retrying with MAP_SHARED\n", path); \
|
||||
(ptr) = mmap(NULL, (size), PROT_READ, MAP_SHARED, (fd), 0); \
|
||||
(ptr) = mmap(nullptr, (size), PROT_READ, MAP_SHARED, (fd), 0); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif // !( defined(_MSC_VER) || defined(__MINGW32__) )
|
||||
@@ -298,8 +298,8 @@ static bool isWhitespace(int c)
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
||||
LexerState *lexerState = NULL;
|
||||
LexerState *lexerStateEOL = NULL;
|
||||
LexerState *lexerState = nullptr;
|
||||
LexerState *lexerStateEOL = nullptr;
|
||||
|
||||
static void initState(LexerState &state)
|
||||
{
|
||||
@@ -310,7 +310,7 @@ static void initState(LexerState &state)
|
||||
state.ifStack.clear();
|
||||
|
||||
state.capturing = false;
|
||||
state.captureBuf = NULL;
|
||||
state.captureBuf = nullptr;
|
||||
|
||||
state.disableMacroArgs = false;
|
||||
state.disableInterpolation = false;
|
||||
@@ -509,7 +509,7 @@ static void beginExpansion(char const *str, bool owned, char const *name)
|
||||
lexer_CheckRecursionDepth();
|
||||
|
||||
lexerState->expansions.push_front({
|
||||
.name = name ? strdup(name) : NULL,
|
||||
.name = name ? strdup(name) : nullptr,
|
||||
.contents = { .unowned = str },
|
||||
.size = size,
|
||||
.offset = 0,
|
||||
@@ -610,7 +610,7 @@ static uint32_t readBracketedMacroArgNum(void)
|
||||
|
||||
static char const *readMacroArg(char name)
|
||||
{
|
||||
char const *str = NULL;
|
||||
char const *str = nullptr;
|
||||
|
||||
if (name == '@') {
|
||||
str = macro_GetUniqueIDStr();
|
||||
@@ -620,14 +620,14 @@ static char const *readMacroArg(char name)
|
||||
uint32_t num = readBracketedMacroArgNum();
|
||||
|
||||
if (num == 0)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
str = macro_GetArg(num);
|
||||
if (!str)
|
||||
error("Macro argument '\\<%" PRIu32 ">' not defined\n", num);
|
||||
return str;
|
||||
} else if (name == '0') {
|
||||
error("Invalid macro argument '\\0'\n");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
} else {
|
||||
assert(name > '0' && name <= '9');
|
||||
str = macro_GetArg(name - '0');
|
||||
@@ -735,7 +735,7 @@ static int peek(void)
|
||||
if (!str || !str[0])
|
||||
return peek();
|
||||
|
||||
beginExpansion(str, c == '#', NULL);
|
||||
beginExpansion(str, c == '#', nullptr);
|
||||
|
||||
// Assuming macro args can't be recursive (I'll be damned if a way
|
||||
// is found...), then we mark the entire macro arg as scanned.
|
||||
@@ -822,7 +822,7 @@ static void handleCRLF(int c)
|
||||
|
||||
char const *lexer_GetFileName(void)
|
||||
{
|
||||
return lexerState ? lexerState->path : NULL;
|
||||
return lexerState ? lexerState->path : nullptr;
|
||||
}
|
||||
|
||||
uint32_t lexer_GetLineNo(void)
|
||||
@@ -1260,7 +1260,7 @@ static char const *readInterpolation(size_t depth)
|
||||
} else {
|
||||
error("Only numerical and string symbols can be interpolated\n");
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#define append_yylval_string(c) do { \
|
||||
@@ -2259,7 +2259,7 @@ int yylex(void)
|
||||
{
|
||||
if (lexerState->atLineStart && lexerStateEOL) {
|
||||
lexer_SetState(lexerStateEOL);
|
||||
lexerStateEOL = NULL;
|
||||
lexerStateEOL = nullptr;
|
||||
}
|
||||
// `lexer_SetState` updates `lexerState`, so check for EOF after it
|
||||
if (lexerState->lastToken == T_EOB && yywrap())
|
||||
@@ -2300,22 +2300,22 @@ static void startCapture(CaptureBody *capture)
|
||||
capture->body = &lexerState->mmap.ptr[lexerState->mmap.offset];
|
||||
} else {
|
||||
lexerState->captureCapacity = 128; // The initial size will be twice that
|
||||
assert(lexerState->captureBuf == NULL);
|
||||
assert(lexerState->captureBuf == nullptr);
|
||||
reallocCaptureBuf();
|
||||
capture->body = NULL; // Indicate to retrieve the capture buffer when done capturing
|
||||
capture->body = nullptr; // Indicate to retrieve the capture buffer when done capturing
|
||||
}
|
||||
}
|
||||
|
||||
static void endCapture(CaptureBody *capture)
|
||||
{
|
||||
// This being NULL means we're capturing from the capture buf, which is `realloc`'d during
|
||||
// the whole capture process, and so MUST be retrieved at the end
|
||||
// This being `nullptr` means we're capturing from the capture buf, which is `realloc`ed
|
||||
// during the whole capture process, and so MUST be retrieved at the end
|
||||
if (!capture->body)
|
||||
capture->body = lexerState->captureBuf;
|
||||
capture->size = lexerState->captureSize;
|
||||
|
||||
lexerState->capturing = false;
|
||||
lexerState->captureBuf = NULL;
|
||||
lexerState->captureBuf = nullptr;
|
||||
lexerState->disableMacroArgs = false;
|
||||
lexerState->disableInterpolation = false;
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ struct MacroArgs {
|
||||
std::vector<char *> args;
|
||||
};
|
||||
|
||||
static MacroArgs *macroArgs = NULL;
|
||||
static MacroArgs *macroArgs = nullptr;
|
||||
static uint32_t uniqueID = 0;
|
||||
static uint32_t maxUniqueID = 0;
|
||||
// The initialization is somewhat harmful, since it is never used, but it
|
||||
// guarantees the size of the buffer will be correct. I was unable to find a
|
||||
// better solution, but if you have one, please feel free!
|
||||
static char uniqueIDBuf[] = "_u4294967295"; // UINT32_MAX
|
||||
static char *uniqueIDPtr = NULL;
|
||||
static char *uniqueIDPtr = nullptr;
|
||||
|
||||
MacroArgs *macro_GetCurrentArgs(void)
|
||||
{
|
||||
@@ -66,17 +66,17 @@ void macro_FreeArgs(MacroArgs *args)
|
||||
char const *macro_GetArg(uint32_t i)
|
||||
{
|
||||
if (!macroArgs)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
uint32_t realIndex = i + macroArgs->shift - 1;
|
||||
|
||||
return realIndex >= macroArgs->args.size() ? NULL : macroArgs->args[realIndex];
|
||||
return realIndex >= macroArgs->args.size() ? nullptr : macroArgs->args[realIndex];
|
||||
}
|
||||
|
||||
char const *macro_GetAllArgs(void)
|
||||
{
|
||||
if (!macroArgs)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
size_t nbArgs = macroArgs->args.size();
|
||||
|
||||
@@ -128,7 +128,7 @@ void macro_SetUniqueID(uint32_t id)
|
||||
{
|
||||
uniqueID = id;
|
||||
if (id == 0 || id == (uint32_t)-1) {
|
||||
uniqueIDPtr = NULL;
|
||||
uniqueIDPtr = nullptr;
|
||||
} else {
|
||||
// The buffer is guaranteed to be the correct size
|
||||
// This is a valid label fragment, but not a valid numeric
|
||||
|
||||
@@ -51,7 +51,7 @@ char const *__asan_default_options(void) { return "detect_leaks=0"; }
|
||||
// Unfortunately, macOS still ships 2.3, which is from 2008...
|
||||
int yyparse(void);
|
||||
|
||||
FILE *dependfile = NULL;
|
||||
FILE *dependfile = nullptr;
|
||||
bool generatedMissingIncludes = false;
|
||||
bool failedOnMissingInclude = false;
|
||||
bool generatePhonyDeps = false;
|
||||
@@ -98,31 +98,31 @@ static int depType; // Variants of `-M`
|
||||
// This is because long opt matching, even to a single char, is prioritized
|
||||
// over short opt matching
|
||||
static option const longopts[] = {
|
||||
{ "binary-digits", required_argument, NULL, 'b' },
|
||||
{ "define", required_argument, NULL, 'D' },
|
||||
{ "export-all", no_argument, NULL, 'E' },
|
||||
{ "gfx-chars", required_argument, NULL, 'g' },
|
||||
{ "nop-after-halt", no_argument, NULL, 'H' },
|
||||
{ "halt-without-nop", no_argument, NULL, 'h' },
|
||||
{ "include", required_argument, NULL, 'I' },
|
||||
{ "preserve-ld", no_argument, NULL, 'L' },
|
||||
{ "auto-ldh", no_argument, NULL, 'l' },
|
||||
{ "dependfile", required_argument, NULL, 'M' },
|
||||
{ "binary-digits", required_argument, nullptr, 'b' },
|
||||
{ "define", required_argument, nullptr, 'D' },
|
||||
{ "export-all", no_argument, nullptr, 'E' },
|
||||
{ "gfx-chars", required_argument, nullptr, 'g' },
|
||||
{ "nop-after-halt", no_argument, nullptr, 'H' },
|
||||
{ "halt-without-nop", no_argument, nullptr, 'h' },
|
||||
{ "include", required_argument, nullptr, 'I' },
|
||||
{ "preserve-ld", no_argument, nullptr, 'L' },
|
||||
{ "auto-ldh", no_argument, nullptr, 'l' },
|
||||
{ "dependfile", required_argument, nullptr, 'M' },
|
||||
{ "MG", no_argument, &depType, 'G' },
|
||||
{ "MP", no_argument, &depType, 'P' },
|
||||
{ "MT", required_argument, &depType, 'T' },
|
||||
{ "warning", required_argument, NULL, 'W' },
|
||||
{ "warning", required_argument, nullptr, 'W' },
|
||||
{ "MQ", required_argument, &depType, 'Q' },
|
||||
{ "output", required_argument, NULL, 'o' },
|
||||
{ "preinclude", required_argument, NULL, 'P' },
|
||||
{ "pad-value", required_argument, NULL, 'p' },
|
||||
{ "q-precision", required_argument, NULL, 'Q' },
|
||||
{ "recursion-depth", required_argument, NULL, 'r' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "warning", required_argument, NULL, 'W' },
|
||||
{ "max-errors", required_argument, NULL, 'X' },
|
||||
{ NULL, no_argument, NULL, 0 }
|
||||
{ "output", required_argument, nullptr, 'o' },
|
||||
{ "preinclude", required_argument, nullptr, 'P' },
|
||||
{ "pad-value", required_argument, nullptr, 'p' },
|
||||
{ "q-precision", required_argument, nullptr, 'Q' },
|
||||
{ "recursion-depth", required_argument, nullptr, 'r' },
|
||||
{ "version", no_argument, nullptr, 'V' },
|
||||
{ "verbose", no_argument, nullptr, 'v' },
|
||||
{ "warning", required_argument, nullptr, 'W' },
|
||||
{ "max-errors", required_argument, nullptr, 'X' },
|
||||
{ nullptr, no_argument, nullptr, 0 }
|
||||
};
|
||||
|
||||
static void printUsage(void)
|
||||
@@ -146,13 +146,13 @@ static void printUsage(void)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
time_t now = time(nullptr);
|
||||
char const *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH");
|
||||
|
||||
// Support SOURCE_DATE_EPOCH for reproducible builds
|
||||
// https://reproducible-builds.org/docs/source-date-epoch/
|
||||
if (sourceDateEpoch)
|
||||
now = (time_t)strtoul(sourceDateEpoch, NULL, 0);
|
||||
now = (time_t)strtoul(sourceDateEpoch, nullptr, 0);
|
||||
|
||||
// Perform some init for below
|
||||
sym_Init(now);
|
||||
@@ -171,14 +171,14 @@ int main(int argc, char *argv[])
|
||||
warnings = true;
|
||||
sym_SetExportAll(false);
|
||||
uint32_t maxDepth = DEFAULT_MAX_DEPTH;
|
||||
char const *dependFileName = NULL;
|
||||
char const *dependFileName = nullptr;
|
||||
std::string newTarget;
|
||||
|
||||
// Maximum of 100 errors only applies if rgbasm is printing errors to a terminal.
|
||||
if (isatty(STDERR_FILENO))
|
||||
maxErrors = 100;
|
||||
|
||||
for (int ch; (ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1;) {
|
||||
for (int ch; (ch = musl_getopt_long_only(argc, argv, optstring, longopts, nullptr)) != -1;) {
|
||||
switch (ch) {
|
||||
char *endptr;
|
||||
|
||||
@@ -258,7 +258,7 @@ int main(int argc, char *argv[])
|
||||
dependfile = fopen(musl_optarg, "w");
|
||||
dependFileName = musl_optarg;
|
||||
}
|
||||
if (dependfile == NULL)
|
||||
if (dependfile == nullptr)
|
||||
err("Failed to open dependfile \"%s\"", dependFileName);
|
||||
break;
|
||||
|
||||
@@ -392,7 +392,7 @@ int main(int argc, char *argv[])
|
||||
fprintf(dependfile, "%s: %s\n", targetFileName.c_str(), mainFileName);
|
||||
}
|
||||
|
||||
charmap_New(DEFAULT_CHARMAP_NAME, NULL);
|
||||
charmap_New(DEFAULT_CHARMAP_NAME, nullptr);
|
||||
|
||||
// Init lexer and file stack, providing file info
|
||||
fstk_Init(mainFileName, maxDepth);
|
||||
@@ -414,7 +414,7 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
|
||||
// If no path specified, don't write file
|
||||
if (objectName != NULL)
|
||||
if (objectName != nullptr)
|
||||
out_WriteObject();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ static void putlong(uint32_t i, FILE *f)
|
||||
putc(i >> 24, f);
|
||||
}
|
||||
|
||||
// Write a NULL-terminated string to a file
|
||||
// Write a NUL-terminated string to a file
|
||||
static void putstring(char const *s, FILE *f)
|
||||
{
|
||||
while (*s)
|
||||
|
||||
@@ -75,13 +75,13 @@ static const char *strrstr(char const *s1, char const *s2)
|
||||
size_t len2 = strlen(s2);
|
||||
|
||||
if (len2 > len1)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
for (char const *p = s1 + len1 - len2; p >= s1; p--)
|
||||
if (!strncmp(p, s2, len2))
|
||||
return p;
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void errorInvalidUTF8Byte(uint8_t byte, char const *functionName)
|
||||
@@ -172,7 +172,7 @@ static size_t charlenUTF8(char const *s)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len = 0; charmap_ConvertNext(&s, NULL); len++)
|
||||
for (len = 0; charmap_ConvertNext(&s, nullptr); len++)
|
||||
;
|
||||
|
||||
return len;
|
||||
@@ -184,11 +184,11 @@ static void charsubUTF8(char *dest, char const *src, uint32_t pos)
|
||||
|
||||
// Advance to starting position in source string.
|
||||
for (uint32_t curPos = 1; charLen && curPos < pos; curPos++)
|
||||
charLen = charmap_ConvertNext(&src, NULL);
|
||||
charLen = charmap_ConvertNext(&src, nullptr);
|
||||
|
||||
char const *start = src;
|
||||
|
||||
if (!charmap_ConvertNext(&src, NULL))
|
||||
if (!charmap_ConvertNext(&src, nullptr))
|
||||
warning(WARNING_BUILTIN_ARG,
|
||||
"CHARSUB: Position %" PRIu32 " is past the end of the string\n", pos);
|
||||
|
||||
@@ -922,7 +922,7 @@ assignment : T_LABEL T_POP_EQUAL const {
|
||||
sym_AddVar($1, $3);
|
||||
}
|
||||
| T_LABEL compoundeq const {
|
||||
const char *compoundEqOperator = NULL;
|
||||
const char *compoundEqOperator = nullptr;
|
||||
switch ($2) {
|
||||
case RPN_ADD: compoundEqOperator = "+="; break;
|
||||
case RPN_SUB: compoundEqOperator = "-="; break;
|
||||
@@ -1287,7 +1287,7 @@ charmap : T_POP_CHARMAP string T_COMMA const_8bit {
|
||||
}
|
||||
;
|
||||
|
||||
newcharmap : T_POP_NEWCHARMAP T_ID { charmap_New($2, NULL); }
|
||||
newcharmap : T_POP_NEWCHARMAP T_ID { charmap_New($2, nullptr); }
|
||||
| T_POP_NEWCHARMAP T_ID T_COMMA T_ID { charmap_New($2, $4); }
|
||||
;
|
||||
|
||||
@@ -1509,7 +1509,7 @@ relocexpr_no_str : scoped_anon_id { rpn_Symbol(&$$, $1); }
|
||||
| T_OP_DEF {
|
||||
lexer_ToggleStringExpansion(false);
|
||||
} T_LPAREN scoped_anon_id T_RPAREN {
|
||||
rpn_Number(&$$, sym_FindScopedValidSymbol($4) != NULL);
|
||||
rpn_Number(&$$, sym_FindScopedValidSymbol($4) != nullptr);
|
||||
|
||||
lexer_ToggleStringExpansion(true);
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ static uint8_t *reserveSpace(Expression *expr, uint32_t size)
|
||||
// Init a RPN expression
|
||||
static void rpn_Init(Expression *expr)
|
||||
{
|
||||
expr->reason = NULL;
|
||||
expr->reason = nullptr;
|
||||
expr->isKnown = true;
|
||||
expr->isSymbol = false;
|
||||
expr->rpn = NULL;
|
||||
expr->rpn = nullptr;
|
||||
expr->rpnPatchSize = 0;
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ void rpn_LOGNOT(Expression *expr, const Expression *src)
|
||||
Symbol const *rpn_SymbolOf(Expression const *expr)
|
||||
{
|
||||
if (!rpn_isSymbol(expr))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
return sym_FindScopedSymbol((char const *)&(*expr->rpn)[1]);
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ void rpn_BinaryOp(enum RPNCommand op, Expression *expr, const Expression *src1,
|
||||
uint8_t bytes[] = {RPN_CONST, (uint8_t)lval, (uint8_t)(lval >> 8),
|
||||
(uint8_t)(lval >> 16), (uint8_t)(lval >> 24)};
|
||||
expr->rpnPatchSize = sizeof(bytes);
|
||||
expr->rpn = NULL;
|
||||
expr->rpn = nullptr;
|
||||
memcpy(reserveSpace(expr, sizeof(bytes)), bytes, sizeof(bytes));
|
||||
|
||||
// Use the other expression's un-const reason
|
||||
@@ -542,7 +542,7 @@ void rpn_BinaryOp(enum RPNCommand op, Expression *expr, const Expression *src1,
|
||||
}
|
||||
|
||||
// Now, merge the right expression into the left one
|
||||
uint8_t const *ptr = NULL;
|
||||
uint8_t const *ptr = nullptr;
|
||||
uint32_t len = 0;
|
||||
uint32_t patchSize = 0;
|
||||
|
||||
@@ -563,11 +563,11 @@ void rpn_BinaryOp(enum RPNCommand op, Expression *expr, const Expression *src1,
|
||||
uint8_t *buf = reserveSpace(expr, len + 1);
|
||||
|
||||
if (ptr)
|
||||
// If there was none, `memcpy(buf, NULL, 0)` would be UB
|
||||
// If there was none, `memcpy(buf, nullptr, 0)` would be UB
|
||||
memcpy(buf, ptr, len);
|
||||
buf[len] = op;
|
||||
|
||||
delete src2->rpn; // If there was none, this is `delete NULL`
|
||||
delete src2->rpn; // If there was none, this is `delete nullptr`
|
||||
expr->rpnPatchSize += patchSize + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ std::stack<UnionStackEntry> currentUnionStack;
|
||||
std::deque<SectionStackEntry> sectionStack;
|
||||
std::deque<Section> sectionList;
|
||||
uint32_t curOffset; // Offset into the current section (see sect_GetSymbolOffset)
|
||||
Section *currentSection = NULL;
|
||||
static Section *currentLoadSection = NULL;
|
||||
char const *currentLoadScope = NULL;
|
||||
Section *currentSection = nullptr;
|
||||
static Section *currentLoadSection = nullptr;
|
||||
char const *currentLoadScope = nullptr;
|
||||
int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutputOffset)
|
||||
|
||||
// A quick check to see if we have an initialized section
|
||||
@@ -116,7 +116,7 @@ Section *sect_FindSectionByName(char const *name)
|
||||
if (strcmp(name, sect.name) == 0)
|
||||
return §
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#define mask(align) ((1U << (align)) - 1)
|
||||
@@ -271,7 +271,7 @@ static Section *createSection(char const *name, enum SectionType type, uint32_t
|
||||
Section § = sectionList.emplace_front();
|
||||
|
||||
sect.name = strdup(name);
|
||||
if (sect.name == NULL)
|
||||
if (sect.name == nullptr)
|
||||
fatalerror("Not enough memory for section name: %s\n", strerror(errno));
|
||||
|
||||
sect.type = type;
|
||||
@@ -372,7 +372,7 @@ static void changeSection(void)
|
||||
if (!currentUnionStack.empty())
|
||||
fatalerror("Cannot change the section within a UNION\n");
|
||||
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
sym_SetCurrentSymbolScope(nullptr);
|
||||
}
|
||||
|
||||
// Set the current section by name and type
|
||||
@@ -441,7 +441,7 @@ void sect_EndLoadSection(void)
|
||||
changeSection();
|
||||
curOffset += loadOffset;
|
||||
loadOffset = 0;
|
||||
currentLoadSection = NULL;
|
||||
currentLoadSection = nullptr;
|
||||
sym_SetCurrentSymbolScope(currentLoadScope);
|
||||
}
|
||||
|
||||
@@ -790,7 +790,7 @@ void sect_BinaryFile(char const *s, int32_t startPos)
|
||||
return;
|
||||
|
||||
std::string *fullPath = fstk_FindFile(s);
|
||||
FILE *f = fullPath ? fopen(fullPath->c_str(), "rb") : NULL;
|
||||
FILE *f = fullPath ? fopen(fullPath->c_str(), "rb") : nullptr;
|
||||
|
||||
delete fullPath;
|
||||
|
||||
@@ -861,7 +861,7 @@ void sect_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
|
||||
return;
|
||||
|
||||
std::string *fullPath = fstk_FindFile(s);
|
||||
FILE *f = fullPath ? fopen(fullPath->c_str(), "rb") : NULL;
|
||||
FILE *f = fullPath ? fopen(fullPath->c_str(), "rb") : nullptr;
|
||||
|
||||
delete fullPath;
|
||||
|
||||
@@ -932,9 +932,9 @@ void sect_PushSection(void)
|
||||
});
|
||||
|
||||
// Reset the section scope
|
||||
currentSection = NULL;
|
||||
currentLoadSection = NULL;
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
currentSection = nullptr;
|
||||
currentLoadSection = nullptr;
|
||||
sym_SetCurrentSymbolScope(nullptr);
|
||||
std::swap(currentUnionStack, sectionStack.front().unionStack);
|
||||
}
|
||||
|
||||
@@ -970,8 +970,8 @@ void sect_EndSection(void)
|
||||
fatalerror("Cannot end the section within a UNION\n");
|
||||
|
||||
// Reset the section scope
|
||||
currentSection = NULL;
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
currentSection = nullptr;
|
||||
sym_SetCurrentSymbolScope(nullptr);
|
||||
}
|
||||
|
||||
bool sect_IsSizeKnown(Section const NONNULL(sect))
|
||||
|
||||
@@ -91,8 +91,8 @@ static void dumpFilename(Symbol const *sym)
|
||||
// Set a symbol's definition filename and line
|
||||
static void setSymbolFilename(Symbol *sym)
|
||||
{
|
||||
sym->src = fstk_GetFileStack();
|
||||
sym->fileLine = sym->src ? lexer_GetLineNo() : 0; // This is (NULL, 1) for built-ins
|
||||
sym->src = fstk_GetFileStack(); // This is `nullptr` for built-ins
|
||||
sym->fileLine = sym->src ? lexer_GetLineNo() : 0; // This is 1 for built-ins
|
||||
}
|
||||
|
||||
// Update a symbol's definition filename and line
|
||||
@@ -118,7 +118,7 @@ static Symbol *createsymbol(char const *symName)
|
||||
sym.isExported = false;
|
||||
sym.isBuiltin = false;
|
||||
sym.hasCallback = false;
|
||||
sym.section = NULL;
|
||||
sym.section = nullptr;
|
||||
setSymbolFilename(&sym);
|
||||
sym.ID = -1;
|
||||
|
||||
@@ -153,7 +153,7 @@ static void assignStringSymbol(Symbol *sym, char const *value)
|
||||
Symbol *sym_FindExactSymbol(char const *symName)
|
||||
{
|
||||
auto search = symbols.find(symName);
|
||||
return search != symbols.end() ? &search->second : NULL;
|
||||
return search != symbols.end() ? &search->second : nullptr;
|
||||
}
|
||||
|
||||
Symbol *sym_FindScopedSymbol(char const *symName)
|
||||
@@ -179,11 +179,11 @@ Symbol *sym_FindScopedValidSymbol(char const *symName)
|
||||
|
||||
// `@` has no value outside a section
|
||||
if (sym == PCSymbol && !sect_GetSymbolSection()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
// `_NARG` has no value outside a macro
|
||||
if (sym == _NARGSymbol && !macro_GetCurrentArgs()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return sym;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ void sym_Purge(std::string const &symName)
|
||||
} else {
|
||||
// Do not keep a reference to the label's name after purging it
|
||||
if (sym->name == labelScope)
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
sym_SetCurrentSymbolScope(nullptr);
|
||||
|
||||
// FIXME: this leaks sym->equs.value for SYM_EQUS and sym->macro.value for SYM_MACRO,
|
||||
// but this can't free either of them because the expansion may be purging itself.
|
||||
@@ -287,13 +287,13 @@ static Symbol *createNonrelocSymbol(char const *symName, bool numeric)
|
||||
error("'%s' already defined at ", symName);
|
||||
dumpFilename(sym);
|
||||
putc('\n', stderr);
|
||||
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
||||
return nullptr; // 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 ", symName);
|
||||
dumpFilename(sym);
|
||||
putc('\n', stderr);
|
||||
return NULL; // Don't allow overriding the symbol, that'd be bad!
|
||||
return nullptr; // Don't allow overriding the symbol, that'd be bad!
|
||||
}
|
||||
|
||||
return sym;
|
||||
@@ -305,7 +305,7 @@ Symbol *sym_AddEqu(char const *symName, int32_t value)
|
||||
Symbol *sym = createNonrelocSymbol(symName, true);
|
||||
|
||||
if (!sym)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
sym->type = SYM_EQU;
|
||||
sym->value = value;
|
||||
@@ -324,10 +324,10 @@ Symbol *sym_RedefEqu(char const *symName, int32_t value)
|
||||
error("'%s' already defined as non-EQU at ", symName);
|
||||
dumpFilename(sym);
|
||||
putc('\n', stderr);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
} else if (sym->isBuiltin) {
|
||||
error("Built-in symbol '%s' cannot be redefined\n", symName);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
updateSymbolFilename(sym);
|
||||
@@ -354,7 +354,7 @@ Symbol *sym_AddString(char const *symName, char const *value)
|
||||
Symbol *sym = createNonrelocSymbol(symName, false);
|
||||
|
||||
if (!sym)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
assignStringSymbol(sym, value);
|
||||
return sym;
|
||||
@@ -374,10 +374,10 @@ Symbol *sym_RedefString(char const *symName, char const *value)
|
||||
error("'%s' already referenced at ", symName);
|
||||
dumpFilename(sym);
|
||||
putc('\n', stderr);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
} else if (sym->isBuiltin) {
|
||||
error("Built-in symbol '%s' cannot be redefined\n", symName);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
updateSymbolFilename(sym);
|
||||
@@ -427,7 +427,7 @@ static Symbol *addLabel(char const *symName)
|
||||
error("'%s' already defined at ", symName);
|
||||
dumpFilename(sym);
|
||||
putc('\n', stderr);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
} else {
|
||||
updateSymbolFilename(sym);
|
||||
}
|
||||
@@ -468,7 +468,7 @@ Symbol *sym_AddLocalLabel(char const *symName)
|
||||
if (localName == symName) {
|
||||
if (!labelScope) {
|
||||
error("Unqualified local label '%s' in main scope\n", symName);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
// Expand `symName` to the full `labelScope.symName` name
|
||||
fullSymbolName(fullName, sizeof(fullName), symName, labelScope);
|
||||
@@ -496,7 +496,7 @@ Symbol *sym_AddAnonLabel(void)
|
||||
{
|
||||
if (anonLabelID == UINT32_MAX) {
|
||||
error("Only %" PRIu32 " anonymous labels can be created!", anonLabelID);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
char name[MAXSYMLEN + 1];
|
||||
|
||||
@@ -551,7 +551,7 @@ Symbol *sym_AddMacro(char const *symName, int32_t defLineNo, char *body, size_t
|
||||
Symbol *sym = createNonrelocSymbol(symName, false);
|
||||
|
||||
if (!sym)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
sym->type = SYM_MACRO;
|
||||
sym->macro.size = size;
|
||||
@@ -599,7 +599,7 @@ static Symbol *createBuiltinSymbol(char const *symName)
|
||||
|
||||
sym->isBuiltin = true;
|
||||
sym->hasCallback = true;
|
||||
sym->src = NULL;
|
||||
sym->src = nullptr;
|
||||
sym->fileLine = 1; // This is 0 for CLI-defined symbols
|
||||
|
||||
return sym;
|
||||
@@ -671,6 +671,6 @@ void sym_Init(time_t now)
|
||||
#undef addString
|
||||
#undef addSym
|
||||
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
sym_SetCurrentSymbolScope(nullptr);
|
||||
anonLabelID = 0;
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ void error(char const *fmt, ...)
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
printDiag(fmt, args, "error", ":", NULL);
|
||||
printDiag(fmt, args, "error", ":", nullptr);
|
||||
va_end(args);
|
||||
|
||||
// This intentionally makes 0 act as "unlimited" (or at least "limited to sizeof(unsigned)")
|
||||
@@ -359,7 +359,7 @@ void error(char const *fmt, ...)
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
printDiag(fmt, args, "FATAL", ":", NULL);
|
||||
printDiag(fmt, args, "FATAL", ":", nullptr);
|
||||
va_end(args);
|
||||
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user