Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart

Issue 762213002: Support top-level field declaration and assignment in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 backend_ast_emitter; 5 library backend_ast_emitter;
6 6
7 import '../tree_ir/tree_ir_nodes.dart' as tree; 7 import '../tree_ir/tree_ir_nodes.dart' as tree;
8 import 'backend_ast_nodes.dart'; 8 import 'backend_ast_nodes.dart';
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (definition is tree.FieldDefinition) { 193 if (definition is tree.FieldDefinition) {
194 return emitField(definition, context); 194 return emitField(definition, context);
195 } 195 }
196 assert(definition is tree.FunctionDefinition); 196 assert(definition is tree.FunctionDefinition);
197 return emitFunction(definition, context); 197 return emitFunction(definition, context);
198 } 198 }
199 199
200 FieldDefinition emitField(tree.FieldDefinition definition, 200 FieldDefinition emitField(tree.FieldDefinition definition,
201 BuilderContext<Statement> context) { 201 BuilderContext<Statement> context) {
202 context.currentElement = definition.element; 202 context.currentElement = definition.element;
203 visitStatement(definition.body, context); 203 Expression initializer;
204 List<Statement> bodyParts; 204 if (definition.hasInitializer) {
205 for (tree.Variable variable in context.variableNames.keys) { 205 visitStatement(definition.body, context);
206 if (!context.declaredVariables.contains(variable)) { 206 List<Statement> bodyParts;
207 context.addDeclaration(variable); 207 for (tree.Variable variable in context.variableNames.keys) {
208 if (!context.declaredVariables.contains(variable)) {
209 context.addDeclaration(variable);
210 }
208 } 211 }
209 } 212 if (context.variables.length > 0) {
210 if (context.variables.length > 0) { 213 bodyParts = new List<Statement>();
211 bodyParts = new List<Statement>(); 214 bodyParts.add(new VariableDeclarations(context.variables));
212 bodyParts.add(new VariableDeclarations(context.variables)); 215 bodyParts.addAll(context.statements);
213 bodyParts.addAll(context.statements); 216 } else {
214 } else { 217 bodyParts = context.statements;
215 bodyParts = context.statements; 218 }
219 initializer = ensureExpression(bodyParts);
216 } 220 }
217 221
218 return new FieldDefinition(definition.element, ensureExpression(bodyParts)); 222 return new FieldDefinition(definition.element, initializer);
219 } 223 }
220 224
221 /// Returns an expression that will evaluate all of [bodyParts]. 225 /// Returns an expression that will evaluate all of [bodyParts].
222 /// If [bodyParts] is a single [Return] return its value. 226 /// If [bodyParts] is a single [Return] return its value.
223 /// Otherwise wrap the body-parts in an immediately invoked closure. 227 /// Otherwise wrap the body-parts in an immediately invoked closure.
224 Expression ensureExpression(List<Statement> bodyParts) { 228 Expression ensureExpression(List<Statement> bodyParts) {
225 if (bodyParts.length == 1) { 229 if (bodyParts.length == 1) {
226 Statement onlyStatement = bodyParts.single; 230 Statement onlyStatement = bodyParts.single;
227 if (onlyStatement is Return) { 231 if (onlyStatement is Return) {
228 return onlyStatement.expression; 232 return onlyStatement.expression;
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null); 1078 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null);
1075 1079
1076 ExecutableElement get executableContext => enclosingElement; 1080 ExecutableElement get executableContext => enclosingElement;
1077 1081
1078 ExecutableElement get memberContext => executableContext.memberContext; 1082 ExecutableElement get memberContext => executableContext.memberContext;
1079 1083
1080 bool get isLocal => true; 1084 bool get isLocal => true;
1081 1085
1082 LibraryElement get implementationLibrary => enclosingElement.library; 1086 LibraryElement get implementationLibrary => enclosingElement.library;
1083 } 1087 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/shrinking_reductions.dart ('k') | pkg/compiler/lib/src/tree_ir/optimization/optimization.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698