From 471419d1fac21412dea9a47eff200d44cd75d825 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès <ludo@gnu.org> Date: Wed, 31 Mar 2010 08:29:05 +0000 Subject: Add source location information to the XML output. * src/libexpr/expr-to-xml.cc (nix::showAttrs): Dereference the attribute RHS. Add "path", "line", and "column" XML attributes to the node when source location information is available. (nix::printTermAsXML): Likewise for functions. --- src/libexpr/expr-to-xml.cc | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src/libexpr') diff --git a/src/libexpr/expr-to-xml.cc b/src/libexpr/expr-to-xml.cc index e401001ead01..4ca71c88909b 100644 --- a/src/libexpr/expr-to-xml.cc +++ b/src/libexpr/expr-to-xml.cc @@ -34,8 +34,25 @@ static void showAttrs(const ATermMap & attrs, XMLWriter & doc, for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i) names.insert(aterm2String(i->key)); for (StringSet::iterator i = names.begin(); i != names.end(); ++i) { - XMLOpenElement _(doc, "attr", singletonAttrs("name", *i)); - printTermAsXML(attrs.get(toATerm(*i)), doc, context, drvsSeen); + ATerm attrRHS = attrs.get(toATerm(*i)); + ATerm attr; + Pos pos; + XMLAttrs xmlAttrs; + + xmlAttrs["name"] = *i; + if(matchAttrRHS(attrRHS, attr, pos)) { + ATerm path; + int line, column; + if (matchPos(pos, path, line, column)) { + xmlAttrs["path"] = aterm2String(path); + xmlAttrs["line"] = (format("%1%") % line).str(); + xmlAttrs["column"] = (format("%1%") % column).str(); + } + } else + abort(); // Should not happen. + + XMLOpenElement _(doc, "attr", xmlAttrs); + printTermAsXML(attr, doc, context, drvsSeen); } } @@ -97,9 +114,12 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context, else if (matchAttrs(e, as)) { ATermMap attrs; - queryAllAttrs(e, attrs); + queryAllAttrs(e, attrs, true); - Expr a = attrs.get(toATerm("type")); + Expr aRHS = attrs.get(toATerm("type")); + Expr a = NULL; + if (aRHS) + matchAttrRHS(aRHS, a, pos); if (a && matchStr(a, s, context) && s == "derivation") { XMLAttrs xmlAttrs; @@ -135,7 +155,15 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context, } else if (matchFunction(e, pat, body, pos)) { - XMLOpenElement _(doc, "function"); + ATerm path; + int line, column; + XMLAttrs xmlAttrs; + if (matchPos(pos, path, line, column)) { + xmlAttrs["path"] = aterm2String(path); + xmlAttrs["line"] = (format("%1%") % line).str(); + xmlAttrs["column"] = (format("%1%") % column).str(); + } + XMLOpenElement _(doc, "function", xmlAttrs); printPatternAsXML(pat, doc); } -- cgit 1.4.1