| 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 elements.modelx; | 5 library elements.modelx; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/names.dart' show Identifiers; | 8 import '../common/names.dart' show Identifiers; |
| 9 import '../common/resolution.dart' show Resolution, ParsingContext; | 9 import '../common/resolution.dart' show Resolution, ParsingContext; |
| 10 import '../compiler.dart' show Compiler; | 10 import '../compiler.dart' show Compiler; |
| (...skipping 2396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 | 2407 |
| 2408 ConstructorBodyElementX( | 2408 ConstructorBodyElementX( |
| 2409 ResolvedAst resolvedAst, ConstructorElement constructor) | 2409 ResolvedAst resolvedAst, ConstructorElement constructor) |
| 2410 : this._resolvedAst = resolvedAst, | 2410 : this._resolvedAst = resolvedAst, |
| 2411 this.constructor = constructor, | 2411 this.constructor = constructor, |
| 2412 super(constructor.name, ElementKind.GENERATIVE_CONSTRUCTOR_BODY, | 2412 super(constructor.name, ElementKind.GENERATIVE_CONSTRUCTOR_BODY, |
| 2413 Modifiers.EMPTY, constructor.enclosingElement) { | 2413 Modifiers.EMPTY, constructor.enclosingElement) { |
| 2414 functionSignature = constructor.functionSignature; | 2414 functionSignature = constructor.functionSignature; |
| 2415 } | 2415 } |
| 2416 | 2416 |
| 2417 /// Returns the constructor body associated with the given constructor or |
| 2418 /// creates a new constructor body, if none can be found. |
| 2419 /// |
| 2420 /// Returns `null` if the constructor does not have a body. |
| 2421 static ConstructorBodyElementX createFromResolvedAst( |
| 2422 ResolvedAst constructorResolvedAst) { |
| 2423 ConstructorElement constructor = |
| 2424 constructorResolvedAst.element.implementation; |
| 2425 assert(constructor.isGenerativeConstructor); |
| 2426 if (constructorResolvedAst.kind != ResolvedAstKind.PARSED) return null; |
| 2427 |
| 2428 FunctionExpression node = constructorResolvedAst.node; |
| 2429 // If we know the body doesn't have any code, we don't generate it. |
| 2430 if (!node.hasBody) return null; |
| 2431 if (node.hasEmptyBody) return null; |
| 2432 ClassElement classElement = constructor.enclosingClass; |
| 2433 ConstructorBodyElement bodyElement; |
| 2434 classElement.forEachBackendMember((Element backendMember) { |
| 2435 if (backendMember.isGenerativeConstructorBody) { |
| 2436 ConstructorBodyElement body = backendMember; |
| 2437 if (body.constructor == constructor) { |
| 2438 // TODO(kasperl): Find a way of stopping the iteration |
| 2439 // through the backend members. |
| 2440 bodyElement = backendMember; |
| 2441 } |
| 2442 } |
| 2443 }); |
| 2444 if (bodyElement == null) { |
| 2445 bodyElement = |
| 2446 new ConstructorBodyElementX(constructorResolvedAst, constructor); |
| 2447 classElement.addBackendMember(bodyElement); |
| 2448 |
| 2449 if (constructor.isPatch) { |
| 2450 // Create origin body element for patched constructors. |
| 2451 ConstructorBodyElementX patch = bodyElement; |
| 2452 ConstructorBodyElementX origin = new ConstructorBodyElementX( |
| 2453 constructorResolvedAst, constructor.origin); |
| 2454 origin.applyPatch(patch); |
| 2455 classElement.origin.addBackendMember(bodyElement.origin); |
| 2456 } |
| 2457 } |
| 2458 assert(bodyElement.isGenerativeConstructorBody); |
| 2459 return bodyElement; |
| 2460 } |
| 2461 |
| 2417 bool get hasNode => _resolvedAst.kind == ResolvedAstKind.PARSED; | 2462 bool get hasNode => _resolvedAst.kind == ResolvedAstKind.PARSED; |
| 2418 | 2463 |
| 2419 FunctionExpression get node => _resolvedAst.node; | 2464 FunctionExpression get node => _resolvedAst.node; |
| 2420 | 2465 |
| 2421 bool get hasResolvedAst => true; | 2466 bool get hasResolvedAst => true; |
| 2422 | 2467 |
| 2423 ResolvedAst get resolvedAst { | 2468 ResolvedAst get resolvedAst { |
| 2424 if (_resolvedAst.kind == ResolvedAstKind.PARSED) { | 2469 if (_resolvedAst.kind == ResolvedAstKind.PARSED) { |
| 2425 return new ParsedResolvedAst(declaration, _resolvedAst.node, | 2470 return new ParsedResolvedAst(declaration, _resolvedAst.node, |
| 2426 _resolvedAst.body, _resolvedAst.elements, _resolvedAst.sourceUri); | 2471 _resolvedAst.body, _resolvedAst.elements, _resolvedAst.sourceUri); |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3421 body = node.asFunctionExpression().body; | 3466 body = node.asFunctionExpression().body; |
| 3422 } | 3467 } |
| 3423 return new ParsedResolvedAst( | 3468 return new ParsedResolvedAst( |
| 3424 declaration, | 3469 declaration, |
| 3425 node, | 3470 node, |
| 3426 body, | 3471 body, |
| 3427 definingElement.treeElements, | 3472 definingElement.treeElements, |
| 3428 definingElement.compilationUnit.script.resourceUri); | 3473 definingElement.compilationUnit.script.resourceUri); |
| 3429 } | 3474 } |
| 3430 } | 3475 } |
| OLD | NEW |