Chromium Code Reviews| 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' | 7 import '../fasta_codes.dart' |
| 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
| 9 | 9 |
| 10 import '../parser/parser.dart' show FormalParameterType, optional; | 10 import '../parser/parser.dart' show FormalParameterType, optional; |
| 11 | 11 |
| 12 import '../parser/identifier_context.dart' show IdentifierContext; | 12 import '../parser/identifier_context.dart' show IdentifierContext; |
| 13 | 13 |
| 14 import 'package:front_end/src/fasta/builder/ast_factory.dart' show AstFactory; | 14 import 'package:front_end/src/fasta/builder/ast_factory.dart' show AstFactory; |
| 15 | 15 |
| 16 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | 16 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
| 17 show KernelVariableDeclaration; | 17 show KernelField, KernelVariableDeclaration; |
| 18 | 18 |
| 19 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' | 19 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' |
| 20 show TypeInferrer; | 20 show FieldNode, TypeInferrer; |
| 21 | 21 |
| 22 import 'package:kernel/ast.dart'; | 22 import 'package:kernel/ast.dart'; |
| 23 | 23 |
| 24 import 'package:kernel/clone.dart' show CloneVisitor; | 24 import 'package:kernel/clone.dart' show CloneVisitor; |
| 25 | 25 |
| 26 import 'package:kernel/transformations/flags.dart' show TransformerFlag; | 26 import 'package:kernel/transformations/flags.dart' show TransformerFlag; |
| 27 | 27 |
| 28 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 28 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
| 29 | 29 |
| 30 import 'package:kernel/core_types.dart' show CoreTypes; | 30 import 'package:kernel/core_types.dart' show CoreTypes; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 final Map<String, FieldInitializer> fieldInitializers = | 80 final Map<String, FieldInitializer> fieldInitializers = |
| 81 <String, FieldInitializer>{}; | 81 <String, FieldInitializer>{}; |
| 82 | 82 |
| 83 final Scope enclosingScope; | 83 final Scope enclosingScope; |
| 84 | 84 |
| 85 final bool isDartLibrary; | 85 final bool isDartLibrary; |
| 86 | 86 |
| 87 @override | 87 @override |
| 88 final Uri uri; | 88 final Uri uri; |
| 89 | 89 |
| 90 final TypeInferrer<Statement, Expression, KernelVariableDeclaration, Field> | 90 final TypeInferrer<Statement, Expression, KernelVariableDeclaration, |
| 91 _typeInferrer; | 91 KernelField> _typeInferrer; |
| 92 | 92 |
| 93 final AstFactory astFactory; | 93 final AstFactory astFactory; |
| 94 | 94 |
| 95 /// If not `null`, dependencies on fields are accumulated into this list. | |
|
karlklose
2017/04/21 11:11:01
Maybe add a short comment on when this is `null`.
Paul Berry
2017/04/21 11:32:25
Done.
| |
| 96 final List<FieldNode<KernelField>> fieldDependencies; | |
| 97 | |
| 95 /// Only used when [member] is a constructor. It tracks if an implicit super | 98 /// Only used when [member] is a constructor. It tracks if an implicit super |
| 96 /// initializer is needed. | 99 /// initializer is needed. |
| 97 /// | 100 /// |
| 98 /// An implicit super initializer isn't needed | 101 /// An implicit super initializer isn't needed |
| 99 /// | 102 /// |
| 100 /// 1. if the current class is Object, | 103 /// 1. if the current class is Object, |
| 101 /// 2. if there is an explicit super initializer, | 104 /// 2. if there is an explicit super initializer, |
| 102 /// 3. if there is a redirecting (this) initializer, or | 105 /// 3. if there is a redirecting (this) initializer, or |
| 103 /// 4. if a compile-time error prevented us from generating code for an | 106 /// 4. if a compile-time error prevented us from generating code for an |
| 104 /// initializer. This avoids cascading errors. | 107 /// initializer. This avoids cascading errors. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 134 KernelLibraryBuilder library, | 137 KernelLibraryBuilder library, |
| 135 this.member, | 138 this.member, |
| 136 Scope scope, | 139 Scope scope, |
| 137 this.formalParameterScope, | 140 this.formalParameterScope, |
| 138 this.hierarchy, | 141 this.hierarchy, |
| 139 this.coreTypes, | 142 this.coreTypes, |
| 140 this.classBuilder, | 143 this.classBuilder, |
| 141 this.isInstanceMember, | 144 this.isInstanceMember, |
| 142 this.uri, | 145 this.uri, |
| 143 this._typeInferrer, | 146 this._typeInferrer, |
| 144 this.astFactory) | 147 this.astFactory, |
| 148 {this.fieldDependencies}) | |
| 145 : enclosingScope = scope, | 149 : enclosingScope = scope, |
| 146 library = library, | 150 library = library, |
| 147 isDartLibrary = library.uri.scheme == "dart", | 151 isDartLibrary = library.uri.scheme == "dart", |
| 148 needsImplicitSuperInitializer = | 152 needsImplicitSuperInitializer = |
| 149 coreTypes.objectClass != classBuilder?.cls, | 153 coreTypes.objectClass != classBuilder?.cls, |
| 150 super(scope); | 154 super(scope); |
| 151 | 155 |
| 152 bool get hasParserError => recoverableErrors.isNotEmpty; | 156 bool get hasParserError => recoverableErrors.isNotEmpty; |
| 153 | 157 |
| 154 bool get inConstructor { | 158 bool get inConstructor { |
| (...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 assert(isConst == constantExpressionRequired); | 1067 assert(isConst == constantExpressionRequired); |
| 1064 push(astFactory.variableDeclaration(identifier.name, | 1068 push(astFactory.variableDeclaration(identifier.name, |
| 1065 initializer: initializer, | 1069 initializer: initializer, |
| 1066 type: currentLocalVariableType, | 1070 type: currentLocalVariableType, |
| 1067 isFinal: isFinal, | 1071 isFinal: isFinal, |
| 1068 isConst: isConst, | 1072 isConst: isConst, |
| 1069 equalsCharOffset: equalsCharOffset)); | 1073 equalsCharOffset: equalsCharOffset)); |
| 1070 } | 1074 } |
| 1071 | 1075 |
| 1072 @override | 1076 @override |
| 1073 void endFieldInitializer(Token assignmentOperator) { | 1077 void endFieldInitializer(Token assignmentOperator, Token token) { |
| 1074 debugEvent("FieldInitializer"); | 1078 debugEvent("FieldInitializer"); |
| 1075 assert(assignmentOperator.stringValue == "="); | 1079 assert(assignmentOperator.stringValue == "="); |
| 1076 push(popForValue()); | 1080 push(popForValue()); |
| 1077 } | 1081 } |
| 1078 | 1082 |
| 1079 @override | 1083 @override |
| 1080 void handleNoFieldInitializer(Token token) { | 1084 void handleNoFieldInitializer(Token token) { |
| 1081 debugEvent("NoFieldInitializer"); | 1085 debugEvent("NoFieldInitializer"); |
| 1082 if (constantExpressionRequired) { | 1086 if (constantExpressionRequired) { |
| 1083 addCompileTimeError( | 1087 addCompileTimeError( |
| (...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2606 new VariableDeclaration.forValue(argument, isFinal: true), | 2610 new VariableDeclaration.forValue(argument, isFinal: true), |
| 2607 expression); | 2611 expression); |
| 2608 } | 2612 } |
| 2609 return expression; | 2613 return expression; |
| 2610 } | 2614 } |
| 2611 | 2615 |
| 2612 @override | 2616 @override |
| 2613 void debugEvent(String name) { | 2617 void debugEvent(String name) { |
| 2614 // printEvent(name); | 2618 // printEvent(name); |
| 2615 } | 2619 } |
| 2620 | |
| 2621 @override | |
| 2622 StaticGet makeStaticGet(Member readTarget, int offset) { | |
| 2623 // TODO(paulberry): only record the dependencies mandated by the top level | |
| 2624 // type inference spec. | |
| 2625 if (fieldDependencies != null && readTarget is KernelField) { | |
| 2626 var fieldNode = _typeInferrer.getFieldNodeForReadTarget(readTarget); | |
| 2627 if (fieldNode != null) { | |
| 2628 fieldDependencies.add(fieldNode); | |
| 2629 } | |
| 2630 } | |
| 2631 return astFactory.staticGet(readTarget, offset); | |
| 2632 } | |
| 2616 } | 2633 } |
| 2617 | 2634 |
| 2618 // TODO(ahe): Shouldn't need to be an expression. | 2635 // TODO(ahe): Shouldn't need to be an expression. |
| 2619 class Identifier extends InvalidExpression { | 2636 class Identifier extends InvalidExpression { |
| 2620 final String name; | 2637 final String name; |
| 2621 | 2638 |
| 2622 Identifier(this.name, int charOffset) { | 2639 Identifier(this.name, int charOffset) { |
| 2623 fileOffset = charOffset; | 2640 fileOffset = charOffset; |
| 2624 } | 2641 } |
| 2625 | 2642 |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3074 } else if (node is PrefixBuilder) { | 3091 } else if (node is PrefixBuilder) { |
| 3075 return node.name; | 3092 return node.name; |
| 3076 } else if (node is ThisAccessor) { | 3093 } else if (node is ThisAccessor) { |
| 3077 return node.isSuper ? "super" : "this"; | 3094 return node.isSuper ? "super" : "this"; |
| 3078 } else if (node is FastaAccessor) { | 3095 } else if (node is FastaAccessor) { |
| 3079 return node.plainNameForRead; | 3096 return node.plainNameForRead; |
| 3080 } else { | 3097 } else { |
| 3081 return internalError("Unhandled: ${node.runtimeType}"); | 3098 return internalError("Unhandled: ${node.runtimeType}"); |
| 3082 } | 3099 } |
| 3083 } | 3100 } |
| OLD | NEW |