#ifndef SOURCE_CC #define SOURCE_CC #include "array.cc" #include "common.cc" #include "memory.cc" typedef u32 Source_Id; struct Span { Source_Id id; usize start, end; Span(Source_Id id, usize start, usize end) : id(id), start(start), end(end) {} }; struct Buffer { String file; String content; Link link; const Allocator* allocator; }; bool buffer_init(Buffer* buffer, const Allocator* allocator, const String* content_in, const String* file_in) { String content, file; bool ret = slice_copy(allocator, content_in, &content); if (unlikely(ret == false)) return false; ret = slice_copy(allocator, file_in, &file); if (unlikely(ret == false)) { slice_deallocate(allocator, &content); return false; } buffer->file = file; buffer->content = content; buffer->link = {}; buffer->allocator = allocator; return true; } void buffer_deinit(Buffer* buffer) { slice_deallocate(buffer->allocator, &buffer->file); slice_deallocate(buffer->allocator, &buffer->content); buffer->allocator = nullptr; } struct Buffer_Manager { Link* stack; Array buffers; }; #define buffer_manager_init(allocator) \ Buffer_Manager { nullptr, array_init(Buffer, allocator) } void buffer_manager_deinit(Buffer_Manager* stack) { assert(stack != nullptr); array_deinit(&stack->buffers); } #endif