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 package com.google.dart.compiler.parser; | 5 package com.google.dart.compiler.parser; |
6 | 6 |
7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
8 import com.google.common.collect.ImmutableSet; | 8 import com.google.common.collect.ImmutableSet; |
9 import com.google.common.io.CharStreams; | 9 import com.google.common.io.CharStreams; |
10 import com.google.dart.compiler.DartCompilationError; | 10 import com.google.dart.compiler.DartCompilationError; |
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 if (modifiers.isFactory()) { | 1452 if (modifiers.isFactory()) { |
1453 if (modifiers.isAbstract()) { | 1453 if (modifiers.isAbstract()) { |
1454 reportError(position(), ParserErrorCode.FACTORY_CANNOT_BE_ABSTRACT); | 1454 reportError(position(), ParserErrorCode.FACTORY_CANNOT_BE_ABSTRACT); |
1455 } | 1455 } |
1456 if (modifiers.isStatic()) { | 1456 if (modifiers.isStatic()) { |
1457 reportError(position(), ParserErrorCode.FACTORY_CANNOT_BE_STATIC); | 1457 reportError(position(), ParserErrorCode.FACTORY_CANNOT_BE_STATIC); |
1458 } | 1458 } |
1459 } | 1459 } |
1460 | 1460 |
1461 int arity = -1; | 1461 int arity = -1; |
| 1462 Token operation = null; |
1462 if (peek(1) != Token.LPAREN && optionalPseudoKeyword(OPERATOR_KEYWORD)) { | 1463 if (peek(1) != Token.LPAREN && optionalPseudoKeyword(OPERATOR_KEYWORD)) { |
1463 // Overloaded operator. | 1464 // Overloaded operator. |
1464 if (modifiers.isStatic()) { | 1465 if (modifiers.isStatic()) { |
1465 reportError(position(), ParserErrorCode.OPERATOR_CANNOT_BE_STATIC); | 1466 reportError(position(), ParserErrorCode.OPERATOR_CANNOT_BE_STATIC); |
1466 } | 1467 } |
1467 modifiers = modifiers.makeOperator(); | 1468 modifiers = modifiers.makeOperator(); |
1468 | 1469 |
1469 beginOperatorName(); | 1470 beginOperatorName(); |
1470 Token operation = next(); | 1471 operation = next(); |
1471 if (operation.isUserDefinableOperator()) { | 1472 if (operation.isUserDefinableOperator()) { |
1472 name = done(new DartIdentifier(operation.getSyntax())); | 1473 name = done(new DartIdentifier(operation.getSyntax())); |
1473 if (operation == Token.ASSIGN_INDEX) { | 1474 if (operation == Token.ASSIGN_INDEX) { |
1474 arity = 2; | 1475 arity = 2; |
| 1476 } else if (operation == Token.SUB) { |
| 1477 arity = -1; |
1475 } else if (operation.isBinaryOperator()) { | 1478 } else if (operation.isBinaryOperator()) { |
1476 arity = 1; | 1479 arity = 1; |
1477 } else if (operation == Token.INDEX) { | 1480 } else if (operation == Token.INDEX) { |
1478 arity = 1; | 1481 arity = 1; |
1479 } else { | 1482 } else { |
1480 assert operation.isUnaryOperator(); | 1483 assert operation.isUnaryOperator(); |
1481 arity = 0; | 1484 arity = 0; |
1482 } | 1485 } |
1483 } else if (operation == Token.IDENTIFIER | 1486 } else if (operation == Token.IDENTIFIER |
1484 && ctx.getTokenString().equals(CALL_KEYWORD)) { | 1487 && ctx.getTokenString().equals(CALL_KEYWORD)) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 if (arity != -1) { | 1567 if (arity != -1) { |
1565 if (parameters.size() != arity) { | 1568 if (parameters.size() != arity) { |
1566 reportError(position(), ParserErrorCode.ILLEGAL_NUMBER_OF_PARAMETERS); | 1569 reportError(position(), ParserErrorCode.ILLEGAL_NUMBER_OF_PARAMETERS); |
1567 } | 1570 } |
1568 // In methods with required arity each parameter is required. | 1571 // In methods with required arity each parameter is required. |
1569 for (DartParameter parameter : parameters) { | 1572 for (DartParameter parameter : parameters) { |
1570 if (parameter.getModifiers().isNamed()) { | 1573 if (parameter.getModifiers().isNamed()) { |
1571 reportError(parameter, ParserErrorCode.NAMED_PARAMETER_NOT_ALLOWED); | 1574 reportError(parameter, ParserErrorCode.NAMED_PARAMETER_NOT_ALLOWED); |
1572 } | 1575 } |
1573 } | 1576 } |
| 1577 } else if (operation == Token.SUB) { |
| 1578 if (parameters.size() != 0 && parameters.size() != 1) { |
| 1579 reportError(position(), ParserErrorCode.ILLEGAL_NUMBER_OF_PARAMETERS); |
| 1580 } |
| 1581 // In methods with required arity each parameter is required. |
| 1582 for (DartParameter parameter : parameters) { |
| 1583 if (parameter.getModifiers().isNamed()) { |
| 1584 reportError(parameter, ParserErrorCode.NAMED_PARAMETER_NOT_ALLOWED); |
| 1585 } |
| 1586 } |
1574 } | 1587 } |
1575 | 1588 |
1576 // Parse initializer expressions for constructors. | 1589 // Parse initializer expressions for constructors. |
1577 List<DartInitializer> initializers = new ArrayList<DartInitializer>(); | 1590 List<DartInitializer> initializers = new ArrayList<DartInitializer>(); |
1578 if (match(Token.COLON) && !(isParsingInterface || modifiers.isFactory())) { | 1591 if (match(Token.COLON) && !(isParsingInterface || modifiers.isFactory())) { |
1579 parseInitializers(initializers); | 1592 parseInitializers(initializers); |
1580 boolean isRedirectedConstructor = validateInitializers(parameters, initial
izers); | 1593 boolean isRedirectedConstructor = validateInitializers(parameters, initial
izers); |
1581 if (isRedirectedConstructor) { | 1594 if (isRedirectedConstructor) { |
1582 modifiers = modifiers.makeRedirectedConstructor(); | 1595 modifiers = modifiers.makeRedirectedConstructor(); |
1583 } | 1596 } |
(...skipping 3276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4860 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen
ts) { | 4873 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen
ts) { |
4861 if (node != null) { | 4874 if (node != null) { |
4862 reportError(new DartCompilationError(node, errorCode, arguments)); | 4875 reportError(new DartCompilationError(node, errorCode, arguments)); |
4863 } | 4876 } |
4864 } | 4877 } |
4865 | 4878 |
4866 private boolean currentlyParsingToplevel() { | 4879 private boolean currentlyParsingToplevel() { |
4867 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); | 4880 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); |
4868 } | 4881 } |
4869 } | 4882 } |
OLD | NEW |