aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-dataloader/AbstractSyntaxTree.hpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2024-07-02 09:51:59 +0200
committer Spartan322 <Megacake1234@gmail.com>2024-07-05 19:17:25 +0200
commit3eb78b27505b602c1ccfa952c4cc00f942ccb2b9 (patch)
tree457b7fbda6d4470465c05d59b0ca51ed30628640 /src/openvic-dataloader/AbstractSyntaxTree.hpp
parentdeed8ec0ae23651529a58125012c1b4aab015d02 (diff)
Fix string interning pointer invalidity for ASTsimplify-string-interning
Fix errorneous string intern compare Add symbol interning tests Optimize non-conversion identifier cases Add `File::size()` Add InstanceOf concept Remove `FlatValue::value(const symbol_interner_type&)` Add `AbstractSyntaxTree::intern/intern_cst(lexy::lexeme)` overload Add `DiagnosticLogger::intern/intern_cstr(lexy::lexeme)` overload Use pinned_vector to maintain string interning pointer validity for buffers Add vmcontainer submodule for pinned_vector pinned_vector reserves virtual memory at runtime using OS APIs to maintain pointer validity Remove Exception and RTTI requirement from range-v3 submodule
Diffstat (limited to 'src/openvic-dataloader/AbstractSyntaxTree.hpp')
-rw-r--r--src/openvic-dataloader/AbstractSyntaxTree.hpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/openvic-dataloader/AbstractSyntaxTree.hpp b/src/openvic-dataloader/AbstractSyntaxTree.hpp
index a5b8886..ade1c82 100644
--- a/src/openvic-dataloader/AbstractSyntaxTree.hpp
+++ b/src/openvic-dataloader/AbstractSyntaxTree.hpp
@@ -9,6 +9,8 @@
#include <openvic-dataloader/detail/SymbolIntern.hpp>
#include <openvic-dataloader/detail/Utility.hpp>
+#include <lexy/lexeme.hpp>
+
#include <dryad/node.hpp>
#include <dryad/node_map.hpp>
#include <dryad/symbol.hpp>
@@ -16,10 +18,12 @@
#include <fmt/core.h>
-#include "detail/InternalConcepts.hpp"
+#include <detail/InternalConcepts.hpp>
namespace ovdl {
struct AbstractSyntaxTree : SymbolIntern {
+ explicit AbstractSyntaxTree(std::size_t max_elements) : _symbol_interner(max_elements) {}
+
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);
@@ -27,6 +31,15 @@ namespace ovdl {
symbol_interner_type& symbol_interner();
const symbol_interner_type& symbol_interner() const;
+ template<typename Reader>
+ symbol_type intern(lexy::lexeme<Reader> lexeme) {
+ return intern(lexeme.begin(), lexeme.size());
+ }
+ template<typename Reader>
+ const char* intern_cstr(lexy::lexeme<Reader> lexeme) {
+ return intern_cstr(lexeme.begin(), lexeme.size());
+ }
+
protected:
symbol_interner_type _symbol_interner;
};
@@ -37,10 +50,14 @@ namespace ovdl {
using root_node_type = RootNodeT;
using node_type = typename file_type::node_type;
- explicit BasicAbstractSyntaxTree(file_type&& file) : _file { std::move(file) } {}
+ explicit BasicAbstractSyntaxTree(file_type&& file)
+ : AbstractSyntaxTree(file.size()),
+ _file { std::move(file) } {}
template<typename Encoding, typename MemoryResource = void>
- explicit BasicAbstractSyntaxTree(lexy::buffer<Encoding, MemoryResource>&& buffer) : _file { std::move(buffer) } {}
+ explicit BasicAbstractSyntaxTree(lexy::buffer<Encoding, MemoryResource>&& buffer)
+ : AbstractSyntaxTree(buffer.size()),
+ _file { std::move(buffer) } {}
void set_location(const node_type* n, NodeLocation loc) {
_file.set_location(n, loc);