| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 | 121 |
| 122 String readUriReference() { | 122 String readUriReference() { |
| 123 return _sourceUriTable[readUInt()]; | 123 return _sourceUriTable[readUInt()]; |
| 124 } | 124 } |
| 125 | 125 |
| 126 String readStringReference() { | 126 String readStringReference() { |
| 127 return _stringTable[readUInt()]; | 127 return _stringTable[readUInt()]; |
| 128 } | 128 } |
| 129 | 129 |
| 130 List<String> readStringReferenceList() { |
| 131 return new List<String>.generate(readUInt(), (i) => readStringReference()); |
| 132 } |
| 133 |
| 130 String readStringOrNullIfEmpty() { | 134 String readStringOrNullIfEmpty() { |
| 131 var string = readStringReference(); | 135 var string = readStringReference(); |
| 132 return string.isEmpty ? null : string; | 136 return string.isEmpty ? null : string; |
| 133 } | 137 } |
| 134 | 138 |
| 135 bool readAndCheckOptionTag() { | 139 bool readAndCheckOptionTag() { |
| 136 int tag = readByte(); | 140 int tag = readByte(); |
| 137 if (tag == Tag.Nothing) { | 141 if (tag == Tag.Nothing) { |
| 138 return false; | 142 return false; |
| 139 } else if (tag == Tag.Something) { | 143 } else if (tag == Tag.Something) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 CanonicalName readCanonicalNameReference() { | 289 CanonicalName readCanonicalNameReference() { |
| 286 var index = readUInt(); | 290 var index = readUInt(); |
| 287 if (index == 0) return null; | 291 if (index == 0) return null; |
| 288 return _linkTable[index - 1]; | 292 return _linkTable[index - 1]; |
| 289 } | 293 } |
| 290 | 294 |
| 291 Reference readLibraryReference() { | 295 Reference readLibraryReference() { |
| 292 return readCanonicalNameReference().getReference(); | 296 return readCanonicalNameReference().getReference(); |
| 293 } | 297 } |
| 294 | 298 |
| 295 DeferredImport readDeferredImportReference() { | 299 LibraryDependency readLibraryDependencyReference() { |
| 296 int index = readUInt(); | 300 int index = readUInt(); |
| 297 return _currentLibrary.deferredImports[index]; | 301 return _currentLibrary.dependencies[index]; |
| 298 } | 302 } |
| 299 | 303 |
| 300 Reference readClassReference({bool allowNull: false}) { | 304 Reference readClassReference({bool allowNull: false}) { |
| 301 var name = readCanonicalNameReference(); | 305 var name = readCanonicalNameReference(); |
| 302 if (name == null && !allowNull) { | 306 if (name == null && !allowNull) { |
| 303 throw 'Expected a class reference to be valid but was `null`.'; | 307 throw 'Expected a class reference to be valid but was `null`.'; |
| 304 } | 308 } |
| 305 return name?.getReference(); | 309 return name?.getReference(); |
| 306 } | 310 } |
| 307 | 311 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 String name = readStringOrNullIfEmpty(); | 347 String name = readStringOrNullIfEmpty(); |
| 344 // TODO(jensj): We currently save (almost the same) uri twice. | 348 // TODO(jensj): We currently save (almost the same) uri twice. |
| 345 String fileUri = readUriReference(); | 349 String fileUri = readUriReference(); |
| 346 | 350 |
| 347 if (shouldWriteData) { | 351 if (shouldWriteData) { |
| 348 library.isExternal = isExternal; | 352 library.isExternal = isExternal; |
| 349 library.name = name; | 353 library.name = name; |
| 350 library.fileUri = fileUri; | 354 library.fileUri = fileUri; |
| 351 } | 355 } |
| 352 | 356 |
| 353 _readDeferredImports(library); | 357 _readLibraryDependencies(library); |
| 354 | 358 |
| 355 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); | 359 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); |
| 356 | 360 |
| 357 _mergeNamedNodeList(library.typedefs, readTypedef, library); | 361 _mergeNamedNodeList(library.typedefs, readTypedef, library); |
| 358 _mergeNamedNodeList(library.classes, readClass, library); | 362 _mergeNamedNodeList(library.classes, readClass, library); |
| 359 _mergeNamedNodeList(library.fields, readField, library); | 363 _mergeNamedNodeList(library.fields, readField, library); |
| 360 _mergeNamedNodeList(library.procedures, readProcedure, library); | 364 _mergeNamedNodeList(library.procedures, readProcedure, library); |
| 361 | 365 |
| 362 debugPath.removeLast(); | 366 debugPath.removeLast(); |
| 363 _currentLibrary = null; | 367 _currentLibrary = null; |
| 364 return library; | 368 return library; |
| 365 } | 369 } |
| 366 | 370 |
| 367 void _readDeferredImports(Library library) { | 371 void _readLibraryDependencies(Library library) { |
| 368 int length = readUInt(); | 372 int length = readUInt(); |
| 369 if (library.isExternal) { | 373 if (library.isExternal) { |
| 370 assert(length == 0); | 374 assert(length == 0); |
| 371 return; | 375 return; |
| 372 } | 376 } |
| 373 library.deferredImports.length = length; | 377 library.dependencies.length = length; |
| 374 for (int i = 0; i < length; ++i) { | 378 for (int i = 0; i < length; ++i) { |
| 375 library.deferredImports[i] = new DeferredImport.byReference( | 379 var flags = readByte(); |
| 376 readLibraryReference(), readStringReference()) | 380 var annotations = readExpressionList(); |
| 381 var targetLibrary = readLibraryReference(); |
| 382 var prefixName = readStringOrNullIfEmpty(); |
| 383 var names = readCombinatorList(); |
| 384 library.dependencies[i] = new LibraryDependency.byReference( |
| 385 flags, annotations, targetLibrary, prefixName, names) |
| 377 ..parent = library; | 386 ..parent = library; |
| 378 } | 387 } |
| 379 } | 388 } |
| 380 | 389 |
| 390 Combinator readCombinator() { |
| 391 var isShow = readUInt() == 1; |
| 392 var names = readStringReferenceList(); |
| 393 return new Combinator(isShow, names); |
| 394 } |
| 395 |
| 396 List<Combinator> readCombinatorList() { |
| 397 return new List<Combinator>.generate(readUInt(), (i) => readCombinator()); |
| 398 } |
| 399 |
| 381 Typedef readTypedef() { | 400 Typedef readTypedef() { |
| 382 var canonicalName = readCanonicalNameReference(); | 401 var canonicalName = readCanonicalNameReference(); |
| 383 var reference = canonicalName.getReference(); | 402 var reference = canonicalName.getReference(); |
| 384 Typedef node = reference.node; | 403 Typedef node = reference.node; |
| 385 bool shouldWriteData = node == null || _isReadingLibraryImplementation; | 404 bool shouldWriteData = node == null || _isReadingLibraryImplementation; |
| 386 if (node == null) { | 405 if (node == null) { |
| 387 node = new Typedef(null, null, reference: reference); | 406 node = new Typedef(null, null, reference: reference); |
| 388 } | 407 } |
| 389 int fileOffset = readOffset(); | 408 int fileOffset = readOffset(); |
| 390 String name = readStringReference(); | 409 String name = readStringReference(); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 return readAndCheckOptionTag() ? readExpression() : null; | 670 return readAndCheckOptionTag() ? readExpression() : null; |
| 652 } | 671 } |
| 653 | 672 |
| 654 Expression readExpression() { | 673 Expression readExpression() { |
| 655 int tagByte = readByte(); | 674 int tagByte = readByte(); |
| 656 int tag = tagByte & Tag.SpecializedTagHighBit == 0 | 675 int tag = tagByte & Tag.SpecializedTagHighBit == 0 |
| 657 ? tagByte | 676 ? tagByte |
| 658 : (tagByte & Tag.SpecializedTagMask); | 677 : (tagByte & Tag.SpecializedTagMask); |
| 659 switch (tag) { | 678 switch (tag) { |
| 660 case Tag.LoadLibrary: | 679 case Tag.LoadLibrary: |
| 661 return new LoadLibrary(readDeferredImportReference()); | 680 return new LoadLibrary(readLibraryDependencyReference()); |
| 662 case Tag.CheckLibraryIsLoaded: | 681 case Tag.CheckLibraryIsLoaded: |
| 663 return new CheckLibraryIsLoaded(readDeferredImportReference()); | 682 return new CheckLibraryIsLoaded(readLibraryDependencyReference()); |
| 664 case Tag.InvalidExpression: | 683 case Tag.InvalidExpression: |
| 665 return new InvalidExpression(); | 684 return new InvalidExpression(); |
| 666 case Tag.VariableGet: | 685 case Tag.VariableGet: |
| 667 int offset = readOffset(); | 686 int offset = readOffset(); |
| 668 readUInt(); // offset of the variable declaration in the binary. | 687 readUInt(); // offset of the variable declaration in the binary. |
| 669 return new VariableGet(readVariableReference(), readDartTypeOption()) | 688 return new VariableGet(readVariableReference(), readDartTypeOption()) |
| 670 ..fileOffset = offset; | 689 ..fileOffset = offset; |
| 671 case Tag.SpecializedVariableGet: | 690 case Tag.SpecializedVariableGet: |
| 672 int index = tagByte & Tag.SpecializedPayloadMask; | 691 int index = tagByte & Tag.SpecializedPayloadMask; |
| 673 int offset = readOffset(); | 692 int offset = readOffset(); |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 ..fileOffset = offset | 1191 ..fileOffset = offset |
| 1173 ..fileEqualsOffset = fileEqualsOffset; | 1192 ..fileEqualsOffset = fileEqualsOffset; |
| 1174 } | 1193 } |
| 1175 | 1194 |
| 1176 int readOffset() { | 1195 int readOffset() { |
| 1177 // Offset is saved as unsigned, | 1196 // Offset is saved as unsigned, |
| 1178 // but actually ranges from -1 and up (thus the -1) | 1197 // but actually ranges from -1 and up (thus the -1) |
| 1179 return readUInt() - 1; | 1198 return readUInt() - 1; |
| 1180 } | 1199 } |
| 1181 } | 1200 } |
| OLD | NEW |