mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
Record Typedef reference into Kernel FunctionType and resynthesyze typedefs in Analyzer.
R=ahe@google.com, paulberry@google.com, sigmund@google.com BUG= Review-Url: https://codereview.chromium.org/2986393002 .
This commit is contained in:
parent
41bcfaa4a4
commit
4ef7fd14c1
|
@ -106,6 +106,8 @@ class KernelResynthesizer {
|
|||
} else if (parentName.name == '@methods') {
|
||||
isMethod = true;
|
||||
parentName = parentName.parent;
|
||||
} else if (parentName.name == '@typedefs') {
|
||||
parentName = parentName.parent;
|
||||
}
|
||||
|
||||
ElementImpl parentElement = _getElement(parentName);
|
||||
|
@ -734,6 +736,12 @@ class _KernelUnitResynthesizerContextImpl
|
|||
}
|
||||
|
||||
if (kernelType is kernel.FunctionType) {
|
||||
if (kernelType.typedef != null) {
|
||||
FunctionTypeAliasElementImpl element = libraryContext.resynthesizer
|
||||
._getElement(kernelType.typedef.canonicalName);
|
||||
return element.type;
|
||||
}
|
||||
|
||||
var functionElement = new FunctionElementImpl.synthetic([], null);
|
||||
functionElement.enclosingElement = context;
|
||||
|
||||
|
|
|
@ -9226,7 +9226,7 @@ E e;
|
|||
}
|
||||
|
||||
test_type_reference_to_import() async {
|
||||
addLibrarySource('/a.dart', 'class C {} enum E { v }; typedef F();');
|
||||
addLibrarySource('/a.dart', 'class C {} enum E { v } typedef F();');
|
||||
var library = await checkLibrary('import "a.dart"; C c; E e; F f;');
|
||||
checkElementText(library, r'''
|
||||
import 'a.dart';
|
||||
|
|
|
@ -220,21 +220,11 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_const_invokeConstructor_unnamed_unresolved3();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_reference_type() async {
|
||||
await super.test_const_reference_type();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_reference_type_functionType() async {
|
||||
await super.test_const_reference_type_functionType();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_reference_type_imported() async {
|
||||
await super.test_const_reference_type_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_reference_type_imported_withPrefix() async {
|
||||
await super.test_const_reference_type_imported_withPrefix();
|
||||
|
@ -521,11 +511,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_import_self();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_inferred_type_is_typedef() async {
|
||||
await super.test_inferred_type_is_typedef();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_inferred_type_refers_to_function_typed_param_of_typedef() async {
|
||||
await super.test_inferred_type_refers_to_function_typed_param_of_typedef();
|
||||
|
@ -778,76 +763,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_type_invalid_typeParameter_asPrefix();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_lib_to_lib() async {
|
||||
await super.test_type_reference_lib_to_lib();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_lib_to_part() async {
|
||||
await super.test_type_reference_lib_to_part();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_part_to_lib() async {
|
||||
await super.test_type_reference_part_to_lib();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_part_to_other_part() async {
|
||||
await super.test_type_reference_part_to_other_part();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_part_to_part() async {
|
||||
await super.test_type_reference_part_to_part();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import() async {
|
||||
await super.test_type_reference_to_import();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_export() async {
|
||||
await super.test_type_reference_to_import_export();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_export_export() async {
|
||||
await super.test_type_reference_to_import_export_export();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_export_export_in_subdirs() async {
|
||||
await super.test_type_reference_to_import_export_export_in_subdirs();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_export_in_subdirs() async {
|
||||
await super.test_type_reference_to_import_export_in_subdirs();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_part() async {
|
||||
await super.test_type_reference_to_import_part();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_part_in_subdir() async {
|
||||
await super.test_type_reference_to_import_part_in_subdir();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_relative() async {
|
||||
await super.test_type_reference_to_import_relative();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_typedef() async {
|
||||
await super.test_type_reference_to_typedef();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_typedef_with_type_arguments() async {
|
||||
await super.test_type_reference_to_typedef_with_type_arguments();
|
||||
|
|
|
@ -61,14 +61,19 @@ class KernelFunctionTypeAliasBuilder
|
|||
return thisType;
|
||||
}
|
||||
thisType = const InvalidType();
|
||||
DartType builtType = type?.build(library) ?? const DynamicType();
|
||||
if (typeVariables != null) {
|
||||
for (KernelTypeVariableBuilder tv in typeVariables) {
|
||||
tv.parameter.bound = tv?.bound?.build(library);
|
||||
target.typeParameters.add(tv.parameter..parent = target);
|
||||
FunctionType builtType = type?.build(library);
|
||||
if (builtType != null) {
|
||||
builtType.typedefReference = target.reference;
|
||||
if (typeVariables != null) {
|
||||
for (KernelTypeVariableBuilder tv in typeVariables) {
|
||||
tv.parameter.bound = tv?.bound?.build(library);
|
||||
target.typeParameters.add(tv.parameter..parent = target);
|
||||
}
|
||||
}
|
||||
return thisType = builtType;
|
||||
} else {
|
||||
return thisType = const DynamicType();
|
||||
}
|
||||
return thisType = builtType;
|
||||
}
|
||||
|
||||
/// [arguments] have already been built.
|
||||
|
|
|
@ -37,7 +37,7 @@ class KernelFunctionTypeBuilder extends FunctionTypeBuilder
|
|||
List<FormalParameterBuilder> formals)
|
||||
: super(charOffset, fileUri, returnType, typeVariables, formals);
|
||||
|
||||
DartType build(LibraryBuilder library) {
|
||||
FunctionType build(LibraryBuilder library) {
|
||||
DartType builtReturnType =
|
||||
returnType?.build(library) ?? const DynamicType();
|
||||
List<DartType> positionalParameters = <DartType>[];
|
||||
|
|
|
@ -4143,6 +4143,9 @@ class FunctionType extends DartType {
|
|||
@informative
|
||||
final List<String> positionalParameterNames;
|
||||
|
||||
/// The [Typedef] this function type is created for.
|
||||
Reference typedefReference;
|
||||
|
||||
final DartType returnType;
|
||||
int _hashCode;
|
||||
|
||||
|
@ -4150,11 +4153,15 @@ class FunctionType extends DartType {
|
|||
{this.namedParameters: const <NamedType>[],
|
||||
this.typeParameters: const <TypeParameter>[],
|
||||
int requiredParameterCount,
|
||||
this.positionalParameterNames: const <String>[]})
|
||||
this.positionalParameterNames: const <String>[],
|
||||
this.typedefReference})
|
||||
: this.positionalParameters = positionalParameters,
|
||||
this.requiredParameterCount =
|
||||
requiredParameterCount ?? positionalParameters.length;
|
||||
|
||||
/// The [Typedef] this function type is created for.
|
||||
Typedef get typedef => typedefReference?.asTypedef;
|
||||
|
||||
accept(DartTypeVisitor v) => v.visitFunctionType(this);
|
||||
|
||||
visitChildren(Visitor v) {
|
||||
|
|
|
@ -343,7 +343,7 @@ class BinaryBuilder {
|
|||
}
|
||||
|
||||
Reference readTypedefReference() {
|
||||
return readCanonicalNameReference().getReference();
|
||||
return readCanonicalNameReference()?.getReference();
|
||||
}
|
||||
|
||||
Name readName() {
|
||||
|
@ -1176,6 +1176,7 @@ class BinaryBuilder {
|
|||
var positional = readDartTypeList();
|
||||
var named = readNamedTypeList();
|
||||
var positionalNames = readStringReferenceList();
|
||||
var typedefReference = readTypedefReference();
|
||||
assert(positional.length + named.length == totalParameterCount);
|
||||
var returnType = readDartType();
|
||||
typeParameterStack.length = typeParameterStackHeight;
|
||||
|
@ -1183,7 +1184,8 @@ class BinaryBuilder {
|
|||
typeParameters: typeParameters,
|
||||
requiredParameterCount: requiredParameterCount,
|
||||
namedParameters: named,
|
||||
positionalParameterNames: positionalNames);
|
||||
positionalParameterNames: positionalNames,
|
||||
typedefReference: typedefReference);
|
||||
case Tag.SimpleFunctionType:
|
||||
var positional = readDartTypeList();
|
||||
var positionalNames = readStringReferenceList();
|
||||
|
|
|
@ -1130,7 +1130,8 @@ class BinaryPrinter extends Visitor {
|
|||
visitFunctionType(FunctionType node) {
|
||||
if (node.requiredParameterCount == node.positionalParameters.length &&
|
||||
node.typeParameters.isEmpty &&
|
||||
node.namedParameters.isEmpty) {
|
||||
node.namedParameters.isEmpty &&
|
||||
node.typedefReference == null) {
|
||||
writeByte(Tag.SimpleFunctionType);
|
||||
writeNodeList(node.positionalParameters);
|
||||
writeStringReferenceList(node.positionalParameterNames);
|
||||
|
@ -1145,6 +1146,7 @@ class BinaryPrinter extends Visitor {
|
|||
writeNodeList(node.positionalParameters);
|
||||
writeNodeList(node.namedParameters);
|
||||
writeStringReferenceList(node.positionalParameterNames);
|
||||
writeReference(node.typedefReference);
|
||||
writeNode(node.returnType);
|
||||
_typeParameterIndexer.exit(node.typeParameters);
|
||||
}
|
||||
|
|
|
@ -1097,6 +1097,11 @@ void StreamingScopeBuilder::VisitFunctionType(bool simple) {
|
|||
}
|
||||
|
||||
builder_->SkipListOfStrings(); // read positional parameter names.
|
||||
|
||||
if (!simple) {
|
||||
builder_->SkipCanonicalNameReference(); // read typedef reference.
|
||||
}
|
||||
|
||||
VisitDartType(); // read return type.
|
||||
}
|
||||
|
||||
|
@ -1574,6 +1579,10 @@ void StreamingDartTypeTranslator::BuildFunctionType(bool simple) {
|
|||
|
||||
builder_->SkipListOfStrings(); // read positional parameter names.
|
||||
|
||||
if (!simple) {
|
||||
builder_->SkipCanonicalNameReference(); // read typedef reference.
|
||||
}
|
||||
|
||||
BuildTypeInternal(); // read return type.
|
||||
if (result_.IsMalformed()) {
|
||||
result_ = AbstractType::dynamic_type().raw();
|
||||
|
@ -3812,6 +3821,11 @@ void StreamingFlowGraphBuilder::SkipFunctionType(bool simple) {
|
|||
}
|
||||
|
||||
SkipListOfStrings(); // read positional parameter names.
|
||||
|
||||
if (!simple) {
|
||||
SkipCanonicalNameReference(); // read typedef reference.
|
||||
}
|
||||
|
||||
SkipDartType(); // read return type.
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue