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

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 11014010: Made assert a keyword. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Renamed Assert to assertHelper. Switched parser to use parseArguments. Added assert argument checki… Created 8 years, 2 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 | Annotate | Revision Log
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 abstract class TreeElements { 5 abstract class TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 DartType getType(TypeAnnotation annotation); 8 DartType getType(TypeAnnotation annotation);
9 bool isParameterChecked(Element element); 9 bool isParameterChecked(Element element);
10 } 10 }
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 visit(node.condition); 1394 visit(node.condition);
1395 visit(node.thenPart); 1395 visit(node.thenPart);
1396 visit(node.elsePart); 1396 visit(node.elsePart);
1397 } 1397 }
1398 1398
1399 static bool isLogicalOperator(Identifier op) { 1399 static bool isLogicalOperator(Identifier op) {
1400 String str = op.source.stringValue; 1400 String str = op.source.stringValue;
1401 return (str === '&&' || str == '||' || str == '!'); 1401 return (str === '&&' || str == '||' || str == '!');
1402 } 1402 }
1403 1403
1404 /**
1405 * Check the lexical scope chain for a declaration with the name "assert".
1406 *
1407 * This is used to detect whether "assert(x)" is actually an assertion or
1408 * just a call expression.
1409 * It does not check fields inherited from a superclass.
1410 */
1411 bool isAssertInLexicalScope() {
1412 return scope.lexicalLookup(const SourceString("assert")) !== null;
1413 }
1414
1415 /** Check if [node] is the expression of the current expression statement. */
1416 bool isExpressionStatementExpression(Node node) {
1417 return currentExpressionStatement !== null &&
1418 currentExpressionStatement.expression === node;
1419 }
1420
1421 Element resolveSend(Send node) { 1404 Element resolveSend(Send node) {
1422 Selector selector = resolveSelector(node); 1405 Selector selector = resolveSelector(node);
1423 1406
1424 if (node.receiver === null) { 1407 if (node.receiver === null) {
1425 // If this send is the expression of an expression statement, and is on 1408 // If this send is of the form "assert(expr);", then
1426 // the form "assert(expr);", and there is no declaration with name 1409 // this is an assertion.
1427 // "assert" in the lexical scope, then this is actually an assertion. 1410 if (selector.isAssert()) {
1428 if (isExpressionStatementExpression(node) && 1411 if (selector.argumentCount != 1) {
1429 selector.isAssertSyntax() && 1412 error(node.selector,
1430 !isAssertInLexicalScope()) { 1413 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT,
1414 [selector.argumentCount]);
1415 } else if (selector.namedArgumentCount != 0) {
1416 error(node.selector,
1417 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS,
1418 [selector.namedArgumentCount]);
1419 }
1431 return compiler.assertMethod; 1420 return compiler.assertMethod;
1432 } 1421 }
1433 return node.selector.accept(this); 1422 return node.selector.accept(this);
1434 } 1423 }
1435 1424
1436 var oldCategory = allowedCategory; 1425 var oldCategory = allowedCategory;
1437 allowedCategory |= 1426 allowedCategory |=
1438 ElementCategory.CLASS | ElementCategory.PREFIX | ElementCategory.SUPER; 1427 ElementCategory.CLASS | ElementCategory.PREFIX | ElementCategory.SUPER;
1439 Element resolvedReceiver = visit(node.receiver); 1428 Element resolvedReceiver = visit(node.receiver);
1440 allowedCategory = oldCategory; 1429 allowedCategory = oldCategory;
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 return result; 3131 return result;
3143 } 3132 }
3144 Element lookup(SourceString name) => localLookup(name); 3133 Element lookup(SourceString name) => localLookup(name);
3145 Element lexicalLookup(SourceString name) => localLookup(name); 3134 Element lexicalLookup(SourceString name) => localLookup(name);
3146 3135
3147 Element add(Element newElement) { 3136 Element add(Element newElement) {
3148 throw "Cannot add an element in a patch library scope"; 3137 throw "Cannot add an element in a patch library scope";
3149 } 3138 }
3150 String toString() => 'PatchLibraryScope($origin,$patch)'; 3139 String toString() => 'PatchLibraryScope($origin,$patch)';
3151 } 3140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698