Use std::shared_ptr for fstack nodes (#1371)

This commit is contained in:
Sylvie
2024-03-22 13:27:21 -04:00
committed by GitHub
parent dd43723e20
commit 04405fb444
8 changed files with 45 additions and 100 deletions

View File

@@ -5,6 +5,7 @@
#ifndef RGBDS_ASM_FSTACK_H
#define RGBDS_ASM_FSTACK_H
#include <memory>
#include <optional>
#include <stdint.h>
#include <stdio.h>
@@ -22,12 +23,10 @@ struct FileStackNode {
>
data;
FileStackNode *parent; // Pointer to parent node, for error reporting
std::shared_ptr<FileStackNode> parent; // Pointer to parent node, for error reporting
// Line at which the parent context was exited; meaningless for the root level
uint32_t lineNo;
// If referenced by a Symbol, Section, or Patch's `src`, don't `delete`!
bool referenced = false;
// Set only if referenced: ID within the object file, -1 if not output yet
uint32_t ID = -1;
@@ -50,7 +49,7 @@ extern size_t maxRecursionDepth;
struct MacroArgs;
void fstk_DumpCurrent();
FileStackNode *fstk_GetFileStack();
std::shared_ptr<FileStackNode> fstk_GetFileStack();
void fstk_AddIncludePath(std::string const &path);
void fstk_SetPreIncludeFile(std::string const &path);

View File

@@ -3,6 +3,7 @@
#ifndef RGBDS_ASM_OUTPUT_H
#define RGBDS_ASM_OUTPUT_H
#include <memory>
#include <stdint.h>
#include <string>
@@ -13,8 +14,7 @@ struct FileStackNode;
extern std::string objectName;
void out_RegisterNode(FileStackNode *node);
void out_ReplaceNode(FileStackNode *node);
void out_RegisterNode(std::shared_ptr<FileStackNode> node);
void out_SetFileName(std::string const &name);
void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift);
void out_CreateAssert(

View File

@@ -4,6 +4,7 @@
#define RGBDS_SECTION_H
#include <deque>
#include <memory>
#include <stdint.h>
#include <string>
#include <unordered_map>
@@ -18,7 +19,7 @@ struct FileStackNode;
struct Section;
struct Patch {
FileStackNode const *src;
std::shared_ptr<FileStackNode> src;
uint32_t lineNo;
uint32_t offset;
Section *pcSection;
@@ -31,8 +32,8 @@ struct Section {
std::string name;
SectionType type;
SectionModifier modifier;
FileStackNode const *src; // Where the section was defined
uint32_t fileLine; // Line where the section was defined
std::shared_ptr<FileStackNode> src; // Where the section was defined
uint32_t fileLine; // Line where the section was defined
uint32_t size;
uint32_t org;
uint32_t bank;

View File

@@ -3,6 +3,7 @@
#ifndef RGBDS_SYMBOL_H
#define RGBDS_SYMBOL_H
#include <memory>
#include <optional>
#include <stdint.h>
#include <string.h>
@@ -31,8 +32,8 @@ struct Symbol {
bool isExported; // Whether the symbol is to be exported
bool isBuiltin; // Whether the symbol is a built-in
Section *section;
FileStackNode *src; // Where the symbol was defined
uint32_t fileLine; // Line where the symbol was defined
std::shared_ptr<FileStackNode> src; // Where the symbol was defined
uint32_t fileLine; // Line where the symbol was defined
std::variant<
int32_t, // If isNumeric()