@@ -401,6 +401,28 @@ class positional_printer
401
401
402
402
// Catch up with comment/blank lines
403
403
//
404
+ auto print_comment (comment const & c)
405
+ -> void
406
+ {
407
+ // For a line comment, start it at the right indentation and print it
408
+ // with a newline end
409
+ if (c.kind == comment::comment_kind::line_comment) {
410
+ print ( pad ( c.start .colno - curr_pos.colno + 1 ) );
411
+ print ( c.text );
412
+ assert ( c.text .find (" \n " ) == std::string::npos ); // we shouldn't have newlines
413
+ print (" \n " );
414
+ }
415
+
416
+ // For a stream comment, pad out to its column (if we haven't passed it already)
417
+ // and emit it there
418
+ else {
419
+ print ( pad ( c.start .colno - curr_pos.colno ) );
420
+ print ( c.text );
421
+ }
422
+
423
+ c.dbg_was_printed = true ;
424
+ }
425
+
404
426
auto flush_comments ( source_position pos )
405
427
-> void
406
428
{
@@ -436,24 +458,8 @@ class positional_printer
436
458
)
437
459
)
438
460
{
439
- // For a line comment, start it at the right indentation and print it
440
- // with a newline end
441
- if (comments[next_comment].kind == comment::comment_kind::line_comment) {
442
- print ( pad ( comments[next_comment].start .colno - curr_pos.colno + 1 ) );
443
- print ( comments[next_comment].text );
444
- assert ( comments[next_comment].text .find (" \n " ) == std::string::npos ); // we shouldn't have newlines
445
- print (" \n " );
446
- }
447
-
448
- // For a stream comment, pad out to its column (if we haven't passed it already)
449
- // and emit it there
450
- else {
451
- print ( pad ( comments[next_comment].start .colno - curr_pos.colno ) );
452
- print ( comments[next_comment].text );
453
- assert (curr_pos.lineno <= pos.lineno ); // we shouldn't have overshot
454
- }
455
-
456
- comments[next_comment].dbg_was_printed = true ;
461
+ print_comment ( comments[next_comment] );
462
+ assert (curr_pos.lineno <= pos.lineno ); // we shouldn't have overshot
457
463
}
458
464
459
465
++next_comment;
@@ -466,6 +472,15 @@ class positional_printer
466
472
}
467
473
}
468
474
475
+ auto print_unprinted_comments ()
476
+ {
477
+ for (auto const & c : *pcomments) {
478
+ if (!c.dbg_was_printed ) {
479
+ print_comment (c);
480
+ }
481
+ }
482
+ }
483
+
469
484
// Position ourselves as close to pos as possible,
470
485
// and catch up with displaying comments
471
486
//
@@ -553,7 +568,7 @@ class positional_printer
553
568
// -----------------------------------------------------------------------
554
569
// Finalize phase
555
570
//
556
- auto finalize_phase ()
571
+ auto finalize_phase (bool print_remaining_comments = false )
557
572
{
558
573
if (
559
574
is_open ()
@@ -563,6 +578,10 @@ class positional_printer
563
578
{
564
579
flush_comments ( {curr_pos.lineno +1 , 1 } );
565
580
581
+ if (print_remaining_comments) {
582
+ print_unprinted_comments ();
583
+ }
584
+
566
585
// Always make sure the very last line ends with a newline
567
586
// (not really necessary but makes some tools quieter)
568
587
// -- but only if there's any Cpp2, otherwise don't
@@ -1439,8 +1458,9 @@ class cppfront
1439
1458
printer.print_extra ( " \n #endif" );
1440
1459
}
1441
1460
1461
+ printer.finalize_phase ( true );
1462
+
1442
1463
// Finally, some debug checks
1443
- printer.finalize_phase ();
1444
1464
assert (
1445
1465
(!errors.empty () || tokens.num_unprinted_comments () == 0 )
1446
1466
&& " ICE: not all comments were printed"
0 commit comments