-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstantSubs.go
166 lines (157 loc) · 6.16 KB
/
constantSubs.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
package dLola
/*import (
"fmt"
"strings"
)*/
func (this ConstExpr) ConstantSubs(spec *Spec) Expr {
constDecl, ok := spec.Const[this.Name]
if ok {
return constDecl.Val
}
return this //othw let it be
}
func (this LetExpr) ConstantSubs(spec *Spec) Expr {
return LetExpr{this.Name, this.Params, this.Result, this.Bind.ConstantSubs(spec), this.Body.ConstantSubs(spec)}
}
func (this IfThenElseExpr) ConstantSubs(spec *Spec) Expr {
return IfThenElseExpr{this.If.ConstantSubs(spec), this.Then.ConstantSubs(spec), this.Else.ConstantSubs(spec)}
}
func (this StreamOffsetExpr) ConstantSubs(spec *Spec) Expr { // expr = a[x|d] we will use the default value to infer the type
return this.SExpr.ConstantSubsStreamExpr(spec) //note it does not follow the pattern of the rest
}
func (this BooleanExpr) ConstantSubs(spec *Spec) Expr {
return BooleanExpr{this.BExpr.ConstantSubsBoolExpr(spec)}
}
func (this NumericExpr) ConstantSubs(spec *Spec) Expr {
return NumericExpr{this.NExpr.ConstantSubsNumExpr(spec)}
}
func (this StringExpr) ConstantSubs(spec *Spec) Expr {
return StringExpr{this.StExpr.ConstantSubsStrExpr(spec)}
}
//Boolean
func (this TruePredicate) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return this
}
func (this FalsePredicate) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return this
}
func (this NotPredicate) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return NotPredicate{this.Inner.ConstantSubsBoolExpr(spec)}
}
func (this StreamOffsetExpr) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return this.SExpr.ConstantSubsBoolStreamExpr(spec)
}
func (this ConstExpr) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return ConstExpr{this.Name, this.Pos}
}
func (this AndPredicate) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return AndPredicate{this.Left.ConstantSubsBoolExpr(spec), this.Right.ConstantSubsBoolExpr(spec)}
}
func (this OrPredicate) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return OrPredicate{this.Left.ConstantSubsBoolExpr(spec), this.Right.ConstantSubsBoolExpr(spec)}
}
/*func (this IfThenElsePredicate) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return IfThenElsePredicate{this.If.ConstantSubsBoolExpr(spec), this.Then.ConstantSubsBoolExpr(spec), this.Else.ConstantSubsBoolExpr(spec)}
}*/
func (this NumComparisonPredicate) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return NumComparisonPredicate{this.Comp.ConstantSubsNumCompExpr(spec)}
}
func (this StrComparisonPredicate) ConstantSubsBoolExpr(spec *Spec) BoolExpr {
return StrComparisonPredicate{this.Comp.ConstantSubsStrCompExpr(spec)}
}
//Stream
func (this StreamFetchExpr) ConstantSubsStreamExpr(spec *Spec) Expr {
constDecl, ok := spec.Const[this.Name]
if ok {
return constDecl.Val
}
return StreamOffsetExpr{this} //othw let it be
}
func (this StreamFetchExpr) ConstantSubsBoolStreamExpr(spec *Spec) BoolExpr {
constDecl, ok := spec.Const[this.Name]
if ok {
return constDecl.Val.(BooleanExpr).BExpr
}
return StreamOffsetExpr{this} //othw let it be
}
func (this StreamFetchExpr) ConstantSubsNumStreamExpr(spec *Spec) NumExpr {
constDecl, ok := spec.Const[this.Name]
if ok {
return constDecl.Val.(NumericExpr).NExpr
}
return StreamOffsetExpr{this} //othw let it be
}
func (this StreamFetchExpr) ConstantSubsStrStreamExpr(spec *Spec) StrExpr {
constDecl, ok := spec.Const[this.Name]
if ok {
return constDecl.Val.(StringExpr).StExpr
}
return StreamOffsetExpr{this} //othw let it be
}
//Num
func (this NumLess) ConstantSubsNumCompExpr(spec *Spec) NumComparison {
return NumLess{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this NumLessEq) ConstantSubsNumCompExpr(spec *Spec) NumComparison {
return NumLessEq{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this NumGreater) ConstantSubsNumCompExpr(spec *Spec) NumComparison {
return NumGreater{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this NumGreaterEq) ConstantSubsNumCompExpr(spec *Spec) NumComparison {
return NumGreaterEq{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this NumEq) ConstantSubsNumCompExpr(spec *Spec) NumComparison {
return NumEq{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this NumNotEq) ConstantSubsNumCompExpr(spec *Spec) NumComparison {
return NumNotEq{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this IntLiteralExpr) ConstantSubsNumExpr(spec *Spec) NumExpr {
return this
}
func (this FloatLiteralExpr) ConstantSubsNumExpr(spec *Spec) NumExpr {
return this
}
func (this NumMulExpr) ConstantSubsNumExpr(spec *Spec) NumExpr {
return NumMulExpr{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this NumDivExpr) ConstantSubsNumExpr(spec *Spec) NumExpr {
return NumDivExpr{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this NumPlusExpr) ConstantSubsNumExpr(spec *Spec) NumExpr {
return NumPlusExpr{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this NumMinusExpr) ConstantSubsNumExpr(spec *Spec) NumExpr {
return NumMinusExpr{this.Left.ConstantSubsNumExpr(spec), this.Right.ConstantSubsNumExpr(spec)}
}
func (this StreamOffsetExpr) ConstantSubsNumExpr(spec *Spec) NumExpr {
return this.SExpr.ConstantSubsNumStreamExpr(spec)
}
func (this ConstExpr) ConstantSubsNumExpr(spec *Spec) NumExpr {
constDecl, ok := spec.Const[this.Name]
if ok {
return constDecl.Val.(NumericExpr).NExpr
}
return this //othw let it be
}
//String
func (this StringLiteralExpr) ConstantSubsStrExpr(spec *Spec) StrExpr {
return this
}
func (this StrConcatExpr) ConstantSubsStrExpr(spec *Spec) StrExpr {
return StrConcatExpr{this.Left.ConstantSubsStrExpr(spec), this.Right.ConstantSubsStrExpr(spec)}
}
func (this StreamOffsetExpr) ConstantSubsStrExpr(spec *Spec) StrExpr {
return this.SExpr.ConstantSubsStrStreamExpr(spec)
}
func (this ConstExpr) ConstantSubsStrExpr(spec *Spec) StrExpr {
constDecl, ok := spec.Const[this.Name]
if ok {
return constDecl.Val.(StringExpr).StExpr
}
return this //othw let it be
}
func (this StrEqExpr) ConstantSubsStrCompExpr(spec *Spec) StrComparison {
return StrEqExpr{this.Left.ConstantSubsStrExpr(spec), this.Right.ConstantSubsStrExpr(spec)}
}