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

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: 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
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 List<Expression> readAnnotationList(TreeNode parent) { 150 List<Expression> readAnnotationList(TreeNode parent) {
151 int length = readUInt(); 151 int length = readUInt();
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(List<TreeNode> list, TreeNode buildObject(),
ahe 2017/07/06 13:12:22 If it isn't just me that find this method confusin
Siggi Cherem (dart-lang) 2017/07/06 19:05:28 I like it. Done.
161 List<TreeNode> list, TreeNode buildObject(), TreeNode parent) { 161 TreeNode parent, bool shouldWriteData) {
162 list.length = readUInt(); 162 var length = readUInt();
163 for (int i = 0; i < list.length; ++i) { 163 if (shouldWriteData) list.length = length;
164 list[i] = buildObject()..parent = parent; 164 for (int i = 0; i < length; ++i) {
165 TreeNode object = buildObject();
166 if (shouldWriteData) {
167 list[i] = object..parent = parent;
168 }
165 } 169 }
166 } 170 }
167 171
168 void _fillNonTreeNodeList(List<Node> list, Node buildObject()) { 172 void _fillNonTreeNodeList(
169 list.length = readUInt(); 173 List<Node> list, Node buildObject(), bool shouldWriteData) {
170 for (int i = 0; i < list.length; ++i) { 174 var length = readUInt();
171 list[i] = buildObject(); 175 if (shouldWriteData) list.length = length;
176 for (int i = 0; i < length; ++i) {
177 Node object = buildObject();
178 if (shouldWriteData) {
179 list[i] = object;
180 }
172 } 181 }
173 } 182 }
174 183
175 /// Reads a list of named nodes, reusing any existing objects already in the 184 /// 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 185 /// linking tree. The nodes are merged into [list], and if reading the library
177 /// implementation, the order is corrected. 186 /// implementation, the order is corrected.
178 /// 187 ///
179 /// [readObject] should read the object definition and its canonical name. 188 /// [readObject] should read the object definition and its canonical name.
180 /// If an existing object is bound to the canonical name, the existing object 189 /// If an existing object is bound to the canonical name, the existing object
181 /// must be reused and returned. 190 /// must be reused and returned.
182 void _mergeNamedNodeList( 191 void _mergeNamedNodeList(
183 List<NamedNode> list, NamedNode readObject(), TreeNode parent) { 192 List<NamedNode> list, NamedNode readObject(), TreeNode parent) {
184 if (_isReadingLibraryImplementation) { 193 if (_isReadingLibraryImplementation) {
185 // When reading the library implementation, overwrite the whole list 194 // When reading the library implementation, overwrite the whole list
186 // with the new one. 195 // with the new one.
187 _fillTreeNodeList(list, readObject, parent); 196 _fillTreeNodeList(list, readObject, parent, true);
188 } else { 197 } else {
189 // When reading an external library, the results should either be: 198 // When reading an external library, the results should either be:
190 // - merged with the existing external library definition (if any) 199 // - merged with the existing external library definition (if any)
191 // - ignored if the library implementation is already in memory 200 // - ignored if the library implementation is already in memory
192 int numberOfNodes = readUInt(); 201 int numberOfNodes = readUInt();
193 for (int i = 0; i < numberOfNodes; ++i) { 202 for (int i = 0; i < numberOfNodes; ++i) {
194 var value = readObject(); 203 var value = readObject();
195 // We use the parent pointer of a node to determine if it already is in 204 // We use the parent pointer of a node to determine if it already is in
196 // the AST and hence should not be added again. 205 // the AST and hence should not be added again.
197 if (value.parent == null) { 206 if (value.parent == null) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 String fileUri = readUriReference(); 358 String fileUri = readUriReference();
350 359
351 if (shouldWriteData) { 360 if (shouldWriteData) {
352 library.isExternal = isExternal; 361 library.isExternal = isExternal;
353 library.name = name; 362 library.name = name;
354 library.fileUri = fileUri; 363 library.fileUri = fileUri;
355 } 364 }
356 365
357 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); 366 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library');
358 367
359 _fillTreeNodeList(library.annotations, readExpression, library); 368 _fillTreeNodeList(
369 library.annotations, readExpression, library, shouldWriteData);
360 _readLibraryDependencies(library); 370 _readLibraryDependencies(library);
361 _mergeNamedNodeList(library.typedefs, readTypedef, library); 371 _mergeNamedNodeList(library.typedefs, readTypedef, library);
362 _mergeNamedNodeList(library.classes, readClass, library); 372 _mergeNamedNodeList(library.classes, readClass, library);
363 _mergeNamedNodeList(library.fields, readField, library); 373 _mergeNamedNodeList(library.fields, readField, library);
364 _mergeNamedNodeList(library.procedures, readProcedure, library); 374 _mergeNamedNodeList(library.procedures, readProcedure, library);
365 375
366 debugPath.removeLast(); 376 debugPath.removeLast();
367 _currentLibrary = null; 377 _currentLibrary = null;
368 return library; 378 return library;
369 } 379 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 if (level.index >= node.level.index) { 448 if (level.index >= node.level.index) {
439 node.level = level; 449 node.level = level;
440 } 450 }
441 var name = readStringOrNullIfEmpty(); 451 var name = readStringOrNullIfEmpty();
442 var fileUri = readUriReference(); 452 var fileUri = readUriReference();
443 var annotations = readAnnotationList(node); 453 var annotations = readAnnotationList(node);
444 debugPath.add(node.name ?? 'normal-class'); 454 debugPath.add(node.name ?? 'normal-class');
445 readAndPushTypeParameterList(node.typeParameters, node); 455 readAndPushTypeParameterList(node.typeParameters, node);
446 var supertype = readSupertypeOption(); 456 var supertype = readSupertypeOption();
447 var mixedInType = readSupertypeOption(); 457 var mixedInType = readSupertypeOption();
448 _fillNonTreeNodeList(node.implementedTypes, readSupertype); 458 _fillNonTreeNodeList(node.implementedTypes, readSupertype, shouldWriteData);
449 _mergeNamedNodeList(node.fields, readField, node); 459 _mergeNamedNodeList(node.fields, readField, node);
450 _mergeNamedNodeList(node.constructors, readConstructor, node); 460 _mergeNamedNodeList(node.constructors, readConstructor, node);
451 _mergeNamedNodeList(node.procedures, readProcedure, node); 461 _mergeNamedNodeList(node.procedures, readProcedure, node);
452 typeParameterStack.length = 0; 462 typeParameterStack.length = 0;
453 debugPath.removeLast(); 463 debugPath.removeLast();
454 if (shouldWriteData) { 464 if (shouldWriteData) {
455 node.name = name; 465 node.name = name;
456 node.fileUri = fileUri; 466 node.fileUri = fileUri;
457 node.annotations = annotations; 467 node.annotations = annotations;
458 node.supertype = supertype; 468 node.supertype = supertype;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 var fileOffset = readOffset(); 532 var fileOffset = readOffset();
523 var fileEndOffset = readOffset(); 533 var fileEndOffset = readOffset();
524 var flags = readByte(); 534 var flags = readByte();
525 readUInt(); // parent class binary offset. 535 readUInt(); // parent class binary offset.
526 var name = readName(); 536 var name = readName();
527 var annotations = readAnnotationList(node); 537 var annotations = readAnnotationList(node);
528 debugPath.add(node.name?.name ?? 'constructor'); 538 debugPath.add(node.name?.name ?? 'constructor');
529 var function = readFunctionNode(); 539 var function = readFunctionNode();
530 pushVariableDeclarations(function.positionalParameters); 540 pushVariableDeclarations(function.positionalParameters);
531 pushVariableDeclarations(function.namedParameters); 541 pushVariableDeclarations(function.namedParameters);
532 _fillTreeNodeList(node.initializers, readInitializer, node); 542 _fillTreeNodeList(
543 node.initializers, readInitializer, node, shouldWriteData);
533 variableStack.length = 0; 544 variableStack.length = 0;
534 var transformerFlags = getAndResetTransformerFlags(); 545 var transformerFlags = getAndResetTransformerFlags();
535 debugPath.removeLast(); 546 debugPath.removeLast();
536 if (shouldWriteData) { 547 if (shouldWriteData) {
537 node.fileOffset = fileOffset; 548 node.fileOffset = fileOffset;
538 node.fileEndOffset = fileEndOffset; 549 node.fileEndOffset = fileEndOffset;
539 node.flags = flags; 550 node.flags = flags;
540 node.name = name; 551 node.name = name;
541 node.annotations = annotations; 552 node.annotations = annotations;
542 node.function = function..parent = node; 553 node.function = function..parent = node;
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 ..fileOffset = offset 1212 ..fileOffset = offset
1202 ..fileEqualsOffset = fileEqualsOffset; 1213 ..fileEqualsOffset = fileEqualsOffset;
1203 } 1214 }
1204 1215
1205 int readOffset() { 1216 int readOffset() {
1206 // Offset is saved as unsigned, 1217 // Offset is saved as unsigned,
1207 // but actually ranges from -1 and up (thus the -1) 1218 // but actually ranges from -1 and up (thus the -1)
1208 return readUInt() - 1; 1219 return readUInt() - 1;
1209 } 1220 }
1210 } 1221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698