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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 759193005: Add support for fields to the new dart backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.ir_builder; 5 library dart2js.ir_builder;
6 6
7 import '../constants/expressions.dart'; 7 import '../constants/expressions.dart';
8 import '../constants/values.dart' show PrimitiveConstantValue; 8 import '../constants/values.dart' show PrimitiveConstantValue;
9 import '../dart_backend/dart_backend.dart' show DartBackend; 9 import '../dart_backend/dart_backend.dart' show DartBackend;
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 /// A stack of collectors for breaks. 184 /// A stack of collectors for breaks.
185 final List<JumpCollector> breakCollectors = <JumpCollector>[]; 185 final List<JumpCollector> breakCollectors = <JumpCollector>[];
186 186
187 /// A stack of collectors for continues. 187 /// A stack of collectors for continues.
188 final List<JumpCollector> continueCollectors = <JumpCollector>[]; 188 final List<JumpCollector> continueCollectors = <JumpCollector>[];
189 189
190 final List<ConstDeclaration> localConstants = <ConstDeclaration>[]; 190 final List<ConstDeclaration> localConstants = <ConstDeclaration>[];
191 191
192 final Iterable<Entity> closureLocals; 192 final Iterable<Entity> closureLocals;
193 193
194 final FunctionElement currentFunction; 194 final ExecutableElement currentElement;
195 195
196 final ir.Continuation returnContinuation = new ir.Continuation.retrn(); 196 final ir.Continuation returnContinuation = new ir.Continuation.retrn();
197 197
198 IrBuilderSharedState(this.constantSystem, 198 IrBuilderSharedState(this.constantSystem,
199 this.currentFunction, 199 this.currentElement,
200 this.closureLocals); 200 this.closureLocals);
201 } 201 }
202 202
203 /// A factory for building the cps IR. 203 /// A factory for building the cps IR.
204 class IrBuilder { 204 class IrBuilder {
205 // TODO(johnniwinther): Make these field final and remove the default values 205 // TODO(johnniwinther): Make these field final and remove the default values
206 // when [IrBuilder] is a property of [IrBuilderVisitor] instead of a mixin. 206 // when [IrBuilder] is a property of [IrBuilderVisitor] instead of a mixin.
207 207
208 final List<ir.Parameter> _parameters = <ir.Parameter>[]; 208 final List<ir.Parameter> _parameters = <ir.Parameter>[];
209 209
(...skipping 23 matching lines...) Expand all
233 // 233 //
234 // We do not pass contexts as arguments or return them. Rather we use the 234 // We do not pass contexts as arguments or return them. Rather we use the
235 // current context (root, current) as the visitor state and mutate current. 235 // current context (root, current) as the visitor state and mutate current.
236 // Visiting a statement returns null; visiting an expression returns the 236 // Visiting a statement returns null; visiting an expression returns the
237 // primitive denoting its value. 237 // primitive denoting its value.
238 238
239 ir.Expression _root = null; 239 ir.Expression _root = null;
240 ir.Expression _current = null; 240 ir.Expression _current = null;
241 241
242 IrBuilder(ConstantSystem constantSystem, 242 IrBuilder(ConstantSystem constantSystem,
243 FunctionElement currentFunction, 243 ExecutableElement currentElement,
244 Iterable<Entity> closureLocals) 244 Iterable<Entity> closureLocals)
245 : this.state = new IrBuilderSharedState( 245 : this.state = new IrBuilderSharedState(
246 constantSystem, currentFunction, closureLocals), 246 constantSystem, currentElement, closureLocals),
247 this.environment = new Environment.empty(); 247 this.environment = new Environment.empty();
248 248
249 /// Construct a delimited visitor for visiting a subtree. 249 /// Construct a delimited visitor for visiting a subtree.
250 /// 250 ///
251 /// The delimited visitor has its own compile-time environment mapping 251 /// The delimited visitor has its own compile-time environment mapping
252 /// local variables to their values, which is initially a copy of the parent 252 /// local variables to their values, which is initially a copy of the parent
253 /// environment. It has its own context for building an IR expression, so 253 /// environment. It has its own context for building an IR expression, so
254 /// the built expression is not plugged into the parent's context. 254 /// the built expression is not plugged into the parent's context.
255 IrBuilder.delimited(IrBuilder parent) 255 IrBuilder.delimited(IrBuilder parent)
256 : this.state = parent.state, 256 : this.state = parent.state,
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 * statement on each branch. This includes functions with an empty body, 526 * statement on each branch. This includes functions with an empty body,
527 * such as `foo(){ }`. 527 * such as `foo(){ }`.
528 */ 528 */
529 void _ensureReturn() { 529 void _ensureReturn() {
530 if (!isOpen) return; 530 if (!isOpen) return;
531 ir.Constant constant = buildNullLiteral(); 531 ir.Constant constant = buildNullLiteral();
532 add(new ir.InvokeContinuation(state.returnContinuation, [constant])); 532 add(new ir.InvokeContinuation(state.returnContinuation, [constant]));
533 _current = null; 533 _current = null;
534 } 534 }
535 535
536 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as
537 /// the body.
538 ir.FieldDefinition makeFieldDefinition() {
539 return new ir.FieldDefinition(state.currentElement,
540 state.returnContinuation,
541 _root);
542 }
543
536 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body. 544 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body.
537 /// 545 ///
538 /// Parameters must be created before the construction of the body using 546 /// Parameters must be created before the construction of the body using
539 /// [createParameter]. 547 /// [createParameter].
540 ir.FunctionDefinition buildFunctionDefinition( 548 ir.FunctionDefinition buildFunctionDefinition(
541 FunctionElement element,
542 List<ConstantExpression> defaults) { 549 List<ConstantExpression> defaults) {
550 FunctionElement element = state.currentElement;
543 if (element.isAbstract || element.isExternal) { 551 if (element.isAbstract || element.isExternal) {
544 assert(invariant(element, _root == null, 552 assert(invariant(element, _root == null,
545 message: "Non-empty body for abstract method $element: $_root")); 553 message: "Non-empty body for abstract method $element: $_root"));
546 assert(invariant(element, state.localConstants.isEmpty, 554 assert(invariant(element, state.localConstants.isEmpty,
547 message: "Local constants for abstract method $element: " 555 message: "Local constants for abstract method $element: "
548 "${state.localConstants}")); 556 "${state.localConstants}"));
549 return new ir.FunctionDefinition.abstract( 557 return new ir.FunctionDefinition.abstract(
550 element, _parameters, defaults); 558 element, _parameters, defaults);
551 } else { 559 } else {
552 _ensureReturn(); 560 _ensureReturn();
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 index = 0; 1462 index = 0;
1455 for (int i = 0; i < environment.length; ++i) { 1463 for (int i = 0; i < environment.length; ++i) {
1456 if (common[i] == null) { 1464 if (common[i] == null) {
1457 environment.index2value[i] = parameters[index++]; 1465 environment.index2value[i] = parameters[index++];
1458 } 1466 }
1459 } 1467 }
1460 1468
1461 return join; 1469 return join;
1462 } 1470 }
1463 } 1471 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/constant_propagation.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698