about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-03-31T08·29+0000
committerLudovic Courtès <ludo@gnu.org>2010-03-31T08·29+0000
commit471419d1fac21412dea9a47eff200d44cd75d825 (patch)
treeee3214df328b9dbda698b0d5e23061a59d2c6e59
parenteb07a4f1ee532833407b40a9992bfe65c8a4d1d2 (diff)
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.
-rw-r--r--src/libexpr/expr-to-xml.cc38
1 files changed, 33 insertions, 5 deletions
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);
     }