about summary refs log tree commit diff
path: root/src/fstate.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/fstate.cc')
-rw-r--r--src/fstate.cc36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/fstate.cc b/src/fstate.cc
index 60a8d475c981..cdd620cf1042 100644
--- a/src/fstate.cc
+++ b/src/fstate.cc
@@ -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;
+}