| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 signature.orderedOptionalParameters.forEach((ParameterElement element) { | 187 signature.orderedOptionalParameters.forEach((ParameterElement element) { |
| 188 defaults.add(getConstantForVariable(element)); | 188 defaults.add(getConstantForVariable(element)); |
| 189 }); | 189 }); |
| 190 | 190 |
| 191 List<ir.Initializer> initializers; | 191 List<ir.Initializer> initializers; |
| 192 if (element.isSynthesized) { | 192 if (element.isSynthesized) { |
| 193 assert(element is ConstructorElement); | 193 assert(element is ConstructorElement); |
| 194 return irBuilder.makeConstructorDefinition(const <ConstantExpression>[], | 194 return irBuilder.makeConstructorDefinition(const <ConstantExpression>[], |
| 195 const <ir.Initializer>[]); | 195 const <ir.Initializer>[]); |
| 196 } else if (element.isGenerativeConstructor) { | 196 } else if (element.isGenerativeConstructor) { |
| 197 initializers = buildConstructorInitializers(node, element); | 197 if (element.isExternal) { |
| 198 visit(node.body); | 198 return irBuilder.makeAbstractConstructorDefinition(defaults); |
| 199 return irBuilder.makeConstructorDefinition(defaults, initializers); | 199 } else { |
| 200 initializers = buildConstructorInitializers(node, element); |
| 201 visit(node.body); |
| 202 return irBuilder.makeConstructorDefinition(defaults, initializers); |
| 203 } |
| 200 } else { | 204 } else { |
| 201 visit(node.body); | 205 visit(node.body); |
| 202 return irBuilder.makeFunctionDefinition(defaults); | 206 return irBuilder.makeFunctionDefinition(defaults); |
| 203 } | 207 } |
| 204 } | 208 } |
| 205 | 209 |
| 206 List<ir.Initializer> buildConstructorInitializers( | 210 List<ir.Initializer> buildConstructorInitializers( |
| 207 ast.FunctionExpression function, ConstructorElement element) { | 211 ast.FunctionExpression function, ConstructorElement element) { |
| 208 List<ir.Initializer> result = <ir.Initializer>[]; | 212 List<ir.Initializer> result = <ir.Initializer>[]; |
| 209 FunctionSignature signature = element.functionSignature; | 213 FunctionSignature signature = element.functionSignature; |
| 210 | 214 |
| 211 void tryAddInitializingFormal(ParameterElement parameterElement) { | 215 void tryAddInitializingFormal(ParameterElement parameterElement) { |
| 212 if (parameterElement.isInitializingFormal) { | 216 if (parameterElement.isInitializingFormal) { |
| 213 InitializingFormalElement initializingFormal = parameterElement; | 217 InitializingFormalElement initializingFormal = parameterElement; |
| 214 withBuilder(irBuilder.makeDelimitedBuilder(), () { | 218 withBuilder(irBuilder.makeInitializerBuilder(), () { |
| 215 ir.Primitive value = irBuilder.buildLocalGet(parameterElement); | 219 ir.Primitive value = irBuilder.buildLocalGet(parameterElement); |
| 216 result.add(irBuilder.makeFieldInitializer( | 220 result.add(irBuilder.makeFieldInitializer( |
| 217 initializingFormal.fieldElement, | 221 initializingFormal.fieldElement, |
| 218 irBuilder.makeRunnableBody(value))); | 222 irBuilder.makeRunnableBody(value))); |
| 219 }); | 223 }); |
| 220 } | 224 } |
| 221 } | 225 } |
| 222 | 226 |
| 223 // TODO(sigurdm): Preserve initializing formals as initializing formals. | 227 // TODO(sigurdm): Preserve initializing formals as initializing formals. |
| 224 signature.orderedForEachParameter(tryAddInitializingFormal); | 228 signature.orderedForEachParameter(tryAddInitializingFormal); |
| 225 | 229 |
| 226 if (function.initializers == null) return result; | 230 if (function.initializers == null) return result; |
| 227 bool explicitSuperInitializer = false; | 231 bool explicitSuperInitializer = false; |
| 228 for(ast.Node initializer in function.initializers) { | 232 for(ast.Node initializer in function.initializers) { |
| 229 if (initializer is ast.SendSet) { | 233 if (initializer is ast.SendSet) { |
| 230 // Field initializer. | 234 // Field initializer. |
| 231 FieldElement field = elements[initializer]; | 235 FieldElement field = elements[initializer]; |
| 232 withBuilder(irBuilder.makeDelimitedBuilder(), () { | 236 withBuilder(irBuilder.makeInitializerBuilder(), () { |
| 233 ir.Primitive value = visit(initializer.arguments.head); | 237 ir.Primitive value = visit(initializer.arguments.head); |
| 234 ir.RunnableBody body = irBuilder.makeRunnableBody(value); | 238 ir.RunnableBody body = irBuilder.makeRunnableBody(value); |
| 235 result.add(irBuilder.makeFieldInitializer(field, body)); | 239 result.add(irBuilder.makeFieldInitializer(field, body)); |
| 236 }); | 240 }); |
| 237 } else if (initializer is ast.Send) { | 241 } else if (initializer is ast.Send) { |
| 238 // Super or this initializer. | 242 // Super or this initializer. |
| 239 if (ast.Initializers.isConstructorRedirect(initializer)) { | 243 if (ast.Initializers.isConstructorRedirect(initializer)) { |
| 240 giveup(initializer, "constructor redirect (this) initializer"); | 244 giveup(initializer, "constructor redirect (this) initializer"); |
| 241 } | 245 } |
| 242 ConstructorElement constructor = elements[initializer].implementation; | 246 ConstructorElement constructor = elements[initializer].implementation; |
| 243 Selector selector = elements.getSelector(initializer); | 247 Selector selector = elements.getSelector(initializer); |
| 244 List<ir.RunnableBody> arguments = | 248 List<ir.RunnableBody> arguments = |
| 245 initializer.arguments.mapToList((ast.Node argument) { | 249 initializer.arguments.mapToList((ast.Node argument) { |
| 246 return withBuilder(irBuilder.makeDelimitedBuilder(), () { | 250 return withBuilder(irBuilder.makeInitializerBuilder(), () { |
| 247 ir.Primitive value = visit(argument); | 251 ir.Primitive value = visit(argument); |
| 248 return irBuilder.makeRunnableBody(value); | 252 return irBuilder.makeRunnableBody(value); |
| 249 }); | 253 }); |
| 250 }); | 254 }); |
| 251 result.add(irBuilder.makeSuperInitializer(constructor, | 255 result.add(irBuilder.makeSuperInitializer(constructor, |
| 252 arguments, | 256 arguments, |
| 253 selector)); | 257 selector)); |
| 254 explicitSuperInitializer = true; | 258 explicitSuperInitializer = true; |
| 255 } else { | 259 } else { |
| 256 compiler.internalError(initializer, | 260 compiler.internalError(initializer, |
| (...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 SourceInformation buildCall(ast.Node node) { | 1945 SourceInformation buildCall(ast.Node node) { |
| 1942 return new PositionSourceInformation( | 1946 return new PositionSourceInformation( |
| 1943 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); | 1947 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); |
| 1944 } | 1948 } |
| 1945 | 1949 |
| 1946 @override | 1950 @override |
| 1947 SourceInformationBuilder forContext(AstElement element) { | 1951 SourceInformationBuilder forContext(AstElement element) { |
| 1948 return new PositionSourceInformationBuilder(element); | 1952 return new PositionSourceInformationBuilder(element); |
| 1949 } | 1953 } |
| 1950 } | 1954 } |
| OLD | NEW |