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 library dart2js.resolution.members; | 5 library dart2js.resolution.members; |
6 | 6 |
7 import '../common/names.dart' show | 7 import '../common/names.dart' show |
8 Selectors; | 8 Selectors; |
9 import '../compiler.dart' show | 9 import '../compiler.dart' show |
10 Compiler, | 10 Compiler, |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 compiler.resolver.constantCompiler.compileConstant(parameter); | 493 compiler.resolver.constantCompiler.compileConstant(parameter); |
494 }); | 494 }); |
495 }); | 495 }); |
496 if (inCheckContext) { | 496 if (inCheckContext) { |
497 functionParameters.forEachParameter((ParameterElement element) { | 497 functionParameters.forEachParameter((ParameterElement element) { |
498 registry.registerIsCheck(element.type); | 498 registry.registerIsCheck(element.type); |
499 }); | 499 }); |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
| 503 ResolutionResult visitAssert(Assert node) { |
| 504 registry.registerAssert(); |
| 505 visit(node.condition); |
| 506 visit(node.message); |
| 507 return const NoneResult(); |
| 508 } |
| 509 |
503 ResolutionResult visitCascade(Cascade node) { | 510 ResolutionResult visitCascade(Cascade node) { |
504 visit(node.expression); | 511 visit(node.expression); |
505 return const NoneResult(); | 512 return const NoneResult(); |
506 } | 513 } |
507 | 514 |
508 ResolutionResult visitCascadeReceiver(CascadeReceiver node) { | 515 ResolutionResult visitCascadeReceiver(CascadeReceiver node) { |
509 visit(node.expression); | 516 visit(node.expression); |
510 return const NoneResult(); | 517 return const NoneResult(); |
511 } | 518 } |
512 | 519 |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 Selector selector = callStructure.callSelector; | 1523 Selector selector = callStructure.callSelector; |
1517 // TODO(23998): Remove this when all information goes through the | 1524 // TODO(23998): Remove this when all information goes through the |
1518 // [SendStructure]. | 1525 // [SendStructure]. |
1519 registry.setSelector(node, selector); | 1526 registry.setSelector(node, selector); |
1520 registry.registerDynamicInvocation(new UniverseSelector(selector, null)); | 1527 registry.registerDynamicInvocation(new UniverseSelector(selector, null)); |
1521 registry.registerSendStructure(node, | 1528 registry.registerSendStructure(node, |
1522 new InvokeStructure(const DynamicAccess.expression(), selector)); | 1529 new InvokeStructure(const DynamicAccess.expression(), selector)); |
1523 return const NoneResult(); | 1530 return const NoneResult(); |
1524 } | 1531 } |
1525 | 1532 |
1526 /// Handle a, possibly invalid, assertion, like `assert(cond)` or `assert()`. | |
1527 ResolutionResult handleAssert(Send node) { | |
1528 assert(invariant(node, node.isCall, | |
1529 message: "Unexpected assert: $node")); | |
1530 // If this send is of the form "assert(expr);", then | |
1531 // this is an assertion. | |
1532 | |
1533 CallStructure callStructure = | |
1534 resolveArguments(node.argumentsNode).callStructure; | |
1535 SendStructure sendStructure = const AssertStructure(); | |
1536 if (callStructure.argumentCount != 1) { | |
1537 compiler.reportError( | |
1538 node.selector, | |
1539 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, | |
1540 {'argumentCount': callStructure.argumentCount}); | |
1541 sendStructure = const InvalidAssertStructure(); | |
1542 } else if (callStructure.namedArgumentCount != 0) { | |
1543 compiler.reportError( | |
1544 node.selector, | |
1545 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS, | |
1546 {'argumentCount': callStructure.namedArgumentCount}); | |
1547 sendStructure = const InvalidAssertStructure(); | |
1548 } | |
1549 registry.registerAssert(node); | |
1550 registry.registerSendStructure(node, sendStructure); | |
1551 return const AssertResult(); | |
1552 } | |
1553 | |
1554 /// Handle access of a property of [name] on `this`, like `this.name` and | 1533 /// Handle access of a property of [name] on `this`, like `this.name` and |
1555 /// `this.name()`, or `name` and `name()` in instance context. | 1534 /// `this.name()`, or `name` and `name()` in instance context. |
1556 ResolutionResult handleThisPropertyAccess(Send node, Name name) { | 1535 ResolutionResult handleThisPropertyAccess(Send node, Name name) { |
1557 AccessSemantics semantics = const DynamicAccess.thisProperty(); | 1536 AccessSemantics semantics = const DynamicAccess.thisProperty(); |
1558 return handleDynamicAccessSemantics(node, name, semantics); | 1537 return handleDynamicAccessSemantics(node, name, semantics); |
1559 } | 1538 } |
1560 | 1539 |
1561 /// Handle update of a property of [name] on `this`, like `this.name = b` and | 1540 /// Handle update of a property of [name] on `this`, like `this.name = b` and |
1562 /// `this.name++`, or `name = b` and `name++` in instance context. | 1541 /// `this.name++`, or `name = b` and `name++` in instance context. |
1563 ResolutionResult handleThisPropertyUpdate( | 1542 ResolutionResult handleThisPropertyUpdate( |
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3026 | 3005 |
3027 /// Handle an unqualified [Send], that is where the `node.receiver` is null, | 3006 /// Handle an unqualified [Send], that is where the `node.receiver` is null, |
3028 /// like `a`, `a()`, `this()`, `assert()`, and `(){}()`. | 3007 /// like `a`, `a()`, `this()`, `assert()`, and `(){}()`. |
3029 ResolutionResult handleUnqualifiedSend(Send node) { | 3008 ResolutionResult handleUnqualifiedSend(Send node) { |
3030 Identifier selector = node.selector.asIdentifier(); | 3009 Identifier selector = node.selector.asIdentifier(); |
3031 if (selector == null) { | 3010 if (selector == null) { |
3032 // `(){}()` and `(foo)()`. | 3011 // `(){}()` and `(foo)()`. |
3033 return handleExpressionInvoke(node); | 3012 return handleExpressionInvoke(node); |
3034 } | 3013 } |
3035 String text = selector.source; | 3014 String text = selector.source; |
3036 if (text == 'assert') { | 3015 if (text == 'this') { |
3037 // `assert()`. | |
3038 return handleAssert(node); | |
3039 } else if (text == 'this') { | |
3040 // `this()`. | 3016 // `this()`. |
3041 return handleThisAccess(node); | 3017 return handleThisAccess(node); |
3042 } | 3018 } |
3043 // `name` or `name()` | 3019 // `name` or `name()` |
3044 Name name = new Name(text, enclosingElement.library); | 3020 Name name = new Name(text, enclosingElement.library); |
3045 Element element = lookupInScope(compiler, node, scope, text); | 3021 Element element = lookupInScope(compiler, node, scope, text); |
3046 if (element == null) { | 3022 if (element == null) { |
3047 if (text == 'dynamic') { | 3023 if (text == 'dynamic') { |
3048 // `dynamic` or `dynamic()` where 'dynamic' is not declared in the | 3024 // `dynamic` or `dynamic()` where 'dynamic' is not declared in the |
3049 // current scope. | 3025 // current scope. |
(...skipping 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4662 } | 4638 } |
4663 return const NoneResult(); | 4639 return const NoneResult(); |
4664 } | 4640 } |
4665 } | 4641 } |
4666 | 4642 |
4667 /// Looks up [name] in [scope] and unwraps the result. | 4643 /// Looks up [name] in [scope] and unwraps the result. |
4668 Element lookupInScope(Compiler compiler, Node node, | 4644 Element lookupInScope(Compiler compiler, Node node, |
4669 Scope scope, String name) { | 4645 Scope scope, String name) { |
4670 return Elements.unwrap(scope.lookup(name), compiler, node); | 4646 return Elements.unwrap(scope.lookup(name), compiler, node); |
4671 } | 4647 } |
OLD | NEW |