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

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: Update 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ExecutableDefinition emit(tree.ExecutableDefinition definition) { 73 ExecutableDefinition emit(tree.ExecutableDefinition definition) {
74 if (definition is tree.FieldDefinition) { 74 if (definition is tree.FieldDefinition) {
75 return emitField(definition); 75 return emitField(definition);
76 } 76 }
77 assert(definition is tree.FunctionDefinition); 77 assert(definition is tree.FunctionDefinition);
78 return emitFunction(definition); 78 return emitFunction(definition);
79 } 79 }
80 80
81 FieldDefinition emitField(tree.FieldDefinition definition) { 81 FieldDefinition emitField(tree.FieldDefinition definition) {
82 currentElement = definition.element; 82 currentElement = definition.element;
83 visitStatement(definition.body); 83 Expression initializer;
84 List<Statement> bodyParts; 84 if (definition.hasInitializer) {
85 for (tree.Variable variable in variableNames.keys) { 85 visitStatement(definition.body);
86 if (!declaredVariables.contains(variable)) { 86 List<Statement> bodyParts;
87 addDeclaration(variable); 87 for (tree.Variable variable in variableNames.keys) {
88 if (!declaredVariables.contains(variable)) {
89 addDeclaration(variable);
90 }
88 } 91 }
89 } 92 if (variables.length > 0) {
90 if (variables.length > 0) { 93 bodyParts = new List<Statement>();
91 bodyParts = new List<Statement>(); 94 bodyParts.add(new VariableDeclarations(variables));
92 bodyParts.add(new VariableDeclarations(variables)); 95 bodyParts.addAll(statementBuffer);
93 bodyParts.addAll(statementBuffer); 96 } else {
94 } else { 97 bodyParts = statementBuffer;
95 bodyParts = statementBuffer; 98 }
99 initializer = ensureExpression(bodyParts);
96 } 100 }
97 101
98 return new FieldDefinition(definition.element, ensureExpression(bodyParts)); 102 return new FieldDefinition(definition.element, initializer);
99 } 103 }
100 104
101 /// Returns an expression that will evaluate all of [bodyParts]. 105 /// Returns an expression that will evaluate all of [bodyParts].
102 /// If [bodyParts] is a single [Return] return its value. 106 /// If [bodyParts] is a single [Return] return its value.
103 /// Otherwise wrap the body-parts in an immediately invoked closure. 107 /// Otherwise wrap the body-parts in an immediately invoked closure.
104 Expression ensureExpression(List<Statement> bodyParts) { 108 Expression ensureExpression(List<Statement> bodyParts) {
105 if (bodyParts.length == 1) { 109 if (bodyParts.length == 1) {
106 Statement onlyStatement = bodyParts.single; 110 Statement onlyStatement = bodyParts.single;
107 if (onlyStatement is Return) { 111 if (onlyStatement is Return) {
108 return onlyStatement.expression; 112 return onlyStatement.expression;
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null); 961 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null);
958 962
959 ExecutableElement get executableContext => enclosingElement; 963 ExecutableElement get executableContext => enclosingElement;
960 964
961 ExecutableElement get memberContext => executableContext.memberContext; 965 ExecutableElement get memberContext => executableContext.memberContext;
962 966
963 bool get isLocal => true; 967 bool get isLocal => true;
964 968
965 LibraryElement get implementationLibrary => enclosingElement.library; 969 LibraryElement get implementationLibrary => enclosingElement.library;
966 } 970 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698