| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 ir.FieldDefinition buildField(FieldElement element) { | 151 ir.FieldDefinition buildField(FieldElement element) { |
| 152 assert(invariant(element, element.isImplementation)); | 152 assert(invariant(element, element.isImplementation)); |
| 153 ast.VariableDefinitions definitions = element.node; | 153 ast.VariableDefinitions definitions = element.node; |
| 154 ast.Node fieldDefinition = | 154 ast.Node fieldDefinition = |
| 155 definitions.definitions.nodes.first; | 155 definitions.definitions.nodes.first; |
| 156 if (definitions.modifiers.isConst) { | 156 if (definitions.modifiers.isConst) { |
| 157 // TODO(sigurdm): Just return const value. | 157 // TODO(sigurdm): Just return const value. |
| 158 } | 158 } |
| 159 assert(fieldDefinition != null); | 159 assert(fieldDefinition != null); |
| 160 assert(elements[fieldDefinition] != null); | 160 assert(elements[fieldDefinition] != null); |
| 161 // This means there is no initializer. | |
| 162 // TODO(sigurdm): Avoid ever getting here. Abstract functions and fields | |
| 163 // with no initializer should not have a representation in the IR. | |
| 164 if (fieldDefinition is! ast.SendSet) return null; | |
| 165 DetectClosureVariables closureLocals = | 161 DetectClosureVariables closureLocals = |
| 166 new DetectClosureVariables(elements); | 162 new DetectClosureVariables(elements); |
| 167 closureLocals.visit(fieldDefinition); | 163 closureLocals.visit(fieldDefinition); |
| 168 | 164 |
| 169 IrBuilder builder = new IrBuilder(compiler.backend.constantSystem, | 165 IrBuilder builder = new IrBuilder(compiler.backend.constantSystem, |
| 170 element, | 166 element, |
| 171 closureLocals.usedFromClosure); | 167 closureLocals.usedFromClosure); |
| 172 return withBuilder(builder, () { | 168 return withBuilder(builder, () { |
| 173 ast.SendSet sendSet = fieldDefinition; | 169 ir.Primitive initializer; |
| 174 ir.Primitive result = visit(sendSet.arguments.first); | 170 if (fieldDefinition is ast.SendSet) { |
| 175 builder.buildReturn(result); | 171 ast.SendSet sendSet = fieldDefinition; |
| 176 return builder.makeFieldDefinition(); | 172 initializer = visit(sendSet.arguments.first); |
| 173 } |
| 174 return builder.makeFieldDefinition(initializer); |
| 177 }); | 175 }); |
| 178 } | 176 } |
| 179 | 177 |
| 180 ir.FunctionDefinition buildFunction(FunctionElement element) { | 178 ir.FunctionDefinition buildFunction(FunctionElement element) { |
| 181 assert(invariant(element, element.isImplementation)); | 179 assert(invariant(element, element.isImplementation)); |
| 182 ast.FunctionExpression function = element.node; | 180 ast.FunctionExpression function = element.node; |
| 183 assert(function != null); | 181 assert(function != null); |
| 184 assert(elements[function] != null); | 182 assert(elements[function] != null); |
| 185 | 183 |
| 186 DetectClosureVariables closureLocals = new DetectClosureVariables(elements); | 184 DetectClosureVariables closureLocals = new DetectClosureVariables(elements); |
| 187 closureLocals.visit(function); | 185 closureLocals.visit(function); |
| 188 | 186 |
| 189 return withBuilder( | 187 return withBuilder( |
| 190 new IrBuilder(compiler.backend.constantSystem, | 188 new IrBuilder(compiler.backend.constantSystem, |
| 191 element, closureLocals.usedFromClosure), | 189 element, closureLocals.usedFromClosure), |
| 192 () { | 190 () { |
| 193 FunctionSignature signature = element.functionSignature; | 191 FunctionSignature signature = element.functionSignature; |
| 194 signature.orderedForEachParameter((ParameterElement parameterElement) { | 192 signature.orderedForEachParameter((ParameterElement parameterElement) { |
| 195 irBuilder.createParameter(parameterElement); | 193 irBuilder.createParameter(parameterElement); |
| 196 }); | 194 }); |
| 197 | 195 |
| 198 List<ConstantExpression> defaults = new List<ConstantExpression>(); | 196 List<ConstantExpression> defaults = new List<ConstantExpression>(); |
| 199 signature.orderedOptionalParameters.forEach((ParameterElement element) { | 197 signature.orderedOptionalParameters.forEach((ParameterElement element) { |
| 200 defaults.add(getConstantForVariable(element)); | 198 defaults.add(getConstantForVariable(element)); |
| 201 }); | 199 }); |
| 202 | 200 |
| 203 visit(function.body); | 201 visit(function.body); |
| 204 return irBuilder.buildFunctionDefinition(defaults); | 202 return irBuilder.makeFunctionDefinition(defaults); |
| 205 }); | 203 }); |
| 206 } | 204 } |
| 207 | 205 |
| 208 ir.Primitive visit(ast.Node node) => node.accept(this); | 206 ir.Primitive visit(ast.Node node) => node.accept(this); |
| 209 | 207 |
| 210 // ==== Statements ==== | 208 // ==== Statements ==== |
| 211 visitBlock(ast.Block node) { | 209 visitBlock(ast.Block node) { |
| 212 irBuilder.buildBlock(node.statements.nodes, build); | 210 irBuilder.buildBlock(node.statements.nodes, build); |
| 213 } | 211 } |
| 214 | 212 |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 node.visitChildren(this); | 913 node.visitChildren(this); |
| 916 } | 914 } |
| 917 | 915 |
| 918 visitFunctionExpression(ast.FunctionExpression node) { | 916 visitFunctionExpression(ast.FunctionExpression node) { |
| 919 FunctionElement oldFunction = currentFunction; | 917 FunctionElement oldFunction = currentFunction; |
| 920 currentFunction = elements[node]; | 918 currentFunction = elements[node]; |
| 921 visit(node.body); | 919 visit(node.body); |
| 922 currentFunction = oldFunction; | 920 currentFunction = oldFunction; |
| 923 } | 921 } |
| 924 } | 922 } |
| OLD | NEW |