Turn mkString(Symbol) into a method

This commit is contained in:
Eelco Dolstra 2022-01-04 19:09:40 +01:00
parent ed93aec3c3
commit ca5baf2392
3 changed files with 11 additions and 14 deletions

View file

@ -112,7 +112,7 @@ struct ExprString : Expr
{
Symbol s;
Value v;
ExprString(const Symbol & s) : s(s) { mkString(v, s); };
ExprString(const Symbol & s) : s(s) { v.mkString(s); };
COMMON_METHODS
Value * maybeThunk(EvalState & state, Env & env);
};

View file

@ -412,7 +412,7 @@ static void prim_typeOf(EvalState & state, const Pos & pos, Value * * args, Valu
case nFloat: t = "float"; break;
case nThunk: abort();
}
mkString(v, state.symbols.create(t));
v.mkString(state.symbols.create(t));
}
static RegisterPrimOp primop_typeOf({
@ -2129,7 +2129,7 @@ static void prim_attrNames(EvalState & state, const Pos & pos, Value * * args, V
size_t n = 0;
for (auto & i : *args[0]->attrs)
mkString(*(v.listElems()[n++] = state.allocValue()), i.name);
(v.listElems()[n++] = state.allocValue())->mkString(i.name);
std::sort(v.listElems(), v.listElems() + n,
[](Value * v1, Value * v2) { return strcmp(v1->string.s, v2->string.s) < 0; });
@ -2477,7 +2477,7 @@ static void prim_mapAttrs(EvalState & state, const Pos & pos, Value * * args, Va
for (auto & i : *args[1]->attrs) {
Value * vName = state.allocValue();
Value * vFun2 = state.allocValue();
mkString(*vName, i.name);
vName->mkString(i.name);
vFun2->mkApp(args[0], vName);
state.allocAttr(v, i.name)->mkApp(vFun2, i.value);
}
@ -2540,8 +2540,8 @@ static void prim_zipAttrsWith(EvalState & state, const Pos & pos, Value * * args
}
for (auto & attr : *v.attrs) {
Value * name = state.allocValue();
mkString(*name, attr.name);
auto name = state.allocValue();
name->mkString(attr.name);
auto call1 = state.allocValue();
call1->mkApp(args[0], name);
auto call2 = state.allocValue();

View file

@ -241,6 +241,11 @@ public:
void mkString(std::string_view s, const PathSet & context);
inline void mkString(const Symbol & s)
{
mkString(((const std::string &) s).c_str());
}
inline void mkPath(const char * s)
{
clearValue();
@ -393,14 +398,6 @@ public:
};
// TODO: Remove these static functions, replace call sites with v.mk* instead
static inline void mkString(Value & v, const Symbol & s)
{
v.mkString(((const string &) s).c_str());
}
#if HAVE_BOEHMGC
typedef std::vector<Value *, traceable_allocator<Value *> > ValueVector;
typedef std::map<Symbol, Value *, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, Value *> > > ValueMap;