OLD | NEW |
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 part of dart2js.ir_builder; | 5 part of dart2js.ir_builder; |
6 | 6 |
7 /** | 7 /** |
8 * This task iterates through all resolved elements and builds [ir.Node]s. The | 8 * This task iterates through all resolved elements and builds [ir.Node]s. The |
9 * nodes are stored in the [nodes] map and accessible through [hasIr] and | 9 * nodes are stored in the [nodes] map and accessible through [hasIr] and |
10 * [getIr]. | 10 * [getIr]. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return withBuilder(builder, () { | 168 return withBuilder(builder, () { |
169 ir.Primitive initializer; | 169 ir.Primitive initializer; |
170 if (fieldDefinition is ast.SendSet) { | 170 if (fieldDefinition is ast.SendSet) { |
171 ast.SendSet sendSet = fieldDefinition; | 171 ast.SendSet sendSet = fieldDefinition; |
172 initializer = visit(sendSet.arguments.first); | 172 initializer = visit(sendSet.arguments.first); |
173 } | 173 } |
174 return builder.makeFieldDefinition(initializer); | 174 return builder.makeFieldDefinition(initializer); |
175 }); | 175 }); |
176 } | 176 } |
177 | 177 |
| 178 ir.FunctionDefinition _makeFunctionBody(FunctionElement element, |
| 179 ast.FunctionExpression node) { |
| 180 FunctionSignature signature = element.functionSignature; |
| 181 signature.orderedForEachParameter((ParameterElement parameterElement) { |
| 182 irBuilder.createFunctionParameter(parameterElement); |
| 183 }); |
| 184 |
| 185 List<ConstantExpression> defaults = new List<ConstantExpression>(); |
| 186 signature.orderedOptionalParameters.forEach((ParameterElement element) { |
| 187 defaults.add(getConstantForVariable(element)); |
| 188 }); |
| 189 |
| 190 visit(node.body); |
| 191 |
| 192 return irBuilder.makeFunctionDefinition(defaults); |
| 193 } |
| 194 |
178 ir.FunctionDefinition buildFunction(FunctionElement element) { | 195 ir.FunctionDefinition buildFunction(FunctionElement element) { |
179 assert(invariant(element, element.isImplementation)); | 196 assert(invariant(element, element.isImplementation)); |
180 ast.FunctionExpression function = element.node; | 197 ast.FunctionExpression node = element.node; |
181 assert(function != null); | 198 assert(node != null); |
182 assert(elements[function] != null); | 199 assert(elements[node] != null); |
183 | 200 |
184 DetectClosureVariables closureLocals = new DetectClosureVariables(elements); | 201 DetectClosureVariables closureLocals = new DetectClosureVariables(elements); |
185 closureLocals.visit(function); | 202 closureLocals.visit(node); |
186 | 203 |
187 return withBuilder( | 204 IrBuilder builder = new IrBuilder(compiler.backend.constantSystem, |
188 new IrBuilder(compiler.backend.constantSystem, | 205 element, |
189 element, closureLocals.usedFromClosure), | 206 closureLocals.usedFromClosure); |
190 () { | |
191 FunctionSignature signature = element.functionSignature; | |
192 signature.orderedForEachParameter((ParameterElement parameterElement) { | |
193 irBuilder.createParameter(parameterElement); | |
194 }); | |
195 | 207 |
196 List<ConstantExpression> defaults = new List<ConstantExpression>(); | 208 return withBuilder(builder, () => _makeFunctionBody(element, node)); |
197 signature.orderedOptionalParameters.forEach((ParameterElement element) { | |
198 defaults.add(getConstantForVariable(element)); | |
199 }); | |
200 | |
201 visit(function.body); | |
202 return irBuilder.makeFunctionDefinition(defaults); | |
203 }); | |
204 } | 209 } |
205 | 210 |
206 ir.Primitive visit(ast.Node node) => node.accept(this); | 211 ir.Primitive visit(ast.Node node) => node.accept(this); |
207 | 212 |
208 // ==== Statements ==== | 213 // ==== Statements ==== |
209 visitBlock(ast.Block node) { | 214 visitBlock(ast.Block node) { |
210 irBuilder.buildBlock(node.statements.nodes, build); | 215 irBuilder.buildBlock(node.statements.nodes, build); |
211 } | 216 } |
212 | 217 |
213 ir.Primitive visitBreakStatement(ast.BreakStatement node) { | 218 ir.Primitive visitBreakStatement(ast.BreakStatement node) { |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 | 842 |
838 ir.Primitive translateConstant(ast.Node node, [ConstantExpression constant]) { | 843 ir.Primitive translateConstant(ast.Node node, [ConstantExpression constant]) { |
839 assert(irBuilder.isOpen); | 844 assert(irBuilder.isOpen); |
840 if (constant == null) { | 845 if (constant == null) { |
841 constant = getConstantForNode(node); | 846 constant = getConstantForNode(node); |
842 } | 847 } |
843 return irBuilder.buildConstantLiteral(constant); | 848 return irBuilder.buildConstantLiteral(constant); |
844 } | 849 } |
845 | 850 |
846 ir.FunctionDefinition makeSubFunction(ast.FunctionExpression node) { | 851 ir.FunctionDefinition makeSubFunction(ast.FunctionExpression node) { |
847 return buildFunction(elements[node]); | 852 FunctionElement element = elements[node]; |
| 853 assert(invariant(element, element.isImplementation)); |
| 854 |
| 855 IrBuilder builder = new IrBuilder.innerFunction(irBuilder, element); |
| 856 |
| 857 return withBuilder(builder, () => _makeFunctionBody(element, node)); |
848 } | 858 } |
849 | 859 |
850 ir.Primitive visitFunctionExpression(ast.FunctionExpression node) { | 860 ir.Primitive visitFunctionExpression(ast.FunctionExpression node) { |
851 return irBuilder.buildFunctionExpression(makeSubFunction(node)); | 861 return irBuilder.buildFunctionExpression(makeSubFunction(node)); |
852 } | 862 } |
853 | 863 |
854 visitFunctionDeclaration(ast.FunctionDeclaration node) { | 864 visitFunctionDeclaration(ast.FunctionDeclaration node) { |
855 LocalFunctionElement element = elements[node.function]; | 865 LocalFunctionElement element = elements[node.function]; |
856 ir.FunctionDefinition inner = makeSubFunction(node.function); | 866 ir.FunctionDefinition inner = makeSubFunction(node.function); |
857 irBuilder.declareLocalFunction(element, inner); | 867 irBuilder.declareLocalFunction(element, inner); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 node.visitChildren(this); | 923 node.visitChildren(this); |
914 } | 924 } |
915 | 925 |
916 visitFunctionExpression(ast.FunctionExpression node) { | 926 visitFunctionExpression(ast.FunctionExpression node) { |
917 FunctionElement oldFunction = currentFunction; | 927 FunctionElement oldFunction = currentFunction; |
918 currentFunction = elements[node]; | 928 currentFunction = elements[node]; |
919 visit(node.body); | 929 visit(node.body); |
920 currentFunction = oldFunction; | 930 currentFunction = oldFunction; |
921 } | 931 } |
922 } | 932 } |
OLD | NEW |