Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tests/compiler/dart2js/patch_test.dart

Issue 1182913003: Split TypedSelector into Selector and TypeMask. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add SelectorMask for FunctionSetNode.cache Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import "package:compiler/src/dart2jslib.dart"; 8 import "package:compiler/src/dart2jslib.dart";
9 import "package:compiler/src/elements/elements.dart"; 9 import "package:compiler/src/elements/elements.dart";
10 import "package:compiler/src/tree/tree.dart"; 10 import "package:compiler/src/tree/tree.dart";
11 import "package:compiler/src/types/types.dart";
11 import "mock_compiler.dart"; 12 import "mock_compiler.dart";
12 import "mock_libraries.dart"; 13 import "mock_libraries.dart";
13 import 'package:compiler/src/elements/modelx.dart'; 14 import 'package:compiler/src/elements/modelx.dart';
14 15
15 Future<Compiler> applyPatch(String script, String patch, 16 Future<Compiler> applyPatch(String script, String patch,
16 {bool analyzeAll: false, 17 {bool analyzeAll: false,
17 bool analyzeOnly: false, 18 bool analyzeOnly: false,
18 bool runCompiler: false, 19 bool runCompiler: false,
19 String main: "", 20 String main: "",
20 String patchVersion}) { 21 String patchVersion}) {
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 checkHasBody: true, expectIsRegular: true); 862 checkHasBody: true, expectIsRegular: true);
862 863
863 ensure(compiler, "clear", cls.lookupLocalMember, 864 ensure(compiler, "clear", cls.lookupLocalMember,
864 checkHasBody: true, expectIsPatched: true); 865 checkHasBody: true, expectIsPatched: true);
865 866
866 compiler.phase = Compiler.PHASE_DONE_RESOLVING; 867 compiler.phase = Compiler.PHASE_DONE_RESOLVING;
867 868
868 // Check that a method just in the patch class is a target for a 869 // Check that a method just in the patch class is a target for a
869 // typed selector. 870 // typed selector.
870 Selector selector = new Selector.call('method', compiler.coreLibrary, 0); 871 Selector selector = new Selector.call('method', compiler.coreLibrary, 0);
871 TypedSelector typedSelector = new TypedSelector.exact(cls, selector, world); 872 TypeMask typeMask = new TypeMask.exact(cls, world);
872 FunctionElement method = cls.implementation.lookupLocalMember('method'); 873 FunctionElement method = cls.implementation.lookupLocalMember('method');
873 method.computeSignature(compiler); 874 method.computeType(compiler);
874 Expect.isTrue(selector.applies(method, world)); 875 Expect.isTrue(selector.applies(method, world));
875 Expect.isTrue(typedSelector.applies(method, world)); 876 Expect.isTrue(typeMask.canHit(method, selector, world));
876 877
877 // Check that the declaration method in the declaration class is a target 878 // Check that the declaration method in the declaration class is a target
878 // for a typed selector. 879 // for a typed selector.
879 selector = new Selector.call('clear', compiler.coreLibrary, 0); 880 selector = new Selector.call('clear', compiler.coreLibrary, 0);
880 typedSelector = new TypedSelector.exact(cls, selector, world); 881 typeMask = new TypeMask.exact(cls, world);
881 method = cls.lookupLocalMember('clear'); 882 method = cls.lookupLocalMember('clear');
882 method.computeSignature(compiler); 883 method.computeType(compiler);
883 Expect.isTrue(selector.applies(method, world)); 884 Expect.isTrue(selector.applies(method, world));
884 Expect.isTrue(typedSelector.applies(method, world)); 885 Expect.isTrue(typeMask.canHit(method, selector, world));
885 886
886 // Check that the declaration method in the declaration class is a target 887 // Check that the declaration method in the declaration class is a target
887 // for a typed selector on a subclass. 888 // for a typed selector on a subclass.
888 cls = ensure(compiler, "B", compiler.coreLibrary.find); 889 cls = ensure(compiler, "B", compiler.coreLibrary.find);
889 cls.ensureResolved(compiler); 890 cls.ensureResolved(compiler);
890 typedSelector = new TypedSelector.exact(cls, selector, world); 891 typeMask = new TypeMask.exact(cls, world);
891 Expect.isTrue(selector.applies(method, world)); 892 Expect.isTrue(selector.applies(method, world));
892 Expect.isTrue(typedSelector.applies(method, world)); 893 Expect.isTrue(typeMask.canHit(method, selector, world));
893 })); 894 }));
894 } 895 }
895 896
896 void testAnalyzeAllInjectedMembers() { 897 void testAnalyzeAllInjectedMembers() {
897 void expect(String patchText, [expectedWarnings]) { 898 void expect(String patchText, [expectedWarnings]) {
898 if (expectedWarnings == null) expectedWarnings = []; 899 if (expectedWarnings == null) expectedWarnings = [];
899 if (expectedWarnings is! List) { 900 if (expectedWarnings is! List) {
900 expectedWarnings = <MessageKind>[expectedWarnings]; 901 expectedWarnings = <MessageKind>[expectedWarnings];
901 } 902 }
902 903
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 B.patchTarget() : super(); 947 B.patchTarget() : super();
947 factory B.reflectBack() = B.originTarget; 948 factory B.reflectBack() = B.originTarget;
948 } 949 }
949 """; 950 """;
950 951
951 asyncTest(() => applyPatch(origin, patch, analyzeAll: true, 952 asyncTest(() => applyPatch(origin, patch, analyzeAll: true,
952 analyzeOnly: true, runCompiler: true).then((compiler) { 953 analyzeOnly: true, runCompiler: true).then((compiler) {
953 ClassElement clsA = compiler.coreLibrary.find("A"); 954 ClassElement clsA = compiler.coreLibrary.find("A");
954 ClassElement clsB = compiler.coreLibrary.find("B"); 955 ClassElement clsB = compiler.coreLibrary.find("B");
955 956
956 Selector forwardCall = new Selector.callConstructor("forward", 957 ConstructorElement forward = clsA.lookupConstructor("forward");
957 compiler.coreLibrary);
958 ConstructorElement forward = clsA.lookupConstructor(forwardCall);
959 ConstructorElement target = forward.effectiveTarget; 958 ConstructorElement target = forward.effectiveTarget;
960 Expect.isTrue(target.isPatch); 959 Expect.isTrue(target.isPatch);
961 Expect.equals("patchTarget", target.name); 960 Expect.equals("patchTarget", target.name);
962 961
963 Selector forwardTwoCall = new Selector.callConstructor("forwardTwo", 962 ConstructorElement forwardTwo = clsA.lookupConstructor("forwardTwo");
964 compiler.coreLibrary);
965 ConstructorElement forwardTwo = clsA.lookupConstructor(forwardTwoCall);
966 target = forwardTwo.effectiveTarget; 963 target = forwardTwo.effectiveTarget;
967 Expect.isFalse(forwardTwo.isErroneous); 964 Expect.isFalse(forwardTwo.isErroneous);
968 Expect.isFalse(target.isPatch); 965 Expect.isFalse(target.isPatch);
969 Expect.equals("originTarget", target.name); 966 Expect.equals("originTarget", target.name);
970 })); 967 }));
971 } 968 }
972 969
973 void testTypecheckPatchedMembers() { 970 void testTypecheckPatchedMembers() {
974 String originText = "external void method();"; 971 String originText = "external void method();";
975 String patchText = """ 972 String patchText = """
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 testPatchNoSetter(); 1015 testPatchNoSetter();
1019 testPatchNonFunction(); 1016 testPatchNonFunction();
1020 1017
1021 testPatchAndSelector(); 1018 testPatchAndSelector();
1022 1019
1023 testEffectiveTarget(); /// bug: ok 1020 testEffectiveTarget(); /// bug: ok
1024 1021
1025 testAnalyzeAllInjectedMembers(); 1022 testAnalyzeAllInjectedMembers();
1026 testTypecheckPatchedMembers(); 1023 testTypecheckPatchedMembers();
1027 } 1024 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698