mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Test of class hierachy from dill file
Change-Id: Ib6a8916fd096e4a9a417dbef8a3519ffe1a595aa Reviewed-on: https://dart-review.googlesource.com/c/93408 Reviewed-by: Jens Johansen <jensj@google.com>
This commit is contained in:
parent
f4379435dd
commit
5622925369
4 changed files with 145 additions and 17 deletions
127
pkg/front_end/test/fasta/types/dill_hierachy_test.dart
Normal file
127
pkg/front_end/test/fasta/types/dill_hierachy_test.dart
Normal file
|
@ -0,0 +1,127 @@
|
|||
// Copyright (c) 2019, 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:async_helper/async_helper.dart" show asyncTest;
|
||||
|
||||
import "package:expect/expect.dart" show Expect;
|
||||
|
||||
import "package:kernel/ast.dart" show Class, Component, Library;
|
||||
|
||||
import "package:kernel/core_types.dart" show CoreTypes;
|
||||
|
||||
import "package:kernel/target/targets.dart" show NoneTarget, TargetFlags;
|
||||
|
||||
import "package:front_end/src/api_prototype/compiler_options.dart"
|
||||
show CompilerOptions;
|
||||
|
||||
import "package:front_end/src/base/processed_options.dart"
|
||||
show ProcessedOptions;
|
||||
|
||||
import "package:front_end/src/fasta/compiler_context.dart" show CompilerContext;
|
||||
|
||||
import "package:front_end/src/fasta/dill/dill_loader.dart" show DillLoader;
|
||||
|
||||
import "package:front_end/src/fasta/dill/dill_target.dart" show DillTarget;
|
||||
|
||||
import "package:front_end/src/fasta/kernel/kernel_builder.dart"
|
||||
show ClassHierarchyBuilder, KernelClassBuilder;
|
||||
|
||||
import "package:front_end/src/fasta/ticker.dart" show Ticker;
|
||||
|
||||
import "kernel_type_parser.dart" show parseComponent;
|
||||
|
||||
const String expectedHierachy = """
|
||||
Object:
|
||||
superclasses:
|
||||
interfaces:
|
||||
classMembers:
|
||||
classSetters:
|
||||
|
||||
A:
|
||||
superclasses:
|
||||
Object
|
||||
interfaces:
|
||||
classMembers:
|
||||
classSetters:
|
||||
|
||||
B:
|
||||
superclasses:
|
||||
Object
|
||||
interfaces: A
|
||||
classMembers:
|
||||
classSetters:
|
||||
interfaceMembers:
|
||||
interfaceSetters:
|
||||
|
||||
C:
|
||||
superclasses:
|
||||
Object
|
||||
interfaces: A
|
||||
classMembers:
|
||||
classSetters:
|
||||
interfaceMembers:
|
||||
interfaceSetters:
|
||||
|
||||
D:
|
||||
superclasses:
|
||||
Object
|
||||
interfaces: B<T>, A, C<U>
|
||||
classMembers:
|
||||
classSetters:
|
||||
interfaceMembers:
|
||||
interfaceSetters:
|
||||
|
||||
E:
|
||||
superclasses:
|
||||
Object
|
||||
interfaces: D<int, double>, B<int>, A, C<double>
|
||||
classMembers:
|
||||
classSetters:
|
||||
interfaceMembers:
|
||||
interfaceSetters:
|
||||
|
||||
F:
|
||||
superclasses:
|
||||
Object
|
||||
interfaces: D<int, bool>, B<int>, A, C<bool>
|
||||
classMembers:
|
||||
classSetters:
|
||||
interfaceMembers:
|
||||
interfaceSetters:
|
||||
""";
|
||||
|
||||
main() {
|
||||
final Ticker ticker = new Ticker(isVerbose: false);
|
||||
final Component component = parseComponent("""
|
||||
class A;
|
||||
class B<T> implements A;
|
||||
class C<U> implements A;
|
||||
class D<T, U> implements B<T>, C<U>;
|
||||
class E implements D<int, double>;
|
||||
class F implements D<int, bool>;""",
|
||||
Uri.parse("org-dartlang-test:///library.dart"));
|
||||
|
||||
final CompilerContext context = new CompilerContext(new ProcessedOptions(
|
||||
options: new CompilerOptions()
|
||||
..packagesFileUri = Uri.base.resolve(".packages")));
|
||||
|
||||
asyncTest(() => context.runInContext<void>((_) async {
|
||||
DillTarget target = new DillTarget(
|
||||
ticker,
|
||||
await context.options.getUriTranslator(),
|
||||
new NoneTarget(new TargetFlags()));
|
||||
final DillLoader loader = target.loader;
|
||||
loader.appendLibraries(component);
|
||||
await target.buildOutlines();
|
||||
KernelClassBuilder objectClass = loader.coreLibrary["Object"];
|
||||
ClassHierarchyBuilder hierarchy = new ClassHierarchyBuilder(
|
||||
objectClass, loader, new CoreTypes(component));
|
||||
Library library = component.libraries.last;
|
||||
for (Class cls in library.classes) {
|
||||
hierarchy.getNodeFromKernelClass(cls);
|
||||
}
|
||||
Expect.stringEquals(
|
||||
expectedHierachy, hierarchy.nodes.values.join("\n"));
|
||||
}));
|
||||
}
|
|
@ -36,7 +36,7 @@ import "shared_type_tests.dart" show SubtypeTest;
|
|||
import "type_parser.dart" as type_parser show parse, parseTypeVariables;
|
||||
|
||||
main() {
|
||||
final Ticker ticker = Ticker();
|
||||
final Ticker ticker = new Ticker(isVerbose: false);
|
||||
final CompilerContext context = new CompilerContext(new ProcessedOptions(
|
||||
options: new CompilerOptions()
|
||||
..packagesFileUri = Uri.base.resolve(".packages")));
|
||||
|
|
|
@ -6,6 +6,7 @@ import "package:kernel/ast.dart"
|
|||
show
|
||||
BottomType,
|
||||
Class,
|
||||
Component,
|
||||
DartType,
|
||||
DynamicType,
|
||||
FunctionType,
|
||||
|
@ -24,6 +25,8 @@ import "package:kernel/ast.dart"
|
|||
|
||||
import "package:kernel/src/bounds_checks.dart" show calculateBounds;
|
||||
|
||||
import "mock_sdk.dart" show mockSdk;
|
||||
|
||||
import "type_parser.dart" as type_parser show parse;
|
||||
|
||||
import "type_parser.dart"
|
||||
|
@ -38,6 +41,17 @@ import "type_parser.dart"
|
|||
ParsedVoidType,
|
||||
Visitor;
|
||||
|
||||
Component parseComponent(String source, Uri uri) {
|
||||
Uri coreUri = Uri.parse("dart:core");
|
||||
KernelEnvironment coreEnvironment = new KernelEnvironment(coreUri, coreUri);
|
||||
Library coreLibrary =
|
||||
parseLibrary(coreUri, mockSdk, environment: coreEnvironment);
|
||||
KernelEnvironment libraryEnvironment =
|
||||
new KernelEnvironment(uri, uri).extend(coreEnvironment.declarations);
|
||||
Library library = parseLibrary(uri, source, environment: libraryEnvironment);
|
||||
return new Component(libraries: <Library>[coreLibrary, library]);
|
||||
}
|
||||
|
||||
Library parseLibrary(Uri uri, String text,
|
||||
{Uri fileUri, KernelEnvironment environment}) {
|
||||
fileUri ??= uri;
|
||||
|
|
|
@ -4,14 +4,11 @@
|
|||
|
||||
import "package:expect/expect.dart" show Expect;
|
||||
|
||||
import "package:kernel/ast.dart"
|
||||
show Class, Component, DartType, InterfaceType, Library;
|
||||
import "package:kernel/ast.dart" show Class, Component, DartType, InterfaceType;
|
||||
|
||||
import "package:kernel/library_index.dart" show LibraryIndex;
|
||||
|
||||
import "kernel_type_parser.dart" show KernelEnvironment, parseLibrary;
|
||||
|
||||
import "mock_sdk.dart" show mockSdk;
|
||||
import "kernel_type_parser.dart" as kernel_type_parser show parseComponent;
|
||||
|
||||
final Uri libraryUri = Uri.parse("org-dartlang-test:///library.dart");
|
||||
|
||||
|
@ -31,17 +28,7 @@ abstract class LegacyUpperBoundTest {
|
|||
DartType get boolType => getCoreClass("bool").rawType;
|
||||
|
||||
void parseComponent(String source) {
|
||||
Uri coreUri = Uri.parse("dart:core");
|
||||
KernelEnvironment coreEnvironment = new KernelEnvironment(coreUri, coreUri);
|
||||
Library coreLibrary =
|
||||
parseLibrary(coreUri, mockSdk, environment: coreEnvironment);
|
||||
KernelEnvironment libraryEnvironment =
|
||||
new KernelEnvironment(libraryUri, libraryUri)
|
||||
.extend(coreEnvironment.declarations);
|
||||
Library library =
|
||||
parseLibrary(libraryUri, source, environment: libraryEnvironment);
|
||||
|
||||
component = new Component(libraries: <Library>[coreLibrary, library]);
|
||||
component = kernel_type_parser.parseComponent(source, libraryUri);
|
||||
index = new LibraryIndex.all(component);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue