about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-10-03T15·38+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-10-03T15·38+0000
commit5fd44654dbca02f188957279eb25a33a3ecfe96b (patch)
tree12b0cb0d2e3018795f810314402450b91bc6b7ae /src
parent3837fb233cccc8f65629749f07820afba04952a0 (diff)
* toXML: propagate the context to allow derivations to be used in the
  argument.

Diffstat (limited to 'src')
-rw-r--r--src/libexpr/expr-to-xml.cc19
-rw-r--r--src/libexpr/expr-to-xml.hh3
-rw-r--r--src/libexpr/primops.cc5
-rw-r--r--src/nix-instantiate/main.cc4
4 files changed, 21 insertions, 10 deletions
diff --git a/src/libexpr/expr-to-xml.cc b/src/libexpr/expr-to-xml.cc
index b84c0058e236..085488bb5dd5 100644
--- a/src/libexpr/expr-to-xml.cc
+++ b/src/libexpr/expr-to-xml.cc
@@ -15,14 +15,21 @@ static XMLAttrs singletonAttrs(const string & name, const string & value)
 }
 
 
-static void printTermAsXML(Expr e, XMLWriter & doc)
+static void printTermAsXML(Expr e, XMLWriter & doc, ATermList & context)
 {
     XMLAttrs attrs;
     ATerm s;
     int i;
+    Expr e2;
     ATermList as, es, formals;
     ATerm body, pos;
 
+    while (matchContext(e, es, e2)) {
+        e = e2;
+        for (ATermIterator i(es); i; ++i)
+            context = ATinsert(context, *i);
+    }
+
     if (matchStr(e, s))
         doc.writeEmptyElement("string", singletonAttrs("value", aterm2String(s)));
 
@@ -53,14 +60,14 @@ static void printTermAsXML(Expr e, XMLWriter & doc)
             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);
+            printTermAsXML(attrs.get(toATerm(*i)), doc, context);
         }
     }
 
     else if (matchList(e, es)) {
         XMLOpenElement _(doc, "list");
         for (ATermIterator i(es); i; ++i)
-            printTermAsXML(*i, doc);
+            printTermAsXML(*i, doc, context);
     }
 
     else if (matchFunction(e, formals, body, pos)) {
@@ -75,7 +82,7 @@ static void printTermAsXML(Expr e, XMLWriter & doc)
             if (matchValidValues(valids, valids2)) {
                 for (ATermIterator j(valids2); j; ++j) {
                     XMLOpenElement _(doc, "value");
-                    printTermAsXML(*j, doc);
+                    printTermAsXML(*j, doc, context);
                 }
             }
         }
@@ -86,11 +93,11 @@ static void printTermAsXML(Expr e, XMLWriter & doc)
 }
 
 
-void printTermAsXML(Expr e, std::ostream & out)
+void printTermAsXML(Expr e, std::ostream & out, ATermList & context)
 {
     XMLWriter doc(true, out);
     XMLOpenElement root(doc, "expr");
-    printTermAsXML(e, doc);
+    printTermAsXML(e, doc, context);
 }
 
  
diff --git a/src/libexpr/expr-to-xml.hh b/src/libexpr/expr-to-xml.hh
index 6b95c88f5909..eb628660d937 100644
--- a/src/libexpr/expr-to-xml.hh
+++ b/src/libexpr/expr-to-xml.hh
@@ -5,10 +5,11 @@
 #include <map>
 
 #include "nixexpr.hh"
+#include "aterm.hh"
 
 namespace nix {
 
-void printTermAsXML(Expr e, std::ostream & out);
+void printTermAsXML(Expr e, std::ostream & out, ATermList & context);
     
 }
 
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 926ea7b80927..babd6df37b8a 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -507,8 +507,9 @@ static Expr primToPath(EvalState & state, const ATermVector & args)
 static Expr primToXML(EvalState & state, const ATermVector & args)
 {
     std::ostringstream out;
-    printTermAsXML(strictEvalExpr(state, args[0]), out);
-    return makeStr(toATerm(out.str()));
+    ATermList context = ATempty;
+    printTermAsXML(strictEvalExpr(state, args[0]), out, context);
+    return wrapInContext(context, makeStr(toATerm(out.str())));
 }
 
 
diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc
index fefc17c48053..93b7c03be360 100644
--- a/src/nix-instantiate/main.cc
+++ b/src/nix-instantiate/main.cc
@@ -41,9 +41,11 @@ static bool indirectRoot = false;
 static void printResult(EvalState & state, Expr e,
     bool evalOnly, bool xmlOutput, const ATermMap & autoArgs)
 {
+    ATermList context;
+    
     if (evalOnly)
         if (xmlOutput)
-            printTermAsXML(e, std::cout);
+            printTermAsXML(e, std::cout, context);
         else
             std::cout << format("%1%\n") % e;