| 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 | 8 |
| 8 import '../ast.dart'; | 9 import '../ast.dart'; |
| 9 import '../transformations/flags.dart'; | 10 import '../transformations/flags.dart'; |
| 10 import 'tag.dart'; | 11 import 'tag.dart'; |
| 11 | 12 |
| 12 class ParseError { | 13 class ParseError { |
| 13 String filename; | 14 String filename; |
| 14 int byteIndex; | 15 int byteIndex; |
| 15 String message; | 16 String message; |
| 16 String path; | 17 String path; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 int readMagicWord() { | 71 int readMagicWord() { |
| 71 return (readByte() << 24) | | 72 return (readByte() << 24) | |
| 72 (readByte() << 16) | | 73 (readByte() << 16) | |
| 73 (readByte() << 8) | | 74 (readByte() << 8) | |
| 74 readByte(); | 75 readByte(); |
| 75 } | 76 } |
| 76 | 77 |
| 78 List<int> readUtf8Bytes() { |
| 79 List<int> bytes = new Uint8List(readUInt()); |
| 80 bytes.setRange(0, bytes.length, _bytes, _byteIndex); |
| 81 _byteIndex += bytes.length; |
| 82 return bytes; |
| 83 } |
| 84 |
| 77 String readStringEntry() { | 85 String readStringEntry() { |
| 78 int numBytes = readUInt(); | 86 int numBytes = readUInt(); |
| 79 // Utf8Decoder will skip leading BOM characters, but we must preserve them. | 87 // Utf8Decoder will skip leading BOM characters, but we must preserve them. |
| 80 // Collect leading BOMs before passing the bytes onto Utf8Decoder. | 88 // Collect leading BOMs before passing the bytes onto Utf8Decoder. |
| 81 int numByteOrderMarks = 0; | 89 int numByteOrderMarks = 0; |
| 82 while (_byteIndex + 2 < _bytes.length && | 90 while (_byteIndex + 2 < _bytes.length && |
| 83 _bytes[_byteIndex] == 0xef && | 91 _bytes[_byteIndex] == 0xef && |
| 84 _bytes[_byteIndex + 1] == 0xbb && | 92 _bytes[_byteIndex + 1] == 0xbb && |
| 85 _bytes[_byteIndex + 2] == 0xbf) { | 93 _bytes[_byteIndex + 2] == 0xbf) { |
| 86 ++numByteOrderMarks; | 94 ++numByteOrderMarks; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 var mainMethod = readMemberReference(allowNull: true); | 272 var mainMethod = readMemberReference(allowNull: true); |
| 265 program.mainMethodName ??= mainMethod; | 273 program.mainMethodName ??= mainMethod; |
| 266 } | 274 } |
| 267 | 275 |
| 268 Map<String, Source> readUriToSource() { | 276 Map<String, Source> readUriToSource() { |
| 269 readSourceUriTable(); | 277 readSourceUriTable(); |
| 270 int length = _sourceUriTable.length; | 278 int length = _sourceUriTable.length; |
| 271 Map<String, Source> uriToSource = <String, Source>{}; | 279 Map<String, Source> uriToSource = <String, Source>{}; |
| 272 for (int i = 0; i < length; ++i) { | 280 for (int i = 0; i < length; ++i) { |
| 273 String uri = _sourceUriTable[i]; | 281 String uri = _sourceUriTable[i]; |
| 274 String sourceCode = readStringEntry(); | 282 List<int> sourceCode = readUtf8Bytes(); |
| 275 int lineCount = readUInt(); | 283 int lineCount = readUInt(); |
| 276 List<int> lineStarts = new List<int>(lineCount); | 284 List<int> lineStarts = new List<int>(lineCount); |
| 277 int previousLineStart = 0; | 285 int previousLineStart = 0; |
| 278 for (int j = 0; j < lineCount; ++j) { | 286 for (int j = 0; j < lineCount; ++j) { |
| 279 int lineStart = readUInt() + previousLineStart; | 287 int lineStart = readUInt() + previousLineStart; |
| 280 lineStarts[j] = lineStart; | 288 lineStarts[j] = lineStart; |
| 281 previousLineStart = lineStart; | 289 previousLineStart = lineStart; |
| 282 } | 290 } |
| 283 uriToSource[uri] = new Source(lineStarts, sourceCode); | 291 uriToSource[uri] = new Source(lineStarts, sourceCode); |
| 284 } | 292 } |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 ..fileOffset = offset | 1108 ..fileOffset = offset |
| 1101 ..fileEqualsOffset = fileEqualsOffset; | 1109 ..fileEqualsOffset = fileEqualsOffset; |
| 1102 } | 1110 } |
| 1103 | 1111 |
| 1104 int readOffset() { | 1112 int readOffset() { |
| 1105 // Offset is saved as unsigned, | 1113 // Offset is saved as unsigned, |
| 1106 // but actually ranges from -1 and up (thus the -1) | 1114 // but actually ranges from -1 and up (thus the -1) |
| 1107 return readUInt() - 1; | 1115 return readUInt() - 1; |
| 1108 } | 1116 } |
| 1109 } | 1117 } |
| OLD | NEW |