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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 compiler.resolver.constantCompiler.compileConstant(parameter); | 492 compiler.resolver.constantCompiler.compileConstant(parameter); |
493 }); | 493 }); |
494 }); | 494 }); |
495 if (inCheckContext) { | 495 if (inCheckContext) { |
496 functionParameters.forEachParameter((ParameterElement element) { | 496 functionParameters.forEachParameter((ParameterElement element) { |
497 registry.registerIsCheck(element.type); | 497 registry.registerIsCheck(element.type); |
498 }); | 498 }); |
499 } | 499 } |
500 } | 500 } |
501 | 501 |
502 ResolutionResult visitAssert(Assert node) { | |
503 // TODO(sra): We could completely ignore the assert in production mode if we | |
504 // didn't need it to be resolved for type checking. | |
505 registry.registerAssert(node.hasMessage); | |
506 visit(node.condition); | |
507 visit(node.message); | |
Johnni Winther
2015/09/16 16:48:38
The fastest way is the add an option like in https
sra1
2015/09/16 17:33:29
I will do this under a separate CL.
A separate CL
| |
508 return const NoneResult(); | |
509 } | |
510 | |
502 ResolutionResult visitCascade(Cascade node) { | 511 ResolutionResult visitCascade(Cascade node) { |
503 visit(node.expression); | 512 visit(node.expression); |
504 return const NoneResult(); | 513 return const NoneResult(); |
505 } | 514 } |
506 | 515 |
507 ResolutionResult visitCascadeReceiver(CascadeReceiver node) { | 516 ResolutionResult visitCascadeReceiver(CascadeReceiver node) { |
508 visit(node.expression); | 517 visit(node.expression); |
509 return const NoneResult(); | 518 return const NoneResult(); |
510 } | 519 } |
511 | 520 |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1519 Selector selector = callStructure.callSelector; | 1528 Selector selector = callStructure.callSelector; |
1520 // TODO(23998): Remove this when all information goes through the | 1529 // TODO(23998): Remove this when all information goes through the |
1521 // [SendStructure]. | 1530 // [SendStructure]. |
1522 registry.setSelector(node, selector); | 1531 registry.setSelector(node, selector); |
1523 registry.registerDynamicInvocation(new UniverseSelector(selector, null)); | 1532 registry.registerDynamicInvocation(new UniverseSelector(selector, null)); |
1524 registry.registerSendStructure(node, | 1533 registry.registerSendStructure(node, |
1525 new InvokeStructure(const DynamicAccess.expression(), selector)); | 1534 new InvokeStructure(const DynamicAccess.expression(), selector)); |
1526 return const NoneResult(); | 1535 return const NoneResult(); |
1527 } | 1536 } |
1528 | 1537 |
1529 /// Handle a, possibly invalid, assertion, like `assert(cond)` or `assert()`. | |
1530 ResolutionResult handleAssert(Send node) { | |
1531 assert(invariant(node, node.isCall, | |
1532 message: "Unexpected assert: $node")); | |
1533 // If this send is of the form "assert(expr);", then | |
1534 // this is an assertion. | |
1535 | |
1536 CallStructure callStructure = | |
1537 resolveArguments(node.argumentsNode).callStructure; | |
1538 SendStructure sendStructure = const AssertStructure(); | |
1539 if (callStructure.argumentCount != 1) { | |
1540 compiler.reportError( | |
1541 node.selector, | |
1542 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, | |
1543 {'argumentCount': callStructure.argumentCount}); | |
1544 sendStructure = const InvalidAssertStructure(); | |
1545 } else if (callStructure.namedArgumentCount != 0) { | |
1546 compiler.reportError( | |
1547 node.selector, | |
1548 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS, | |
1549 {'argumentCount': callStructure.namedArgumentCount}); | |
1550 sendStructure = const InvalidAssertStructure(); | |
1551 } | |
1552 registry.registerAssert(node); | |
1553 registry.registerSendStructure(node, sendStructure); | |
1554 return const AssertResult(); | |
1555 } | |
1556 | |
1557 /// Handle access of a property of [name] on `this`, like `this.name` and | 1538 /// Handle access of a property of [name] on `this`, like `this.name` and |
1558 /// `this.name()`, or `name` and `name()` in instance context. | 1539 /// `this.name()`, or `name` and `name()` in instance context. |
1559 ResolutionResult handleThisPropertyAccess(Send node, Name name) { | 1540 ResolutionResult handleThisPropertyAccess(Send node, Name name) { |
1560 AccessSemantics semantics = new DynamicAccess.thisProperty(name); | 1541 AccessSemantics semantics = new DynamicAccess.thisProperty(name); |
1561 return handleDynamicAccessSemantics(node, name, semantics); | 1542 return handleDynamicAccessSemantics(node, name, semantics); |
1562 } | 1543 } |
1563 | 1544 |
1564 /// Handle update of a property of [name] on `this`, like `this.name = b` and | 1545 /// Handle update of a property of [name] on `this`, like `this.name = b` and |
1565 /// `this.name++`, or `name = b` and `name++` in instance context. | 1546 /// `this.name++`, or `name = b` and `name++` in instance context. |
1566 ResolutionResult handleThisPropertyUpdate( | 1547 ResolutionResult handleThisPropertyUpdate( |
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3024 | 3005 |
3025 /// 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, |
3026 /// like `a`, `a()`, `this()`, `assert()`, and `(){}()`. | 3007 /// like `a`, `a()`, `this()`, `assert()`, and `(){}()`. |
3027 ResolutionResult handleUnqualifiedSend(Send node) { | 3008 ResolutionResult handleUnqualifiedSend(Send node) { |
3028 Identifier selector = node.selector.asIdentifier(); | 3009 Identifier selector = node.selector.asIdentifier(); |
3029 if (selector == null) { | 3010 if (selector == null) { |
3030 // `(){}()` and `(foo)()`. | 3011 // `(){}()` and `(foo)()`. |
3031 return handleExpressionInvoke(node); | 3012 return handleExpressionInvoke(node); |
3032 } | 3013 } |
3033 String text = selector.source; | 3014 String text = selector.source; |
3034 if (text == 'assert') { | 3015 if (text == 'this') { |
3035 // `assert()`. | |
3036 return handleAssert(node); | |
3037 } else if (text == 'this') { | |
3038 // `this()`. | 3016 // `this()`. |
3039 return handleThisAccess(node); | 3017 return handleThisAccess(node); |
3040 } | 3018 } |
3041 // `name` or `name()` | 3019 // `name` or `name()` |
3042 Name name = new Name(text, enclosingElement.library); | 3020 Name name = new Name(text, enclosingElement.library); |
3043 Element element = lookupInScope(compiler, node, scope, text); | 3021 Element element = lookupInScope(compiler, node, scope, text); |
3044 if (element == null) { | 3022 if (element == null) { |
3045 if (text == 'dynamic') { | 3023 if (text == 'dynamic') { |
3046 // `dynamic` or `dynamic()` where 'dynamic' is not declared in the | 3024 // `dynamic` or `dynamic()` where 'dynamic' is not declared in the |
3047 // current scope. | 3025 // current scope. |
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4668 } | 4646 } |
4669 return const NoneResult(); | 4647 return const NoneResult(); |
4670 } | 4648 } |
4671 } | 4649 } |
4672 | 4650 |
4673 /// Looks up [name] in [scope] and unwraps the result. | 4651 /// Looks up [name] in [scope] and unwraps the result. |
4674 Element lookupInScope(Compiler compiler, Node node, | 4652 Element lookupInScope(Compiler compiler, Node node, |
4675 Scope scope, String name) { | 4653 Scope scope, String name) { |
4676 return Elements.unwrap(scope.lookup(name), compiler, node); | 4654 return Elements.unwrap(scope.lookup(name), compiler, node); |
4677 } | 4655 } |
OLD | NEW |