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 library kernel.ast_from_binary; | 4 library kernel.ast_from_binary; |
5 | 5 |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import '../ast.dart'; | 9 import '../ast.dart'; |
10 import '../transformations/flags.dart'; | 10 import '../transformations/flags.dart'; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 361 |
362 void _readDeferredImports(Library library) { | 362 void _readDeferredImports(Library library) { |
363 int length = readUInt(); | 363 int length = readUInt(); |
364 if (library.isExternal) { | 364 if (library.isExternal) { |
365 assert(length == 0); | 365 assert(length == 0); |
366 return; | 366 return; |
367 } | 367 } |
368 library.deferredImports.length = length; | 368 library.deferredImports.length = length; |
369 for (int i = 0; i < length; ++i) { | 369 for (int i = 0; i < length; ++i) { |
370 library.deferredImports[i] = new DeferredImport.byReference( | 370 library.deferredImports[i] = new DeferredImport.byReference( |
371 readLibraryReference(), readStringReference())..parent = library; | 371 readLibraryReference(), readStringReference()) |
| 372 ..parent = library; |
372 } | 373 } |
373 } | 374 } |
374 | 375 |
375 Class readClass() { | 376 Class readClass() { |
376 int tag = readByte(); | 377 int tag = readByte(); |
377 assert(tag == Tag.Class); | 378 assert(tag == Tag.Class); |
378 var canonicalName = readCanonicalNameReference(); | 379 var canonicalName = readCanonicalNameReference(); |
379 var reference = canonicalName.getReference(); | 380 var reference = canonicalName.getReference(); |
380 Class node = reference.node; | 381 Class node = reference.node; |
381 bool shouldWriteData = node == null || _isReadingLibraryImplementation; | 382 bool shouldWriteData = node == null || _isReadingLibraryImplementation; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 int offset = readOffset(); | 652 int offset = readOffset(); |
652 return new VariableSet(variableStack[index], readExpression()) | 653 return new VariableSet(variableStack[index], readExpression()) |
653 ..fileOffset = offset; | 654 ..fileOffset = offset; |
654 case Tag.PropertyGet: | 655 case Tag.PropertyGet: |
655 int offset = readOffset(); | 656 int offset = readOffset(); |
656 return new PropertyGet.byReference( | 657 return new PropertyGet.byReference( |
657 readExpression(), readName(), readMemberReference(allowNull: true)) | 658 readExpression(), readName(), readMemberReference(allowNull: true)) |
658 ..fileOffset = offset; | 659 ..fileOffset = offset; |
659 case Tag.PropertySet: | 660 case Tag.PropertySet: |
660 int offset = readOffset(); | 661 int offset = readOffset(); |
661 return new PropertySet.byReference( | 662 return new PropertySet.byReference(readExpression(), readName(), |
662 readExpression(), | 663 readExpression(), readMemberReference(allowNull: true)) |
663 readName(), | 664 ..fileOffset = offset; |
664 readExpression(), | |
665 readMemberReference(allowNull: true))..fileOffset = offset; | |
666 case Tag.SuperPropertyGet: | 665 case Tag.SuperPropertyGet: |
667 addTransformerFlag(TransformerFlag.superCalls); | 666 addTransformerFlag(TransformerFlag.superCalls); |
668 return new SuperPropertyGet.byReference( | 667 return new SuperPropertyGet.byReference( |
669 readName(), readMemberReference(allowNull: true)); | 668 readName(), readMemberReference(allowNull: true)); |
670 case Tag.SuperPropertySet: | 669 case Tag.SuperPropertySet: |
671 addTransformerFlag(TransformerFlag.superCalls); | 670 addTransformerFlag(TransformerFlag.superCalls); |
672 return new SuperPropertySet.byReference( | 671 return new SuperPropertySet.byReference( |
673 readName(), readExpression(), readMemberReference(allowNull: true)); | 672 readName(), readExpression(), readMemberReference(allowNull: true)); |
674 case Tag.DirectPropertyGet: | 673 case Tag.DirectPropertyGet: |
675 int offset = readOffset(); | 674 int offset = readOffset(); |
676 return new DirectPropertyGet.byReference( | 675 return new DirectPropertyGet.byReference( |
677 readExpression(), readMemberReference())..fileOffset = offset; | 676 readExpression(), readMemberReference()) |
| 677 ..fileOffset = offset; |
678 case Tag.DirectPropertySet: | 678 case Tag.DirectPropertySet: |
679 int offset = readOffset(); | 679 int offset = readOffset(); |
680 return new DirectPropertySet.byReference( | 680 return new DirectPropertySet.byReference( |
681 readExpression(), readMemberReference(), readExpression()) | 681 readExpression(), readMemberReference(), readExpression()) |
682 ..fileOffset = offset; | 682 ..fileOffset = offset; |
683 case Tag.StaticGet: | 683 case Tag.StaticGet: |
684 int offset = readOffset(); | 684 int offset = readOffset(); |
685 return new StaticGet.byReference(readMemberReference()) | 685 return new StaticGet.byReference(readMemberReference()) |
686 ..fileOffset = offset; | 686 ..fileOffset = offset; |
687 case Tag.StaticSet: | 687 case Tag.StaticSet: |
688 int offset = readOffset(); | 688 int offset = readOffset(); |
689 return new StaticSet.byReference( | 689 return new StaticSet.byReference( |
690 readMemberReference(), readExpression())..fileOffset = offset; | 690 readMemberReference(), readExpression()) |
| 691 ..fileOffset = offset; |
691 case Tag.MethodInvocation: | 692 case Tag.MethodInvocation: |
692 int offset = readOffset(); | 693 int offset = readOffset(); |
693 return new MethodInvocation.byReference( | 694 return new MethodInvocation.byReference(readExpression(), readName(), |
694 readExpression(), | 695 readArguments(), readMemberReference(allowNull: true)) |
695 readName(), | 696 ..fileOffset = offset; |
696 readArguments(), | |
697 readMemberReference(allowNull: true))..fileOffset = offset; | |
698 case Tag.SuperMethodInvocation: | 697 case Tag.SuperMethodInvocation: |
699 int offset = readOffset(); | 698 int offset = readOffset(); |
700 addTransformerFlag(TransformerFlag.superCalls); | 699 addTransformerFlag(TransformerFlag.superCalls); |
701 return new SuperMethodInvocation.byReference( | 700 return new SuperMethodInvocation.byReference( |
702 readName(), readArguments(), readMemberReference(allowNull: true)) | 701 readName(), readArguments(), readMemberReference(allowNull: true)) |
703 ..fileOffset = offset; | 702 ..fileOffset = offset; |
704 case Tag.DirectMethodInvocation: | 703 case Tag.DirectMethodInvocation: |
705 return new DirectMethodInvocation.byReference( | 704 return new DirectMethodInvocation.byReference( |
706 readExpression(), readMemberReference(), readArguments()); | 705 readExpression(), readMemberReference(), readArguments()); |
707 case Tag.StaticInvocation: | 706 case Tag.StaticInvocation: |
708 int offset = readOffset(); | 707 int offset = readOffset(); |
709 return new StaticInvocation.byReference( | 708 return new StaticInvocation.byReference( |
710 readMemberReference(), readArguments(), isConst: false) | 709 readMemberReference(), readArguments(), |
| 710 isConst: false) |
711 ..fileOffset = offset; | 711 ..fileOffset = offset; |
712 case Tag.ConstStaticInvocation: | 712 case Tag.ConstStaticInvocation: |
713 int offset = readOffset(); | 713 int offset = readOffset(); |
714 return new StaticInvocation.byReference( | 714 return new StaticInvocation.byReference( |
715 readMemberReference(), readArguments(), isConst: true) | 715 readMemberReference(), readArguments(), |
| 716 isConst: true) |
716 ..fileOffset = offset; | 717 ..fileOffset = offset; |
717 case Tag.ConstructorInvocation: | 718 case Tag.ConstructorInvocation: |
718 int offset = readOffset(); | 719 int offset = readOffset(); |
719 return new ConstructorInvocation.byReference( | 720 return new ConstructorInvocation.byReference( |
720 readMemberReference(), readArguments(), isConst: false) | 721 readMemberReference(), readArguments(), |
| 722 isConst: false) |
721 ..fileOffset = offset; | 723 ..fileOffset = offset; |
722 case Tag.ConstConstructorInvocation: | 724 case Tag.ConstConstructorInvocation: |
723 int offset = readOffset(); | 725 int offset = readOffset(); |
724 return new ConstructorInvocation.byReference( | 726 return new ConstructorInvocation.byReference( |
725 readMemberReference(), readArguments(), isConst: true) | 727 readMemberReference(), readArguments(), |
| 728 isConst: true) |
726 ..fileOffset = offset; | 729 ..fileOffset = offset; |
727 case Tag.Not: | 730 case Tag.Not: |
728 return new Not(readExpression()); | 731 return new Not(readExpression()); |
729 case Tag.LogicalExpression: | 732 case Tag.LogicalExpression: |
730 return new LogicalExpression(readExpression(), | 733 return new LogicalExpression(readExpression(), |
731 logicalOperatorToString(readByte()), readExpression()); | 734 logicalOperatorToString(readByte()), readExpression()); |
732 case Tag.ConditionalExpression: | 735 case Tag.ConditionalExpression: |
733 return new ConditionalExpression(readExpression(), readExpression(), | 736 return new ConditionalExpression(readExpression(), readExpression(), |
734 readExpression(), readDartTypeOption()); | 737 readExpression(), readDartTypeOption()); |
735 case Tag.StringConcatenation: | 738 case Tag.StringConcatenation: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 case Tag.Rethrow: | 775 case Tag.Rethrow: |
773 int offset = readOffset(); | 776 int offset = readOffset(); |
774 return new Rethrow()..fileOffset = offset; | 777 return new Rethrow()..fileOffset = offset; |
775 case Tag.Throw: | 778 case Tag.Throw: |
776 int offset = readOffset(); | 779 int offset = readOffset(); |
777 return new Throw(readExpression())..fileOffset = offset; | 780 return new Throw(readExpression())..fileOffset = offset; |
778 case Tag.ListLiteral: | 781 case Tag.ListLiteral: |
779 int offset = readOffset(); | 782 int offset = readOffset(); |
780 var typeArgument = readDartType(); | 783 var typeArgument = readDartType(); |
781 return new ListLiteral(readExpressionList(), | 784 return new ListLiteral(readExpressionList(), |
782 typeArgument: typeArgument, isConst: false)..fileOffset = offset; | 785 typeArgument: typeArgument, isConst: false) |
| 786 ..fileOffset = offset; |
783 case Tag.ConstListLiteral: | 787 case Tag.ConstListLiteral: |
784 int offset = readOffset(); | 788 int offset = readOffset(); |
785 var typeArgument = readDartType(); | 789 var typeArgument = readDartType(); |
786 return new ListLiteral(readExpressionList(), | 790 return new ListLiteral(readExpressionList(), |
787 typeArgument: typeArgument, isConst: true)..fileOffset = offset; | 791 typeArgument: typeArgument, isConst: true) |
| 792 ..fileOffset = offset; |
788 case Tag.MapLiteral: | 793 case Tag.MapLiteral: |
789 int offset = readOffset(); | 794 int offset = readOffset(); |
790 var keyType = readDartType(); | 795 var keyType = readDartType(); |
791 var valueType = readDartType(); | 796 var valueType = readDartType(); |
792 return new MapLiteral(readMapEntryList(), | 797 return new MapLiteral(readMapEntryList(), |
793 keyType: keyType, | 798 keyType: keyType, valueType: valueType, isConst: false) |
794 valueType: valueType, | 799 ..fileOffset = offset; |
795 isConst: false)..fileOffset = offset; | |
796 case Tag.ConstMapLiteral: | 800 case Tag.ConstMapLiteral: |
797 int offset = readOffset(); | 801 int offset = readOffset(); |
798 var keyType = readDartType(); | 802 var keyType = readDartType(); |
799 var valueType = readDartType(); | 803 var valueType = readDartType(); |
800 return new MapLiteral(readMapEntryList(), | 804 return new MapLiteral(readMapEntryList(), |
801 keyType: keyType, | 805 keyType: keyType, valueType: valueType, isConst: true) |
802 valueType: valueType, | 806 ..fileOffset = offset; |
803 isConst: true)..fileOffset = offset; | |
804 case Tag.AwaitExpression: | 807 case Tag.AwaitExpression: |
805 return new AwaitExpression(readExpression()); | 808 return new AwaitExpression(readExpression()); |
806 case Tag.FunctionExpression: | 809 case Tag.FunctionExpression: |
807 return new FunctionExpression(readFunctionNode()); | 810 return new FunctionExpression(readFunctionNode()); |
808 case Tag.Let: | 811 case Tag.Let: |
809 var variable = readVariableDeclaration(); | 812 var variable = readVariableDeclaration(); |
810 int stackHeight = variableStack.length; | 813 int stackHeight = variableStack.length; |
811 pushVariableDeclaration(variable); | 814 pushVariableDeclaration(variable); |
812 var body = readExpression(); | 815 var body = readExpression(); |
813 variableStack.length = stackHeight; | 816 variableStack.length = stackHeight; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 ..fileOffset = offset | 1127 ..fileOffset = offset |
1125 ..fileEqualsOffset = fileEqualsOffset; | 1128 ..fileEqualsOffset = fileEqualsOffset; |
1126 } | 1129 } |
1127 | 1130 |
1128 int readOffset() { | 1131 int readOffset() { |
1129 // Offset is saved as unsigned, | 1132 // Offset is saved as unsigned, |
1130 // but actually ranges from -1 and up (thus the -1) | 1133 // but actually ranges from -1 and up (thus the -1) |
1131 return readUInt() - 1; | 1134 return readUInt() - 1; |
1132 } | 1135 } |
1133 } | 1136 } |
OLD | NEW |