-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecToGraphVisitor.go
181 lines (138 loc) · 4.72 KB
/
SpecToGraphVisitor.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package dLola
/*import (
"fmt"
"strings"
)*/
/*SpecToGraph Visitor that traverses recursively the AST, to build the Dependency Graph as in well-formed.go */
type SpecToGraphVisitor struct { //implements ExprVisitor, BooleanExprVisitor, NumExprVisitor, NumComparisonVisitor and StreamExprVisitor
//fields, may be stateful
g DepGraphAdj //stateful, need correct initialization
s StreamName //streamname of the expression
}
/*ExprVisitor methods*/
func (v *SpecToGraphVisitor) VisitConstExpr(c ConstExpr) {
}
func (v *SpecToGraphVisitor) VisitLetExpr(l LetExpr) {
specToGraphLet(v, l)
}
func (v *SpecToGraphVisitor) VisitIfThenElseExpr(ite IfThenElseExpr) {
specToGraphIf(v, ite)
}
func (v *SpecToGraphVisitor) VisitStringExpr(s StringExpr) {
s.StExpr.AcceptStr(v)
}
func (v *SpecToGraphVisitor) VisitStreamOffsetExpr(s StreamOffsetExpr) {
s.SExpr.AcceptStream(v)
}
func (v *SpecToGraphVisitor) VisitBooleanExpr(b BooleanExpr) {
b.BExpr.AcceptBool(v)
}
func (v *SpecToGraphVisitor) VisitNumericExpr(n NumericExpr) {
n.NExpr.AcceptNum(v)
}
/*END ExprVisitor methods*/
/*BoolExprVisitor methods*/
func (v *SpecToGraphVisitor) VisitTruePredicate(t TruePredicate) {
}
func (v *SpecToGraphVisitor) VisitFalsePredicate(f FalsePredicate) {
}
func (v *SpecToGraphVisitor) VisitNotPredicate(n NotPredicate) {
n.Inner.AcceptBool(v)
}
func (v *SpecToGraphVisitor) VisitAndPredicate(a AndPredicate) {
specToGraphBoolOp(v, a.Left, a.Right)
}
func (v *SpecToGraphVisitor) VisitOrPredicate(o OrPredicate) {
specToGraphBoolOp(v, o.Left, o.Right)
}
func (v *SpecToGraphVisitor) VisitNumComparisonPredicate(n NumComparisonPredicate) {
n.Comp.AcceptNumComp(v)
}
func (v *SpecToGraphVisitor) VisitStrComparisonPredicate(s StrComparisonPredicate) {
s.Comp.AcceptStrComp(v)
}
/*END BoolExprVisitor methods*/
/*NumComparisonVisitor methods*/
func (v *SpecToGraphVisitor) VisitNumLess(e NumLess) {
specToGraphNumOp(v, e.Left, e.Right)
}
func (v *SpecToGraphVisitor) VisitNumLessEq(e NumLessEq) {
specToGraphNumOp(v, e.Left, e.Right)
}
func (v *SpecToGraphVisitor) VisitNumEq(e NumEq) {
specToGraphNumOp(v, e.Left, e.Right)
}
func (v *SpecToGraphVisitor) VisitNumGreater(e NumGreater) {
specToGraphNumOp(v, e.Left, e.Right)
}
func (v *SpecToGraphVisitor) VisitNumGreaterEq(e NumGreaterEq) {
specToGraphNumOp(v, e.Left, e.Right)
}
func (v *SpecToGraphVisitor) VisitNumNotEq(e NumNotEq) {
specToGraphNumOp(v, e.Left, e.Right)
}
/*END NumComparisonVisitor methods*/
/*NumExprVisitor methods*/
func (v *SpecToGraphVisitor) VisitIntLiteralExpr(i IntLiteralExpr) {
}
func (v *SpecToGraphVisitor) VisitFloatLiteralExpr(f FloatLiteralExpr) {
}
func (v *SpecToGraphVisitor) VisitNumMulExpr(e NumMulExpr) {
specToGraphNumOp(v, e.Left, e.Right)
}
func (v *SpecToGraphVisitor) VisitNumDivExpr(e NumDivExpr) {
specToGraphNumOp(v, e.Left, e.Right)
}
func (v *SpecToGraphVisitor) VisitNumPlusExpr(e NumPlusExpr) {
specToGraphNumOp(v, e.Left, e.Right)
}
func (v *SpecToGraphVisitor) VisitNumMinusExpr(e NumMinusExpr) {
specToGraphNumOp(v, e.Left, e.Right)
}
/*END NumExprVisitor methods*/
/*StreamExprVisitor methods*/
func (v *SpecToGraphVisitor) VisitStreamFetchExpr(s StreamFetchExpr) {
a := Adj{v.s, s.Offset.val, s.Name}
adjs, ok := v.g[v.s]
if ok {
if !elem(adjs, a, EqAdj) {
v.g[v.s] = append(adjs, a) // add the dependency: v.s depends on the value of s
}
} else {
v.g[v.s] = []Adj{a}
}
}
/*END StreamExprVisitor methods*/
/*StrExprVisitor methods: strings*/
func (v *SpecToGraphVisitor) VisitStringLiteralExpr(s StringLiteralExpr) {
}
func (v *SpecToGraphVisitor) VisitStrConcatExpr(s StrConcatExpr) {
specToGraphStrOp(v, s.Left, s.Right)
}
func (v *SpecToGraphVisitor) VisitStrEqExpr(s StrEqExpr) {
specToGraphStrOp(v, s.Left, s.Right)
}
/*END StrExprVisitor methods*/
/*Not exported functions*/
func specToGraphNumOp(v *SpecToGraphVisitor, left NumExpr, right NumExpr) {
left.AcceptNum(v) //will treat the left expression
right.AcceptNum(v) //will treat the right expression
}
func specToGraphBoolOp(v *SpecToGraphVisitor, left BoolExpr, right BoolExpr) {
left.AcceptBool(v) //will treat the left expression
right.AcceptBool(v) //will treat the right expression
}
func specToGraphIf(v *SpecToGraphVisitor, ite IfThenElseExpr) {
ite.If.Accept(v) //will treat the left expression
ite.Then.Accept(v) //will treat the right expression
ite.Else.Accept(v) //will treat the right expression
}
func specToGraphLet(v *SpecToGraphVisitor, l LetExpr) {
l.Bind.Accept(v) //will treat the right expression
l.Body.Accept(v) //will treat the right expression
}
func specToGraphStrOp(v *SpecToGraphVisitor, left StrExpr, right StrExpr) {
left.AcceptStr(v) //will treat the right expression
right.AcceptStr(v) //will treat the right expression
}
/*END Not exported functions*/