OLD | NEW |
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library fletchc.function_codegen; | 5 library fletchc.function_codegen; |
6 | 6 |
7 import 'package:compiler/src/dart2jslib.dart' show | 7 import 'package:compiler/src/dart2jslib.dart' show |
8 MessageKind, | 8 MessageKind, |
9 Registry; | 9 Registry; |
10 | 10 |
11 import 'package:compiler/src/elements/elements.dart'; | 11 import 'package:compiler/src/elements/elements.dart'; |
12 import 'package:compiler/src/resolution/resolution.dart'; | 12 import 'package:compiler/src/resolution/resolution.dart'; |
13 import 'package:compiler/src/tree/tree.dart'; | 13 import 'package:compiler/src/tree/tree.dart'; |
14 | 14 |
15 import 'fletch_context.dart'; | 15 import 'fletch_context.dart'; |
16 | 16 |
17 import 'compiled_function.dart' show | 17 import 'fletch_function_builder.dart' show |
18 CompiledFunction; | 18 FletchFunctionBuilder; |
19 | 19 |
20 import 'closure_environment.dart'; | 20 import 'closure_environment.dart'; |
21 | 21 |
22 import 'codegen_visitor.dart'; | 22 import 'codegen_visitor.dart'; |
23 | 23 |
24 class FunctionCodegen extends CodegenVisitor { | 24 class FunctionCodegen extends CodegenVisitor { |
25 | 25 |
26 int setterResultSlot; | 26 int setterResultSlot; |
27 | 27 |
28 FunctionCodegen(CompiledFunction compiledFunction, | 28 FunctionCodegen(FletchFunctionBuilder functionBuilder, |
29 FletchContext context, | 29 FletchContext context, |
30 TreeElements elements, | 30 TreeElements elements, |
31 Registry registry, | 31 Registry registry, |
32 ClosureEnvironment closureEnvironment, | 32 ClosureEnvironment closureEnvironment, |
33 FunctionElement function) | 33 FunctionElement function) |
34 : super(compiledFunction, context, elements, registry, | 34 : super(functionBuilder, context, elements, registry, |
35 closureEnvironment, function); | 35 closureEnvironment, function); |
36 | 36 |
37 FunctionElement get function => element; | 37 FunctionElement get function => element; |
38 | 38 |
39 // If the function is a setter, push the argument to later be returned. | 39 // If the function is a setter, push the argument to later be returned. |
40 // TODO(ajohnsen): If the argument is semantically final, we don't have to | 40 // TODO(ajohnsen): If the argument is semantically final, we don't have to |
41 // do this. | 41 // do this. |
42 bool get hasAssignmentSemantics => function.isSetter || function.name == '[]='
; | 42 bool get hasAssignmentSemantics => |
| 43 function.isSetter || function.name == '[]='; |
43 | 44 |
44 void compile() { | 45 void compile() { |
45 if (checkCompileError(function)) { | 46 if (checkCompileError(function)) { |
46 // TODO(ajohnsen): We can simply emit a MethodEnd here, but for now we | 47 // TODO(ajohnsen): We can simply emit a MethodEnd here, but for now we |
47 // compile the method to stress our CodegenVisitor with erroneous | 48 // compile the method to stress our CodegenVisitor with erroneous |
48 // elements. | 49 // elements. |
49 builder.pop(); | 50 builder.pop(); |
50 } | 51 } |
51 | 52 |
52 ClassElement enclosing = function.enclosingClass; | 53 ClassElement enclosing = function.enclosingClass; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 builder.methodEnd(); | 116 builder.methodEnd(); |
116 } | 117 } |
117 | 118 |
118 void optionalReplaceResultValue() { | 119 void optionalReplaceResultValue() { |
119 if (hasAssignmentSemantics) { | 120 if (hasAssignmentSemantics) { |
120 builder.pop(); | 121 builder.pop(); |
121 builder.loadSlot(setterResultSlot); | 122 builder.loadSlot(setterResultSlot); |
122 } | 123 } |
123 } | 124 } |
124 } | 125 } |
OLD | NEW |