mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 13:35:05 +00:00
[dart2js] migrate kernel/native_basic_data.dart and kernel/no_such_method_resolver.dart
Change-Id: Idb789679871b0702b02cfc840456702708970f6e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260301 Reviewed-by: Nate Biggs <natebiggs@google.com>
This commit is contained in:
parent
9d8ea01862
commit
5fbd406929
|
@ -861,15 +861,15 @@ class KernelToElementMap
|
|||
|
||||
/// Returns the defining node for [member].
|
||||
@override
|
||||
ir.Member getMemberNode(covariant IndexedMember member) {
|
||||
ir.Member getMemberNode(MemberEntity member) {
|
||||
assert(checkFamily(member));
|
||||
return members.getData(member).node;
|
||||
return members.getData(member as IndexedMember).node;
|
||||
}
|
||||
|
||||
/// Returns the defining node for [cls].
|
||||
ir.Class getClassNode(covariant IndexedClass cls) {
|
||||
ir.Class getClassNode(ClassEntity cls) {
|
||||
assert(checkFamily(cls));
|
||||
return classes.getData(cls).node;
|
||||
return classes.getData(cls as IndexedClass).node;
|
||||
}
|
||||
|
||||
/// Return the [ImportEntity] corresponding to [node].
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.10
|
||||
|
||||
import 'package:kernel/ast.dart' as ir;
|
||||
|
||||
import '../common.dart';
|
||||
|
@ -22,30 +20,29 @@ class KernelAnnotationProcessor {
|
|||
final IrAnnotationData annotationData;
|
||||
|
||||
KernelAnnotationProcessor(
|
||||
this.elementMap, this._nativeBasicDataBuilder, this.annotationData)
|
||||
: assert(annotationData != null);
|
||||
this.elementMap, this._nativeBasicDataBuilder, this.annotationData);
|
||||
|
||||
void extractNativeAnnotations(LibraryEntity library) {
|
||||
KElementEnvironment elementEnvironment = elementMap.elementEnvironment;
|
||||
|
||||
elementEnvironment.forEachClass(library, (ClassEntity cls) {
|
||||
ir.Class node = elementMap.getClassNode(cls);
|
||||
String annotationName = annotationData.getNativeClassName(node);
|
||||
String? annotationName = annotationData.getNativeClassName(node);
|
||||
if (annotationName != null) {
|
||||
_nativeBasicDataBuilder.setNativeClassTagInfo(cls, annotationName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String getJsInteropName(
|
||||
String? getJsInteropName(
|
||||
Spannable spannable, Iterable<ConstantValue> metadata) {
|
||||
KCommonElements commonElements = elementMap.commonElements;
|
||||
String annotationName;
|
||||
String? annotationName;
|
||||
for (ConstantValue value in metadata) {
|
||||
String name = readAnnotationName(commonElements.dartTypes, spannable,
|
||||
value, commonElements.jsAnnotationClass1, defaultValue: '') ??
|
||||
String? name = readAnnotationName(commonElements.dartTypes, spannable,
|
||||
value, commonElements.jsAnnotationClass1!, defaultValue: '') ??
|
||||
readAnnotationName(commonElements.dartTypes, spannable, value,
|
||||
commonElements.jsAnnotationClass2,
|
||||
commonElements.jsAnnotationClass2!,
|
||||
defaultValue: '');
|
||||
if (annotationName == null) {
|
||||
annotationName = name;
|
||||
|
@ -63,13 +60,13 @@ class KernelAnnotationProcessor {
|
|||
KElementEnvironment elementEnvironment = elementMap.elementEnvironment;
|
||||
|
||||
ir.Library libraryNode = elementMap.getLibraryNode(library);
|
||||
String libraryName = annotationData.getJsInteropLibraryName(libraryNode);
|
||||
String? libraryName = annotationData.getJsInteropLibraryName(libraryNode);
|
||||
final bool isExplicitlylyJsLibrary = libraryName != null;
|
||||
bool isJsLibrary = isExplicitlylyJsLibrary;
|
||||
|
||||
elementEnvironment.forEachLibraryMember(library, (MemberEntity member) {
|
||||
ir.Member memberNode = elementMap.getMemberNode(member);
|
||||
String memberName = annotationData.getJsInteropMemberName(memberNode);
|
||||
String? memberName = annotationData.getJsInteropMemberName(memberNode);
|
||||
if (member.isField) {
|
||||
if (memberName != null) {
|
||||
// TODO(34174): Disallow js-interop fields.
|
||||
|
@ -77,7 +74,7 @@ class KernelAnnotationProcessor {
|
|||
member, MessageKind.JS_INTEROP_FIELD_NOT_SUPPORTED);*/
|
||||
}
|
||||
} else {
|
||||
FunctionEntity function = member;
|
||||
FunctionEntity function = member as FunctionEntity;
|
||||
if (function.isExternal && isExplicitlylyJsLibrary) {
|
||||
// External members of explicit js-interop library are implicitly
|
||||
// js-interop members.
|
||||
|
@ -100,7 +97,7 @@ class KernelAnnotationProcessor {
|
|||
|
||||
elementEnvironment.forEachClass(library, (ClassEntity cls) {
|
||||
ir.Class classNode = elementMap.getClassNode(cls);
|
||||
String className = annotationData.getJsInteropClassName(classNode);
|
||||
String? className = annotationData.getJsInteropClassName(classNode);
|
||||
if (className != null) {
|
||||
bool isAnonymous = annotationData.isAnonymousJsInteropClass(classNode);
|
||||
// TODO(johnniwinther): Report an error if the class is anonymous but
|
||||
|
@ -117,12 +114,12 @@ class KernelAnnotationProcessor {
|
|||
/*reporter.reportErrorMessage(
|
||||
member, MessageKind.IMPLICIT_JS_INTEROP_FIELD_NOT_SUPPORTED);*/
|
||||
} else {
|
||||
FunctionEntity function = member;
|
||||
FunctionEntity function = member as FunctionEntity;
|
||||
ir.Member memberNode = elementMap.getMemberNode(member);
|
||||
// Members that are not annotated and not external will result in
|
||||
// null here. For example, the default constructor which is not
|
||||
// user-specified.
|
||||
String /*?*/ memberName =
|
||||
String? memberName =
|
||||
annotationData.getJsInteropMemberName(memberNode);
|
||||
if (function.isExternal) {
|
||||
memberName ??= function.name;
|
||||
|
@ -137,7 +134,7 @@ class KernelAnnotationProcessor {
|
|||
});
|
||||
elementEnvironment.forEachConstructor(cls,
|
||||
(ConstructorEntity constructor) {
|
||||
String memberName = getJsInteropName(
|
||||
String? memberName = getJsInteropName(
|
||||
library, elementEnvironment.getMemberMetadata(constructor));
|
||||
if (constructor.isExternal) {
|
||||
// TODO(johnniwinther): It should probably be an error to have a
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.10
|
||||
|
||||
import 'package:kernel/ast.dart' as ir;
|
||||
|
||||
import '../common/elements.dart';
|
||||
|
@ -30,8 +28,8 @@ class NoSuchMethodResolver {
|
|||
if (node.function.positionalParameters.isEmpty) return false;
|
||||
ir.VariableDeclaration firstParameter =
|
||||
node.function.positionalParameters.first;
|
||||
ir.Statement body = node.function.body;
|
||||
ir.Expression expr;
|
||||
ir.Statement? body = node.function.body;
|
||||
ir.Expression? expr;
|
||||
if (body is ir.Block && body.statements.isNotEmpty) {
|
||||
ir.Block block = body;
|
||||
body = block.statements.first;
|
||||
|
@ -50,7 +48,7 @@ class NoSuchMethodResolver {
|
|||
if (arguments.positional.length == 1 &&
|
||||
arguments.named.isEmpty &&
|
||||
arguments.positional.first is ir.VariableGet) {
|
||||
ir.VariableGet get = arguments.positional.first;
|
||||
ir.VariableGet get = arguments.positional.first as ir.VariableGet;
|
||||
return get.variable == firstParameter;
|
||||
}
|
||||
}
|
||||
|
@ -63,12 +61,12 @@ class NoSuchMethodResolver {
|
|||
///
|
||||
bool hasThrowingSyntax(KFunction method) {
|
||||
ir.Procedure node = elementMap.lookupProcedure(method);
|
||||
ir.Statement body = node.function.body;
|
||||
ir.Statement? body = node.function.body;
|
||||
if (body is ir.Block && body.statements.isNotEmpty) {
|
||||
ir.Block block = body;
|
||||
body = block.statements.first;
|
||||
}
|
||||
ir.Expression expr;
|
||||
ir.Expression? expr;
|
||||
if (body is ir.ReturnStatement) {
|
||||
expr = body.expression;
|
||||
} else if (body is ir.ExpressionStatement) {
|
||||
|
@ -79,6 +77,6 @@ class NoSuchMethodResolver {
|
|||
|
||||
/// Returns the `noSuchMethod` that [method] overrides.
|
||||
FunctionEntity getSuperNoSuchMethod(FunctionEntity method) {
|
||||
return elementMap.getSuperNoSuchMethod(method.enclosingClass);
|
||||
return elementMap.getSuperNoSuchMethod(method.enclosingClass!);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue