| 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 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 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 visit(node.condition); | 1405 visit(node.condition); |
| 1406 visit(node.thenPart); | 1406 visit(node.thenPart); |
| 1407 visit(node.elsePart); | 1407 visit(node.elsePart); |
| 1408 } | 1408 } |
| 1409 | 1409 |
| 1410 static bool isLogicalOperator(Identifier op) { | 1410 static bool isLogicalOperator(Identifier op) { |
| 1411 String str = op.source.stringValue; | 1411 String str = op.source.stringValue; |
| 1412 return (str === '&&' || str == '||' || str == '!'); | 1412 return (str === '&&' || str == '||' || str == '!'); |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 /** | |
| 1416 * Check the lexical scope chain for a declaration with the name "assert". | |
| 1417 * | |
| 1418 * This is used to detect whether "assert(x)" is actually an assertion or | |
| 1419 * just a call expression. | |
| 1420 * It does not check fields inherited from a superclass. | |
| 1421 */ | |
| 1422 bool isAssertInLexicalScope() { | |
| 1423 return scope.lexicalLookup(const SourceString("assert")) !== null; | |
| 1424 } | |
| 1425 | |
| 1426 /** Check if [node] is the expression of the current expression statement. */ | |
| 1427 bool isExpressionStatementExpression(Node node) { | |
| 1428 return currentExpressionStatement !== null && | |
| 1429 currentExpressionStatement.expression === node; | |
| 1430 } | |
| 1431 | |
| 1432 Element resolveSend(Send node) { | 1415 Element resolveSend(Send node) { |
| 1433 Selector selector = resolveSelector(node); | 1416 Selector selector = resolveSelector(node); |
| 1434 | 1417 |
| 1435 if (node.receiver === null) { | 1418 if (node.receiver === null) { |
| 1436 // If this send is the expression of an expression statement, and is on | 1419 // If this send is of the form "assert(expr);", then |
| 1437 // the form "assert(expr);", and there is no declaration with name | 1420 // this is an assertion. |
| 1438 // "assert" in the lexical scope, then this is actually an assertion. | 1421 if (selector.isAssert()) { |
| 1439 if (isExpressionStatementExpression(node) && | 1422 if (selector.argumentCount != 1) { |
| 1440 selector.isAssertSyntax() && | 1423 error(node.selector, |
| 1441 !isAssertInLexicalScope()) { | 1424 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, |
| 1425 [selector.argumentCount]); |
| 1426 } else if (selector.namedArgumentCount != 0) { |
| 1427 error(node.selector, |
| 1428 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS, |
| 1429 [selector.namedArgumentCount]); |
| 1430 } |
| 1442 return compiler.assertMethod; | 1431 return compiler.assertMethod; |
| 1443 } | 1432 } |
| 1444 return node.selector.accept(this); | 1433 return node.selector.accept(this); |
| 1445 } | 1434 } |
| 1446 | 1435 |
| 1447 var oldCategory = allowedCategory; | 1436 var oldCategory = allowedCategory; |
| 1448 allowedCategory |= | 1437 allowedCategory |= |
| 1449 ElementCategory.CLASS | ElementCategory.PREFIX | ElementCategory.SUPER; | 1438 ElementCategory.CLASS | ElementCategory.PREFIX | ElementCategory.SUPER; |
| 1450 Element resolvedReceiver = visit(node.receiver); | 1439 Element resolvedReceiver = visit(node.receiver); |
| 1451 allowedCategory = oldCategory; | 1440 allowedCategory = oldCategory; |
| (...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3152 return result; | 3141 return result; |
| 3153 } | 3142 } |
| 3154 Element lookup(SourceString name) => localLookup(name); | 3143 Element lookup(SourceString name) => localLookup(name); |
| 3155 Element lexicalLookup(SourceString name) => localLookup(name); | 3144 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3156 | 3145 |
| 3157 Element add(Element newElement) { | 3146 Element add(Element newElement) { |
| 3158 throw "Cannot add an element in a patch library scope"; | 3147 throw "Cannot add an element in a patch library scope"; |
| 3159 } | 3148 } |
| 3160 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3149 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3161 } | 3150 } |
| OLD | NEW |