| 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/dart_vm_native.dart' show removeNativeClause; | 31 import '../parser/dart_vm_native.dart' show removeNativeClause; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } | 194 } |
| 195 | 195 |
| 196 @override | 196 @override |
| 197 void endLiteralString(int interpolationCount, Token endToken) { | 197 void endLiteralString(int interpolationCount, Token endToken) { |
| 198 debugEvent("endLiteralString"); | 198 debugEvent("endLiteralString"); |
| 199 if (interpolationCount == 0) { | 199 if (interpolationCount == 0) { |
| 200 Token token = pop(); | 200 Token token = pop(); |
| 201 push(unescapeString(token.lexeme)); | 201 push(unescapeString(token.lexeme)); |
| 202 push(token.charOffset); | 202 push(token.charOffset); |
| 203 } else { | 203 } else { |
| 204 internalError("String interpolation not implemented."); | 204 deprecated_internalProblem("String interpolation not implemented."); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 @override | 208 @override |
| 209 void handleStringJuxtaposition(int literalCount) { | 209 void handleStringJuxtaposition(int literalCount) { |
| 210 debugEvent("StringJuxtaposition"); | 210 debugEvent("StringJuxtaposition"); |
| 211 List<String> list = | 211 List<String> list = |
| 212 new List<String>.filled(literalCount, null, growable: false); | 212 new List<String>.filled(literalCount, null, growable: false); |
| 213 int charOffset = -1; | 213 int charOffset = -1; |
| 214 for (int i = literalCount - 1; i >= 0; i--) { | 214 for (int i = literalCount - 1; i >= 0; i--) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 List<MetadataBuilder> metadata = pop(); | 283 List<MetadataBuilder> metadata = pop(); |
| 284 library.addClass(metadata, modifiers, name, typeVariables, supertype, | 284 library.addClass(metadata, modifiers, name, typeVariables, supertype, |
| 285 interfaces, charOffset); | 285 interfaces, charOffset); |
| 286 checkEmpty(beginToken.charOffset); | 286 checkEmpty(beginToken.charOffset); |
| 287 } | 287 } |
| 288 | 288 |
| 289 ProcedureKind computeProcedureKind(Token token) { | 289 ProcedureKind computeProcedureKind(Token token) { |
| 290 if (token == null) return ProcedureKind.Method; | 290 if (token == null) return ProcedureKind.Method; |
| 291 if (optional("get", token)) return ProcedureKind.Getter; | 291 if (optional("get", token)) return ProcedureKind.Getter; |
| 292 if (optional("set", token)) return ProcedureKind.Setter; | 292 if (optional("set", token)) return ProcedureKind.Setter; |
| 293 return internalError("Unhandled: ${token.lexeme}"); | 293 return deprecated_internalProblem("Unhandled: ${token.lexeme}"); |
| 294 } | 294 } |
| 295 | 295 |
| 296 @override | 296 @override |
| 297 void beginTopLevelMethod(Token token, Token name) { | 297 void beginTopLevelMethod(Token token, Token name) { |
| 298 library.beginNestedDeclaration(name.lexeme, hasMembers: false); | 298 library.beginNestedDeclaration(name.lexeme, hasMembers: false); |
| 299 } | 299 } |
| 300 | 300 |
| 301 @override | 301 @override |
| 302 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | 302 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { |
| 303 debugEvent("endTopLevelMethod"); | 303 debugEvent("endTopLevelMethod"); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 if (Operator.subtract == nameOrOperator && formals == null) { | 361 if (Operator.subtract == nameOrOperator && formals == null) { |
| 362 nameOrOperator = Operator.unaryMinus; | 362 nameOrOperator = Operator.unaryMinus; |
| 363 } | 363 } |
| 364 String name; | 364 String name; |
| 365 ProcedureKind kind; | 365 ProcedureKind kind; |
| 366 if (nameOrOperator is Operator) { | 366 if (nameOrOperator is Operator) { |
| 367 name = operatorToString(nameOrOperator); | 367 name = operatorToString(nameOrOperator); |
| 368 kind = ProcedureKind.Operator; | 368 kind = ProcedureKind.Operator; |
| 369 int requiredArgumentCount = operatorRequiredArgumentCount(nameOrOperator); | 369 int requiredArgumentCount = operatorRequiredArgumentCount(nameOrOperator); |
| 370 if ((formals?.length ?? 0) != requiredArgumentCount) { | 370 if ((formals?.length ?? 0) != requiredArgumentCount) { |
| 371 library.addCompileTimeError( | 371 library.deprecated_addCompileTimeError( |
| 372 charOffset, | 372 charOffset, |
| 373 "Operator '$name' must have exactly $requiredArgumentCount " | 373 "Operator '$name' must have exactly $requiredArgumentCount " |
| 374 "parameters."); | 374 "parameters."); |
| 375 } else { | 375 } else { |
| 376 if (formals != null) { | 376 if (formals != null) { |
| 377 for (FormalParameterBuilder formal in formals) { | 377 for (FormalParameterBuilder formal in formals) { |
| 378 if (!formal.isRequired) { | 378 if (!formal.isRequired) { |
| 379 library.addCompileTimeError(formal.charOffset, | 379 library.deprecated_addCompileTimeError(formal.charOffset, |
| 380 "An operator can't have optional parameters."); | 380 "An operator can't have optional parameters."); |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 } else { | 385 } else { |
| 386 name = nameOrOperator; | 386 name = nameOrOperator; |
| 387 kind = computeProcedureKind(getOrSet); | 387 kind = computeProcedureKind(getOrSet); |
| 388 } | 388 } |
| 389 TypeBuilder returnType = pop(); | 389 TypeBuilder returnType = pop(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 formals = new List<FormalParameterBuilder>.filled(count + 1, null, | 540 formals = new List<FormalParameterBuilder>.filled(count + 1, null, |
| 541 growable: true); | 541 growable: true); |
| 542 formals[count] = last; | 542 formals[count] = last; |
| 543 } | 543 } |
| 544 popList(count, formals); | 544 popList(count, formals); |
| 545 } | 545 } |
| 546 if (formals != null) { | 546 if (formals != null) { |
| 547 if (formals.length == 2) { | 547 if (formals.length == 2) { |
| 548 // The name may be null for generalized function types. | 548 // The name may be null for generalized function types. |
| 549 if (formals[0].name != null && formals[0].name == formals[1].name) { | 549 if (formals[0].name != null && formals[0].name == formals[1].name) { |
| 550 library.addCompileTimeError(formals[1].charOffset, | 550 library.deprecated_addCompileTimeError(formals[1].charOffset, |
| 551 "Duplicated parameter name '${formals[1].name}'."); | 551 "Duplicated parameter name '${formals[1].name}'."); |
| 552 library.addCompileTimeError(formals[0].charOffset, | 552 library.deprecated_addCompileTimeError(formals[0].charOffset, |
| 553 "Other parameter named '${formals[1].name}'."); | 553 "Other parameter named '${formals[1].name}'."); |
| 554 } | 554 } |
| 555 } else if (formals.length > 2) { | 555 } else if (formals.length > 2) { |
| 556 Map<String, FormalParameterBuilder> seenNames = | 556 Map<String, FormalParameterBuilder> seenNames = |
| 557 <String, FormalParameterBuilder>{}; | 557 <String, FormalParameterBuilder>{}; |
| 558 for (FormalParameterBuilder formal in formals) { | 558 for (FormalParameterBuilder formal in formals) { |
| 559 if (formal.name == null) continue; | 559 if (formal.name == null) continue; |
| 560 if (seenNames.containsKey(formal.name)) { | 560 if (seenNames.containsKey(formal.name)) { |
| 561 library.addCompileTimeError(formal.charOffset, | 561 library.deprecated_addCompileTimeError(formal.charOffset, |
| 562 "Duplicated parameter name '${formal.name}'."); | 562 "Duplicated parameter name '${formal.name}'."); |
| 563 library.addCompileTimeError(seenNames[formal.name].charOffset, | 563 library.deprecated_addCompileTimeError( |
| 564 seenNames[formal.name].charOffset, |
| 564 "Other parameter named '${formal.name}'."); | 565 "Other parameter named '${formal.name}'."); |
| 565 } else { | 566 } else { |
| 566 seenNames[formal.name] = formal; | 567 seenNames[formal.name] = formal; |
| 567 } | 568 } |
| 568 } | 569 } |
| 569 } | 570 } |
| 570 } | 571 } |
| 571 push(beginToken.charOffset); | 572 push(beginToken.charOffset); |
| 572 push(formals ?? NullValue.FormalParameters); | 573 push(formals ?? NullValue.FormalParameters); |
| 573 } | 574 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 name = pop(); | 657 name = pop(); |
| 657 if (type is FunctionTypeBuilder) { | 658 if (type is FunctionTypeBuilder) { |
| 658 // TODO(ahe): We need to start a nested declaration when parsing the | 659 // TODO(ahe): We need to start a nested declaration when parsing the |
| 659 // formals and return type so we can correctly bind | 660 // formals and return type so we can correctly bind |
| 660 // `type.typeVariables`. A typedef can have type variables, and a new | 661 // `type.typeVariables`. A typedef can have type variables, and a new |
| 661 // function type can also have type variables (representing the type of | 662 // function type can also have type variables (representing the type of |
| 662 // a generic function). | 663 // a generic function). |
| 663 functionType = type; | 664 functionType = type; |
| 664 } else { | 665 } else { |
| 665 // TODO(ahe): Improve this error message. | 666 // TODO(ahe): Improve this error message. |
| 666 library.addCompileTimeError( | 667 library.deprecated_addCompileTimeError( |
| 667 equals.charOffset, "Can't create typedef from non-function type."); | 668 equals.charOffset, "Can't create typedef from non-function type."); |
| 668 } | 669 } |
| 669 } | 670 } |
| 670 List<MetadataBuilder> metadata = pop(); | 671 List<MetadataBuilder> metadata = pop(); |
| 671 library.addFunctionTypeAlias( | 672 library.addFunctionTypeAlias( |
| 672 metadata, name, typeVariables, functionType, charOffset); | 673 metadata, name, typeVariables, functionType, charOffset); |
| 673 checkEmpty(typedefKeyword.charOffset); | 674 checkEmpty(typedefKeyword.charOffset); |
| 674 silenceParserErrors = true; | 675 silenceParserErrors = true; |
| 675 } | 676 } |
| 676 | 677 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 if (recover != null) { | 855 if (recover != null) { |
| 855 nativeMethodName = target.extractNativeMethodName(token); | 856 nativeMethodName = target.extractNativeMethodName(token); |
| 856 return recover; | 857 return recover; |
| 857 } | 858 } |
| 858 } | 859 } |
| 859 return super.handleUnrecoverableError(token, message); | 860 return super.handleUnrecoverableError(token, message); |
| 860 } | 861 } |
| 861 | 862 |
| 862 @override | 863 @override |
| 863 void addCompileTimeErrorFromMessage(FastaMessage message) { | 864 void addCompileTimeErrorFromMessage(FastaMessage message) { |
| 864 library.addCompileTimeError(message.charOffset, message.message, | 865 library.deprecated_addCompileTimeError(message.charOffset, message.message, |
| 865 fileUri: message.uri); | 866 fileUri: message.uri); |
| 866 } | 867 } |
| 867 | 868 |
| 868 @override | 869 @override |
| 869 Link<Token> handleMemberName(Link<Token> identifiers) { | 870 Link<Token> handleMemberName(Link<Token> identifiers) { |
| 870 if (!enableNative || identifiers.isEmpty) return identifiers; | 871 if (!enableNative || identifiers.isEmpty) return identifiers; |
| 871 return removeNativeClause(identifiers); | 872 return removeNativeClause(identifiers); |
| 872 } | 873 } |
| 873 | 874 |
| 874 @override | 875 @override |
| 875 void debugEvent(String name) { | 876 void debugEvent(String name) { |
| 876 // printEvent(name); | 877 // printEvent(name); |
| 877 } | 878 } |
| 878 } | 879 } |
| OLD | NEW |