OLD | NEW |
---|---|
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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 | 6 |
7 import '../closure.dart'; | 7 import '../closure.dart'; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
(...skipping 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1935 } | 1935 } |
1936 | 1936 |
1937 @override | 1937 @override |
1938 void visitIsExpression(ir.IsExpression isExpression) { | 1938 void visitIsExpression(ir.IsExpression isExpression) { |
1939 isExpression.operand.accept(this); | 1939 isExpression.operand.accept(this); |
1940 HInstruction expression = pop(); | 1940 HInstruction expression = pop(); |
1941 push(buildIsNode(isExpression, isExpression.type, expression)); | 1941 push(buildIsNode(isExpression, isExpression.type, expression)); |
1942 } | 1942 } |
1943 | 1943 |
1944 HInstruction buildIsNode( | 1944 HInstruction buildIsNode( |
1945 ir.Node node, ir.DartType dart_type, HInstruction expression) { | 1945 ir.Node node, ir.DartType type, HInstruction expression) { |
1946 // TODO(sra): Convert the type testing logic here to use ir.DartType. | 1946 if (type is ir.InvalidType) { |
1947 DartType type = astAdapter.getDartType(dart_type); | 1947 generateTypeError(node, |
1948 | 1948 (astAdapter.getDartType(type).element as ErroneousElement).message); |
Siggi Cherem (dart-lang)
2016/12/20 22:37:30
we call astAdapter.getDartType on all branches her
Emily Fortuna
2016/12/22 19:22:12
Done.
| |
1949 type = localsHandler.substInContext(type).unaliased; | 1949 return new HIs.compound(astAdapter.getDartType(type), expression, pop(), |
Siggi Cherem (dart-lang)
2016/12/20 22:37:29
Are the kernel type-variables substituted by the t
| |
1950 | 1950 commonMasks.boolType); |
1951 if (type is MethodTypeVariableType) { | 1951 } else if (type is ir.FunctionType) { |
Siggi Cherem (dart-lang)
2016/12/20 22:37:30
style nit (here and below): I know this comes from
Emily Fortuna
2016/12/22 19:22:12
ah, I didn't know this was the preferred style. Fi
| |
1952 return graph.addConstantBool(true, closedWorld); | 1952 List arguments = [ |
1953 } | 1953 buildFunctionType(astAdapter.getDartType(type)), |
1954 | 1954 expression |
1955 if (type is MalformedType) { | 1955 ]; |
1956 ErroneousElement element = type.element; | 1956 _pushDynamicInvocation(node, null, arguments, |
1957 generateTypeError(node, element.message); | |
1958 return new HIs.compound(type, expression, pop(), commonMasks.boolType); | |
1959 } | |
1960 | |
1961 if (type.isFunctionType) { | |
1962 List arguments = <HInstruction>[buildFunctionType(type), expression]; | |
1963 _pushDynamicInvocation(node, commonMasks.boolType, arguments, | |
1964 selector: new Selector.call( | 1957 selector: new Selector.call( |
1965 new PrivateName('_isTest', astAdapter.jsHelperLibrary), | 1958 new PrivateName('_isTest', backend.helpers.jsHelperLibrary), |
1966 CallStructure.ONE_ARG)); | 1959 CallStructure.ONE_ARG)); |
1967 return new HIs.compound(type, expression, pop(), commonMasks.boolType); | 1960 return new HIs.compound(astAdapter.getDartType(type), expression, pop(), |
1968 } | 1961 commonMasks.boolType); |
1969 | 1962 } else if (type is ir.TypeParameterType) { |
1970 if (type.isTypeVariable) { | 1963 HInstruction runtimeType = typeBuilder.addTypeVariableReference( |
1971 HInstruction runtimeType = | 1964 astAdapter.getDartType(type), sourceElement); |
1972 typeBuilder.addTypeVariableReference(type, sourceElement); | |
1973 _pushStaticInvocation(astAdapter.checkSubtypeOfRuntimeType, | 1965 _pushStaticInvocation(astAdapter.checkSubtypeOfRuntimeType, |
1974 <HInstruction>[expression, runtimeType], commonMasks.boolType); | 1966 <HInstruction>[expression, runtimeType], commonMasks.boolType); |
1975 return new HIs.variable(type, expression, pop(), commonMasks.boolType); | 1967 return new HIs.variable(astAdapter.getDartType(type), expression, pop(), |
1968 commonMasks.boolType); | |
1969 } else if (_isInterfaceWithNoRawTypes(type)) { | |
1970 HInstruction representations = | |
1971 typeBuilder.buildTypeArgumentRepresentations( | |
1972 astAdapter.getDartType(type), sourceElement); | |
1973 add(representations); | |
1974 ClassElement element = astAdapter.getDartType(type).element; | |
1975 js.Name operator = backend.namer.operatorIs(element); | |
1976 HInstruction isFieldName = | |
1977 graph.addConstantStringFromName(operator, closedWorld); | |
1978 HInstruction asFieldName = | |
1979 closedWorld.hasAnyStrictSubtype(element) | |
1980 ? graph.addConstantStringFromName( | |
1981 backend.namer.substitutionName(element), closedWorld) | |
1982 : graph.addConstantNull(closedWorld); | |
1983 List<HInstruction> inputs = <HInstruction>[ | |
1984 expression, | |
1985 isFieldName, | |
1986 representations, | |
1987 asFieldName | |
1988 ]; | |
1989 _pushStaticInvocation( | |
1990 astAdapter.checkSubtype, inputs, commonMasks.boolType); | |
1991 return new HIs.compound(astAdapter.getDartType(type), expression, pop(), | |
1992 commonMasks.boolType); | |
1993 } else { | |
1994 if (backend.hasDirectCheckFor(astAdapter.getDartType(type))) { | |
1995 return new HIs.direct( | |
1996 astAdapter.getDartType(type), expression, commonMasks.boolType); | |
1997 } | |
1998 // The interceptor is not always needed. It is removed by optimization | |
1999 // when the receiver type or tested type permit. | |
2000 return new HIs.raw(astAdapter.getDartType(type), expression, | |
2001 _interceptorFor(expression), commonMasks.boolType); | |
1976 } | 2002 } |
2003 } | |
1977 | 2004 |
1978 // TODO(sra): Type with type parameters. | 2005 bool _isInterfaceWithNoRawTypes(ir.DartType type) { |
Siggi Cherem (dart-lang)
2016/12/20 22:37:30
nit: we might need a different name here. One idea
Emily Fortuna
2016/12/22 19:22:12
Done.
| |
1979 | 2006 return type is ir.InterfaceType && |
1980 if (backend.hasDirectCheckFor(type)) { | 2007 (type as ir.InterfaceType) |
1981 return new HIs.direct(type, expression, commonMasks.boolType); | 2008 .typeArguments |
1982 } | 2009 .any((ir.DartType typeArgType) => typeArgType is! ir.DynamicType); |
Siggi Cherem (dart-lang)
2016/12/20 22:37:30
I believe we should also exclude a couple other ca
Emily Fortuna
2016/12/22 19:22:12
Done.
| |
1983 | |
1984 // The interceptor is not always needed. It is removed by optimization | |
1985 // when the receiver type or tested type permit. | |
1986 HInterceptor interceptor = _interceptorFor(expression); | |
1987 return new HIs.raw(type, expression, interceptor, commonMasks.boolType); | |
1988 } | 2010 } |
1989 | 2011 |
1990 @override | 2012 @override |
1991 void visitThrow(ir.Throw throwNode) { | 2013 void visitThrow(ir.Throw throwNode) { |
1992 _visitThrowExpression(throwNode.expression); | 2014 _visitThrowExpression(throwNode.expression); |
1993 if (isReachable) { | 2015 if (isReachable) { |
1994 push(new HThrowExpression(pop(), null)); | 2016 push(new HThrowExpression(pop(), null)); |
1995 isReachable = false; | 2017 isReachable = false; |
1996 } | 2018 } |
1997 } | 2019 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2279 kernelBuilder.open(exitBlock); | 2301 kernelBuilder.open(exitBlock); |
2280 enterBlock.setBlockFlow( | 2302 enterBlock.setBlockFlow( |
2281 new HTryBlockInformation( | 2303 new HTryBlockInformation( |
2282 kernelBuilder.wrapStatementGraph(bodyGraph), | 2304 kernelBuilder.wrapStatementGraph(bodyGraph), |
2283 exception, | 2305 exception, |
2284 kernelBuilder.wrapStatementGraph(catchGraph), | 2306 kernelBuilder.wrapStatementGraph(catchGraph), |
2285 kernelBuilder.wrapStatementGraph(finallyGraph)), | 2307 kernelBuilder.wrapStatementGraph(finallyGraph)), |
2286 exitBlock); | 2308 exitBlock); |
2287 } | 2309 } |
2288 } | 2310 } |
OLD | NEW |