FE 0.13.1
Header-only C++ frontend library
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 133 of file src.h.

Member Function Documentation

◆ add() [1/2]

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

As above, but reads the content from path.

Returns
a nullptr Src if path cannot be opened.

Definition at line 147 of file src.h.

References key(), and slurp().

◆ add() [2/2]

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

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.

Definition at line 139 of file src.h.

References key().

◆ key()

std::filesystem::path fe::SrcMap::key ( const std::filesystem::path & path)
inlinestatic

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.

Definition at line 177 of file src.h.

Referenced by add(), add(), and lookup().

◆ lookup()

const Src * fe::SrcMap::lookup ( const std::filesystem::path & path) const
inline
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.

Definition at line 167 of file src.h.

References fe::Src::end(), and key().

◆ slurp()

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

Reads all of is into a std::string.

Definition at line 157 of file src.h.

Referenced by add().


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