Use std::deque for assertions

This commit is contained in:
Rangi42
2024-02-21 10:51:24 -05:00
committed by Sylvie
parent 521ca1c34a
commit b87ee62e6c

View File

@@ -42,7 +42,6 @@ struct Assertion {
struct Patch *patch; struct Patch *patch;
struct Section *section; struct Section *section;
char *message; char *message;
struct Assertion *next;
}; };
const char *objectName; const char *objectName;
@@ -52,7 +51,7 @@ std::deque<struct Section *> sectionList;
// List of symbols to put in the object file // List of symbols to put in the object file
static std::vector<struct Symbol *> objectSymbols; static std::vector<struct Symbol *> objectSymbols;
static struct Assertion *assertions = NULL; static std::deque<struct Assertion *> assertions;
static struct FileStackNode *fileStackNodes = NULL; static struct FileStackNode *fileStackNodes = NULL;
@@ -68,19 +67,6 @@ static uint32_t countPatches(struct Section const *sect)
return r; return r;
} }
// Count the number of assertions used in this object
static uint32_t countAsserts(void)
{
struct Assertion *assert = assertions;
uint32_t count = 0;
while (assert) {
count++;
assert = assert->next;
}
return count;
}
// Write a long to a file (little-endian) // Write a long to a file (little-endian)
static void putlong(uint32_t i, FILE *f) static void putlong(uint32_t i, FILE *f)
{ {
@@ -413,8 +399,7 @@ bool out_CreateAssert(enum AssertionType type, struct Expression const *expr,
return false; return false;
} }
assertion->next = assertions; assertions.push_front(assertion);
assertions = assertion;
return true; return true;
} }
@@ -497,15 +482,11 @@ void out_WriteObject(void)
freesection(sect); freesection(sect);
} }
putlong(countAsserts(), f); putlong(assertions.size(), f);
struct Assertion *assert = assertions;
while (assert != NULL) {
struct Assertion *next = assert->next;
for (struct Assertion *assert : assertions) {
writeassert(assert, f); writeassert(assert, f);
freeassert(assert); freeassert(assert);
assert = next;
} }
fclose(f); fclose(f);