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

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

Issue 2750013002: [kernel] Debugging of switch statement (Closed)
Patch Set: Addressed comments Created 3 years, 9 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/binary/ast_from_binary.dart ('k') | pkg/kernel/lib/clone.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_to_binary; 4 library kernel.ast_to_binary;
5 5
6 import '../ast.dart'; 6 import '../ast.dart';
7 import '../import_table.dart'; 7 import '../import_table.dart';
8 import 'tag.dart'; 8 import 'tag.dart';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 writeByte(0); 214 writeByte(0);
215 } else { 215 } else {
216 writeUInt30(name.index + 1); 216 writeUInt30(name.index + 1);
217 } 217 }
218 } 218 }
219 219
220 void writeLibraryReference(Library node) { 220 void writeLibraryReference(Library node) {
221 writeCanonicalNameReference(node.canonicalName); 221 writeCanonicalNameReference(node.canonicalName);
222 } 222 }
223 223
224 writeOffset(TreeNode node, int offset) { 224 writeOffset(int offset) {
225 // TODO(jensj): Delta-encoding. 225 // TODO(jensj): Delta-encoding.
226 // File offset ranges from -1 and up, 226 // File offset ranges from -1 and up,
227 // but is here saved as unsigned (thus the +1) 227 // but is here saved as unsigned (thus the +1)
228 writeUInt30(offset + 1); 228 writeUInt30(offset + 1);
229 } 229 }
230 230
231 void writeClassReference(Class class_, {bool allowNull: false}) { 231 void writeClassReference(Class class_, {bool allowNull: false}) {
232 if (class_ == null && !allowNull) { 232 if (class_ == null && !allowNull) {
233 throw 'Expected a class reference to be valid but was `null`.'; 233 throw 'Expected a class reference to be valid but was `null`.';
234 } 234 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return abstactFlag | levelFlags; 298 return abstactFlag | levelFlags;
299 } 299 }
300 300
301 visitClass(Class node) { 301 visitClass(Class node) {
302 int flags = _encodeClassFlags(node.isAbstract, node.level); 302 int flags = _encodeClassFlags(node.isAbstract, node.level);
303 if (node.canonicalName == null) { 303 if (node.canonicalName == null) {
304 throw 'Missing canonical name for $node'; 304 throw 'Missing canonical name for $node';
305 } 305 }
306 writeByte(Tag.Class); 306 writeByte(Tag.Class);
307 writeCanonicalNameReference(getCanonicalNameOfClass(node)); 307 writeCanonicalNameReference(getCanonicalNameOfClass(node));
308 writeOffset(node, node.fileOffset); 308 writeOffset(node.fileOffset);
309 writeByte(flags); 309 writeByte(flags);
310 writeStringReference(node.name ?? ''); 310 writeStringReference(node.name ?? '');
311 writeUriReference(node.fileUri ?? ''); 311 writeUriReference(node.fileUri ?? '');
312 writeAnnotationList(node.annotations); 312 writeAnnotationList(node.annotations);
313 _typeParameterIndexer.enter(node.typeParameters); 313 _typeParameterIndexer.enter(node.typeParameters);
314 writeNodeList(node.typeParameters); 314 writeNodeList(node.typeParameters);
315 writeOptionalNode(node.supertype); 315 writeOptionalNode(node.supertype);
316 writeOptionalNode(node.mixedInType); 316 writeOptionalNode(node.mixedInType);
317 writeNodeList(node.implementedTypes); 317 writeNodeList(node.implementedTypes);
318 writeNodeList(node.fields); 318 writeNodeList(node.fields);
319 writeNodeList(node.constructors); 319 writeNodeList(node.constructors);
320 writeNodeList(node.procedures); 320 writeNodeList(node.procedures);
321 _typeParameterIndexer.exit(node.typeParameters); 321 _typeParameterIndexer.exit(node.typeParameters);
322 } 322 }
323 323
324 static final Name _emptyName = new Name(''); 324 static final Name _emptyName = new Name('');
325 325
326 visitConstructor(Constructor node) { 326 visitConstructor(Constructor node) {
327 if (node.canonicalName == null) { 327 if (node.canonicalName == null) {
328 throw 'Missing canonical name for $node'; 328 throw 'Missing canonical name for $node';
329 } 329 }
330 _variableIndexer = new VariableIndexer(); 330 _variableIndexer = new VariableIndexer();
331 writeByte(Tag.Constructor); 331 writeByte(Tag.Constructor);
332 writeCanonicalNameReference(getCanonicalNameOfMember(node)); 332 writeCanonicalNameReference(getCanonicalNameOfMember(node));
333 writeOffset(node, node.fileOffset); 333 writeOffset(node.fileOffset);
334 writeOffset(node, node.fileEndOffset); 334 writeOffset(node.fileEndOffset);
335 writeByte(node.flags); 335 writeByte(node.flags);
336 writeName(node.name ?? _emptyName); 336 writeName(node.name ?? _emptyName);
337 writeAnnotationList(node.annotations); 337 writeAnnotationList(node.annotations);
338 assert(node.function.typeParameters.isEmpty); 338 assert(node.function.typeParameters.isEmpty);
339 writeNode(node.function); 339 writeNode(node.function);
340 // Parameters are in scope in the initializers. 340 // Parameters are in scope in the initializers.
341 _variableIndexer.restoreScope(node.function.positionalParameters.length + 341 _variableIndexer.restoreScope(node.function.positionalParameters.length +
342 node.function.namedParameters.length); 342 node.function.namedParameters.length);
343 writeNodeList(node.initializers); 343 writeNodeList(node.initializers);
344 _variableIndexer = null; 344 _variableIndexer = null;
345 } 345 }
346 346
347 visitProcedure(Procedure node) { 347 visitProcedure(Procedure node) {
348 if (node.canonicalName == null) { 348 if (node.canonicalName == null) {
349 throw 'Missing canonical name for $node'; 349 throw 'Missing canonical name for $node';
350 } 350 }
351 _variableIndexer = new VariableIndexer(); 351 _variableIndexer = new VariableIndexer();
352 writeByte(Tag.Procedure); 352 writeByte(Tag.Procedure);
353 writeCanonicalNameReference(getCanonicalNameOfMember(node)); 353 writeCanonicalNameReference(getCanonicalNameOfMember(node));
354 writeOffset(node, node.fileOffset); 354 writeOffset(node.fileOffset);
355 writeOffset(node, node.fileEndOffset); 355 writeOffset(node.fileEndOffset);
356 writeByte(node.kind.index); 356 writeByte(node.kind.index);
357 writeByte(node.flags); 357 writeByte(node.flags);
358 writeName(node.name ?? ''); 358 writeName(node.name ?? '');
359 writeUriReference(node.fileUri ?? ''); 359 writeUriReference(node.fileUri ?? '');
360 writeAnnotationList(node.annotations); 360 writeAnnotationList(node.annotations);
361 writeOptionalNode(node.function); 361 writeOptionalNode(node.function);
362 _variableIndexer = null; 362 _variableIndexer = null;
363 } 363 }
364 364
365 visitField(Field node) { 365 visitField(Field node) {
366 if (node.canonicalName == null) { 366 if (node.canonicalName == null) {
367 throw 'Missing canonical name for $node'; 367 throw 'Missing canonical name for $node';
368 } 368 }
369 _variableIndexer = new VariableIndexer(); 369 _variableIndexer = new VariableIndexer();
370 writeByte(Tag.Field); 370 writeByte(Tag.Field);
371 writeCanonicalNameReference(getCanonicalNameOfMember(node)); 371 writeCanonicalNameReference(getCanonicalNameOfMember(node));
372 writeOffset(node, node.fileOffset); 372 writeOffset(node.fileOffset);
373 writeOffset(node, node.fileEndOffset); 373 writeOffset(node.fileEndOffset);
374 writeByte(node.flags); 374 writeByte(node.flags);
375 writeName(node.name); 375 writeName(node.name);
376 writeUriReference(node.fileUri ?? ''); 376 writeUriReference(node.fileUri ?? '');
377 writeAnnotationList(node.annotations); 377 writeAnnotationList(node.annotations);
378 writeNode(node.type); 378 writeNode(node.type);
379 writeOptionalInferredValue(node.inferredValue); 379 writeOptionalInferredValue(node.inferredValue);
380 writeOptionalNode(node.initializer); 380 writeOptionalNode(node.initializer);
381 _variableIndexer = null; 381 _variableIndexer = null;
382 } 382 }
383 383
(...skipping 26 matching lines...) Expand all
410 410
411 visitFunctionNode(FunctionNode node) { 411 visitFunctionNode(FunctionNode node) {
412 assert(_variableIndexer != null); 412 assert(_variableIndexer != null);
413 _variableIndexer.pushScope(); 413 _variableIndexer.pushScope();
414 var oldLabels = _labelIndexer; 414 var oldLabels = _labelIndexer;
415 _labelIndexer = new LabelIndexer(); 415 _labelIndexer = new LabelIndexer();
416 var oldCases = _switchCaseIndexer; 416 var oldCases = _switchCaseIndexer;
417 _switchCaseIndexer = new SwitchCaseIndexer(); 417 _switchCaseIndexer = new SwitchCaseIndexer();
418 // Note: FunctionNode has no tag. 418 // Note: FunctionNode has no tag.
419 _typeParameterIndexer.enter(node.typeParameters); 419 _typeParameterIndexer.enter(node.typeParameters);
420 writeOffset(node, node.fileOffset); 420 writeOffset(node.fileOffset);
421 writeOffset(node, node.fileEndOffset); 421 writeOffset(node.fileEndOffset);
422 writeByte(node.asyncMarker.index); 422 writeByte(node.asyncMarker.index);
423 writeByte(node.dartAsyncMarker.index); 423 writeByte(node.dartAsyncMarker.index);
424 writeNodeList(node.typeParameters); 424 writeNodeList(node.typeParameters);
425 writeUInt30(node.requiredParameterCount); 425 writeUInt30(node.requiredParameterCount);
426 writeVariableDeclarationList(node.positionalParameters); 426 writeVariableDeclarationList(node.positionalParameters);
427 writeVariableDeclarationList(node.namedParameters); 427 writeVariableDeclarationList(node.namedParameters);
428 writeNode(node.returnType); 428 writeNode(node.returnType);
429 writeOptionalInferredValue(node.inferredReturnValue); 429 writeOptionalInferredValue(node.inferredReturnValue);
430 writeOptionalNode(node.body); 430 writeOptionalNode(node.body);
431 _labelIndexer = oldLabels; 431 _labelIndexer = oldLabels;
432 _switchCaseIndexer = oldCases; 432 _switchCaseIndexer = oldCases;
433 _typeParameterIndexer.exit(node.typeParameters); 433 _typeParameterIndexer.exit(node.typeParameters);
434 _variableIndexer.popScope(); 434 _variableIndexer.popScope();
435 } 435 }
436 436
437 visitInvalidExpression(InvalidExpression node) { 437 visitInvalidExpression(InvalidExpression node) {
438 writeByte(Tag.InvalidExpression); 438 writeByte(Tag.InvalidExpression);
439 } 439 }
440 440
441 visitVariableGet(VariableGet node) { 441 visitVariableGet(VariableGet node) {
442 assert(_variableIndexer != null); 442 assert(_variableIndexer != null);
443 int index = _variableIndexer[node.variable]; 443 int index = _variableIndexer[node.variable];
444 assert(index != null); 444 assert(index != null);
445 if (index & Tag.SpecializedPayloadMask == index && 445 if (index & Tag.SpecializedPayloadMask == index &&
446 node.promotedType == null) { 446 node.promotedType == null) {
447 writeByte(Tag.SpecializedVariableGet + index); 447 writeByte(Tag.SpecializedVariableGet + index);
448 writeOffset(node, node.fileOffset); 448 writeOffset(node.fileOffset);
449 } else { 449 } else {
450 writeByte(Tag.VariableGet); 450 writeByte(Tag.VariableGet);
451 writeOffset(node, node.fileOffset); 451 writeOffset(node.fileOffset);
452 writeUInt30(_variableIndexer[node.variable]); 452 writeUInt30(_variableIndexer[node.variable]);
453 writeOptionalNode(node.promotedType); 453 writeOptionalNode(node.promotedType);
454 } 454 }
455 } 455 }
456 456
457 visitVariableSet(VariableSet node) { 457 visitVariableSet(VariableSet node) {
458 assert(_variableIndexer != null); 458 assert(_variableIndexer != null);
459 int index = _variableIndexer[node.variable]; 459 int index = _variableIndexer[node.variable];
460 if (index & Tag.SpecializedPayloadMask == index) { 460 if (index & Tag.SpecializedPayloadMask == index) {
461 writeByte(Tag.SpecializedVariableSet + index); 461 writeByte(Tag.SpecializedVariableSet + index);
462 writeOffset(node, node.fileOffset); 462 writeOffset(node.fileOffset);
463 writeNode(node.value); 463 writeNode(node.value);
464 } else { 464 } else {
465 writeByte(Tag.VariableSet); 465 writeByte(Tag.VariableSet);
466 writeOffset(node, node.fileOffset); 466 writeOffset(node.fileOffset);
467 writeUInt30(_variableIndexer[node.variable]); 467 writeUInt30(_variableIndexer[node.variable]);
468 writeNode(node.value); 468 writeNode(node.value);
469 } 469 }
470 } 470 }
471 471
472 visitPropertyGet(PropertyGet node) { 472 visitPropertyGet(PropertyGet node) {
473 writeByte(Tag.PropertyGet); 473 writeByte(Tag.PropertyGet);
474 writeOffset(node, node.fileOffset); 474 writeOffset(node.fileOffset);
475 writeNode(node.receiver); 475 writeNode(node.receiver);
476 writeName(node.name); 476 writeName(node.name);
477 writeReference(node.interfaceTargetReference); 477 writeReference(node.interfaceTargetReference);
478 } 478 }
479 479
480 visitPropertySet(PropertySet node) { 480 visitPropertySet(PropertySet node) {
481 writeByte(Tag.PropertySet); 481 writeByte(Tag.PropertySet);
482 writeOffset(node, node.fileOffset); 482 writeOffset(node.fileOffset);
483 writeNode(node.receiver); 483 writeNode(node.receiver);
484 writeName(node.name); 484 writeName(node.name);
485 writeNode(node.value); 485 writeNode(node.value);
486 writeReference(node.interfaceTargetReference); 486 writeReference(node.interfaceTargetReference);
487 } 487 }
488 488
489 visitSuperPropertyGet(SuperPropertyGet node) { 489 visitSuperPropertyGet(SuperPropertyGet node) {
490 writeByte(Tag.SuperPropertyGet); 490 writeByte(Tag.SuperPropertyGet);
491 writeName(node.name); 491 writeName(node.name);
492 writeReference(node.interfaceTargetReference); 492 writeReference(node.interfaceTargetReference);
(...skipping 14 matching lines...) Expand all
507 507
508 visitDirectPropertySet(DirectPropertySet node) { 508 visitDirectPropertySet(DirectPropertySet node) {
509 writeByte(Tag.DirectPropertySet); 509 writeByte(Tag.DirectPropertySet);
510 writeNode(node.receiver); 510 writeNode(node.receiver);
511 writeReference(node.targetReference); 511 writeReference(node.targetReference);
512 writeNode(node.value); 512 writeNode(node.value);
513 } 513 }
514 514
515 visitStaticGet(StaticGet node) { 515 visitStaticGet(StaticGet node) {
516 writeByte(Tag.StaticGet); 516 writeByte(Tag.StaticGet);
517 writeOffset(node, node.fileOffset); 517 writeOffset(node.fileOffset);
518 writeReference(node.targetReference); 518 writeReference(node.targetReference);
519 } 519 }
520 520
521 visitStaticSet(StaticSet node) { 521 visitStaticSet(StaticSet node) {
522 writeByte(Tag.StaticSet); 522 writeByte(Tag.StaticSet);
523 writeOffset(node, node.fileOffset); 523 writeOffset(node.fileOffset);
524 writeReference(node.targetReference); 524 writeReference(node.targetReference);
525 writeNode(node.value); 525 writeNode(node.value);
526 } 526 }
527 527
528 visitMethodInvocation(MethodInvocation node) { 528 visitMethodInvocation(MethodInvocation node) {
529 writeByte(Tag.MethodInvocation); 529 writeByte(Tag.MethodInvocation);
530 writeOffset(node, node.fileOffset); 530 writeOffset(node.fileOffset);
531 writeNode(node.receiver); 531 writeNode(node.receiver);
532 writeName(node.name); 532 writeName(node.name);
533 writeNode(node.arguments); 533 writeNode(node.arguments);
534 writeReference(node.interfaceTargetReference); 534 writeReference(node.interfaceTargetReference);
535 } 535 }
536 536
537 visitSuperMethodInvocation(SuperMethodInvocation node) { 537 visitSuperMethodInvocation(SuperMethodInvocation node) {
538 writeByte(Tag.SuperMethodInvocation); 538 writeByte(Tag.SuperMethodInvocation);
539 writeOffset(node, node.fileOffset); 539 writeOffset(node.fileOffset);
540 writeName(node.name); 540 writeName(node.name);
541 writeNode(node.arguments); 541 writeNode(node.arguments);
542 writeReference(node.interfaceTargetReference); 542 writeReference(node.interfaceTargetReference);
543 } 543 }
544 544
545 visitDirectMethodInvocation(DirectMethodInvocation node) { 545 visitDirectMethodInvocation(DirectMethodInvocation node) {
546 writeByte(Tag.DirectMethodInvocation); 546 writeByte(Tag.DirectMethodInvocation);
547 writeNode(node.receiver); 547 writeNode(node.receiver);
548 writeReference(node.targetReference); 548 writeReference(node.targetReference);
549 writeNode(node.arguments); 549 writeNode(node.arguments);
550 } 550 }
551 551
552 visitStaticInvocation(StaticInvocation node) { 552 visitStaticInvocation(StaticInvocation node) {
553 writeByte(node.isConst ? Tag.ConstStaticInvocation : Tag.StaticInvocation); 553 writeByte(node.isConst ? Tag.ConstStaticInvocation : Tag.StaticInvocation);
554 writeOffset(node, node.fileOffset); 554 writeOffset(node.fileOffset);
555 writeReference(node.targetReference); 555 writeReference(node.targetReference);
556 writeNode(node.arguments); 556 writeNode(node.arguments);
557 } 557 }
558 558
559 visitConstructorInvocation(ConstructorInvocation node) { 559 visitConstructorInvocation(ConstructorInvocation node) {
560 writeByte(node.isConst 560 writeByte(node.isConst
561 ? Tag.ConstConstructorInvocation 561 ? Tag.ConstConstructorInvocation
562 : Tag.ConstructorInvocation); 562 : Tag.ConstructorInvocation);
563 writeOffset(node, node.fileOffset); 563 writeOffset(node.fileOffset);
564 writeReference(node.targetReference); 564 writeReference(node.targetReference);
565 writeNode(node.arguments); 565 writeNode(node.arguments);
566 } 566 }
567 567
568 visitArguments(Arguments node) { 568 visitArguments(Arguments node) {
569 writeNodeList(node.types); 569 writeNodeList(node.types);
570 writeNodeList(node.positional); 570 writeNodeList(node.positional);
571 writeNodeList(node.named); 571 writeNodeList(node.named);
572 } 572 }
573 573
(...skipping 27 matching lines...) Expand all
601 visitConditionalExpression(ConditionalExpression node) { 601 visitConditionalExpression(ConditionalExpression node) {
602 writeByte(Tag.ConditionalExpression); 602 writeByte(Tag.ConditionalExpression);
603 writeNode(node.condition); 603 writeNode(node.condition);
604 writeNode(node.then); 604 writeNode(node.then);
605 writeNode(node.otherwise); 605 writeNode(node.otherwise);
606 writeOptionalNode(node.staticType); 606 writeOptionalNode(node.staticType);
607 } 607 }
608 608
609 visitStringConcatenation(StringConcatenation node) { 609 visitStringConcatenation(StringConcatenation node) {
610 writeByte(Tag.StringConcatenation); 610 writeByte(Tag.StringConcatenation);
611 writeOffset(node, node.fileOffset); 611 writeOffset(node.fileOffset);
612 writeNodeList(node.expressions); 612 writeNodeList(node.expressions);
613 } 613 }
614 614
615 visitIsExpression(IsExpression node) { 615 visitIsExpression(IsExpression node) {
616 writeByte(Tag.IsExpression); 616 writeByte(Tag.IsExpression);
617 writeOffset(node, node.fileOffset); 617 writeOffset(node.fileOffset);
618 writeNode(node.operand); 618 writeNode(node.operand);
619 writeNode(node.type); 619 writeNode(node.type);
620 } 620 }
621 621
622 visitAsExpression(AsExpression node) { 622 visitAsExpression(AsExpression node) {
623 writeByte(Tag.AsExpression); 623 writeByte(Tag.AsExpression);
624 writeOffset(node, node.fileOffset); 624 writeOffset(node.fileOffset);
625 writeNode(node.operand); 625 writeNode(node.operand);
626 writeNode(node.type); 626 writeNode(node.type);
627 } 627 }
628 628
629 visitStringLiteral(StringLiteral node) { 629 visitStringLiteral(StringLiteral node) {
630 writeByte(Tag.StringLiteral); 630 writeByte(Tag.StringLiteral);
631 writeStringReference(node.value); 631 writeStringReference(node.value);
632 } 632 }
633 633
634 visitIntLiteral(IntLiteral node) { 634 visitIntLiteral(IntLiteral node) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 writeByte(Tag.TypeLiteral); 675 writeByte(Tag.TypeLiteral);
676 writeNode(node.type); 676 writeNode(node.type);
677 } 677 }
678 678
679 visitThisExpression(ThisExpression node) { 679 visitThisExpression(ThisExpression node) {
680 writeByte(Tag.ThisExpression); 680 writeByte(Tag.ThisExpression);
681 } 681 }
682 682
683 visitRethrow(Rethrow node) { 683 visitRethrow(Rethrow node) {
684 writeByte(Tag.Rethrow); 684 writeByte(Tag.Rethrow);
685 writeOffset(node, node.fileOffset); 685 writeOffset(node.fileOffset);
686 } 686 }
687 687
688 visitThrow(Throw node) { 688 visitThrow(Throw node) {
689 writeByte(Tag.Throw); 689 writeByte(Tag.Throw);
690 writeOffset(node, node.fileOffset); 690 writeOffset(node.fileOffset);
691 writeNode(node.expression); 691 writeNode(node.expression);
692 } 692 }
693 693
694 visitListLiteral(ListLiteral node) { 694 visitListLiteral(ListLiteral node) {
695 writeByte(node.isConst ? Tag.ConstListLiteral : Tag.ListLiteral); 695 writeByte(node.isConst ? Tag.ConstListLiteral : Tag.ListLiteral);
696 writeOffset(node, node.fileOffset); 696 writeOffset(node.fileOffset);
697 writeNode(node.typeArgument); 697 writeNode(node.typeArgument);
698 writeNodeList(node.expressions); 698 writeNodeList(node.expressions);
699 } 699 }
700 700
701 visitMapLiteral(MapLiteral node) { 701 visitMapLiteral(MapLiteral node) {
702 writeByte(node.isConst ? Tag.ConstMapLiteral : Tag.MapLiteral); 702 writeByte(node.isConst ? Tag.ConstMapLiteral : Tag.MapLiteral);
703 writeOffset(node, node.fileOffset); 703 writeOffset(node.fileOffset);
704 writeNode(node.keyType); 704 writeNode(node.keyType);
705 writeNode(node.valueType); 705 writeNode(node.valueType);
706 writeNodeList(node.entries); 706 writeNodeList(node.entries);
707 } 707 }
708 708
709 visitMapEntry(MapEntry node) { 709 visitMapEntry(MapEntry node) {
710 // Note: there is no tag on MapEntry 710 // Note: there is no tag on MapEntry
711 writeNode(node.key); 711 writeNode(node.key);
712 writeNode(node.value); 712 writeNode(node.value);
713 } 713 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 775
776 visitLabeledStatement(LabeledStatement node) { 776 visitLabeledStatement(LabeledStatement node) {
777 _labelIndexer.enter(node); 777 _labelIndexer.enter(node);
778 writeByte(Tag.LabeledStatement); 778 writeByte(Tag.LabeledStatement);
779 writeNode(node.body); 779 writeNode(node.body);
780 _labelIndexer.exit(); 780 _labelIndexer.exit();
781 } 781 }
782 782
783 visitBreakStatement(BreakStatement node) { 783 visitBreakStatement(BreakStatement node) {
784 writeByte(Tag.BreakStatement); 784 writeByte(Tag.BreakStatement);
785 writeOffset(node, node.fileOffset); 785 writeOffset(node.fileOffset);
786 writeUInt30(_labelIndexer[node.target]); 786 writeUInt30(_labelIndexer[node.target]);
787 } 787 }
788 788
789 visitWhileStatement(WhileStatement node) { 789 visitWhileStatement(WhileStatement node) {
790 writeByte(Tag.WhileStatement); 790 writeByte(Tag.WhileStatement);
791 writeNode(node.condition); 791 writeNode(node.condition);
792 writeNode(node.body); 792 writeNode(node.body);
793 } 793 }
794 794
795 visitDoStatement(DoStatement node) { 795 visitDoStatement(DoStatement node) {
796 writeByte(Tag.DoStatement); 796 writeByte(Tag.DoStatement);
797 writeNode(node.body); 797 writeNode(node.body);
798 writeNode(node.condition); 798 writeNode(node.condition);
799 } 799 }
800 800
801 visitForStatement(ForStatement node) { 801 visitForStatement(ForStatement node) {
802 _variableIndexer.pushScope(); 802 _variableIndexer.pushScope();
803 writeByte(Tag.ForStatement); 803 writeByte(Tag.ForStatement);
804 writeVariableDeclarationList(node.variables); 804 writeVariableDeclarationList(node.variables);
805 writeOptionalNode(node.condition); 805 writeOptionalNode(node.condition);
806 writeNodeList(node.updates); 806 writeNodeList(node.updates);
807 writeNode(node.body); 807 writeNode(node.body);
808 _variableIndexer.popScope(); 808 _variableIndexer.popScope();
809 } 809 }
810 810
811 visitForInStatement(ForInStatement node) { 811 visitForInStatement(ForInStatement node) {
812 _variableIndexer.pushScope(); 812 _variableIndexer.pushScope();
813 writeByte(node.isAsync ? Tag.AsyncForInStatement : Tag.ForInStatement); 813 writeByte(node.isAsync ? Tag.AsyncForInStatement : Tag.ForInStatement);
814 writeOffset(node, node.fileOffset); 814 writeOffset(node.fileOffset);
815 writeVariableDeclaration(node.variable); 815 writeVariableDeclaration(node.variable);
816 writeNode(node.iterable); 816 writeNode(node.iterable);
817 writeNode(node.body); 817 writeNode(node.body);
818 _variableIndexer.popScope(); 818 _variableIndexer.popScope();
819 } 819 }
820 820
821 visitSwitchStatement(SwitchStatement node) { 821 visitSwitchStatement(SwitchStatement node) {
822 _switchCaseIndexer.enter(node); 822 _switchCaseIndexer.enter(node);
823 writeByte(Tag.SwitchStatement); 823 writeByte(Tag.SwitchStatement);
824 writeNode(node.expression); 824 writeNode(node.expression);
825 writeNodeList(node.cases); 825 writeNodeList(node.cases);
826 _switchCaseIndexer.exit(node); 826 _switchCaseIndexer.exit(node);
827 } 827 }
828 828
829 visitSwitchCase(SwitchCase node) { 829 visitSwitchCase(SwitchCase node) {
830 // Note: there is no tag on SwitchCase. 830 // Note: there is no tag on SwitchCase.
831 writeNodeList(node.expressions); 831 writeNodeList(node.expressions);
832 node.expressionOffsets.forEach(writeOffset);
832 writeByte(node.isDefault ? 1 : 0); 833 writeByte(node.isDefault ? 1 : 0);
833 writeNode(node.body); 834 writeNode(node.body);
834 } 835 }
835 836
836 visitContinueSwitchStatement(ContinueSwitchStatement node) { 837 visitContinueSwitchStatement(ContinueSwitchStatement node) {
837 writeByte(Tag.ContinueSwitchStatement); 838 writeByte(Tag.ContinueSwitchStatement);
838 writeUInt30(_switchCaseIndexer[node.target]); 839 writeUInt30(_switchCaseIndexer[node.target]);
839 } 840 }
840 841
841 visitIfStatement(IfStatement node) { 842 visitIfStatement(IfStatement node) {
842 writeByte(Tag.IfStatement); 843 writeByte(Tag.IfStatement);
843 writeNode(node.condition); 844 writeNode(node.condition);
844 writeNode(node.then); 845 writeNode(node.then);
845 writeStatementOrEmpty(node.otherwise); 846 writeStatementOrEmpty(node.otherwise);
846 } 847 }
847 848
848 visitReturnStatement(ReturnStatement node) { 849 visitReturnStatement(ReturnStatement node) {
849 writeByte(Tag.ReturnStatement); 850 writeByte(Tag.ReturnStatement);
850 writeOffset(node, node.fileOffset); 851 writeOffset(node.fileOffset);
851 writeOptionalNode(node.expression); 852 writeOptionalNode(node.expression);
852 } 853 }
853 854
854 visitTryCatch(TryCatch node) { 855 visitTryCatch(TryCatch node) {
855 writeByte(Tag.TryCatch); 856 writeByte(Tag.TryCatch);
856 writeNode(node.body); 857 writeNode(node.body);
857 writeNodeList(node.catches); 858 writeNodeList(node.catches);
858 } 859 }
859 860
860 visitCatch(Catch node) { 861 visitCatch(Catch node) {
861 // Note: there is no tag on Catch. 862 // Note: there is no tag on Catch.
862 _variableIndexer.pushScope(); 863 _variableIndexer.pushScope();
863 writeNode(node.guard); 864 writeNode(node.guard);
864 writeOptionalVariableDeclaration(node.exception); 865 writeOptionalVariableDeclaration(node.exception);
865 writeOptionalVariableDeclaration(node.stackTrace); 866 writeOptionalVariableDeclaration(node.stackTrace);
866 writeNode(node.body); 867 writeNode(node.body);
867 _variableIndexer.popScope(); 868 _variableIndexer.popScope();
868 } 869 }
869 870
870 visitTryFinally(TryFinally node) { 871 visitTryFinally(TryFinally node) {
871 writeByte(Tag.TryFinally); 872 writeByte(Tag.TryFinally);
872 writeNode(node.body); 873 writeNode(node.body);
873 writeNode(node.finalizer); 874 writeNode(node.finalizer);
874 } 875 }
875 876
876 visitYieldStatement(YieldStatement node) { 877 visitYieldStatement(YieldStatement node) {
877 writeByte(Tag.YieldStatement); 878 writeByte(Tag.YieldStatement);
878 writeOffset(node, node.fileOffset); 879 writeOffset(node.fileOffset);
879 writeByte(node.flags); 880 writeByte(node.flags);
880 writeNode(node.expression); 881 writeNode(node.expression);
881 } 882 }
882 883
883 visitVariableDeclaration(VariableDeclaration node) { 884 visitVariableDeclaration(VariableDeclaration node) {
884 writeByte(Tag.VariableDeclaration); 885 writeByte(Tag.VariableDeclaration);
885 writeVariableDeclaration(node); 886 writeVariableDeclaration(node);
886 } 887 }
887 888
888 void writeVariableDeclaration(VariableDeclaration node) { 889 void writeVariableDeclaration(VariableDeclaration node) {
889 writeOffset(node, node.fileOffset); 890 writeOffset(node.fileOffset);
890 writeOffset(node, node.fileEqualsOffset); 891 writeOffset(node.fileEqualsOffset);
891 writeByte(node.flags); 892 writeByte(node.flags);
892 writeStringReference(node.name ?? ''); 893 writeStringReference(node.name ?? '');
893 writeNode(node.type); 894 writeNode(node.type);
894 writeOptionalInferredValue(node.inferredValue); 895 writeOptionalInferredValue(node.inferredValue);
895 writeOptionalNode(node.initializer); 896 writeOptionalNode(node.initializer);
896 // Declare the variable after its initializer. It is not in scope in its 897 // Declare the variable after its initializer. It is not in scope in its
897 // own initializer. 898 // own initializer.
898 _variableIndexer.declare(node); 899 _variableIndexer.declare(node);
899 } 900 }
900 901
901 void writeVariableDeclarationList(List<VariableDeclaration> nodes) { 902 void writeVariableDeclarationList(List<VariableDeclaration> nodes) {
902 writeList(nodes, writeVariableDeclaration); 903 writeList(nodes, writeVariableDeclaration);
903 } 904 }
904 905
905 void writeOptionalVariableDeclaration(VariableDeclaration node) { 906 void writeOptionalVariableDeclaration(VariableDeclaration node) {
906 if (node == null) { 907 if (node == null) {
907 writeByte(Tag.Nothing); 908 writeByte(Tag.Nothing);
908 } else { 909 } else {
909 writeByte(Tag.Something); 910 writeByte(Tag.Something);
910 writeVariableDeclaration(node); 911 writeVariableDeclaration(node);
911 } 912 }
912 } 913 }
913 914
914 visitFunctionDeclaration(FunctionDeclaration node) { 915 visitFunctionDeclaration(FunctionDeclaration node) {
915 writeByte(Tag.FunctionDeclaration); 916 writeByte(Tag.FunctionDeclaration);
916 writeOffset(node, node.fileOffset); 917 writeOffset(node.fileOffset);
917 writeVariableDeclaration(node.variable); 918 writeVariableDeclaration(node.variable);
918 writeNode(node.function); 919 writeNode(node.function);
919 } 920 }
920 921
921 visitBottomType(BottomType node) { 922 visitBottomType(BottomType node) {
922 writeByte(Tag.BottomType); 923 writeByte(Tag.BottomType);
923 } 924 }
924 925
925 visitInvalidType(InvalidType node) { 926 visitInvalidType(InvalidType node) {
926 writeByte(Tag.InvalidType); 927 writeByte(Tag.InvalidType);
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 void flush() { 1282 void flush() {
1282 _sink.add(_buffer.sublist(0, length)); 1283 _sink.add(_buffer.sublist(0, length));
1283 _buffer = new Uint8List(SIZE); 1284 _buffer = new Uint8List(SIZE);
1284 length = 0; 1285 length = 0;
1285 } 1286 }
1286 1287
1287 void flushAndDestroy() { 1288 void flushAndDestroy() {
1288 _sink.add(_buffer.sublist(0, length)); 1289 _sink.add(_buffer.sublist(0, length));
1289 } 1290 }
1290 } 1291 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/binary/ast_from_binary.dart ('k') | pkg/kernel/lib/clone.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698