diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-04-06 13:15:50 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2023-04-06 13:15:50 +0200 |
commit | 94812cca98fbb157e5f64a15a85a2b852d289feb (patch) | |
tree | 2f02c31fc42c7286f3c35dfd3ff1a88f235ab65b /src/libexpr/value.hh | |
parent | 5256ba6d87403f2b58ec4586c26d8fb14027252f (diff) |
Backport SourcePath from the lazy-trees branch
This introduces the SourcePath type from lazy-trees as an abstraction
for accessing files from inputs that may not be materialized in the
real filesystem (e.g. Git repositories). Currently, however, it's just
a wrapper around CanonPath, so it shouldn't change any behaviour. (On
lazy-trees, SourcePath is a <InputAccessor, CanonPath> tuple.)
Diffstat (limited to 'src/libexpr/value.hh')
-rw-r--r-- | src/libexpr/value.hh | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/libexpr/value.hh b/src/libexpr/value.hh index bfae4ee94..eb6f56d07 100644 --- a/src/libexpr/value.hh +++ b/src/libexpr/value.hh @@ -5,6 +5,7 @@ #include "symbol-table.hh" #include "value/context.hh" +#include "input-accessor.hh" #if HAVE_BOEHMGC #include <gc/gc_allocator.h> @@ -171,7 +172,7 @@ public: const char * * context; // must be in sorted order } string; - const char * path; + const char * _path; Bindings * attrs; struct { size_t size; @@ -251,15 +252,20 @@ public: void mkStringMove(const char * s, const PathSet & context); - inline void mkPath(const char * s) + inline void mkString(const Symbol & s) + { + mkString(((const std::string &) s).c_str()); + } + + void mkPath(const SourcePath & path); + + inline void mkPath(const char * path) { clearValue(); internalType = tPath; - path = s; + _path = path; } - void mkPath(std::string_view s); - inline void mkNull() { clearValue(); @@ -400,6 +406,18 @@ public: auto begin = listElems(); return ConstListIterable { begin, begin + listSize() }; } + + SourcePath path() const + { + assert(internalType == tPath); + return SourcePath{CanonPath(_path)}; + } + + std::string_view str() const + { + assert(internalType == tString); + return std::string_view(string.s); + } }; |