#ifndef WILLOWC_INCLUDE_SOURCEMANAGER_HPP #define WILLOWC_INCLUDE_SOURCEMANAGER_HPP #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}}} {} }; 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 #endif // WILLOWC_INCLUDE_SOURCEMANAGER_HPP