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

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: Updated cf. comments. 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(
2668 effectiveTarget.functionSignature)) {
2669 return visitor.visitRedirectingFactoryConstructorInvoke(
2670 node, semantics.element, semantics.type,
2671 effectiveTarget, effectiveTargetType,
2672 node.send.argumentsNode, callStructure, arg);
2673 } else {
2674 return visitor.visitUnresolvedRedirectingFactoryConstructorInvoke(
2675 node, semantics.element, semantics.type,
2676 node.send.argumentsNode, callStructure, arg);
2677 }
2678 }
2679 if (callStructure.signatureApplies(constructor.functionSignature)) {
2680 return visitor.visitFactoryConstructorInvoke(
2681 node, constructor, semantics.type,
2682 node.send.argumentsNode, callStructure, arg);
2683 }
2684 return visitor.visitConstructorIncompatibleInvoke(
2685 node, constructor, semantics.type,
2661 node.send.argumentsNode, callStructure, arg); 2686 node.send.argumentsNode, callStructure, arg);
2662 case ConstructorAccessKind.ABSTRACT: 2687 case ConstructorAccessKind.ABSTRACT:
2663 return visitor.visitAbstractClassConstructorInvoke( 2688 return visitor.visitAbstractClassConstructorInvoke(
2664 node, semantics.element, semantics.type, 2689 node, semantics.element, semantics.type,
2665 node.send.argumentsNode, callStructure, arg); 2690 node.send.argumentsNode, callStructure, arg);
2666 case ConstructorAccessKind.UNRESOLVED_CONSTRUCTOR: 2691 case ConstructorAccessKind.UNRESOLVED_CONSTRUCTOR:
2667 return visitor.visitUnresolvedConstructorInvoke( 2692 return visitor.visitUnresolvedConstructorInvoke(
2668 node, semantics.element, semantics.type, 2693 node, semantics.element, semantics.type,
2669 node.send.argumentsNode, selector, arg); 2694 node.send.argumentsNode, selector, arg);
2670 case ConstructorAccessKind.UNRESOLVED_TYPE: 2695 case ConstructorAccessKind.UNRESOLVED_TYPE:
2671 return visitor.visitUnresolvedClassConstructorInvoke( 2696 return visitor.visitUnresolvedClassConstructorInvoke(
2672 node, semantics.element, semantics.type, 2697 node, semantics.element, semantics.type,
2673 node.send.argumentsNode, selector, arg); 2698 node.send.argumentsNode, selector, arg);
2674 case ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR: 2699 case ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR:
2675 return visitor.errorNonConstantConstructorInvoke( 2700 return visitor.errorNonConstantConstructorInvoke(
2676 node, semantics.element, semantics.type, 2701 node, semantics.element, semantics.type,
2677 node.send.argumentsNode, callStructure, arg); 2702 node.send.argumentsNode, callStructure, arg);
2678 case ConstructorAccessKind.ERRONEOUS_REDIRECTING_FACTORY:
2679 return visitor.visitUnresolvedRedirectingFactoryConstructorInvoke(
2680 node, semantics.element, semantics.type,
2681 node.send.argumentsNode, callStructure, arg);
2682 case ConstructorAccessKind.INCOMPATIBLE: 2703 case ConstructorAccessKind.INCOMPATIBLE:
2683 return visitor.visitConstructorIncompatibleInvoke( 2704 return visitor.visitConstructorIncompatibleInvoke(
2684 node, semantics.element, semantics.type, 2705 node, semantics.element, semantics.type,
2685 node.send.argumentsNode, callStructure, arg); 2706 node.send.argumentsNode, callStructure, arg);
2686 } 2707 }
2687 throw new SpannableAssertionFailure(node, 2708 throw new SpannableAssertionFailure(node,
2688 "Unhandled constructor invocation kind: ${semantics.kind}"); 2709 "Unhandled constructor invocation kind: ${semantics.kind}");
2689 } 2710 }
2690 2711
2691 String toString() => 'new($semantics,$selector)'; 2712 String toString() => 'new($semantics,$selector)';
(...skipping 24 matching lines...) Expand all
2716 case ConstantInvokeKind.INT_FROM_ENVIRONMENT: 2737 case ConstantInvokeKind.INT_FROM_ENVIRONMENT:
2717 return visitor.visitIntFromEnvironmentConstructorInvoke( 2738 return visitor.visitIntFromEnvironmentConstructorInvoke(
2718 node, constant, arg); 2739 node, constant, arg);
2719 case ConstantInvokeKind.STRING_FROM_ENVIRONMENT: 2740 case ConstantInvokeKind.STRING_FROM_ENVIRONMENT:
2720 return visitor.visitStringFromEnvironmentConstructorInvoke( 2741 return visitor.visitStringFromEnvironmentConstructorInvoke(
2721 node, constant, arg); 2742 node, constant, arg);
2722 } 2743 }
2723 } 2744 }
2724 } 2745 }
2725 2746
2747 /// A constant constructor invocation that couldn't be determined fully during
2748 /// resolution.
2749 // TODO(johnniwinther): Remove this when all constants are computed during
2750 // resolution.
2751 class LateConstInvokeStructure<R, A> extends NewStructure<R, A> {
2752 final TreeElements elements;
2753
2754 LateConstInvokeStructure(this.elements);
2755
2756 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) {
2757 Element element = elements[node.send];
2758 Selector selector = elements.getSelector(node.send);
2759 DartType type = elements.getType(node);
2760 ConstantExpression constant = elements.getConstant(node);
2761 if (element.isMalformed ||
2762 constant == null ||
2763 constant.kind == ConstantExpressionKind.ERRONEOUS) {
2764 // This is a non-constant constant constructor invocation, like
2765 // `const Const(method())`.
2766 return visitor.errorNonConstantConstructorInvoke(
2767 node, element, type,
2768 node.send.argumentsNode, selector.callStructure, arg);
2769 } else {
2770 ConstantInvokeKind kind;
2771 switch (constant.kind) {
2772 case ConstantExpressionKind.CONSTRUCTED:
2773 return visitor.visitConstConstructorInvoke(node, constant, arg);
2774 case ConstantExpressionKind.BOOL_FROM_ENVIRONMENT:
2775 return visitor.visitBoolFromEnvironmentConstructorInvoke(
2776 node, constant, arg);
2777 case ConstantExpressionKind.INT_FROM_ENVIRONMENT:
2778 return visitor.visitIntFromEnvironmentConstructorInvoke(
2779 node, constant, arg);
2780 case ConstantExpressionKind.STRING_FROM_ENVIRONMENT:
2781 return visitor.visitStringFromEnvironmentConstructorInvoke(
2782 node, constant, arg);
2783 default:
2784 throw new SpannableAssertionFailure(
2785 node, "Unexpected constant kind $kind: ${constant.getText()}");
2786 }
2787 }
2788 }
2789 }
2790
2726 /// The structure of a parameter declaration. 2791 /// The structure of a parameter declaration.
2727 abstract class ParameterStructure<R, A> { 2792 abstract class ParameterStructure<R, A> {
2728 final VariableDefinitions definitions; 2793 final VariableDefinitions definitions;
2729 final Node node; 2794 final Node node;
2730 final ParameterElement parameter; 2795 final ParameterElement parameter;
2731 2796
2732 ParameterStructure(this.definitions, this.node, this.parameter); 2797 ParameterStructure(this.definitions, this.node, this.parameter);
2733 2798
2734 /// Calls the matching visit method on [visitor] with [definitions] and [arg]. 2799 /// Calls the matching visit method on [visitor] with [definitions] and [arg].
2735 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg); 2800 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2949 ThisConstructorInvokeStructure( 3014 ThisConstructorInvokeStructure(
2950 this.node, this.constructor, this.callStructure); 3015 this.node, this.constructor, this.callStructure);
2951 3016
2952 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) { 3017 R dispatch(SemanticDeclarationVisitor<R, A> visitor, A arg) {
2953 return visitor.visitThisConstructorInvoke( 3018 return visitor.visitThisConstructorInvoke(
2954 node, constructor, node.argumentsNode, callStructure, arg); 3019 node, constructor, node.argumentsNode, callStructure, arg);
2955 } 3020 }
2956 3021
2957 bool get isConstructorInvoke => true; 3022 bool get isConstructorInvoke => true;
2958 } 3023 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/send_resolver.dart ('k') | pkg/compiler/lib/src/resolution/tree_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698