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

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

Issue 2931773005: [kernel] Delete most of the AST (Closed)
Patch Set: Remove getMainClosure handeling as it no longer exists Created 3 years, 6 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 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return ((byte & 0x3F) << 8) | readByte(); 61 return ((byte & 0x3F) << 8) | readByte();
62 } else { 62 } else {
63 // 11xxxxxx 63 // 11xxxxxx
64 return ((byte & 0x3F) << 24) | 64 return ((byte & 0x3F) << 24) |
65 (readByte() << 16) | 65 (readByte() << 16) |
66 (readByte() << 8) | 66 (readByte() << 8) |
67 readByte(); 67 readByte();
68 } 68 }
69 } 69 }
70 70
71 int readMagicWord() { 71 int readUint32() {
72 return (readByte() << 24) | 72 return (readByte() << 24) |
73 (readByte() << 16) | 73 (readByte() << 16) |
74 (readByte() << 8) | 74 (readByte() << 8) |
75 readByte(); 75 readByte();
76 } 76 }
77 77
78 List<int> readUtf8Bytes() { 78 List<int> readUtf8Bytes() {
79 List<int> bytes = new Uint8List(readUInt()); 79 List<int> bytes = new Uint8List(readUInt());
80 bytes.setRange(0, bytes.length, _bytes, _byteIndex); 80 bytes.setRange(0, bytes.length, _bytes, _byteIndex);
81 _byteIndex += bytes.length; 81 _byteIndex += bytes.length;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 /// 230 ///
231 /// When linking with a non-empty program, canonical names must have been 231 /// When linking with a non-empty program, canonical names must have been
232 /// computed ahead of time. 232 /// computed ahead of time.
233 /// 233 ///
234 /// This should *only* be used when there is a reason to not allow 234 /// This should *only* be used when there is a reason to not allow
235 /// concatenated files. 235 /// concatenated files.
236 void readSingleFileProgram(Program program) { 236 void readSingleFileProgram(Program program) {
237 _readOneProgram(program); 237 _readOneProgram(program);
238 if (_byteIndex < _bytes.length) { 238 if (_byteIndex < _bytes.length) {
239 if (_byteIndex + 3 < _bytes.length) { 239 if (_byteIndex + 3 < _bytes.length) {
240 int magic = readMagicWord(); 240 int magic = readUint32();
241 if (magic == Tag.ProgramFile) { 241 if (magic == Tag.ProgramFile) {
242 throw 'Concatenated program file given when a single program ' 242 throw 'Concatenated program file given when a single program '
243 'was expected.'; 243 'was expected.';
244 } 244 }
245 } 245 }
246 throw 'Unrecognized bytes following program data'; 246 throw 'Unrecognized bytes following program data';
247 } 247 }
248 } 248 }
249 249
250 void _readOneProgram(Program program) { 250 void _readOneProgram(Program program) {
251 int magic = readMagicWord(); 251 int magic = readUint32();
252 if (magic != Tag.ProgramFile) { 252 if (magic != Tag.ProgramFile) {
253 throw fail('This is not a binary dart file. ' 253 throw fail('This is not a binary dart file. '
254 'Magic number was: ${magic.toRadixString(16)}'); 254 'Magic number was: ${magic.toRadixString(16)}');
255 } 255 }
256 readStringTable(_stringTable); 256 readStringTable(_stringTable);
257 Map<String, Source> uriToSource = readUriToSource(); 257 Map<String, Source> uriToSource = readUriToSource();
258 program.uriToSource.addAll(uriToSource); 258 program.uriToSource.addAll(uriToSource);
259 readLinkTable(program.root); 259 readLinkTable(program.root);
260 int numberOfLibraries = readUInt(); 260 int numberOfLibraries = readUInt();
261 List<Library> libraries = new List<Library>(numberOfLibraries); 261 List<Library> libraries = new List<Library>(numberOfLibraries);
262 for (int i = 0; i < numberOfLibraries; ++i) { 262 for (int i = 0; i < numberOfLibraries; ++i) {
263 libraries[i] = readLibrary(program); 263 libraries[i] = readLibrary(program);
264 } 264 }
265 var mainMethod = readMemberReference(allowNull: true); 265 var mainMethod = readMemberReference(allowNull: true);
266 program.mainMethodName ??= mainMethod; 266 program.mainMethodName ??= mainMethod;
267 readUint32(); // binary offset for source table.
268 readUint32(); // binary offset for link table.
269 readUint32(); // main
270 for (int i = 0; i < numberOfLibraries; i++) {
271 readUint32(); // binary offset for library #i.
272 }
273 int numberOfLibrariesCheck = readUint32();
274 if (numberOfLibraries != numberOfLibrariesCheck) {
275 throw "Expected number of libraries to match!";
Kevin Millikin (Google) 2017/06/29 12:27:36 Even if you're just throwing a string and not some
jensj 2017/06/30 05:51:17 I'm not sure about throwing if we're not at the en
276 }
267 } 277 }
268 278
269 Map<String, Source> readUriToSource() { 279 Map<String, Source> readUriToSource() {
270 readStringTable(_sourceUriTable); 280 readStringTable(_sourceUriTable);
271 int length = _sourceUriTable.length; 281 int length = _sourceUriTable.length;
272 Map<String, Source> uriToSource = <String, Source>{}; 282 Map<String, Source> uriToSource = <String, Source>{};
273 for (int i = 0; i < length; ++i) { 283 for (int i = 0; i < length; ++i) {
274 String uri = _sourceUriTable[i]; 284 String uri = _sourceUriTable[i];
275 List<int> sourceCode = readUtf8Bytes(); 285 List<int> sourceCode = readUtf8Bytes();
276 int lineCount = readUInt(); 286 int lineCount = readUInt();
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 ..fileOffset = offset 1211 ..fileOffset = offset
1202 ..fileEqualsOffset = fileEqualsOffset; 1212 ..fileEqualsOffset = fileEqualsOffset;
1203 } 1213 }
1204 1214
1205 int readOffset() { 1215 int readOffset() {
1206 // Offset is saved as unsigned, 1216 // Offset is saved as unsigned,
1207 // but actually ranges from -1 and up (thus the -1) 1217 // but actually ranges from -1 and up (thus the -1)
1208 return readUInt() - 1; 1218 return readUInt() - 1;
1209 } 1219 }
1210 } 1220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698