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