Use std::shared_ptr for lexer capture buffers

This commit is contained in:
Rangi42
2024-03-26 13:45:20 -04:00
committed by Sylvie
parent a68bebf4a2
commit bf0cabb3ea
6 changed files with 67 additions and 52 deletions

View File

@@ -10,6 +10,7 @@
#include <string>
#include <string_view>
#include <time.h>
#include <utility>
#include <variant>
#include "asm/section.hpp"
@@ -36,10 +37,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::shared_ptr<std::string> // For SYM_EQUS
int32_t, // If isNumeric()
int32_t (*)(), // If isNumeric() and has a callback
std::pair<std::shared_ptr<char const[]>, size_t>, // For SYM_MACRO
std::shared_ptr<std::string> // For SYM_EQUS
>
data;
@@ -61,7 +62,7 @@ struct Symbol {
int32_t getValue() const;
int32_t getOutputValue() const;
std::string_view getMacro() const;
std::pair<std::shared_ptr<char const[]>, size_t> getMacro() const;
std::shared_ptr<std::string> getEqus() const;
uint32_t getConstantValue() const;
};
@@ -88,7 +89,9 @@ Symbol *sym_FindScopedSymbol(std::string const &symName);
// Find a scoped symbol by name; do not return `@` or `_NARG` when they have no value
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_AddMacro(
std::string const &symName, int32_t defLineNo, std::shared_ptr<char const[]> body, size_t size
);
Symbol *sym_Ref(std::string const &symName);
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);