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') {
|
} else if (parentName.name == '@methods') {
|
||||||
isMethod = true;
|
isMethod = true;
|
||||||
parentName = parentName.parent;
|
parentName = parentName.parent;
|
||||||
|
} else if (parentName.name == '@typedefs') {
|
||||||
|
parentName = parentName.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementImpl parentElement = _getElement(parentName);
|
ElementImpl parentElement = _getElement(parentName);
|
||||||
|
@ -734,6 +736,12 @@ class _KernelUnitResynthesizerContextImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kernelType is kernel.FunctionType) {
|
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);
|
var functionElement = new FunctionElementImpl.synthetic([], null);
|
||||||
functionElement.enclosingElement = context;
|
functionElement.enclosingElement = context;
|
||||||
|
|
||||||
|
|
|
@ -9226,7 +9226,7 @@ E e;
|
||||||
}
|
}
|
||||||
|
|
||||||
test_type_reference_to_import() async {
|
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;');
|
var library = await checkLibrary('import "a.dart"; C c; E e; F f;');
|
||||||
checkElementText(library, r'''
|
checkElementText(library, r'''
|
||||||
import 'a.dart';
|
import 'a.dart';
|
||||||
|
|
|
@ -220,21 +220,11 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
||||||
await super.test_const_invokeConstructor_unnamed_unresolved3();
|
await super.test_const_invokeConstructor_unnamed_unresolved3();
|
||||||
}
|
}
|
||||||
|
|
||||||
@failingTest
|
|
||||||
test_const_reference_type() async {
|
|
||||||
await super.test_const_reference_type();
|
|
||||||
}
|
|
||||||
|
|
||||||
@failingTest
|
@failingTest
|
||||||
test_const_reference_type_functionType() async {
|
test_const_reference_type_functionType() async {
|
||||||
await super.test_const_reference_type_functionType();
|
await super.test_const_reference_type_functionType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@failingTest
|
|
||||||
test_const_reference_type_imported() async {
|
|
||||||
await super.test_const_reference_type_imported();
|
|
||||||
}
|
|
||||||
|
|
||||||
@failingTest
|
@failingTest
|
||||||
test_const_reference_type_imported_withPrefix() async {
|
test_const_reference_type_imported_withPrefix() async {
|
||||||
await super.test_const_reference_type_imported_withPrefix();
|
await super.test_const_reference_type_imported_withPrefix();
|
||||||
|
@ -521,11 +511,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
||||||
await super.test_import_self();
|
await super.test_import_self();
|
||||||
}
|
}
|
||||||
|
|
||||||
@failingTest
|
|
||||||
test_inferred_type_is_typedef() async {
|
|
||||||
await super.test_inferred_type_is_typedef();
|
|
||||||
}
|
|
||||||
|
|
||||||
@failingTest
|
@failingTest
|
||||||
test_inferred_type_refers_to_function_typed_param_of_typedef() async {
|
test_inferred_type_refers_to_function_typed_param_of_typedef() async {
|
||||||
await super.test_inferred_type_refers_to_function_typed_param_of_typedef();
|
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();
|
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
|
@failingTest
|
||||||
test_type_reference_to_typedef_with_type_arguments() async {
|
test_type_reference_to_typedef_with_type_arguments() async {
|
||||||
await super.test_type_reference_to_typedef_with_type_arguments();
|
await super.test_type_reference_to_typedef_with_type_arguments();
|
||||||
|
|
|
@ -61,14 +61,19 @@ class KernelFunctionTypeAliasBuilder
|
||||||
return thisType;
|
return thisType;
|
||||||
}
|
}
|
||||||
thisType = const InvalidType();
|
thisType = const InvalidType();
|
||||||
DartType builtType = type?.build(library) ?? const DynamicType();
|
FunctionType builtType = type?.build(library);
|
||||||
if (typeVariables != null) {
|
if (builtType != null) {
|
||||||
for (KernelTypeVariableBuilder tv in typeVariables) {
|
builtType.typedefReference = target.reference;
|
||||||
tv.parameter.bound = tv?.bound?.build(library);
|
if (typeVariables != null) {
|
||||||
target.typeParameters.add(tv.parameter..parent = target);
|
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.
|
/// [arguments] have already been built.
|
||||||
|
|
|
@ -37,7 +37,7 @@ class KernelFunctionTypeBuilder extends FunctionTypeBuilder
|
||||||
List<FormalParameterBuilder> formals)
|
List<FormalParameterBuilder> formals)
|
||||||
: super(charOffset, fileUri, returnType, typeVariables, formals);
|
: super(charOffset, fileUri, returnType, typeVariables, formals);
|
||||||
|
|
||||||
DartType build(LibraryBuilder library) {
|
FunctionType build(LibraryBuilder library) {
|
||||||
DartType builtReturnType =
|
DartType builtReturnType =
|
||||||
returnType?.build(library) ?? const DynamicType();
|
returnType?.build(library) ?? const DynamicType();
|
||||||
List<DartType> positionalParameters = <DartType>[];
|
List<DartType> positionalParameters = <DartType>[];
|
||||||
|
|
|
@ -4143,6 +4143,9 @@ class FunctionType extends DartType {
|
||||||
@informative
|
@informative
|
||||||
final List<String> positionalParameterNames;
|
final List<String> positionalParameterNames;
|
||||||
|
|
||||||
|
/// The [Typedef] this function type is created for.
|
||||||
|
Reference typedefReference;
|
||||||
|
|
||||||
final DartType returnType;
|
final DartType returnType;
|
||||||
int _hashCode;
|
int _hashCode;
|
||||||
|
|
||||||
|
@ -4150,11 +4153,15 @@ class FunctionType extends DartType {
|
||||||
{this.namedParameters: const <NamedType>[],
|
{this.namedParameters: const <NamedType>[],
|
||||||
this.typeParameters: const <TypeParameter>[],
|
this.typeParameters: const <TypeParameter>[],
|
||||||
int requiredParameterCount,
|
int requiredParameterCount,
|
||||||
this.positionalParameterNames: const <String>[]})
|
this.positionalParameterNames: const <String>[],
|
||||||
|
this.typedefReference})
|
||||||
: this.positionalParameters = positionalParameters,
|
: this.positionalParameters = positionalParameters,
|
||||||
this.requiredParameterCount =
|
this.requiredParameterCount =
|
||||||
requiredParameterCount ?? positionalParameters.length;
|
requiredParameterCount ?? positionalParameters.length;
|
||||||
|
|
||||||
|
/// The [Typedef] this function type is created for.
|
||||||
|
Typedef get typedef => typedefReference?.asTypedef;
|
||||||
|
|
||||||
accept(DartTypeVisitor v) => v.visitFunctionType(this);
|
accept(DartTypeVisitor v) => v.visitFunctionType(this);
|
||||||
|
|
||||||
visitChildren(Visitor v) {
|
visitChildren(Visitor v) {
|
||||||
|
|
|
@ -343,7 +343,7 @@ class BinaryBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference readTypedefReference() {
|
Reference readTypedefReference() {
|
||||||
return readCanonicalNameReference().getReference();
|
return readCanonicalNameReference()?.getReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
Name readName() {
|
Name readName() {
|
||||||
|
@ -1176,6 +1176,7 @@ class BinaryBuilder {
|
||||||
var positional = readDartTypeList();
|
var positional = readDartTypeList();
|
||||||
var named = readNamedTypeList();
|
var named = readNamedTypeList();
|
||||||
var positionalNames = readStringReferenceList();
|
var positionalNames = readStringReferenceList();
|
||||||
|
var typedefReference = readTypedefReference();
|
||||||
assert(positional.length + named.length == totalParameterCount);
|
assert(positional.length + named.length == totalParameterCount);
|
||||||
var returnType = readDartType();
|
var returnType = readDartType();
|
||||||
typeParameterStack.length = typeParameterStackHeight;
|
typeParameterStack.length = typeParameterStackHeight;
|
||||||
|
@ -1183,7 +1184,8 @@ class BinaryBuilder {
|
||||||
typeParameters: typeParameters,
|
typeParameters: typeParameters,
|
||||||
requiredParameterCount: requiredParameterCount,
|
requiredParameterCount: requiredParameterCount,
|
||||||
namedParameters: named,
|
namedParameters: named,
|
||||||
positionalParameterNames: positionalNames);
|
positionalParameterNames: positionalNames,
|
||||||
|
typedefReference: typedefReference);
|
||||||
case Tag.SimpleFunctionType:
|
case Tag.SimpleFunctionType:
|
||||||
var positional = readDartTypeList();
|
var positional = readDartTypeList();
|
||||||
var positionalNames = readStringReferenceList();
|
var positionalNames = readStringReferenceList();
|
||||||
|
|
|
@ -1130,7 +1130,8 @@ class BinaryPrinter extends Visitor {
|
||||||
visitFunctionType(FunctionType node) {
|
visitFunctionType(FunctionType node) {
|
||||||
if (node.requiredParameterCount == node.positionalParameters.length &&
|
if (node.requiredParameterCount == node.positionalParameters.length &&
|
||||||
node.typeParameters.isEmpty &&
|
node.typeParameters.isEmpty &&
|
||||||
node.namedParameters.isEmpty) {
|
node.namedParameters.isEmpty &&
|
||||||
|
node.typedefReference == null) {
|
||||||
writeByte(Tag.SimpleFunctionType);
|
writeByte(Tag.SimpleFunctionType);
|
||||||
writeNodeList(node.positionalParameters);
|
writeNodeList(node.positionalParameters);
|
||||||
writeStringReferenceList(node.positionalParameterNames);
|
writeStringReferenceList(node.positionalParameterNames);
|
||||||
|
@ -1145,6 +1146,7 @@ class BinaryPrinter extends Visitor {
|
||||||
writeNodeList(node.positionalParameters);
|
writeNodeList(node.positionalParameters);
|
||||||
writeNodeList(node.namedParameters);
|
writeNodeList(node.namedParameters);
|
||||||
writeStringReferenceList(node.positionalParameterNames);
|
writeStringReferenceList(node.positionalParameterNames);
|
||||||
|
writeReference(node.typedefReference);
|
||||||
writeNode(node.returnType);
|
writeNode(node.returnType);
|
||||||
_typeParameterIndexer.exit(node.typeParameters);
|
_typeParameterIndexer.exit(node.typeParameters);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1097,6 +1097,11 @@ void StreamingScopeBuilder::VisitFunctionType(bool simple) {
|
||||||
}
|
}
|
||||||
|
|
||||||
builder_->SkipListOfStrings(); // read positional parameter names.
|
builder_->SkipListOfStrings(); // read positional parameter names.
|
||||||
|
|
||||||
|
if (!simple) {
|
||||||
|
builder_->SkipCanonicalNameReference(); // read typedef reference.
|
||||||
|
}
|
||||||
|
|
||||||
VisitDartType(); // read return type.
|
VisitDartType(); // read return type.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1574,6 +1579,10 @@ void StreamingDartTypeTranslator::BuildFunctionType(bool simple) {
|
||||||
|
|
||||||
builder_->SkipListOfStrings(); // read positional parameter names.
|
builder_->SkipListOfStrings(); // read positional parameter names.
|
||||||
|
|
||||||
|
if (!simple) {
|
||||||
|
builder_->SkipCanonicalNameReference(); // read typedef reference.
|
||||||
|
}
|
||||||
|
|
||||||
BuildTypeInternal(); // read return type.
|
BuildTypeInternal(); // read return type.
|
||||||
if (result_.IsMalformed()) {
|
if (result_.IsMalformed()) {
|
||||||
result_ = AbstractType::dynamic_type().raw();
|
result_ = AbstractType::dynamic_type().raw();
|
||||||
|
@ -3812,6 +3821,11 @@ void StreamingFlowGraphBuilder::SkipFunctionType(bool simple) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SkipListOfStrings(); // read positional parameter names.
|
SkipListOfStrings(); // read positional parameter names.
|
||||||
|
|
||||||
|
if (!simple) {
|
||||||
|
SkipCanonicalNameReference(); // read typedef reference.
|
||||||
|
}
|
||||||
|
|
||||||
SkipDartType(); // read return type.
|
SkipDartType(); // read return type.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue