* Fix the -qr query.

This commit is contained in:
Eelco Dolstra 2003-07-16 11:05:59 +00:00
parent c11bbcfd26
commit b9ecadee6e
3 changed files with 40 additions and 15 deletions

View File

@ -186,9 +186,10 @@ void registerSuccessor(const FSId & id1, const FSId & id2)
}
static FSId storeSuccessor(const FSId & id1, FState sc)
static FSId storeSuccessor(const FSId & id1, FState sc,
string * p)
{
FSId id2 = writeTerm(sc, "-s-" + (string) id1, 0);
FSId id2 = writeTerm(sc, "-s-" + (string) id1, p);
registerSuccessor(id1, id2);
return id2;
}
@ -267,7 +268,7 @@ static FState unparseSlice(const Slice & slice)
typedef set<FSId> FSIdSet;
Slice normaliseFState(FSId id)
static Slice normaliseFState2(FSId id, StringSet & usedPaths)
{
debug(format("normalising fstate"));
Nest nest(true);
@ -281,12 +282,16 @@ Slice normaliseFState(FSId id)
}
/* Get the fstate expression. */
FState fs = termFromId(id);
string fsPath;
FState fs = termFromId(id, &fsPath);
/* Already in normal form (i.e., a slice)? */
if (ATgetType(fs) == AT_APPL &&
(string) ATgetName(ATgetAFun(fs)) == "Slice")
{
usedPaths.insert(fsPath);
return parseSlice(fs);
}
/* Then we it's a Derive node. */
ATermList outs, ins, bnds;
@ -402,12 +407,20 @@ Slice normaliseFState(FSId id)
FState nf = unparseSlice(slice);
debug(printTerm(nf));
storeSuccessor(id, nf);
storeSuccessor(id, nf, &fsPath);
usedPaths.insert(fsPath);
return slice;
}
Slice normaliseFState(FSId id)
{
StringSet dummy;
return normaliseFState2(id, dummy);
}
static void checkSlice(const Slice & slice)
{
if (slice.elems.size() == 0)
@ -475,7 +488,7 @@ void realiseSlice(const Slice & slice)
}
Strings fstatePaths(FSId id, bool normalise)
Strings fstatePaths(const FSId & id, bool normalise)
{
Strings paths;
@ -520,3 +533,14 @@ Strings fstatePaths(FSId id, bool normalise)
return paths;
}
StringSet fstateRefs(const FSId & id)
{
StringSet paths;
Slice slice = normaliseFState2(id, paths);
for (SliceElems::const_iterator i = slice.elems.begin();
i != slice.elems.end(); i++)
paths.insert(i->path);
return paths;
}

View File

@ -101,7 +101,12 @@ Slice normaliseFState(FSId id);
/* Realise a Slice in the file system. */
void realiseSlice(const Slice & slice);
Strings fstatePaths(FSId id, bool normalise);
/* Get the list of root (output) paths of the given
fstate-expression. */
Strings fstatePaths(const FSId & id, bool normalise);
/* Get the list of paths referenced by the given fstate-expression. */
StringSet fstateRefs(const FSId & id);
#endif /* !__FSTATE_H */

View File

@ -159,23 +159,19 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qPath: {
Strings paths = fstatePaths(id, true);
for (Strings::iterator i = paths.begin();
i != paths.end(); i++)
cout << format("%s\n") % *i;
for (Strings::iterator j = paths.begin();
j != paths.end(); j++)
cout << format("%s\n") % *j;
break;
}
#if 0
case qRefs: {
StringSet refs;
FState fs = hash2fstate(hash);
fstateRefs(realiseFState(fs, refs), refs);
StringSet refs = fstateRefs(id);
for (StringSet::iterator j = refs.begin();
j != refs.end(); j++)
cout << format("%s\n") % *j;
break;
}
#endif
default:
abort();