[go: up one dir, main page]

Menu

[390b88]: / ir / path.py  Maximize  Restore  History

Download this file

97 lines (68 with data), 1.4 kB

 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
'''Path/selection related transformations.'''
from transf import parse
import ir.match
parse.Transfs(r'''
#######################################################################
# Path annotation
# Only annotate term applications
annotate = path.Annotate(
match.ApplNames(`
ir.match.stmtNames +
ir.match.exprNames +
ir.match.typeNames
`)
)
deannotate = path.deannotate
#######################################################################
# Selection
shared selection
Applicable(t) =
with selection in
?[root, selection] ;
!root ;
t
end
Input(t) =
with selection in
?[root, selection] ;
!root ;
# annotate ;
t ;
![selection, *<id>]
end
Input2(t) =
with selection in
?[root, selection] ;
!root ;
# annotate ;
t
end
Apply(t) =
with selection in
?[root, [selection, *args]] ;
![root, args] ;
t ;
deannotate
end
WithSelection(s, x) = with selection in x where selection := s end
projectSelection = path.Project(!selection)
MatchSelectionTo(s) = projectSelection ; s
#######################################################################
# Selection context
getSelection = !selection
isSelected =
Where(
path.get ;
path.Equals(getSelection)
)
inSelection =
Where(
path.get ;
path.Contained(getSelection)
)
hasSelection =
Where(
path.get ;
path.Contains(getSelection)
)
''')