lix/src/libexpr/common-opts.cc
Eelco Dolstra 41c45a9b31 * Store Value nodes outside of attribute sets. I.e., Attr now stores
a pointer to a Value, rather than the Value directly.  This improves
  the effectiveness of garbage collection a lot: if the Value is
  stored inside the set directly, then any live pointer to the Value
  causes all other attributes in the set to be live as well.
2010-10-22 14:47:42 +00:00

36 lines
776 B
C++

#include "common-opts.hh"
#include "../libmain/shared.hh"
#include "util.hh"
#include "parser.hh"
namespace nix {
bool parseOptionArg(const string & arg, Strings::iterator & i,
const Strings::iterator & argsEnd, EvalState & state,
Bindings & autoArgs)
{
if (arg != "--arg" && arg != "--argstr") return false;
UsageError error(format("`%1%' requires two arguments") % arg);
if (i == argsEnd) throw error;
string name = *i++;
if (i == argsEnd) throw error;
string value = *i++;
Value * v = state.allocValue();
autoArgs[state.symbols.create(name)].value = v;
if (arg == "--arg")
state.mkThunk_(*v, parseExprFromString(state, value, absPath(".")));
else
mkString(*v, value);
return true;
}
}