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 '../parser/parser.dart' show FormalParameterType, optional; | 7 import '../parser/parser.dart' show FormalParameterType, optional; |
8 | 8 |
9 import '../parser/error_kind.dart' show ErrorKind; | 9 import '../parser/error_kind.dart' show ErrorKind; |
10 | 10 |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 @override | 971 @override |
972 void endFieldInitializer(Token assignmentOperator) { | 972 void endFieldInitializer(Token assignmentOperator) { |
973 debugEvent("FieldInitializer"); | 973 debugEvent("FieldInitializer"); |
974 assert(assignmentOperator.stringValue == "="); | 974 assert(assignmentOperator.stringValue == "="); |
975 push(popForValue()); | 975 push(popForValue()); |
976 } | 976 } |
977 | 977 |
978 @override | 978 @override |
979 void handleNoFieldInitializer(Token token) { | 979 void handleNoFieldInitializer(Token token) { |
980 debugEvent("NoFieldInitializer"); | 980 debugEvent("NoFieldInitializer"); |
981 push(NullValue.FieldInitializer); | 981 if (constantExpressionRequired) { |
| 982 addCompileTimeError( |
| 983 token.charOffset, "const field must have initializer."); |
| 984 // Creating a null value to prevent the Dart VM from crashing. |
| 985 push(new NullLiteral()..fileOffset = token.charOffset); |
| 986 } else { |
| 987 push(NullValue.FieldInitializer); |
| 988 } |
982 } | 989 } |
983 | 990 |
984 @override | 991 @override |
985 void endInitializedIdentifier(Token nameToken) { | 992 void endInitializedIdentifier(Token nameToken) { |
986 // TODO(ahe): Use [InitializedIdentifier] here? | 993 // TODO(ahe): Use [InitializedIdentifier] here? |
987 debugEvent("InitializedIdentifier"); | 994 debugEvent("InitializedIdentifier"); |
988 VariableDeclaration variable = pop(); | 995 VariableDeclaration variable = pop(); |
989 variable.fileOffset = nameToken.charOffset; | 996 variable.fileOffset = nameToken.charOffset; |
990 push(variable); | 997 push(variable); |
991 scope[variable.name] = new KernelVariableBuilder( | 998 scope[variable.name] = new KernelVariableBuilder( |
(...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2857 } else if (node is PrefixBuilder) { | 2864 } else if (node is PrefixBuilder) { |
2858 return node.name; | 2865 return node.name; |
2859 } else if (node is ThisAccessor) { | 2866 } else if (node is ThisAccessor) { |
2860 return node.isSuper ? "super" : "this"; | 2867 return node.isSuper ? "super" : "this"; |
2861 } else if (node is BuilderAccessor) { | 2868 } else if (node is BuilderAccessor) { |
2862 return node.plainNameForRead; | 2869 return node.plainNameForRead; |
2863 } else { | 2870 } else { |
2864 return internalError("Unhandled: ${node.runtimeType}"); | 2871 return internalError("Unhandled: ${node.runtimeType}"); |
2865 } | 2872 } |
2866 } | 2873 } |
OLD | NEW |