mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 22:11:19 +00:00
Add import dependencies to Kernel libraries and use them to resynthesize ImportElement(s) in Analyzer.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com BUG= Review-Url: https://codereview.chromium.org/2987553002 .
This commit is contained in:
parent
000bec45ac
commit
2289ce12ae
|
@ -5501,6 +5501,11 @@ class ImportElementImpl extends ElementImpl implements ImportElement {
|
|||
*/
|
||||
final int _linkedDependency;
|
||||
|
||||
/**
|
||||
* The kernel of the element.
|
||||
*/
|
||||
final kernel.LibraryDependency _kernel;
|
||||
|
||||
/**
|
||||
* The offset of the prefix of this import in the file that contains the this
|
||||
* import directive, or `-1` if this import is synthetic.
|
||||
|
@ -5531,14 +5536,24 @@ class ImportElementImpl extends ElementImpl implements ImportElement {
|
|||
ImportElementImpl(int offset)
|
||||
: _unlinkedImport = null,
|
||||
_linkedDependency = null,
|
||||
_kernel = null,
|
||||
super(null, offset);
|
||||
|
||||
/**
|
||||
* Initialize using the given kernel.
|
||||
*/
|
||||
ImportElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel)
|
||||
: _unlinkedImport = null,
|
||||
_linkedDependency = null,
|
||||
super.forSerialized(enclosingLibrary);
|
||||
|
||||
/**
|
||||
* Initialize using the given serialized information.
|
||||
*/
|
||||
ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency,
|
||||
LibraryElementImpl enclosingLibrary)
|
||||
: super.forSerialized(enclosingLibrary);
|
||||
: _kernel = null,
|
||||
super.forSerialized(enclosingLibrary);
|
||||
|
||||
@override
|
||||
List<NamespaceCombinator> get combinators {
|
||||
|
@ -5566,6 +5581,14 @@ class ImportElementImpl extends ElementImpl implements ImportElement {
|
|||
|
||||
@override
|
||||
LibraryElement get importedLibrary {
|
||||
if (_kernel != null) {
|
||||
if (_importedLibrary == null) {
|
||||
Uri importedUri = _kernel.targetLibrary.importUri;
|
||||
String importedUriStr = importedUri.toString();
|
||||
LibraryElementImpl library = enclosingElement as LibraryElementImpl;
|
||||
_importedLibrary = library._kernelContext.getLibrary(importedUriStr);
|
||||
}
|
||||
}
|
||||
if (_linkedDependency != null) {
|
||||
if (_importedLibrary == null) {
|
||||
LibraryElementImpl library = enclosingElement as LibraryElementImpl;
|
||||
|
@ -5710,6 +5733,11 @@ abstract class KernelLibraryResynthesizerContext {
|
|||
*/
|
||||
InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type);
|
||||
|
||||
/**
|
||||
* Return the [LibraryElement] for the given absolute [uriStr].
|
||||
*/
|
||||
LibraryElement getLibrary(String uriStr);
|
||||
|
||||
/**
|
||||
* Return the [DartType] for the given Kernel [type], or `null` if the [type]
|
||||
* does not correspond to a [DartType].
|
||||
|
@ -6091,21 +6119,30 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
|
|||
|
||||
@override
|
||||
List<ImportElement> get imports {
|
||||
if (_unlinkedDefiningUnit != null && _imports == null) {
|
||||
List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports;
|
||||
int length = unlinkedImports.length;
|
||||
if (length != 0) {
|
||||
List<ImportElement> imports = new List<ImportElement>();
|
||||
LinkedLibrary linkedLibrary = resynthesizerContext.linkedLibrary;
|
||||
for (int i = 0; i < length; i++) {
|
||||
int dependency = linkedLibrary.importDependencies[i];
|
||||
ImportElementImpl importElement = new ImportElementImpl.forSerialized(
|
||||
unlinkedImports[i], dependency, library);
|
||||
imports.add(importElement);
|
||||
if (_imports == null) {
|
||||
if (_kernelContext != null) {
|
||||
_imports = _kernelContext.library.dependencies
|
||||
.where((k) => k.isImport)
|
||||
.map((k) => new ImportElementImpl.forKernel(this, k))
|
||||
.toList(growable: false);
|
||||
}
|
||||
if (_unlinkedDefiningUnit != null) {
|
||||
List<UnlinkedImport> unlinkedImports = _unlinkedDefiningUnit.imports;
|
||||
int length = unlinkedImports.length;
|
||||
if (length != 0) {
|
||||
List<ImportElement> imports = new List<ImportElement>();
|
||||
LinkedLibrary linkedLibrary = resynthesizerContext.linkedLibrary;
|
||||
for (int i = 0; i < length; i++) {
|
||||
int dependency = linkedLibrary.importDependencies[i];
|
||||
ImportElementImpl importElement =
|
||||
new ImportElementImpl.forSerialized(
|
||||
unlinkedImports[i], dependency, library);
|
||||
imports.add(importElement);
|
||||
}
|
||||
_imports = imports;
|
||||
} else {
|
||||
_imports = const <ImportElement>[];
|
||||
}
|
||||
_imports = imports;
|
||||
} else {
|
||||
_imports = const <ImportElement>[];
|
||||
}
|
||||
}
|
||||
return _imports ?? ImportElement.EMPTY_LIST;
|
||||
|
|
|
@ -222,33 +222,18 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_const_invalid_topLevel();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_invokeConstructor_generic_named_imported() async {
|
||||
await super.test_const_invokeConstructor_generic_named_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_invokeConstructor_generic_named_imported_withPrefix() async {
|
||||
await super
|
||||
.test_const_invokeConstructor_generic_named_imported_withPrefix();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_invokeConstructor_generic_unnamed_imported() async {
|
||||
await super.test_const_invokeConstructor_generic_unnamed_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_invokeConstructor_generic_unnamed_imported_withPrefix() async {
|
||||
await super
|
||||
.test_const_invokeConstructor_generic_unnamed_imported_withPrefix();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_invokeConstructor_named_imported() async {
|
||||
await super.test_const_invokeConstructor_named_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_invokeConstructor_named_imported_withPrefix() async {
|
||||
await super.test_const_invokeConstructor_named_imported_withPrefix();
|
||||
|
@ -284,11 +269,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_const_invokeConstructor_named_unresolved6();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_invokeConstructor_unnamed_imported() async {
|
||||
await super.test_const_invokeConstructor_unnamed_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_invokeConstructor_unnamed_imported_withPrefix() async {
|
||||
await super.test_const_invokeConstructor_unnamed_imported_withPrefix();
|
||||
|
@ -309,11 +289,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_const_invokeConstructor_unnamed_unresolved3();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_length_ofClassConstField_imported() async {
|
||||
await super.test_const_length_ofClassConstField_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_length_ofClassConstField_imported_withPrefix() async {
|
||||
await super.test_const_length_ofClassConstField_imported_withPrefix();
|
||||
|
@ -334,11 +309,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_const_length_staticMethod();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_reference_staticField_imported() async {
|
||||
await super.test_const_reference_staticField_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_reference_staticField_imported_withPrefix() async {
|
||||
await super.test_const_reference_staticField_imported_withPrefix();
|
||||
|
@ -374,11 +344,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_const_reference_topLevelFunction_imported_withPrefix();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_reference_topLevelVariable_imported() async {
|
||||
await super.test_const_reference_topLevelVariable_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_reference_topLevelVariable_imported_withPrefix() async {
|
||||
await super.test_const_reference_topLevelVariable_imported_withPrefix();
|
||||
|
@ -439,11 +404,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_const_topLevel_this();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_topLevel_typedList_imported() async {
|
||||
await super.test_const_topLevel_typedList_imported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_const_topLevel_typedList_importedWithPrefix() async {
|
||||
await super.test_const_topLevel_typedList_importedWithPrefix();
|
||||
|
@ -805,16 +765,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_field_propagatedType_final_noDep_instance();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_function_async() async {
|
||||
await super.test_function_async();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_function_asyncStar() async {
|
||||
await super.test_function_asyncStar();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_function_documented() async {
|
||||
await super.test_function_documented();
|
||||
|
@ -1015,21 +965,11 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_import_self();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_import_short_absolute() async {
|
||||
await super.test_import_short_absolute();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_import_show() async {
|
||||
await super.test_import_show();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_imports() async {
|
||||
await super.test_imports();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_inferred_function_type_for_variable_in_generic_function() async {
|
||||
await super.test_inferred_function_type_for_variable_in_generic_function();
|
||||
|
@ -1267,16 +1207,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_main_variable_via_export();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_member_function_async() async {
|
||||
await super.test_member_function_async();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_member_function_asyncStar() async {
|
||||
await super.test_member_function_asyncStar();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_metadata_classDeclaration() async {
|
||||
await super.test_metadata_classDeclaration();
|
||||
|
@ -1467,26 +1397,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_method_type_parameter_with_function_typed_parameter();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_nameConflict_exportedAndLocal() async {
|
||||
await super.test_nameConflict_exportedAndLocal();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_nameConflict_exportedAndLocal_exported() async {
|
||||
await super.test_nameConflict_exportedAndLocal_exported();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_nameConflict_exportedAndParted() async {
|
||||
await super.test_nameConflict_exportedAndParted();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_nameConflict_importWithRelativeUri_exportWithAbsolute() async {
|
||||
await super.test_nameConflict_importWithRelativeUri_exportWithAbsolute();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_nested_generic_functions_in_generic_class_with_function_typed_params() async {
|
||||
await super
|
||||
|
@ -1684,11 +1594,6 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_type_reference_to_import_part();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_part2() async {
|
||||
await super.test_type_reference_to_import_part2();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_type_reference_to_import_part_in_subdir() async {
|
||||
await super.test_type_reference_to_import_part_in_subdir();
|
||||
|
@ -1929,21 +1834,11 @@ class ResynthesizeKernelStrongTest extends ResynthesizeTest {
|
|||
await super.test_variable_getterInPart_setterInPart();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_variable_propagatedType_final_dep_inLib() async {
|
||||
await super.test_variable_propagatedType_final_dep_inLib();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_variable_propagatedType_final_dep_inPart() async {
|
||||
await super.test_variable_propagatedType_final_dep_inPart();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_variable_propagatedType_implicit_dep() async {
|
||||
await super.test_variable_propagatedType_implicit_dep();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
test_variable_setterInPart_getterInPart() async {
|
||||
await super.test_variable_setterInPart_getterInPart();
|
||||
|
@ -2266,6 +2161,11 @@ class _KernelLibraryResynthesizerContextImpl
|
|||
kernelType.className.canonicalName, kernelType.typeArguments);
|
||||
}
|
||||
|
||||
@override
|
||||
LibraryElement getLibrary(String uriStr) {
|
||||
return _resynthesizer.getLibrary(uriStr);
|
||||
}
|
||||
|
||||
DartType getType(ElementImpl context, kernel.DartType kernelType) {
|
||||
if (kernelType is kernel.DynamicType) return DynamicTypeImpl.instance;
|
||||
if (kernelType is kernel.VoidType) return VoidTypeImpl.instance;
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
library fasta.kernel_library_builder;
|
||||
|
||||
import 'package:front_end/src/fasta/dill/dill_library_builder.dart';
|
||||
import 'package:front_end/src/fasta/import.dart';
|
||||
import 'package:kernel/ast.dart';
|
||||
|
||||
import 'package:kernel/clone.dart' show CloneVisitor;
|
||||
|
@ -704,6 +706,19 @@ class KernelLibraryBuilder
|
|||
@override
|
||||
Library build(LibraryBuilder coreLibrary) {
|
||||
super.build(coreLibrary);
|
||||
for (Import import in imports) {
|
||||
var importedBuilder = import.imported;
|
||||
Library importedLibrary;
|
||||
if (importedBuilder is DillLibraryBuilder) {
|
||||
importedLibrary = importedBuilder.library;
|
||||
} else if (importedBuilder is KernelLibraryBuilder) {
|
||||
importedLibrary = importedBuilder.library;
|
||||
}
|
||||
if (importedLibrary != null) {
|
||||
library.addDependency(
|
||||
new LibraryDependency.import(importedLibrary, name: import.prefix));
|
||||
}
|
||||
}
|
||||
library.name = name;
|
||||
library.procedures.sort(compareProcedures);
|
||||
return library;
|
||||
|
|
|
@ -75,7 +75,10 @@ Future<CompilerResult> generateKernelInternal(
|
|||
}
|
||||
|
||||
// All summaries are considered external and shouldn't include source-info.
|
||||
dillTarget.loader.libraries.forEach((lib) => lib.isExternal = true);
|
||||
dillTarget.loader.libraries.forEach((lib) {
|
||||
lib.isExternal = true;
|
||||
lib.dependencies.clear();
|
||||
});
|
||||
|
||||
// Linked dependencies are meant to be part of the program so they are not
|
||||
// marked external.
|
||||
|
|
|
@ -283,12 +283,9 @@ class Printer extends Visitor<Null> {
|
|||
endLine('import "$importPath" as $prefix;');
|
||||
}
|
||||
}
|
||||
for (var import in library.dependencies) {
|
||||
import.accept(this);
|
||||
}
|
||||
// TODO(scheglov): Do we want to print dependencies? dartbug.com/30224
|
||||
endLine();
|
||||
var inner = new Printer._inner(this, imports);
|
||||
library.dependencies.forEach(inner.writeNode);
|
||||
library.typedefs.forEach(inner.writeNode);
|
||||
library.classes.forEach(inner.writeNode);
|
||||
library.fields.forEach(inner.writeNode);
|
||||
|
|
Loading…
Reference in a new issue