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.body_builder; | 5 library fasta.body_builder; |
6 | 6 |
| 7 import '../fasta_codes.dart' |
| 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
| 9 |
7 import '../parser/parser.dart' show FormalParameterType, optional; | 10 import '../parser/parser.dart' show FormalParameterType, optional; |
8 | 11 |
9 import '../parser/error_kind.dart' show ErrorKind; | |
10 | |
11 import '../parser/identifier_context.dart' show IdentifierContext; | 12 import '../parser/identifier_context.dart' show IdentifierContext; |
12 | 13 |
13 import 'package:kernel/ast.dart'; | 14 import 'package:kernel/ast.dart'; |
14 | 15 |
15 import 'package:kernel/clone.dart' show CloneVisitor; | 16 import 'package:kernel/clone.dart' show CloneVisitor; |
16 | 17 |
17 import 'package:kernel/transformations/flags.dart' show TransformerFlag; | 18 import 'package:kernel/transformations/flags.dart' show TransformerFlag; |
18 | 19 |
19 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 20 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
20 | 21 |
(...skipping 2292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2313 } | 2314 } |
2314 | 2315 |
2315 @override | 2316 @override |
2316 void handleModifiers(int count) { | 2317 void handleModifiers(int count) { |
2317 debugEvent("Modifiers"); | 2318 debugEvent("Modifiers"); |
2318 // TODO(ahe): Copied from outline_builder.dart. | 2319 // TODO(ahe): Copied from outline_builder.dart. |
2319 push(popList(count) ?? NullValue.Modifiers); | 2320 push(popList(count) ?? NullValue.Modifiers); |
2320 } | 2321 } |
2321 | 2322 |
2322 @override | 2323 @override |
2323 void handleRecoverableError(Token token, ErrorKind kind, Map arguments) { | 2324 void handleRecoverableError(Token token, FastaMessage message) { |
2324 bool silent = hasParserError; | 2325 bool silent = hasParserError; |
2325 super.handleRecoverableError(token, kind, arguments); | 2326 super.handleRecoverableError(token, message); |
2326 addCompileTimeError(recoverableErrors.last.beginOffset, | 2327 addCompileTimeError(message.charOffset, message.message, silent: silent); |
2327 '${recoverableErrors.last.kind} $arguments', | |
2328 silent: silent); | |
2329 } | 2328 } |
2330 | 2329 |
2331 @override | 2330 @override |
2332 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { | 2331 Token handleUnrecoverableError(Token token, FastaMessage message) { |
2333 if (isDartLibrary && kind == ErrorKind.ExpectedFunctionBody) { | 2332 if (isDartLibrary && message.code == codeExpectedFunctionBody) { |
2334 Token recover = skipNativeClause(token); | 2333 Token recover = skipNativeClause(token); |
2335 if (recover != null) return recover; | 2334 if (recover != null) return recover; |
2336 } else if (kind == ErrorKind.UnexpectedToken) { | 2335 } else if (message.code == codeExpectedButGot) { |
2337 String expected = arguments["expected"]; | 2336 String expected = message.arguments["string"]; |
2338 const List<String> trailing = const <String>[")", "}", ";", ","]; | 2337 const List<String> trailing = const <String>[")", "}", ";", ","]; |
2339 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { | 2338 if (trailing.contains(token.stringValue) && trailing.contains(expected)) { |
2340 arguments.putIfAbsent("actual", () => token.lexeme); | 2339 handleRecoverableError(token, message); |
2341 handleRecoverableError(token, ErrorKind.ExpectedButGot, arguments); | |
2342 return newSyntheticToken(token); | 2340 return newSyntheticToken(token); |
2343 } | 2341 } |
2344 } | 2342 } |
2345 return super.handleUnrecoverableError(token, kind, arguments); | 2343 return super.handleUnrecoverableError(token, message); |
2346 } | 2344 } |
2347 | 2345 |
2348 @override | 2346 @override |
2349 Expression buildCompileTimeError(error, [int charOffset = -1]) { | 2347 Expression buildCompileTimeError(error, [int charOffset = -1]) { |
2350 addCompileTimeError(charOffset, error); | 2348 addCompileTimeError(charOffset, error); |
2351 String message = formatUnexpected(uri, charOffset, error); | 2349 String message = formatUnexpected(uri, charOffset, error); |
2352 Builder constructor = library.loader.getCompileTimeError(); | 2350 Builder constructor = library.loader.getCompileTimeError(); |
2353 return new Throw(buildStaticInvocation(constructor.target, | 2351 return new Throw(buildStaticInvocation(constructor.target, |
2354 new Arguments(<Expression>[new StringLiteral(message)]), | 2352 new Arguments(<Expression>[new StringLiteral(message)]), |
2355 isConst: false)); // TODO(ahe): Make this const. | 2353 isConst: false)); // TODO(ahe): Make this const. |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2879 } else if (node is PrefixBuilder) { | 2877 } else if (node is PrefixBuilder) { |
2880 return node.name; | 2878 return node.name; |
2881 } else if (node is ThisAccessor) { | 2879 } else if (node is ThisAccessor) { |
2882 return node.isSuper ? "super" : "this"; | 2880 return node.isSuper ? "super" : "this"; |
2883 } else if (node is BuilderAccessor) { | 2881 } else if (node is BuilderAccessor) { |
2884 return node.plainNameForRead; | 2882 return node.plainNameForRead; |
2885 } else { | 2883 } else { |
2886 return internalError("Unhandled: ${node.runtimeType}"); | 2884 return internalError("Unhandled: ${node.runtimeType}"); |
2887 } | 2885 } |
2888 } | 2886 } |
OLD | NEW |