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

Side by Side Diff: pkg/kernel/lib/ast.dart

Issue 2923653003: Change MethodInvocation.interfaceTarget from a Procedure to a Member. (Closed)
Patch Set: Update after https://codereview.chromium.org/2920223008/ Created 3 years, 6 months 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /// ----------------------------------------------------------------------- 5 /// -----------------------------------------------------------------------
6 /// ERROR HANDLING 6 /// ERROR HANDLING
7 /// ----------------------------------------------------------------------- 7 /// -----------------------------------------------------------------------
8 /// 8 ///
9 /// As a rule of thumb, errors that can be detected statically are handled by 9 /// As a rule of thumb, errors that can be detected statically are handled by
10 /// the frontend, typically by translating the erroneous code into a 'throw' or 10 /// the frontend, typically by translating the erroneous code into a 'throw' or
(...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 2125
2126 /// Expression of form `x.foo(y)`. 2126 /// Expression of form `x.foo(y)`.
2127 class MethodInvocation extends InvocationExpression { 2127 class MethodInvocation extends InvocationExpression {
2128 Expression receiver; 2128 Expression receiver;
2129 Name name; 2129 Name name;
2130 Arguments arguments; 2130 Arguments arguments;
2131 2131
2132 Reference interfaceTargetReference; 2132 Reference interfaceTargetReference;
2133 2133
2134 MethodInvocation(Expression receiver, Name name, Arguments arguments, 2134 MethodInvocation(Expression receiver, Name name, Arguments arguments,
2135 [Procedure interfaceTarget]) 2135 [Member interfaceTarget])
2136 : this.byReference( 2136 : this.byReference(
2137 receiver, name, arguments, getMemberReference(interfaceTarget)); 2137 receiver, name, arguments, getMemberReference(interfaceTarget));
2138 2138
2139 MethodInvocation.byReference( 2139 MethodInvocation.byReference(
2140 this.receiver, this.name, this.arguments, this.interfaceTargetReference) { 2140 this.receiver, this.name, this.arguments, this.interfaceTargetReference) {
2141 receiver?.parent = this; 2141 receiver?.parent = this;
2142 arguments?.parent = this; 2142 arguments?.parent = this;
2143 } 2143 }
2144 2144
2145 Procedure get interfaceTarget => interfaceTargetReference?.asProcedure; 2145 Member get interfaceTarget => interfaceTargetReference?.asMember;
2146 2146
2147 void set interfaceTarget(Member target) { 2147 void set interfaceTarget(Member target) {
2148 interfaceTargetReference = getMemberReference(target); 2148 interfaceTargetReference = getMemberReference(target);
2149 } 2149 }
2150 2150
2151 DartType getStaticType(TypeEnvironment types) { 2151 DartType getStaticType(TypeEnvironment types) {
2152 var interfaceTarget = this.interfaceTarget;
2152 if (interfaceTarget != null) { 2153 if (interfaceTarget != null) {
2153 if (types.isOverloadedArithmeticOperator(interfaceTarget)) { 2154 if (interfaceTarget is Procedure &&
2155 types.isOverloadedArithmeticOperator(interfaceTarget)) {
2154 return types.getTypeOfOverloadedArithmetic( 2156 return types.getTypeOfOverloadedArithmetic(
2155 receiver.getStaticType(types), 2157 receiver.getStaticType(types),
2156 arguments.positional[0].getStaticType(types)); 2158 arguments.positional[0].getStaticType(types));
2157 } 2159 }
2158 Class superclass = interfaceTarget.enclosingClass; 2160 Class superclass = interfaceTarget.enclosingClass;
2159 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types); 2161 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types);
2160 var returnType = Substitution 2162 var getterType = Substitution
2161 .fromInterfaceType(receiverType) 2163 .fromInterfaceType(receiverType)
2162 .substituteType(interfaceTarget.function.returnType); 2164 .substituteType(interfaceTarget.getterType);
2163 return Substitution 2165 if (getterType is FunctionType) {
2164 .fromPairs(interfaceTarget.function.typeParameters, arguments.types) 2166 return Substitution
2165 .substituteType(returnType); 2167 .fromPairs(getterType.typeParameters, arguments.types)
2168 .substituteType(getterType.returnType);
2169 } else {
2170 return const DynamicType();
2171 }
2166 } 2172 }
2167 if (name.name == 'call') { 2173 if (name.name == 'call') {
2168 var receiverType = receiver.getStaticType(types); 2174 var receiverType = receiver.getStaticType(types);
2169 if (receiverType is FunctionType) { 2175 if (receiverType is FunctionType) {
2170 if (receiverType.typeParameters.length != arguments.types.length) { 2176 if (receiverType.typeParameters.length != arguments.types.length) {
2171 return const BottomType(); 2177 return const BottomType();
2172 } 2178 }
2173 return Substitution 2179 return Substitution
2174 .fromPairs(receiverType.typeParameters, arguments.types) 2180 .fromPairs(receiverType.typeParameters, arguments.types)
2175 .substituteType(receiverType.returnType); 2181 .substituteType(receiverType.returnType);
(...skipping 2428 matching lines...) Expand 10 before | Expand all | Expand 10 after
4604 /// typedef has not been assigned a canonical name yet. 4610 /// typedef has not been assigned a canonical name yet.
4605 /// 4611 ///
4606 /// Returns `null` if the typedef is `null`. 4612 /// Returns `null` if the typedef is `null`.
4607 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) { 4613 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) {
4608 if (typedef_ == null) return null; 4614 if (typedef_ == null) return null;
4609 if (typedef_.canonicalName == null) { 4615 if (typedef_.canonicalName == null) {
4610 throw '$typedef_ has no canonical name'; 4616 throw '$typedef_ has no canonical name';
4611 } 4617 }
4612 return typedef_.canonicalName; 4618 return typedef_.canonicalName;
4613 } 4619 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698