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 '../fasta_codes.dart' show FastaMessage, codeExpectedBlockToSkip; | 9 import '../fasta_codes.dart' show FastaMessage, codeExpectedBlockToSkip; |
10 | 10 |
11 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; | 11 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; |
12 | 12 |
13 import '../parser/identifier_context.dart' show IdentifierContext; | 13 import '../parser/identifier_context.dart' show IdentifierContext; |
14 | 14 |
15 import '../../scanner/token.dart' show Token; | 15 import '../../scanner/token.dart' show Token; |
16 | 16 |
17 import '../util/link.dart' show Link; | 17 import '../util/link.dart' show Link; |
18 | 18 |
19 import '../combinator.dart' show Combinator; | 19 import '../combinator.dart' show Combinator; |
20 | 20 |
21 import '../errors.dart' show internalError; | 21 import '../deprecated_problems.dart' show deprecated_internalProblem; |
22 | 22 |
23 import '../builder/builder.dart'; | 23 import '../builder/builder.dart'; |
24 | 24 |
25 import '../modifier.dart' show abstractMask, externalMask, Modifier; | 25 import '../modifier.dart' show abstractMask, externalMask, Modifier; |
26 | 26 |
27 import 'source_library_builder.dart' show SourceLibraryBuilder; | 27 import 'source_library_builder.dart' show SourceLibraryBuilder; |
28 | 28 |
29 import 'unhandled_listener.dart' show NullValue, Unhandled, UnhandledListener; | 29 import 'unhandled_listener.dart' show NullValue, Unhandled, UnhandledListener; |
30 | 30 |
31 import '../parser/native_support.dart' | 31 import '../parser/native_support.dart' |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 199 } |
200 | 200 |
201 @override | 201 @override |
202 void endLiteralString(int interpolationCount, Token endToken) { | 202 void endLiteralString(int interpolationCount, Token endToken) { |
203 debugEvent("endLiteralString"); | 203 debugEvent("endLiteralString"); |
204 if (interpolationCount == 0) { | 204 if (interpolationCount == 0) { |
205 Token token = pop(); | 205 Token token = pop(); |
206 push(unescapeString(token.lexeme)); | 206 push(unescapeString(token.lexeme)); |
207 push(token.charOffset); | 207 push(token.charOffset); |
208 } else { | 208 } else { |
209 internalError("String interpolation not implemented."); | 209 deprecated_internalProblem("String interpolation not implemented."); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 @override | 213 @override |
214 void handleStringJuxtaposition(int literalCount) { | 214 void handleStringJuxtaposition(int literalCount) { |
215 debugEvent("StringJuxtaposition"); | 215 debugEvent("StringJuxtaposition"); |
216 List<String> list = | 216 List<String> list = |
217 new List<String>.filled(literalCount, null, growable: false); | 217 new List<String>.filled(literalCount, null, growable: false); |
218 int charOffset = -1; | 218 int charOffset = -1; |
219 for (int i = literalCount - 1; i >= 0; i--) { | 219 for (int i = literalCount - 1; i >= 0; i--) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 List<MetadataBuilder> metadata = pop(); | 288 List<MetadataBuilder> metadata = pop(); |
289 library.addClass(metadata, modifiers, name, typeVariables, supertype, | 289 library.addClass(metadata, modifiers, name, typeVariables, supertype, |
290 interfaces, charOffset); | 290 interfaces, charOffset); |
291 checkEmpty(beginToken.charOffset); | 291 checkEmpty(beginToken.charOffset); |
292 } | 292 } |
293 | 293 |
294 ProcedureKind computeProcedureKind(Token token) { | 294 ProcedureKind computeProcedureKind(Token token) { |
295 if (token == null) return ProcedureKind.Method; | 295 if (token == null) return ProcedureKind.Method; |
296 if (optional("get", token)) return ProcedureKind.Getter; | 296 if (optional("get", token)) return ProcedureKind.Getter; |
297 if (optional("set", token)) return ProcedureKind.Setter; | 297 if (optional("set", token)) return ProcedureKind.Setter; |
298 return internalError("Unhandled: ${token.lexeme}"); | 298 return deprecated_internalProblem("Unhandled: ${token.lexeme}"); |
299 } | 299 } |
300 | 300 |
301 @override | 301 @override |
302 void beginTopLevelMethod(Token token, Token name) { | 302 void beginTopLevelMethod(Token token, Token name) { |
303 library.beginNestedDeclaration(name.lexeme, hasMembers: false); | 303 library.beginNestedDeclaration(name.lexeme, hasMembers: false); |
304 } | 304 } |
305 | 305 |
306 @override | 306 @override |
307 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | 307 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { |
308 debugEvent("endTopLevelMethod"); | 308 debugEvent("endTopLevelMethod"); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 if (Operator.subtract == nameOrOperator && formals == null) { | 366 if (Operator.subtract == nameOrOperator && formals == null) { |
367 nameOrOperator = Operator.unaryMinus; | 367 nameOrOperator = Operator.unaryMinus; |
368 } | 368 } |
369 String name; | 369 String name; |
370 ProcedureKind kind; | 370 ProcedureKind kind; |
371 if (nameOrOperator is Operator) { | 371 if (nameOrOperator is Operator) { |
372 name = operatorToString(nameOrOperator); | 372 name = operatorToString(nameOrOperator); |
373 kind = ProcedureKind.Operator; | 373 kind = ProcedureKind.Operator; |
374 int requiredArgumentCount = operatorRequiredArgumentCount(nameOrOperator); | 374 int requiredArgumentCount = operatorRequiredArgumentCount(nameOrOperator); |
375 if ((formals?.length ?? 0) != requiredArgumentCount) { | 375 if ((formals?.length ?? 0) != requiredArgumentCount) { |
376 library.addCompileTimeError( | 376 library.deprecated_addCompileTimeError( |
377 charOffset, | 377 charOffset, |
378 "Operator '$name' must have exactly $requiredArgumentCount " | 378 "Operator '$name' must have exactly $requiredArgumentCount " |
379 "parameters."); | 379 "parameters."); |
380 } else { | 380 } else { |
381 if (formals != null) { | 381 if (formals != null) { |
382 for (FormalParameterBuilder formal in formals) { | 382 for (FormalParameterBuilder formal in formals) { |
383 if (!formal.isRequired) { | 383 if (!formal.isRequired) { |
384 library.addCompileTimeError(formal.charOffset, | 384 library.deprecated_addCompileTimeError(formal.charOffset, |
385 "An operator can't have optional parameters."); | 385 "An operator can't have optional parameters."); |
386 } | 386 } |
387 } | 387 } |
388 } | 388 } |
389 } | 389 } |
390 } else { | 390 } else { |
391 name = nameOrOperator; | 391 name = nameOrOperator; |
392 kind = computeProcedureKind(getOrSet); | 392 kind = computeProcedureKind(getOrSet); |
393 } | 393 } |
394 TypeBuilder returnType = pop(); | 394 TypeBuilder returnType = pop(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 formals = new List<FormalParameterBuilder>.filled(count + 1, null, | 545 formals = new List<FormalParameterBuilder>.filled(count + 1, null, |
546 growable: true); | 546 growable: true); |
547 formals[count] = last; | 547 formals[count] = last; |
548 } | 548 } |
549 popList(count, formals); | 549 popList(count, formals); |
550 } | 550 } |
551 if (formals != null) { | 551 if (formals != null) { |
552 if (formals.length == 2) { | 552 if (formals.length == 2) { |
553 // The name may be null for generalized function types. | 553 // The name may be null for generalized function types. |
554 if (formals[0].name != null && formals[0].name == formals[1].name) { | 554 if (formals[0].name != null && formals[0].name == formals[1].name) { |
555 library.addCompileTimeError(formals[1].charOffset, | 555 library.deprecated_addCompileTimeError(formals[1].charOffset, |
556 "Duplicated parameter name '${formals[1].name}'."); | 556 "Duplicated parameter name '${formals[1].name}'."); |
557 library.addCompileTimeError(formals[0].charOffset, | 557 library.deprecated_addCompileTimeError(formals[0].charOffset, |
558 "Other parameter named '${formals[1].name}'."); | 558 "Other parameter named '${formals[1].name}'."); |
559 } | 559 } |
560 } else if (formals.length > 2) { | 560 } else if (formals.length > 2) { |
561 Map<String, FormalParameterBuilder> seenNames = | 561 Map<String, FormalParameterBuilder> seenNames = |
562 <String, FormalParameterBuilder>{}; | 562 <String, FormalParameterBuilder>{}; |
563 for (FormalParameterBuilder formal in formals) { | 563 for (FormalParameterBuilder formal in formals) { |
564 if (formal.name == null) continue; | 564 if (formal.name == null) continue; |
565 if (seenNames.containsKey(formal.name)) { | 565 if (seenNames.containsKey(formal.name)) { |
566 library.addCompileTimeError(formal.charOffset, | 566 library.deprecated_addCompileTimeError(formal.charOffset, |
567 "Duplicated parameter name '${formal.name}'."); | 567 "Duplicated parameter name '${formal.name}'."); |
568 library.addCompileTimeError(seenNames[formal.name].charOffset, | 568 library.deprecated_addCompileTimeError( |
| 569 seenNames[formal.name].charOffset, |
569 "Other parameter named '${formal.name}'."); | 570 "Other parameter named '${formal.name}'."); |
570 } else { | 571 } else { |
571 seenNames[formal.name] = formal; | 572 seenNames[formal.name] = formal; |
572 } | 573 } |
573 } | 574 } |
574 } | 575 } |
575 } | 576 } |
576 push(beginToken.charOffset); | 577 push(beginToken.charOffset); |
577 push(formals ?? NullValue.FormalParameters); | 578 push(formals ?? NullValue.FormalParameters); |
578 } | 579 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 name = pop(); | 662 name = pop(); |
662 if (type is FunctionTypeBuilder) { | 663 if (type is FunctionTypeBuilder) { |
663 // TODO(ahe): We need to start a nested declaration when parsing the | 664 // TODO(ahe): We need to start a nested declaration when parsing the |
664 // formals and return type so we can correctly bind | 665 // formals and return type so we can correctly bind |
665 // `type.typeVariables`. A typedef can have type variables, and a new | 666 // `type.typeVariables`. A typedef can have type variables, and a new |
666 // function type can also have type variables (representing the type of | 667 // function type can also have type variables (representing the type of |
667 // a generic function). | 668 // a generic function). |
668 functionType = type; | 669 functionType = type; |
669 } else { | 670 } else { |
670 // TODO(ahe): Improve this error message. | 671 // TODO(ahe): Improve this error message. |
671 library.addCompileTimeError( | 672 library.deprecated_addCompileTimeError( |
672 equals.charOffset, "Can't create typedef from non-function type."); | 673 equals.charOffset, "Can't create typedef from non-function type."); |
673 } | 674 } |
674 } | 675 } |
675 List<MetadataBuilder> metadata = pop(); | 676 List<MetadataBuilder> metadata = pop(); |
676 library.addFunctionTypeAlias( | 677 library.addFunctionTypeAlias( |
677 metadata, name, typeVariables, functionType, charOffset); | 678 metadata, name, typeVariables, functionType, charOffset); |
678 checkEmpty(typedefKeyword.charOffset); | 679 checkEmpty(typedefKeyword.charOffset); |
679 silenceParserErrors = true; | 680 silenceParserErrors = true; |
680 } | 681 } |
681 | 682 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 nativeMethodName = | 860 nativeMethodName = |
860 stringExpectedAfterNative ? extractNativeMethodName(token) : ""; | 861 stringExpectedAfterNative ? extractNativeMethodName(token) : ""; |
861 return recover; | 862 return recover; |
862 } | 863 } |
863 } | 864 } |
864 return super.handleUnrecoverableError(token, message); | 865 return super.handleUnrecoverableError(token, message); |
865 } | 866 } |
866 | 867 |
867 @override | 868 @override |
868 void addCompileTimeErrorFromMessage(FastaMessage message) { | 869 void addCompileTimeErrorFromMessage(FastaMessage message) { |
869 library.addCompileTimeError(message.charOffset, message.message, | 870 library.deprecated_addCompileTimeError(message.charOffset, message.message, |
870 fileUri: message.uri); | 871 fileUri: message.uri); |
871 } | 872 } |
872 | 873 |
873 @override | 874 @override |
874 Link<Token> handleMemberName(Link<Token> identifiers) { | 875 Link<Token> handleMemberName(Link<Token> identifiers) { |
875 if (!enableNative || identifiers.isEmpty) return identifiers; | 876 if (!enableNative || identifiers.isEmpty) return identifiers; |
876 return removeNativeClause(identifiers, stringExpectedAfterNative); | 877 return removeNativeClause(identifiers, stringExpectedAfterNative); |
877 } | 878 } |
878 | 879 |
879 @override | 880 @override |
880 void debugEvent(String name) { | 881 void debugEvent(String name) { |
881 // printEvent(name); | 882 // printEvent(name); |
882 } | 883 } |
883 } | 884 } |
OLD | NEW |