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

Side by Side Diff: pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart

Issue 787603003: Generative constructors in the new dart backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 tree_ir_builder; 5 library tree_ir_builder;
6 6
7 import '../dart2jslib.dart' as dart2js; 7 import '../dart2jslib.dart' as dart2js;
8 import '../dart_types.dart'; 8 import '../dart_types.dart';
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; 10 import '../cps_ir/cps_ir_nodes.dart' as cps_ir;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 compiler.currentElement, 112 compiler.currentElement,
113 "Reference to ${reference.definition} has no register"); 113 "Reference to ${reference.definition} has no register");
114 } 114 }
115 ++variable.readCount; 115 ++variable.readCount;
116 return variable; 116 return variable;
117 } 117 }
118 118
119 ExecutableDefinition build(cps_ir.ExecutableDefinition node) { 119 ExecutableDefinition build(cps_ir.ExecutableDefinition node) {
120 if (node is cps_ir.FieldDefinition) { 120 if (node is cps_ir.FieldDefinition) {
121 return buildField(node); 121 return buildField(node);
122 } else if (node is cps_ir.ConstructorDefinition) {
123 return buildConstructor(node);
122 } else if (node is cps_ir.FunctionDefinition) { 124 } else if (node is cps_ir.FunctionDefinition) {
123 return buildFunction(node); 125 return buildFunction(node);
124 } 126 }
125 assert(false); 127 assert(false);
128 return null;
126 } 129 }
127 130
128 FieldDefinition buildField(cps_ir.FieldDefinition node) { 131 FieldDefinition buildField(cps_ir.FieldDefinition node) {
129 Statement body; 132 Statement body;
130 if (node.hasInitializer) { 133 if (node.hasInitializer) {
131 currentElement = node.element; 134 currentElement = node.element;
132 returnContinuation = node.returnContinuation; 135 returnContinuation = node.body.returnContinuation;
133 136
134 phiTempVar = new Variable(node.element, null); 137 phiTempVar = new Variable(node.element, null);
135 138
136 body = visit(node.body); 139 body = visit(node.body);
137 } 140 }
138 return new FieldDefinition(node.element, body); 141 return new FieldDefinition(node.element, body);
139 } 142 }
140 143
141 Variable getFunctionParameter(cps_ir.Definition variable) { 144 Variable getFunctionParameter(cps_ir.Definition variable) {
142 if (variable is cps_ir.Parameter) { 145 if (variable is cps_ir.Parameter) {
143 return getVariable(variable); 146 return getVariable(variable);
144 } else { 147 } else {
145 return getClosureVariable(variable as cps_ir.ClosureVariable); 148 return getClosureVariable(variable as cps_ir.ClosureVariable);
146 } 149 }
147 } 150 }
148 151
149 FunctionDefinition buildFunction(cps_ir.FunctionDefinition node) { 152 FunctionDefinition buildFunction(cps_ir.FunctionDefinition node) {
150 currentElement = node.element; 153 currentElement = node.element;
151 List<Variable> parameters = <Variable>[]; 154 List<Variable> parameters = <Variable>[];
152 for (cps_ir.Definition p in node.parameters) { 155 for (cps_ir.Definition p in node.parameters) {
153 Variable parameter = getFunctionParameter(p); 156 Variable parameter = getFunctionParameter(p);
154 assert(parameter != null); 157 assert(parameter != null);
155 ++parameter.writeCount; // Being a parameter counts as a write. 158 ++parameter.writeCount; // Being a parameter counts as a write.
156 parameters.add(parameter); 159 parameters.add(parameter);
157 } 160 }
158 returnContinuation = node.returnContinuation;
159 161
160 Statement body; 162 Statement body;
161 if (!node.isAbstract) { 163 if (!node.isAbstract) {
164 returnContinuation = node.body.returnContinuation;
162 phiTempVar = new Variable(node.element, null); 165 phiTempVar = new Variable(node.element, null);
163 body = visit(node.body); 166 body = visit(node.body);
164 } 167 }
165 168
166 return new FunctionDefinition(node.element, parameters, 169 return new FunctionDefinition(node.element, parameters,
167 body, node.localConstants, node.defaultParameterValues); 170 body, node.localConstants, node.defaultParameterValues);
168 } 171 }
169 172
173 ConstructorDefinition buildConstructor(cps_ir.ConstructorDefinition node) {
174 currentElement = node.element;
175 List<Variable> parameters = <Variable>[];
176 for (cps_ir.Definition p in node.parameters) {
177 Variable parameter = getFunctionParameter(p);
178 assert(parameter != null);
179 ++parameter.writeCount; // Being a parameter counts as a write.
180 parameters.add(parameter);
181 }
182 List<Initializer> initializers;
183 Statement body;
184 if (!node.isAbstract) {
185 initializers = node.initializers.map(visit).toList();
186 returnContinuation = node.body.returnContinuation;
187
188 phiTempVar = new Variable(node.element, null);
189 body = visit(node.body);
190 }
191
192 return new ConstructorDefinition(node.element, parameters,
193 body, initializers, node.localConstants, node.defaultParameterValues,
194 node.isConst);
195 }
196
197
170 List<Expression> translateArguments(List<cps_ir.Reference> args) { 198 List<Expression> translateArguments(List<cps_ir.Reference> args) {
171 return new List<Expression>.generate(args.length, 199 return new List<Expression>.generate(args.length,
172 (int index) => getVariableReference(args[index])); 200 (int index) => getVariableReference(args[index]));
173 } 201 }
174 202
175 List<Variable> translatePhiArguments(List<cps_ir.Reference> args) { 203 List<Variable> translatePhiArguments(List<cps_ir.Reference> args) {
176 return new List<Variable>.generate(args.length, 204 return new List<Variable>.generate(args.length,
177 (int index) => getVariableReference(args[index])); 205 (int index) => getVariableReference(args[index]));
178 } 206 }
179 207
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (first == null) { 299 if (first == null) {
272 first = buildRest(); 300 first = buildRest();
273 } else { 301 } else {
274 current.next = buildRest(); 302 current.next = buildRest();
275 } 303 }
276 return first; 304 return first;
277 } 305 }
278 306
279 visitNode(cps_ir.Node node) => throw "Unhandled node: $node"; 307 visitNode(cps_ir.Node node) => throw "Unhandled node: $node";
280 308
309 Initializer visitFieldInitializer(cps_ir.FieldInitializer node) {
310 returnContinuation = node.body.returnContinuation;
311 return new FieldInitializer(node.element, visit(node.body.body));
312 }
313
314 Initializer visitSuperInitializer(cps_ir.SuperInitializer node) {
315 List<Statement> arguments =
316 node.arguments.map((cps_ir.RunnableBody argument) {
317 returnContinuation = argument.returnContinuation;
318 return visit(argument.body);
319 }).toList();
320 return new SuperInitializer(node.target, node.selector, arguments);
321 }
322
281 Statement visitLetPrim(cps_ir.LetPrim node) { 323 Statement visitLetPrim(cps_ir.LetPrim node) {
282 Variable variable = getVariable(node.primitive); 324 Variable variable = getVariable(node.primitive);
283 325
284 // Don't translate unused primitives. 326 // Don't translate unused primitives.
285 if (variable == null) return visit(node.body); 327 if (variable == null) return visit(node.body);
286 328
287 Node definition = visit(node.primitive); 329 Node definition = visit(node.primitive);
288 330
289 // visitPrimitive returns a Statement without successor if it cannot occur 331 // visitPrimitive returns a Statement without successor if it cannot occur
290 // in expression context (currently only the case for FunctionDeclarations). 332 // in expression context (currently only the case for FunctionDeclarations).
291 if (definition is Statement) { 333 if (definition is Statement) {
292 definition.next = visit(node.body); 334 definition.next = visit(node.body);
293 return definition; 335 return definition;
294 } else { 336 } else {
295 return new Assign(variable, definition, visit(node.body)); 337 return new Assign(variable, definition, visit(node.body));
296 } 338 }
297 } 339 }
298 340
341 Statement visitRunnableBody(cps_ir.RunnableBody node) {
342 return visit(node.body);
343 }
344
299 Statement visitLetCont(cps_ir.LetCont node) { 345 Statement visitLetCont(cps_ir.LetCont node) {
300 Label label; 346 Label label;
301 if (node.continuation.hasMultipleUses) { 347 if (node.continuation.hasMultipleUses) {
302 label = new Label(); 348 label = new Label();
303 labels[node.continuation] = label; 349 labels[node.continuation] = label;
304 } 350 }
305 Statement body = visit(node.body); 351 Statement body = visit(node.body);
306 // The continuation's body is not always translated directly here because 352 // The continuation's body is not always translated directly here because
307 // it may have been already translated: 353 // it may have been already translated:
308 // * For singly-used continuations, the continuation's body is 354 // * For singly-used continuations, the continuation's body is
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 554
509 Expression visitIdentical(cps_ir.Identical node) { 555 Expression visitIdentical(cps_ir.Identical node) {
510 return new InvokeStatic( 556 return new InvokeStatic(
511 compiler.identicalFunction, 557 compiler.identicalFunction,
512 identicalSelector, 558 identicalSelector,
513 <Expression>[getVariableReference(node.left), 559 <Expression>[getVariableReference(node.left),
514 getVariableReference(node.right)]); 560 getVariableReference(node.right)]);
515 } 561 }
516 } 562 }
517 563
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698