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

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

Issue 27510003: Scanner for UTF-8 byte arrays (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixes compiler tests Created 7 years, 2 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 | Annotate | Revision Log
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 '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; 8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart';
9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; 9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart';
10 import '../../../sdk/lib/_internal/compiler/implementation/types/concrete_types_ inferrer.dart'; 10 import '../../../sdk/lib/_internal/compiler/implementation/types/concrete_types_ inferrer.dart';
11 11
12 import "parser_helper.dart"; 12 import "parser_helper.dart";
13 import "compiler_helper.dart"; 13 import "compiler_helper.dart";
14 14
15 /** 15 /**
16 * Finds the node corresponding to the last occurence of the substring 16 * Finds the node corresponding to the last occurence of the substring
17 * [: identifier; :] in the program represented by the visited AST. 17 * [: identifier; :] in the program represented by the visited AST.
18 */ 18 */
19 class VariableFinderVisitor extends Visitor { 19 class VariableFinderVisitor extends Visitor {
20 final String identifier; 20 final String identifier;
21 Node result; 21 Node result;
22 22
23 VariableFinderVisitor(this.identifier); 23 VariableFinderVisitor(this.identifier);
24 24
25 visitSend(Send node) { 25 visitSend(Send node) {
26 if (node.isPropertyAccess 26 if (node.isPropertyAccess
27 && node.selector.asIdentifier().source.slowToString() == identifier) { 27 && node.selector.asIdentifier().source == identifier) {
28 result = node; 28 result = node;
29 } else { 29 } else {
30 node.visitChildren(this); 30 node.visitChildren(this);
31 } 31 }
32 } 32 }
33 33
34 visitNode(Node node) { 34 visitNode(Node node) {
35 node.visitChildren(this); 35 node.visitChildren(this);
36 } 36 }
37 } 37 }
(...skipping 19 matching lines...) Expand all
57 int = inferrer.baseTypes.intBaseType; 57 int = inferrer.baseTypes.intBaseType;
58 double = inferrer.baseTypes.doubleBaseType; 58 double = inferrer.baseTypes.doubleBaseType;
59 num = inferrer.baseTypes.numBaseType; 59 num = inferrer.baseTypes.numBaseType;
60 bool = inferrer.baseTypes.boolBaseType; 60 bool = inferrer.baseTypes.boolBaseType;
61 string = inferrer.baseTypes.stringBaseType; 61 string = inferrer.baseTypes.stringBaseType;
62 list = inferrer.baseTypes.listBaseType; 62 list = inferrer.baseTypes.listBaseType;
63 growableList = inferrer.baseTypes.growableListBaseType; 63 growableList = inferrer.baseTypes.growableListBaseType;
64 map = inferrer.baseTypes.mapBaseType; 64 map = inferrer.baseTypes.mapBaseType;
65 nullType = const NullBaseType(); 65 nullType = const NullBaseType();
66 functionType = inferrer.baseTypes.functionBaseType; 66 functionType = inferrer.baseTypes.functionBaseType;
67 Element mainElement = compiler.mainApp.find(buildSourceString('main')); 67 Element mainElement = compiler.mainApp.find('main');
68 ast = mainElement.parseNode(compiler); 68 ast = mainElement.parseNode(compiler);
69 } 69 }
70 70
71 BaseType base(String className) { 71 BaseType base(String className) {
72 final source = buildSourceString(className); 72 final source = className;
73 return new ClassBaseType(compiler.mainApp.find(source)); 73 return new ClassBaseType(compiler.mainApp.find(source));
74 } 74 }
75 75
76 /** 76 /**
77 * Finds the [Node] corresponding to the last occurence of the substring 77 * Finds the [Node] corresponding to the last occurence of the substring
78 * [: identifier; :] in the program represented by the visited AST. For 78 * [: identifier; :] in the program represented by the visited AST. For
79 * instance, returns the AST node representing [: foo; :] in 79 * instance, returns the AST node representing [: foo; :] in
80 * [: main() { foo = 1; foo; } :]. 80 * [: main() { foo = 1; foo; } :].
81 */ 81 */
82 Node findNode(String identifier) { 82 Node findNode(String identifier) {
83 VariableFinderVisitor finder = new VariableFinderVisitor(identifier); 83 VariableFinderVisitor finder = new VariableFinderVisitor(identifier);
84 ast.accept(finder); 84 ast.accept(finder);
85 return finder.result; 85 return finder.result;
86 } 86 }
87 87
88 /** 88 /**
89 * Finds the [Element] corresponding to [: className#fieldName :]. 89 * Finds the [Element] corresponding to [: className#fieldName :].
90 */ 90 */
91 Element findField(String className, String fieldName) { 91 Element findField(String className, String fieldName) {
92 ClassElement element = compiler.mainApp.find(buildSourceString(className)); 92 ClassElement element = compiler.mainApp.find(className);
93 return element.lookupLocalMember(buildSourceString(fieldName)); 93 return element.lookupLocalMember(fieldName);
94 } 94 }
95 95
96 ConcreteType concreteFrom(List<BaseType> baseTypes) { 96 ConcreteType concreteFrom(List<BaseType> baseTypes) {
97 ConcreteType result = inferrer.emptyConcreteType; 97 ConcreteType result = inferrer.emptyConcreteType;
98 for (final baseType in baseTypes) { 98 for (final baseType in baseTypes) {
99 result = result.union(inferrer.singletonConcreteType(baseType)); 99 result = result.union(inferrer.singletonConcreteType(baseType));
100 } 100 }
101 // We make sure the concrete types expected by the tests don't default to 101 // We make sure the concrete types expected by the tests don't default to
102 // dynamic because of widening. 102 // dynamic because of widening.
103 assert(!result.isUnknown()); 103 assert(!result.isUnknown());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 class StackTrace {} 175 class StackTrace {}
176 class Dynamic_ {} 176 class Dynamic_ {}
177 bool identical(Object a, Object b) {}'''; 177 bool identical(Object a, Object b) {}''';
178 178
179 Future<AnalysisResult> analyze(String code, {int maxConcreteTypeSize: 1000}) { 179 Future<AnalysisResult> analyze(String code, {int maxConcreteTypeSize: 1000}) {
180 Uri uri = new Uri(scheme: 'source'); 180 Uri uri = new Uri(scheme: 'source');
181 MockCompiler compiler = new MockCompiler( 181 MockCompiler compiler = new MockCompiler(
182 coreSource: CORELIB, 182 coreSource: CORELIB,
183 enableConcreteTypeInference: true, 183 enableConcreteTypeInference: true,
184 maxConcreteTypeSize: maxConcreteTypeSize); 184 maxConcreteTypeSize: maxConcreteTypeSize);
185 compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); 185 compiler.sourceFiles[uri.toString()] =
186 new StringSourceFile(uri.toString(), code);
186 compiler.typesTask.concreteTypesInferrer.testMode = true; 187 compiler.typesTask.concreteTypesInferrer.testMode = true;
187 return compiler.runCompiler(uri).then((_) { 188 return compiler.runCompiler(uri).then((_) {
188 return new AnalysisResult(compiler); 189 return new AnalysisResult(compiler);
189 }); 190 });
190 } 191 }
191 192
192 testDynamicBackDoor() { 193 testDynamicBackDoor() {
193 final String source = r""" 194 final String source = r"""
194 main () { 195 main () {
195 var x = "__dynamic_for_test"; 196 var x = "__dynamic_for_test";
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 ClassElement abc = findElement(result.compiler, 'ABC'); 1535 ClassElement abc = findElement(result.compiler, 'ABC');
1535 ClassElement bc = findElement(result.compiler, 'BC'); 1536 ClassElement bc = findElement(result.compiler, 'BC');
1536 ClassElement a = findElement(result.compiler, 'A'); 1537 ClassElement a = findElement(result.compiler, 'A');
1537 ClassElement b = findElement(result.compiler, 'B'); 1538 ClassElement b = findElement(result.compiler, 'B');
1538 ClassElement c = findElement(result.compiler, 'C'); 1539 ClassElement c = findElement(result.compiler, 'C');
1539 ClassElement xy = findElement(result.compiler, 'XY'); 1540 ClassElement xy = findElement(result.compiler, 'XY');
1540 ClassElement x = findElement(result.compiler, 'X'); 1541 ClassElement x = findElement(result.compiler, 'X');
1541 ClassElement y = findElement(result.compiler, 'Y'); 1542 ClassElement y = findElement(result.compiler, 'Y');
1542 ClassElement z = findElement(result.compiler, 'Z'); 1543 ClassElement z = findElement(result.compiler, 'Z');
1543 1544
1544 Selector foo = new Selector.call(buildSourceString("foo"), null, 0); 1545 Selector foo = new Selector.call("foo", null, 0);
1545 1546
1546 Expect.equals( 1547 Expect.equals(
1547 inferredType(foo).simplify(result.compiler), 1548 inferredType(foo).simplify(result.compiler),
1548 new TypeMask.nonNullSubclass(abc)); 1549 new TypeMask.nonNullSubclass(abc));
1549 Expect.equals( 1550 Expect.equals(
1550 inferredType(new TypedSelector.subclass(x, foo)), 1551 inferredType(new TypedSelector.subclass(x, foo)),
1551 new TypeMask.nonNullExact(b)); 1552 new TypeMask.nonNullExact(b));
1552 Expect.equals( 1553 Expect.equals(
1553 inferredType(new TypedSelector.subclass(y, foo)), 1554 inferredType(new TypedSelector.subclass(y, foo)),
1554 new TypeMask.nonNullExact(c)); 1555 new TypeMask.nonNullExact(c));
1555 Expect.equals( 1556 Expect.equals(
1556 inferredType(new TypedSelector.subclass(z, foo)), 1557 inferredType(new TypedSelector.subclass(z, foo)),
1557 new TypeMask.nonNullExact(a)); 1558 new TypeMask.nonNullExact(a));
1558 Expect.equals( 1559 Expect.equals(
1559 inferredType(new TypedSelector.subclass( 1560 inferredType(new TypedSelector.subclass(
1560 xy, foo)).simplify(result.compiler), 1561 xy, foo)).simplify(result.compiler),
1561 new TypeMask.nonNullSubclass(bc)); 1562 new TypeMask.nonNullSubclass(bc));
1562 1563
1563 Selector bar = new Selector.call(buildSourceString("bar"), null, 0); 1564 Selector bar = new Selector.call("bar", null, 0);
1564 1565
1565 Expect.isNull(inferredType(bar)); 1566 Expect.isNull(inferredType(bar));
1566 }); 1567 });
1567 } 1568 }
1568 1569
1569 testMixins() { 1570 testMixins() {
1570 final String source = r""" 1571 final String source = r"""
1571 class A { 1572 class A {
1572 foo() => "abc"; 1573 foo() => "abc";
1573 get x => 42; 1574 get x => 42;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 testIsCheck, 1701 testIsCheck,
1701 testSeenClasses, 1702 testSeenClasses,
1702 testIntDoubleNum, 1703 testIntDoubleNum,
1703 testConcreteTypeToTypeMask, 1704 testConcreteTypeToTypeMask,
1704 testSelectors, 1705 testSelectors,
1705 testMixins, 1706 testMixins,
1706 testClosures, 1707 testClosures,
1707 testNestedFunctions, 1708 testNestedFunctions,
1708 ], (f) => f())); 1709 ], (f) => f()));
1709 } 1710 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698