mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
[dart2js] migreate js_model/element_map_impl
Change-Id: Ie490c4b592a9caa155d22eefe24af1a2816414df Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259640 Reviewed-by: Mayank Patke <fishythefish@google.com> Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
81efd79749
commit
026f253075
9 changed files with 386 additions and 417 deletions
|
@ -152,7 +152,7 @@ abstract class CommonElements {
|
|||
// so this cannot be found in kernel. Find a consistent way to handle
|
||||
// this and similar cases.
|
||||
return _symbolConstructorTarget ??=
|
||||
_findConstructor(symbolImplementationClass, '');
|
||||
_findConstructor(symbolImplementationClass, '')!;
|
||||
}
|
||||
|
||||
void _ensureSymbolConstructorDependencies() {
|
||||
|
@ -324,14 +324,14 @@ abstract class CommonElements {
|
|||
setter: setter, required: required) as T?;
|
||||
}
|
||||
|
||||
T _findClassMember<T extends MemberEntity>(ClassEntity cls, String name,
|
||||
T? _findClassMember<T extends MemberEntity>(ClassEntity cls, String name,
|
||||
{bool setter = false, bool required = true}) {
|
||||
return _env.lookupLocalClassMember(
|
||||
cls, Name(name, cls.library.canonicalUri, isSetter: setter),
|
||||
required: required) as T;
|
||||
required: required) as T?;
|
||||
}
|
||||
|
||||
ConstructorEntity _findConstructor(ClassEntity cls, String name,
|
||||
ConstructorEntity? _findConstructor(ClassEntity cls, String name,
|
||||
{bool required = true}) {
|
||||
return _env.lookupConstructor(cls, name, required: required);
|
||||
}
|
||||
|
@ -395,9 +395,9 @@ abstract class CommonElements {
|
|||
}
|
||||
|
||||
late final ConstructorEntity mapLiteralConstructor =
|
||||
_env.lookupConstructor(mapLiteralClass, '_literal');
|
||||
_env.lookupConstructor(mapLiteralClass, '_literal')!;
|
||||
late final ConstructorEntity mapLiteralConstructorEmpty =
|
||||
_env.lookupConstructor(mapLiteralClass, '_empty');
|
||||
_env.lookupConstructor(mapLiteralClass, '_empty')!;
|
||||
late final FunctionEntity mapLiteralUntypedMaker =
|
||||
_env.lookupLocalClassMember(mapLiteralClass,
|
||||
PrivateName('_makeLiteral', mapLiteralClass.library.canonicalUri))
|
||||
|
@ -411,9 +411,9 @@ abstract class CommonElements {
|
|||
_findClass(_env.lookupLibrary(Uris.dart_collection), 'LinkedHashSet')!;
|
||||
|
||||
late final ConstructorEntity setLiteralConstructor =
|
||||
_env.lookupConstructor(setLiteralClass, '_literal');
|
||||
_env.lookupConstructor(setLiteralClass, '_literal')!;
|
||||
late final ConstructorEntity setLiteralConstructorEmpty =
|
||||
_env.lookupConstructor(setLiteralClass, '_empty');
|
||||
_env.lookupConstructor(setLiteralClass, '_empty')!;
|
||||
late final FunctionEntity setLiteralUntypedMaker =
|
||||
_env.lookupLocalClassMember(setLiteralClass,
|
||||
PrivateName('_makeLiteral', setLiteralClass.library.canonicalUri))
|
||||
|
@ -489,7 +489,7 @@ abstract class CommonElements {
|
|||
ClassEntity get streamIterator => _findAsyncHelperClass("StreamIterator");
|
||||
|
||||
ConstructorEntity get streamIteratorConstructor =>
|
||||
_env.lookupConstructor(streamIterator, "");
|
||||
_env.lookupConstructor(streamIterator, "")!;
|
||||
|
||||
late final FunctionEntity syncStarIterableFactory =
|
||||
_findAsyncHelperFunction('_makeSyncStarIterable');
|
||||
|
@ -580,7 +580,7 @@ abstract class CommonElements {
|
|||
_findInterceptorsFunction('getNativeInterceptor');
|
||||
|
||||
late final ConstructorEntity jsArrayTypedConstructor =
|
||||
_findConstructor(jsArrayClass, 'typed');
|
||||
_findConstructor(jsArrayClass, 'typed')!;
|
||||
|
||||
// From dart:_js_helper
|
||||
// TODO(johnniwinther): Avoid the need for this (from [CheckedModeHelper]).
|
||||
|
@ -619,7 +619,7 @@ abstract class CommonElements {
|
|||
InterfaceType get requiredSentinelType => _getRawType(requiredSentinelClass);
|
||||
|
||||
late final MemberEntity invocationTypeArgumentGetter =
|
||||
_findClassMember(jsInvocationMirrorClass, 'typeArguments');
|
||||
_findClassMember(jsInvocationMirrorClass, 'typeArguments')!;
|
||||
|
||||
/// Interface used to determine if an object has the JavaScript
|
||||
/// indexing behavior. The interface is only visible to specific libraries.
|
||||
|
@ -813,7 +813,7 @@ abstract class CommonElements {
|
|||
ClassEntity get _rtiUniverseClass => _findClass(rtiLibrary, '_Universe')!;
|
||||
|
||||
FieldEntity _findRtiClassField(String name) =>
|
||||
_findClassMember(_rtiImplClass, name);
|
||||
_findClassMember(_rtiImplClass, name)!;
|
||||
|
||||
late final FieldEntity rtiAsField = _findRtiClassField('_as');
|
||||
|
||||
|
@ -825,19 +825,19 @@ abstract class CommonElements {
|
|||
_findRtiClassField('_precomputed1');
|
||||
|
||||
late final FunctionEntity rtiEvalMethod =
|
||||
_findClassMember(_rtiImplClass, '_eval');
|
||||
_findClassMember(_rtiImplClass, '_eval')!;
|
||||
|
||||
late final FunctionEntity rtiBindMethod =
|
||||
_findClassMember(_rtiImplClass, '_bind');
|
||||
_findClassMember(_rtiImplClass, '_bind')!;
|
||||
|
||||
late final FunctionEntity rtiAddRulesMethod =
|
||||
_findClassMember(_rtiUniverseClass, 'addRules');
|
||||
_findClassMember(_rtiUniverseClass, 'addRules')!;
|
||||
|
||||
late final FunctionEntity rtiAddErasedTypesMethod =
|
||||
_findClassMember(_rtiUniverseClass, 'addErasedTypes');
|
||||
_findClassMember(_rtiUniverseClass, 'addErasedTypes')!;
|
||||
|
||||
late final FunctionEntity rtiAddTypeParameterVariancesMethod =
|
||||
_findClassMember(_rtiUniverseClass, 'addTypeParameterVariances');
|
||||
_findClassMember(_rtiUniverseClass, 'addTypeParameterVariances')!;
|
||||
|
||||
FunctionEntity get installSpecializedIsTest =>
|
||||
_findRtiFunction('_installSpecializedIsTest');
|
||||
|
@ -1057,10 +1057,10 @@ class KCommonElements extends CommonElements {
|
|||
late final ClassEntity pragmaClass = _findClass(coreLibrary, 'pragma')!;
|
||||
|
||||
late final FieldEntity pragmaClassNameField =
|
||||
_findClassMember(pragmaClass, 'name');
|
||||
_findClassMember(pragmaClass, 'name')!;
|
||||
|
||||
late final FieldEntity pragmaClassOptionsField =
|
||||
_findClassMember(pragmaClass, 'options');
|
||||
_findClassMember(pragmaClass, 'options')!;
|
||||
}
|
||||
|
||||
class JCommonElements extends CommonElements {
|
||||
|
@ -1106,9 +1106,9 @@ class JCommonElements extends CommonElements {
|
|||
}
|
||||
|
||||
late final FunctionEntity jsArrayRemoveLast =
|
||||
_findClassMember(jsArrayClass, 'removeLast');
|
||||
_findClassMember(jsArrayClass, 'removeLast')!;
|
||||
|
||||
late final FunctionEntity jsArrayAdd = _findClassMember(jsArrayClass, 'add');
|
||||
late final FunctionEntity jsArrayAdd = _findClassMember(jsArrayClass, 'add')!;
|
||||
|
||||
bool _isJsStringClass(ClassEntity cls) {
|
||||
return cls.name == 'JSString' && cls.library == interceptorsLibrary;
|
||||
|
@ -1141,13 +1141,13 @@ class JCommonElements extends CommonElements {
|
|||
}
|
||||
|
||||
FunctionEntity get jsStringSplit =>
|
||||
_jsStringSplit ??= _findClassMember(jsStringClass, 'split');
|
||||
_jsStringSplit ??= _findClassMember(jsStringClass, 'split')!;
|
||||
|
||||
late final FunctionEntity jsStringToString =
|
||||
_findClassMember(jsStringClass, 'toString');
|
||||
_findClassMember(jsStringClass, 'toString')!;
|
||||
|
||||
late final FunctionEntity jsStringOperatorAdd =
|
||||
_findClassMember(jsStringClass, '+');
|
||||
_findClassMember(jsStringClass, '+')!;
|
||||
|
||||
late final ClassEntity jsConstClass = _findClass(foreignLibrary, 'JS_CONST')!;
|
||||
|
||||
|
@ -1224,10 +1224,10 @@ class JCommonElements extends CommonElements {
|
|||
// both resolution and codegen.
|
||||
abstract class ElementEnvironment {
|
||||
/// Returns the main library for the compilation.
|
||||
LibraryEntity get mainLibrary;
|
||||
LibraryEntity? get mainLibrary;
|
||||
|
||||
/// Returns the main method for the compilation.
|
||||
FunctionEntity get mainFunction;
|
||||
FunctionEntity? get mainFunction;
|
||||
|
||||
/// Returns all known libraries.
|
||||
Iterable<LibraryEntity> get libraries;
|
||||
|
@ -1276,7 +1276,7 @@ abstract class ElementEnvironment {
|
|||
|
||||
/// Lookup the constructor [name] in [cls], fail if the class is missing and
|
||||
/// [required].
|
||||
ConstructorEntity lookupConstructor(ClassEntity cls, String name,
|
||||
ConstructorEntity? lookupConstructor(ClassEntity cls, String name,
|
||||
{bool required = false});
|
||||
|
||||
/// Calls [f] for each class member declared in [cls].
|
||||
|
@ -1394,7 +1394,7 @@ abstract class ElementEnvironment {
|
|||
///
|
||||
/// The mixin classes of `B` and `C` are `A` and `B`, respectively, but the
|
||||
/// _effective_ mixin class of both is `A`.
|
||||
ClassEntity getEffectiveMixinClass(ClassEntity cls);
|
||||
ClassEntity? getEffectiveMixinClass(ClassEntity cls);
|
||||
}
|
||||
|
||||
abstract class KElementEnvironment extends ElementEnvironment {
|
||||
|
|
|
@ -281,7 +281,7 @@ class EntityDataInfoVisitor extends EntityDataVisitor {
|
|||
void addClassAndMaybeAddEffectiveMixinClass(ClassEntity cls) {
|
||||
infoBuilder.addClass(cls);
|
||||
if (elementEnvironment.isMixinApplication(cls)) {
|
||||
infoBuilder.addClass(elementEnvironment.getEffectiveMixinClass(cls));
|
||||
infoBuilder.addClass(elementEnvironment.getEffectiveMixinClass(cls)!);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -704,7 +704,7 @@ class JsClosureClassInfo extends JsScopeInfo
|
|||
ir.FunctionNode closureSourceNode,
|
||||
Map<ir.VariableDeclaration, migrated.JRecordField> boxedVariables,
|
||||
KernelScopeInfo info,
|
||||
ClassEntity enclosingClass,
|
||||
ClassEntity? enclosingClass,
|
||||
this._closureEntity,
|
||||
this._closureEntityVariable,
|
||||
this.thisLocal)
|
||||
|
|
|
@ -106,8 +106,8 @@ abstract class JsToElementMap implements interfaces.JsToElementMap {
|
|||
// only needed because effectively constant expressions are not replaced by
|
||||
// constant expressions during resolution.
|
||||
@override
|
||||
ConstantValue getConstantValue(
|
||||
ir.Member memberContext, ir.Expression expression,
|
||||
ConstantValue? getConstantValue(
|
||||
ir.Member memberContext, ir.Expression? expression,
|
||||
{bool requireConstant = true, bool implicitNull = false});
|
||||
|
||||
/// Returns the [ConstantValue] for the sentinel used to indicate that a
|
||||
|
@ -136,11 +136,11 @@ abstract class JsToElementMap implements interfaces.JsToElementMap {
|
|||
MemberDefinition getMemberDefinition(MemberEntity member);
|
||||
|
||||
/// Returns the [ir.Member] containing the definition of [member], if any.
|
||||
ir.Member getMemberContextNode(MemberEntity member);
|
||||
ir.Member? getMemberContextNode(MemberEntity member);
|
||||
|
||||
/// Returns the type of `this` in [member], or `null` if member is defined in
|
||||
/// a static context.
|
||||
InterfaceType getMemberThisType(MemberEntity member);
|
||||
InterfaceType? getMemberThisType(MemberEntity member);
|
||||
|
||||
/// Returns how [member] has access to type variables of the this type
|
||||
/// returned by [getMemberThisType].
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -19,8 +19,8 @@ abstract class JsToElementMap {
|
|||
JCommonElements get commonElements;
|
||||
JElementEnvironment get elementEnvironment;
|
||||
DartTypes get types;
|
||||
ConstantValue getConstantValue(
|
||||
ir.Member memberContext, ir.Expression expression,
|
||||
ConstantValue? getConstantValue(
|
||||
ir.Member memberContext, ir.Expression? expression,
|
||||
{bool requireConstant = true, bool implicitNull = false});
|
||||
DartType getDartType(ir.DartType type);
|
||||
|
||||
|
|
|
@ -737,7 +737,7 @@ class SignatureFunctionData implements FunctionData {
|
|||
|
||||
@override
|
||||
final MemberDefinition definition;
|
||||
final InterfaceType memberThisType;
|
||||
final InterfaceType? memberThisType;
|
||||
@override
|
||||
final ClassTypeVariableAccess classTypeVariableAccess;
|
||||
List<ir.TypeParameter> get typeParameters => _typeParameters.loaded();
|
||||
|
@ -753,8 +753,8 @@ class SignatureFunctionData implements FunctionData {
|
|||
factory SignatureFunctionData.readFromDataSource(DataSourceReader source) {
|
||||
source.begin(tag);
|
||||
MemberDefinition definition = MemberDefinition.readFromDataSource(source);
|
||||
InterfaceType /*?*/ memberThisType =
|
||||
source.readDartTypeOrNull() as InterfaceType /*?*/;
|
||||
InterfaceType? memberThisType =
|
||||
source.readDartTypeOrNull() as InterfaceType?;
|
||||
Deferrable<List<ir.TypeParameter>> typeParameters =
|
||||
source.readDeferrable(() => source.readTypeParameterNodes());
|
||||
ClassTypeVariableAccess classTypeVariableAccess =
|
||||
|
@ -804,9 +804,7 @@ class SignatureFunctionData implements FunctionData {
|
|||
}
|
||||
|
||||
@override
|
||||
InterfaceType getMemberThisType(JsToElementMap elementMap) {
|
||||
return memberThisType;
|
||||
}
|
||||
InterfaceType? getMemberThisType(JsToElementMap elementMap) => memberThisType;
|
||||
}
|
||||
|
||||
abstract class DelegatedFunctionData implements FunctionData {
|
||||
|
|
|
@ -640,7 +640,7 @@ void forEachOrderedParameterAsLocal(
|
|||
GlobalLocalsMap globalLocalsMap,
|
||||
JsToElementMap elementMap,
|
||||
FunctionEntity function,
|
||||
void f(Local parameter, {bool? isElided})) {
|
||||
void f(Local parameter, {required bool isElided})) {
|
||||
KernelToLocalsMap localsMap = globalLocalsMap.getLocalsMap(function);
|
||||
forEachOrderedParameter(elementMap, function,
|
||||
(ir.VariableDeclaration variable, {required bool isElided}) {
|
||||
|
|
|
@ -14,11 +14,11 @@ DiagnosticMessage _createDiagnosticMessage(
|
|||
}
|
||||
|
||||
void reportLocatedMessage(DiagnosticReporter reporter,
|
||||
ir.LocatedMessage message, List<ir.LocatedMessage> context) {
|
||||
ir.LocatedMessage message, List<ir.LocatedMessage>? context) {
|
||||
DiagnosticMessage diagnosticMessage =
|
||||
_createDiagnosticMessage(reporter, message);
|
||||
List<DiagnosticMessage> infos = [];
|
||||
for (ir.LocatedMessage message in context) {
|
||||
for (ir.LocatedMessage message in context ?? const []) {
|
||||
infos.add(_createDiagnosticMessage(reporter, message));
|
||||
}
|
||||
reporter.reportError(diagnosticMessage, infos);
|
||||
|
|
Loading…
Reference in a new issue