diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-01-02 20:53:39 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2023-01-02 20:53:39 +0100 |
commit | 6b6965238506705382892b14ef22700fc5112c3d (patch) | |
tree | c5a0f04bee2bace1281d7c7b405c8214641072c8 /src/libexpr/nixexpr.hh | |
parent | e0ab2069c975abf80db9fdca23f0c164df921829 (diff) | |
parent | 9af16c5f742300e831a2cc400e43df1e22f87f31 (diff) |
Merge remote-tracking branch 'origin/master' into coerce-string
Diffstat (limited to 'src/libexpr/nixexpr.hh')
-rw-r--r-- | src/libexpr/nixexpr.hh | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index ea0ce1a7f..ffe67f97d 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -22,15 +22,22 @@ MakeError(MissingArgumentError, EvalError); MakeError(RestrictedPathError, Error); /* Position objects. */ - struct Pos { - std::string file; - FileOrigin origin; uint32_t line; uint32_t column; + struct none_tag { }; + struct Stdin { ref<std::string> source; }; + struct String { ref<std::string> source; }; + + typedef std::variant<none_tag, Stdin, String, Path> Origin; + + Origin origin; + explicit operator bool() const { return line > 0; } + + operator std::shared_ptr<AbstractPos>() const; }; class PosIdx { @@ -46,7 +53,11 @@ public: explicit operator bool() const { return id > 0; } - bool operator<(const PosIdx other) const { return id < other.id; } + bool operator <(const PosIdx other) const { return id < other.id; } + + bool operator ==(const PosIdx other) const { return id == other.id; } + + bool operator !=(const PosIdx other) const { return id != other.id; } }; class PosTable @@ -60,13 +71,13 @@ public: // current origins.back() can be reused or not. mutable uint32_t idx = std::numeric_limits<uint32_t>::max(); - explicit Origin(uint32_t idx): idx(idx), file{}, origin{} {} + // Used for searching in PosTable::[]. + explicit Origin(uint32_t idx): idx(idx), origin{Pos::none_tag()} {} public: - const std::string file; - const FileOrigin origin; + const Pos::Origin origin; - Origin(std::string file, FileOrigin origin): file(std::move(file)), origin(origin) {} + Origin(Pos::Origin origin): origin(origin) {} }; struct Offset { @@ -106,7 +117,7 @@ public: [] (const auto & a, const auto & b) { return a.idx < b.idx; }); const auto origin = *std::prev(pastOrigin); const auto offset = offsets[idx]; - return {origin.file, origin.origin, offset.line, offset.column}; + return {offset.line, offset.column, origin.origin}; } }; |