aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/nixexpr.hh
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-08 09:51:40 +0100
committereldritch horrors <pennae@lix.systems>2024-03-10 03:18:32 -0600
commit1cf0fa06332712e41e132dd8fce1198c89351e6e (patch)
tree6bd76f019950a5f40c5420611bfe66a5df252da7 /src/libexpr/nixexpr.hh
parent03f852b2c69233667de839a4777331114304c983 (diff)
add ExprAttrs::AttrDef::chooseByKind
in place of inherited() — not quite useful yet since we don't distinguish plain and inheritFrom attr kinds so far. (cherry picked from commit 1f542adb3e18e7078e6a589182a53a47d971748a) Change-Id: If948c9d43e875de18f213a73a06a36f7c335b536
Diffstat (limited to 'src/libexpr/nixexpr.hh')
-rw-r--r--src/libexpr/nixexpr.hh14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index fe75592f0..246221c0f 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -172,6 +172,20 @@ struct ExprAttrs : Expr
AttrDef() { };
bool inherited() const { return kind == Kind::Inherited; }
+
+ template<typename T>
+ const T & chooseByKind(const T & plain, const T & inherited, const T & inheritedFrom) const
+ {
+ switch (kind) {
+ case Kind::Plain:
+ return plain;
+ case Kind::Inherited:
+ return inherited;
+ default:
+ case Kind::InheritedFrom:
+ return inheritedFrom;
+ }
+ }
};
typedef std::map<Symbol, AttrDef> AttrDefs;
AttrDefs attrs;