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

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

Issue 2849803002: Revert "Add typedef AST node boilerplate." (Closed)
Patch Set: Created 3 years, 7 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/kernel/lib/ast.dart ('k') | pkg/kernel/lib/binary/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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
320 Name readName() { 316 Name readName() {
321 String text = readStringReference(); 317 String text = readStringReference();
322 if (text.isNotEmpty && text[0] == '_') { 318 if (text.isNotEmpty && text[0] == '_') {
323 return new Name.byReference(text, readLibraryReference()); 319 return new Name.byReference(text, readLibraryReference());
324 } else { 320 } else {
325 return new Name(text); 321 return new Name(text);
326 } 322 }
327 } 323 }
328 324
329 Library readLibrary(Program program) { 325 Library readLibrary(Program program) {
(...skipping 17 matching lines...) Expand all
347 if (shouldWriteData) { 343 if (shouldWriteData) {
348 library.isExternal = isExternal; 344 library.isExternal = isExternal;
349 library.name = name; 345 library.name = name;
350 library.fileUri = fileUri; 346 library.fileUri = fileUri;
351 } 347 }
352 348
353 _readDeferredImports(library); 349 _readDeferredImports(library);
354 350
355 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library'); 351 debugPath.add(library.name ?? library.importUri?.toString() ?? 'library');
356 352
357 _mergeNamedNodeList(library.typedefs, readTypedef, library);
358 _mergeNamedNodeList(library.classes, readClass, library); 353 _mergeNamedNodeList(library.classes, readClass, library);
359 _mergeNamedNodeList(library.fields, readField, library); 354 _mergeNamedNodeList(library.fields, readField, library);
360 _mergeNamedNodeList(library.procedures, readProcedure, library); 355 _mergeNamedNodeList(library.procedures, readProcedure, library);
361 356
362 debugPath.removeLast(); 357 debugPath.removeLast();
363 _currentLibrary = null; 358 _currentLibrary = null;
364 return library; 359 return library;
365 } 360 }
366 361
367 void _readDeferredImports(Library library) { 362 void _readDeferredImports(Library library) {
368 int length = readUInt(); 363 int length = readUInt();
369 if (library.isExternal) { 364 if (library.isExternal) {
370 assert(length == 0); 365 assert(length == 0);
371 return; 366 return;
372 } 367 }
373 library.deferredImports.length = length; 368 library.deferredImports.length = length;
374 for (int i = 0; i < length; ++i) { 369 for (int i = 0; i < length; ++i) {
375 library.deferredImports[i] = new DeferredImport.byReference( 370 library.deferredImports[i] = new DeferredImport.byReference(
376 readLibraryReference(), readStringReference()) 371 readLibraryReference(), readStringReference())
377 ..parent = library; 372 ..parent = library;
378 } 373 }
379 } 374 }
380 375
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
404 Class readClass() { 376 Class readClass() {
405 int tag = readByte(); 377 int tag = readByte();
406 assert(tag == Tag.Class); 378 assert(tag == Tag.Class);
407 var canonicalName = readCanonicalNameReference(); 379 var canonicalName = readCanonicalNameReference();
408 var reference = canonicalName.getReference(); 380 var reference = canonicalName.getReference();
409 Class node = reference.node; 381 Class node = reference.node;
410 bool shouldWriteData = node == null || _isReadingLibraryImplementation; 382 bool shouldWriteData = node == null || _isReadingLibraryImplementation;
411 if (node == null) { 383 if (node == null) {
412 node = new Class(reference: reference)..level = ClassLevel.Temporary; 384 node = new Class(reference: reference)..level = ClassLevel.Temporary;
413 } 385 }
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 return new NamedType(readStringReference(), readDartType()); 1012 return new NamedType(readStringReference(), readDartType());
1041 } 1013 }
1042 1014
1043 DartType readDartTypeOption() { 1015 DartType readDartTypeOption() {
1044 return readAndCheckOptionTag() ? readDartType() : null; 1016 return readAndCheckOptionTag() ? readDartType() : null;
1045 } 1017 }
1046 1018
1047 DartType readDartType() { 1019 DartType readDartType() {
1048 int tag = readByte(); 1020 int tag = readByte();
1049 switch (tag) { 1021 switch (tag) {
1050 case Tag.TypedefType:
1051 return new TypedefType.byReference(
1052 readTypedefReference(), readDartTypeList());
1053 case Tag.VectorType: 1022 case Tag.VectorType:
1054 return const VectorType(); 1023 return const VectorType();
1055 case Tag.BottomType: 1024 case Tag.BottomType:
1056 return const BottomType(); 1025 return const BottomType();
1057 case Tag.InvalidType: 1026 case Tag.InvalidType:
1058 return const InvalidType(); 1027 return const InvalidType();
1059 case Tag.DynamicType: 1028 case Tag.DynamicType:
1060 return const DynamicType(); 1029 return const DynamicType();
1061 case Tag.VoidType: 1030 case Tag.VoidType:
1062 return const VoidType(); 1031 return const VoidType();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 ..fileOffset = offset 1127 ..fileOffset = offset
1159 ..fileEqualsOffset = fileEqualsOffset; 1128 ..fileEqualsOffset = fileEqualsOffset;
1160 } 1129 }
1161 1130
1162 int readOffset() { 1131 int readOffset() {
1163 // Offset is saved as unsigned, 1132 // Offset is saved as unsigned,
1164 // but actually ranges from -1 and up (thus the -1) 1133 // but actually ranges from -1 and up (thus the -1)
1165 return readUInt() - 1; 1134 return readUInt() - 1;
1166 } 1135 }
1167 } 1136 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/ast.dart ('k') | pkg/kernel/lib/binary/ast_to_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698