aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-10-29 11:22:49 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-10-29 11:22:49 +0000
commita69534fc217666d53a418605de0ebb0879cbb2f7 (patch)
treeb91bc4123796ff607c0c0b3861fe45ed37028bf3 /src/libstore
parented09821859e8e585c8479a3c3bf95e76d518d66f (diff)
* Drop ATmake / ATMatcher also in handling store expressions.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/Makefile.am9
-rw-r--r--src/libstore/storeexpr-ast.def7
-rw-r--r--src/libstore/storeexpr.cc61
3 files changed, 46 insertions, 31 deletions
diff --git a/src/libstore/Makefile.am b/src/libstore/Makefile.am
index 31735e893..7e0f32d1f 100644
--- a/src/libstore/Makefile.am
+++ b/src/libstore/Makefile.am
@@ -5,7 +5,14 @@ libstore_a_SOURCES = \
normalise.cc misc.cc normalise.hh \
globals.cc globals.hh db.cc db.hh \
references.cc references.hh pathlocks.cc pathlocks.hh \
- gc.cc gc.hh
+ gc.cc gc.hh storeexpr-ast.hh
+
+EXTRA_DIST = storeexpr-ast.def storeexpr-ast.cc
AM_CXXFLAGS = -Wall \
-I.. ${bdb_include} ${aterm_include} -I../libutil
+
+storeexpr-ast.cc storeexpr-ast.hh: ../aterm-helper.pl storeexpr-ast.def
+ $(perl) ../aterm-helper.pl storeexpr-ast.hh storeexpr-ast.cc < storeexpr-ast.def
+
+storeexpr.cc: storeexpr-ast.hh \ No newline at end of file
diff --git a/src/libstore/storeexpr-ast.def b/src/libstore/storeexpr-ast.def
new file mode 100644
index 000000000..9d2433dbe
--- /dev/null
+++ b/src/libstore/storeexpr-ast.def
@@ -0,0 +1,7 @@
+init initStoreExprHelpers
+
+Closure | ATermList ATermList | ATerm |
+Derive | ATermList ATermList string string ATermList ATermList | ATerm |
+
+| string string | ATerm | EnvBinding |
+| string ATermList | ATerm | ClosureElem |
diff --git a/src/libstore/storeexpr.cc b/src/libstore/storeexpr.cc
index 29f271de8..0b92be0e7 100644
--- a/src/libstore/storeexpr.cc
+++ b/src/libstore/storeexpr.cc
@@ -2,6 +2,9 @@
#include "globals.hh"
#include "store.hh"
+#include "storeexpr-ast.hh"
+#include "storeexpr-ast.cc"
+
Hash hashTerm(ATerm t)
{
@@ -29,10 +32,11 @@ Path writeTerm(ATerm t, const string & suffix)
static void parsePaths(ATermList paths, PathSet & out)
{
- ATMatcher m;
for (ATermIterator i(paths); i; ++i) {
- string s;
- if (!(atMatch(m, *i) >> s))
+ if (ATgetType(*i) != AT_APPL)
+ throw badTerm("not a path", *i);
+ string s = aterm2String(*i);
+ if (s.size() == 0 || s[0] != '/')
throw badTerm("not a path", *i);
out.insert(s);
}
@@ -69,21 +73,20 @@ static void checkClosure(const Closure & closure)
static bool parseClosure(ATerm t, Closure & closure)
{
ATermList roots, elems;
- ATMatcher m;
- if (!(atMatch(m, t) >> "Closure" >> roots >> elems))
+ if (!matchClosure(t, roots, elems))
return false;
parsePaths(roots, closure.roots);
for (ATermIterator i(elems); i; ++i) {
- string path;
+ ATerm path;
ATermList refs;
- if (!(atMatch(m, *i) >> "" >> path >> refs))
+ if (!matchClosureElem(*i, path, refs))
throw badTerm("not a closure element", *i);
ClosureElem elem;
parsePaths(refs, elem.refs);
- closure.elems[path] = elem;
+ closure.elems[aterm2String(path)] = elem;
}
checkClosure(closure);
@@ -93,32 +96,29 @@ static bool parseClosure(ATerm t, Closure & closure)
static bool parseDerivation(ATerm t, Derivation & derivation)
{
- ATMatcher m;
ATermList outs, ins, args, bnds;
- string builder, platform;
+ ATerm builder, platform;
- if (!(atMatch(m, t) >> "Derive" >> outs >> ins >> platform
- >> builder >> args >> bnds))
+ if (!matchDerive(t, outs, ins, platform, builder, args, bnds))
return false;
parsePaths(outs, derivation.outputs);
parsePaths(ins, derivation.inputs);
- derivation.builder = builder;
- derivation.platform = platform;
+ derivation.builder = aterm2String(builder);
+ derivation.platform = aterm2String(platform);
for (ATermIterator i(args); i; ++i) {
- string s;
- if (!(atMatch(m, *i) >> s))
+ if (ATgetType(*i) != AT_APPL)
throw badTerm("string expected", *i);
- derivation.args.push_back(s);
+ derivation.args.push_back(aterm2String(*i));
}
for (ATermIterator i(bnds); i; ++i) {
- string s1, s2;
- if (!(atMatch(m, *i) >> "" >> s1 >> s2))
+ ATerm s1, s2;
+ if (!matchEnvBinding(*i, s1, s2))
throw badTerm("tuple of strings expected", *i);
- derivation.env[s1] = s2;
+ derivation.env[aterm2String(s1)] = aterm2String(s2);
}
return true;
@@ -142,7 +142,7 @@ static ATermList unparsePaths(const PathSet & paths)
ATermList l = ATempty;
for (PathSet::const_iterator i = paths.begin();
i != paths.end(); i++)
- l = ATinsert(l, ATmake("<str>", i->c_str()));
+ l = ATinsert(l, string2ATerm(i->c_str()));
return ATreverse(l);
}
@@ -155,11 +155,11 @@ static ATerm unparseClosure(const Closure & closure)
for (ClosureElems::const_iterator i = closure.elems.begin();
i != closure.elems.end(); i++)
elems = ATinsert(elems,
- ATmake("(<str>, <term>)",
- i->first.c_str(),
+ makeClosureElem(
+ string2ATerm(i->first.c_str()),
unparsePaths(i->second.refs)));
- return ATmake("Closure(<term>, <term>)", roots, elems);
+ return makeClosure(roots, elems);
}
@@ -168,20 +168,21 @@ static ATerm unparseDerivation(const Derivation & derivation)
ATermList args = ATempty;
for (Strings::const_iterator i = derivation.args.begin();
i != derivation.args.end(); i++)
- args = ATinsert(args, ATmake("<str>", i->c_str()));
+ args = ATinsert(args, string2ATerm(i->c_str()));
ATermList env = ATempty;
for (StringPairs::const_iterator i = derivation.env.begin();
i != derivation.env.end(); i++)
env = ATinsert(env,
- ATmake("(<str>, <str>)",
- i->first.c_str(), i->second.c_str()));
+ makeEnvBinding(
+ string2ATerm(i->first.c_str()),
+ string2ATerm(i->second.c_str())));
- return ATmake("Derive(<term>, <term>, <str>, <str>, <term>, <term>)",
+ return makeDerive(
unparsePaths(derivation.outputs),
unparsePaths(derivation.inputs),
- derivation.platform.c_str(),
- derivation.builder.c_str(),
+ string2ATerm(derivation.platform.c_str()),
+ string2ATerm(derivation.builder.c_str()),
ATreverse(args),
ATreverse(env));
}