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

Side by Side Diff: pkg/compiler/lib/src/kernel/no_such_method_resolver.dart

Issue 2857943002: Implement KernelNoSuchMethodResolver. (Closed)
Patch Set: Created 3 years, 7 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 part of dart2js.kernel.element_map; 5 part of dart2js.kernel.element_map;
6 6
7 class KernelNoSuchMethodResolver implements NoSuchMethodResolver { 7 class KernelNoSuchMethodResolver implements NoSuchMethodResolver {
8 final KernelToElementMap elementMap; 8 final KernelToElementMap elementMap;
9 9
10 KernelNoSuchMethodResolver(this.elementMap); 10 KernelNoSuchMethodResolver(this.elementMap);
11 11
12 ElementEnvironment get _elementEnvironment => elementMap.elementEnvironment;
13
14 CommonElements get _commonElements => elementMap.commonElements;
15
12 @override 16 @override
13 bool hasForwardingSyntax(KFunction method) { 17 bool hasForwardingSyntax(KFunction method) {
14 throw new UnimplementedError( 18 ir.Procedure node = elementMap._memberList[method.memberIndex].node;
Siggi Cherem (dart-lang) 2017/05/03 17:29:49 Since we are preparing to move this file as a sepa
Johnni Winther 2017/05/04 09:13:36 Done.
15 "KernelNoSuchMethodResolver.hasForwardingSyntax"); 19 if (node.function.positionalParameters.isEmpty) return false;
20 ir.VariableDeclaration firstParameter =
21 node.function.positionalParameters.first;
22 ir.Statement body = node.function.body;
23 ir.Expression expr;
24 if (body is ir.ReturnStatement) {
25 expr = body.expression;
26 } else if (body is ir.Block && body.statements.isNotEmpty) {
Siggi Cherem (dart-lang) 2017/05/03 17:29:49 ha - the old implementation checked that statement
Johnni Winther 2017/05/04 09:13:35 Ahh - I thought I was equally silly...
27 ir.Statement first = body.statements.first;
28 if (first is ir.ReturnStatement) {
29 expr = first.expression;
30 }
31 }
32 if (expr is ir.AsExpression &&
33 elementMap.getDartType(expr.type) == _commonElements.dynamicType) {
34 ir.AsExpression asExpression = expr;
35 expr = asExpression.operand;
36 }
37 if (expr is ir.SuperMethodInvocation &&
38 expr.name.name == Identifiers.noSuchMethod_) {
39 ir.Arguments arguments = expr.arguments;
40 if (arguments.positional.length == 1 &&
41 arguments.named.isEmpty &&
42 arguments.positional.first is ir.VariableGet) {
43 ir.VariableGet get = arguments.positional.first;
44 return get.variable == firstParameter;
45 }
46 }
47 return false;
16 } 48 }
17 49
18 @override 50 @override
19 bool hasThrowingSyntax(KFunction method) { 51 bool hasThrowingSyntax(KFunction method) {
20 throw new UnimplementedError( 52 ir.Procedure node = elementMap._memberList[method.memberIndex].node;
21 "KernelNoSuchMethodResolver.hasThrowingSyntax"); 53 ir.Statement body = node.function.body;
54 ir.Expression expr;
55 if (body is ir.ReturnStatement) {
56 expr = body.expression;
57 } else if (body is ir.ExpressionStatement) {
58 expr = body.expression;
59 } else if (body is ir.Block && body.statements.isNotEmpty) {
Siggi Cherem (dart-lang) 2017/05/03 17:29:49 nit: move this out first, so we can reuse the othe
Johnni Winther 2017/05/04 09:13:36 Done.
60 ir.Statement first = body.statements.first;
61 if (first is ir.ReturnStatement) {
62 expr = first.expression;
63 } else if (first is ir.ExpressionStatement) {
64 expr = first.expression;
65 }
66 }
67 return expr is ir.Throw;
22 } 68 }
23 69
24 @override 70 @override
25 FunctionEntity getSuperNoSuchMethod(FunctionEntity method) { 71 FunctionEntity getSuperNoSuchMethod(FunctionEntity method) {
26 throw new UnimplementedError( 72 ClassEntity cls = method.enclosingClass;
27 "KernelNoSuchMethodResolver.getSuperNoSuchMethod"); 73 while (cls != null) {
74 cls = _elementEnvironment.getSuperClass(cls);
75 MemberEntity member =
76 _elementEnvironment.lookupClassMember(cls, Identifiers.noSuchMethod_);
77 if (member != null) {
78 if (member.isFunction) {
79 FunctionEntity function = member;
80 if (function.parameterStructure.positionalParameters >= 1) {
81 return function;
82 }
83 }
84 break;
Siggi Cherem (dart-lang) 2017/05/03 17:29:49 not sure what this case does - if you have a noSuc
Johnni Winther 2017/05/04 09:13:36 Yep. That's the spec!
85 }
86 }
87 FunctionEntity function = _elementEnvironment.lookupClassMember(
88 _commonElements.objectClass, Identifiers.noSuchMethod_);
89 assert(invariant(method, function != null,
90 message: "No super noSuchMethod found for $method."));
91 return function;
28 } 92 }
29 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698