| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 } | 306 } |
| 307 | 307 |
| 308 Reference readMemberReference({bool allowNull: false}) { | 308 Reference readMemberReference({bool allowNull: false}) { |
| 309 var name = readCanonicalNameReference(); | 309 var name = readCanonicalNameReference(); |
| 310 if (name == null && !allowNull) { | 310 if (name == null && !allowNull) { |
| 311 throw 'Expected a member reference to be valid but was `null`.'; | 311 throw 'Expected a member reference to be valid but was `null`.'; |
| 312 } | 312 } |
| 313 return name?.getReference(); | 313 return name?.getReference(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 Reference readTypedefReference() { |
| 317 return readCanonicalNameReference().getReference(); |
| 318 } |
| 319 |
| 316 Name readName() { | 320 Name readName() { |
| 317 String text = readStringReference(); | 321 String text = readStringReference(); |
| 318 if (text.isNotEmpty && text[0] == '_') { | 322 if (text.isNotEmpty && text[0] == '_') { |
| 319 return new Name.byReference(text, readLibraryReference()); | 323 return new Name.byReference(text, readLibraryReference()); |
| 320 } else { | 324 } else { |
| 321 return new Name(text); | 325 return new Name(text); |
| 322 } | 326 } |
| 323 } | 327 } |
| 324 | 328 |
| 325 Library readLibrary(Program program) { | 329 Library readLibrary(Program program) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 343 if (shouldWriteData) { | 347 if (shouldWriteData) { |
| 344 library.isExternal = isExternal; | 348 library.isExternal = isExternal; |
| 345 library.name = name; | 349 library.name = name; |
| 346 library.fileUri = fileUri; | 350 library.fileUri = fileUri; |
| 347 } | 351 } |
| 348 | 352 |
| 349 _readDeferredImports(library); | 353 _readDeferredImports(library); |
| 350 | 354 |
| 351 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); | 355 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); |
| 352 | 356 |
| 357 _mergeNamedNodeList(library.typedefs, readTypedef, library); |
| 353 _mergeNamedNodeList(library.classes, readClass, library); | 358 _mergeNamedNodeList(library.classes, readClass, library); |
| 354 _mergeNamedNodeList(library.fields, readField, library); | 359 _mergeNamedNodeList(library.fields, readField, library); |
| 355 _mergeNamedNodeList(library.procedures, readProcedure, library); | 360 _mergeNamedNodeList(library.procedures, readProcedure, library); |
| 356 | 361 |
| 357 debugPath.removeLast(); | 362 debugPath.removeLast(); |
| 358 _currentLibrary = null; | 363 _currentLibrary = null; |
| 359 return library; | 364 return library; |
| 360 } | 365 } |
| 361 | 366 |
| 362 void _readDeferredImports(Library library) { | 367 void _readDeferredImports(Library library) { |
| 363 int length = readUInt(); | 368 int length = readUInt(); |
| 364 if (library.isExternal) { | 369 if (library.isExternal) { |
| 365 assert(length == 0); | 370 assert(length == 0); |
| 366 return; | 371 return; |
| 367 } | 372 } |
| 368 library.deferredImports.length = length; | 373 library.deferredImports.length = length; |
| 369 for (int i = 0; i < length; ++i) { | 374 for (int i = 0; i < length; ++i) { |
| 370 library.deferredImports[i] = new DeferredImport.byReference( | 375 library.deferredImports[i] = new DeferredImport.byReference( |
| 371 readLibraryReference(), readStringReference()) | 376 readLibraryReference(), readStringReference()) |
| 372 ..parent = library; | 377 ..parent = library; |
| 373 } | 378 } |
| 374 } | 379 } |
| 375 | 380 |
| 381 Typedef readTypedef() { |
| 382 var canonicalName = readCanonicalNameReference(); |
| 383 var reference = canonicalName.getReference(); |
| 384 Typedef node = reference.node; |
| 385 bool shouldWriteData = node == null || _isReadingLibraryImplementation; |
| 386 if (node == null) { |
| 387 node = new Typedef(null, null, reference: reference); |
| 388 } |
| 389 int fileOffset = readOffset(); |
| 390 String name = readStringReference(); |
| 391 String fileUri = readUriReference(); |
| 392 readAndPushTypeParameterList(node.typeParameters, node); |
| 393 var type = readDartType(); |
| 394 typeParameterStack.length = 0; |
| 395 if (shouldWriteData) { |
| 396 node.fileOffset = fileOffset; |
| 397 node.name = name; |
| 398 node.fileUri = fileUri; |
| 399 node.type = type; |
| 400 } |
| 401 return node; |
| 402 } |
| 403 |
| 376 Class readClass() { | 404 Class readClass() { |
| 377 int tag = readByte(); | 405 int tag = readByte(); |
| 378 assert(tag == Tag.Class); | 406 assert(tag == Tag.Class); |
| 379 var canonicalName = readCanonicalNameReference(); | 407 var canonicalName = readCanonicalNameReference(); |
| 380 var reference = canonicalName.getReference(); | 408 var reference = canonicalName.getReference(); |
| 381 Class node = reference.node; | 409 Class node = reference.node; |
| 382 bool shouldWriteData = node == null || _isReadingLibraryImplementation; | 410 bool shouldWriteData = node == null || _isReadingLibraryImplementation; |
| 383 if (node == null) { | 411 if (node == null) { |
| 384 node = new Class(reference: reference)..level = ClassLevel.Temporary; | 412 node = new Class(reference: reference)..level = ClassLevel.Temporary; |
| 385 } | 413 } |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 return new NamedType(readStringReference(), readDartType()); | 1040 return new NamedType(readStringReference(), readDartType()); |
| 1013 } | 1041 } |
| 1014 | 1042 |
| 1015 DartType readDartTypeOption() { | 1043 DartType readDartTypeOption() { |
| 1016 return readAndCheckOptionTag() ? readDartType() : null; | 1044 return readAndCheckOptionTag() ? readDartType() : null; |
| 1017 } | 1045 } |
| 1018 | 1046 |
| 1019 DartType readDartType() { | 1047 DartType readDartType() { |
| 1020 int tag = readByte(); | 1048 int tag = readByte(); |
| 1021 switch (tag) { | 1049 switch (tag) { |
| 1050 case Tag.TypedefType: |
| 1051 return new TypedefType.byReference( |
| 1052 readTypedefReference(), readDartTypeList()); |
| 1022 case Tag.VectorType: | 1053 case Tag.VectorType: |
| 1023 return const VectorType(); | 1054 return const VectorType(); |
| 1024 case Tag.BottomType: | 1055 case Tag.BottomType: |
| 1025 return const BottomType(); | 1056 return const BottomType(); |
| 1026 case Tag.InvalidType: | 1057 case Tag.InvalidType: |
| 1027 return const InvalidType(); | 1058 return const InvalidType(); |
| 1028 case Tag.DynamicType: | 1059 case Tag.DynamicType: |
| 1029 return const DynamicType(); | 1060 return const DynamicType(); |
| 1030 case Tag.VoidType: | 1061 case Tag.VoidType: |
| 1031 return const VoidType(); | 1062 return const VoidType(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 ..fileOffset = offset | 1158 ..fileOffset = offset |
| 1128 ..fileEqualsOffset = fileEqualsOffset; | 1159 ..fileEqualsOffset = fileEqualsOffset; |
| 1129 } | 1160 } |
| 1130 | 1161 |
| 1131 int readOffset() { | 1162 int readOffset() { |
| 1132 // Offset is saved as unsigned, | 1163 // Offset is saved as unsigned, |
| 1133 // but actually ranges from -1 and up (thus the -1) | 1164 // but actually ranges from -1 and up (thus the -1) |
| 1134 return readUInt() - 1; | 1165 return readUInt() - 1; |
| 1135 } | 1166 } |
| 1136 } | 1167 } |
| OLD | NEW |