| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (length == 0) return const <Expression>[]; | 152 if (length == 0) return const <Expression>[]; |
| 153 List<Expression> list = new List<Expression>(length); | 153 List<Expression> list = new List<Expression>(length); |
| 154 for (int i = 0; i < length; ++i) { | 154 for (int i = 0; i < length; ++i) { |
| 155 list[i] = readExpression()..parent = parent; | 155 list[i] = readExpression()..parent = parent; |
| 156 } | 156 } |
| 157 return list; | 157 return list; |
| 158 } | 158 } |
| 159 | 159 |
| 160 void _fillTreeNodeList( | 160 void _fillTreeNodeList( |
| 161 List<TreeNode> list, TreeNode buildObject(), TreeNode parent) { | 161 List<TreeNode> list, TreeNode buildObject(), TreeNode parent) { |
| 162 var length = readUInt(); | 162 list.length = readUInt(); |
| 163 list.length = length; | 163 for (int i = 0; i < list.length; ++i) { |
| 164 for (int i = 0; i < length; ++i) { | 164 list[i] = buildObject()..parent = parent; |
| 165 TreeNode object = buildObject(); | |
| 166 list[i] = object..parent = parent; | |
| 167 } | 165 } |
| 168 } | 166 } |
| 169 | 167 |
| 170 void _fillNonTreeNodeList(List<Node> list, Node buildObject()) { | 168 void _fillNonTreeNodeList(List<Node> list, Node buildObject()) { |
| 171 var length = readUInt(); | 169 list.length = readUInt(); |
| 172 list.length = length; | 170 for (int i = 0; i < list.length; ++i) { |
| 173 for (int i = 0; i < length; ++i) { | 171 list[i] = buildObject(); |
| 174 Node object = buildObject(); | |
| 175 list[i] = object; | |
| 176 } | 172 } |
| 177 } | 173 } |
| 178 | 174 |
| 179 void _skipNodeList(Node skipObject()) { | |
| 180 var length = readUInt(); | |
| 181 for (int i = 0; i < length; ++i) { | |
| 182 skipObject(); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 /// Reads a list of named nodes, reusing any existing objects already in the | 175 /// Reads a list of named nodes, reusing any existing objects already in the |
| 187 /// linking tree. The nodes are merged into [list], and if reading the library | 176 /// linking tree. The nodes are merged into [list], and if reading the library |
| 188 /// implementation, the order is corrected. | 177 /// implementation, the order is corrected. |
| 189 /// | 178 /// |
| 190 /// [readObject] should read the object definition and its canonical name. | 179 /// [readObject] should read the object definition and its canonical name. |
| 191 /// If an existing object is bound to the canonical name, the existing object | 180 /// If an existing object is bound to the canonical name, the existing object |
| 192 /// must be reused and returned. | 181 /// must be reused and returned. |
| 193 void _mergeNamedNodeList( | 182 void _mergeNamedNodeList( |
| 194 List<NamedNode> list, NamedNode readObject(), TreeNode parent) { | 183 List<NamedNode> list, NamedNode readObject(), TreeNode parent) { |
| 195 if (_isReadingLibraryImplementation) { | 184 if (_isReadingLibraryImplementation) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 String fileUri = readUriReference(); | 363 String fileUri = readUriReference(); |
| 375 | 364 |
| 376 if (shouldWriteData) { | 365 if (shouldWriteData) { |
| 377 library.isExternal = isExternal; | 366 library.isExternal = isExternal; |
| 378 library.name = name; | 367 library.name = name; |
| 379 library.fileUri = fileUri; | 368 library.fileUri = fileUri; |
| 380 } | 369 } |
| 381 | 370 |
| 382 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); | 371 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); |
| 383 | 372 |
| 384 if (shouldWriteData) { | 373 _fillTreeNodeList(library.annotations, readExpression, library); |
| 385 _fillTreeNodeList(library.annotations, readExpression, library); | |
| 386 } else { | |
| 387 _skipNodeList(readExpression); | |
| 388 } | |
| 389 _readLibraryDependencies(library); | 374 _readLibraryDependencies(library); |
| 390 _mergeNamedNodeList(library.typedefs, readTypedef, library); | 375 _mergeNamedNodeList(library.typedefs, readTypedef, library); |
| 391 _mergeNamedNodeList(library.classes, readClass, library); | 376 _mergeNamedNodeList(library.classes, readClass, library); |
| 392 _mergeNamedNodeList(library.fields, readField, library); | 377 _mergeNamedNodeList(library.fields, readField, library); |
| 393 _mergeNamedNodeList(library.procedures, readProcedure, library); | 378 _mergeNamedNodeList(library.procedures, readProcedure, library); |
| 394 | 379 |
| 395 debugPath.removeLast(); | 380 debugPath.removeLast(); |
| 396 _currentLibrary = null; | 381 _currentLibrary = null; |
| 397 return library; | 382 return library; |
| 398 } | 383 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 if (level.index >= node.level.index) { | 453 if (level.index >= node.level.index) { |
| 469 node.level = level; | 454 node.level = level; |
| 470 } | 455 } |
| 471 var name = readStringOrNullIfEmpty(); | 456 var name = readStringOrNullIfEmpty(); |
| 472 var fileUri = readUriReference(); | 457 var fileUri = readUriReference(); |
| 473 var annotations = readAnnotationList(node); | 458 var annotations = readAnnotationList(node); |
| 474 debugPath.add(node.name ?? 'normal-class'); | 459 debugPath.add(node.name ?? 'normal-class'); |
| 475 readAndPushTypeParameterList(node.typeParameters, node); | 460 readAndPushTypeParameterList(node.typeParameters, node); |
| 476 var supertype = readSupertypeOption(); | 461 var supertype = readSupertypeOption(); |
| 477 var mixedInType = readSupertypeOption(); | 462 var mixedInType = readSupertypeOption(); |
| 478 if (shouldWriteData) { | 463 _fillNonTreeNodeList(node.implementedTypes, readSupertype); |
| 479 _fillNonTreeNodeList(node.implementedTypes, readSupertype); | |
| 480 } else { | |
| 481 _skipNodeList(readSupertype); | |
| 482 } | |
| 483 _mergeNamedNodeList(node.fields, readField, node); | 464 _mergeNamedNodeList(node.fields, readField, node); |
| 484 _mergeNamedNodeList(node.constructors, readConstructor, node); | 465 _mergeNamedNodeList(node.constructors, readConstructor, node); |
| 485 _mergeNamedNodeList(node.procedures, readProcedure, node); | 466 _mergeNamedNodeList(node.procedures, readProcedure, node); |
| 486 typeParameterStack.length = 0; | 467 typeParameterStack.length = 0; |
| 487 debugPath.removeLast(); | 468 debugPath.removeLast(); |
| 488 if (shouldWriteData) { | 469 if (shouldWriteData) { |
| 489 node.name = name; | 470 node.name = name; |
| 490 node.fileUri = fileUri; | 471 node.fileUri = fileUri; |
| 491 node.annotations = annotations; | 472 node.annotations = annotations; |
| 492 node.supertype = supertype; | 473 node.supertype = supertype; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 var fileOffset = readOffset(); | 537 var fileOffset = readOffset(); |
| 557 var fileEndOffset = readOffset(); | 538 var fileEndOffset = readOffset(); |
| 558 var flags = readByte(); | 539 var flags = readByte(); |
| 559 readUInt(); // parent class binary offset. | 540 readUInt(); // parent class binary offset. |
| 560 var name = readName(); | 541 var name = readName(); |
| 561 var annotations = readAnnotationList(node); | 542 var annotations = readAnnotationList(node); |
| 562 debugPath.add(node.name?.name ?? 'constructor'); | 543 debugPath.add(node.name?.name ?? 'constructor'); |
| 563 var function = readFunctionNode(); | 544 var function = readFunctionNode(); |
| 564 pushVariableDeclarations(function.positionalParameters); | 545 pushVariableDeclarations(function.positionalParameters); |
| 565 pushVariableDeclarations(function.namedParameters); | 546 pushVariableDeclarations(function.namedParameters); |
| 566 if (shouldWriteData) { | 547 _fillTreeNodeList(node.initializers, readInitializer, node); |
| 567 _fillTreeNodeList(node.initializers, readInitializer, node); | |
| 568 } else { | |
| 569 _skipNodeList(readInitializer); | |
| 570 } | |
| 571 variableStack.length = 0; | 548 variableStack.length = 0; |
| 572 var transformerFlags = getAndResetTransformerFlags(); | 549 var transformerFlags = getAndResetTransformerFlags(); |
| 573 debugPath.removeLast(); | 550 debugPath.removeLast(); |
| 574 if (shouldWriteData) { | 551 if (shouldWriteData) { |
| 575 node.fileOffset = fileOffset; | 552 node.fileOffset = fileOffset; |
| 576 node.fileEndOffset = fileEndOffset; | 553 node.fileEndOffset = fileEndOffset; |
| 577 node.flags = flags; | 554 node.flags = flags; |
| 578 node.name = name; | 555 node.name = name; |
| 579 node.annotations = annotations; | 556 node.annotations = annotations; |
| 580 node.function = function..parent = node; | 557 node.function = function..parent = node; |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 ..fileOffset = offset | 1216 ..fileOffset = offset |
| 1240 ..fileEqualsOffset = fileEqualsOffset; | 1217 ..fileEqualsOffset = fileEqualsOffset; |
| 1241 } | 1218 } |
| 1242 | 1219 |
| 1243 int readOffset() { | 1220 int readOffset() { |
| 1244 // Offset is saved as unsigned, | 1221 // Offset is saved as unsigned, |
| 1245 // but actually ranges from -1 and up (thus the -1) | 1222 // but actually ranges from -1 and up (thus the -1) |
| 1246 return readUInt() - 1; | 1223 return readUInt() - 1; |
| 1247 } | 1224 } |
| 1248 } | 1225 } |
| OLD | NEW |