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

Side by Side Diff: pkg/compiler/lib/src/resolution/members.dart

Issue 1325843003: Add optional message to assert in Dart2js. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Reintroduce assertHelper for asserts without messages. Created 5 years, 3 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
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 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
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 registry.registerAssert(node.hasMessage);
504 visit(node.condition);
505 visit(node.message);
506 return const NoneResult();
507 }
508
502 ResolutionResult visitCascade(Cascade node) { 509 ResolutionResult visitCascade(Cascade node) {
503 visit(node.expression); 510 visit(node.expression);
504 return const NoneResult(); 511 return const NoneResult();
505 } 512 }
506 513
507 ResolutionResult visitCascadeReceiver(CascadeReceiver node) { 514 ResolutionResult visitCascadeReceiver(CascadeReceiver node) {
508 visit(node.expression); 515 visit(node.expression);
509 return const NoneResult(); 516 return const NoneResult();
510 } 517 }
511 518
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 Selector selector = callStructure.callSelector; 1526 Selector selector = callStructure.callSelector;
1520 // TODO(23998): Remove this when all information goes through the 1527 // TODO(23998): Remove this when all information goes through the
1521 // [SendStructure]. 1528 // [SendStructure].
1522 registry.setSelector(node, selector); 1529 registry.setSelector(node, selector);
1523 registry.registerDynamicInvocation(new UniverseSelector(selector, null)); 1530 registry.registerDynamicInvocation(new UniverseSelector(selector, null));
1524 registry.registerSendStructure(node, 1531 registry.registerSendStructure(node,
1525 new InvokeStructure(const DynamicAccess.expression(), selector)); 1532 new InvokeStructure(const DynamicAccess.expression(), selector));
1526 return const NoneResult(); 1533 return const NoneResult();
1527 } 1534 }
1528 1535
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 1536 /// Handle access of a property of [name] on `this`, like `this.name` and
1558 /// `this.name()`, or `name` and `name()` in instance context. 1537 /// `this.name()`, or `name` and `name()` in instance context.
1559 ResolutionResult handleThisPropertyAccess(Send node, Name name) { 1538 ResolutionResult handleThisPropertyAccess(Send node, Name name) {
1560 AccessSemantics semantics = new DynamicAccess.thisProperty(name); 1539 AccessSemantics semantics = new DynamicAccess.thisProperty(name);
1561 return handleDynamicAccessSemantics(node, name, semantics); 1540 return handleDynamicAccessSemantics(node, name, semantics);
1562 } 1541 }
1563 1542
1564 /// Handle update of a property of [name] on `this`, like `this.name = b` and 1543 /// 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. 1544 /// `this.name++`, or `name = b` and `name++` in instance context.
1566 ResolutionResult handleThisPropertyUpdate( 1545 ResolutionResult handleThisPropertyUpdate(
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 2999
3021 /// Handle an unqualified [Send], that is where the `node.receiver` is null, 3000 /// Handle an unqualified [Send], that is where the `node.receiver` is null,
3022 /// like `a`, `a()`, `this()`, `assert()`, and `(){}()`. 3001 /// like `a`, `a()`, `this()`, `assert()`, and `(){}()`.
3023 ResolutionResult handleUnqualifiedSend(Send node) { 3002 ResolutionResult handleUnqualifiedSend(Send node) {
3024 Identifier selector = node.selector.asIdentifier(); 3003 Identifier selector = node.selector.asIdentifier();
3025 if (selector == null) { 3004 if (selector == null) {
3026 // `(){}()` and `(foo)()`. 3005 // `(){}()` and `(foo)()`.
3027 return handleExpressionInvoke(node); 3006 return handleExpressionInvoke(node);
3028 } 3007 }
3029 String text = selector.source; 3008 String text = selector.source;
3030 if (text == 'assert') { 3009 if (text == 'this') {
3031 // `assert()`.
3032 return handleAssert(node);
3033 } else if (text == 'this') {
3034 // `this()`. 3010 // `this()`.
3035 return handleThisAccess(node); 3011 return handleThisAccess(node);
3036 } 3012 }
3037 // `name` or `name()` 3013 // `name` or `name()`
3038 Name name = new Name(text, enclosingElement.library); 3014 Name name = new Name(text, enclosingElement.library);
3039 Element element = lookupInScope(compiler, node, scope, text); 3015 Element element = lookupInScope(compiler, node, scope, text);
3040 if (element == null) { 3016 if (element == null) {
3041 if (text == 'dynamic') { 3017 if (text == 'dynamic') {
3042 // `dynamic` or `dynamic()` where 'dynamic' is not declared in the 3018 // `dynamic` or `dynamic()` where 'dynamic' is not declared in the
3043 // current scope. 3019 // current scope.
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after
4648 } 4624 }
4649 return const NoneResult(); 4625 return const NoneResult();
4650 } 4626 }
4651 } 4627 }
4652 4628
4653 /// Looks up [name] in [scope] and unwraps the result. 4629 /// Looks up [name] in [scope] and unwraps the result.
4654 Element lookupInScope(Compiler compiler, Node node, 4630 Element lookupInScope(Compiler compiler, Node node,
4655 Scope scope, String name) { 4631 Scope scope, String name) {
4656 return Elements.unwrap(scope.lookup(name), compiler, node); 4632 return Elements.unwrap(scope.lookup(name), compiler, node);
4657 } 4633 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698