完成 Error定义和ErrorLog. 以及一些相关的东西

This commit is contained in:
2026-02-13 23:11:37 +08:00
parent cfcdfde170
commit 877253cbbc
22 changed files with 2200 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
#pragma once
#include <Deps/Deps.hpp>
#include <Core/SourceLocations.hpp>
#include <fstream>
namespace Fig
{
class SourceManager
{
private:
String filePath;
String source;
std::vector<String> lines;
public:
bool read = false;
String &Read()
{
std::fstream fs(filePath.toStdString());
if (!fs.is_open())
{
read = false;
return source;
}
std::string line;
while (std::getline(fs, line))
{
source += line + '\n';
lines.push_back(String(line));
}
read = true;
return source;
}
SourceManager() {}
SourceManager(String _path) { filePath = std::move(_path); }
bool HasLine(int64_t _line) const
{
return _line <= lines.size() && _line >= 1;
}
String GetLine(size_t _line) const
{
assert(_line <= lines.size() && "SourceManager: GetLine failed, index out of range");
return lines[_line - 1];
}
String GetSub(size_t _index_start, size_t _length) const
{
return source.substr(_index_start, _length);
}
};
};