| 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 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3141 return result; | 3130 return result; |
| 3142 } | 3131 } |
| 3143 Element lookup(SourceString name) => localLookup(name); | 3132 Element lookup(SourceString name) => localLookup(name); |
| 3144 Element lexicalLookup(SourceString name) => localLookup(name); | 3133 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3145 | 3134 |
| 3146 Element add(Element newElement) { | 3135 Element add(Element newElement) { |
| 3147 throw "Cannot add an element in a patch library scope"; | 3136 throw "Cannot add an element in a patch library scope"; |
| 3148 } | 3137 } |
| 3149 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3138 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3150 } | 3139 } |
| OLD | NEW |