From 2b9e29b1c8b6b8e4884a46a3ba71ee795f1f97cd Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Jul 2011 12:28:57 +0000 Subject: =?UTF-8?q?*=20Change=20the=20right-hand=20side=20of=20the=20?= =?UTF-8?q?=E2=80=98.=E2=80=99=20operator=20from=20an=20attribute=20to=20?= =?UTF-8?q?=20=20an=20attribute=20path.=20=20This=20is=20a=20refactoring?= =?UTF-8?q?=20to=20support=20default=20values.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libexpr/eval.cc | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/libexpr/eval.cc') diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index c307f2a42..4d3a369aa 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -636,21 +636,35 @@ unsigned long nrLookupSize = 0; void ExprSelect::eval(EvalState & state, Env & env, Value & v) { - nrLookups++; - Value v2; - state.evalAttrs(env, e, v2); - nrLookupSize += v2.attrs->size(); - Bindings::iterator i = v2.attrs->find(name); - if (i == v2.attrs->end()) - throwEvalError("attribute `%1%' missing", name); - try { - state.forceValue(*i->value); + Value vTmp; + Pos * pos = 0; + Value * vAttrs = &vTmp; + + state.eval(env, e, vTmp); + + try { + + foreach (AttrPath::const_iterator, i, attrPath) { + nrLookups++; + state.forceAttrs(*vAttrs); + nrLookupSize += vAttrs->attrs->size(); + Bindings::iterator j; + if ((j = vAttrs->attrs->find(*i)) == vAttrs->attrs->end()) + throwEvalError("attribute `%1%' missing", showAttrPath(attrPath)); + vAttrs = j->value; + pos = j->pos; + } + + state.forceValue(*vAttrs); + } catch (Error & e) { - addErrorPrefix(e, "while evaluating the attribute `%1%' at %2%:\n", - name, *i->pos); + if (pos) + addErrorPrefix(e, "while evaluating the attribute `%1%' at %2%:\n", + showAttrPath(attrPath), *pos); throw; } - v = *i->value; + + v = *vAttrs; } -- cgit v1.2.3