@@ -35,62 +35,89 @@ case class NonEmpty() extends Constructor {
35
35
override lazy val hashCode : Int = scala.runtime.ScalaRunTime ._hashCode(this )
36
36
}
37
37
38
- case class HasKey (isSet : Boolean , element : SymbolOrAlias , key : Option [Pattern [Option [Occurrence ]]])
39
- extends Constructor {
38
+ case class HasKey (
39
+ cat : SortCategory ,
40
+ element : SymbolOrAlias ,
41
+ key : Option [Pattern [Option [Occurrence ]]]
42
+ ) extends Constructor {
40
43
def name = " 1"
41
44
def isBest (pat : Pattern [Option [Occurrence ]]): Boolean = key.isDefined && pat == key.get
42
45
def expand (f : Fringe ): Option [immutable.Seq [Fringe ]] = {
43
46
val sorts = f.symlib.signatures(element)._1
44
47
key match {
45
48
case None =>
46
- if (isSet) {
47
- Some (
48
- immutable.Seq (
49
- Fringe (f.symlib, sorts.head, Choice (f.occurrence), isExact = false ),
50
- Fringe (f.symlib, f.sort, ChoiceRem (f.occurrence), isExact = false )
49
+ cat match {
50
+ case SetS () =>
51
+ Some (
52
+ immutable.Seq (
53
+ Fringe (f.symlib, sorts.head, Choice (f.occurrence), isExact = false ),
54
+ Fringe (f.symlib, f.sort, ChoiceRem (f.occurrence), isExact = false )
55
+ )
56
+ )
57
+ case MapS () =>
58
+ Some (
59
+ immutable.Seq (
60
+ Fringe (f.symlib, sorts.head, Choice (f.occurrence), isExact = false ),
61
+ Fringe (f.symlib, sorts(1 ), ChoiceValue (f.occurrence), isExact = false ),
62
+ Fringe (f.symlib, f.sort, ChoiceRem (f.occurrence), isExact = false )
63
+ )
51
64
)
52
- )
53
- } else {
54
- Some (
55
- immutable. Seq (
56
- Fringe (f.symlib, sorts.head, Choice (f.occurrence), isExact = false ),
57
- Fringe (f.symlib, sorts( 1 ), ChoiceValue (f.occurrence), isExact = false ),
58
- Fringe (f.symlib, f.sort, ChoiceRem (f.occurrence), isExact = false )
65
+ case ListS () =>
66
+ Some (
67
+ immutable. Seq (
68
+ Fringe (f.symlib, sorts( 1 ), Choice (f.occurrence), isExact = false ),
69
+ Fringe (f.symlib, sorts( 2 ), ChoiceValue (f.occurrence), isExact = false ),
70
+ Fringe (f.symlib, f.sort, ChoiceRem (f.occurrence), isExact = false )
71
+ )
59
72
)
60
- )
73
+ case _ => ???
61
74
}
62
75
case Some (k) =>
63
- if (isSet) {
64
- Some (immutable.Seq (Fringe (f.symlib, f.sort, Rem (k, f.occurrence), isExact = false ), f))
65
- } else {
66
- Some (
67
- immutable.Seq (
68
- Fringe (f.symlib, sorts(1 ), Value (k, f.occurrence), isExact = false ),
69
- Fringe (f.symlib, f.sort, Rem (k, f.occurrence), isExact = false ),
70
- f
76
+ cat match {
77
+ case SetS () =>
78
+ Some (immutable.Seq (Fringe (f.symlib, f.sort, Rem (k, f.occurrence), isExact = false ), f))
79
+ case MapS () =>
80
+ Some (
81
+ immutable.Seq (
82
+ Fringe (f.symlib, sorts(1 ), Value (k, f.occurrence), isExact = false ),
83
+ Fringe (f.symlib, f.sort, Rem (k, f.occurrence), isExact = false ),
84
+ f
85
+ )
86
+ )
87
+ case ListS () =>
88
+ Some (
89
+ immutable.Seq (
90
+ Fringe (f.symlib, sorts(2 ), Value (k, f.occurrence), isExact = false ),
91
+ Fringe (f.symlib, f.sort, f.occurrence, isExact = false ),
92
+ f
93
+ )
71
94
)
72
- )
95
+ case _ => ???
73
96
}
74
97
}
75
98
}
76
99
def contract (f : Fringe , children : immutable.Seq [Pattern [String ]]): Pattern [String ] = {
77
100
val child = children.last
78
101
var key : Pattern [String ] = null
79
102
var value : Pattern [String ] = null
80
- assert((isSet && children.size == 2 ) || (! isSet && children.size == 3 ))
103
+ assert((cat == SetS () && children.size == 2 ) || (cat != SetS () && children.size == 3 ))
81
104
if (this .key.isEmpty) {
82
- if (isSet) {
83
- key = children.head
84
- } else {
85
- key = children.head
86
- value = children(1 )
105
+ cat match {
106
+ case SetS () =>
107
+ key = children.head
108
+ case MapS () =>
109
+ key = children.head
110
+ value = children(1 )
111
+ case _ => ???
87
112
}
88
113
} else {
89
- if (isSet) {
90
- key = this .key.get.decanonicalize
91
- } else {
92
- key = this .key.get.decanonicalize
93
- value = children.head
114
+ cat match {
115
+ case SetS () =>
116
+ key = this .key.get.decanonicalize
117
+ case ListS () | MapS () =>
118
+ key = this .key.get.decanonicalize
119
+ value = children.head
120
+ case _ => ???
94
121
}
95
122
}
96
123
def element (k : Pattern [String ], v : Pattern [String ]): Pattern [String ] =
@@ -99,35 +126,53 @@ case class HasKey(isSet: Boolean, element: SymbolOrAlias, key: Option[Pattern[Op
99
126
SymbolP (Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get, immutable.Seq (k))
100
127
def concat (m1 : Pattern [String ], m2 : Pattern [String ]): Pattern [String ] =
101
128
SymbolP (Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " concat" ).get, immutable.Seq (m1, m2))
129
+ def update (m1 : Pattern [String ], m2 : Pattern [String ], m3 : Pattern [String ]): Pattern [String ] =
130
+ SymbolP (
131
+ Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " update" ).get,
132
+ immutable.Seq (m1, m2, m3)
133
+ )
102
134
child match {
103
135
case MapP (keys, values, frame, ctr, orig) =>
104
136
MapP (key +: keys, value +: values, frame, ctr, orig)
137
+ case ListGetP (keys, values, frame, ctr, orig) =>
138
+ ListGetP (key +: keys, value +: values, frame, ctr, orig)
105
139
case SetP (elems, frame, ctr, orig) =>
106
140
SetP (key +: elems, frame, ctr, orig)
107
141
case WildcardP () | VariableP (_, _) =>
108
- if (isSet) {
109
- SetP (
110
- immutable.Seq (key),
111
- Some (child),
112
- Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get,
113
- concat(setElement(key), child)
114
- )
115
- } else {
116
- MapP (
117
- immutable.Seq (key),
118
- immutable.Seq (value),
119
- Some (child),
120
- Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get,
121
- concat(element(key, value), child)
122
- )
142
+ cat match {
143
+ case SetS () =>
144
+ SetP (
145
+ immutable.Seq (key),
146
+ Some (child),
147
+ Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get,
148
+ concat(setElement(key), child)
149
+ )
150
+ case MapS () =>
151
+ MapP (
152
+ immutable.Seq (key),
153
+ immutable.Seq (value),
154
+ Some (child),
155
+ Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get,
156
+ concat(element(key, value), child)
157
+ )
158
+ case ListS () =>
159
+ ListGetP (
160
+ immutable.Seq (key),
161
+ immutable.Seq (value),
162
+ child,
163
+ Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " update" ).get,
164
+ update(child, key, value)
165
+ )
166
+ case _ => ???
123
167
}
124
168
case _ => ???
125
169
}
126
170
}
127
171
override lazy val hashCode : Int = scala.runtime.ScalaRunTime ._hashCode(this )
128
172
}
129
173
130
- case class HasNoKey (isSet : Boolean , key : Option [Pattern [Option [Occurrence ]]]) extends Constructor {
174
+ case class HasNoKey (cat : SortCategory , key : Option [Pattern [Option [Occurrence ]]])
175
+ extends Constructor {
131
176
def name = " 0"
132
177
def isBest (pat : Pattern [Option [Occurrence ]]): Boolean = key.isDefined && pat == key.get
133
178
def expand (f : Fringe ): Option [immutable.Seq [Fringe ]] = Some (immutable.Seq (f))
@@ -141,6 +186,11 @@ case class HasNoKey(isSet: Boolean, key: Option[Pattern[Option[Occurrence]]]) ex
141
186
SymbolP (Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " unit" ).get, immutable.Seq ())
142
187
def concat (m1 : Pattern [String ], m2 : Pattern [String ]): Pattern [String ] =
143
188
SymbolP (Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " concat" ).get, immutable.Seq (m1, m2))
189
+ def update (m1 : Pattern [String ], m2 : Pattern [String ], m3 : Pattern [String ]): Pattern [String ] =
190
+ SymbolP (
191
+ Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " update" ).get,
192
+ immutable.Seq (m1, m2, m3)
193
+ )
144
194
def wildcard = WildcardP [String ]()
145
195
child match {
146
196
case MapP (keys, values, frame, ctr, orig) =>
@@ -154,21 +204,31 @@ case class HasNoKey(isSet: Boolean, key: Option[Pattern[Option[Occurrence]]]) ex
154
204
case SetP (elems, frame, ctr, orig) =>
155
205
SetP (wildcard +: elems, frame, ctr, concat(setElement(wildcard), orig))
156
206
case WildcardP () | VariableP (_, _) =>
157
- if (isSet) {
158
- SetP (
159
- immutable.Seq (wildcard),
160
- Some (child),
161
- Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get,
162
- concat(setElement(wildcard), child)
163
- )
164
- } else {
165
- MapP (
166
- immutable.Seq (wildcard),
167
- immutable.Seq (wildcard),
168
- Some (child),
169
- Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get,
170
- concat(element(wildcard, wildcard), child)
171
- )
207
+ cat match {
208
+ case SetS () =>
209
+ SetP (
210
+ immutable.Seq (wildcard),
211
+ Some (child),
212
+ Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get,
213
+ concat(setElement(wildcard), child)
214
+ )
215
+ case MapS () =>
216
+ MapP (
217
+ immutable.Seq (wildcard),
218
+ immutable.Seq (wildcard),
219
+ Some (child),
220
+ Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " element" ).get,
221
+ concat(element(wildcard, wildcard), child)
222
+ )
223
+ case ListS () =>
224
+ ListGetP (
225
+ immutable.Seq (wildcard),
226
+ immutable.Seq (wildcard),
227
+ child,
228
+ Parser .getSymbolAtt(f.symlib.sortAtt(f.sort), " update" ).get,
229
+ update(child, wildcard, wildcard)
230
+ )
231
+ case _ => ???
172
232
}
173
233
case _ => ???
174
234
}
0 commit comments