| 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 | 7 |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import 'package:compiler/src/constants/expressions.dart'; | 10 import 'package:compiler/src/constants/expressions.dart'; |
| 11 import 'package:compiler/src/dart_types.dart'; | 11 import 'package:compiler/src/dart_types.dart'; |
| 12 import 'package:compiler/src/elements/modelx.dart'; | 12 import 'package:compiler/src/elements/modelx.dart'; |
| 13 import 'package:compiler/src/resolution/resolution.dart'; | 13 import 'package:compiler/src/resolution/constructors.dart'; |
| 14 import 'package:compiler/src/resolution/members.dart'; |
| 15 import 'package:compiler/src/resolution/registry.dart'; |
| 16 import 'package:compiler/src/resolution/resolution_result.dart'; |
| 17 import 'package:compiler/src/resolution/scope.dart'; |
| 18 import 'package:compiler/src/resolution/tree_elements.dart'; |
| 14 | 19 |
| 15 import 'compiler_helper.dart'; | 20 import 'compiler_helper.dart'; |
| 16 import 'link_helper.dart'; | 21 import 'link_helper.dart'; |
| 17 import 'parser_helper.dart'; | 22 import 'parser_helper.dart'; |
| 18 | 23 |
| 19 Node buildIdentifier(String name) => new Identifier(scan(name)); | 24 Node buildIdentifier(String name) => new Identifier(scan(name)); |
| 20 | 25 |
| 21 Node buildInitialization(String name) => | 26 Node buildInitialization(String name) => |
| 22 parseBodyCode('$name = 1', | 27 parseBodyCode('$name = 1', |
| 23 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens)); | 28 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens)); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 compiler.parseScript(script); | 210 compiler.parseScript(script); |
| 206 compiler.resolveStatement("B b;"); | 211 compiler.resolveStatement("B b;"); |
| 207 | 212 |
| 208 ClassElement classB = compiler.mainApp.find("B"); | 213 ClassElement classB = compiler.mainApp.find("B"); |
| 209 FunctionElement fooB = classB.lookupLocalMember("foo"); | 214 FunctionElement fooB = classB.lookupLocalMember("foo"); |
| 210 ClassElement classA = compiler.mainApp.find("A"); | 215 ClassElement classA = compiler.mainApp.find("A"); |
| 211 FunctionElement fooA = classA.lookupLocalMember("foo"); | 216 FunctionElement fooA = classA.lookupLocalMember("foo"); |
| 212 | 217 |
| 213 ResolverVisitor visitor = | 218 ResolverVisitor visitor = |
| 214 new ResolverVisitor(compiler, fooB, | 219 new ResolverVisitor(compiler, fooB, |
| 215 new ResolutionRegistry.internal(compiler, | 220 new ResolutionRegistry(compiler, |
| 216 new CollectingTreeElements(fooB))); | 221 new CollectingTreeElements(fooB))); |
| 217 FunctionExpression node = (fooB as FunctionElementX).parseNode(compiler); | 222 FunctionExpression node = (fooB as FunctionElementX).parseNode(compiler); |
| 218 visitor.visit(node.body); | 223 visitor.visit(node.body); |
| 219 Map mapping = map(visitor); | 224 Map mapping = map(visitor); |
| 220 | 225 |
| 221 Send superCall = node.body.asReturn().expression; | 226 Send superCall = node.body.asReturn().expression; |
| 222 FunctionElement called = mapping[superCall]; | 227 FunctionElement called = mapping[superCall]; |
| 223 Expect.isNotNull(called); | 228 Expect.isNotNull(called); |
| 224 Expect.equals(fooA, called); | 229 Expect.equals(fooA, called); |
| 225 }); | 230 }); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 247 | 252 |
| 248 Future testThis() { | 253 Future testThis() { |
| 249 return Future.wait([ | 254 return Future.wait([ |
| 250 MockCompiler.create((MockCompiler compiler) { | 255 MockCompiler.create((MockCompiler compiler) { |
| 251 compiler.parseScript("class Foo { foo() { return this; } }"); | 256 compiler.parseScript("class Foo { foo() { return this; } }"); |
| 252 compiler.resolveStatement("Foo foo;"); | 257 compiler.resolveStatement("Foo foo;"); |
| 253 ClassElement fooElement = compiler.mainApp.find("Foo"); | 258 ClassElement fooElement = compiler.mainApp.find("Foo"); |
| 254 FunctionElement funElement = fooElement.lookupLocalMember("foo"); | 259 FunctionElement funElement = fooElement.lookupLocalMember("foo"); |
| 255 ResolverVisitor visitor = | 260 ResolverVisitor visitor = |
| 256 new ResolverVisitor(compiler, funElement, | 261 new ResolverVisitor(compiler, funElement, |
| 257 new ResolutionRegistry.internal(compiler, | 262 new ResolutionRegistry(compiler, |
| 258 new CollectingTreeElements(funElement))); | 263 new CollectingTreeElements(funElement))); |
| 259 FunctionExpression function = | 264 FunctionExpression function = |
| 260 (funElement as FunctionElementX).parseNode(compiler); | 265 (funElement as FunctionElementX).parseNode(compiler); |
| 261 visitor.visit(function.body); | 266 visitor.visit(function.body); |
| 262 Map mapping = map(visitor); | 267 Map mapping = map(visitor); |
| 263 List<Element> values = mapping.values.toList(); | 268 List<Element> values = mapping.values.toList(); |
| 264 Expect.equals(0, mapping.length); | 269 Expect.equals(0, mapping.length); |
| 265 Expect.equals(0, compiler.warnings.length); | 270 Expect.equals(0, compiler.warnings.length); |
| 266 }), | 271 }), |
| 267 MockCompiler.create((MockCompiler compiler) { | 272 MockCompiler.create((MockCompiler compiler) { |
| 268 compiler.resolveStatement("main() { return this; }"); | 273 compiler.resolveStatement("main() { return this; }"); |
| 269 Expect.equals(0, compiler.warnings.length); | 274 Expect.equals(0, compiler.warnings.length); |
| 270 Expect.equals(1, compiler.errors.length); | 275 Expect.equals(1, compiler.errors.length); |
| 271 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, | 276 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, |
| 272 compiler.errors[0].message.kind); | 277 compiler.errors[0].message.kind); |
| 273 }), | 278 }), |
| 274 MockCompiler.create((MockCompiler compiler) { | 279 MockCompiler.create((MockCompiler compiler) { |
| 275 compiler.parseScript("class Foo { static foo() { return this; } }"); | 280 compiler.parseScript("class Foo { static foo() { return this; } }"); |
| 276 compiler.resolveStatement("Foo foo;"); | 281 compiler.resolveStatement("Foo foo;"); |
| 277 ClassElement fooElement = compiler.mainApp.find("Foo"); | 282 ClassElement fooElement = compiler.mainApp.find("Foo"); |
| 278 FunctionElement funElement = fooElement.lookupLocalMember("foo"); | 283 FunctionElement funElement = fooElement.lookupLocalMember("foo"); |
| 279 ResolverVisitor visitor = new ResolverVisitor(compiler, funElement, | 284 ResolverVisitor visitor = new ResolverVisitor(compiler, funElement, |
| 280 new ResolutionRegistry.internal(compiler, | 285 new ResolutionRegistry(compiler, |
| 281 new CollectingTreeElements(funElement))); | 286 new CollectingTreeElements(funElement))); |
| 282 FunctionExpression function = | 287 FunctionExpression function = |
| 283 (funElement as FunctionElementX).parseNode(compiler); | 288 (funElement as FunctionElementX).parseNode(compiler); |
| 284 visitor.visit(function.body); | 289 visitor.visit(function.body); |
| 285 Expect.equals(0, compiler.warnings.length); | 290 Expect.equals(0, compiler.warnings.length); |
| 286 Expect.equals(1, compiler.errors.length); | 291 Expect.equals(1, compiler.errors.length); |
| 287 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, | 292 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, |
| 288 compiler.errors[0].message.kind); | 293 compiler.errors[0].message.kind); |
| 289 }), | 294 }), |
| 290 ]); | 295 ]); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 {'typeName': 'bar'}, false), | 571 {'typeName': 'bar'}, false), |
| 567 compiler.errors[0].message); | 572 compiler.errors[0].message); |
| 568 compiler.clearMessages(); | 573 compiler.clearMessages(); |
| 569 | 574 |
| 570 // Add the abstract class to the world and make sure everything is setup | 575 // Add the abstract class to the world and make sure everything is setup |
| 571 // correctly. | 576 // correctly. |
| 572 compiler.parseScript("abstract class Bar {}"); | 577 compiler.parseScript("abstract class Bar {}"); |
| 573 | 578 |
| 574 ResolverVisitor visitor = | 579 ResolverVisitor visitor = |
| 575 new ResolverVisitor(compiler, null, | 580 new ResolverVisitor(compiler, null, |
| 576 new ResolutionRegistry.internal(compiler, | 581 new ResolutionRegistry(compiler, |
| 577 new CollectingTreeElements(null))); | 582 new CollectingTreeElements(null))); |
| 578 compiler.resolveStatement("Foo bar;"); | 583 compiler.resolveStatement("Foo bar;"); |
| 579 | 584 |
| 580 ClassElement fooElement = compiler.mainApp.find('Foo'); | 585 ClassElement fooElement = compiler.mainApp.find('Foo'); |
| 581 ClassElement barElement = compiler.mainApp.find('Bar'); | 586 ClassElement barElement = compiler.mainApp.find('Bar'); |
| 582 | 587 |
| 583 Expect.equals(null, barElement.supertype); | 588 Expect.equals(null, barElement.supertype); |
| 584 Expect.isTrue(barElement.interfaces.isEmpty); | 589 Expect.isTrue(barElement.interfaces.isEmpty); |
| 585 | 590 |
| 586 Expect.equals(barElement.computeType(compiler), | 591 Expect.equals(barElement.computeType(compiler), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 MockCompiler compiler = new MockCompiler.internal(coreSource: corelib); | 688 MockCompiler compiler = new MockCompiler.internal(coreSource: corelib); |
| 684 return compiler.init().then((_) { | 689 return compiler.init().then((_) { |
| 685 compiler.parseScript(script); | 690 compiler.parseScript(script); |
| 686 compiler.resolveStatement(statement); | 691 compiler.resolveStatement(statement); |
| 687 ClassElement classElement = compiler.mainApp.find(className); | 692 ClassElement classElement = compiler.mainApp.find(className); |
| 688 Element element; | 693 Element element; |
| 689 element = classElement.lookupConstructor(constructor); | 694 element = classElement.lookupConstructor(constructor); |
| 690 FunctionExpression tree = (element as FunctionElement).node; | 695 FunctionExpression tree = (element as FunctionElement).node; |
| 691 ResolverVisitor visitor = | 696 ResolverVisitor visitor = |
| 692 new ResolverVisitor(compiler, element, | 697 new ResolverVisitor(compiler, element, |
| 693 new ResolutionRegistry.internal(compiler, | 698 new ResolutionRegistry(compiler, |
| 694 new CollectingTreeElements(element))); | 699 new CollectingTreeElements(element))); |
| 695 new InitializerResolver(visitor, element, tree).resolveInitializers(); | 700 new InitializerResolver(visitor, element, tree).resolveInitializers(); |
| 696 visitor.visit(tree.body); | 701 visitor.visit(tree.body); |
| 697 Expect.equals(expectedElementCount, map(visitor).length, | 702 Expect.equals(expectedElementCount, map(visitor).length, |
| 698 "${map(visitor).values} for '$statement' in context of `$script`"); | 703 "${map(visitor).values} for '$statement' in context of `$script`"); |
| 699 | 704 |
| 700 compareWarningKinds(script, expectedWarnings, compiler.warnings); | 705 compareWarningKinds(script, expectedWarnings, compiler.warnings); |
| 701 compareWarningKinds(script, expectedErrors, compiler.errors); | 706 compareWarningKinds(script, expectedErrors, compiler.errors); |
| 702 compareWarningKinds(script, expectedInfos, compiler.infos); | 707 compareWarningKinds(script, expectedInfos, compiler.infos); |
| 703 }); | 708 }); |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 } | 1412 } |
| 1408 main() => A.m(); | 1413 main() => A.m(); |
| 1409 ''', functionName: 'm'); | 1414 ''', functionName: 'm'); |
| 1410 check(''' | 1415 check(''' |
| 1411 class A { | 1416 class A { |
| 1412 m() => () => await - 3; | 1417 m() => () => await - 3; |
| 1413 } | 1418 } |
| 1414 main() => new A().m(); | 1419 main() => new A().m(); |
| 1415 ''', className: 'A'); | 1420 ''', className: 'A'); |
| 1416 } | 1421 } |
| OLD | NEW |