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

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

Issue 2953703002: Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service (Closed)
Patch Set: cl review updates: cleanup in kernel deserialization Created 3 years, 5 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
« no previous file with comments | « pkg/front_end/tool/perf.dart ('k') | pkg/kernel/lib/binary/limited_ast_to_binary.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 list.length = readUInt(); 162 var length = readUInt();
163 for (int i = 0; i < list.length; ++i) { 163 list.length = length;
164 list[i] = buildObject()..parent = parent; 164 for (int i = 0; i < length; ++i) {
165 TreeNode object = buildObject();
166 list[i] = object..parent = parent;
165 } 167 }
166 } 168 }
167 169
168 void _fillNonTreeNodeList(List<Node> list, Node buildObject()) { 170 void _fillNonTreeNodeList(List<Node> list, Node buildObject()) {
169 list.length = readUInt(); 171 var length = readUInt();
170 for (int i = 0; i < list.length; ++i) { 172 list.length = length;
171 list[i] = buildObject(); 173 for (int i = 0; i < length; ++i) {
174 Node object = buildObject();
175 list[i] = object;
172 } 176 }
173 } 177 }
174 178
179 void _skipNodeList(Node skipObject()) {
180 var length = readUInt();
181 for (int i = 0; i < length; ++i) {
182 skipObject();
183 }
184 }
185
175 /// Reads a list of named nodes, reusing any existing objects already in the 186 /// Reads a list of named nodes, reusing any existing objects already in the
176 /// linking tree. The nodes are merged into [list], and if reading the library 187 /// linking tree. The nodes are merged into [list], and if reading the library
177 /// implementation, the order is corrected. 188 /// implementation, the order is corrected.
178 /// 189 ///
179 /// [readObject] should read the object definition and its canonical name. 190 /// [readObject] should read the object definition and its canonical name.
180 /// If an existing object is bound to the canonical name, the existing object 191 /// If an existing object is bound to the canonical name, the existing object
181 /// must be reused and returned. 192 /// must be reused and returned.
182 void _mergeNamedNodeList( 193 void _mergeNamedNodeList(
183 List<NamedNode> list, NamedNode readObject(), TreeNode parent) { 194 List<NamedNode> list, NamedNode readObject(), TreeNode parent) {
184 if (_isReadingLibraryImplementation) { 195 if (_isReadingLibraryImplementation) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 String fileUri = readUriReference(); 360 String fileUri = readUriReference();
350 361
351 if (shouldWriteData) { 362 if (shouldWriteData) {
352 library.isExternal = isExternal; 363 library.isExternal = isExternal;
353 library.name = name; 364 library.name = name;
354 library.fileUri = fileUri; 365 library.fileUri = fileUri;
355 } 366 }
356 367
357 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); 368 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library');
358 369
359 _fillTreeNodeList(library.annotations, readExpression, library); 370 if (shouldWriteData) {
371 _fillTreeNodeList(library.annotations, readExpression, library);
372 } else {
373 _skipNodeList(readExpression);
374 }
360 _readLibraryDependencies(library); 375 _readLibraryDependencies(library);
361 _mergeNamedNodeList(library.typedefs, readTypedef, library); 376 _mergeNamedNodeList(library.typedefs, readTypedef, library);
362 _mergeNamedNodeList(library.classes, readClass, library); 377 _mergeNamedNodeList(library.classes, readClass, library);
363 _mergeNamedNodeList(library.fields, readField, library); 378 _mergeNamedNodeList(library.fields, readField, library);
364 _mergeNamedNodeList(library.procedures, readProcedure, library); 379 _mergeNamedNodeList(library.procedures, readProcedure, library);
365 380
366 debugPath.removeLast(); 381 debugPath.removeLast();
367 _currentLibrary = null; 382 _currentLibrary = null;
368 return library; 383 return library;
369 } 384 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 if (level.index >= node.level.index) { 453 if (level.index >= node.level.index) {
439 node.level = level; 454 node.level = level;
440 } 455 }
441 var name = readStringOrNullIfEmpty(); 456 var name = readStringOrNullIfEmpty();
442 var fileUri = readUriReference(); 457 var fileUri = readUriReference();
443 var annotations = readAnnotationList(node); 458 var annotations = readAnnotationList(node);
444 debugPath.add(node.name ?? 'normal-class'); 459 debugPath.add(node.name ?? 'normal-class');
445 readAndPushTypeParameterList(node.typeParameters, node); 460 readAndPushTypeParameterList(node.typeParameters, node);
446 var supertype = readSupertypeOption(); 461 var supertype = readSupertypeOption();
447 var mixedInType = readSupertypeOption(); 462 var mixedInType = readSupertypeOption();
448 _fillNonTreeNodeList(node.implementedTypes, readSupertype); 463 if (shouldWriteData) {
464 _fillNonTreeNodeList(node.implementedTypes, readSupertype);
465 } else {
466 _skipNodeList(readSupertype);
467 }
449 _mergeNamedNodeList(node.fields, readField, node); 468 _mergeNamedNodeList(node.fields, readField, node);
450 _mergeNamedNodeList(node.constructors, readConstructor, node); 469 _mergeNamedNodeList(node.constructors, readConstructor, node);
451 _mergeNamedNodeList(node.procedures, readProcedure, node); 470 _mergeNamedNodeList(node.procedures, readProcedure, node);
452 typeParameterStack.length = 0; 471 typeParameterStack.length = 0;
453 debugPath.removeLast(); 472 debugPath.removeLast();
454 if (shouldWriteData) { 473 if (shouldWriteData) {
455 node.name = name; 474 node.name = name;
456 node.fileUri = fileUri; 475 node.fileUri = fileUri;
457 node.annotations = annotations; 476 node.annotations = annotations;
458 node.supertype = supertype; 477 node.supertype = supertype;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 var fileOffset = readOffset(); 541 var fileOffset = readOffset();
523 var fileEndOffset = readOffset(); 542 var fileEndOffset = readOffset();
524 var flags = readByte(); 543 var flags = readByte();
525 readUInt(); // parent class binary offset. 544 readUInt(); // parent class binary offset.
526 var name = readName(); 545 var name = readName();
527 var annotations = readAnnotationList(node); 546 var annotations = readAnnotationList(node);
528 debugPath.add(node.name?.name ?? 'constructor'); 547 debugPath.add(node.name?.name ?? 'constructor');
529 var function = readFunctionNode(); 548 var function = readFunctionNode();
530 pushVariableDeclarations(function.positionalParameters); 549 pushVariableDeclarations(function.positionalParameters);
531 pushVariableDeclarations(function.namedParameters); 550 pushVariableDeclarations(function.namedParameters);
532 _fillTreeNodeList(node.initializers, readInitializer, node); 551 if (shouldWriteData) {
552 _fillTreeNodeList(node.initializers, readInitializer, node);
553 } else {
554 _skipNodeList(readInitializer);
555 }
533 variableStack.length = 0; 556 variableStack.length = 0;
534 var transformerFlags = getAndResetTransformerFlags(); 557 var transformerFlags = getAndResetTransformerFlags();
535 debugPath.removeLast(); 558 debugPath.removeLast();
536 if (shouldWriteData) { 559 if (shouldWriteData) {
537 node.fileOffset = fileOffset; 560 node.fileOffset = fileOffset;
538 node.fileEndOffset = fileEndOffset; 561 node.fileEndOffset = fileEndOffset;
539 node.flags = flags; 562 node.flags = flags;
540 node.name = name; 563 node.name = name;
541 node.annotations = annotations; 564 node.annotations = annotations;
542 node.function = function..parent = node; 565 node.function = function..parent = node;
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 ..fileOffset = offset 1224 ..fileOffset = offset
1202 ..fileEqualsOffset = fileEqualsOffset; 1225 ..fileEqualsOffset = fileEqualsOffset;
1203 } 1226 }
1204 1227
1205 int readOffset() { 1228 int readOffset() {
1206 // Offset is saved as unsigned, 1229 // Offset is saved as unsigned,
1207 // but actually ranges from -1 and up (thus the -1) 1230 // but actually ranges from -1 and up (thus the -1)
1208 return readUInt() - 1; 1231 return readUInt() - 1;
1209 } 1232 }
1210 } 1233 }
OLDNEW
« no previous file with comments | « pkg/front_end/tool/perf.dart ('k') | pkg/kernel/lib/binary/limited_ast_to_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698