From 9617863bbb82fbe5c3c203dec2b9a7d7f6a746d5 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sat, 10 Aug 2024 20:59:55 -0400 Subject: Fix logger file invalid pointer Add explicit move semantics to AbstractSyntaxTree Add explicit move semantics to ParseState --- src/openvic-dataloader/AbstractSyntaxTree.hpp | 23 +++++++++++++++++++++++ src/openvic-dataloader/ParseState.hpp | 14 ++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/openvic-dataloader/AbstractSyntaxTree.hpp b/src/openvic-dataloader/AbstractSyntaxTree.hpp index f2d941b..156b7d0 100644 --- a/src/openvic-dataloader/AbstractSyntaxTree.hpp +++ b/src/openvic-dataloader/AbstractSyntaxTree.hpp @@ -26,6 +26,14 @@ namespace ovdl { AbstractSyntaxTree() = default; explicit AbstractSyntaxTree(std::size_t max_elements) : _symbol_interner(max_elements) {} + AbstractSyntaxTree(AbstractSyntaxTree&& other) : _symbol_interner { std::move(other._symbol_interner) } {} + AbstractSyntaxTree& operator=(AbstractSyntaxTree&& rhs) { + this->~AbstractSyntaxTree(); + new (this) AbstractSyntaxTree(std::move(rhs)); + + return *this; + } + symbol_type intern(const char* str, std::size_t length); symbol_type intern(std::string_view str); const char* intern_cstr(const char* str, std::size_t length); @@ -63,6 +71,21 @@ namespace ovdl { : AbstractSyntaxTree(buffer.size() * sizeof(Encoding::char_type)), _file { std::move(buffer) } {} + BasicAbstractSyntaxTree(const BasicAbstractSyntaxTree&) = delete; + BasicAbstractSyntaxTree& operator=(const BasicAbstractSyntaxTree&) = delete; + + BasicAbstractSyntaxTree(BasicAbstractSyntaxTree&& other) + : _tree { std::move(other._tree) }, + _file { std::move(other._file) }, + AbstractSyntaxTree(std::move(other)) {} + + BasicAbstractSyntaxTree& operator=(AbstractSyntaxTree&& rhs) { + this->~BasicAbstractSyntaxTree(); + new (this) BasicAbstractSyntaxTree(std::move(rhs)); + + return *this; + } + void set_location(const node_type* n, NodeLocation loc) { _file.set_location(n, loc); } diff --git a/src/openvic-dataloader/ParseState.hpp b/src/openvic-dataloader/ParseState.hpp index 259f2a5..a9a9953 100644 --- a/src/openvic-dataloader/ParseState.hpp +++ b/src/openvic-dataloader/ParseState.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include #include @@ -37,6 +35,18 @@ namespace ovdl { _logger { this->ast().file() }, BasicParseState(encoding) {} + ParseState(ParseState&& other) + : _ast { std::move(other._ast) }, + _logger { this->ast().file() }, + BasicParseState(other.encoding()) {} + + ParseState& operator=(ParseState&& rhs) { + this->~ParseState(); + new (this) ParseState(std::move(rhs)); + + return *this; + } + template ParseState(lexy::buffer&& buffer, detail::Encoding encoding) : ParseState(typename ast_type::file_type { std::move(buffer) }, encoding) {} -- cgit v1.2.3-56-ga3b1