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.9
6-
75/// Handling of native code and entry points.
8- library vm.transformations.type_flow.native_code;
96
107import 'dart:core' hide Type;
118
@@ -35,24 +32,21 @@ abstract class EntryPointsListener {
3532 /// Record the fact that given member is called from this.
3633 void recordMemberCalledViaThis (Member target);
3734
38- /// Record the fact that given method is torn off.
39- void recordTearOff (Procedure target) {}
35+ /// Record the fact that given member is torn off.
36+ void recordTearOff (Member target) {}
4037}
4138
4239class PragmaEntryPointsVisitor extends RecursiveVisitor {
4340 final EntryPointsListener entryPoints;
4441 final NativeCodeOracle nativeCodeOracle;
4542 final PragmaAnnotationParser matcher;
46- Class currentClass = null ;
4743
4844 PragmaEntryPointsVisitor (
49- this .entryPoints, this .nativeCodeOracle, this .matcher) {
50- assert (matcher != null );
51- }
45+ this .entryPoints, this .nativeCodeOracle, this .matcher);
5246
53- PragmaEntryPointType _annotationsDefineRoot (List <Expression > annotations) {
47+ PragmaEntryPointType ? _annotationsDefineRoot (List <Expression > annotations) {
5448 for (var annotation in annotations) {
55- ParsedPragma pragma = matcher.parsePragma (annotation);
49+ ParsedPragma ? pragma = matcher.parsePragma (annotation);
5650 if (pragma == null ) continue ;
5751 if (pragma is ParsedEntryPointPragma ) return pragma.type;
5852 }
@@ -72,7 +66,6 @@ class PragmaEntryPointsVisitor extends RecursiveVisitor {
7266 }
7367 nativeCodeOracle.addClassReferencedFromNativeCode (klass);
7468 }
75- currentClass = klass;
7669 klass.visitChildren (this );
7770 }
7871
@@ -88,8 +81,7 @@ class PragmaEntryPointsVisitor extends RecursiveVisitor {
8881 }
8982 Member target = proc;
9083 while (target is Procedure && target.isRedirectingFactory) {
91- target = getRedirectingFactoryBody (target).target;
92- assert (target != null );
84+ target = getRedirectingFactoryBody (target)! .target! ;
9385 assert (
9486 (target is Procedure && target.isFactory) || target is Constructor );
9587 }
@@ -152,7 +144,7 @@ class PragmaEntryPointsVisitor extends RecursiveVisitor {
152144 }
153145 entryPoints
154146 .addRawCall (new DirectSelector (ctor, callKind: CallKind .Method ));
155- entryPoints.addAllocatedClass (currentClass );
147+ entryPoints.addAllocatedClass (ctor.enclosingClass );
156148 nativeCodeOracle.setMemberReferencedFromNativeCode (ctor);
157149 }
158150 }
@@ -201,9 +193,7 @@ class NativeCodeOracle {
201193 final Set <Class > _classesReferencedFromNativeCode = new Set <Class >();
202194 final PragmaAnnotationParser _matcher;
203195
204- NativeCodeOracle (this ._libraryIndex, this ._matcher) {
205- assert (_matcher != null );
206- }
196+ NativeCodeOracle (this ._libraryIndex, this ._matcher);
207197
208198 void addClassReferencedFromNativeCode (Class klass) {
209199 _classesReferencedFromNativeCode.add (klass);
@@ -219,25 +209,26 @@ class NativeCodeOracle {
219209 bool isMemberReferencedFromNativeCode (Member member) =>
220210 _membersReferencedFromNativeCode.contains (member);
221211
222- PragmaRecognizedType recognizedType (Member member) {
212+ PragmaRecognizedType ? recognizedType (Member member) {
223213 for (var annotation in member.annotations) {
224- ParsedPragma pragma = _matcher.parsePragma (annotation);
214+ ParsedPragma ? pragma = _matcher.parsePragma (annotation);
225215 if (pragma is ParsedRecognized ) {
226216 return pragma.type;
227217 }
228218 }
229219 return null ;
230220 }
231221
232- bool isRecognized (Member member, [List <PragmaRecognizedType > expectedTypes]) {
233- PragmaRecognizedType type = recognizedType (member);
222+ bool isRecognized (Member member,
223+ [List <PragmaRecognizedType >? expectedTypes]) {
224+ PragmaRecognizedType ? type = recognizedType (member);
234225 return type != null &&
235226 (expectedTypes == null || expectedTypes.contains (type));
236227 }
237228
238229 bool hasDisableUnboxedParameters (Member member) {
239230 for (var annotation in member.annotations) {
240- ParsedPragma pragma = _matcher.parsePragma (annotation);
231+ ParsedPragma ? pragma = _matcher.parsePragma (annotation);
241232 if (pragma is ParsedDisableUnboxedParameters ) {
242233 if (member.enclosingLibrary.importUri.scheme != "dart" ) {
243234 throw "ERROR: Cannot use @pragma(vm:disable-unboxed-parameters) outside core libraries." ;
@@ -255,11 +246,11 @@ class NativeCodeOracle {
255246 EntryPointsListener entryPointsListener,
256247 TypesBuilder typesBuilder,
257248 RuntimeTypeTranslator translator) {
258- TypeExpr returnType = null ;
259- bool nullable = null ;
249+ TypeExpr ? returnType = null ;
250+ bool ? nullable = null ;
260251
261252 for (var annotation in member.annotations) {
262- ParsedPragma pragma = _matcher.parsePragma (annotation);
253+ ParsedPragma ? pragma = _matcher.parsePragma (annotation);
263254 if (pragma == null ) continue ;
264255 if (pragma is ParsedResultTypeByTypePragma ||
265256 pragma is ParsedResultTypeByPathPragma ||
@@ -278,8 +269,8 @@ class NativeCodeOracle {
278269 returnType = entryPointsListener.addAllocatedClass (type.classNode);
279270 if (pragma.resultTypeUsesPassedTypeArguments) {
280271 returnType = translator.instantiateConcreteType (
281- returnType,
282- member.function.typeParameters
272+ returnType as ConcreteType ,
273+ member.function! .typeParameters
283274 .map ((t) => TypeParameterType (
284275 t, TypeParameterType .computeNullabilityFromBound (t)))
285276 .toList ());
@@ -314,7 +305,7 @@ class NativeCodeOracle {
314305 return returnType;
315306 } else {
316307 return typesBuilder.fromStaticType (
317- member.function.returnType, nullable ?? true );
308+ member.function! .returnType, nullable ?? true );
318309 }
319310 }
320311}
0 commit comments