FE 0.15.0
A C++23 toolkit for writing compiler/interpreter frontends.
Loading...
Searching...
No Matches
fe::SrcMap Class Reference

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 Srclookup (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.

Detailed Description

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.

Definition at line 93 of file src.h.

Member Function Documentation

◆ add() [1/2]

std::pair< const Src *, bool > fe::SrcMap::add ( std::filesystem::path path)

As above, but reads the content from path.

Returns
a nullptr Src if path cannot be opened.

◆ add() [2/2]

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.

◆ key()

std::filesystem::path fe::SrcMap::key ( const std::filesystem::path & path)
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.

Note
Resolves symlinks and ./.. as far as path exists on disk and normalizes the rest lexically. A relative path is resolved against the current working directory now.

◆ lookup()

const Src * fe::SrcMap::lookup ( const std::filesystem::path & path) const
Returns
nullptr if path has not been registered.
Note
Compares SrcMap::keys, so a path that merely spells a registered file differently still finds it.

◆ slurp()

std::string fe::SrcMap::slurp ( std::istream & is)
static

Reads all of is into a std::string.


The documentation for this class was generated from the following file: