mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:59:47 +00:00
6faa5f3bd0
This is work in progress. Several language features are still unimplemented or only partially implemented. Instructions for running the compiler and its output can be found in pkg/dart2wasm/dart2wasm.md. These procedures are preliminary and expected to change. The best version of d8 to use for this version of dart2wasm is 10.0.40, as explained here: https://dart-review.googlesource.com/c/sdk/+/232097 This commit also adds a dart2wasm-hostasserts-linux-x64-d8 testing configuration to run the compiler over the test suite. The history of the prototype that this is based on can be seen here: https://github.com/askeksa-google/sdk/tree/wasm_prototype Issue: https://github.com/dart-lang/sdk/issues/32894 Change-Id: I910b6ff239ef9c5f66863e4ca97b39b8202cce85 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175728 Reviewed-by: Joshua Litt <joshualitt@google.com> Commit-Queue: Aske Simon Christensen <askesc@google.com>
94 lines
3.2 KiB
Dart
94 lines
3.2 KiB
Dart
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
|
// 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.
|
|
|
|
import 'package:dart2wasm/reference_extensions.dart';
|
|
|
|
import 'package:kernel/ast.dart';
|
|
|
|
/// Information about optional parameters and their default values for a
|
|
/// member or a set of members belonging to the same override group.
|
|
class ParameterInfo {
|
|
final Member member;
|
|
int typeParamCount = 0;
|
|
late final List<Constant?> positional;
|
|
late final Map<String, Constant?> named;
|
|
|
|
// Do not access these until the info is complete.
|
|
late final List<String> names = named.keys.toList()..sort();
|
|
late final Map<String, int> nameIndex = {
|
|
for (int i = 0; i < names.length; i++) names[i]: positional.length + i
|
|
};
|
|
|
|
int get paramCount => positional.length + named.length;
|
|
|
|
static Constant? defaultValue(VariableDeclaration param) {
|
|
Expression? initializer = param.initializer;
|
|
if (initializer is ConstantExpression) {
|
|
return initializer.constant;
|
|
} else if (initializer == null) {
|
|
return null;
|
|
} else {
|
|
throw "Non-constant default value";
|
|
}
|
|
}
|
|
|
|
ParameterInfo.fromMember(Reference target) : member = target.asMember {
|
|
FunctionNode? function = member.function;
|
|
if (target.isTearOffReference) {
|
|
positional = [];
|
|
named = {};
|
|
} else if (function != null) {
|
|
typeParamCount = (member is Constructor
|
|
? member.enclosingClass!.typeParameters
|
|
: function.typeParameters)
|
|
.length;
|
|
positional = List.generate(function.positionalParameters.length, (i) {
|
|
// A required parameter has no default value.
|
|
if (i < function.requiredParameterCount) return null;
|
|
return defaultValue(function.positionalParameters[i]);
|
|
});
|
|
named = {
|
|
for (VariableDeclaration param in function.namedParameters)
|
|
param.name!: defaultValue(param)
|
|
};
|
|
} else {
|
|
// A setter parameter has no default value.
|
|
positional = [if (target.isSetter) null];
|
|
named = {};
|
|
}
|
|
}
|
|
|
|
void merge(ParameterInfo other) {
|
|
assert(typeParamCount == other.typeParamCount);
|
|
for (int i = 0; i < other.positional.length; i++) {
|
|
if (i >= positional.length) {
|
|
positional.add(other.positional[i]);
|
|
} else {
|
|
if (positional[i] == null) {
|
|
positional[i] = other.positional[i];
|
|
} else if (other.positional[i] != null) {
|
|
if (positional[i] != other.positional[i]) {
|
|
print("Mismatching default value for parameter $i: "
|
|
"${member}: ${positional[i]} vs "
|
|
"${other.member}: ${other.positional[i]}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (String name in other.named.keys) {
|
|
Constant? value = named[name];
|
|
Constant? otherValue = other.named[name];
|
|
if (value == null) {
|
|
named[name] = otherValue;
|
|
} else if (otherValue != null) {
|
|
if (value != otherValue) {
|
|
print("Mismatching default value for parameter '$name': "
|
|
"${member}: ${value} vs "
|
|
"${other.member}: ${otherValue}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|