OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.outline_builder; | 5 library fasta.outline_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' show ProcedureKind; | 7 import 'package:kernel/ast.dart' show ProcedureKind; |
8 | 8 |
9 import '../../scanner/token.dart' show Token; | 9 import '../../scanner/token.dart' show Token; |
10 | 10 |
11 import '../builder/builder.dart'; | 11 import '../builder/builder.dart'; |
12 | 12 |
13 import '../combinator.dart' show Combinator; | 13 import '../combinator.dart' show Combinator; |
14 | 14 |
15 import '../fasta_codes.dart' | 15 import '../fasta_codes.dart' |
16 show | 16 show |
17 Message, | 17 Message, |
18 codeExpectedBlockToSkip, | 18 codeExpectedBlockToSkip, |
19 messageOperatorWithOptionalFormals, | 19 messageOperatorWithOptionalFormals, |
20 messageTypedefNotFunction, | 20 messageTypedefNotFunction, |
21 templateDuplicatedParameterName, | 21 templateDuplicatedParameterName, |
22 templateDuplicatedParameterNameCause, | 22 templateDuplicatedParameterNameCause, |
23 templateOperatorParameterMismatch; | 23 templateOperatorMinusParameterMismatch, |
| 24 templateOperatorParameterMismatch0, |
| 25 templateOperatorParameterMismatch1, |
| 26 templateOperatorParameterMismatch2; |
24 | 27 |
25 import '../modifier.dart' show abstractMask, externalMask, Modifier; | 28 import '../modifier.dart' show abstractMask, externalMask, Modifier; |
26 | 29 |
27 import '../operator.dart' | 30 import '../operator.dart' |
28 show | 31 show |
29 Operator, | 32 Operator, |
30 operatorFromString, | 33 operatorFromString, |
31 operatorToString, | 34 operatorToString, |
32 operatorRequiredArgumentCount; | 35 operatorRequiredArgumentCount; |
33 | 36 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 if (Operator.subtract == nameOrOperator && formals == null) { | 384 if (Operator.subtract == nameOrOperator && formals == null) { |
382 nameOrOperator = Operator.unaryMinus; | 385 nameOrOperator = Operator.unaryMinus; |
383 } | 386 } |
384 String name; | 387 String name; |
385 ProcedureKind kind; | 388 ProcedureKind kind; |
386 if (nameOrOperator is Operator) { | 389 if (nameOrOperator is Operator) { |
387 name = operatorToString(nameOrOperator); | 390 name = operatorToString(nameOrOperator); |
388 kind = ProcedureKind.Operator; | 391 kind = ProcedureKind.Operator; |
389 int requiredArgumentCount = operatorRequiredArgumentCount(nameOrOperator); | 392 int requiredArgumentCount = operatorRequiredArgumentCount(nameOrOperator); |
390 if ((formals?.length ?? 0) != requiredArgumentCount) { | 393 if ((formals?.length ?? 0) != requiredArgumentCount) { |
391 addCompileTimeError( | 394 var template; |
392 templateOperatorParameterMismatch.withArguments( | 395 switch (requiredArgumentCount) { |
393 name, requiredArgumentCount), | 396 case 0: |
394 charOffset); | 397 template = templateOperatorParameterMismatch0; |
| 398 break; |
| 399 |
| 400 case 1: |
| 401 if (Operator.subtract == nameOrOperator) { |
| 402 template = templateOperatorMinusParameterMismatch; |
| 403 } else { |
| 404 template = templateOperatorParameterMismatch1; |
| 405 } |
| 406 break; |
| 407 |
| 408 case 2: |
| 409 template = templateOperatorParameterMismatch2; |
| 410 break; |
| 411 |
| 412 default: |
| 413 unhandled("$requiredArgumentCount", "operatorRequiredArgumentCount", |
| 414 charOffset, uri); |
| 415 } |
| 416 addCompileTimeError(template.withArguments(name), charOffset); |
395 } else { | 417 } else { |
396 if (formals != null) { | 418 if (formals != null) { |
397 for (FormalParameterBuilder formal in formals) { | 419 for (FormalParameterBuilder formal in formals) { |
398 if (!formal.isRequired) { | 420 if (!formal.isRequired) { |
399 addCompileTimeError( | 421 addCompileTimeError( |
400 messageOperatorWithOptionalFormals, formal.charOffset); | 422 messageOperatorWithOptionalFormals, formal.charOffset); |
401 } | 423 } |
402 } | 424 } |
403 } | 425 } |
404 } | 426 } |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 Link<Token> handleMemberName(Link<Token> identifiers) { | 914 Link<Token> handleMemberName(Link<Token> identifiers) { |
893 if (!enableNative || identifiers.isEmpty) return identifiers; | 915 if (!enableNative || identifiers.isEmpty) return identifiers; |
894 return removeNativeClause(identifiers, stringExpectedAfterNative); | 916 return removeNativeClause(identifiers, stringExpectedAfterNative); |
895 } | 917 } |
896 | 918 |
897 @override | 919 @override |
898 void debugEvent(String name) { | 920 void debugEvent(String name) { |
899 // printEvent(name); | 921 // printEvent(name); |
900 } | 922 } |
901 } | 923 } |
OLD | NEW |