-
Notifications
You must be signed in to change notification settings - Fork 1
/
EnhancedForStatement.xjl
64 lines (54 loc) · 2.03 KB
/
EnhancedForStatement.xjl
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
package extensions;
public extension EnhancedForStatement {
lexical syntax
"for" -> Keyword
context-free syntax
"for" "(" Type ID ":" Expr ")" Statement -> Statement
inductive definitions
S-EnhancedFor:
// "context"
typevars(CT) = X*
norm(CT, X*, T) = t
norm(CT, X*, JLIterator<T>) = javalight.util.JLIterator t::[]
CT.javalight.lang.JLIterable = {[], iterator:[]->javalight.util.JLIterator A::[] :: [], Object, A::[]}
CT.javalight.util.JLIterator = {[], hasNext:[]->boolean :: next:[]->A :: [], Object, A::[]}
// right-hand side
CT; Ef; El |- e : s
CT |- s <: javalight.lang.JLIterable t::[]
// body
x notin dom(El)
CT; Ef; El,x:t |- stm ~ void
// subsequent statements
CT; Ef; El |- stm* ~ rt
------------------------------------------------------------------------------------------------------
CT; Ef; El |- for(T x : e) stm stm* ~ rt
desugarings
{
// "context"
typevars(CT) = X*
norm(CT, X*, T) = t
norm(CT, X*, JLIterator<T>) = javalight.util.JLIterator t::[]
CT.javalight.lang.JLIterable = {[], iterator:[]->javalight.util.JLIterator A::[] :: [], Object, A::[]}
CT.javalight.util.JLIterator = {[], hasNext:[]->boolean :: next:[]->A :: [], Object, A::[]}
// right-hand side
CT; Ef; El |- e : s
CT |- s <: javalight.lang.JLIterable t::[]
// body
x notin dom(El)
CT; Ef; El,x:t |- stm ~ void
// subsequent statements
CT; Ef; El |- stm* ~ rt
------------------------------------------------------------------------------------------------------
CT; Ef; El |- [ for(T x : e) stm stm* ] ~ rt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>
{
JLIterator<T> y = e.iterator();
while(y.hasNext()) {
T x = y.next();
stm
}
}
stm*
where y =ID fresh(Ef;El,x:t)
}
}