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 library dart2js.ir_builder_task; | 5 library dart2js.ir_builder_task; |
6 | 6 |
7 import 'package:js_runtime/shared/embedded_names.dart' | 7 import 'package:js_runtime/shared/embedded_names.dart' |
8 show JsBuiltin, JsGetName; | 8 show JsBuiltin, JsGetName; |
9 | 9 |
10 import '../closure.dart' as closure; | 10 import '../closure.dart' as closure; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 /// Returns `null` if the constructor does not have a body. | 284 /// Returns `null` if the constructor does not have a body. |
285 ConstructorBodyElement getConstructorBody(FunctionElement constructor) { | 285 ConstructorBodyElement getConstructorBody(FunctionElement constructor) { |
286 // TODO(asgerf): This is largely inherited from the SSA builder. | 286 // TODO(asgerf): This is largely inherited from the SSA builder. |
287 // The ConstructorBodyElement has an invalid function signature, but we | 287 // The ConstructorBodyElement has an invalid function signature, but we |
288 // cannot add a BoxLocal as parameter, because BoxLocal is not an element. | 288 // cannot add a BoxLocal as parameter, because BoxLocal is not an element. |
289 // Instead of forging ParameterElements to forge a FunctionSignature, we | 289 // Instead of forging ParameterElements to forge a FunctionSignature, we |
290 // need a way to create backend methods without creating more fake elements. | 290 // need a way to create backend methods without creating more fake elements. |
291 assert(constructor.isGenerativeConstructor); | 291 assert(constructor.isGenerativeConstructor); |
292 assert(constructor.isImplementation); | 292 assert(constructor.isImplementation); |
293 if (constructor.isSynthesized) return null; | 293 if (constructor.isSynthesized) return null; |
| 294 ResolvedAst resolvedAst = backend.frontend.getResolvedAst(constructor); |
294 ast.FunctionExpression node = constructor.node; | 295 ast.FunctionExpression node = constructor.node; |
295 // If we know the body doesn't have any code, we don't generate it. | 296 // If we know the body doesn't have any code, we don't generate it. |
296 if (!node.hasBody) return null; | 297 if (!node.hasBody) return null; |
297 if (node.hasEmptyBody) return null; | 298 if (node.hasEmptyBody) return null; |
298 ClassElement classElement = constructor.enclosingClass; | 299 ClassElement classElement = constructor.enclosingClass; |
299 ConstructorBodyElement bodyElement; | 300 ConstructorBodyElement bodyElement; |
300 classElement.forEachBackendMember((Element backendMember) { | 301 classElement.forEachBackendMember((Element backendMember) { |
301 if (backendMember.isGenerativeConstructorBody) { | 302 if (backendMember.isGenerativeConstructorBody) { |
302 ConstructorBodyElement body = backendMember; | 303 ConstructorBodyElement body = backendMember; |
303 if (body.constructor == constructor) { | 304 if (body.constructor == constructor) { |
304 bodyElement = backendMember; | 305 bodyElement = backendMember; |
305 } | 306 } |
306 } | 307 } |
307 }); | 308 }); |
308 if (bodyElement == null) { | 309 if (bodyElement == null) { |
309 bodyElement = new ConstructorBodyElementX(constructor); | 310 bodyElement = new ConstructorBodyElementX(resolvedAst, constructor); |
310 classElement.addBackendMember(bodyElement); | 311 classElement.addBackendMember(bodyElement); |
311 | 312 |
312 if (constructor.isPatch) { | 313 if (constructor.isPatch) { |
313 // Create origin body element for patched constructors. | 314 // Create origin body element for patched constructors. |
314 ConstructorBodyElementX patch = bodyElement; | 315 ConstructorBodyElementX patch = bodyElement; |
315 ConstructorBodyElementX origin = | 316 ConstructorBodyElementX origin = |
316 new ConstructorBodyElementX(constructor.origin); | 317 new ConstructorBodyElementX(resolvedAst, constructor.origin); |
317 origin.applyPatch(patch); | 318 origin.applyPatch(patch); |
318 classElement.origin.addBackendMember(bodyElement.origin); | 319 classElement.origin.addBackendMember(bodyElement.origin); |
319 } | 320 } |
320 } | 321 } |
321 assert(bodyElement.isGenerativeConstructorBody); | 322 assert(bodyElement.isGenerativeConstructorBody); |
322 return bodyElement; | 323 return bodyElement; |
323 } | 324 } |
324 | 325 |
325 /// The list of parameters to send from the generative constructor | 326 /// The list of parameters to send from the generative constructor |
326 /// to the generative constructor body. | 327 /// to the generative constructor body. |
(...skipping 3692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4019 _backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass); | 4020 _backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass); |
4020 | 4021 |
4021 String getJsInteropTargetPath(FunctionElement element) { | 4022 String getJsInteropTargetPath(FunctionElement element) { |
4022 return '${_backend.namer.fixedBackendPath(element)}.' | 4023 return '${_backend.namer.fixedBackendPath(element)}.' |
4023 '${_backend.nativeData.getFixedBackendName(element)}'; | 4024 '${_backend.nativeData.getFixedBackendName(element)}'; |
4024 } | 4025 } |
4025 | 4026 |
4026 DartType get jsJavascriptObjectType => | 4027 DartType get jsJavascriptObjectType => |
4027 _backend.helpers.jsJavaScriptObjectClass.thisType; | 4028 _backend.helpers.jsJavaScriptObjectClass.thisType; |
4028 } | 4029 } |
OLD | NEW |