OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library js_tree_ir_builder; | |
6 | |
7 import '../../tree_ir/tree_ir_builder.dart' show Builder; | |
8 import 'glue.dart' show Glue; | |
9 import '../../dart2jslib.dart' show Selector, InternalErrorFunction; | |
10 import '../../elements/elements.dart'; | |
11 import '../../cps_ir/cps_ir_nodes.dart' as cps_ir; | |
12 import '../../tree_ir/tree_ir_nodes.dart'; | |
13 | |
14 /// Subclass of [Builder] that can translate nodes which are specific to the | |
15 /// JavaScript backend. | |
16 class JsTreeBuilder extends Builder { | |
17 final Glue _glue; | |
18 final Element identicalFunction; | |
19 | |
20 JsTreeBuilder( | |
21 InternalErrorFunction internalError, | |
22 this.identicalFunction, | |
23 this._glue, | |
24 [Builder parent]) | |
25 : super(internalError, parent); | |
26 | |
27 JsTreeBuilder createInnerBuilder() { | |
28 return new JsTreeBuilder(internalError, identicalFunction, _glue, this); | |
29 } | |
30 | |
31 Selector get identicalSelector { | |
32 return new Selector.call('identical', null, 2); | |
33 } | |
34 | |
35 Expression visitIdentical(cps_ir.Identical node) { | |
36 return new InvokeStatic( | |
37 identicalFunction, | |
38 identicalSelector, | |
39 <Expression>[getVariableUse(node.left), | |
40 getVariableUse(node.right)])..isEffectivelyConstant = true; | |
41 } | |
42 | |
43 Expression visitInterceptor(cps_ir.Interceptor node) { | |
44 Element getInterceptor = _glue.getInterceptorMethod; | |
45 String name = _glue.getInterceptorName(node.interceptedClasses); | |
46 Selector selector = new Selector.call(name, null, 1); | |
47 _glue.registerUseInterceptorInCodegen(); | |
48 return new InvokeStatic( | |
49 getInterceptor, | |
50 selector, | |
51 <Expression>[getVariableUse(node.input)])..isEffectivelyConstant = true; | |
52 } | |
53 | |
54 Expression visitGetField(cps_ir.GetField node) { | |
55 return new GetField(getVariableUse(node.object), node.field); | |
56 } | |
57 | |
58 Statement visitSetField(cps_ir.SetField node) { | |
59 SetField setField = | |
60 new SetField(getVariableUse(node.object), | |
61 node.field, | |
62 getVariableUse(node.value)); | |
63 return new ExpressionStatement(setField, visit(node.body)); | |
64 } | |
65 | |
66 Expression visitCreateBox(cps_ir.CreateBox node) { | |
67 return new CreateBox(); | |
68 } | |
69 | |
70 Expression visitCreateInstance(cps_ir.CreateInstance node) { | |
71 return new CreateInstance( | |
72 node.classElement, | |
73 node.arguments.map(getVariableUse).toList(growable: false), | |
74 node.typeInformation.map(getVariableUse).toList(growable: false)); | |
75 } | |
76 | |
77 Expression visitCreateInvocationMirror(cps_ir.CreateInvocationMirror node) { | |
78 return new CreateInvocationMirror(node.selector, | |
79 node.arguments.map(getVariableUse).toList(growable: false)); | |
80 } | |
81 | |
82 Statement visitForeignCode(cps_ir.ForeignCode node) { | |
83 if (node.codeTemplate.isExpression) { | |
84 Expression foreignCode = new ForeignExpression( | |
85 node.codeTemplate, | |
86 node.type, | |
87 node.arguments.map(getVariableUse).toList(growable: false), | |
88 node.nativeBehavior, | |
89 node.dependency); | |
90 return continueWithExpression(node.continuation, foreignCode); | |
91 } else { | |
92 assert(node.continuation == null); | |
93 return new ForeignStatement( | |
94 node.codeTemplate, | |
95 node.type, | |
96 node.arguments.map(getVariableUse).toList(growable: false), | |
97 node.nativeBehavior, | |
98 node.dependency); | |
99 } | |
100 } | |
101 } | |
OLD | NEW |