| OLD | NEW |
| 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; | 10 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; |
| 11 import "compiler_helper.dart"; | 11 import "compiler_helper.dart"; |
| 12 import "parser_helper.dart"; | 12 import "parser_helper.dart"; |
| 13 | 13 |
| 14 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; | 14 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; |
| 15 import 'link_helper.dart'; |
| 15 | 16 |
| 16 Node buildIdentifier(String name) => new Identifier(scan(name)); | 17 Node buildIdentifier(String name) => new Identifier(scan(name)); |
| 17 | 18 |
| 18 Node buildInitialization(String name) => | 19 Node buildInitialization(String name) => |
| 19 parseBodyCode('$name = 1', | 20 parseBodyCode('$name = 1', |
| 20 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens)); | 21 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens)); |
| 21 | 22 |
| 22 createLocals(List variables) { | 23 createLocals(List variables) { |
| 23 var locals = []; | 24 var locals = <Node>[]; |
| 24 for (final variable in variables) { | 25 for (final variable in variables) { |
| 25 String name = variable[0]; | 26 String name = variable[0]; |
| 26 bool init = variable[1]; | 27 bool init = variable[1]; |
| 27 if (init) { | 28 if (init) { |
| 28 locals.add(buildInitialization(name)); | 29 locals.add(buildInitialization(name)); |
| 29 } else { | 30 } else { |
| 30 locals.add(buildIdentifier(name)); | 31 locals.add(buildIdentifier(name)); |
| 31 } | 32 } |
| 32 } | 33 } |
| 33 var definitions = new NodeList(null, new Link.fromList(locals), null, null); | 34 var definitions = new NodeList(null, LinkFromList(locals), null, null); |
| 34 return new VariableDefinitions(null, Modifiers.EMPTY, definitions); | 35 return new VariableDefinitions(null, Modifiers.EMPTY, definitions); |
| 35 } | 36 } |
| 36 | 37 |
| 37 testLocals(List variables) { | 38 testLocals(List variables) { |
| 38 MockCompiler compiler = new MockCompiler(); | 39 MockCompiler compiler = new MockCompiler(); |
| 39 ResolverVisitor visitor = compiler.resolverVisitor(); | 40 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 40 Element element = visitor.visit(createLocals(variables)); | 41 Element element = visitor.visit(createLocals(variables)); |
| 41 // A VariableDefinitions does not have an element. | 42 // A VariableDefinitions does not have an element. |
| 42 Expect.equals(null, element); | 43 Expect.equals(null, element); |
| 43 Expect.equals(variables.length, map(visitor).length); | 44 Expect.equals(variables.length, map(visitor).length); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 Expect.equals(MessageKind.MULTI_INHERITANCE, | 122 Expect.equals(MessageKind.MULTI_INHERITANCE, |
| 122 compiler.crashes[0].message.kind); | 123 compiler.crashes[0].message.kind); |
| 123 } | 124 } |
| 124 | 125 |
| 125 testTypeVariables() { | 126 testTypeVariables() { |
| 126 matchResolvedTypes(visitor, text, name, expectedElements) { | 127 matchResolvedTypes(visitor, text, name, expectedElements) { |
| 127 VariableDefinitions definition = parseStatement(text); | 128 VariableDefinitions definition = parseStatement(text); |
| 128 visitor.visit(definition.type); | 129 visitor.visit(definition.type); |
| 129 InterfaceType type = visitor.mapping.getType(definition.type); | 130 InterfaceType type = visitor.mapping.getType(definition.type); |
| 130 Expect.equals(definition.type.typeArguments.slowLength(), | 131 Expect.equals(definition.type.typeArguments.slowLength(), |
| 131 length(type.typeArguments)); | 132 type.typeArguments.length); |
| 132 int index = 0; | 133 int index = 0; |
| 133 Link<DartType> arguments = type.typeArguments; | 134 for (DartType argument in type.typeArguments) { |
| 134 while (!arguments.isEmpty) { | |
| 135 Expect.equals(true, index < expectedElements.length); | 135 Expect.equals(true, index < expectedElements.length); |
| 136 Expect.equals(expectedElements[index], arguments.head.element); | 136 Expect.equals(expectedElements[index], argument.element); |
| 137 index++; | 137 index++; |
| 138 arguments = arguments.tail; | |
| 139 } | 138 } |
| 140 Expect.equals(index, expectedElements.length); | 139 Expect.equals(index, expectedElements.length); |
| 141 } | 140 } |
| 142 | 141 |
| 143 MockCompiler compiler = new MockCompiler(); | 142 MockCompiler compiler = new MockCompiler(); |
| 144 ResolverVisitor visitor = compiler.resolverVisitor(); | 143 ResolverVisitor visitor = compiler.resolverVisitor(); |
| 145 compiler.parseScript('class Foo<T, U> {}'); | 144 compiler.parseScript('class Foo<T, U> {}'); |
| 146 ClassElement foo = compiler.mainApp.find('Foo'); | 145 ClassElement foo = compiler.mainApp.find('Foo'); |
| 147 matchResolvedTypes(visitor, 'Foo<int, String> x;', 'Foo', | 146 matchResolvedTypes(visitor, 'Foo<int, String> x;', 'Foo', |
| 148 [compiler.intClass, compiler.stringClass]); | 147 [compiler.intClass, compiler.stringClass]); |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 }"""; | 1009 }"""; |
| 1011 asyncTest(() => compileScript(script2).then((compiler) { | 1010 asyncTest(() => compileScript(script2).then((compiler) { |
| 1012 expect(compiler, | 1011 expect(compiler, |
| 1013 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], | 1012 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], |
| 1014 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, | 1013 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, |
| 1015 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, | 1014 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, |
| 1016 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, | 1015 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, |
| 1017 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); | 1016 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); |
| 1018 })); | 1017 })); |
| 1019 } | 1018 } |
| OLD | NEW |