| 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:js_runtime/shared/embedded_names.dart'; | 5 import 'package:js_runtime/shared/embedded_names.dart'; |
| 6 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
| 7 | 7 |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
| 10 import '../compiler.dart'; | 10 import '../compiler.dart'; |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 557 |
| 558 ResolutionInterfaceType getInterfaceType(ir.InterfaceType type) => | 558 ResolutionInterfaceType getInterfaceType(ir.InterfaceType type) => |
| 559 getDartType(type); | 559 getDartType(type); |
| 560 | 560 |
| 561 ResolutionInterfaceType createInterfaceType( | 561 ResolutionInterfaceType createInterfaceType( |
| 562 ir.Class cls, List<ir.DartType> typeArguments) { | 562 ir.Class cls, List<ir.DartType> typeArguments) { |
| 563 return new ResolutionInterfaceType( | 563 return new ResolutionInterfaceType( |
| 564 getClass(cls), getDartTypes(typeArguments)); | 564 getClass(cls), getDartTypes(typeArguments)); |
| 565 } | 565 } |
| 566 | 566 |
| 567 /// Converts [annotations] into a list of [ConstantExpression]s. | |
| 568 List<ConstantExpression> getMetadata(List<ir.Expression> annotations) { | |
| 569 List<ConstantExpression> metadata = <ConstantExpression>[]; | |
| 570 annotations.forEach((ir.Expression node) { | |
| 571 ConstantExpression constant = node.accept(new Constantifier(this)); | |
| 572 if (constant == null) { | |
| 573 throw new UnsupportedError( | |
| 574 'No constant for ${DebugPrinter.prettyPrint(node)}'); | |
| 575 } | |
| 576 metadata.add(constant); | |
| 577 }); | |
| 578 return metadata; | |
| 579 } | |
| 580 | |
| 581 @override | 567 @override |
| 582 LibraryEntity lookupLibrary(Uri uri) { | 568 LibraryEntity lookupLibrary(Uri uri) { |
| 583 return _compiler.libraryLoader.lookupLibrary(uri); | 569 return _compiler.libraryLoader.lookupLibrary(uri); |
| 584 } | 570 } |
| 585 | 571 |
| 586 @override | 572 @override |
| 587 ClassElement lookupClass(LibraryElement library, String name) { | 573 ClassElement lookupClass(LibraryElement library, String name) { |
| 588 Element element = library.find(name); | 574 Element element = library.find(name); |
| 589 if (element != null && element.isClass) { | 575 if (element != null && element.isClass) { |
| 590 return element; | 576 return element; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 ResolutionDartType visitInvalidType(ir.InvalidType node) { | 709 ResolutionDartType visitInvalidType(ir.InvalidType node) { |
| 724 if (topLevel) { | 710 if (topLevel) { |
| 725 throw new UnimplementedError( | 711 throw new UnimplementedError( |
| 726 "Outermost invalid types not currently supported"); | 712 "Outermost invalid types not currently supported"); |
| 727 } | 713 } |
| 728 // Nested invalid types are treated as `dynamic`. | 714 // Nested invalid types are treated as `dynamic`. |
| 729 return const ResolutionDynamicType(); | 715 return const ResolutionDynamicType(); |
| 730 } | 716 } |
| 731 } | 717 } |
| 732 | 718 |
| 733 /// Visitor that converts a kernel constant expression into a | |
| 734 /// [ConstantExpression]. | |
| 735 class Constantifier extends ir.ExpressionVisitor<ConstantExpression> { | |
| 736 final KernelAstAdapter astAdapter; | |
| 737 | |
| 738 Constantifier(this.astAdapter); | |
| 739 | |
| 740 @override | |
| 741 ConstantExpression visitConstructorInvocation(ir.ConstructorInvocation node) { | |
| 742 ConstructorElement constructor = | |
| 743 astAdapter.getElement(node.target).declaration; | |
| 744 List<ResolutionDartType> typeArguments = <ResolutionDartType>[]; | |
| 745 for (ir.DartType type in node.arguments.types) { | |
| 746 typeArguments.add(astAdapter.getDartType(type)); | |
| 747 } | |
| 748 List<ConstantExpression> arguments = <ConstantExpression>[]; | |
| 749 List<String> argumentNames = <String>[]; | |
| 750 for (ir.Expression argument in node.arguments.positional) { | |
| 751 ConstantExpression constant = argument.accept(this); | |
| 752 if (constant == null) return null; | |
| 753 arguments.add(constant); | |
| 754 } | |
| 755 for (ir.NamedExpression argument in node.arguments.named) { | |
| 756 argumentNames.add(argument.name); | |
| 757 ConstantExpression constant = argument.value.accept(this); | |
| 758 if (constant == null) return null; | |
| 759 arguments.add(constant); | |
| 760 } | |
| 761 return new ConstructedConstantExpression( | |
| 762 constructor.enclosingClass.thisType.createInstantiation(typeArguments), | |
| 763 constructor, | |
| 764 new CallStructure( | |
| 765 node.arguments.positional.length + argumentNames.length, | |
| 766 argumentNames), | |
| 767 arguments); | |
| 768 } | |
| 769 | |
| 770 @override | |
| 771 ConstantExpression visitStaticGet(ir.StaticGet node) { | |
| 772 Element element = astAdapter.getMember(node.target); | |
| 773 if (element.isField) { | |
| 774 return new VariableConstantExpression(element); | |
| 775 } | |
| 776 astAdapter.reporter.internalError( | |
| 777 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element."); | |
| 778 return null; | |
| 779 } | |
| 780 | |
| 781 @override | |
| 782 ConstantExpression visitStringLiteral(ir.StringLiteral node) { | |
| 783 return new StringConstantExpression(node.value); | |
| 784 } | |
| 785 } | |
| 786 | |
| 787 class KernelJumpTarget extends JumpTarget { | 719 class KernelJumpTarget extends JumpTarget { |
| 788 static int index = 0; | 720 static int index = 0; |
| 789 | 721 |
| 790 /// Pointer to the actual executable statements that a jump target refers to. | 722 /// Pointer to the actual executable statements that a jump target refers to. |
| 791 /// If this jump target was not initially constructed with a LabeledStatement, | 723 /// If this jump target was not initially constructed with a LabeledStatement, |
| 792 /// this value is identical to originalStatement. | 724 /// this value is identical to originalStatement. |
| 793 // TODO(efortuna): In an ideal world the Node should be some common | 725 // TODO(efortuna): In an ideal world the Node should be some common |
| 794 // interface we create for both ir.Statements and ir.SwitchCase (the | 726 // interface we create for both ir.Statements and ir.SwitchCase (the |
| 795 // ContinueSwitchStatement's target is a SwitchCase) rather than general | 727 // ContinueSwitchStatement's target is a SwitchCase) rather than general |
| 796 // Node. Talking to Asger about this. | 728 // Node. Talking to Asger about this. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 JumpTarget continueTarget = | 825 JumpTarget continueTarget = |
| 894 astAdapter.getJumpTarget(switchCase, isContinueTarget: true); | 826 astAdapter.getJumpTarget(switchCase, isContinueTarget: true); |
| 895 assert(continueTarget is KernelJumpTarget); | 827 assert(continueTarget is KernelJumpTarget); |
| 896 targetIndexMap[continueTarget] = switchIndex; | 828 targetIndexMap[continueTarget] = switchIndex; |
| 897 assert(builder.jumpTargets[continueTarget] == null); | 829 assert(builder.jumpTargets[continueTarget] == null); |
| 898 builder.jumpTargets[continueTarget] = this; | 830 builder.jumpTargets[continueTarget] = this; |
| 899 switchIndex++; | 831 switchIndex++; |
| 900 } | 832 } |
| 901 } | 833 } |
| 902 } | 834 } |
| OLD | NEW |