* Drop ATmake / ATMatcher also in handling store expressions.

This commit is contained in:
Eelco Dolstra 2004-10-29 11:22:49 +00:00
parent ed09821859
commit a69534fc21
19 changed files with 118 additions and 258 deletions

View file

@ -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

View file

@ -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 |

View file

@ -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));
}