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

Side by Side Diff: pkg/kernel/lib/binary/ast_from_binary.dart

Issue 2729913005: [Fasta] include source code in dill (Closed)
Patch Set: Addressed comments Created 3 years, 9 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
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 library kernel.ast_from_binary; 4 library kernel.ast_from_binary;
5 5
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import '../ast.dart'; 8 import '../ast.dart';
9 import '../transformations/flags.dart'; 9 import '../transformations/flags.dart';
10 import 'tag.dart'; 10 import 'tag.dart';
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 } 68 }
69 69
70 int readMagicWord() { 70 int readMagicWord() {
71 return (readByte() << 24) | 71 return (readByte() << 24) |
72 (readByte() << 16) | 72 (readByte() << 16) |
73 (readByte() << 8) | 73 (readByte() << 8) |
74 readByte(); 74 readByte();
75 } 75 }
76 76
77 List<int> readRawString() {
ahe 2017/03/03 13:14:50 Change name to readUtf8Bytes, readUint8List, or so
jensj 2017/03/06 07:38:36 Done.
78 return new List<int>.generate(readUInt(), (i) => readByte());
ahe 2017/03/03 13:14:51 How about: List<int> bytes = new Uint8List(readUI
jensj 2017/03/06 07:38:36 Done.
79 }
80
77 String readStringEntry() { 81 String readStringEntry() {
78 int numBytes = readUInt(); 82 int numBytes = readUInt();
79 // Utf8Decoder will skip leading BOM characters, but we must preserve them. 83 // Utf8Decoder will skip leading BOM characters, but we must preserve them.
80 // Collect leading BOMs before passing the bytes onto Utf8Decoder. 84 // Collect leading BOMs before passing the bytes onto Utf8Decoder.
81 int numByteOrderMarks = 0; 85 int numByteOrderMarks = 0;
82 while (_byteIndex + 2 < _bytes.length && 86 while (_byteIndex + 2 < _bytes.length &&
83 _bytes[_byteIndex] == 0xef && 87 _bytes[_byteIndex] == 0xef &&
84 _bytes[_byteIndex + 1] == 0xbb && 88 _bytes[_byteIndex + 1] == 0xbb &&
85 _bytes[_byteIndex + 2] == 0xbf) { 89 _bytes[_byteIndex + 2] == 0xbf) {
86 ++numByteOrderMarks; 90 ++numByteOrderMarks;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 var mainMethod = readMemberReference(allowNull: true); 268 var mainMethod = readMemberReference(allowNull: true);
265 program.mainMethodName ??= mainMethod; 269 program.mainMethodName ??= mainMethod;
266 } 270 }
267 271
268 Map<String, Source> readUriToSource() { 272 Map<String, Source> readUriToSource() {
269 readSourceUriTable(); 273 readSourceUriTable();
270 int length = _sourceUriTable.length; 274 int length = _sourceUriTable.length;
271 Map<String, Source> uriToSource = <String, Source>{}; 275 Map<String, Source> uriToSource = <String, Source>{};
272 for (int i = 0; i < length; ++i) { 276 for (int i = 0; i < length; ++i) {
273 String uri = _sourceUriTable[i]; 277 String uri = _sourceUriTable[i];
274 String sourceCode = readStringEntry(); 278 List<int> sourceCode = readRawString();
275 int lineCount = readUInt(); 279 int lineCount = readUInt();
276 List<int> lineStarts = new List<int>(lineCount); 280 List<int> lineStarts = new List<int>(lineCount);
277 int previousLineStart = 0; 281 int previousLineStart = 0;
278 for (int j = 0; j < lineCount; ++j) { 282 for (int j = 0; j < lineCount; ++j) {
279 int lineStart = readUInt() + previousLineStart; 283 int lineStart = readUInt() + previousLineStart;
280 lineStarts[j] = lineStart; 284 lineStarts[j] = lineStart;
281 previousLineStart = lineStart; 285 previousLineStart = lineStart;
282 } 286 }
283 uriToSource[uri] = new Source(lineStarts, sourceCode); 287 uriToSource[uri] = new Source(lineStarts, sourceCode);
284 } 288 }
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 isFinal: flags & 0x1 != 0, 1093 isFinal: flags & 0x1 != 0,
1090 isConst: flags & 0x2 != 0)..fileOffset = offset; 1094 isConst: flags & 0x2 != 0)..fileOffset = offset;
1091 } 1095 }
1092 1096
1093 int readOffset() { 1097 int readOffset() {
1094 // Offset is saved as unsigned, 1098 // Offset is saved as unsigned,
1095 // but actually ranges from -1 and up (thus the -1) 1099 // but actually ranges from -1 and up (thus the -1)
1096 return readUInt() - 1; 1100 return readUInt() - 1;
1097 } 1101 }
1098 } 1102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698