-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.fs
67 lines (48 loc) · 1.88 KB
/
Node.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(* Represents a CFG node, with an expression and a Successor-nodes list, recursively *)
type Node(id : int, exp : Exp, succ : Node list ) =
let mutable Succ = succ
// method called by a Node instance
member this.ID() = id
interface INode<Exp> with
// method called by a Node:>INode instance
member this.ID() = id
member this.Statm() = exp
// returns succ
member this.Succ() = Succ |> List.map (fun x -> x :> INode<Exp>)
// used to compute the list of all nodes
member this.AllNodes(ls) =
let mutable l = ls
match (this:>INode<Exp>).Succ() with
|[] -> l
|xs -> for x in xs do
if List.contains x l then ignore()
else l<-l@[x]@(x.AllNodes(l@[x]))
l
// forward-analysis -> dep = succ
member this.Dep() = (this :> INode<Exp>).Succ()
// method called by a Node:>INode instance
member this.CompareTo(o : obj) : int =
let node = o:?>Node
if this.ID()>node.ID()
then 1
else if this.ID()<node.ID()
then -1
else 0
end
interface System.IComparable with
// method called by a Node instance
member this.CompareTo(o : obj) : int =
let node = o:?>Node
if this.ID()>node.ID()
then 1
else if this.ID()<node.ID()
then -1
else 0
end
override this.Equals( o : obj ) =
let node = o:?>Node
if node.ID()=this.ID() then true else false
override this.GetHashCode() = this.ID()
override this.ToString() = (string (this.ID())+", "+string ((this:>INode<Exp>).Statm()))
member this.ChangeSucc(nodes : Node list) = Succ <- nodes
;;