|
FE 0.15.0
A C++23 toolkit for writing compiler/interpreter frontends.
|
Interns the text - and the std::filesystem::path - of every file a Loc may point into. More...
#include <fe/src.h>
Register a File | |
| std::pair< const Src *, bool > | add (std::filesystem::path path, std::string buf) |
| std::pair< const Src *, bool > | add (std::filesystem::path path) |
As above, but reads the content from path. | |
| static std::string | slurp (std::istream &is) |
Reads all of is into a std::string. | |
Lookup | |
| const Src * | lookup (const std::filesystem::path &path) const |
| static std::filesystem::path | key (const std::filesystem::path &path) |
The key path is interned under - absolute, symlink-free, and normalized. | |
Interns the text - and the std::filesystem::path - of every file a Loc may point into.
Keep one in your Driver: a Loc is only as good as the SrcMap that keeps its Src alive. Each file lives here exactly once, so Loc::src identifies it by pointer - see SrcMap::key.
| std::pair< const Src *, bool > fe::SrcMap::add | ( | std::filesystem::path | path | ) |
As above, but reads the content from path.
path cannot be opened. | std::pair< const Src *, bool > fe::SrcMap::add | ( | std::filesystem::path | path, |
| std::string | buf ) |
Registers path with buf as its content and reports whether it is fresh. A path with the same SrcMap::key as an already registered one yields that entry instead.
|
static |
The key path is interned under - absolute, symlink-free, and normalized.
This is where "do these two paths name the same file?" is decided - once, upon SrcMap::add - so that every comparison afterwards is a plain Loc::src pointer comparison.
path exists on disk and normalizes the rest lexically. A relative path is resolved against the current working directory now. | const Src * fe::SrcMap::lookup | ( | const std::filesystem::path & | path | ) | const |
path has not been registered. path that merely spells a registered file differently still finds it.
|
static |
Reads all of is into a std::string.