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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2542783002: dart2js-kernel: Handle some more 'is' cases (Closed)
Patch Set: dartfmt Created 4 years 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
9 import '../common/names.dart'; 9 import '../common/names.dart';
10 import '../common/tasks.dart' show CompilerTask; 10 import '../common/tasks.dart' show CompilerTask;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 expression, graph.addConstantNull(compiler), null, backend.boolType)); 378 expression, graph.addConstantNull(compiler), null, backend.boolType));
379 } 379 }
380 380
381 @override 381 @override
382 void defaultExpression(ir.Expression expression) { 382 void defaultExpression(ir.Expression expression) {
383 // TODO(het): This is only to get tests working. 383 // TODO(het): This is only to get tests working.
384 String message = 'Unhandled ir.${expression.runtimeType} $expression'; 384 String message = 'Unhandled ir.${expression.runtimeType} $expression';
385 HInstruction nullValue = graph.addConstantNull(compiler); 385 HInstruction nullValue = graph.addConstantNull(compiler);
386 HInstruction errorMessage = 386 HInstruction errorMessage =
387 graph.addConstantString(new DartString.literal(message), compiler); 387 graph.addConstantString(new DartString.literal(message), compiler);
388 HInstruction trap = new HForeignCode( 388 HInstruction trap = new HForeignCode(js.js.parseForeignJS("#.#"),
389 js.js.parseForeignJS("#.#"), 389 backend.dynamicType, <HInstruction>[nullValue, errorMessage]);
390 backend.dynamicType, 390 trap.sideEffects
391 <HInstruction>[nullValue, errorMessage]); 391 ..setAllSideEffects()
392 trap.sideEffects..setAllSideEffects()..setDependsOnSomething(); 392 ..setDependsOnSomething();
393 push(trap); 393 push(trap);
394 } 394 }
395 395
396 /// Returns the current source element. 396 /// Returns the current source element.
397 /// 397 ///
398 /// The returned element is a declaration element. 398 /// The returned element is a declaration element.
399 // TODO(efortuna): Update this when we implement inlining. 399 // TODO(efortuna): Update this when we implement inlining.
400 @override 400 @override
401 Element get sourceElement => astAdapter.getElement(target); 401 Element get sourceElement => astAdapter.getElement(target);
402 402
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 // Invoke the getter 945 // Invoke the getter
946 _pushStaticInvocation(staticTarget, const <HInstruction>[], 946 _pushStaticInvocation(staticTarget, const <HInstruction>[],
947 astAdapter.returnTypeOf(staticTarget)); 947 astAdapter.returnTypeOf(staticTarget));
948 } else if (staticTarget is ir.Field && staticTarget.isConst) { 948 } else if (staticTarget is ir.Field && staticTarget.isConst) {
949 assert(staticTarget.initializer != null); 949 assert(staticTarget.initializer != null);
950 stack.add(graph.addConstant( 950 stack.add(graph.addConstant(
951 astAdapter.getConstantFor(staticTarget.initializer), compiler)); 951 astAdapter.getConstantFor(staticTarget.initializer), compiler));
952 } else { 952 } else {
953 if (_isLazyStatic(staticTarget)) { 953 if (_isLazyStatic(staticTarget)) {
954 push(new HLazyStatic(astAdapter.getField(staticTarget), 954 push(new HLazyStatic(astAdapter.getField(staticTarget),
955 astAdapter.inferredTypeOf(staticTarget))); 955 astAdapter.inferredTypeOf(staticTarget)));
956 } else { 956 } else {
957 push(new HStatic(astAdapter.getMember(staticTarget), 957 push(new HStatic(astAdapter.getMember(staticTarget),
958 astAdapter.inferredTypeOf(staticTarget))); 958 astAdapter.inferredTypeOf(staticTarget)));
959 } 959 }
960 } 960 }
961 } 961 }
962 962
963 bool _isLazyStatic(ir.Member target) { 963 bool _isLazyStatic(ir.Member target) {
964 return astAdapter.isLazyStatic(target); 964 return astAdapter.isLazyStatic(target);
965 } 965 }
966 966
967 @override 967 @override
968 void visitStaticSet(ir.StaticSet staticSet) { 968 void visitStaticSet(ir.StaticSet staticSet) {
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 TypeMask typeMask = new TypeMask.nonNullExact( 1634 TypeMask typeMask = new TypeMask.nonNullExact(
1635 astAdapter.getElement(target.enclosingClass), compiler.closedWorld); 1635 astAdapter.getElement(target.enclosingClass), compiler.closedWorld);
1636 _pushStaticInvocation(target, arguments, typeMask); 1636 _pushStaticInvocation(target, arguments, typeMask);
1637 } 1637 }
1638 1638
1639 @override 1639 @override
1640 void visitIsExpression(ir.IsExpression isExpression) { 1640 void visitIsExpression(ir.IsExpression isExpression) {
1641 isExpression.operand.accept(this); 1641 isExpression.operand.accept(this);
1642 HInstruction expression = pop(); 1642 HInstruction expression = pop();
1643 1643
1644 // TODO(sra): Convert the type testing logic here to use ir.DartType.
1644 DartType type = astAdapter.getDartType(isExpression.type); 1645 DartType type = astAdapter.getDartType(isExpression.type);
1645 1646
1647 type = localsHandler.substInContext(type).unaliased;
1648
1649 if (type is MethodTypeVariableType) {
1650 push(graph.addConstantBool(true, compiler));
1651 return;
1652 }
1653
1654 if (type is MalformedType) {
1655 ErroneousElement element = type.element;
1656 generateTypeError(isExpression, element.message);
1657 push(new HIs.compound(type, expression, pop(), backend.boolType));
1658 return;
1659 }
1660
1661 if (type.isFunctionType) {
1662 List arguments = <HInstruction>[buildFunctionType(type), expression];
1663 _pushDynamicInvocation(isExpression, backend.boolType, arguments,
1664 selector: new Selector.call(
1665 new PrivateName('_isTest', astAdapter.jsHelperLibrary),
1666 CallStructure.ONE_ARG));
1667 push(new HIs.compound(type, expression, pop(), backend.boolType));
1668 return;
1669 }
1670
1671 if (type.isTypeVariable) {
1672 HInstruction runtimeType =
1673 typeBuilder.addTypeVariableReference(type, sourceElement);
1674 _pushStaticInvocation(astAdapter.checkSubtypeOfRuntimeType,
1675 <HInstruction>[expression, runtimeType], backend.boolType);
1676 push(new HIs.variable(type, expression, pop(), backend.boolType));
1677 return;
1678 }
1679
1680 // TODO(sra): Type with type parameters.
1681
1646 if (backend.hasDirectCheckFor(type)) { 1682 if (backend.hasDirectCheckFor(type)) {
1647 push(new HIs.direct(type, expression, backend.boolType)); 1683 push(new HIs.direct(type, expression, backend.boolType));
1648 return; 1684 return;
1649 } 1685 }
1650 1686
1651 // The interceptor is not always needed. It is removed by optimization 1687 // The interceptor is not always needed. It is removed by optimization
1652 // when the receiver type or tested type permit. 1688 // when the receiver type or tested type permit.
1653 HInterceptor interceptor = _interceptorFor(expression); 1689 HInterceptor interceptor = _interceptorFor(expression);
1654 push(new HIs.raw(type, expression, interceptor, backend.boolType)); 1690 push(new HIs.raw(type, expression, interceptor, backend.boolType));
1655 } 1691 }
(...skipping 19 matching lines...) Expand all
1675 push(new HNot(popBoolified(), backend.boolType)); 1711 push(new HNot(popBoolified(), backend.boolType));
1676 } 1712 }
1677 1713
1678 @override 1714 @override
1679 void visitStringConcatenation(ir.StringConcatenation stringConcat) { 1715 void visitStringConcatenation(ir.StringConcatenation stringConcat) {
1680 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); 1716 KernelStringBuilder stringBuilder = new KernelStringBuilder(this);
1681 stringConcat.accept(stringBuilder); 1717 stringConcat.accept(stringBuilder);
1682 stack.add(stringBuilder.result); 1718 stack.add(stringBuilder.result);
1683 } 1719 }
1684 } 1720 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698