mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
libexpr: Deduplicate Value::primOpAppPrimOp
`getPrimOp` function was basically identical to existing `Value::primOpAppPrimOp` modulo some trivial differences. Makes sense to reuse existing code for that.
This commit is contained in:
parent
587b5f5361
commit
9563b509ff
1 changed files with 3 additions and 10 deletions
|
@ -94,15 +94,6 @@ void Value::print(EvalState & state, std::ostream & str, PrintOptions options)
|
||||||
printValue(state, str, *this, options);
|
printValue(state, str, *this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value * getPrimOp(const Value &v) {
|
|
||||||
const Value * primOp = &v;
|
|
||||||
while (primOp->isPrimOpApp()) {
|
|
||||||
primOp = primOp->payload.primOpApp.left;
|
|
||||||
}
|
|
||||||
assert(primOp->isPrimOp());
|
|
||||||
return primOp;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string_view showType(ValueType type, bool withArticle)
|
std::string_view showType(ValueType type, bool withArticle)
|
||||||
{
|
{
|
||||||
#define WA(a, w) withArticle ? a " " w : w
|
#define WA(a, w) withArticle ? a " " w : w
|
||||||
|
@ -133,7 +124,7 @@ std::string showType(const Value & v)
|
||||||
case tPrimOp:
|
case tPrimOp:
|
||||||
return fmt("the built-in function '%s'", std::string(v.payload.primOp->name));
|
return fmt("the built-in function '%s'", std::string(v.payload.primOp->name));
|
||||||
case tPrimOpApp:
|
case tPrimOpApp:
|
||||||
return fmt("the partially applied built-in function '%s'", std::string(getPrimOp(v)->payload.primOp->name));
|
return fmt("the partially applied built-in function '%s'", v.primOpAppPrimOp()->name);
|
||||||
case tExternal: return v.external()->showType();
|
case tExternal: return v.external()->showType();
|
||||||
case tThunk: return v.isBlackhole() ? "a black hole" : "a thunk";
|
case tThunk: return v.isBlackhole() ? "a black hole" : "a thunk";
|
||||||
case tApp: return "a function application";
|
case tApp: return "a function application";
|
||||||
|
@ -535,6 +526,8 @@ const PrimOp * Value::primOpAppPrimOp() const
|
||||||
|
|
||||||
if (!left)
|
if (!left)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
assert(left->isPrimOp());
|
||||||
return left->primOp();
|
return left->primOp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue