| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if (element is FunctionElement) { | 64 if (element is FunctionElement) { |
| 65 // TODO(sigurdm): Support native functions for dart2js. | 65 // TODO(sigurdm): Support native functions for dart2js. |
| 66 assert(invariant(element, !element.isNative)); | 66 assert(invariant(element, !element.isNative)); |
| 67 | 67 |
| 68 // TODO(kmillikin,sigurdm): Support constructors. | 68 // TODO(kmillikin,sigurdm): Support constructors. |
| 69 if (element is ConstructorElement && !element.isGenerativeConstructor) { | 69 if (element is ConstructorElement && !element.isGenerativeConstructor) { |
| 70 return false; | 70 return false; |
| 71 } | 71 } |
| 72 | 72 |
| 73 } else if (element is! FieldElement) { | 73 } else if (element is! FieldElement) { |
| 74 compiler.internalError(element, "Unexpected elementtype $element"); | 74 compiler.internalError(element, "Unexpected element type $element"); |
| 75 } | 75 } |
| 76 return compiler.backend.shouldOutput(element); | 76 return compiler.backend.shouldOutput(element); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool get inCheckedMode { | 79 bool get inCheckedMode { |
| 80 bool result = false; | 80 bool result = false; |
| 81 assert((result = true)); | 81 assert((result = true)); |
| 82 return result; | 82 return result; |
| 83 } | 83 } |
| 84 | 84 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 signature.orderedForEachParameter((ParameterElement parameterElement) { | 183 signature.orderedForEachParameter((ParameterElement parameterElement) { |
| 184 irBuilder.createFunctionParameter(parameterElement); | 184 irBuilder.createFunctionParameter(parameterElement); |
| 185 }); | 185 }); |
| 186 | 186 |
| 187 List<ConstantExpression> defaults = new List<ConstantExpression>(); | 187 List<ConstantExpression> defaults = new List<ConstantExpression>(); |
| 188 signature.orderedOptionalParameters.forEach((ParameterElement element) { | 188 signature.orderedOptionalParameters.forEach((ParameterElement element) { |
| 189 defaults.add(getConstantForVariable(element)); | 189 defaults.add(getConstantForVariable(element)); |
| 190 }); | 190 }); |
| 191 | 191 |
| 192 List<ir.Initializer> initializers; | 192 List<ir.Initializer> initializers; |
| 193 if (element.isGenerativeConstructor) { | 193 if (element.isSynthesized) { |
| 194 assert(element is ConstructorElement); |
| 195 return irBuilder.makeConstructorDefinition(const <ConstantExpression>[], |
| 196 const <ir.Initializer>[]); |
| 197 } else if (element.isGenerativeConstructor) { |
| 194 initializers = buildConstructorInitializers(node, element); | 198 initializers = buildConstructorInitializers(node, element); |
| 195 visit(node.body); | 199 visit(node.body); |
| 196 return irBuilder.makeConstructorDefinition(defaults, initializers); | 200 return irBuilder.makeConstructorDefinition(defaults, initializers); |
| 197 } else { | 201 } else { |
| 198 visit(node.body); | 202 visit(node.body); |
| 199 return irBuilder.makeFunctionDefinition(defaults); | 203 return irBuilder.makeFunctionDefinition(defaults); |
| 200 } | 204 } |
| 201 } | 205 } |
| 202 | 206 |
| 203 List<ir.Initializer> buildConstructorInitializers( | 207 List<ir.Initializer> buildConstructorInitializers( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 <ir.RunnableBody>[], | 276 <ir.RunnableBody>[], |
| 273 selector)); | 277 selector)); |
| 274 } | 278 } |
| 275 } | 279 } |
| 276 return result; | 280 return result; |
| 277 } | 281 } |
| 278 | 282 |
| 279 ir.FunctionDefinition buildFunction(FunctionElement element) { | 283 ir.FunctionDefinition buildFunction(FunctionElement element) { |
| 280 assert(invariant(element, element.isImplementation)); | 284 assert(invariant(element, element.isImplementation)); |
| 281 ast.FunctionExpression node = element.node; | 285 ast.FunctionExpression node = element.node; |
| 282 assert(node != null); | |
| 283 assert(elements[node] != null); | |
| 284 | 286 |
| 285 DetectClosureVariables closureLocals = new DetectClosureVariables(elements); | 287 Iterable<Entity> usedFromClosure; |
| 286 closureLocals.visit(node); | 288 if (!element.isSynthesized) { |
| 289 assert(node != null); |
| 290 assert(elements[node] != null); |
| 291 |
| 292 // TODO(karlklose): this information should be provided by resolution. |
| 293 DetectClosureVariables closureLocals = |
| 294 new DetectClosureVariables(elements); |
| 295 closureLocals.visit(node); |
| 296 usedFromClosure = closureLocals.usedFromClosure; |
| 297 } else { |
| 298 SynthesizedConstructorElementX constructor = element; |
| 299 if (!constructor.isDefaultConstructor) { |
| 300 giveup(null, 'cannot handle synthetic forwarding constructors'); |
| 301 } |
| 302 |
| 303 usedFromClosure = <Entity>[]; |
| 304 } |
| 287 | 305 |
| 288 IrBuilder builder = new IrBuilder(compiler.backend.constantSystem, | 306 IrBuilder builder = new IrBuilder(compiler.backend.constantSystem, |
| 289 element, | 307 element, |
| 290 closureLocals.usedFromClosure); | 308 usedFromClosure); |
| 291 | 309 |
| 292 return withBuilder(builder, () => _makeFunctionBody(element, node)); | 310 return withBuilder(builder, () => _makeFunctionBody(element, node)); |
| 293 } | 311 } |
| 294 | 312 |
| 295 ir.Primitive visit(ast.Node node) => node.accept(this); | 313 ir.Primitive visit(ast.Node node) => node.accept(this); |
| 296 | 314 |
| 297 // ==== Statements ==== | 315 // ==== Statements ==== |
| 298 visitBlock(ast.Block node) { | 316 visitBlock(ast.Block node) { |
| 299 irBuilder.buildBlock(node.statements.nodes, build); | 317 irBuilder.buildBlock(node.statements.nodes, build); |
| 300 } | 318 } |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 currentFunction = elements[node]; | 1054 currentFunction = elements[node]; |
| 1037 if (node.initializers != null) { | 1055 if (node.initializers != null) { |
| 1038 insideInitializer = true; | 1056 insideInitializer = true; |
| 1039 visit(node.initializers); | 1057 visit(node.initializers); |
| 1040 insideInitializer = false; | 1058 insideInitializer = false; |
| 1041 } | 1059 } |
| 1042 visit(node.body); | 1060 visit(node.body); |
| 1043 currentFunction = oldFunction; | 1061 currentFunction = oldFunction; |
| 1044 } | 1062 } |
| 1045 } | 1063 } |
| OLD | NEW |