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

Side by Side Diff: pkg/analyzer/tool/summary/generate.dart

Issue 1998833002: Use BufferContext + offset instead of BufferPointer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: tweaks Created 4 years, 7 months 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 | « pkg/analyzer/tool/summary/build_sdk_summaries.dart ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /** 5 /**
6 * This file contains code to generate serialization/deserialization logic for 6 * This file contains code to generate serialization/deserialization logic for
7 * summaries based on an "IDL" description of the summary format (written in 7 * summaries based on an "IDL" description of the summary format (written in
8 * stylized Dart). 8 * stylized Dart).
9 * 9 *
10 * For each class in the "IDL" input, two corresponding classes are generated: 10 * For each class in the "IDL" input, two corresponding classes are generated:
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 String count = '${idlPrefix(name)}.values.length'; 742 String count = '${idlPrefix(name)}.values.length';
743 String def = '${idlPrefix(name)}.${enm.values[0].name}'; 743 String def = '${idlPrefix(name)}.${enm.values[0].name}';
744 out('class $readerName extends fb.Reader<${idlPrefix(name)}> {'); 744 out('class $readerName extends fb.Reader<${idlPrefix(name)}> {');
745 indent(() { 745 indent(() {
746 out('const $readerName() : super();'); 746 out('const $readerName() : super();');
747 out(); 747 out();
748 out('@override'); 748 out('@override');
749 out('int get size => 1;'); 749 out('int get size => 1;');
750 out(); 750 out();
751 out('@override'); 751 out('@override');
752 out('${idlPrefix(name)} read(fb.BufferPointer bp) {'); 752 out('${idlPrefix(name)} read(fb.BufferContext bc, int offset) {');
753 indent(() { 753 indent(() {
754 out('int index = const fb.Uint8Reader().read(bp);'); 754 out('int index = const fb.Uint8Reader().read(bc, offset);');
755 out('return index < $count ? ${idlPrefix(name)}.values[index] : $def;'); 755 out('return index < $count ? ${idlPrefix(name)}.values[index] : $def;');
756 }); 756 });
757 out('}'); 757 out('}');
758 }); 758 });
759 out('}'); 759 out('}');
760 } 760 }
761 761
762 void _generateImpl(idlModel.ClassDeclaration cls) { 762 void _generateImpl(idlModel.ClassDeclaration cls) {
763 String name = cls.name; 763 String name = cls.name;
764 String implName = '_${name}Impl'; 764 String implName = '_${name}Impl';
765 String mixinName = '_${name}Mixin'; 765 String mixinName = '_${name}Mixin';
766 out('class $implName extends Object with $mixinName' 766 out('class $implName extends Object with $mixinName'
767 ' implements ${idlPrefix(name)} {'); 767 ' implements ${idlPrefix(name)} {');
768 indent(() { 768 indent(() {
769 out('final fb.BufferPointer _bp;'); 769 out('final fb.BufferContext _bc;');
770 out('final int _bcOffset;');
770 out(); 771 out();
771 out('$implName(this._bp);'); 772 out('$implName(this._bc, this._bcOffset);');
772 out(); 773 out();
773 // Write cache fields. 774 // Write cache fields.
774 for (idlModel.FieldDeclaration field in cls.fields) { 775 for (idlModel.FieldDeclaration field in cls.fields) {
775 String returnType = dartType(field.type); 776 String returnType = dartType(field.type);
776 String fieldName = field.name; 777 String fieldName = field.name;
777 out('$returnType _$fieldName;'); 778 out('$returnType _$fieldName;');
778 } 779 }
779 // Write getters. 780 // Write getters.
780 for (idlModel.FieldDeclaration field in cls.allFields) { 781 for (idlModel.FieldDeclaration field in cls.allFields) {
781 int index = field.id; 782 int index = field.id;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 assert(readCode != null); 818 assert(readCode != null);
818 // Write the getter implementation. 819 // Write the getter implementation.
819 out(); 820 out();
820 out('@override'); 821 out('@override');
821 String returnType = dartType(type); 822 String returnType = dartType(type);
822 if (field.isDeprecated) { 823 if (field.isDeprecated) {
823 out('$returnType get $fieldName => $_throwDeprecated;'); 824 out('$returnType get $fieldName => $_throwDeprecated;');
824 } else { 825 } else {
825 out('$returnType get $fieldName {'); 826 out('$returnType get $fieldName {');
826 indent(() { 827 indent(() {
827 String readExpr = '$readCode.vTableGet(_bp, $index, $def)'; 828 String readExpr = '$readCode.vTableGet(_bc, _bcOffset, $index, $def) ';
828 out('_$fieldName ??= $readExpr;'); 829 out('_$fieldName ??= $readExpr;');
829 out('return _$fieldName;'); 830 out('return _$fieldName;');
830 }); 831 });
831 out('}'); 832 out('}');
832 } 833 }
833 } 834 }
834 }); 835 });
835 out('}'); 836 out('}');
836 } 837 }
837 838
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 900
900 void _generateReader(idlModel.ClassDeclaration cls) { 901 void _generateReader(idlModel.ClassDeclaration cls) {
901 String name = cls.name; 902 String name = cls.name;
902 String readerName = '_${name}Reader'; 903 String readerName = '_${name}Reader';
903 String implName = '_${name}Impl'; 904 String implName = '_${name}Impl';
904 out('class $readerName extends fb.TableReader<$implName> {'); 905 out('class $readerName extends fb.TableReader<$implName> {');
905 indent(() { 906 indent(() {
906 out('const $readerName();'); 907 out('const $readerName();');
907 out(); 908 out();
908 out('@override'); 909 out('@override');
909 out('$implName createObject(fb.BufferPointer bp) => new $implName(bp);'); 910 out('$implName createObject(fb.BufferContext bc, int offset) => new $implN ame(bc, offset);');
910 }); 911 });
911 out('}'); 912 out('}');
912 } 913 }
913 914
914 void _generateReadFunction(idlModel.ClassDeclaration cls) { 915 void _generateReadFunction(idlModel.ClassDeclaration cls) {
915 String name = cls.name; 916 String name = cls.name;
916 out('${idlPrefix(name)} read$name(List<int> buffer) {'); 917 out('${idlPrefix(name)} read$name(List<int> buffer) {');
917 indent(() { 918 indent(() {
918 out('fb.BufferPointer rootRef = new fb.BufferPointer.fromBytes(buffer);'); 919 out('fb.BufferContext rootRef = new fb.BufferContext.fromBytes(buffer);');
919 out('return const _${name}Reader().read(rootRef);'); 920 out('return const _${name}Reader().read(rootRef, 0);');
920 }); 921 });
921 out('}'); 922 out('}');
922 } 923 }
923 924
924 /** 925 /**
925 * Return the documentation text of the given [node], or `null` if the [node] 926 * Return the documentation text of the given [node], or `null` if the [node]
926 * does not have a comment. Each line is `\n` separated. 927 * does not have a comment. Each line is `\n` separated.
927 */ 928 */
928 String _getNodeDoc(LineInfo lineInfo, AnnotatedNode node) { 929 String _getNodeDoc(LineInfo lineInfo, AnnotatedNode node) {
929 Comment comment = node.documentationComment; 930 Comment comment = node.documentationComment;
930 if (comment != null && 931 if (comment != null &&
931 comment.isDocumentation && 932 comment.isDocumentation &&
932 comment.tokens.length == 1 && 933 comment.tokens.length == 1 &&
933 comment.tokens.first.type == TokenType.MULTI_LINE_COMMENT) { 934 comment.tokens.first.type == TokenType.MULTI_LINE_COMMENT) {
934 Token token = comment.tokens.first; 935 Token token = comment.tokens.first;
935 int column = lineInfo.getLocation(token.offset).columnNumber; 936 int column = lineInfo.getLocation(token.offset).columnNumber;
936 String indent = ' ' * (column - 1); 937 String indent = ' ' * (column - 1);
937 return token.lexeme.split('\n').map((String line) { 938 return token.lexeme.split('\n').map((String line) {
938 if (line.startsWith(indent)) { 939 if (line.startsWith(indent)) {
939 line = line.substring(indent.length); 940 line = line.substring(indent.length);
940 } 941 }
941 return line; 942 return line;
942 }).join('\n'); 943 }).join('\n');
943 } 944 }
944 return null; 945 return null;
945 } 946 }
946 } 947 }
OLDNEW
« no previous file with comments | « pkg/analyzer/tool/summary/build_sdk_summaries.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698