mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-24 20:12:07 +00:00
Use std::shared_ptr<std::string> for lexed/parsed strings
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#define RGBDS_ASM_LEXER_H
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
@@ -31,13 +32,10 @@ enum LexerMode {
|
||||
|
||||
struct Expansion {
|
||||
std::optional<std::string> name;
|
||||
union {
|
||||
char const *unowned;
|
||||
char *owned; // Non-`const` only so it can be `delete []`d
|
||||
} contents;
|
||||
size_t size; // Length of the contents
|
||||
std::shared_ptr<std::string> contents;
|
||||
size_t offset; // Cursor into the contents
|
||||
bool owned; // Whether or not to free contents when this expansion is freed
|
||||
|
||||
size_t size() const { return contents->size(); }
|
||||
};
|
||||
|
||||
struct IfStackEntry {
|
||||
@@ -140,10 +138,6 @@ struct CaptureBody {
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct String {
|
||||
char string[MAXSTRLEN + 1];
|
||||
};
|
||||
|
||||
void lexer_CheckRecursionDepth();
|
||||
uint32_t lexer_GetLineNo();
|
||||
uint32_t lexer_GetColNo();
|
||||
|
||||
@@ -3,26 +3,22 @@
|
||||
#ifndef RGBDS_MACRO_H
|
||||
#define RGBDS_MACRO_H
|
||||
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
#include "asm/warning.hpp"
|
||||
|
||||
struct MacroArgs {
|
||||
unsigned int shift;
|
||||
std::vector<std::string> args;
|
||||
std::vector<std::shared_ptr<std::string>> args;
|
||||
|
||||
void append(std::string s);
|
||||
void append(std::shared_ptr<std::string> arg);
|
||||
};
|
||||
|
||||
MacroArgs *macro_GetCurrentArgs();
|
||||
void macro_UseNewArgs(MacroArgs *args);
|
||||
char const *macro_GetArg(uint32_t i);
|
||||
char const *macro_GetAllArgs();
|
||||
std::shared_ptr<std::string> macro_GetArg(uint32_t i);
|
||||
std::shared_ptr<std::string> macro_GetAllArgs();
|
||||
|
||||
void macro_ShiftCurrentArgs(int32_t count);
|
||||
uint32_t macro_NbArgs();
|
||||
|
||||
@@ -36,10 +36,10 @@ struct Symbol {
|
||||
uint32_t fileLine; // Line where the symbol was defined
|
||||
|
||||
std::variant<
|
||||
int32_t, // If isNumeric()
|
||||
int32_t (*)(), // If isNumeric() and has a callback
|
||||
std::string_view *, // For SYM_MACRO
|
||||
std::string * // For SYM_EQUS
|
||||
int32_t, // If isNumeric()
|
||||
int32_t (*)(), // If isNumeric() and has a callback
|
||||
std::string_view *, // For SYM_MACRO
|
||||
std::shared_ptr<std::string> // For SYM_EQUS
|
||||
>
|
||||
data;
|
||||
|
||||
@@ -62,7 +62,7 @@ struct Symbol {
|
||||
int32_t getValue() const;
|
||||
int32_t getOutputValue() const;
|
||||
std::string_view *getMacro() const;
|
||||
std::string *getEqus() const;
|
||||
std::shared_ptr<std::string> getEqus() const;
|
||||
uint32_t getConstantValue() const;
|
||||
};
|
||||
|
||||
@@ -90,8 +90,8 @@ Symbol *sym_FindScopedValidSymbol(std::string const &symName);
|
||||
Symbol const *sym_GetPC();
|
||||
Symbol *sym_AddMacro(std::string const &symName, int32_t defLineNo, char const *body, size_t size);
|
||||
Symbol *sym_Ref(std::string const &symName);
|
||||
Symbol *sym_AddString(std::string const &symName, char const *value);
|
||||
Symbol *sym_RedefString(std::string const &symName, char const *value);
|
||||
Symbol *sym_AddString(std::string const &symName, std::shared_ptr<std::string> value);
|
||||
Symbol *sym_RedefString(std::string const &symName, std::shared_ptr<std::string> value);
|
||||
void sym_Purge(std::string const &symName);
|
||||
void sym_Init(time_t now);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user