Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/src/go-symexpr/getset.go @ 16620

Last change on this file since 16620 was 16620, checked in by hmaislin, 5 years ago

#2929: Reorganized folder structure for make script, removed explicit marshalling, erased go-side logging

File size: 8.7 KB
RevLine 
[16620]1package symexpr
2
3func (n *Time) GetExpr(pos *int) Expr {
4  if (*pos) == 0 {
5    return n
6  }
7  (*pos)--
8  return nil
9}
10func (n *Time) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
11  if (*pos) == 0 {
12    return true, false
13  }
14  (*pos)--
15  return false, false
16}
17
18func (v *Var) GetExpr(pos *int) Expr {
19  if (*pos) == 0 {
20    return v
21  }
22  (*pos)--
23  return nil
24}
25func (v *Var) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
26  if (*pos) == 0 {
27    return true, false
28  }
29  (*pos)--
30  return false, false
31}
32
33func (c *Constant) GetExpr(pos *int) Expr {
34  if (*pos) == 0 {
35    return c
36  }
37  (*pos)--
38  return nil
39}
40func (c *Constant) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
41  if (*pos) == 0 {
42    return true, false
43  }
44  (*pos)--
45  return false, false
46}
47
48func (c *ConstantF) GetExpr(pos *int) Expr {
49  if (*pos) == 0 {
50    return c
51  }
52  (*pos)--
53  return nil
54}
55func (c *ConstantF) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
56  if (*pos) == 0 {
57    return true, false
58  }
59  (*pos)--
60  return false, false
61}
62
63func (s *System) GetExpr(pos *int) Expr {
64  if (*pos) == 0 {
65    return s
66  }
67  (*pos)--
68  return nil
69}
70func (s *System) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
71  if (*pos) == 0 {
72    return true, false
73  }
74  (*pos)--
75  return false, false
76}
77
78func (u *Neg) GetExpr(pos *int) Expr {
79  if (*pos) == 0 {
80    return u
81  }
82  (*pos)--
83  return u.C.GetExpr(pos)
84}
85func (u *Neg) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
86  if (*pos) == 0 {
87    return true, false
88  }
89  (*pos)--
90  if *pos == 0 {
91    u.C = e
92    return false, true
93  }
94  rme, repd := u.C.SetExpr(pos, e)
95  if repd {
96    return false, true
97  }
98  if rme {
99    u.C = e
100    return false, true
101  }
102  return false, repd
103}
104
105func (u *Abs) GetExpr(pos *int) Expr {
106  if (*pos) == 0 {
107    return u
108  }
109  (*pos)--
110  return u.C.GetExpr(pos)
111}
112func (u *Abs) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
113  if (*pos) == 0 {
114    return true, false
115  }
116  (*pos)--
117  if *pos == 0 {
118    u.C = e
119    return false, true
120  }
121  rme, repd := u.C.SetExpr(pos, e)
122  if repd {
123    return false, true
124  }
125  if rme {
126    u.C = e
127    return false, true
128  }
129  return false, repd
130}
131
132func (u *Sqrt) GetExpr(pos *int) Expr {
133  if (*pos) == 0 {
134    return u
135  }
136  (*pos)--
137  return u.C.GetExpr(pos)
138}
139func (u *Sqrt) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
140  if (*pos) == 0 {
141    return true, false
142  }
143  (*pos)--
144  if *pos == 0 {
145    u.C = e
146    return false, true
147  }
148  rme, repd := u.C.SetExpr(pos, e)
149  if repd {
150    return false, true
151  }
152  if rme {
153    u.C = e
154    return false, true
155  }
156  return false, repd
157}
158
159func (u *Sin) GetExpr(pos *int) Expr {
160  if (*pos) == 0 {
161    return u
162  }
163  (*pos)--
164  return u.C.GetExpr(pos)
165}
166func (u *Sin) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
167  if (*pos) == 0 {
168    return true, false
169  }
170  (*pos)--
171  if *pos == 0 {
172    u.C = e
173    return false, true
174  }
175  rme, repd := u.C.SetExpr(pos, e)
176  if repd {
177    return false, true
178  }
179  if rme {
180    u.C = e
181    return false, true
182  }
183  return false, repd
184}
185
186func (u *Cos) GetExpr(pos *int) Expr {
187  if (*pos) == 0 {
188    return u
189  }
190  (*pos)--
191  return u.C.GetExpr(pos)
192}
193func (u *Cos) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
194  if (*pos) == 0 {
195    return true, false
196  }
197  (*pos)--
198  if *pos == 0 {
199    u.C = e
200    return false, true
201  }
202  rme, repd := u.C.SetExpr(pos, e)
203  if repd {
204    return false, true
205  }
206  if rme {
207    u.C = e
208    return false, true
209  }
210  return false, repd
211}
212
213func (u *Tan) GetExpr(pos *int) Expr {
214  if (*pos) == 0 {
215    return u
216  }
217  (*pos)--
218  return u.C.GetExpr(pos)
219}
220func (u *Tan) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
221  if (*pos) == 0 {
222    return true, false
223  }
224  (*pos)--
225  if *pos == 0 {
226    u.C = e
227    return false, true
228  }
229  rme, repd := u.C.SetExpr(pos, e)
230  if repd {
231    return false, true
232  }
233  if rme {
234    u.C = e
235    return false, true
236  }
237  return false, repd
238}
239
240func (u *Exp) GetExpr(pos *int) Expr {
241  if (*pos) == 0 {
242    return u
243  }
244  (*pos)--
245  return u.C.GetExpr(pos)
246}
247
248func (u *Log) GetExpr(pos *int) Expr {
249  if (*pos) == 0 {
250    return u
251  }
252  (*pos)--
253  return u.C.GetExpr(pos)
254}
255
256func (u *PowI) GetExpr(pos *int) Expr {
257  if (*pos) == 0 {
258    return u
259  }
260  (*pos)--
261  return u.Base.GetExpr(pos)
262}
263
264func (u *PowF) GetExpr(pos *int) Expr {
265  if (*pos) == 0 {
266    return u
267  }
268  (*pos)--
269  return u.Base.GetExpr(pos)
270}
271
272func (n *PowE) GetExpr(pos *int) Expr {
273  if (*pos) == 0 {
274    return n
275  }
276  (*pos)--
277  tmp := n.Base.GetExpr(pos)
278  if tmp != nil {
279    return tmp
280  }
281  return n.Power.GetExpr(pos)
282}
283
284func (n *Div) GetExpr(pos *int) Expr {
285  if (*pos) == 0 {
286    return n
287  }
288  (*pos)--
289  tmp := n.Numer.GetExpr(pos)
290  if tmp != nil {
291    return tmp
292  }
293  return n.Denom.GetExpr(pos)
294}
295
296func (n *Add) GetExpr(pos *int) Expr {
297  if (*pos) == 0 {
298    return n
299  }
300  (*pos)--
301  for _, C := range n.CS {
302    if C == nil {
303      continue
304    }
305    tmp := C.GetExpr(pos)
306    if tmp != nil {
307      return tmp
308    }
309    if *pos < 0 {
310      return nil
311    }
312  }
313  return nil
314}
315
316func (n *Mul) GetExpr(pos *int) Expr {
317  if (*pos) == 0 {
318    return n
319  }
320  (*pos)--
321  for _, C := range n.CS {
322    if C == nil {
323      continue
324    }
325    tmp := C.GetExpr(pos)
326    if tmp != nil {
327      return tmp
328    }
329    if *pos < 0 {
330      return nil
331    }
332  }
333  return nil
334}
335
336func SwapExpr(orig, newt Expr, pos int) (ret Expr) {
337  //   fmt.Printf( "SWAP orig  %v\n", orig )
338  p := pos
339  //   oldt := orig.GetExpr(&p)
340  //   fmt.Printf( "SWAP (%d)\n%v\n%v\n", pos, oldt, newt )
341  rme, _ := orig.SetExpr(&p, newt)
342  if rme {
343    ret = newt
344  }
345
346  //   fmt.Printf( "SWAP ret  %v\n", ret )
347  return
348}
349
350func (u *Exp) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
351  if (*pos) == 0 {
352    return true, false
353  }
354  (*pos)--
355  if *pos == 0 {
356    u.C = e
357    return false, true
358  }
359  rme, repd := u.C.SetExpr(pos, e)
360  if repd {
361    return false, true
362  }
363  if rme {
364    u.C = e
365    return false, true
366  }
367  return false, repd
368}
369func (u *Log) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
370  if (*pos) == 0 {
371    return true, false
372  }
373  (*pos)--
374  if *pos == 0 {
375    u.C = e
376    return false, true
377  }
378  rme, repd := u.C.SetExpr(pos, e)
379  if repd {
380    return false, true
381  }
382  if rme {
383    u.C = e
384    return false, true
385  }
386  return false, repd
387}
388func (u *PowI) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
389  if (*pos) == 0 {
390    return true, false
391  }
392  (*pos)--
393  if *pos == 0 {
394    u.Base = e
395    return false, true
396  }
397  rme, repd := u.Base.SetExpr(pos, e)
398  if repd {
399    return false, true
400  }
401  if rme {
402    u.Base = e
403    return false, true
404  }
405  return false, repd
406}
407func (u *PowF) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
408  if (*pos) == 0 {
409    return true, false
410  }
411  (*pos)--
412  if *pos == 0 {
413    u.Base = e
414    return false, true
415  }
416  rme, repd := u.Base.SetExpr(pos, e)
417  if repd {
418    return false, true
419  }
420  if rme {
421    u.Base = e
422    return false, true
423  }
424  return false, repd
425}
426
427func (n *Add) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
428  if (*pos) == 0 {
429    return true, false
430  }
431  (*pos)--
432  var rme, repd bool
433  for i, C := range n.CS {
434    if C == nil {
435      continue
436    }
437    rme, repd = C.SetExpr(pos, e)
438    if repd {
439      return false, true
440    }
441    if rme {
442      n.CS[i] = e
443      return false, true
444    }
445  }
446  if *pos == 0 {
447    n.CS = append(n.CS, e)
448    return false, true
449  }
450  return false, repd
451}
452
453func (n *Mul) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
454  if (*pos) == 0 {
455    return true, false
456  }
457  (*pos)--
458  var rme, repd bool
459  for i, C := range n.CS {
460    if C == nil {
461      continue
462    }
463    rme, repd = C.SetExpr(pos, e)
464    if repd {
465      return false, true
466    }
467    if rme {
468      n.CS[i] = e
469      return false, true
470    }
471  }
472  if *pos == 0 {
473    n.CS = append(n.CS, e)
474    return false, true
475  }
476  return false, repd
477}
478func (n *Div) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
479  if (*pos) == 0 {
480    return true, false
481  }
482  (*pos)--
483  if *pos == 0 {
484    n.Numer = e
485    return false, true
486  }
487  rme, repd := n.Numer.SetExpr(pos, e)
488  if repd {
489    return false, true
490  }
491  if rme {
492    n.Numer = e
493    return false, true
494  }
495  if *pos == 0 {
496    n.Denom = e
497    return false, true
498  }
499  rme, repd = n.Denom.SetExpr(pos, e)
500  if repd {
501    return false, true
502  }
503  if rme {
504    n.Denom = e
505    return false, true
506  }
507  return false, repd
508}
509func (n *PowE) SetExpr(pos *int, e Expr) (replace_me, replaced bool) {
510  if (*pos) == 0 {
511    return true, false
512  }
513  (*pos)--
514  if *pos == 0 {
515    n.Base = e
516    return false, true
517  }
518  rme, repd := n.Base.SetExpr(pos, e)
519  if repd {
520    return false, true
521  }
522  if rme {
523    n.Power = e
524    return false, true
525  }
526  if *pos == 0 {
527    n.Power = e
528    return false, true
529  }
530  rme, repd = n.Power.SetExpr(pos, e)
531  if repd {
532    return false, true
533  }
534  if rme {
535    n.Power = e
536    return false, true
537  }
538  return false, repd
539}
Note: See TracBrowser for help on using the repository browser.