Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: pkg/compiler/lib/src/resolution/send_structure.dart

Issue 1437463005: Compute NewStructure in resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Long line. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.resolution.send_structure; 5 library dart2js.resolution.send_structure;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../constants/expressions.dart'; 8 import '../constants/expressions.dart';
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../elements/elements.dart'; 10 import '../elements/elements.dart';
11 import '../resolution/tree_elements.dart' show
12 TreeElements;
11 import '../tree/tree.dart'; 13 import '../tree/tree.dart';
12 import '../universe/call_structure.dart' show 14 import '../universe/call_structure.dart' show
13 CallStructure; 15 CallStructure;
14 import '../universe/selector.dart' show 16 import '../universe/selector.dart' show
15 Selector; 17 Selector;
16 18
17 import 'access_semantics.dart'; 19 import 'access_semantics.dart';
18 import 'operators.dart'; 20 import 'operators.dart';
19 import 'semantic_visitor.dart'; 21 import 'semantic_visitor.dart';
20 22
(...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 final ConstructorAccessSemantics semantics; 2637 final ConstructorAccessSemantics semantics;
2636 final Selector selector; 2638 final Selector selector;
2637 2639
2638 NewInvokeStructure(this.semantics, this.selector); 2640 NewInvokeStructure(this.semantics, this.selector);
2639 2641
2640 CallStructure get callStructure => selector.callStructure; 2642 CallStructure get callStructure => selector.callStructure;
2641 2643
2642 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) { 2644 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) {
2643 switch (semantics.kind) { 2645 switch (semantics.kind) {
2644 case ConstructorAccessKind.GENERATIVE: 2646 case ConstructorAccessKind.GENERATIVE:
2647 ConstructorElement constructor = semantics.element;
2648 if (constructor.isRedirectingGenerative) {
2649 return visitor.visitRedirectingGenerativeConstructorInvoke(
2650 node, constructor, semantics.type,
2651 node.send.argumentsNode, callStructure, arg);
2652 }
2645 return visitor.visitGenerativeConstructorInvoke( 2653 return visitor.visitGenerativeConstructorInvoke(
2646 node, semantics.element, semantics.type, 2654 node, constructor, semantics.type,
2647 node.send.argumentsNode, callStructure, arg);
2648 case ConstructorAccessKind.REDIRECTING_GENERATIVE:
2649 return visitor.visitRedirectingGenerativeConstructorInvoke(
2650 node, semantics.element, semantics.type,
2651 node.send.argumentsNode, callStructure, arg); 2655 node.send.argumentsNode, callStructure, arg);
2652 case ConstructorAccessKind.FACTORY: 2656 case ConstructorAccessKind.FACTORY:
2653 return visitor.visitFactoryConstructorInvoke( 2657 ConstructorElement constructor = semantics.element;
2654 node, semantics.element, semantics.type, 2658 if (constructor.isRedirectingFactory) {
2655 node.send.argumentsNode, callStructure, arg); 2659 if (constructor.isEffectiveTargetMalformed) {
2656 case ConstructorAccessKind.REDIRECTING_FACTORY: 2660 return visitor.visitUnresolvedRedirectingFactoryConstructorInvoke(
2657 return visitor.visitRedirectingFactoryConstructorInvoke( 2661 node, semantics.element, semantics.type,
2658 node, semantics.element, semantics.type, 2662 node.send.argumentsNode, callStructure, arg);
2659 semantics.effectiveTargetSemantics.element, 2663 }
2660 semantics.effectiveTargetSemantics.type, 2664 ConstructorElement effectiveTarget = constructor.effectiveTarget;
2665 InterfaceType effectiveTargetType =
2666 constructor.computeEffectiveTargetType(semantics.type);
2667 if (callStructure.signatureApplies(effectiveTarget.functionSignature)) {
sigurdm 2015/11/11 08:24:52 Long line
Johnni Winther 2015/11/11 09:56:30 Done.
2668 return visitor.visitRedirectingFactoryConstructorInvoke(
2669 node, semantics.element, semantics.type,
2670 effectiveTarget, effectiveTargetType,
2671 node.send.argumentsNode, callStructure, arg);
2672 } else {
2673 return visitor.visitUnresolvedRedirectingFactoryConstructorInvoke(
2674 node, semantics.element, semantics.type,
2675 node.send.argumentsNode, callStructure, arg);
2676 }
2677 }
2678 if (callStructure.signatureApplies(constructor.functionSignature)) {
2679 return visitor.visitFactoryConstructorInvoke(
2680 node, constructor, semantics.type,
2681 node.send.argumentsNode, callStructure, arg);
2682 }
2683 return visitor.visitConstructorIncompatibleInvoke(
2684 node, constructor, semantics.type,
2661 node.send.argumentsNode, callStructure, arg); 2685 node.send.argumentsNode, callStructure, arg);
2662 case ConstructorAccessKind.ABSTRACT: 2686 case ConstructorAccessKind.ABSTRACT:
2663 return visitor.visitAbstractClassConstructorInvoke( 2687 return visitor.visitAbstractClassConstructorInvoke(
2664 node, semantics.element, semantics.type, 2688 node, semantics.element, semantics.type,
2665 node.send.argumentsNode, callStructure, arg); 2689 node.send.argumentsNode, callStructure, arg);
2666 case ConstructorAccessKind.UNRESOLVED_CONSTRUCTOR: 2690 case ConstructorAccessKind.UNRESOLVED_CONSTRUCTOR:
2667 return visitor.visitUnresolvedConstructorInvoke( 2691 return visitor.visitUnresolvedConstructorInvoke(
2668 node, semantics.element, semantics.type, 2692 node, semantics.element, semantics.type,
2669 node.send.argumentsNode, selector, arg); 2693 node.send.argumentsNode, selector, arg);
2670 case ConstructorAccessKind.UNRESOLVED_TYPE: 2694 case ConstructorAccessKind.UNRESOLVED_TYPE:
2671 return visitor.visitUnresolvedClassConstructorInvoke( 2695 return visitor.visitUnresolvedClassConstructorInvoke(
2672 node, semantics.element, semantics.type, 2696 node, semantics.element, semantics.type,
2673 node.send.argumentsNode, selector, arg); 2697 node.send.argumentsNode, selector, arg);
2674 case ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR: 2698 case ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR:
2675 return visitor.errorNonConstantConstructorInvoke( 2699 return visitor.errorNonConstantConstructorInvoke(
2676 node, semantics.element, semantics.type, 2700 node, semantics.element, semantics.type,
2677 node.send.argumentsNode, callStructure, arg); 2701 node.send.argumentsNode, callStructure, arg);
2678 case ConstructorAccessKind.ERRONEOUS_REDIRECTING_FACTORY:
sigurdm 2015/11/11 08:24:52 Where did this go?
Johnni Winther 2015/11/11 09:56:30 Inside the FACTORY case.
2679 return visitor.visitUnresolvedRedirectingFactoryConstructorInvoke(
2680 node, semantics.element, semantics.type,
2681 node.send.argumentsNode, callStructure, arg);
2682 case ConstructorAccessKind.INCOMPATIBLE: 2702 case ConstructorAccessKind.INCOMPATIBLE:
2683 return visitor.visitConstructorIncompatibleInvoke( 2703 return visitor.visitConstructorIncompatibleInvoke(
2684 node, semantics.element, semantics.type, 2704 node, semantics.element, semantics.type,
2685 node.send.argumentsNode, callStructure, arg); 2705 node.send.argumentsNode, callStructure, arg);
2686 } 2706 }
2687 throw new SpannableAssertionFailure(node, 2707 throw new SpannableAssertionFailure(node,
2688 "Unhandled constructor invocation kind: ${semantics.kind}"); 2708 "Unhandled constructor invocation kind: ${semantics.kind}");
2689 } 2709 }
2690 2710
2691 String toString() => 'new($semantics,$selector)'; 2711 String toString() => 'new($semantics,$selector)';
(...skipping 24 matching lines...) Expand all
2716 case ConstantInvokeKind.INT_FROM_ENVIRONMENT: 2736 case ConstantInvokeKind.INT_FROM_ENVIRONMENT:
2717 return visitor.visitIntFromEnvironmentConstructorInvoke( 2737 return visitor.visitIntFromEnvironmentConstructorInvoke(
2718 node, constant, arg); 2738 node, constant, arg);
2719 case ConstantInvokeKind.STRING_FROM_ENVIRONMENT: 2739 case ConstantInvokeKind.STRING_FROM_ENVIRONMENT:
2720 return visitor.visitStringFromEnvironmentConstructorInvoke( 2740 return visitor.visitStringFromEnvironmentConstructorInvoke(
2721 node, constant, arg); 2741 node, constant, arg);
2722 } 2742 }
2723 } 2743 }
2724 } 2744 }
2725 2745
2746 /// A constant constructor invocation that couldn't be determined fully during
2747 /// resolution.
2748 // TODO(johnniwinther): Remove this when all constants are computed during
2749 // resolution.
2750 class LateConstInvokeStructure<R, A> extends NewStructure<R, A> {
2751 final TreeElements elements;
2752
2753 LateConstInvokeStructure(this.elements);
2754
2755 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) {
2756 Element element = elements[node.send];
2757 Selector selector = elements.getSelector(node.send);
2758 DartType type = elements.getType(node);
2759 ConstantExpression constant = elements.getConstant(node);
2760 if (element.isMalformed ||
2761 constant == null ||
2762 constant.kind == ConstantExpressionKind.ERRONEOUS) {
2763 // This is a non-constant constant constructor invocation, like
2764 // `const Const(method())`.
2765 return visitor.errorNonConstantConstructorInvoke(
2766 node, element, type,
2767 node.send.argumentsNode, selector.callStructure, arg);
2768 } else {
2769 ConstantInvokeKind kind;
2770 switch (constant.kind) {
2771 case ConstantExpressionKind.CONSTRUCTED:
2772 return visitor.visitConstConstructorInvoke(node, constant, arg);
2773 case ConstantExpressionKind.BOOL_FROM_ENVIRONMENT:
2774 return visitor.visitBoolFromEnvironmentConstructorInvoke(
2775 node, constant, arg);
2776 case ConstantExpressionKind.INT_FROM_ENVIRONMENT:
2777 return visitor.visitIntFromEnvironmentConstructorInvoke(
2778 node, constant, arg);
2779 case ConstantExpressionKind.STRING_FROM_ENVIRONMENT:
2780 return visitor.visitStringFromEnvironmentConstructorInvoke(
2781 node, constant, arg);
2782 default:
2783 throw new SpannableAssertionFailure(
2784 node, "Unexpected constant kind $kind: ${constant.getText()}");
2785 }
2786 }
2787 }
2788 }
2789
2726 /// The structure of a parameter declaration. 2790 /// The structure of a parameter declaration.
2727 abstract class ParameterStructure<R, A> { 2791 abstract class ParameterStructure<R, A> {
2728 final VariableDefinitions definitions; 2792 final VariableDefinitions definitions;
2729 final Node node; 2793 final Node node;
2730 final ParameterElement parameter; 2794 final ParameterElement parameter;
2731 2795
2732 ParameterStructure(this.definitions, this.node, this.parameter); 2796 ParameterStructure(this.definitions, this.node, this.parameter);
2733 2797
2734 /// Calls the matching visit method on [visitor] with [definitions] and [arg]. 2798 /// Calls the matching visit method on [visitor] with [definitions] and [arg].
2735 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg); 2799 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2949 ThisConstructorInvokeStructure( 3013 ThisConstructorInvokeStructure(
2950 this.node, this.constructor, this.callStructure); 3014 this.node, this.constructor, this.callStructure);
2951 3015
2952 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { 3016 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) {
2953 return visitor.visitThisConstructorInvoke( 3017 return visitor.visitThisConstructorInvoke(
2954 node, constructor, node.argumentsNode, callStructure, arg); 3018 node, constructor, node.argumentsNode, callStructure, arg);
2955 } 3019 }
2956 3020
2957 bool get isConstructorInvoke => true; 3021 bool get isConstructorInvoke => true;
2958 } 3022 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698