aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/attr-path.cc5
-rw-r--r--src/libexpr/eval.cc90
-rw-r--r--src/libexpr/get-drvs.cc20
-rw-r--r--src/libexpr/names.cc4
-rw-r--r--src/libexpr/nixexpr.cc92
-rw-r--r--src/libexpr/parser.y20
-rw-r--r--src/libexpr/primops.cc95
-rw-r--r--src/libexpr/value-to-json.cc28
-rw-r--r--src/libexpr/value-to-xml.cc40
9 files changed, 194 insertions, 200 deletions
diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc
index fdd61a5fd..a4945111e 100644
--- a/src/libexpr/attr-path.cc
+++ b/src/libexpr/attr-path.cc
@@ -42,11 +42,10 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
Value * v = &vIn;
- foreach (Strings::iterator, i, tokens) {
+ for (auto & attr : tokens) {
- /* Is *i an index (integer) or a normal attribute name? */
+ /* Is i an index (integer) or a normal attribute name? */
enum { apAttr, apIndex } apType = apAttr;
- string attr = *i;
unsigned int attrIndex;
if (string2Int(attr, attrIndex)) apType = apIndex;
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 7b74d99b1..b1436b842 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -98,8 +98,8 @@ static void printValue(std::ostream & str, std::set<const Value *> & active, con
str << "{ ";
typedef std::map<string, Value *> Sorted;
Sorted sorted;
- foreach (Bindings::iterator, i, *v.attrs)
- sorted[i->name] = i->value;
+ for (auto & i : *v.attrs)
+ sorted[i.name] = i.value;
for (auto & i : sorted) {
str << i.first << " = ";
printValue(str, active, *i.second);
@@ -442,8 +442,8 @@ void mkString(Value & v, const string & s, const PathSet & context)
unsigned int n = 0;
v.string.context = (const char * *)
allocBytes((context.size() + 1) * sizeof(char *));
- foreach (PathSet::const_iterator, i, context)
- v.string.context[n++] = dupString(i->c_str());
+ for (auto & i : context)
+ v.string.context[n++] = dupString(i.c_str());
v.string.context[n] = 0;
}
}
@@ -723,15 +723,15 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
environment, while the inherited attributes are evaluated
in the original environment. */
unsigned int displ = 0;
- foreach (AttrDefs::iterator, i, attrs) {
+ for (auto & i : attrs) {
Value * vAttr;
- if (hasOverrides && !i->second.inherited) {
+ if (hasOverrides && !i.second.inherited) {
vAttr = state.allocValue();
- mkThunk(*vAttr, env2, i->second.e);
+ mkThunk(*vAttr, env2, i.second.e);
} else
- vAttr = i->second.e->maybeThunk(state, i->second.inherited ? env : env2);
+ vAttr = i.second.e->maybeThunk(state, i.second.inherited ? env : env2);
env2.values[displ++] = vAttr;
- v.attrs->push_back(Attr(i->first, vAttr, &i->second.pos));
+ v.attrs->push_back(Attr(i.first, vAttr, &i.second.pos));
}
/* If the rec contains an attribute called `__overrides', then
@@ -762,13 +762,13 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
}
else
- foreach (AttrDefs::iterator, i, attrs)
- v.attrs->push_back(Attr(i->first, i->second.e->maybeThunk(state, env), &i->second.pos));
+ for (auto & i : attrs)
+ v.attrs->push_back(Attr(i.first, i.second.e->maybeThunk(state, env), &i.second.pos));
/* Dynamic attrs apply *after* rec and __overrides. */
- foreach (DynamicAttrDefs::iterator, i, dynamicAttrs) {
+ for (auto & i : dynamicAttrs) {
Value nameVal;
- i->nameExpr->eval(state, *dynamicEnv, nameVal);
+ i.nameExpr->eval(state, *dynamicEnv, nameVal);
state.forceValue(nameVal);
if (nameVal.type == tNull)
continue;
@@ -776,11 +776,11 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
Symbol nameSym = state.symbols.create(nameVal.string.s);
Bindings::iterator j = v.attrs->find(nameSym);
if (j != v.attrs->end())
- throwEvalError("dynamic attribute ‘%1%’ at %2% already defined at %3%", nameSym, i->pos, *j->pos);
+ throwEvalError("dynamic attribute ‘%1%’ at %2% already defined at %3%", nameSym, i.pos, *j->pos);
- i->valueExpr->setName(nameSym);
+ i.valueExpr->setName(nameSym);
/* Keep sorted order so find can catch duplicates */
- v.attrs->push_back(Attr(nameSym, i->valueExpr->maybeThunk(state, *dynamicEnv), &i->pos));
+ v.attrs->push_back(Attr(nameSym, i.valueExpr->maybeThunk(state, *dynamicEnv), &i.pos));
v.attrs->sort(); // FIXME: inefficient
}
}
@@ -797,8 +797,8 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
while the inherited attributes are evaluated in the original
environment. */
unsigned int displ = 0;
- foreach (ExprAttrs::AttrDefs::iterator, i, attrs->attrs)
- env2.values[displ++] = i->second.e->maybeThunk(state, i->second.inherited ? env : env2);
+ for (auto & i : attrs->attrs)
+ env2.values[displ++] = i.second.e->maybeThunk(state, i.second.inherited ? env : env2);
body->eval(state, env2, v);
}
@@ -849,10 +849,10 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
try {
- foreach (AttrPath::const_iterator, i, attrPath) {
+ for (auto & i : attrPath) {
nrLookups++;
Bindings::iterator j;
- Symbol name = getName(*i, state, env);
+ Symbol name = getName(i, state, env);
if (def) {
state.forceValue(*vAttrs);
if (vAttrs->type != tAttrs ||
@@ -891,10 +891,10 @@ void ExprOpHasAttr::eval(EvalState & state, Env & env, Value & v)
e->eval(state, env, vTmp);
- foreach (AttrPath::const_iterator, i, attrPath) {
+ for (auto & i : attrPath) {
state.forceValue(*vAttrs);
Bindings::iterator j;
- Symbol name = getName(*i, state, env);
+ Symbol name = getName(i, state, env);
if (vAttrs->type != tAttrs ||
(j = vAttrs->attrs->find(name)) == vAttrs->attrs->end())
{
@@ -1007,12 +1007,12 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
there is no matching actual argument but the formal
argument has a default, use the default. */
unsigned int attrsUsed = 0;
- foreach (Formals::Formals_::iterator, i, lambda.formals->formals) {
- Bindings::iterator j = arg.attrs->find(i->name);
+ for (auto & i : lambda.formals->formals) {
+ Bindings::iterator j = arg.attrs->find(i.name);
if (j == arg.attrs->end()) {
- if (!i->def) throwTypeError("%1% called without required argument ‘%2%’, at %3%",
- lambda, i->name, pos);
- env2.values[displ++] = i->def->maybeThunk(*this, env2);
+ if (!i.def) throwTypeError("%1% called without required argument ‘%2%’, at %3%",
+ lambda, i.name, pos);
+ env2.values[displ++] = i.def->maybeThunk(*this, env2);
} else {
attrsUsed++;
env2.values[displ++] = j->value;
@@ -1024,9 +1024,9 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
if (!lambda.formals->ellipsis && attrsUsed != arg.attrs->size()) {
/* Nope, so show the first unexpected argument to the
user. */
- foreach (Bindings::iterator, i, *arg.attrs)
- if (lambda.formals->argNames.find(i->name) == lambda.formals->argNames.end())
- throwTypeError("%1% called with unexpected argument ‘%2%’, at %3%", lambda, i->name, pos);
+ for (auto & i : *arg.attrs)
+ if (lambda.formals->argNames.find(i.name) == lambda.formals->argNames.end())
+ throwTypeError("%1% called with unexpected argument ‘%2%’, at %3%", lambda, i.name, pos);
abort(); // can't happen
}
}
@@ -1068,12 +1068,12 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res)
Value * actualArgs = allocValue();
mkAttrs(*actualArgs, fun.lambda.fun->formals->formals.size());
- foreach (Formals::Formals_::iterator, i, fun.lambda.fun->formals->formals) {
- Bindings::iterator j = args.find(i->name);
+ for (auto & i : fun.lambda.fun->formals->formals) {
+ Bindings::iterator j = args.find(i.name);
if (j != args.end())
actualArgs->attrs->push_back(*j);
- else if (!i->def)
- throwTypeError("cannot auto-call a function that has an argument without a default value (‘%1%’)", i->name);
+ else if (!i.def)
+ throwTypeError("cannot auto-call a function that has an argument without a default value (‘%1%’)", i.name);
}
actualArgs->attrs->sort();
@@ -1229,9 +1229,9 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
bool first = !forceString;
ValueType firstType = tString;
- foreach (vector<Expr *>::iterator, i, *es) {
+ for (auto & i : *es) {
Value vTmp;
- (*i)->eval(state, env, vTmp);
+ i->eval(state, env, vTmp);
/* If the first element is a path, then the result will also
be a path, we don't copy anything (yet - that's done later,
@@ -1583,25 +1583,25 @@ void EvalState::printStats()
printMsg(v, format("calls to %1% primops:") % primOpCalls.size());
typedef std::multimap<unsigned int, Symbol> PrimOpCalls_;
PrimOpCalls_ primOpCalls_;
- foreach (PrimOpCalls::iterator, i, primOpCalls)
- primOpCalls_.insert(std::pair<unsigned int, Symbol>(i->second, i->first));
- foreach_reverse (PrimOpCalls_::reverse_iterator, i, primOpCalls_)
+ for (auto & i : primOpCalls)
+ primOpCalls_.insert(std::pair<unsigned int, Symbol>(i.second, i.first));
+ for (auto i = primOpCalls_.rbegin(); i != primOpCalls_.rend(); ++i)
printMsg(v, format("%1$10d %2%") % i->first % i->second);
printMsg(v, format("calls to %1% functions:") % functionCalls.size());
typedef std::multimap<unsigned int, ExprLambda *> FunctionCalls_;
FunctionCalls_ functionCalls_;
- foreach (FunctionCalls::iterator, i, functionCalls)
- functionCalls_.insert(std::pair<unsigned int, ExprLambda *>(i->second, i->first));
- foreach_reverse (FunctionCalls_::reverse_iterator, i, functionCalls_)
+ for (auto & i : functionCalls)
+ functionCalls_.insert(std::pair<unsigned int, ExprLambda *>(i.second, i.first));
+ for (auto i = functionCalls_.rbegin(); i != functionCalls_.rend(); ++i)
printMsg(v, format("%1$10d %2%") % i->first % i->second->showNamePos());
printMsg(v, format("evaluations of %1% attributes:") % attrSelects.size());
typedef std::multimap<unsigned int, Pos> AttrSelects_;
AttrSelects_ attrSelects_;
- foreach (AttrSelects::iterator, i, attrSelects)
- attrSelects_.insert(std::pair<unsigned int, Pos>(i->second, i->first));
- foreach_reverse (AttrSelects_::reverse_iterator, i, attrSelects_)
+ for (auto & i : attrSelects)
+ attrSelects_.insert(std::pair<unsigned int, Pos>(i.second, i.first));
+ for (auto i = attrSelects_.rbegin(); i != attrSelects_.rend(); ++i)
printMsg(v, format("%1$10d %2%") % i->first % i->second);
}
diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc
index 1c9fa02a3..b7c3b0d33 100644
--- a/src/libexpr/get-drvs.cc
+++ b/src/libexpr/get-drvs.cc
@@ -85,8 +85,8 @@ StringSet DrvInfo::queryMetaNames()
{
StringSet res;
if (!getMeta()) return res;
- foreach (Bindings::iterator, i, *meta)
- res.insert(i->name);
+ for (auto & i : *meta)
+ res.insert(i.name);
return res;
}
@@ -102,8 +102,8 @@ bool DrvInfo::checkMeta(Value & v)
else if (v.type == tAttrs) {
Bindings::iterator i = v.attrs->find(state->sOutPath);
if (i != v.attrs->end()) return false;
- foreach (Bindings::iterator, i, *v.attrs)
- if (!checkMeta(*i->value)) return false;
+ for (auto & i : *v.attrs)
+ if (!checkMeta(*i.value)) return false;
return true;
}
else return v.type == tInt || v.type == tBool || v.type == tString;
@@ -255,13 +255,13 @@ static void getDerivations(EvalState & state, Value & vIn,
precedence). */
typedef std::map<string, Symbol> SortedSymbols;
SortedSymbols attrs;
- foreach (Bindings::iterator, i, *v.attrs)
- attrs.insert(std::pair<string, Symbol>(i->name, i->name));
+ for (auto & i : *v.attrs)
+ attrs.insert(std::pair<string, Symbol>(i.name, i.name));
- foreach (SortedSymbols::iterator, i, attrs) {
- startNest(nest, lvlDebug, format("evaluating attribute ‘%1%’") % i->first);
- string pathPrefix2 = addToPath(pathPrefix, i->first);
- Value & v2(*v.attrs->find(i->second)->value);
+ for (auto & i : attrs) {
+ startNest(nest, lvlDebug, format("evaluating attribute ‘%1%’") % i.first);
+ string pathPrefix2 = addToPath(pathPrefix, i.first);
+ Value & v2(*v.attrs->find(i.second)->value);
if (combineChannels)
getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures);
else if (getDerivation(state, v2, pathPrefix2, drvs, done, ignoreAssertionFailures)) {
diff --git a/src/libexpr/names.cc b/src/libexpr/names.cc
index cda5aa195..7bca9b655 100644
--- a/src/libexpr/names.cc
+++ b/src/libexpr/names.cc
@@ -98,8 +98,8 @@ int compareVersions(const string & v1, const string & v2)
DrvNames drvNamesFromArgs(const Strings & opArgs)
{
DrvNames result;
- foreach (Strings::const_iterator, i, opArgs)
- result.push_back(DrvName(*i));
+ for (auto & i : opArgs)
+ result.push_back(DrvName(i));
return result;
}
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 43f3161f8..35db52a13 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -97,21 +97,21 @@ void ExprAttrs::show(std::ostream & str)
{
if (recursive) str << "rec ";
str << "{ ";
- foreach (AttrDefs::iterator, i, attrs)
- if (i->second.inherited)
- str << "inherit " << i->first << " " << "; ";
+ for (auto & i : attrs)
+ if (i.second.inherited)
+ str << "inherit " << i.first << " " << "; ";
else
- str << i->first << " = " << *i->second.e << "; ";
- foreach (DynamicAttrDefs::iterator, i, dynamicAttrs)
- str << "\"${" << *i->nameExpr << "}\" = " << *i->valueExpr << "; ";
+ str << i.first << " = " << *i.second.e << "; ";
+ for (auto & i : dynamicAttrs)
+ str << "\"${" << *i.nameExpr << "}\" = " << *i.valueExpr << "; ";
str << "}";
}
void ExprList::show(std::ostream & str)
{
str << "[ ";
- foreach (vector<Expr *>::iterator, i, elems)
- str << "(" << **i << ") ";
+ for (auto & i : elems)
+ str << "(" << *i << ") ";
str << "]";
}
@@ -121,10 +121,10 @@ void ExprLambda::show(std::ostream & str)
if (matchAttrs) {
str << "{ ";
bool first = true;
- foreach (Formals::Formals_::iterator, i, formals->formals) {
+ for (auto & i : formals->formals) {
if (first) first = false; else str << ", ";
- str << i->name;
- if (i->def) str << " ? " << *i->def;
+ str << i.name;
+ if (i.def) str << " ? " << *i.def;
}
if (formals->ellipsis) {
if (!first) str << ", ";
@@ -140,12 +140,12 @@ void ExprLambda::show(std::ostream & str)
void ExprLet::show(std::ostream & str)
{
str << "(let ";
- foreach (ExprAttrs::AttrDefs::iterator, i, attrs->attrs)
- if (i->second.inherited) {
- str << "inherit " << i->first << "; ";
+ for (auto & i : attrs->attrs)
+ if (i.second.inherited) {
+ str << "inherit " << i.first << "; ";
}
else
- str << i->first << " = " << *i->second.e << "; ";
+ str << i.first << " = " << *i.second.e << "; ";
str << "in " << *body << ")";
}
@@ -173,9 +173,9 @@ void ExprConcatStrings::show(std::ostream & str)
{
bool first = true;
str << "(";
- foreach (vector<Expr *>::iterator, i, *es) {
+ for (auto & i : *es) {
if (first) first = false; else str << " + ";
- str << **i;
+ str << *i;
}
str << ")";
}
@@ -267,17 +267,17 @@ void ExprSelect::bindVars(const StaticEnv & env)
{
e->bindVars(env);
if (def) def->bindVars(env);
- foreach (AttrPath::iterator, i, attrPath)
- if (!i->symbol.set())
- i->expr->bindVars(env);
+ for (auto & i : attrPath)
+ if (!i.symbol.set())
+ i.expr->bindVars(env);
}
void ExprOpHasAttr::bindVars(const StaticEnv & env)
{
e->bindVars(env);
- foreach (AttrPath::iterator, i, attrPath)
- if (!i->symbol.set())
- i->expr->bindVars(env);
+ for (auto & i : attrPath)
+ if (!i.symbol.set())
+ i.expr->bindVars(env);
}
void ExprAttrs::bindVars(const StaticEnv & env)
@@ -289,27 +289,27 @@ void ExprAttrs::bindVars(const StaticEnv & env)
dynamicEnv = &newEnv;
unsigned int displ = 0;
- foreach (AttrDefs::iterator, i, attrs)
- newEnv.vars[i->first] = i->second.displ = displ++;
+ for (auto & i : attrs)
+ newEnv.vars[i.first] = i.second.displ = displ++;
- foreach (AttrDefs::iterator, i, attrs)
- i->second.e->bindVars(i->second.inherited ? env : newEnv);
+ for (auto & i : attrs)
+ i.second.e->bindVars(i.second.inherited ? env : newEnv);
}
else
- foreach (AttrDefs::iterator, i, attrs)
- i->second.e->bindVars(env);
+ for (auto & i : attrs)
+ i.second.e->bindVars(env);
- foreach (DynamicAttrDefs::iterator, i, dynamicAttrs) {
- i->nameExpr->bindVars(*dynamicEnv);
- i->valueExpr->bindVars(*dynamicEnv);
+ for (auto & i : dynamicAttrs) {
+ i.nameExpr->bindVars(*dynamicEnv);
+ i.valueExpr->bindVars(*dynamicEnv);
}
}
void ExprList::bindVars(const StaticEnv & env)
{
- foreach (vector<Expr *>::iterator, i, elems)
- (*i)->bindVars(env);
+ for (auto & i : elems)
+ i->bindVars(env);
}
void ExprLambda::bindVars(const StaticEnv & env)
@@ -321,11 +321,11 @@ void ExprLambda::bindVars(const StaticEnv & env)
if (!arg.empty()) newEnv.vars[arg] = displ++;
if (matchAttrs) {
- foreach (Formals::Formals_::iterator, i, formals->formals)
- newEnv.vars[i->name] = displ++;
+ for (auto & i : formals->formals)
+ newEnv.vars[i.name] = displ++;
- foreach (Formals::Formals_::iterator, i, formals->formals)
- if (i->def) i->def->bindVars(newEnv);
+ for (auto & i : formals->formals)
+ if (i.def) i.def->bindVars(newEnv);
}
body->bindVars(newEnv);
@@ -336,11 +336,11 @@ void ExprLet::bindVars(const StaticEnv & env)
StaticEnv newEnv(false, &env);
unsigned int displ = 0;
- foreach (ExprAttrs::AttrDefs::iterator, i, attrs->attrs)
- newEnv.vars[i->first] = i->second.displ = displ++;
+ for (auto & i : attrs->attrs)
+ newEnv.vars[i.first] = i.second.displ = displ++;
- foreach (ExprAttrs::AttrDefs::iterator, i, attrs->attrs)
- i->second.e->bindVars(i->second.inherited ? env : newEnv);
+ for (auto & i : attrs->attrs)
+ i.second.e->bindVars(i.second.inherited ? env : newEnv);
body->bindVars(newEnv);
}
@@ -384,8 +384,8 @@ void ExprOpNot::bindVars(const StaticEnv & env)
void ExprConcatStrings::bindVars(const StaticEnv & env)
{
- foreach (vector<Expr *>::iterator, i, *es)
- (*i)->bindVars(env);
+ for (auto & i : *es)
+ i->bindVars(env);
}
void ExprPos::bindVars(const StaticEnv & env)
@@ -419,8 +419,8 @@ string ExprLambda::showNamePos() const
size_t SymbolTable::totalSize() const
{
size_t n = 0;
- foreach (Symbols::const_iterator, i, symbols)
- n += i->size();
+ for (auto & i : symbols)
+ n += i.size();
return n;
}
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 1f830b7e3..d34882f36 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -136,8 +136,8 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex
bool atStartOfLine = true; /* = seen only whitespace in the current line */
unsigned int minIndent = 1000000;
unsigned int curIndent = 0;
- foreach (vector<Expr *>::iterator, i, es) {
- ExprIndStr * e = dynamic_cast<ExprIndStr *>(*i);
+ for (auto & i : es) {
+ ExprIndStr * e = dynamic_cast<ExprIndStr *>(i);
if (!e) {
/* Anti-quotations end the current start-of-line whitespace. */
if (atStartOfLine) {
@@ -419,20 +419,20 @@ binds
: binds attrpath '=' expr ';' { $$ = $1; addAttr($$, *$2, $4, makeCurPos(@2, data)); }
| binds INHERIT attrs ';'
{ $$ = $1;
- foreach (AttrPath::iterator, i, *$3) {
- if ($$->attrs.find(i->symbol) != $$->attrs.end())
- dupAttr(i->symbol, makeCurPos(@3, data), $$->attrs[i->symbol].pos);
+ for (auto & i : *$3) {
+ if ($$->attrs.find(i.symbol) != $$->attrs.end())
+ dupAttr(i.symbol, makeCurPos(@3, data), $$->attrs[i.symbol].pos);
Pos pos = makeCurPos(@3, data);
- $$->attrs[i->symbol] = ExprAttrs::AttrDef(new ExprVar(CUR_POS, i->symbol), pos, true);
+ $$->attrs[i.symbol] = ExprAttrs::AttrDef(new ExprVar(CUR_POS, i.symbol), pos, true);
}
}
| binds INHERIT '(' expr ')' attrs ';'
{ $$ = $1;
/* !!! Should ensure sharing of the expression in $4. */
- foreach (AttrPath::iterator, i, *$6) {
- if ($$->attrs.find(i->symbol) != $$->attrs.end())
- dupAttr(i->symbol, makeCurPos(@6, data), $$->attrs[i->symbol].pos);
- $$->attrs[i->symbol] = ExprAttrs::AttrDef(new ExprSelect(CUR_POS, $4, i->symbol), makeCurPos(@6, data));
+ for (auto & i : *$6) {
+ if ($$->attrs.find(i.symbol) != $$->attrs.end())
+ dupAttr(i.symbol, makeCurPos(@6, data), $$->attrs[i.symbol].pos);
+ $$->attrs[i.symbol] = ExprAttrs::AttrDef(new ExprSelect(CUR_POS, $4, i.symbol), makeCurPos(@6, data));
}
}
| { $$ = new ExprAttrs; }
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 355b81adf..c36a68ce0 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -330,8 +330,8 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
/* Create the result list. */
state.mkList(v, res.size());
unsigned int n = 0;
- foreach (ValueList::iterator, i, res)
- v.list.elems[n++] = *i;
+ for (auto & i : res)
+ v.list.elems[n++] = i;
}
@@ -477,24 +477,24 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
StringSet outputs;
outputs.insert("out");
- foreach (Bindings::iterator, i, *args[0]->attrs) {
- if (i->name == state.sIgnoreNulls) continue;
- string key = i->name;
+ for (auto & i : *args[0]->attrs) {
+ if (i.name == state.sIgnoreNulls) continue;
+ string key = i.name;
startNest(nest, lvlVomit, format("processing attribute ‘%1%’") % key);
try {
if (ignoreNulls) {
- state.forceValue(*i->value);
- if (i->value->type == tNull) continue;
+ state.forceValue(*i.value);
+ if (i.value->type == tNull) continue;
}
/* The `args' attribute is special: it supplies the
command-line arguments to the builder. */
if (key == "args") {
- state.forceList(*i->value, pos);
- for (unsigned int n = 0; n < i->value->list.length; ++n) {
- string s = state.coerceToString(posDrvName, *i->value->list.elems[n], context, true);
+ state.forceList(*i.value, pos);
+ for (unsigned int n = 0; n < i.value->list.length; ++n) {
+ string s = state.coerceToString(posDrvName, *i.value->list.elems[n], context, true);
drv.args.push_back(s);
}
}
@@ -502,11 +502,11 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
/* All other attributes are passed to the builder through
the environment. */
else {
- string s = state.coerceToString(posDrvName, *i->value, context, true);
+ string s = state.coerceToString(posDrvName, *i.value, context, true);
drv.env[key] = s;
if (key == "builder") drv.builder = s;
- else if (i->name == state.sSystem) drv.platform = s;
- else if (i->name == state.sName) {
+ else if (i.name == state.sSystem) drv.platform = s;
+ else if (i.name == state.sName) {
drvName = s;
printMsg(lvlVomit, format("derivation name is ‘%1%’") % drvName);
}
@@ -520,17 +520,17 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
else if (key == "outputs") {
Strings tmp = tokenizeString<Strings>(s);
outputs.clear();
- foreach (Strings::iterator, j, tmp) {
- if (outputs.find(*j) != outputs.end())
- throw EvalError(format("duplicate derivation output ‘%1%’, at %2%") % *j % posDrvName);
- /* !!! Check whether *j is a valid attribute
+ for (auto & j : tmp) {
+ if (outputs.find(j) != outputs.end())
+ throw EvalError(format("duplicate derivation output ‘%1%’, at %2%") % j % posDrvName);
+ /* !!! Check whether j is a valid attribute
name. */
/* Derivations cannot be named ‘drv’, because
then we'd have an attribute ‘drvPath’ in
the resulting set. */
- if (*j == "drv")
+ if (j == "drv")
throw EvalError(format("invalid derivation output name ‘drv’, at %1%") % posDrvName);
- outputs.insert(*j);
+ outputs.insert(j);
}
if (outputs.empty())
throw EvalError(format("derivation cannot have an empty set of outputs, at %1%") % posDrvName);
@@ -547,8 +547,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
/* Everything in the context of the strings in the derivation
attributes should be added as dependencies of the resulting
derivation. */
- foreach (PathSet::iterator, i, context) {
- Path path = *i;
+ for (auto & path : context) {
/* Paths marked with `=' denote that the path of a derivation
is explicitly passed to the builder. Since that allows the
@@ -560,10 +559,10 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
if (path.at(0) == '=') {
/* !!! This doesn't work if readOnlyMode is set. */
PathSet refs; computeFSClosure(*store, string(path, 1), refs);
- foreach (PathSet::iterator, j, refs) {
- drv.inputSrcs.insert(*j);
- if (isDerivation(*j))
- drv.inputDrvs[*j] = store->queryDerivationOutputNames(*j);
+ for (auto & j : refs) {
+ drv.inputSrcs.insert(j);
+ if (isDerivation(j))
+ drv.inputDrvs[j] = store->queryDerivationOutputNames(j);
}
}
@@ -622,20 +621,20 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
are empty, and the corresponding environment variables have
an empty value. This ensures that changes in the set of
output names do get reflected in the hash. */
- foreach (StringSet::iterator, i, outputs) {
- drv.env[*i] = "";
- drv.outputs[*i] = DerivationOutput("", "", "");
+ for (auto & i : outputs) {
+ drv.env[i] = "";
+ drv.outputs[i] = DerivationOutput("", "", "");
}
/* Use the masked derivation expression to compute the output
path. */
Hash h = hashDerivationModulo(*store, drv);
- foreach (DerivationOutputs::iterator, i, drv.outputs)
- if (i->second.path == "") {
- Path outPath = makeOutputPath(i->first, h, drvName);
- drv.env[i->first] = outPath;
- i->second.path = outPath;
+ for (auto & i : drv.outputs)
+ if (i.second.path == "") {
+ Path outPath = makeOutputPath(i.first, h, drvName);
+ drv.env[i.first] = outPath;
+ i.second.path = outPath;
}
}
@@ -652,9 +651,9 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
state.mkAttrs(v, 1 + drv.outputs.size());
mkString(*state.allocAttr(v, state.sDrvPath), drvPath, singleton<PathSet>("=" + drvPath));
- foreach (DerivationOutputs::iterator, i, drv.outputs) {
- mkString(*state.allocAttr(v, state.symbols.create(i->first)),
- i->second.path, singleton<PathSet>("!" + i->first + "!" + drvPath));
+ for (auto & i : drv.outputs) {
+ mkString(*state.allocAttr(v, state.symbols.create(i.first)),
+ i.second.path, singleton<PathSet>("!" + i.first + "!" + drvPath));
}
v.attrs->sort();
}
@@ -871,8 +870,7 @@ static void prim_toFile(EvalState & state, const Pos & pos, Value * * args, Valu
PathSet refs;
- foreach (PathSet::iterator, i, context) {
- Path path = *i;
+ for (auto path : context) {
if (path.at(0) == '=') path = string(path, 1);
if (isDerivation(path))
throw EvalError(format("in ‘toFile’: the file ‘%1%’ cannot refer to derivation outputs, at %2%") % name % pos);
@@ -1057,9 +1055,9 @@ static void prim_removeAttrs(EvalState & state, const Pos & pos, Value * * args,
to sort v.attrs because it's a subset of an already sorted
vector. */
state.mkAttrs(v, args[0]->attrs->size());
- foreach (Bindings::iterator, i, *args[0]->attrs) {
- if (names.find(i->name) == names.end())
- v.attrs->push_back(*i);
+ for (auto & i : *args[0]->attrs) {
+ if (names.find(i.name) == names.end())
+ v.attrs->push_back(i);
}
}
@@ -1111,8 +1109,8 @@ static void prim_intersectAttrs(EvalState & state, const Pos & pos, Value * * ar
state.mkAttrs(v, std::min(args[0]->attrs->size(), args[1]->attrs->size()));
- foreach (Bindings::iterator, i, *args[0]->attrs) {
- Bindings::iterator j = args[1]->attrs->find(i->name);
+ for (auto & i : *args[0]->attrs) {
+ Bindings::iterator j = args[1]->attrs->find(i.name);
if (j != args[1]->attrs->end())
v.attrs->push_back(*j);
}
@@ -1173,9 +1171,9 @@ static void prim_functionArgs(EvalState & state, const Pos & pos, Value * * args
}
state.mkAttrs(v, args[0]->lambda.fun->formals->formals.size());
- foreach (Formals::Formals_::iterator, i, args[0]->lambda.fun->formals->formals)
+ for (auto & i : args[0]->lambda.fun->formals->formals)
// !!! should optimise booleans (allocate only once)
- mkBool(*state.allocAttr(v, i->name), i->def);
+ mkBool(*state.allocAttr(v, i.name), i.def);
v.attrs->sort();
}
@@ -1407,11 +1405,8 @@ static void prim_unsafeDiscardOutputDependency(EvalState & state, const Pos & po
string s = state.coerceToString(pos, *args[0], context);
PathSet context2;
- foreach (PathSet::iterator, i, context) {
- Path p = *i;
- if (p.at(0) == '=') p = "~" + string(p, 1);
- context2.insert(p);
- }
+ for (auto & p : context)
+ context2.insert(p.at(0) == '=' ? "~" + string(p, 1) : p);
mkString(v, s, context2);
}
diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc
index cdb713418..b08d82497 100644
--- a/src/libexpr/value-to-json.cc
+++ b/src/libexpr/value-to-json.cc
@@ -12,14 +12,14 @@ namespace nix {
void escapeJSON(std::ostream & str, const string & s)
{
str << "\"";
- foreach (string::const_iterator, i, s)
- if (*i == '\"' || *i == '\\') str << "\\" << *i;
- else if (*i == '\n') str << "\\n";
- else if (*i == '\r') str << "\\r";
- else if (*i == '\t') str << "\\t";
- else if (*i >= 0 && *i < 32)
- str << "\\u" << std::setfill('0') << std::setw(4) << std::hex << (uint16_t) *i << std::dec;
- else str << *i;
+ for (auto & i : s)
+ if (i == '\"' || i == '\\') str << "\\" << i;
+ else if (i == '\n') str << "\\n";
+ else if (i == '\r') str << "\\r";
+ else if (i == '\t') str << "\\t";
+ else if (i >= 0 && i < 32)
+ str << "\\u" << std::setfill('0') << std::setw(4) << std::hex << (uint16_t) i << std::dec;
+ else str << i;
str << "\"";
}
@@ -59,11 +59,11 @@ void printValueAsJSON(EvalState & state, bool strict,
if (i == v.attrs->end()) {
JSONObject json(str);
StringSet names;
- foreach (Bindings::iterator, i, *v.attrs)
- names.insert(i->name);
- foreach (StringSet::iterator, i, names) {
- Attr & a(*v.attrs->find(state.symbols.create(*i)));
- json.attr(*i);
+ for (auto & j : *v.attrs)
+ names.insert(j.name);
+ for (auto & j : names) {
+ Attr & a(*v.attrs->find(state.symbols.create(j)));
+ json.attr(j);
printValueAsJSON(state, strict, *a.value, str, context);
}
} else
@@ -80,7 +80,7 @@ void printValueAsJSON(EvalState & state, bool strict,
break;
}
- case tExternal:
+ case tExternal:
v.external->printValueAsJSON(state, strict, str, context);
break;
diff --git a/src/libexpr/value-to-xml.cc b/src/libexpr/value-to-xml.cc
index bbbb7039b..9cb04bad3 100644
--- a/src/libexpr/value-to-xml.cc
+++ b/src/libexpr/value-to-xml.cc
@@ -8,7 +8,7 @@
namespace nix {
-
+
static XMLAttrs singletonAttrs(const string & name, const string & value)
{
XMLAttrs attrs;
@@ -33,17 +33,17 @@ static void showAttrs(EvalState & state, bool strict, bool location,
Bindings & attrs, XMLWriter & doc, PathSet & context, PathSet & drvsSeen)
{
StringSet names;
-
- foreach (Bindings::iterator, i, attrs)
- names.insert(i->name);
-
- foreach (StringSet::iterator, i, names) {
- Attr & a(*attrs.find(state.symbols.create(*i)));
-
+
+ for (auto & i : attrs)
+ names.insert(i.name);
+
+ for (auto & i : names) {
+ Attr & a(*attrs.find(state.symbols.create(i)));
+
XMLAttrs xmlAttrs;
- xmlAttrs["name"] = *i;
+ xmlAttrs["name"] = i;
if (location && a.pos != &noPos) posToXML(xmlAttrs, *a.pos);
-
+
XMLOpenElement _(doc, "attr", xmlAttrs);
printValueAsXML(state, strict, location,
*a.value, doc, context, drvsSeen);
@@ -57,7 +57,7 @@ static void printValueAsXML(EvalState & state, bool strict, bool location,
checkInterrupt();
if (strict) state.forceValue(v);
-
+
switch (v.type) {
case tInt:
@@ -85,7 +85,7 @@ static void printValueAsXML(EvalState & state, bool strict, bool location,
case tAttrs:
if (state.isDerivation(v)) {
XMLAttrs xmlAttrs;
-
+
Bindings::iterator a = v.attrs->find(state.symbols.create("derivation"));
Path drvPath;
@@ -95,7 +95,7 @@ static void printValueAsXML(EvalState & state, bool strict, bool location,
if (a->value->type == tString)
xmlAttrs["drvPath"] = drvPath = a->value->string.s;
}
-
+
a = v.attrs->find(state.sOutPath);
if (a != v.attrs->end()) {
if (strict) state.forceValue(*a->value);
@@ -116,7 +116,7 @@ static void printValueAsXML(EvalState & state, bool strict, bool location,
XMLOpenElement _(doc, "attrs");
showAttrs(state, strict, location, *v.attrs, doc, context, drvsSeen);
}
-
+
break;
case tList: {
@@ -130,17 +130,17 @@ static void printValueAsXML(EvalState & state, bool strict, bool location,
XMLAttrs xmlAttrs;
if (location) posToXML(xmlAttrs, v.lambda.fun->pos);
XMLOpenElement _(doc, "function", xmlAttrs);
-
+
if (v.lambda.fun->matchAttrs) {
XMLAttrs attrs;
if (!v.lambda.fun->arg.empty()) attrs["name"] = v.lambda.fun->arg;
if (v.lambda.fun->formals->ellipsis) attrs["ellipsis"] = "1";
XMLOpenElement _(doc, "attrspat", attrs);
- foreach (Formals::Formals_::iterator, i, v.lambda.fun->formals->formals)
- doc.writeEmptyElement("attr", singletonAttrs("name", i->name));
+ for (auto & i : v.lambda.fun->formals->formals)
+ doc.writeEmptyElement("attr", singletonAttrs("name", i.name));
} else
doc.writeEmptyElement("varpat", singletonAttrs("name", v.lambda.fun->arg));
-
+
break;
}
@@ -166,9 +166,9 @@ void printValueAsXML(EvalState & state, bool strict, bool location,
{
XMLWriter doc(true, out);
XMLOpenElement root(doc, "expr");
- PathSet drvsSeen;
+ PathSet drvsSeen;
printValueAsXML(state, strict, location, v, doc, context, drvsSeen);
}
-
+
}