-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexpression.sig
215 lines (181 loc) · 8.36 KB
/
expression.sig
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
(* $Id$
*
* Copyright (c) 2008 Timothy Bourke (University of NSW and NICTA)
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the "BSD License" which is distributed with the
* software in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the BSD
* License for more details.
*)
(* Notes:
* * Uppaal does not permit recursive records (no pointers)
* * Uppaal does not permit array assignment
* * meta and const prefixes are incompatible and may only be used for
* `Integers, booleans, and arrays and records over integers and booleans
* can be marked as meta/const variables...'
* * Scalar: only assignment and identity testing.
* * Structs are not named.
* * The `urgent' qualifier must precede `broadcast' (behaviour of Uppaal).
* * The conditional expression (?:) may appear on the LHS of an assignment.
*)
signature EXPRESSION =
sig
type symbol = Atom.atom
type unique = int
val uniqueTag: unit -> unique
datatype tyqual = NoQual | Meta | Const
datatype direction = Output (* c! *)
| Input (* c? *)
datatype unaryModOp = PreIncOp (* ++_ *)
| PostIncOp (* _++ *)
| PreDecOp (* --_ *)
| PostDecOp (* _-- *)
datatype binIntOp = PlusOp (* + *)
| MinusOp (* - *)
| TimesOp (* * *)
| DivideOp (* / *)
| ModOp (* % *)
| BAndOp (* & *)
| BOrOp (* | *)
| BXorOp (* ^ *)
| ShlOp (* << *)
| ShrOp (* >> *)
| MinOp (* <? *)
| MaxOp (* >? *)
datatype rel = LtOp (* < *)
| LeOp (* <= *)
| EqOp (* == *)
| NeOp (* != *)
| GeOp (* >= *)
| GtOp (* > *)
datatype binBoolOp = AndOp (* && *)
| OrOp (* || *)
| ImplyOp (* imply *)
datatype assignOp = AssignOp (* =/:= *)
| PlusEqOp (* += *)
| MinusEqOp (* -= *)
| TimesEqOp (* *= *)
| DivideEqOp(* /= *)
| ModEqOp (* %= *)
| BOrEqOp (* |= *)
| BAndEqOp (* &= *)
| BXorEqOp (* ^= *)
| ShlEqOp (* <<= *)
| ShrEqOp (* >>= *)
datatype var = SimpleVar of symbol
| ReturnVar of {func: symbol, args: expr list}
| RecordVar of var * symbol
| SubscriptVar of var * expr
and ty = VOID
| INT of (expr * expr) option * tyqual
| BOOL of tyqual
| CLOCK
| CHANNEL of {urgent: bool, broadcast: bool}
| SCALAR of expr * tyqual * unique
| RECORD of (symbol * ty) list * tyqual * unique
| ARRAY of ty * unresolvedty
| NAME of symbol * tyqual * ty option
(* last component of NAME is the fully expanded
version incorporating the tyqual. *)
and expr = VarExpr of var
| IntCExpr of int
| BoolCExpr of bool
| CallExpr of {func: symbol, args: expr list}
| NegExpr of expr
| NotExpr of expr
| UnaryModExpr of {uop: unaryModOp, expr: expr}
| BinIntExpr of {left: expr,
bop: binIntOp,
right: expr}
| BinBoolExpr of {left: expr,
bop: binBoolOp,
right: expr}
| RelExpr of {left: expr,
rel: rel,
right: expr}
| AssignExpr of {var: expr,
aop: assignOp,
expr: expr}
| CondExpr of {test: expr,
trueexpr: expr,
falseexpr: expr}
| ForAllExpr of {id: symbol,
ty: ty,
expr: expr}
| ExistsExpr of {id: symbol,
ty: ty,
expr: expr}
| Deadlock
and boundid = BoundId of symbol * ty
and unresolvedty = Type of ty
| Unresolved of symbol (* could be a typedef or
a variable (INT[0, x]) *)
val varName : var -> string
(* return a name suitable for debugging output and error messages *)
val tyQual : ty -> tyqual
val getFreeNames : expr -> AtomSet.set
val getBoundNames : boundid list -> AtomSet.set
val renameVar : {old : symbol, new: symbol} * expr -> expr
val renameVars : symbol AtomMap.map -> expr -> expr
(* simultaneous renaming *)
val stripArray : ty -> (ty * ty list)
val trueExpr : expr
val falseExpr : expr
val conflictExists : AtomSet.set * AtomSet.set * expr -> bool
(* Looks (with over-approximation) through Boolean formulae for terms that
contain variables from both sets, returning true if one is found. *)
val ensureNoBindingConflict : (boundid list * expr) ->
(boundid list * expr) -> (boundid list * expr)
(* (l', e') = ensureNoBindingConflict (rl, re) (l, e)
* Renames bound variables (l => l') in (e => e') to ensure that combination
* with the reference expression will not capture names improperly.
*
* e.g. it would then be safe to and the reference and result expressions:
* (al, ae) = (rl @ l', andexpr (re, e'))
* *)
val otherDirection : direction -> direction
(* Strictly syntactic equality (e.g. ignores commutativity).
Assumes functions return the same result given the same input arguments.
(i.e. referentially transparent and side-effect free)
Cost proportional to expression size *)
val equal : expr * expr -> bool
val varequal : var * var -> bool
val tyequal : ty * ty -> bool
val inc : expr -> expr (* add one to an expression *)
val dec : expr -> expr (* substract one from an expression *)
(* Assumes the expression is of type BOOL, returns the logical negation. *)
val negate : expr -> expr
val andexpr : expr * expr -> expr
val orexpr : expr * expr -> expr
val mulClocks : expr * (symbol -> bool) -> expr -> expr
(* mulClocks (m, isClockVar) e
* Work through e, multiplying the following by m:
* -RHS of assignments to clocks.
* -Either side of a relation involving a clock.
*)
val isNegation : expr * expr -> bool
(* returnval => ((e1 && e2) == false)
Simple and conservative syntactic checks, i.e. sound but not complete
guarantees:
isNegation(e, negate e) = true
isNegation(negate, e) = true
*)
val shrinkScope : (symbol * ty * bool) * (expr -> bool)
-> expr -> expr option
(* Given a binding, true: forall (symbol : ty)
* false: exists (symbol : ty)
*
* Find the smallest subexpression of expr that contains all occurrences
* of symbol, and, if the given predicate is true of the subexpression
* then return (SOME newexpr) such that the symbol is bound around the
* subexpression. Return NONE if the predicate is false.
*
* If expr does not contain symbol, then (SOME expr) is returned.
* (i.e. the binding is thrown away if it is unused.)
*)
end