2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.10
6
-
7
5
/// Indexed entity interfaces for modeling elements derived from Kernel IR.
8
6
9
7
import '../elements/entities.dart' ;
10
8
11
9
abstract class _Indexed {
12
- int _index;
10
+ late final int _index;
13
11
}
14
12
15
13
abstract class IndexedLibrary extends _Indexed implements LibraryEntity {
@@ -56,10 +54,10 @@ abstract class EntityMapBase<E extends _Indexed> {
56
54
bool _closed = false ;
57
55
58
56
int _size = 0 ;
59
- final List <E > _list = < E > [];
57
+ final List <E ? > _list = < E ? > [];
60
58
61
59
/// Returns the [index] th entity in the map.
62
- E getEntity (int index) => _list[index];
60
+ E ? getEntity (int index) => _list[index];
63
61
64
62
/// Returns the number of non-null entities in the map.
65
63
int get size => _size;
@@ -85,8 +83,7 @@ class EntityMap<E extends _Indexed> extends EntityMapBase<E> {
85
83
E0 register <E0 extends E >(E0 entity) {
86
84
assert (
87
85
! _closed, "Trying to register $entity @ ${_list .length } when closed." );
88
- assert (entity != null );
89
- assert (entity._index == null );
86
+ assert ((entity as dynamic ) != null ); // TODO(48820): Remove.
90
87
entity._index = _list.length;
91
88
_list.add (entity);
92
89
_size++ ;
@@ -103,7 +100,7 @@ class EntityMap<E extends _Indexed> extends EntityMapBase<E> {
103
100
/// Calls [f] for each non-null entity.
104
101
void forEach <E0 extends E >(void f (E0 entity)) {
105
102
for (int index = 0 ; index < _list.length; index++ ) {
106
- E entity = _list[index];
103
+ final entity = _list[index] as E0 ? ;
107
104
if (entity != null ) {
108
105
f (entity);
109
106
}
@@ -115,7 +112,7 @@ class EntityMap<E extends _Indexed> extends EntityMapBase<E> {
115
112
/// corresponding data object of type [D] .
116
113
abstract class EntityDataMapBase <E extends _Indexed , D >
117
114
extends EntityMapBase <E > {
118
- final List <D > _data = < D > [];
115
+ final List <D ? > _data = < D ? > [];
119
116
120
117
/// Returns the data object stored for the [index] th entity.
121
118
D getData (E entity) {
@@ -124,7 +121,7 @@ abstract class EntityDataMapBase<E extends _Indexed, D>
124
121
throw StateError (
125
122
'Data is in the process of being created for ${_list [index ]}.' );
126
123
}
127
- return _data[index];
124
+ return _data[index]! ;
128
125
}
129
126
}
130
127
@@ -145,8 +142,7 @@ class EntityDataMap<E extends _Indexed, D> extends EntityDataMapBase<E, D> {
145
142
E0 register <E0 extends E , D0 extends D >(E0 entity, D0 data) {
146
143
assert (
147
144
! _closed, "Trying to register $entity @ ${_list .length } when closed." );
148
- assert (entity != null );
149
- assert (entity._index == null );
145
+ assert ((entity as dynamic ) != null ); // TODO(48820): Remove.
150
146
assert (
151
147
_list.length == _data.length,
152
148
'Data list length ${_data .length } inconsistent '
@@ -174,9 +170,9 @@ class EntityDataMap<E extends _Indexed, D> extends EntityDataMapBase<E, D> {
174
170
throw StateError ('Data is in the process of being created.' );
175
171
}
176
172
for (int index = 0 ; index < _list.length; index++ ) {
177
- E entity = _list[index];
173
+ final entity = _list[index] as E0 ? ;
178
174
if (entity != null ) {
179
- f (entity, _data[index]);
175
+ f (entity, _data[index] as D0 );
180
176
}
181
177
}
182
178
}
@@ -212,8 +208,7 @@ class EntityDataEnvMap<E extends _Indexed, D, V>
212
208
E0 entity, D0 data, V0 env) {
213
209
assert (
214
210
! _closed, "Trying to register $entity @ ${_list .length } when closed." );
215
- assert (entity != null );
216
- assert (entity._index == null );
211
+ assert ((entity as dynamic ) != null ); // TODO(48820): Remove.
217
212
assert (
218
213
_list.length == _data.length,
219
214
'Data list length ${_data .length } inconsistent '
@@ -244,8 +239,7 @@ class EntityDataEnvMap<E extends _Indexed, D, V>
244
239
void _preRegister <E0 extends E , V0 extends V >(E0 entity, V0 env) {
245
240
assert (
246
241
! _closed, "Trying to register $entity @ ${_list .length } when closed." );
247
- assert (entity != null );
248
- assert (entity._index == null );
242
+ assert ((entity as dynamic ) != null ); // TODO(48820): Remove.
249
243
assert (
250
244
_list.length == _env.length,
251
245
'Env list length ${_env .length } inconsistent '
@@ -272,7 +266,7 @@ class EntityDataEnvMap<E extends _Indexed, D, V>
272
266
void postRegisterData <E0 extends E , D0 extends D >(E0 entity, D0 data) {
273
267
assert (
274
268
! _closed, "Trying to register $entity @ ${_list .length } when closed." );
275
- assert (entity != null );
269
+ assert (( entity as dynamic ) != null ); // TODO(48820): Remove.
276
270
assert (
277
271
(_list.length - 1 ) == _data.length,
278
272
'Data list length ${_data .length } inconsistent '
@@ -292,9 +286,9 @@ class EntityDataEnvMap<E extends _Indexed, D, V>
292
286
throw StateError ('Env is in the process of being created.' );
293
287
}
294
288
for (int index = 0 ; index < _list.length; index++ ) {
295
- E entity = _list[index];
289
+ final entity = _list[index] as E0 ? ;
296
290
if (entity != null ) {
297
- f (entity, _data[index], _env[index]);
291
+ f (entity, _data[index] as D0 , _env[index] as V0 );
298
292
}
299
293
}
300
294
}
0 commit comments