22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // @dart = 2.10
6-
75/// Indexed entity interfaces for modeling elements derived from Kernel IR.
86
97import '../elements/entities.dart' ;
108
119abstract class _Indexed {
12- int _index;
10+ late final int _index;
1311}
1412
1513abstract class IndexedLibrary extends _Indexed implements LibraryEntity {
@@ -56,10 +54,10 @@ abstract class EntityMapBase<E extends _Indexed> {
5654 bool _closed = false ;
5755
5856 int _size = 0 ;
59- final List <E > _list = < E > [];
57+ final List <E ? > _list = < E ? > [];
6058
6159 /// Returns the [index] th entity in the map.
62- E getEntity (int index) => _list[index];
60+ E ? getEntity (int index) => _list[index];
6361
6462 /// Returns the number of non-null entities in the map.
6563 int get size => _size;
@@ -85,8 +83,7 @@ class EntityMap<E extends _Indexed> extends EntityMapBase<E> {
8583 E0 register <E0 extends E >(E0 entity) {
8684 assert (
8785 ! _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.
9087 entity._index = _list.length;
9188 _list.add (entity);
9289 _size++ ;
@@ -103,7 +100,7 @@ class EntityMap<E extends _Indexed> extends EntityMapBase<E> {
103100 /// Calls [f] for each non-null entity.
104101 void forEach <E0 extends E >(void f (E0 entity)) {
105102 for (int index = 0 ; index < _list.length; index++ ) {
106- E entity = _list[index];
103+ final entity = _list[index] as E0 ? ;
107104 if (entity != null ) {
108105 f (entity);
109106 }
@@ -115,7 +112,7 @@ class EntityMap<E extends _Indexed> extends EntityMapBase<E> {
115112/// corresponding data object of type [D] .
116113abstract class EntityDataMapBase <E extends _Indexed , D >
117114 extends EntityMapBase <E > {
118- final List <D > _data = < D > [];
115+ final List <D ? > _data = < D ? > [];
119116
120117 /// Returns the data object stored for the [index] th entity.
121118 D getData (E entity) {
@@ -124,7 +121,7 @@ abstract class EntityDataMapBase<E extends _Indexed, D>
124121 throw StateError (
125122 'Data is in the process of being created for ${_list [index ]}.' );
126123 }
127- return _data[index];
124+ return _data[index]! ;
128125 }
129126}
130127
@@ -145,8 +142,7 @@ class EntityDataMap<E extends _Indexed, D> extends EntityDataMapBase<E, D> {
145142 E0 register <E0 extends E , D0 extends D >(E0 entity, D0 data) {
146143 assert (
147144 ! _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.
150146 assert (
151147 _list.length == _data.length,
152148 'Data list length ${_data .length } inconsistent '
@@ -174,9 +170,9 @@ class EntityDataMap<E extends _Indexed, D> extends EntityDataMapBase<E, D> {
174170 throw StateError ('Data is in the process of being created.' );
175171 }
176172 for (int index = 0 ; index < _list.length; index++ ) {
177- E entity = _list[index];
173+ final entity = _list[index] as E0 ? ;
178174 if (entity != null ) {
179- f (entity, _data[index]);
175+ f (entity, _data[index] as D0 );
180176 }
181177 }
182178 }
@@ -212,8 +208,7 @@ class EntityDataEnvMap<E extends _Indexed, D, V>
212208 E0 entity, D0 data, V0 env) {
213209 assert (
214210 ! _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.
217212 assert (
218213 _list.length == _data.length,
219214 'Data list length ${_data .length } inconsistent '
@@ -244,8 +239,7 @@ class EntityDataEnvMap<E extends _Indexed, D, V>
244239 void _preRegister <E0 extends E , V0 extends V >(E0 entity, V0 env) {
245240 assert (
246241 ! _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.
249243 assert (
250244 _list.length == _env.length,
251245 'Env list length ${_env .length } inconsistent '
@@ -272,7 +266,7 @@ class EntityDataEnvMap<E extends _Indexed, D, V>
272266 void postRegisterData <E0 extends E , D0 extends D >(E0 entity, D0 data) {
273267 assert (
274268 ! _closed, "Trying to register $entity @ ${_list .length } when closed." );
275- assert (entity != null );
269+ assert (( entity as dynamic ) != null ); // TODO(48820): Remove.
276270 assert (
277271 (_list.length - 1 ) == _data.length,
278272 'Data list length ${_data .length } inconsistent '
@@ -292,9 +286,9 @@ class EntityDataEnvMap<E extends _Indexed, D, V>
292286 throw StateError ('Env is in the process of being created.' );
293287 }
294288 for (int index = 0 ; index < _list.length; index++ ) {
295- E entity = _list[index];
289+ final entity = _list[index] as E0 ? ;
296290 if (entity != null ) {
297- f (entity, _data[index], _env[index]);
291+ f (entity, _data[index] as D0 , _env[index] as V0 );
298292 }
299293 }
300294 }
0 commit comments