mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Use std::shared_ptr for lexer capture buffers
This commit is contained in:
@@ -64,14 +64,16 @@ std::optional<std::string> fstk_FindFile(std::string const &path);
|
||||
bool yywrap();
|
||||
void fstk_RunInclude(std::string const &path, bool updateStateNow);
|
||||
void fstk_RunMacro(std::string const ¯oName, std::shared_ptr<MacroArgs> macroArgs);
|
||||
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char const *body, size_t size);
|
||||
void fstk_RunRept(
|
||||
uint32_t count, int32_t reptLineNo, std::shared_ptr<char const[]> body, size_t size
|
||||
);
|
||||
void fstk_RunFor(
|
||||
std::string const &symName,
|
||||
int32_t start,
|
||||
int32_t stop,
|
||||
int32_t step,
|
||||
int32_t reptLineNo,
|
||||
char const *body,
|
||||
std::shared_ptr<char const[]> body,
|
||||
size_t size
|
||||
);
|
||||
void fstk_StopRept();
|
||||
|
||||
@@ -52,21 +52,19 @@ struct BufferedContent {
|
||||
};
|
||||
|
||||
struct MmappedContent {
|
||||
char *ptr;
|
||||
std::shared_ptr<char[]> ptr;
|
||||
size_t size;
|
||||
size_t offset = 0;
|
||||
bool isReferenced = false; // If a macro in this file requires not unmapping it
|
||||
|
||||
MmappedContent(char *ptr_, size_t size_) : ptr(ptr_), size(size_) {}
|
||||
~MmappedContent();
|
||||
MmappedContent(std::shared_ptr<char[]> ptr_, size_t size_) : ptr(ptr_), size(size_) {}
|
||||
};
|
||||
|
||||
struct ViewedContent {
|
||||
char const *ptr;
|
||||
std::shared_ptr<char const[]> ptr;
|
||||
size_t size;
|
||||
size_t offset = 0;
|
||||
|
||||
ViewedContent(char const *ptr_, size_t size_) : ptr(ptr_), size(size_) {}
|
||||
ViewedContent(std::shared_ptr<char const[]> ptr_, size_t size_) : ptr(ptr_), size(size_) {}
|
||||
};
|
||||
|
||||
struct LexerState {
|
||||
@@ -80,9 +78,10 @@ struct LexerState {
|
||||
|
||||
std::deque<IfStackEntry> ifStack;
|
||||
|
||||
bool capturing; // Whether the text being lexed should be captured
|
||||
size_t captureSize; // Amount of text captured
|
||||
std::vector<char> *captureBuf; // Buffer to send the captured text to if non-null
|
||||
bool capturing; // Whether the text being lexed should be captured
|
||||
size_t captureSize; // Amount of text captured
|
||||
std::shared_ptr<std::vector<char>>
|
||||
captureBuf; // Buffer to send the captured text to if non-null
|
||||
|
||||
bool disableMacroArgs;
|
||||
bool disableInterpolation;
|
||||
@@ -96,7 +95,9 @@ struct LexerState {
|
||||
|
||||
void setAsCurrentState();
|
||||
bool setFileAsNextState(std::string const &filePath, bool updateStateNow);
|
||||
void setViewAsNextState(char const *name, char const *buf, size_t size, uint32_t lineNo_);
|
||||
void setViewAsNextState(
|
||||
char const *name, std::shared_ptr<char const[]> ptr, size_t size, uint32_t lineNo_
|
||||
);
|
||||
|
||||
void clear(uint32_t lineNo_);
|
||||
};
|
||||
@@ -136,7 +137,7 @@ void lexer_DumpStringExpansions();
|
||||
|
||||
struct Capture {
|
||||
uint32_t lineNo;
|
||||
char const *body;
|
||||
std::shared_ptr<char const[]> body;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user