No more flexible array members (not standard C++) (#1307)

* Replace FAMs with `std::vector`s (or one `std::string`) in four `struct`s

* Anonymous types declared in an anonymous union are also non-standard
  Only Clang complains about this (-Wnested-anon-types)
This commit is contained in:
Sylvie
2024-02-22 16:22:37 -05:00
committed by GitHub
parent 6d29d2a67e
commit c0d534f5ad
12 changed files with 170 additions and 203 deletions

View File

@@ -9,6 +9,7 @@
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <vector>
#include "asm/lexer.hpp"
@@ -28,14 +29,12 @@ struct FileStackNode {
struct FileStackReptNode { // NODE_REPT
struct FileStackNode node;
uint32_t reptDepth;
// WARNING: if changing this type, change overflow check in `fstk_Init`
uint32_t iters[]; // REPT iteration counts since last named node, in reverse depth order
std::vector<uint32_t> *iters; // REPT iteration counts since last named node, in reverse depth order
};
struct FileStackNamedNode { // NODE_FILE, NODE_MACRO
struct FileStackNode node;
char name[]; // File name for files, file::macro name for macros
std::string *name; // File name for files, file::macro name for macros
};
#define DEFAULT_MAX_DEPTH 64

View File

@@ -15,7 +15,7 @@ struct MacroArgs;
struct MacroArgs *macro_GetCurrentArgs(void);
struct MacroArgs *macro_NewArgs(void);
void macro_AppendArg(struct MacroArgs **args, char *s);
void macro_AppendArg(struct MacroArgs *args, char *s);
void macro_UseNewArgs(struct MacroArgs *args);
void macro_FreeArgs(struct MacroArgs *args);
char const *macro_GetArg(uint32_t i);

View File

@@ -23,6 +23,12 @@ enum SymbolType {
SYM_REF // Forward reference to a label
};
// Only used in an anonymous union by `struct Symbol`
struct strValue {
size_t size;
char *value;
};
struct Symbol {
char name[MAXSYMLEN + 1];
enum SymbolType type;
@@ -36,18 +42,12 @@ struct Symbol {
union {
// If sym_IsNumeric
int32_t value;
int32_t (*numCallback)(void);
int32_t (*numCallback)(void); // If hasCallback
// For SYM_MACRO
struct {
size_t size;
char *value;
} macro;
struct strValue macro;
// For SYM_EQUS
struct {
size_t size;
char *value;
} equs;
char const *(*strCallback)(void);
struct strValue equs;
char const *(*strCallback)(void); // If hasCallback
};
uint32_t ID; // ID of the symbol in the object file (-1 if none)