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

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

Issue 1342213003: Add optional message to assert in Dart2js - continued (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add --assert-message flag 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
« no previous file with comments | « pkg/compiler/lib/src/parser/parser.dart ('k') | pkg/compiler/lib/src/resolution/registry.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 compiler.resolver.constantCompiler.compileConstant(parameter); 494 compiler.resolver.constantCompiler.compileConstant(parameter);
495 }); 495 });
496 }); 496 });
497 if (inCheckContext) { 497 if (inCheckContext) {
498 functionParameters.forEachParameter((ParameterElement element) { 498 functionParameters.forEachParameter((ParameterElement element) {
499 registry.registerIsCheck(element.type); 499 registry.registerIsCheck(element.type);
500 }); 500 });
501 } 501 }
502 } 502 }
503 503
504 ResolutionResult visitAssert(Assert node) {
505 if (!compiler.enableAssertMessage) {
506 if (node.hasMessage) {
507 compiler.reportError(node, MessageKind.EXPERIMENTAL_ASSERT_MESSAGE);
508 }
509 }
510 // TODO(sra): We could completely ignore the assert in production mode if we
511 // didn't need it to be resolved for type checking.
512 registry.registerAssert(node.hasMessage);
513 visit(node.condition);
514 visit(node.message);
515 return const NoneResult();
516 }
517
504 ResolutionResult visitCascade(Cascade node) { 518 ResolutionResult visitCascade(Cascade node) {
505 visit(node.expression); 519 visit(node.expression);
506 return const NoneResult(); 520 return const NoneResult();
507 } 521 }
508 522
509 ResolutionResult visitCascadeReceiver(CascadeReceiver node) { 523 ResolutionResult visitCascadeReceiver(CascadeReceiver node) {
510 visit(node.expression); 524 visit(node.expression);
511 return const NoneResult(); 525 return const NoneResult();
512 } 526 }
513 527
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 Selector selector = callStructure.callSelector; 1535 Selector selector = callStructure.callSelector;
1522 // TODO(23998): Remove this when all information goes through the 1536 // TODO(23998): Remove this when all information goes through the
1523 // [SendStructure]. 1537 // [SendStructure].
1524 registry.setSelector(node, selector); 1538 registry.setSelector(node, selector);
1525 registry.registerDynamicInvocation(new UniverseSelector(selector, null)); 1539 registry.registerDynamicInvocation(new UniverseSelector(selector, null));
1526 registry.registerSendStructure(node, 1540 registry.registerSendStructure(node,
1527 new InvokeStructure(const DynamicAccess.expression(), selector)); 1541 new InvokeStructure(const DynamicAccess.expression(), selector));
1528 return const NoneResult(); 1542 return const NoneResult();
1529 } 1543 }
1530 1544
1531 /// Handle a, possibly invalid, assertion, like `assert(cond)` or `assert()`.
1532 ResolutionResult handleAssert(Send node) {
1533 assert(invariant(node, node.isCall,
1534 message: "Unexpected assert: $node"));
1535 // If this send is of the form "assert(expr);", then
1536 // this is an assertion.
1537
1538 CallStructure callStructure =
1539 resolveArguments(node.argumentsNode).callStructure;
1540 SendStructure sendStructure = const AssertStructure();
1541 if (callStructure.argumentCount != 1) {
1542 compiler.reportError(
1543 node.selector,
1544 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT,
1545 {'argumentCount': callStructure.argumentCount});
1546 sendStructure = const InvalidAssertStructure();
1547 } else if (callStructure.namedArgumentCount != 0) {
1548 compiler.reportError(
1549 node.selector,
1550 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS,
1551 {'argumentCount': callStructure.namedArgumentCount});
1552 sendStructure = const InvalidAssertStructure();
1553 }
1554 registry.registerAssert(node);
1555 registry.registerSendStructure(node, sendStructure);
1556 return const AssertResult();
1557 }
1558
1559 /// Handle access of a property of [name] on `this`, like `this.name` and 1545 /// Handle access of a property of [name] on `this`, like `this.name` and
1560 /// `this.name()`, or `name` and `name()` in instance context. 1546 /// `this.name()`, or `name` and `name()` in instance context.
1561 ResolutionResult handleThisPropertyAccess(Send node, Name name) { 1547 ResolutionResult handleThisPropertyAccess(Send node, Name name) {
1562 AccessSemantics semantics = new DynamicAccess.thisProperty(name); 1548 AccessSemantics semantics = new DynamicAccess.thisProperty(name);
1563 return handleDynamicAccessSemantics(node, name, semantics); 1549 return handleDynamicAccessSemantics(node, name, semantics);
1564 } 1550 }
1565 1551
1566 /// Handle update of a property of [name] on `this`, like `this.name = b` and 1552 /// Handle update of a property of [name] on `this`, like `this.name = b` and
1567 /// `this.name++`, or `name = b` and `name++` in instance context. 1553 /// `this.name++`, or `name = b` and `name++` in instance context.
1568 ResolutionResult handleThisPropertyUpdate( 1554 ResolutionResult handleThisPropertyUpdate(
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after
3026 3012
3027 /// Handle an unqualified [Send], that is where the `node.receiver` is null, 3013 /// Handle an unqualified [Send], that is where the `node.receiver` is null,
3028 /// like `a`, `a()`, `this()`, `assert()`, and `(){}()`. 3014 /// like `a`, `a()`, `this()`, `assert()`, and `(){}()`.
3029 ResolutionResult handleUnqualifiedSend(Send node) { 3015 ResolutionResult handleUnqualifiedSend(Send node) {
3030 Identifier selector = node.selector.asIdentifier(); 3016 Identifier selector = node.selector.asIdentifier();
3031 if (selector == null) { 3017 if (selector == null) {
3032 // `(){}()` and `(foo)()`. 3018 // `(){}()` and `(foo)()`.
3033 return handleExpressionInvoke(node); 3019 return handleExpressionInvoke(node);
3034 } 3020 }
3035 String text = selector.source; 3021 String text = selector.source;
3036 if (text == 'assert') { 3022 if (text == 'this') {
3037 // `assert()`.
3038 return handleAssert(node);
3039 } else if (text == 'this') {
3040 // `this()`. 3023 // `this()`.
3041 return handleThisAccess(node); 3024 return handleThisAccess(node);
3042 } 3025 }
3043 // `name` or `name()` 3026 // `name` or `name()`
3044 Name name = new Name(text, enclosingElement.library); 3027 Name name = new Name(text, enclosingElement.library);
3045 Element element = lookupInScope(compiler, node, scope, text); 3028 Element element = lookupInScope(compiler, node, scope, text);
3046 if (element == null) { 3029 if (element == null) {
3047 if (text == 'dynamic') { 3030 if (text == 'dynamic') {
3048 // `dynamic` or `dynamic()` where 'dynamic' is not declared in the 3031 // `dynamic` or `dynamic()` where 'dynamic' is not declared in the
3049 // current scope. 3032 // current scope.
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after
4670 } 4653 }
4671 return const NoneResult(); 4654 return const NoneResult();
4672 } 4655 }
4673 } 4656 }
4674 4657
4675 /// Looks up [name] in [scope] and unwraps the result. 4658 /// Looks up [name] in [scope] and unwraps the result.
4676 Element lookupInScope(Compiler compiler, Node node, 4659 Element lookupInScope(Compiler compiler, Node node,
4677 Scope scope, String name) { 4660 Scope scope, String name) {
4678 return Elements.unwrap(scope.lookup(name), compiler, node); 4661 return Elements.unwrap(scope.lookup(name), compiler, node);
4679 } 4662 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/parser/parser.dart ('k') | pkg/compiler/lib/src/resolution/registry.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698