-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstantiateExpr.go
667 lines (632 loc) · 23.1 KB
/
InstantiateExpr.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
package dLola
import (
"fmt"
"strconv"
)
//Expression
type InstExpr interface {
Sprint() string
Substitute(InstStreamExpr, InstExpr) InstExpr
Simplify() (InstExpr, bool)
Udependencies(adj []Adj, depen map[InstStreamExpr]struct{})
}
type InstConstExpr struct { // implements Expr,NumExpr,BoolExpr
Name StreamName
Pos Position
}
type InstLetExpr struct {
Name StreamName
Bind InstExpr
Body InstExpr
}
type InstIfThenElseExpr struct { // implements Expr,NumExpr,BoolExpr
If InstExpr
Then InstExpr
Else InstExpr
}
type InstStreamOffsetExpr struct { // StreamOffsetExpr implements Expr,NumExpr,BoolExpr, StrExpr
SExpr InstStreamExpr
}
type InstBooleanExpr struct {
BExpr InstBoolExpr
}
type InstNumericExpr struct {
NExpr InstNumExpr
}
type InstStringExpr struct {
StExpr InstStrExpr
}
//Stream
type InstStreamExpr interface {
Sprint() string
Substitute(InstStreamExpr, InstExpr) InstExpr
SubstituteBool(InstStreamExpr, InstExpr) InstBoolExpr
SubstituteNum(InstStreamExpr, InstExpr) InstNumExpr
SubstituteStr(InstStreamExpr, InstExpr) InstStrExpr
Udependencies(adj []Adj, depen map[InstStreamExpr]struct{})
GetName() StreamName
GetTick() int
Eq(InstStreamExpr) bool
//Simplify() InstExpr THESE WILL NOT BE USED AS AN INSTANTIATED STREAM CANNOT BE SIMPLIFIED
//SimplifyBool() InstBoolExpr
//SimplifyNum() InstNumExpr
//SimplifyStr() InstStrExpr
}
func SprintStreams(streams []InstStreamExpr) string {
r := "["
for _, s := range streams {
r += s.Sprint()
}
r += "]"
return r
}
func elemStream(as []InstStreamExpr, a InstStreamExpr, f func(InstStreamExpr, InstStreamExpr) bool) bool { //will usually be called with f = EqInstStreamExpr
//fmt.Printf("path %v, node %s", path, node)
is := false
for i := 0; i < len(as) && !is; i++ {
if f(a, as[i]) {
is = true
}
}
return is
}
func EqInstStreamExpr(this, s InstStreamExpr) bool {
return this.Eq(s)
}
type InstStreamFetchExpr struct { //implements StreamExpr
Name StreamName
Tick int
//Default DefaultExpr //default value for the instantiated stream that gets out of the trace
//Pos Position
}
func (this InstStreamFetchExpr) GetName() StreamName {
return this.Name
}
func (this InstStreamFetchExpr) GetTick() int {
return this.Tick
}
func (this InstStreamFetchExpr) Eq(s InstStreamExpr) bool {
return this.GetName() == s.GetName() && this.GetTick() == s.GetTick()
}
//Boolean
type InstBoolExpr interface {
Sprint() string
SubstituteBool(InstStreamExpr, InstExpr) InstBoolExpr
SimplifyBool() (InstBoolExpr, bool)
UdependenciesBool(adj []Adj, depen map[InstStreamExpr]struct{})
}
type InstTruePredicate struct{ Pos Position }
type InstFalsePredicate struct{ Pos Position }
type InstNotPredicate struct {
Inner InstBoolExpr
}
type InstAndPredicate struct {
Left InstBoolExpr
Right InstBoolExpr
}
type InstOrPredicate struct {
Left InstBoolExpr
Right InstBoolExpr
}
type InstIfThenElsePredicate struct {
If InstBoolExpr
Then InstBoolExpr
Else InstBoolExpr
}
type InstNumComparisonPredicate struct {
Comp InstNumComparison
}
type InstStrComparisonPredicate struct {
Comp InstStrComparison
}
//Numeric
type InstNumComparison interface {
Sprint() string
SubstituteNumComp(InstStreamExpr, InstExpr) InstNumComparison
SimplifyNumComp() (InstBoolExpr, bool)
UdependenciesNumComp(adj []Adj, depen map[InstStreamExpr]struct{})
}
type InstNumLess struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumLessEq struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumEq struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumGreater struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumGreaterEq struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumNotEq struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumExpr interface {
Sprint() string
SubstituteNum(InstStreamExpr, InstExpr) InstNumExpr
SimplifyNum() (InstNumExpr, bool)
UdependenciesNum(adj []Adj, depen map[InstStreamExpr]struct{})
}
type InstIntLiteralExpr struct {
Num int
// Pos Position
}
type InstFloatLiteralExpr struct {
Num float32
// Pos Position
}
type InstNumMulExpr struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumDivExpr struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumPlusExpr struct {
Left InstNumExpr
Right InstNumExpr
}
type InstNumMinusExpr struct {
Left InstNumExpr
Right InstNumExpr
}
//String
type InstStrExpr interface {
Sprint() string
SubstituteStr(InstStreamExpr, InstExpr) InstStrExpr
SimplifyStr() (InstStrExpr, bool)
UdependenciesStr(adj []Adj, depen map[InstStreamExpr]struct{})
}
type InstStringLiteralExpr struct {
S string
// Pos Position
}
type InstStrConcatExpr struct {
Left InstStrExpr
Right InstStrExpr
}
type InstStrComparison interface {
Sprint() string
SubstituteStrComp(InstStreamExpr, InstExpr) InstStrComparison
SimplifyStrComp() (InstBoolExpr, bool)
UdependenciesStrComp(adj []Adj, depen map[InstStreamExpr]struct{})
}
type InstStrEqExpr struct {
Left InstStrExpr
Right InstStrExpr
}
func (this ConstExpr) InstantiateExpr(tick, tlen int) InstExpr {
return InstConstExpr{this.Name, this.Pos}
}
func (this LetExpr) InstantiateExpr(tick, tlen int) InstExpr {
//fmt.Printf("Instantiating expr %s\n", this.Sprint())
bind := SimplifyExpr(this.Bind.InstantiateExpr(tick, tlen))
body := this.Body.InstantiateExpr(tick, tlen) //recursive call
if isGround(bind) {
//fmt.Printf("Bind is ground %s\n", bind.Sprint())
bodySub := body.Substitute(InstStreamFetchExpr{this.Name, 0}, bind)
return SimplifyExpr(bodySub) //we remove a bind of the let expr, simplifying it
}
body = SimplifyExpr(body)
return InstLetExpr{this.Name, bind, body}
}
func (this IfThenElseExpr) InstantiateExpr(tick, tlen int) InstExpr {
return InstIfThenElseExpr{this.If.InstantiateExpr(tick, tlen), this.Then.InstantiateExpr(tick, tlen), this.Else.InstantiateExpr(tick, tlen)}
}
func (this StreamOffsetExpr) InstantiateExpr(tick, tlen int) InstExpr { // expr = a[x|d] we will use the default value to infer the type
return this.SExpr.InstantiateStreamExpr(tick, tlen) //note it does not follow the pattern of the rest
}
func (this BooleanExpr) InstantiateExpr(tick, tlen int) InstExpr {
return InstBooleanExpr{this.BExpr.InstantiateBoolExpr(tick, tlen)}
}
func (this NumericExpr) InstantiateExpr(tick, tlen int) InstExpr {
return InstNumericExpr{this.NExpr.InstantiateNumExpr(tick, tlen)}
}
func (this StringExpr) InstantiateExpr(tick, tlen int) InstExpr {
return InstStringExpr{this.StExpr.InstantiateStrExpr(tick, tlen)}
}
//Boolean
func (this TruePredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstTruePredicate{}
}
func (this FalsePredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstFalsePredicate{}
}
func (this NotPredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstNotPredicate{this.Inner.InstantiateBoolExpr(tick, tlen)}
}
func (this StreamOffsetExpr) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return this.SExpr.InstantiateBoolStreamExpr(tick, tlen)
}
func (this ConstExpr) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstConstExpr{this.Name, this.Pos}
}
func (this AndPredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstAndPredicate{this.Left.InstantiateBoolExpr(tick, tlen), this.Right.InstantiateBoolExpr(tick, tlen)}
}
func (this OrPredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstOrPredicate{this.Left.InstantiateBoolExpr(tick, tlen), this.Right.InstantiateBoolExpr(tick, tlen)}
}
/*func (this IfThenElsePredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstIfThenElsePredicate{this.If.InstantiateBoolExpr(tick, tlen), this.Then.InstantiateBoolExpr(tick, tlen), this.Else.InstantiateBoolExpr(tick, tlen)}
}*/
func (this NumComparisonPredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstNumComparisonPredicate{this.Comp.InstantiateNumCompExpr(tick, tlen)}
}
func (this StrComparisonPredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstStrComparisonPredicate{this.Comp.InstantiateStrCompExpr(tick, tlen)}
}
//Stream
func (this StreamFetchExpr) InstantiateStreamExpr(tick, tlen int) InstExpr {
if this.Offset.val+tick < 0 || this.Offset.val+tick >= tlen {
return convertToInstExpr(this.Default)
}
r := InstStreamOffsetExpr{InstStreamFetchExpr{this.Name, this.Offset.val + tick}}
// fmt.Printf("Instantiated stream: %s for tick %d with tlen %d\n", r.Sprint(), tick, tlen)
return r
}
func convertToInstExpr(d DefaultExpr) InstExpr {
var r InstExpr
switch v := d.val.(type) {
case TruePredicate:
r = InstTruePredicate{}
case FalsePredicate:
r = InstFalsePredicate{}
case IntLiteralExpr:
r = InstIntLiteralExpr{v.Num}
case FloatLiteralExpr:
r = InstFloatLiteralExpr{v.Num}
case StringLiteralExpr:
r = InstStringLiteralExpr{v.S}
default: //will occurr for streams used as s = r without specifying default values
panic("Impossible to convert other thing to InstExpr\n")
}
return r
}
func (this StreamFetchExpr) InstantiateBoolStreamExpr(tick, tlen int) InstBoolExpr {
if this.Offset.val+tick < 0 || this.Offset.val+tick > tlen {
return convertToInstExpr(this.Default).(InstBoolExpr)
}
r := InstStreamOffsetExpr{InstStreamFetchExpr{this.Name, this.Offset.val + tick}}
// fmt.Printf("Instantiated stream: %s for tick %d with tlen %d\n", r.Sprint(), tick, tlen)
return r
}
func (this StreamFetchExpr) InstantiateNumStreamExpr(tick, tlen int) InstNumExpr {
if this.Offset.val+tick < 0 || this.Offset.val+tick > tlen {
return convertToInstExpr(this.Default).(InstNumExpr)
}
r := InstStreamOffsetExpr{InstStreamFetchExpr{this.Name, this.Offset.val + tick}}
// fmt.Printf("Instantiated stream: %s for tick %d with tlen %d\n", r.Sprint(), tick, tlen)
return r
}
func (this StreamFetchExpr) InstantiateStrStreamExpr(tick, tlen int) InstStrExpr {
if this.Offset.val+tick < 0 || this.Offset.val+tick > tlen {
return convertToInstExpr(this.Default).(InstStrExpr)
}
r := InstStreamOffsetExpr{InstStreamFetchExpr{this.Name, this.Offset.val + tick}}
// fmt.Printf("Instantiated stream: %s for tick %d with tlen %d\n", r.Sprint(), tick, tlen)
return r
}
//Num
func (this NumLess) InstantiateNumCompExpr(tick, tlen int) InstNumComparison {
return InstNumLess{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this NumLessEq) InstantiateNumCompExpr(tick, tlen int) InstNumComparison {
return InstNumLessEq{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this NumGreater) InstantiateNumCompExpr(tick, tlen int) InstNumComparison {
return InstNumGreater{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this NumGreaterEq) InstantiateNumCompExpr(tick, tlen int) InstNumComparison {
return InstNumGreaterEq{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this NumEq) InstantiateNumCompExpr(tick, tlen int) InstNumComparison {
return InstNumEq{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this NumNotEq) InstantiateNumCompExpr(tick, tlen int) InstNumComparison {
return InstNumNotEq{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this IntLiteralExpr) InstantiateNumExpr(tick, tlen int) InstNumExpr {
return InstIntLiteralExpr{this.Num}
}
func (this FloatLiteralExpr) InstantiateNumExpr(tick, tlen int) InstNumExpr {
return InstFloatLiteralExpr{this.Num}
}
func (this NumMulExpr) InstantiateNumExpr(tick, tlen int) InstNumExpr {
return InstNumMulExpr{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this NumDivExpr) InstantiateNumExpr(tick, tlen int) InstNumExpr {
return InstNumDivExpr{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this NumPlusExpr) InstantiateNumExpr(tick, tlen int) InstNumExpr {
return InstNumPlusExpr{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this NumMinusExpr) InstantiateNumExpr(tick, tlen int) InstNumExpr {
return InstNumMinusExpr{this.Left.InstantiateNumExpr(tick, tlen), this.Right.InstantiateNumExpr(tick, tlen)}
}
func (this StreamOffsetExpr) InstantiateNumExpr(tick, tlen int) InstNumExpr {
return this.SExpr.InstantiateNumStreamExpr(tick, tlen)
}
func (this ConstExpr) InstantiateNumExpr(tick, tlen int) InstNumExpr {
return InstConstExpr{this.Name, this.Pos}
}
//String
func (this StringLiteralExpr) InstantiateStrExpr(tick, tlen int) InstStrExpr {
return InstStringLiteralExpr{this.S}
}
func (this StrConcatExpr) InstantiateStrExpr(tick, tlen int) InstStrExpr {
return InstStrConcatExpr{this.Left.InstantiateStrExpr(tick, tlen), this.Right.InstantiateStrExpr(tick, tlen)}
}
func (this StreamOffsetExpr) InstantiateStrExpr(tick, tlen int) InstStrExpr {
return this.SExpr.InstantiateStrStreamExpr(tick, tlen)
}
func (this ConstExpr) InstantiateStrExpr(tick, tlen int) InstStrExpr {
return InstConstExpr{this.Name, this.Pos}
}
func (this StrEqExpr) InstantiateStrCompExpr(tick, tlen int) InstStrComparison {
return InstStrEqExpr{this.Left.InstantiateStrExpr(tick, tlen), this.Right.InstantiateStrExpr(tick, tlen)}
}
//Sprint
//Expr
func (this InstConstExpr) Sprint() string {
return string(this.Name)
}
func (this InstLetExpr) Sprint() string {
bind := this.Bind.Sprint()
body := this.Body.Sprint()
return fmt.Sprintf("let %s = %s in %s", this.Name, bind, body)
}
func (this InstIfThenElseExpr) Sprint() string {
if_part := this.If.Sprint()
then_part := this.Then.Sprint()
else_part := this.Else.Sprint()
return fmt.Sprintf("if %s then %s else %s", if_part, then_part, else_part)
}
func (this InstNumericExpr) Sprint() string {
return this.NExpr.Sprint()
}
func (this InstStreamOffsetExpr) Sprint() string {
return this.SExpr.Sprint()
}
func (this InstBooleanExpr) Sprint() string {
return this.BExpr.Sprint()
}
func (this InstStringExpr) Sprint() string {
return this.StExpr.Sprint()
}
//Stream
func (this InstStreamFetchExpr) Sprint() string {
return fmt.Sprintf("%s[%d]", this.Name.Sprint(), this.Tick)
}
//predicates
func (this InstAndPredicate) Sprint() string {
return fmt.Sprintf("(%s) /\\ (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstOrPredicate) Sprint() string {
return fmt.Sprintf("(%s) \\/ (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstNotPredicate) Sprint() string {
return fmt.Sprintf("~ (%s)", this.Inner.Sprint())
}
func (this InstTruePredicate) Sprint() string {
return fmt.Sprintf("true")
}
func (this InstFalsePredicate) Sprint() string {
return fmt.Sprintf("false")
}
func (this InstNumComparisonPredicate) Sprint() string {
return this.Comp.Sprint()
}
func (this InstStrComparisonPredicate) Sprint() string {
return this.Comp.Sprint()
}
//numeric
func (this InstNumLess) Sprint() string {
return fmt.Sprintf("(%s) < (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstNumLessEq) Sprint() string {
return fmt.Sprintf("(%s) <= (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstNumGreater) Sprint() string {
return fmt.Sprintf("(%s) > (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstNumGreaterEq) Sprint() string {
return fmt.Sprintf("(%s) >= (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstNumNotEq) Sprint() string {
return fmt.Sprintf("(%s) != (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstNumEq) Sprint() string {
return fmt.Sprintf("(%s) = (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstNumMulExpr) Sprint() string {
return fmt.Sprintf("(%s)%s(%s)", this.Left.Sprint(), "*", this.Right.Sprint())
}
func (this InstNumDivExpr) Sprint() string {
return fmt.Sprintf("(%s)%s(%s)", this.Left.Sprint(), "/", this.Right.Sprint())
}
func (this InstNumPlusExpr) Sprint() string {
return fmt.Sprintf("(%s)%s(%s)", this.Left.Sprint(), "+", this.Right.Sprint())
}
func (this InstNumMinusExpr) Sprint() string {
return fmt.Sprintf("(%s)%s(%s)", this.Left.Sprint(), "-", this.Right.Sprint())
}
func (this InstIntLiteralExpr) Sprint() string {
return strconv.Itoa(this.Num)
}
func (this InstFloatLiteralExpr) Sprint() string {
return strconv.FormatFloat(float64(this.Num), 'f', 4, 32)
}
//string
func (this InstStringLiteralExpr) Sprint() string {
return this.S
}
func (this InstStrConcatExpr) Sprint() string {
return fmt.Sprintf("(%s) strConcat (%s)", this.Left.Sprint(), this.Right.Sprint())
}
func (this InstStrEqExpr) Sprint() string {
return fmt.Sprintf("(%s) strEq (%s)", this.Left.Sprint(), this.Right.Sprint())
}
//Substitute
func (this InstConstExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return this
}
func (this InstLetExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return InstLetExpr{this.Name, this.Bind.Substitute(s, v), this.Body.Substitute(s, v)}
}
func (this InstIfThenElseExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return InstIfThenElseExpr{this.If.Substitute(s, v), this.Then.Substitute(s, v), this.Else.Substitute(s, v)}
}
func (this InstStreamOffsetExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return this.SExpr.Substitute(s, v) //note it does not follow the pattern of the rest
}
func (this InstBooleanExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return InstBooleanExpr{this.BExpr.SubstituteBool(s, v)}
}
func (this InstNumericExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return InstNumericExpr{this.NExpr.SubstituteNum(s, v)}
}
func (this InstStringExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return InstStringExpr{this.StExpr.SubstituteStr(s, v)}
}
//Boolean
func (this InstTruePredicate) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return this
}
func (this InstFalsePredicate) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return this
}
func (this InstNotPredicate) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return InstNotPredicate{this.Inner.SubstituteBool(s, v)}
}
func (this InstStreamOffsetExpr) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return this.SExpr.SubstituteBool(s, v)
}
func (this InstConstExpr) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return this
}
func (this InstAndPredicate) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return InstAndPredicate{this.Left.SubstituteBool(s, v), this.Right.SubstituteBool(s, v)}
}
func (this InstOrPredicate) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return InstOrPredicate{this.Left.SubstituteBool(s, v), this.Right.SubstituteBool(s, v)}
}
/*func (this InstIfThenElsePredicate) InstantiateBoolExpr(tick, tlen int) InstBoolExpr {
return InstIfThenElsePredicate{this.If.Substitute(s, v), this.Then.Substitute(s, v), this.Else.Substitute(s, v)}
}*/
func (this InstNumComparisonPredicate) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return InstNumComparisonPredicate{this.Comp.SubstituteNumComp(s, v)}
}
func (this InstStrComparisonPredicate) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
return InstStrComparisonPredicate{this.Comp.SubstituteStrComp(s, v)}
}
//Stream
func (this InstStreamFetchExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
if s.GetName() == this.Name && this.Tick == s.GetTick() {
return v
}
return InstStreamOffsetExpr{this}
}
func (this InstStreamFetchExpr) SubstituteBool(s InstStreamExpr, v InstExpr) InstBoolExpr {
if s.GetName() == this.Name && this.Tick == s.GetTick() {
return v.(InstBoolExpr)
}
return InstStreamOffsetExpr{this}
}
func (this InstStreamFetchExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
if s.GetName() == this.Name && this.Tick == s.GetTick() {
return v.(InstNumExpr)
}
return InstStreamOffsetExpr{this}
}
func (this InstStreamFetchExpr) SubstituteStr(s InstStreamExpr, v InstExpr) InstStrExpr {
if s.GetName() == this.Name && this.Tick == s.GetTick() {
return v.(InstStrExpr)
}
return InstStreamOffsetExpr{this}
}
//Num
func (this InstNumLess) SubstituteNumComp(s InstStreamExpr, v InstExpr) InstNumComparison {
return InstNumLess{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstNumLessEq) SubstituteNumComp(s InstStreamExpr, v InstExpr) InstNumComparison {
return InstNumLessEq{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstNumGreater) SubstituteNumComp(s InstStreamExpr, v InstExpr) InstNumComparison {
return InstNumGreater{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstNumGreaterEq) SubstituteNumComp(s InstStreamExpr, v InstExpr) InstNumComparison {
return InstNumGreaterEq{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstNumEq) SubstituteNumComp(s InstStreamExpr, v InstExpr) InstNumComparison {
return InstNumEq{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstNumNotEq) SubstituteNumComp(s InstStreamExpr, v InstExpr) InstNumComparison {
return InstNumNotEq{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstIntLiteralExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
return this
}
func (this InstFloatLiteralExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
return this
}
func (this InstNumMulExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
return InstNumMulExpr{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstNumDivExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
return InstNumDivExpr{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstNumPlusExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
return InstNumPlusExpr{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstNumMinusExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
return InstNumMinusExpr{this.Left.SubstituteNum(s, v), this.Right.SubstituteNum(s, v)}
}
func (this InstStreamOffsetExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
return this.SExpr.SubstituteNum(s, v)
}
func (this InstConstExpr) SubstituteNum(s InstStreamExpr, v InstExpr) InstNumExpr {
return this
}
//String
func (this InstStringLiteralExpr) SubstituteStr(s InstStreamExpr, v InstExpr) InstStrExpr {
return this
}
func (this InstStrConcatExpr) SubstituteStr(s InstStreamExpr, v InstExpr) InstStrExpr {
return InstStrConcatExpr{this.Left.SubstituteStr(s, v), this.Right.SubstituteStr(s, v)}
}
func (this InstStreamOffsetExpr) SubstituteStr(s InstStreamExpr, v InstExpr) InstStrExpr {
return this.SExpr.SubstituteStr(s, v)
}
func (this InstConstExpr) SubstituteStr(s InstStreamExpr, v InstExpr) InstStrExpr {
return this
}
func (this InstStrEqExpr) SubstituteStrComp(s InstStreamExpr, v InstExpr) InstStrComparison {
return InstStrEqExpr{this.Left.SubstituteStr(s, v), this.Right.SubstituteStr(s, v)}
}
//Literals need to implement InstExpr to compile, implementation of Substitute will be used for resolved streams
func (this InstTruePredicate) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return this
}
func (this InstFalsePredicate) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return this
}
func (this InstIntLiteralExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return this
}
func (this InstFloatLiteralExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return this
}
func (this InstStringLiteralExpr) Substitute(s InstStreamExpr, v InstExpr) InstExpr {
return this
}