OLD | NEW |
---|---|
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 '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; | 9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; |
10 import '../util/util.dart' show CURRENT_ELEMENT_SPANNABLE; | 10 import '../util/util.dart' show CURRENT_ELEMENT_SPANNABLE; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 } | 251 } |
252 return first; | 252 return first; |
253 } | 253 } |
254 | 254 |
255 visit(cps_ir.Node node) => node.accept(this); | 255 visit(cps_ir.Node node) => node.accept(this); |
256 | 256 |
257 unexpectedNode(cps_ir.Node node) { | 257 unexpectedNode(cps_ir.Node node) { |
258 internalError(CURRENT_ELEMENT_SPANNABLE, 'Unexpected IR node: $node'); | 258 internalError(CURRENT_ELEMENT_SPANNABLE, 'Unexpected IR node: $node'); |
259 } | 259 } |
260 | 260 |
261 Statement visitSetField(cps_ir.SetField node) { | 261 Expression visitSetField(cps_ir.SetField node) { |
262 return new ExpressionStatement( | 262 return new SetField(getVariableUse(node.object), |
263 new SetField(getVariableUse(node.object), | 263 node.field, |
264 node.field, | 264 getVariableUse(node.value)); |
265 getVariableUse(node.value)), | |
266 visit(node.body)); | |
267 } | 265 } |
268 | 266 |
269 Expression visitInterceptor(cps_ir.Interceptor node) { | 267 Expression visitInterceptor(cps_ir.Interceptor node) { |
270 return new Interceptor(getVariableUse(node.input), node.interceptedClasses); | 268 return new Interceptor(getVariableUse(node.input), node.interceptedClasses); |
271 } | 269 } |
272 | 270 |
273 Expression visitCreateInstance(cps_ir.CreateInstance node) { | 271 Expression visitCreateInstance(cps_ir.CreateInstance node) { |
274 return new CreateInstance( | 272 return new CreateInstance( |
275 node.classElement, | 273 node.classElement, |
276 translateArguments(node.arguments), | 274 translateArguments(node.arguments), |
(...skipping 16 matching lines...) Expand all Loading... | |
293 } | 291 } |
294 | 292 |
295 // Executable definitions are not visited directly. They have 'build' | 293 // Executable definitions are not visited directly. They have 'build' |
296 // functions as entry points. | 294 // functions as entry points. |
297 visitFunctionDefinition(cps_ir.FunctionDefinition node) { | 295 visitFunctionDefinition(cps_ir.FunctionDefinition node) { |
298 return unexpectedNode(node); | 296 return unexpectedNode(node); |
299 } | 297 } |
300 | 298 |
301 Statement visitLetPrim(cps_ir.LetPrim node) { | 299 Statement visitLetPrim(cps_ir.LetPrim node) { |
302 Variable variable = getVariable(node.primitive); | 300 Variable variable = getVariable(node.primitive); |
303 | |
304 // Don't translate unused primitives. | |
305 if (variable == null) return visit(node.body); | |
asgerf
2015/07/20 13:35:23
This was dead code, left behind after another refa
| |
306 | |
307 Expression value = visit(node.primitive); | 301 Expression value = visit(node.primitive); |
308 return Assign.makeStatement(variable, value, visit(node.body)); | 302 if (node.primitive.hasAtLeastOneUse) { |
303 return Assign.makeStatement(variable, value, visit(node.body)); | |
304 } else { | |
305 return new ExpressionStatement(value, visit(node.body)); | |
306 } | |
309 } | 307 } |
310 | 308 |
311 Statement visitLetCont(cps_ir.LetCont node) { | 309 Statement visitLetCont(cps_ir.LetCont node) { |
312 // Introduce labels for continuations that need them. | 310 // Introduce labels for continuations that need them. |
313 for (cps_ir.Continuation continuation in node.continuations) { | 311 for (cps_ir.Continuation continuation in node.continuations) { |
314 if (continuation.hasMultipleUses || continuation.isRecursive) { | 312 if (continuation.hasMultipleUses || continuation.isRecursive) { |
315 labels[continuation] = new Label(); | 313 labels[continuation] = new Label(); |
316 } | 314 } |
317 } | 315 } |
318 Statement body = visit(node.body); | 316 Statement body = visit(node.body); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 Variable variable = addMutableVariable(node.variable); | 407 Variable variable = addMutableVariable(node.variable); |
410 Expression value = getVariableUse(node.value); | 408 Expression value = getVariableUse(node.value); |
411 Statement body = visit(node.body); | 409 Statement body = visit(node.body); |
412 return Assign.makeStatement(variable, value, body); | 410 return Assign.makeStatement(variable, value, body); |
413 } | 411 } |
414 | 412 |
415 Expression visitGetMutableVariable(cps_ir.GetMutableVariable node) { | 413 Expression visitGetMutableVariable(cps_ir.GetMutableVariable node) { |
416 return getMutableVariableUse(node.variable); | 414 return getMutableVariableUse(node.variable); |
417 } | 415 } |
418 | 416 |
419 Statement visitSetMutableVariable(cps_ir.SetMutableVariable node) { | 417 Expression visitSetMutableVariable(cps_ir.SetMutableVariable node) { |
420 Variable variable = getMutableVariable(node.variable.definition); | 418 Variable variable = getMutableVariable(node.variable.definition); |
421 Expression value = getVariableUse(node.value); | 419 Expression value = getVariableUse(node.value); |
422 return Assign.makeStatement(variable, value, visit(node.body)); | 420 return new Assign(variable, value); |
423 } | 421 } |
424 | 422 |
425 Statement visitTypeCast(cps_ir.TypeCast node) { | 423 Statement visitTypeCast(cps_ir.TypeCast node) { |
426 Expression value = getVariableUse(node.value); | 424 Expression value = getVariableUse(node.value); |
427 List<Expression> typeArgs = translateArguments(node.typeArguments); | 425 List<Expression> typeArgs = translateArguments(node.typeArguments); |
428 Expression expression = | 426 Expression expression = |
429 new TypeOperator(value, node.type, typeArgs, isTypeTest: false); | 427 new TypeOperator(value, node.type, typeArgs, isTypeTest: false); |
430 return continueWithExpression(node.continuation, expression); | 428 return continueWithExpression(node.continuation, expression); |
431 } | 429 } |
432 | 430 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 return new GetStatic(node.element, node.sourceInformation); | 577 return new GetStatic(node.element, node.sourceInformation); |
580 } | 578 } |
581 | 579 |
582 Statement visitGetLazyStatic(cps_ir.GetLazyStatic node) { | 580 Statement visitGetLazyStatic(cps_ir.GetLazyStatic node) { |
583 // In the tree IR, GetStatic handles lazy fields because tree | 581 // In the tree IR, GetStatic handles lazy fields because tree |
584 // expressions are allowed to have side effects. | 582 // expressions are allowed to have side effects. |
585 GetStatic value = new GetStatic(node.element, node.sourceInformation); | 583 GetStatic value = new GetStatic(node.element, node.sourceInformation); |
586 return continueWithExpression(node.continuation, value); | 584 return continueWithExpression(node.continuation, value); |
587 } | 585 } |
588 | 586 |
589 Statement visitSetStatic(cps_ir.SetStatic node) { | 587 Expression visitSetStatic(cps_ir.SetStatic node) { |
590 SetStatic setStatic = new SetStatic( | 588 return new SetStatic( |
591 node.element, | 589 node.element, |
592 getVariableUse(node.value), | 590 getVariableUse(node.value), |
593 node.sourceInformation); | 591 node.sourceInformation); |
594 return new ExpressionStatement(setStatic, visit(node.body)); | |
595 } | 592 } |
596 | 593 |
597 Expression visitApplyBuiltinOperator(cps_ir.ApplyBuiltinOperator node) { | 594 Expression visitApplyBuiltinOperator(cps_ir.ApplyBuiltinOperator node) { |
598 if (node.operator == BuiltinOperator.IsFalsy) { | 595 if (node.operator == BuiltinOperator.IsFalsy) { |
599 return new Not(getVariableUse(node.arguments.single)); | 596 return new Not(getVariableUse(node.arguments.single)); |
600 } | 597 } |
601 return new ApplyBuiltinOperator(node.operator, | 598 return new ApplyBuiltinOperator(node.operator, |
602 translateArguments(node.arguments)); | 599 translateArguments(node.arguments)); |
603 } | 600 } |
604 | 601 |
(...skipping 26 matching lines...) Expand all Loading... | |
631 getVariableUse(node.index)); | 628 getVariableUse(node.index)); |
632 } | 629 } |
633 | 630 |
634 Expression visitSetIndex(cps_ir.SetIndex node) { | 631 Expression visitSetIndex(cps_ir.SetIndex node) { |
635 return new SetIndex(getVariableUse(node.object), | 632 return new SetIndex(getVariableUse(node.object), |
636 getVariableUse(node.index), | 633 getVariableUse(node.index), |
637 getVariableUse(node.value)); | 634 getVariableUse(node.value)); |
638 } | 635 } |
639 } | 636 } |
640 | 637 |
OLD | NEW |