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

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

Issue 2857943002: Implement KernelNoSuchMethodResolver. (Closed)
Patch Set: Updated cf. comments 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import '../common/names.dart' show Identifiers, Names;
6 import '../elements/elements.dart';
7 import '../js_backend/no_such_method_registry.dart';
8 import '../tree/tree.dart';
9
10 /// AST-based implementation of [NoSuchMethodResolver].
11 class ResolutionNoSuchMethodResolver implements NoSuchMethodResolver {
12 bool hasForwardingSyntax(MethodElement element) {
13 // At this point we know that this is signature-compatible with
14 // Object.noSuchMethod, but it may have more than one argument as long as
15 // it only has one required argument.
16 if (!element.hasResolvedAst) {
17 // TODO(johnniwinther): Why do we see unresolved elements here?
18 return false;
19 }
20 ResolvedAst resolvedAst = element.resolvedAst;
21 if (resolvedAst.kind != ResolvedAstKind.PARSED) {
22 return false;
23 }
24 String param = element.parameters.first.name;
25 Statement body = resolvedAst.body;
26 Expression expr;
27 if (body is Return && body.isArrowBody) {
28 expr = body.expression;
29 } else if (body is Block &&
30 !body.statements.isEmpty &&
31 body.statements.nodes.tail.isEmpty) {
32 Statement stmt = body.statements.nodes.head;
33 if (stmt is Return && stmt.hasExpression) {
34 expr = stmt.expression;
35 }
36 }
37 if (expr is Send && expr.isTypeCast) {
38 Send sendExpr = expr;
39 var typeAnnotation = sendExpr.typeAnnotationFromIsCheckOrCast;
40 var typeName = typeAnnotation.asNominalTypeAnnotation()?.typeName;
41 if (typeName is Identifier && typeName.source == "dynamic") {
42 expr = sendExpr.receiver;
43 }
44 }
45 if (expr is Send &&
46 expr.isSuperCall &&
47 expr.selector is Identifier &&
48 (expr.selector as Identifier).source == Identifiers.noSuchMethod_) {
49 var arg = expr.arguments.head;
50 if (expr.arguments.tail.isEmpty &&
51 arg is Send &&
52 arg.argumentsNode == null &&
53 arg.receiver == null &&
54 arg.selector is Identifier &&
55 arg.selector.source == param) {
56 return true;
57 }
58 }
59 return false;
60 }
61
62 bool hasThrowingSyntax(MethodElement element) {
63 if (!element.hasResolvedAst) {
64 // TODO(johnniwinther): Why do we see unresolved elements here?
65 return false;
66 }
67 ResolvedAst resolvedAst = element.resolvedAst;
68 if (resolvedAst.kind != ResolvedAstKind.PARSED) {
69 return false;
70 }
71 Statement body = resolvedAst.body;
72 if (body is Return && body.isArrowBody) {
73 if (body.expression is Throw) {
74 return true;
75 }
76 } else if (body is Block &&
77 !body.statements.isEmpty &&
78 body.statements.nodes.tail.isEmpty) {
79 if (body.statements.nodes.head is ExpressionStatement) {
80 ExpressionStatement stmt = body.statements.nodes.head;
81 return stmt.expression is Throw;
82 }
83 }
84 return false;
85 }
86
87 MethodElement getSuperNoSuchMethod(MethodElement method) {
88 return method.enclosingClass.lookupSuperByName(Names.noSuchMethod_);
89 }
90 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/no_such_method_resolver.dart ('k') | pkg/compiler/lib/src/resolution/resolution_strategy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698