about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-03-31T12·38+0000
committerLudovic Courtès <ludo@gnu.org>2010-03-31T12·38+0000
commit09381cccffe675ccbc8d183f043788f99dc018cd (patch)
tree0c38ffd9438be5422dc871c75abd7b5b19ee11da /src/libexpr
parent471419d1fac21412dea9a47eff200d44cd75d825 (diff)
Make source location info in the XML output optional.
* src/libexpr/expr-to-xml.cc (nix::showAttrs): Add `location'
  parameter.  Provide location XML attributes when it's true.  Update
  callers.
  (nix::printTermAsXML): Likewise.

* src/libexpr/expr-to-xml.hh (nix::printTermAsXML): Update prototype;
  have `location' default to `false'.

* src/nix-instantiate/nix-instantiate.cc (printResult, processExpr): Add
  `location' parameter; update callers.
  (run): Add support for `--no-location'.

* src/nix-instantiate/help.txt: Update accordingly.

* tests/lang.sh: Invoke `nix-instantiate' with `--no-location' for the
  XML tests.

* tests/lang/eval-okay-toxml.exp, tests/lang/eval-okay-to-xml.nix: New
  files.
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/expr-to-xml.cc22
-rw-r--r--src/libexpr/expr-to-xml.hh2
2 files changed, 12 insertions, 12 deletions
diff --git a/src/libexpr/expr-to-xml.cc b/src/libexpr/expr-to-xml.cc
index 4ca71c88909b..5857537d7501 100644
--- a/src/libexpr/expr-to-xml.cc
+++ b/src/libexpr/expr-to-xml.cc
@@ -24,11 +24,11 @@ typedef set<Expr> ExprSet;
 
 
 static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
-    ExprSet & drvsSeen);
+    ExprSet & drvsSeen, bool location);
 
 
 static void showAttrs(const ATermMap & attrs, XMLWriter & doc,
-    PathSet & context, ExprSet & drvsSeen)
+    PathSet & context, ExprSet & drvsSeen, bool location)
 {
     StringSet names;
     for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i)
@@ -43,7 +43,7 @@ static void showAttrs(const ATermMap & attrs, XMLWriter & doc,
 	if(matchAttrRHS(attrRHS, attr, pos)) {
 	    ATerm path;
 	    int line, column;
-	    if (matchPos(pos, path, line, column)) {
+            if (location && matchPos(pos, path, line, column)) {
 		xmlAttrs["path"] = aterm2String(path);
 		xmlAttrs["line"] = (format("%1%") % line).str();
 		xmlAttrs["column"] = (format("%1%") % column).str();
@@ -52,7 +52,7 @@ static void showAttrs(const ATermMap & attrs, XMLWriter & doc,
 	    abort(); // Should not happen.
 
         XMLOpenElement _(doc, "attr", xmlAttrs);
-        printTermAsXML(attr, doc, context, drvsSeen);
+        printTermAsXML(attr, doc, context, drvsSeen, location);
     }
 }
 
@@ -83,7 +83,7 @@ static void printPatternAsXML(Pattern pat, XMLWriter & doc)
 
 
 static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
-    ExprSet & drvsSeen)
+    ExprSet & drvsSeen, bool location)
 {
     XMLAttrs attrs;
     string s;
@@ -137,28 +137,28 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
 
             if (drvsSeen.find(e) == drvsSeen.end()) {
                 drvsSeen.insert(e);
-                showAttrs(attrs, doc, context, drvsSeen);
+                showAttrs(attrs, doc, context, drvsSeen, location);
             } else
                 doc.writeEmptyElement("repeated");
         }
 
         else {
             XMLOpenElement _(doc, "attrs");
-            showAttrs(attrs, doc, context, drvsSeen);
+            showAttrs(attrs, doc, context, drvsSeen, location);
         }
     }
 
     else if (matchList(e, es)) {
         XMLOpenElement _(doc, "list");
         for (ATermIterator i(es); i; ++i)
-            printTermAsXML(*i, doc, context, drvsSeen);
+            printTermAsXML(*i, doc, context, drvsSeen, location);
     }
 
     else if (matchFunction(e, pat, body, pos)) {
         ATerm path;
 	int line, column;
 	XMLAttrs xmlAttrs;
-	if (matchPos(pos, path, line, column)) {
+	if (location && matchPos(pos, path, line, column)) {
 	    xmlAttrs["path"] = aterm2String(path);
 	    xmlAttrs["line"] = (format("%1%") % line).str();
 	    xmlAttrs["column"] = (format("%1%") % column).str();
@@ -172,12 +172,12 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
 }
 
 
-void printTermAsXML(Expr e, std::ostream & out, PathSet & context)
+void printTermAsXML(Expr e, std::ostream & out, PathSet & context, bool location)
 {
     XMLWriter doc(true, out);
     XMLOpenElement root(doc, "expr");
     ExprSet drvsSeen;    
-    printTermAsXML(e, doc, context, drvsSeen);
+    printTermAsXML(e, doc, context, drvsSeen, location);
 }
 
  
diff --git a/src/libexpr/expr-to-xml.hh b/src/libexpr/expr-to-xml.hh
index 36b8e40424d8..de9d55f320ac 100644
--- a/src/libexpr/expr-to-xml.hh
+++ b/src/libexpr/expr-to-xml.hh
@@ -9,7 +9,7 @@
 
 namespace nix {
 
-void printTermAsXML(Expr e, std::ostream & out, PathSet & context);
+void printTermAsXML(Expr e, std::ostream & out, PathSet & context, bool location = false);
     
 }