mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Use std::vector for fstack REPT nodes
This commit is contained in:
@@ -6,13 +6,14 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include "helpers.hpp"
|
||||
#include "linkdefs.hpp"
|
||||
|
||||
// Variables related to CLI options
|
||||
extern bool isDmgMode;
|
||||
extern char *linkerScriptName;
|
||||
extern char *linkerScriptName;
|
||||
extern char const *mapFileName;
|
||||
extern bool noSymInMap;
|
||||
extern char const *symFileName;
|
||||
@@ -27,12 +28,6 @@ extern bool beVerbose;
|
||||
extern bool isWRA0Mode;
|
||||
extern bool disablePadding;
|
||||
|
||||
// Only used in an anonymous union by `struct FileStackNode`
|
||||
struct reptNodeData {
|
||||
uint32_t depth;
|
||||
uint32_t *iters;
|
||||
};
|
||||
|
||||
struct FileStackNode {
|
||||
struct FileStackNode *parent;
|
||||
// Line at which the parent context was exited; meaningless for the root level
|
||||
@@ -41,7 +36,7 @@ struct FileStackNode {
|
||||
enum FileStackNodeType type;
|
||||
union {
|
||||
char *name; // NODE_FILE, NODE_MACRO
|
||||
struct reptNodeData rept; // NODE_REPT
|
||||
std::vector<uint32_t> *iters; // NODE_REPT
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ char const *dumpFileStack(struct FileStackNode const *node)
|
||||
lastName = node->name;
|
||||
fprintf(stderr, "(%" PRIu32 ") -> %s", node->lineNo, lastName);
|
||||
if (node->type == NODE_REPT) {
|
||||
for (uint32_t i = 0; i < node->rept.depth; i++)
|
||||
fprintf(stderr, "::REPT~%" PRIu32, node->rept.iters[i]);
|
||||
for (uint32_t iter : *node->iters)
|
||||
fprintf(stderr, "::REPT~%" PRIu32, iter);
|
||||
}
|
||||
} else {
|
||||
assert(node->type != NODE_REPT);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
|
||||
#include "link/assign.hpp"
|
||||
#include "link/main.hpp"
|
||||
@@ -181,16 +182,17 @@ static void readFileStackNode(FILE *file, struct FileStackNode fileNodes[], uint
|
||||
"%s: Cannot read node #%" PRIu32 "'s file name: %s", fileName, i);
|
||||
break;
|
||||
|
||||
uint32_t depth;
|
||||
case NODE_REPT:
|
||||
tryReadlong(fileNodes[i].rept.depth, file,
|
||||
tryReadlong(depth, file,
|
||||
"%s: Cannot read node #%" PRIu32 "'s rept depth: %s", fileName, i);
|
||||
fileNodes[i].rept.iters =
|
||||
(uint32_t *)malloc(sizeof(*fileNodes[i].rept.iters) * fileNodes[i].rept.depth);
|
||||
if (!fileNodes[i].rept.iters)
|
||||
fileNodes[i].iters = new(std::nothrow) std::vector<uint32_t>();
|
||||
if (!fileNodes[i].iters)
|
||||
fatal(NULL, 0, "%s: Failed to alloc node #%" PRIu32 "'s iters: %s",
|
||||
fileName, i, strerror(errno));
|
||||
for (uint32_t k = 0; k < fileNodes[i].rept.depth; k++)
|
||||
tryReadlong(fileNodes[i].rept.iters[k], file,
|
||||
fileNodes[i].iters->resize(depth);
|
||||
for (uint32_t k = 0; k < depth; k++)
|
||||
tryReadlong((*fileNodes[i].iters)[k], file,
|
||||
"%s: Cannot read node #%" PRIu32 "'s iter #%" PRIu32 ": %s",
|
||||
fileName, i, k);
|
||||
if (!fileNodes[i].parent)
|
||||
@@ -651,7 +653,7 @@ static void freeNode(struct FileStackNode *node)
|
||||
{
|
||||
if (node) {
|
||||
if (node->type == NODE_REPT)
|
||||
free(node->rept.iters);
|
||||
delete node->iters;
|
||||
else
|
||||
free(node->name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user