OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library subtype_test; | 5 library subtype_test; |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 import 'type_test_helper.dart'; | 8 import 'type_test_helper.dart'; |
9 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; | 9 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; |
10 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t' | 10 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t' |
11 show Element, ClassElement; | 11 show Element, ClassElement; |
12 import '../../../sdk/lib/_internal/compiler/implementation/js_backend/js_backend
.dart' | 12 import '../../../sdk/lib/_internal/compiler/implementation/js_backend/js_backend
.dart' |
13 show TypeRepresentationGenerator; | 13 show JavaScriptBackend, TypeRepresentationGenerator; |
14 | 14 |
15 void main() { | 15 void main() { |
16 testTypeRepresentations(); | 16 testTypeRepresentations(); |
17 } | 17 } |
18 | 18 |
19 void testTypeRepresentations() { | 19 void testTypeRepresentations() { |
20 var env = new TypeEnvironment(r""" | 20 var env = new TypeEnvironment(r""" |
21 typedef void Typedef(); | 21 typedef void Typedef(); |
22 | 22 |
23 void m1() {} | 23 void m1() {} |
(...skipping 11 matching lines...) Expand all Loading... |
35 TypeRepresentationGenerator typeRepresentation = | 35 TypeRepresentationGenerator typeRepresentation = |
36 new TypeRepresentationGenerator(env.compiler); | 36 new TypeRepresentationGenerator(env.compiler); |
37 String onVariable(TypeVariableType type) => type.name.slowToString(); | 37 String onVariable(TypeVariableType type) => type.name.slowToString(); |
38 | 38 |
39 void expect(String expectedRepresentation, DartType type) { | 39 void expect(String expectedRepresentation, DartType type) { |
40 String foundRepresentation = | 40 String foundRepresentation = |
41 typeRepresentation.getTypeRepresentation(type, onVariable); | 41 typeRepresentation.getTypeRepresentation(type, onVariable); |
42 Expect.stringEquals(expectedRepresentation, foundRepresentation); | 42 Expect.stringEquals(expectedRepresentation, foundRepresentation); |
43 } | 43 } |
44 | 44 |
| 45 JavaScriptBackend backend = env.compiler.backend; |
| 46 String func = backend.namer.functionTypeTag(); |
| 47 String retvoid = backend.namer.functionTypeVoidReturnTag(); |
| 48 String ret = backend.namer.functionTypeReturnTypeTag(); |
| 49 String args = backend.namer.functionTypeRequiredParametersTag(); |
| 50 String opt = backend.namer.functionTypeOptionalParametersTag(); |
| 51 String named = backend.namer.functionTypeNamedParametersTag(); |
| 52 |
45 ClassElement List_ = env.getElement('List'); | 53 ClassElement List_ = env.getElement('List'); |
46 TypeVariableType List_E = List_.typeVariables.head; | 54 TypeVariableType List_E = List_.typeVariables.head; |
47 ClassElement Map_ = env.getElement('Map'); | 55 ClassElement Map_ = env.getElement('Map'); |
48 TypeVariableType Map_K = Map_.typeVariables.head; | 56 TypeVariableType Map_K = Map_.typeVariables.head; |
49 TypeVariableType Map_V = Map_.typeVariables.tail.head; | 57 TypeVariableType Map_V = Map_.typeVariables.tail.head; |
50 | 58 |
51 DartType Object_ = env['Object']; | 59 DartType Object_ = env['Object']; |
52 DartType int_ = env['int']; | 60 DartType int_ = env['int']; |
53 DartType String_ = env['String']; | 61 DartType String_ = env['String']; |
54 DartType dynamic_ = env['dynamic']; | 62 DartType dynamic_ = env['dynamic']; |
(...skipping 15 matching lines...) Expand all Loading... |
70 | 78 |
71 // List<E> | 79 // List<E> |
72 expect('[$List_rep, $List_E_rep]', List_.computeType(env.compiler)); | 80 expect('[$List_rep, $List_E_rep]', List_.computeType(env.compiler)); |
73 // List | 81 // List |
74 expect('$List_rep', List_.rawType); | 82 expect('$List_rep', List_.rawType); |
75 // List<dynamic> | 83 // List<dynamic> |
76 expect('[$List_rep, null]', instantiate(List_, [dynamic_])); | 84 expect('[$List_rep, null]', instantiate(List_, [dynamic_])); |
77 // List<int> | 85 // List<int> |
78 expect('[$List_rep, $int_rep]', instantiate(List_, [int_])); | 86 expect('[$List_rep, $int_rep]', instantiate(List_, [int_])); |
79 // List<Typedef> | 87 // List<Typedef> |
80 expect('[$List_rep, {func: true, retvoid: true}]', | 88 expect('[$List_rep, {$func: "void_", $retvoid: true}]', |
81 instantiate(List_, [Typedef_])); | 89 instantiate(List_, [Typedef_])); |
82 | 90 |
83 // Map<K,V> | 91 // Map<K,V> |
84 expect('[$Map_rep, $Map_K_rep, $Map_V_rep]', Map_.computeType(env.compiler)); | 92 expect('[$Map_rep, $Map_K_rep, $Map_V_rep]', Map_.computeType(env.compiler)); |
85 // Map | 93 // Map |
86 expect('$Map_rep', Map_.rawType); | 94 expect('$Map_rep', Map_.rawType); |
87 // Map<dynamic,dynamic> | 95 // Map<dynamic,dynamic> |
88 expect('[$Map_rep, null, null]', instantiate(Map_, [dynamic_, dynamic_])); | 96 expect('[$Map_rep, null, null]', instantiate(Map_, [dynamic_, dynamic_])); |
89 // Map<int,String> | 97 // Map<int,String> |
90 expect('[$Map_rep, $int_rep, $String_rep]', | 98 expect('[$Map_rep, $int_rep, $String_rep]', |
91 instantiate(Map_, [int_, String_])); | 99 instantiate(Map_, [int_, String_])); |
92 | 100 |
93 // void m1() {} | 101 // void m1() {} |
94 expect("{func: true, retvoid: true}", | 102 expect('{$func: "void_", $retvoid: true}', |
95 env.getElement('m1').computeType(env.compiler)); | 103 env.getElement('m1').computeType(env.compiler)); |
96 | 104 |
97 // int m2() => 0; | 105 // int m2() => 0; |
98 expect("{func: true, ret: $int_rep}", | 106 expect('{$func: "int_", $ret: $int_rep}', |
99 env.getElement('m2').computeType(env.compiler)); | 107 env.getElement('m2').computeType(env.compiler)); |
100 | 108 |
101 // List<int> m3() => null; | 109 // List<int> m3() => null; |
102 expect("{func: true, ret: [$List_rep, $int_rep]}", | 110 expect('{$func: "List_", $ret: [$List_rep, $int_rep]}', |
103 env.getElement('m3').computeType(env.compiler)); | 111 env.getElement('m3').computeType(env.compiler)); |
104 | 112 |
105 // m4() {} | 113 // m4() {} |
106 expect("{func: true}", | 114 expect('{$func: "dynamic_"}', |
107 env.getElement('m4').computeType(env.compiler)); | 115 env.getElement('m4').computeType(env.compiler)); |
108 | 116 |
109 // m5(int a, String b) {} | 117 // m5(int a, String b) {} |
110 expect("{func: true, args: [$int_rep, $String_rep]}", | 118 expect('{$func: "dynamic__int_String", $args: [$int_rep, $String_rep]}', |
111 env.getElement('m5').computeType(env.compiler)); | 119 env.getElement('m5').computeType(env.compiler)); |
112 | 120 |
113 // m6(int a, [String b]) {} | 121 // m6(int a, [String b]) {} |
114 expect("{func: true, args: [$int_rep], opt: [$String_rep]}", | 122 expect('{$func: "dynamic__int__String", $args: [$int_rep],' |
| 123 ' $opt: [$String_rep]}', |
115 env.getElement('m6').computeType(env.compiler)); | 124 env.getElement('m6').computeType(env.compiler)); |
116 | 125 |
117 // m7(int a, String b, [List<int> c, d]) {} | 126 // m7(int a, String b, [List<int> c, d]) {} |
118 expect("{func: true, args: [$int_rep, $String_rep]," | 127 expect('{$func: "dynamic__int_String__List_dynamic",' |
119 " opt: [[$List_rep, $int_rep], null]}", | 128 ' $args: [$int_rep, $String_rep],' |
| 129 ' $opt: [[$List_rep, $int_rep], null]}', |
120 env.getElement('m7').computeType(env.compiler)); | 130 env.getElement('m7').computeType(env.compiler)); |
121 | 131 |
122 // m8(int a, {String b}) {} | 132 // m8(int a, {String b}) {} |
123 expect("{func: true, args: [$int_rep], named: {b: $String_rep}}", | 133 expect('{$func: "dynamic__int__String0",' |
| 134 ' $args: [$int_rep], $named: {b: $String_rep}}', |
124 env.getElement('m8').computeType(env.compiler)); | 135 env.getElement('m8').computeType(env.compiler)); |
125 | 136 |
126 // m9(int a, String b, {List<int> c, d}) {} | 137 // m9(int a, String b, {List<int> c, d}) {} |
127 expect("{func: true, args: [$int_rep, $String_rep]," | 138 expect('{$func: "dynamic__int_String__List_dynamic0",' |
128 " named: {c: [$List_rep, $int_rep], d: null}}", | 139 ' $args: [$int_rep, $String_rep],' |
| 140 ' $named: {c: [$List_rep, $int_rep], d: null}}', |
129 env.getElement('m9').computeType(env.compiler)); | 141 env.getElement('m9').computeType(env.compiler)); |
130 | 142 |
131 // m10(void f(int a, [b])) {} | 143 // m10(void f(int a, [b])) {} |
132 expect("{func: true, args:" | 144 expect('{$func: "dynamic__void__int__dynamic", $args:' |
133 " [{func: true, retvoid: true, args: [$int_rep], opt: [null]}]}", | 145 ' [{$func: "void__int__dynamic",' |
| 146 ' $retvoid: true, $args: [$int_rep], $opt: [null]}]}', |
134 env.getElement('m10').computeType(env.compiler)); | 147 env.getElement('m10').computeType(env.compiler)); |
135 } | 148 } |
136 | 149 |
137 | 150 |
OLD | NEW |