Chromium Code Reviews| Index: pkg/compiler/lib/src/kernel/no_such_method_resolver.dart |
| diff --git a/pkg/compiler/lib/src/kernel/no_such_method_resolver.dart b/pkg/compiler/lib/src/kernel/no_such_method_resolver.dart |
| index 7fc92d4f7d2fbb06282eb6c44f36fb1543d8fa5f..d8ae8ef5d61b23f113ff07397aaf0ad2005d6b3d 100644 |
| --- a/pkg/compiler/lib/src/kernel/no_such_method_resolver.dart |
| +++ b/pkg/compiler/lib/src/kernel/no_such_method_resolver.dart |
| @@ -9,21 +9,85 @@ class KernelNoSuchMethodResolver implements NoSuchMethodResolver { |
| KernelNoSuchMethodResolver(this.elementMap); |
| + ElementEnvironment get _elementEnvironment => elementMap.elementEnvironment; |
| + |
| + CommonElements get _commonElements => elementMap.commonElements; |
| + |
| @override |
| bool hasForwardingSyntax(KFunction method) { |
| - throw new UnimplementedError( |
| - "KernelNoSuchMethodResolver.hasForwardingSyntax"); |
| + 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.
|
| + if (node.function.positionalParameters.isEmpty) return false; |
| + ir.VariableDeclaration firstParameter = |
| + node.function.positionalParameters.first; |
| + ir.Statement body = node.function.body; |
| + ir.Expression expr; |
| + if (body is ir.ReturnStatement) { |
| + expr = body.expression; |
| + } 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...
|
| + ir.Statement first = body.statements.first; |
| + if (first is ir.ReturnStatement) { |
| + expr = first.expression; |
| + } |
| + } |
| + if (expr is ir.AsExpression && |
| + elementMap.getDartType(expr.type) == _commonElements.dynamicType) { |
| + ir.AsExpression asExpression = expr; |
| + expr = asExpression.operand; |
| + } |
| + if (expr is ir.SuperMethodInvocation && |
| + expr.name.name == Identifiers.noSuchMethod_) { |
| + ir.Arguments arguments = expr.arguments; |
| + if (arguments.positional.length == 1 && |
| + arguments.named.isEmpty && |
| + arguments.positional.first is ir.VariableGet) { |
| + ir.VariableGet get = arguments.positional.first; |
| + return get.variable == firstParameter; |
| + } |
| + } |
| + return false; |
| } |
| @override |
| bool hasThrowingSyntax(KFunction method) { |
| - throw new UnimplementedError( |
| - "KernelNoSuchMethodResolver.hasThrowingSyntax"); |
| + ir.Procedure node = elementMap._memberList[method.memberIndex].node; |
| + ir.Statement body = node.function.body; |
| + ir.Expression expr; |
| + if (body is ir.ReturnStatement) { |
| + expr = body.expression; |
| + } else if (body is ir.ExpressionStatement) { |
| + expr = body.expression; |
| + } 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.
|
| + ir.Statement first = body.statements.first; |
| + if (first is ir.ReturnStatement) { |
| + expr = first.expression; |
| + } else if (first is ir.ExpressionStatement) { |
| + expr = first.expression; |
| + } |
| + } |
| + return expr is ir.Throw; |
| } |
| @override |
| FunctionEntity getSuperNoSuchMethod(FunctionEntity method) { |
| - throw new UnimplementedError( |
| - "KernelNoSuchMethodResolver.getSuperNoSuchMethod"); |
| + ClassEntity cls = method.enclosingClass; |
| + while (cls != null) { |
| + cls = _elementEnvironment.getSuperClass(cls); |
| + MemberEntity member = |
| + _elementEnvironment.lookupClassMember(cls, Identifiers.noSuchMethod_); |
| + if (member != null) { |
| + if (member.isFunction) { |
| + FunctionEntity function = member; |
| + if (function.parameterStructure.positionalParameters >= 1) { |
| + return function; |
| + } |
| + } |
| + 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!
|
| + } |
| + } |
| + FunctionEntity function = _elementEnvironment.lookupClassMember( |
| + _commonElements.objectClass, Identifiers.noSuchMethod_); |
| + assert(invariant(method, function != null, |
| + message: "No super noSuchMethod found for $method.")); |
| + return function; |
| } |
| } |