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 simple_types_inferrer; | 5 library simple_types_inferrer; |
6 | 6 |
7 import '../closure.dart' show | 7 import '../closure.dart' show |
8 ClosureClassMap, | 8 ClosureClassMap, |
9 ClosureScope; | 9 ClosureScope; |
10 import '../common/names.dart' show | 10 import '../common/names.dart' show |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 locals.update(element, parameterType, node); | 585 locals.update(element, parameterType, node); |
586 }); | 586 }); |
587 ClassElement cls = analyzedElement.enclosingClass; | 587 ClassElement cls = analyzedElement.enclosingClass; |
588 Spannable spannable = node; | 588 Spannable spannable = node; |
589 if (analyzedElement.isSynthesized) { | 589 if (analyzedElement.isSynthesized) { |
590 spannable = analyzedElement; | 590 spannable = analyzedElement; |
591 ConstructorElement constructor = analyzedElement; | 591 ConstructorElement constructor = analyzedElement; |
592 synthesizeForwardingCall(spannable, constructor.definingConstructor); | 592 synthesizeForwardingCall(spannable, constructor.definingConstructor); |
593 } else { | 593 } else { |
594 visitingInitializers = true; | 594 visitingInitializers = true; |
595 visit(node.initializers); | 595 if (node.initializers != null) { |
| 596 for (ast.Node initializer in node.initializers) { |
| 597 ast.SendSet fieldInitializer = initializer.asSendSet(); |
| 598 if (fieldInitializer != null) { |
| 599 handleSendSet(fieldInitializer); |
| 600 } else { |
| 601 Element element = elements[initializer]; |
| 602 handleConstructorSend(initializer, element); |
| 603 } |
| 604 } |
| 605 } |
596 visitingInitializers = false; | 606 visitingInitializers = false; |
597 // For a generative constructor like: `Foo();`, we synthesize | 607 // For a generative constructor like: `Foo();`, we synthesize |
598 // a call to the default super constructor (the one that takes | 608 // a call to the default super constructor (the one that takes |
599 // no argument). Resolution ensures that such a constructor | 609 // no argument). Resolution ensures that such a constructor |
600 // exists. | 610 // exists. |
601 if (!isConstructorRedirect | 611 if (!isConstructorRedirect |
602 && !seenSuperConstructorCall | 612 && !seenSuperConstructorCall |
603 && !cls.isObject) { | 613 && !cls.isObject) { |
604 FunctionElement target = cls.superclass.lookupDefaultConstructor(); | 614 FunctionElement target = cls.superclass.lookupDefaultConstructor(); |
605 ArgumentsTypes arguments = new ArgumentsTypes([], {}); | 615 ArgumentsTypes arguments = new ArgumentsTypes([], {}); |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 @override | 1586 @override |
1577 T handleTypeLiteralInvoke(ast.NodeList arguments) { | 1587 T handleTypeLiteralInvoke(ast.NodeList arguments) { |
1578 // This is reached when users forget to put a `new` in front of a type | 1588 // This is reached when users forget to put a `new` in front of a type |
1579 // literal. The emitter will generate an actual call (even though it is | 1589 // literal. The emitter will generate an actual call (even though it is |
1580 // likely invalid), and for that it needs to have the arguments processed | 1590 // likely invalid), and for that it needs to have the arguments processed |
1581 // as well. | 1591 // as well. |
1582 analyzeArguments(arguments.nodes); | 1592 analyzeArguments(arguments.nodes); |
1583 return super.handleTypeLiteralInvoke(arguments); | 1593 return super.handleTypeLiteralInvoke(arguments); |
1584 } | 1594 } |
1585 | 1595 |
1586 T visitStaticSend(ast.Send node) { | |
1587 assert(!elements.isAssert(node)); | |
1588 Element element = elements[node]; | |
1589 return handleConstructorSend(node, element); | |
1590 } | |
1591 | |
1592 /// Handle constructor invocation of [element]. | 1596 /// Handle constructor invocation of [element]. |
1593 T handleConstructorSend(ast.Send node, ConstructorElement element) { | 1597 T handleConstructorSend(ast.Send node, ConstructorElement element) { |
1594 ArgumentsTypes arguments = analyzeArguments(node.arguments); | 1598 ArgumentsTypes arguments = analyzeArguments(node.arguments); |
1595 if (visitingInitializers) { | 1599 if (visitingInitializers) { |
1596 if (ast.Initializers.isConstructorRedirect(node)) { | 1600 if (ast.Initializers.isConstructorRedirect(node)) { |
1597 isConstructorRedirect = true; | 1601 isConstructorRedirect = true; |
1598 } else if (ast.Initializers.isSuperConstructorCall(node)) { | 1602 } else if (ast.Initializers.isSuperConstructorCall(node)) { |
1599 seenSuperConstructorCall = true; | 1603 seenSuperConstructorCall = true; |
1600 analyzeSuperConstructorCall(element, arguments); | 1604 analyzeSuperConstructorCall(element, arguments); |
1601 } | 1605 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 return inferrer.concreteTypes.putIfAbsent( | 1657 return inferrer.concreteTypes.putIfAbsent( |
1654 node, () => types.allocateList( | 1658 node, () => types.allocateList( |
1655 types.nonNullExact(constructor.enclosingClass), node, | 1659 types.nonNullExact(constructor.enclosingClass), node, |
1656 outermostElement, elementType, length)); | 1660 outermostElement, elementType, length)); |
1657 } else { | 1661 } else { |
1658 return returnType; | 1662 return returnType; |
1659 } | 1663 } |
1660 } | 1664 } |
1661 | 1665 |
1662 T handleNewExpression(ast.NewExpression node) { | 1666 T handleNewExpression(ast.NewExpression node) { |
1663 return visitStaticSend(node.send); | 1667 Element element = elements[node.send]; |
| 1668 return handleConstructorSend(node.send, element); |
1664 } | 1669 } |
1665 | 1670 |
1666 /// Handle invocation of a top level or static field or getter [element]. | 1671 /// Handle invocation of a top level or static field or getter [element]. |
1667 T handleStaticFieldOrGetterInvoke(ast.Send node, Element element) { | 1672 T handleStaticFieldOrGetterInvoke(ast.Send node, Element element) { |
1668 ArgumentsTypes arguments = analyzeArguments(node.arguments); | 1673 ArgumentsTypes arguments = analyzeArguments(node.arguments); |
1669 Selector selector = elements.getSelector(node); | 1674 Selector selector = elements.getSelector(node); |
1670 TypeMask mask = elements.getTypeMask(node); | 1675 TypeMask mask = elements.getTypeMask(node); |
1671 handleStaticSend(node, selector, mask, element, arguments); | 1676 handleStaticSend(node, selector, mask, element, arguments); |
1672 return inferrer.registerCalledClosure( | 1677 return inferrer.registerCalledClosure( |
1673 node, selector, mask, inferrer.typeOfElement(element), | 1678 node, selector, mask, inferrer.typeOfElement(element), |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2308 TypeMask moveNextMask = elements.getMoveNextTypeMask(node); | 2313 TypeMask moveNextMask = elements.getMoveNextTypeMask(node); |
2309 | 2314 |
2310 T iteratorType = handleDynamicSend( | 2315 T iteratorType = handleDynamicSend( |
2311 node, iteratorSelector, iteratorMask, expressionType, | 2316 node, iteratorSelector, iteratorMask, expressionType, |
2312 new ArgumentsTypes<T>.empty()); | 2317 new ArgumentsTypes<T>.empty()); |
2313 | 2318 |
2314 return handleForInLoop(node, iteratorType, currentSelector, currentMask, | 2319 return handleForInLoop(node, iteratorType, currentSelector, currentMask, |
2315 moveNextSelector, moveNextMask); | 2320 moveNextSelector, moveNextMask); |
2316 } | 2321 } |
2317 } | 2322 } |
OLD | NEW |