          (soot/soot-field-signature ?soot ?signature)))
 
 
-         
-                  
+(defn
+  advice|reads-field
+  "Relation between an advice and one of the fields it reads from."
+  [?advice ?field]
+  (fresh [?soot|method ?soot|field ?soot|unit]
+         (advice-soot|method ?advice ?soot|method)
+         (field-soot|field ?field ?soot|field)
+         (soot/soot|method-soot|unit ?soot|method ?soot|unit)
+         (soot/soot|unit|reads-soot|field ?soot|unit ?soot|field)))
+
+(defn
+  advice|writes-field
+  "Relation between an advice and one of the fields it writes to."
+  [?advice ?field]
+  (fresh [?soot|method ?soot|field ?soot|unit]
+         (advice-soot|method ?advice ?soot|method)
+         (field-soot|field ?field ?soot|field)
+         (soot/soot|method-soot|unit ?soot|method ?soot|unit)
+         (soot/soot|unit|writes-soot|field ?soot|unit ?soot|field)))
 
 
+(defn
+  advice-soot|calling|unit-soot|calling|method
+  "Relation between an advice and the Soot unit and method that calls it."
+  [?advice ?soot|calling|unit ?soot|calling|method]
+  (fresh [?soot|method]
+         (advice-soot|method ?advice ?soot|method)
+         (soot/soot|method-soot|unit|caller ?soot|method ?soot|calling|unit)
+         ;next 2 lines are expensive, but required as a unit does not know in which method it resides
+         (soot/soot|method-soot|method|caller ?soot|method ?soot|calling|method)
+         (soot/soot|method-soot|unit ?soot|calling|method ?soot|calling|unit)))
 
-  
+(defn
+  advice-icfg-start
+  "Relation between an advice and an interprocedural control flow graph starting at the advice's application."
+  [?advice ?icfg ?icfg|start]
+  (fresh [?soot|method ?soot|unit|start ?soot|method|start]
+         (advice-soot|method ?advice ?soot|method)
+         (advice-soot|calling|unit-soot|calling|method ?advice ?soot|unit|start ?soot|method|start)
+         (soot/soot-method-icfg ?soot|method|start ?icfg)
+         (equals ?icfg|start (soot/make-icfgnode  ?soot|unit|start ?soot|method|start []))))
 
+(defn
+  icfg-start
+  "Relation between interprocedural control flow graph and its starting point at the application's entry method."
+  [?icfg ?icfg|start]
+  (fresh [?soot|method]
+        (soot/soot-entry-method ?soot|method)
+        (soot/soot-method-icfg-entry ?soot|method ?icfg ?icfg|start)))
 
+(defn
+  advice-reachable|advice
+  "Relation between an advice and another advice that may be executed afterwards."
+  [?advice1 ?advice2]
+  (fresh [?soot|method1 ?soot|method2]
+         (advice-soot|method ?advice1 ?soot|method1)
+         (!= ?advice1 ?advice2)
+         (advice-soot|method ?advice2 ?soot|method2)
+         (fresh [?icfg ?icfg|start ?icfg|end]
+                ;starting in main() because starting in the caller of advice1 did not work
+                ;(advice-icfg-start ?advice1 ?icfg ?icfg|start)
+                (icfg-start ?icfg ?icfg|start)
+                (qwal/qwal ?icfg ?icfg|start ?icfg|end []
+                           ;(start in application of first advice, make transition to first advice)
+                           ;qwal/q=>
+                           ;start in main method, make zero or more transitions to first advice
+                           (qwal/q=>*)
+                           (qwal/qcurrent [icfgnode]
+                                          (equals ?soot|method1 (soot/icfgnode-method icfgnode)))
+                           ;make one or more transitions to second advice  
+                           (qwal/q=>+)
+                           (qwal/qcurrent [icfgnode]
+                                          (equals ?soot|method2 (soot/icfgnode-method icfgnode)))))))
+         
+         
+         
+         
 (comment
   (damp.ekeko/ekeko* [?advice ?method] (advice-sootmethod ?advice ?method))
   


(defn
  intertype|method-soot|method
  [?itmethod ?soot]
  (fresh [?model ?scene ?signature]
         (world/intertype|method ?itmethod)

    (:use [clojure.core.logic])
    (:use [damp.ekeko logic])
    (:require 
      [damp.qwal :as qwal]
      [damp.ekeko.aspectj 
       [projectmodel :as projectmodel]
       [xcut :as xcut]
