From 8f98dc579af1993ec85bd849656c4835b4039dd6 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Mon, 23 Feb 2026 22:18:22 -0500 Subject: [willow]: frontend plumbing (#13) ... --- willow/tools/willowc/include/sourcemanager.hpp | 39 ++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'willow/tools/willowc/include/sourcemanager.hpp') diff --git a/willow/tools/willowc/include/sourcemanager.hpp b/willow/tools/willowc/include/sourcemanager.hpp index a526e48..25d4128 100644 --- a/willow/tools/willowc/include/sourcemanager.hpp +++ b/willow/tools/willowc/include/sourcemanager.hpp @@ -1,24 +1,59 @@ #ifndef WILLOWC_INCLUDE_SOURCEMANAGER_HPP #define WILLOWC_INCLUDE_SOURCEMANAGER_HPP -#include #include #include +#include +#include #include +#include + +#include namespace willowc { using FileID = std::uint32_t; +class LineCache { +public: +private: + std::unordered_map cache_; +}; + class SourceManager { +public: struct File { std::string path; + // TODO: remove this, but find something better than using the abs path + std::string display_path; std::unique_ptr buf; + size_t size; + + willow::Location getLoc(std::size_t offset); + std::map linecache_; + + File(std::string path, std::string display_path, std::unique_ptr buf, + size_t size) + : path(std::move(path)), display_path(std::move(display_path)), + buf(std::move(buf)), size(size), linecache_{{{0, 1}}} {} }; -public: + std::optional addFile(std::string_view path); + std::optional addStdIn(); + std::optional getFileID(const std::string& path); + std::string_view getBuf(FileID file) const { + const File &f = file_table.at(file); + return std::string_view(f.buf.get(), f.size); + } + File &getFile(FileID id) { return file_table.at(id); } + + const std::vector& files() const { return file_table; } + std::vector& files() { return file_table; } + + size_t numFiles() { return file_table.size(); } private: std::vector file_table; + std::unordered_map ids; }; } // namespace willowc -- cgit v1.2.3