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
|
// this is being called recursively over the whole tree. if "ordering" is "caring", then the
// parent op wants the lists ordered, otherwise it doesn't care
%operation %virtual void set_ordering(expression *this, ordering_type ordering)
set_ordering(expression)
{
this->ordering = ordering;
}
set_ordering(unary)
{
this->ordering = ordering;
set_ordering(this->expr, ordering);
}
set_ordering(binary)
{
this->ordering = ordering;
set_ordering(this->expr1, ordering);
set_ordering(this->expr2, ordering);
}
set_ordering(sum)
{
this->ordering = ordering;
set_ordering(this->expr, agnostic);
}
set_ordering(prod)
{
this->ordering = ordering;
set_ordering(this->expr, agnostic);
}
set_ordering(count)
{
this->ordering = ordering;
set_ordering(this->expr, agnostic);
}
set_ordering(sort)
{
this->ordering = ordering;
set_ordering(this->expr, agnostic);
}
set_ordering(perm)
{
this->ordering = ordering;
set_ordering(this->expr, agnostic);
}
set_ordering(first)
{
this->ordering = ordering;
set_ordering(this->expr1, agnostic);
set_ordering(this->expr2, caring);
}
set_ordering(last)
{
this->ordering = ordering;
set_ordering(this->expr1, agnostic);
set_ordering(this->expr2, caring);
}
set_ordering(ifthenelse)
{
this->ordering = ordering;
set_ordering(this->if_expr, agnostic);
set_ordering(this->then_expr, ordering);
set_ordering(this->else_expr, ordering);
}
set_ordering(variable)
{
this->ordering = ordering;
// get the symtab
struct symtab *nst = this->symtab;
while (nst != NULL) {
if (strcmp(this->varname, nst->name) == 0) {
break;
}
nst = nst->next;
}
if (nst && nst->ordering == agnostic) {
nst->ordering = ordering;
}
}
set_ordering(let)
{
this->ordering = ordering;
struct symtab *nst = (struct symtab*)malloc(sizeof(struct symtab));
nst->name = this->varname;
nst->ordering = agnostic;
nst->next = this->symtab;
set_symtab(this->expr2, nst);
set_ordering(this->expr2, ordering);
set_ordering(this->expr1, nst->ordering);
free(nst);
}
|