mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
[dart2js] migrate kernel/env.dart to null safety
Change-Id: I0913b133a39f72d29b5332ae38ad7a7a5dba48af Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260078 Reviewed-by: Mayank Patke <fishythefish@google.com> Reviewed-by: Nate Biggs <natebiggs@google.com>
This commit is contained in:
parent
8da75ede06
commit
0ee953d7c2
|
@ -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
|
||||
|
||||
library dart2js.kernel.env;
|
||||
|
||||
import 'package:front_end/src/api_unstable/dart2js.dart'
|
||||
|
@ -33,55 +31,37 @@ import 'env_interfaces.dart' as interfaces;
|
|||
|
||||
/// Environment for fast lookup of component libraries.
|
||||
class KProgramEnv implements interfaces.KProgramEnv {
|
||||
final Set<ir.Component> _components = Set<ir.Component>();
|
||||
final Set<ir.Component> _components = {};
|
||||
|
||||
Map<Uri, KLibraryEnv> _libraryMap;
|
||||
late final Map<Uri, KLibraryEnv> _libraryMap = {
|
||||
for (final component in _components)
|
||||
for (final library in component.libraries)
|
||||
library.importUri: KLibraryEnv(library),
|
||||
};
|
||||
|
||||
/// TODO(johnniwinther): Handle arbitrary load order if needed.
|
||||
ir.Member get mainMethod => _components.first?.mainMethod;
|
||||
ir.Member? get mainMethod => mainComponent.mainMethod;
|
||||
|
||||
ir.Component get mainComponent => _components.first;
|
||||
|
||||
void addComponent(ir.Component component) {
|
||||
if (_components.add(component)) {
|
||||
if (_libraryMap != null) {
|
||||
_addLibraries(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _addLibraries(ir.Component component) {
|
||||
for (ir.Library library in component.libraries) {
|
||||
_libraryMap[library.importUri] = KLibraryEnv(library);
|
||||
}
|
||||
}
|
||||
|
||||
void _ensureLibraryMap() {
|
||||
if (_libraryMap == null) {
|
||||
_libraryMap = <Uri, KLibraryEnv>{};
|
||||
for (ir.Component component in _components) {
|
||||
_addLibraries(component);
|
||||
for (ir.Library library in component.libraries) {
|
||||
_libraryMap[library.importUri] ??= KLibraryEnv(library);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the [KLibraryEnv] for the library with the canonical [uri].
|
||||
KLibraryEnv lookupLibrary(Uri uri) {
|
||||
_ensureLibraryMap();
|
||||
return _libraryMap[uri];
|
||||
}
|
||||
KLibraryEnv? lookupLibrary(Uri uri) => _libraryMap[uri];
|
||||
|
||||
/// Calls [f] for each library in this environment.
|
||||
void forEachLibrary(void f(KLibraryEnv library)) {
|
||||
_ensureLibraryMap();
|
||||
_libraryMap.values.forEach(f);
|
||||
}
|
||||
|
||||
/// Returns the number of libraries in this environment.
|
||||
int get length {
|
||||
_ensureLibraryMap();
|
||||
return _libraryMap.length;
|
||||
}
|
||||
int get length => _libraryMap.length;
|
||||
|
||||
/// Convert this [KProgramEnv] to the corresponding [JProgramEnv].
|
||||
@override
|
||||
|
@ -93,30 +73,20 @@ class KLibraryEnv implements interfaces.KLibraryEnv {
|
|||
@override
|
||||
final ir.Library library;
|
||||
|
||||
Map<String, KClassEnv> _classMap;
|
||||
Map<String, ir.Member> _memberMap;
|
||||
Map<String, ir.Member> _setterMap;
|
||||
late final Map<String, KClassEnv> _classMap = {
|
||||
for (ir.Class cls in library.classes) cls.name: KClassEnvImpl(cls),
|
||||
};
|
||||
|
||||
Map<String, ir.Member>? _memberMap;
|
||||
Map<String, ir.Member>? _setterMap;
|
||||
|
||||
KLibraryEnv(this.library);
|
||||
|
||||
void _ensureClassMap() {
|
||||
if (_classMap == null) {
|
||||
_classMap = <String, KClassEnv>{};
|
||||
for (ir.Class cls in library.classes) {
|
||||
_classMap[cls.name] = KClassEnvImpl(cls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the [KClassEnv] for the class [name] in [library].
|
||||
KClassEnv lookupClass(String name) {
|
||||
_ensureClassMap();
|
||||
return _classMap[name];
|
||||
}
|
||||
KClassEnv? lookupClass(String name) => _classMap[name];
|
||||
|
||||
/// Calls [f] for each class in this library.
|
||||
void forEachClass(void f(KClassEnv cls)) {
|
||||
_ensureClassMap();
|
||||
_classMap.values.forEach(f);
|
||||
}
|
||||
|
||||
|
@ -130,14 +100,14 @@ class KLibraryEnv implements interfaces.KLibraryEnv {
|
|||
}
|
||||
if (member is ir.Procedure) {
|
||||
if (member.kind == ir.ProcedureKind.Setter) {
|
||||
_setterMap[member.name.text] = member;
|
||||
_setterMap![member.name.text] = member;
|
||||
} else {
|
||||
_memberMap[member.name.text] = member;
|
||||
_memberMap![member.name.text] = member;
|
||||
}
|
||||
} else if (member is ir.Field) {
|
||||
_memberMap[member.name.text] = member;
|
||||
_memberMap![member.name.text] = member;
|
||||
if (member.hasSetter) {
|
||||
_setterMap[member.name.text] = member;
|
||||
_setterMap![member.name.text] = member;
|
||||
}
|
||||
} else {
|
||||
failedAt(
|
||||
|
@ -148,15 +118,15 @@ class KLibraryEnv implements interfaces.KLibraryEnv {
|
|||
}
|
||||
|
||||
/// Return the [ir.Member] for the member [name] in [library].
|
||||
ir.Member lookupMember(String name, {bool setter = false}) {
|
||||
ir.Member? lookupMember(String name, {bool setter = false}) {
|
||||
_ensureMemberMaps();
|
||||
return setter ? _setterMap[name] : _memberMap[name];
|
||||
return setter ? _setterMap![name] : _memberMap![name];
|
||||
}
|
||||
|
||||
void forEachMember(void f(ir.Member member)) {
|
||||
_ensureMemberMaps();
|
||||
_memberMap.values.forEach(f);
|
||||
for (ir.Member member in _setterMap.values) {
|
||||
_memberMap!.values.forEach(f);
|
||||
for (ir.Member member in _setterMap!.values) {
|
||||
if (member is ir.Procedure) {
|
||||
f(member);
|
||||
} else {
|
||||
|
@ -176,7 +146,7 @@ class KLibraryEnv implements interfaces.KLibraryEnv {
|
|||
memberMap = const <String, ir.Member>{};
|
||||
} else {
|
||||
memberMap = <String, ir.Member>{};
|
||||
_memberMap.forEach((String name, ir.Member node) {
|
||||
_memberMap!.forEach((String name, ir.Member node) {
|
||||
MemberEntity member = kElementMap.getMember(node);
|
||||
if (liveMemberUsage.containsKey(member)) {
|
||||
memberMap[name] = node;
|
||||
|
@ -187,7 +157,7 @@ class KLibraryEnv implements interfaces.KLibraryEnv {
|
|||
setterMap = const <String, ir.Member>{};
|
||||
} else {
|
||||
setterMap = <String, ir.Member>{};
|
||||
_setterMap.forEach((String name, ir.Member node) {
|
||||
_setterMap!.forEach((String name, ir.Member node) {
|
||||
MemberEntity member = kElementMap.getMember(node);
|
||||
if (liveMemberUsage.containsKey(member)) {
|
||||
setterMap[name] = node;
|
||||
|
@ -200,9 +170,9 @@ class KLibraryEnv implements interfaces.KLibraryEnv {
|
|||
|
||||
class KLibraryData implements interfaces.KLibraryData {
|
||||
final ir.Library library;
|
||||
Iterable<ConstantValue> _metadata;
|
||||
Iterable<ConstantValue>? _metadata;
|
||||
// TODO(johnniwinther): Avoid direct access to [imports].
|
||||
Map<ir.LibraryDependency, ImportEntity> imports;
|
||||
Map<ir.LibraryDependency, ImportEntity>? imports;
|
||||
|
||||
KLibraryData(this.library);
|
||||
|
||||
|
@ -222,7 +192,7 @@ class KLibraryData implements interfaces.KLibraryData {
|
|||
imports = <ir.LibraryDependency, ImportEntity>{};
|
||||
dependencies.forEach((ir.LibraryDependency node) {
|
||||
if (node.isExport) return;
|
||||
imports[node] = ImportEntity(
|
||||
imports![node] = ImportEntity(
|
||||
node.isDeferred,
|
||||
node.name,
|
||||
node.targetLibrary.importUri,
|
||||
|
@ -230,7 +200,7 @@ class KLibraryData implements interfaces.KLibraryData {
|
|||
});
|
||||
}
|
||||
}
|
||||
return imports.values;
|
||||
return imports!.values;
|
||||
}
|
||||
|
||||
/// Convert this [KLibraryData] to the corresponding [JLibraryData].
|
||||
|
@ -260,13 +230,13 @@ abstract class KClassEnv implements interfaces.KClassEnv {
|
|||
void ensureMembers(KernelToElementMapForEnv elementMap);
|
||||
|
||||
/// Return the [MemberEntity] for the member [name] in the class.
|
||||
MemberEntity lookupMember(IrToElementMap elementMap, Name name);
|
||||
MemberEntity? lookupMember(IrToElementMap elementMap, Name name);
|
||||
|
||||
/// Calls [f] for each member of [cls].
|
||||
void forEachMember(IrToElementMap elementMap, void f(MemberEntity member));
|
||||
|
||||
/// Return the [ConstructorEntity] for the constructor [name] in [cls].
|
||||
ConstructorEntity lookupConstructor(IrToElementMap elementMap, String name);
|
||||
ConstructorEntity? lookupConstructor(IrToElementMap elementMap, String? name);
|
||||
|
||||
/// Calls [f] for each constructor of [cls].
|
||||
void forEachConstructor(
|
||||
|
@ -295,8 +265,8 @@ abstract class KClassEnv implements interfaces.KClassEnv {
|
|||
}
|
||||
|
||||
int orderByFileOffset(ir.TreeNode a, ir.TreeNode b) {
|
||||
var aLoc = a.location;
|
||||
var bLoc = b.location;
|
||||
var aLoc = a.location!;
|
||||
var bLoc = b.location!;
|
||||
var aUri = '${aLoc.file}';
|
||||
var bUri = '${bLoc.file}';
|
||||
var uriCompare = aUri.compareTo(bUri);
|
||||
|
@ -309,33 +279,27 @@ class KClassEnvImpl implements KClassEnv {
|
|||
@override
|
||||
final ir.Class cls;
|
||||
|
||||
Map<String, ir.Member> _constructorMap;
|
||||
Map<Name, ir.Member> _memberMap;
|
||||
List<ir.Member> _members; // in declaration order.
|
||||
bool _isMixinApplicationWithMembers;
|
||||
Map<String, ir.Member>? _constructorMap;
|
||||
Map<Name, ir.Member>? _memberMap;
|
||||
List<ir.Member>? _members; // in declaration order.
|
||||
bool? _isMixinApplicationWithMembers;
|
||||
|
||||
/// Constructor bodies created for this class.
|
||||
List<ConstructorBodyEntity> _constructorBodyList;
|
||||
List<ConstructorBodyEntity>? _constructorBodyList;
|
||||
|
||||
KClassEnvImpl(this.cls);
|
||||
|
||||
KClassEnvImpl.internal(this.cls, this._constructorMap, this._memberMap,
|
||||
this._members, this._isMixinApplicationWithMembers);
|
||||
|
||||
@override
|
||||
bool get isUnnamedMixinApplication => cls.isAnonymousMixin;
|
||||
|
||||
@override
|
||||
bool get isMixinApplicationWithMembers {
|
||||
assert(_isMixinApplicationWithMembers != null);
|
||||
return _isMixinApplicationWithMembers;
|
||||
}
|
||||
bool get isMixinApplicationWithMembers => _isMixinApplicationWithMembers!;
|
||||
|
||||
@override
|
||||
bool checkHasMember(ir.Member node) {
|
||||
if (_memberMap == null) return false;
|
||||
return _memberMap.values.contains(node) ||
|
||||
_constructorMap.values.contains(node);
|
||||
return _memberMap!.values.contains(node) ||
|
||||
_constructorMap!.values.contains(node);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -351,20 +315,20 @@ class KClassEnvImpl implements KClassEnv {
|
|||
var members = <ir.Member>[];
|
||||
_isMixinApplicationWithMembers = false;
|
||||
|
||||
void addField(ir.Field member, {bool includeStatic}) {
|
||||
void addField(ir.Field member, {required bool includeStatic}) {
|
||||
if (!includeStatic && member.isStatic) return;
|
||||
if (isRedirectingFactoryField(member)) return;
|
||||
var name = elementMap.getName(member.name);
|
||||
_memberMap[name] = member;
|
||||
_memberMap![name] = member;
|
||||
if (member.hasSetter) {
|
||||
_memberMap[name.setter] = member;
|
||||
_memberMap![name.setter] = member;
|
||||
}
|
||||
members.add(member);
|
||||
}
|
||||
|
||||
void addProcedure(ir.Procedure member,
|
||||
{bool includeStatic,
|
||||
bool includeNoSuchMethodForwarders,
|
||||
{required bool includeStatic,
|
||||
required bool includeNoSuchMethodForwarders,
|
||||
bool isFromMixinApplication = false}) {
|
||||
if (memberIsIgnorable(member, cls: cls)) return;
|
||||
if (!includeStatic && member.isStatic) return;
|
||||
|
@ -378,10 +342,10 @@ class KClassEnvImpl implements KClassEnv {
|
|||
// Don't include redirecting factories.
|
||||
return;
|
||||
}
|
||||
_constructorMap[member.name.text] = member;
|
||||
_constructorMap![member.name.text] = member;
|
||||
} else {
|
||||
var name = elementMap.getName(member.name, setter: member.isSetter);
|
||||
_memberMap[name] = member;
|
||||
_memberMap![name] = member;
|
||||
members.add(member);
|
||||
if (isFromMixinApplication) {
|
||||
_isMixinApplicationWithMembers = true;
|
||||
|
@ -392,21 +356,21 @@ class KClassEnvImpl implements KClassEnv {
|
|||
void addConstructors(ir.Class c) {
|
||||
for (ir.Constructor member in c.constructors) {
|
||||
var name = member.name.text;
|
||||
_constructorMap[name] = member;
|
||||
_constructorMap![name] = member;
|
||||
}
|
||||
}
|
||||
|
||||
int mixinMemberCount = 0;
|
||||
|
||||
if (cls.mixedInClass != null) {
|
||||
for (ir.Field field in cls.mixedInClass.mixin.fields) {
|
||||
for (ir.Field field in cls.mixedInClass!.mixin.fields) {
|
||||
if (field.containsSuperCalls) {
|
||||
_isMixinApplicationWithMembers = true;
|
||||
continue;
|
||||
}
|
||||
addField(field, includeStatic: false);
|
||||
}
|
||||
for (ir.Procedure procedure in cls.mixedInClass.mixin.procedures) {
|
||||
for (ir.Procedure procedure in cls.mixedInClass!.mixin.procedures) {
|
||||
if (procedure.containsSuperCalls) {
|
||||
_isMixinApplicationWithMembers = true;
|
||||
continue;
|
||||
|
@ -434,39 +398,41 @@ class KClassEnvImpl implements KClassEnv {
|
|||
}
|
||||
|
||||
@override
|
||||
MemberEntity lookupMember(IrToElementMap elementMap, Name name) {
|
||||
MemberEntity? lookupMember(
|
||||
covariant KernelToElementMapForEnv elementMap, Name name) {
|
||||
_ensureMaps(elementMap);
|
||||
ir.Member member = _memberMap[name];
|
||||
ir.Member? member = _memberMap![name];
|
||||
return member != null ? elementMap.getMember(member) : null;
|
||||
}
|
||||
|
||||
@override
|
||||
void forEachMember(IrToElementMap elementMap, void f(MemberEntity member)) {
|
||||
_ensureMaps(elementMap);
|
||||
_members.forEach((ir.Member member) {
|
||||
_ensureMaps(elementMap as KernelToElementMapForEnv);
|
||||
_members!.forEach((ir.Member member) {
|
||||
f(elementMap.getMember(member));
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
ConstructorEntity lookupConstructor(IrToElementMap elementMap, String name) {
|
||||
_ensureMaps(elementMap);
|
||||
ir.Member constructor = _constructorMap[name];
|
||||
ConstructorEntity? lookupConstructor(
|
||||
IrToElementMap elementMap, String? name) {
|
||||
_ensureMaps(elementMap as KernelToElementMapForEnv);
|
||||
ir.Member? constructor = _constructorMap![name!];
|
||||
return constructor != null ? elementMap.getConstructor(constructor) : null;
|
||||
}
|
||||
|
||||
@override
|
||||
void forEachConstructor(
|
||||
IrToElementMap elementMap, void f(ConstructorEntity constructor)) {
|
||||
_ensureMaps(elementMap);
|
||||
_constructorMap.values.forEach((ir.Member constructor) {
|
||||
_ensureMaps(elementMap as KernelToElementMapForEnv);
|
||||
_constructorMap!.values.forEach((ir.Member constructor) {
|
||||
f(elementMap.getConstructor(constructor));
|
||||
});
|
||||
}
|
||||
|
||||
void addConstructorBody(ConstructorBodyEntity constructorBody) {
|
||||
_constructorBodyList ??= <ConstructorBodyEntity>[];
|
||||
_constructorBodyList.add(constructorBody);
|
||||
_constructorBodyList!.add(constructorBody);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -486,7 +452,7 @@ class KClassEnvImpl implements KClassEnv {
|
|||
constructorMap = const <String, ir.Member>{};
|
||||
} else {
|
||||
constructorMap = <String, ir.Member>{};
|
||||
_constructorMap.forEach((String name, ir.Member node) {
|
||||
_constructorMap!.forEach((String name, ir.Member node) {
|
||||
MemberEntity member = kElementMap.getMember(node);
|
||||
if (liveMemberUsage.containsKey(member)) {
|
||||
constructorMap[name] = node;
|
||||
|
@ -497,7 +463,7 @@ class KClassEnvImpl implements KClassEnv {
|
|||
memberMap = const <Name, ir.Member>{};
|
||||
} else {
|
||||
memberMap = <Name, ir.Member>{};
|
||||
_memberMap.forEach((Name name, ir.Member node) {
|
||||
_memberMap!.forEach((Name name, ir.Member node) {
|
||||
MemberEntity member = kElementMap.getMember(node);
|
||||
if (liveMemberUsage.containsKey(member)) {
|
||||
memberMap[name] = node;
|
||||
|
@ -508,7 +474,7 @@ class KClassEnvImpl implements KClassEnv {
|
|||
members = const <ir.Member>[];
|
||||
} else {
|
||||
members = <ir.Member>[];
|
||||
_members.forEach((ir.Member node) {
|
||||
_members!.forEach((ir.Member node) {
|
||||
MemberEntity member = kElementMap.getMember(node);
|
||||
if (liveMemberUsage.containsKey(member)) {
|
||||
members.add(node);
|
||||
|
@ -523,15 +489,15 @@ class KClassEnvImpl implements KClassEnv {
|
|||
abstract class KClassData implements interfaces.KClassData {
|
||||
ir.Class get node;
|
||||
|
||||
InterfaceType get thisType;
|
||||
InterfaceType get jsInteropType;
|
||||
InterfaceType /*?*/ get rawType;
|
||||
InterfaceType /*?*/ get instantiationToBounds;
|
||||
InterfaceType get supertype;
|
||||
InterfaceType get mixedInType;
|
||||
List<InterfaceType> get interfaces;
|
||||
OrderedTypeSet get orderedTypeSet;
|
||||
DartType get callType;
|
||||
InterfaceType? get thisType;
|
||||
InterfaceType? get jsInteropType;
|
||||
InterfaceType? get rawType;
|
||||
InterfaceType? get instantiationToBounds;
|
||||
InterfaceType? get supertype;
|
||||
InterfaceType? get mixedInType;
|
||||
List<InterfaceType>? get interfaces;
|
||||
OrderedTypeSet? get orderedTypeSet;
|
||||
DartType? get callType;
|
||||
|
||||
bool get isEnumClass;
|
||||
bool get isMixinApplication;
|
||||
|
@ -548,27 +514,27 @@ class KClassDataImpl implements KClassData {
|
|||
@override
|
||||
final ir.Class node;
|
||||
@override
|
||||
bool isMixinApplication;
|
||||
late bool isMixinApplication;
|
||||
|
||||
@override
|
||||
InterfaceType thisType;
|
||||
InterfaceType? thisType;
|
||||
@override
|
||||
InterfaceType jsInteropType;
|
||||
InterfaceType? jsInteropType;
|
||||
@override
|
||||
InterfaceType rawType;
|
||||
InterfaceType? rawType;
|
||||
@override
|
||||
InterfaceType instantiationToBounds;
|
||||
InterfaceType? instantiationToBounds;
|
||||
@override
|
||||
InterfaceType supertype;
|
||||
InterfaceType? supertype;
|
||||
@override
|
||||
InterfaceType mixedInType;
|
||||
InterfaceType? mixedInType;
|
||||
@override
|
||||
List<InterfaceType> interfaces;
|
||||
List<InterfaceType>? interfaces;
|
||||
@override
|
||||
OrderedTypeSet orderedTypeSet;
|
||||
OrderedTypeSet? orderedTypeSet;
|
||||
|
||||
Iterable<ConstantValue> _metadata;
|
||||
List<Variance> _variances;
|
||||
Iterable<ConstantValue>? _metadata;
|
||||
List<Variance>? _variances;
|
||||
|
||||
KClassDataImpl(this.node);
|
||||
|
||||
|
@ -576,7 +542,7 @@ class KClassDataImpl implements KClassData {
|
|||
bool get isEnumClass => node.isEnum;
|
||||
|
||||
@override
|
||||
FunctionType callType;
|
||||
FunctionType? callType;
|
||||
bool isCallTypeComputed = false;
|
||||
|
||||
@override
|
||||
|
@ -602,11 +568,11 @@ abstract class KMemberData implements interfaces.KMemberData {
|
|||
@override
|
||||
ir.Member get node;
|
||||
|
||||
StaticTypeCache staticTypes;
|
||||
StaticTypeCache? staticTypes;
|
||||
|
||||
Iterable<ConstantValue> getMetadata(IrToElementMap elementMap);
|
||||
|
||||
InterfaceType getMemberThisType(JsToElementMap elementMap);
|
||||
InterfaceType? getMemberThisType(JsToElementMap elementMap);
|
||||
|
||||
ClassTypeVariableAccess get classTypeVariableAccess;
|
||||
|
||||
|
@ -619,10 +585,10 @@ abstract class KMemberDataImpl implements KMemberData {
|
|||
@override
|
||||
final ir.Member node;
|
||||
|
||||
Iterable<ConstantValue> _metadata;
|
||||
Iterable<ConstantValue>? _metadata;
|
||||
|
||||
@override
|
||||
StaticTypeCache staticTypes;
|
||||
StaticTypeCache? staticTypes;
|
||||
|
||||
KMemberDataImpl(this.node);
|
||||
|
||||
|
@ -635,9 +601,9 @@ abstract class KMemberDataImpl implements KMemberData {
|
|||
}
|
||||
|
||||
@override
|
||||
InterfaceType getMemberThisType(JsToElementMap elementMap) {
|
||||
InterfaceType? getMemberThisType(JsToElementMap elementMap) {
|
||||
MemberEntity member = elementMap.getMember(node);
|
||||
ClassEntity cls = member.enclosingClass;
|
||||
ClassEntity? cls = member.enclosingClass;
|
||||
if (cls != null) {
|
||||
return elementMap.elementEnvironment.getThisType(cls);
|
||||
}
|
||||
|
@ -651,21 +617,21 @@ abstract class KFunctionData implements KMemberData {
|
|||
List<TypeVariableType> getFunctionTypeVariables(IrToElementMap elementMap);
|
||||
|
||||
void forEachParameter(JsToElementMap elementMap,
|
||||
void f(DartType type, String name, ConstantValue defaultValue));
|
||||
void f(DartType type, String? name, ConstantValue? defaultValue));
|
||||
}
|
||||
|
||||
abstract class KFunctionDataMixin implements KFunctionData {
|
||||
ir.FunctionNode get functionNode;
|
||||
List<TypeVariableType> _typeVariables;
|
||||
List<TypeVariableType>? _typeVariables;
|
||||
|
||||
@override
|
||||
List<TypeVariableType> /*!*/ getFunctionTypeVariables(
|
||||
List<TypeVariableType> getFunctionTypeVariables(
|
||||
covariant KernelToElementMapForEnv elementMap) {
|
||||
if (_typeVariables == null) {
|
||||
if (functionNode.typeParameters.isEmpty) {
|
||||
_typeVariables = const <TypeVariableType>[];
|
||||
} else {
|
||||
ir.TreeNode parent = functionNode.parent;
|
||||
ir.TreeNode? parent = functionNode.parent;
|
||||
if (parent is ir.Constructor ||
|
||||
(parent is ir.Procedure &&
|
||||
parent.kind == ir.ProcedureKind.Factory)) {
|
||||
|
@ -676,12 +642,12 @@ abstract class KFunctionDataMixin implements KFunctionData {
|
|||
return elementMap
|
||||
.getDartType(ir.TypeParameterType(
|
||||
typeParameter, ir.Nullability.nonNullable))
|
||||
.withoutNullability;
|
||||
.withoutNullability as TypeVariableType;
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
return _typeVariables;
|
||||
return _typeVariables!;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -690,9 +656,9 @@ class KFunctionDataImpl extends KMemberDataImpl
|
|||
implements KFunctionData {
|
||||
@override
|
||||
final ir.FunctionNode functionNode;
|
||||
FunctionType _type;
|
||||
FunctionType? _type;
|
||||
|
||||
KFunctionDataImpl(ir.Member node, this.functionNode) : super(node);
|
||||
KFunctionDataImpl(super.node, this.functionNode);
|
||||
|
||||
@override
|
||||
FunctionType getFunctionType(covariant KernelToElementMapForEnv elementMap) {
|
||||
|
@ -701,12 +667,12 @@ class KFunctionDataImpl extends KMemberDataImpl
|
|||
|
||||
@override
|
||||
void forEachParameter(JsToElementMap elementMap,
|
||||
void f(DartType type, String name, ConstantValue defaultValue)) {
|
||||
void f(DartType type, String? name, ConstantValue? defaultValue)) {
|
||||
void handleParameter(ir.VariableDeclaration parameter,
|
||||
{bool isOptional = true}) {
|
||||
DartType type = elementMap.getDartType(parameter.type);
|
||||
String name = parameter.name;
|
||||
ConstantValue defaultValue;
|
||||
String? name = parameter.name;
|
||||
ConstantValue? defaultValue;
|
||||
if (isOptional) {
|
||||
if (parameter.initializer != null) {
|
||||
defaultValue =
|
||||
|
@ -730,7 +696,7 @@ class KFunctionDataImpl extends KMemberDataImpl
|
|||
@override
|
||||
FunctionData convert() {
|
||||
return FunctionDataImpl(
|
||||
node, functionNode, RegularMemberDefinition(node), staticTypes);
|
||||
node, functionNode, RegularMemberDefinition(node), staticTypes!);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -744,10 +710,9 @@ abstract class KConstructorData extends KFunctionData {}
|
|||
|
||||
class KConstructorDataImpl extends KFunctionDataImpl
|
||||
implements KConstructorData {
|
||||
ConstructorBodyEntity constructorBody;
|
||||
ConstructorBodyEntity? constructorBody;
|
||||
|
||||
KConstructorDataImpl(ir.Member node, ir.FunctionNode functionNode)
|
||||
: super(node, functionNode);
|
||||
KConstructorDataImpl(super.node, super.functionNode);
|
||||
|
||||
@override
|
||||
JConstructorData convert() {
|
||||
|
@ -757,7 +722,7 @@ class KConstructorDataImpl extends KFunctionDataImpl
|
|||
} else {
|
||||
definition = RegularMemberDefinition(node);
|
||||
}
|
||||
return JConstructorDataImpl(node, functionNode, definition, staticTypes);
|
||||
return JConstructorDataImpl(node, functionNode, definition, staticTypes!);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -778,7 +743,7 @@ abstract class KFieldData extends KMemberData {
|
|||
}
|
||||
|
||||
class KFieldDataImpl extends KMemberDataImpl implements KFieldData {
|
||||
DartType _type;
|
||||
DartType? _type;
|
||||
|
||||
@override
|
||||
final bool isLateBackingField;
|
||||
|
@ -786,13 +751,12 @@ class KFieldDataImpl extends KMemberDataImpl implements KFieldData {
|
|||
@override
|
||||
final bool isLateFinalBackingField;
|
||||
|
||||
KFieldDataImpl(ir.Field node,
|
||||
{/*required*/ this.isLateBackingField,
|
||||
/*required*/ this.isLateFinalBackingField})
|
||||
: super(node);
|
||||
KFieldDataImpl(super.node,
|
||||
{required this.isLateBackingField,
|
||||
required this.isLateFinalBackingField});
|
||||
|
||||
@override
|
||||
ir.Field get node => super.node;
|
||||
ir.Field get node => super.node as ir.Field;
|
||||
|
||||
@override
|
||||
DartType getFieldType(covariant KernelToElementMapForEnv elementMap) {
|
||||
|
@ -807,15 +771,15 @@ class KFieldDataImpl extends KMemberDataImpl implements KFieldData {
|
|||
|
||||
@override
|
||||
JFieldData convert() {
|
||||
return JFieldDataImpl(node, RegularMemberDefinition(node), staticTypes);
|
||||
return JFieldDataImpl(node, RegularMemberDefinition(node), staticTypes!);
|
||||
}
|
||||
}
|
||||
|
||||
class KTypeVariableData implements interfaces.KTypeVariableData {
|
||||
@override
|
||||
final ir.TypeParameter node;
|
||||
DartType _bound;
|
||||
DartType _defaultType;
|
||||
DartType? _bound;
|
||||
DartType? _defaultType;
|
||||
|
||||
KTypeVariableData(this.node);
|
||||
|
||||
|
@ -824,10 +788,7 @@ class KTypeVariableData implements interfaces.KTypeVariableData {
|
|||
}
|
||||
|
||||
DartType getDefaultType(IrToElementMap elementMap) {
|
||||
// TODO(34522): Remove `?? const ir.DynamicType()` when issue 34522 is
|
||||
// fixed.
|
||||
return _defaultType ??=
|
||||
elementMap.getDartType(node.defaultType ?? const ir.DynamicType());
|
||||
return _defaultType ??= elementMap.getDartType(node.defaultType);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
Loading…
Reference in a new issue