comparison gcc/c-family/c-ppoutput.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Preprocess only, using cpplib. 1 /* Preprocess only, using cpplib.
2 Copyright (C) 1995-2018 Free Software Foundation, Inc. 2 Copyright (C) 1995-2020 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994-95. 3 Written by Per Bothner, 1994-95.
4 4
5 This program is free software; you can redistribute it and/or modify it 5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the 6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any 7 Free Software Foundation; either version 3, or (at your option) any
57 static void scan_translation_unit_trad (cpp_reader *); 57 static void scan_translation_unit_trad (cpp_reader *);
58 static void account_for_newlines (const unsigned char *, size_t); 58 static void account_for_newlines (const unsigned char *, size_t);
59 static int dump_macro (cpp_reader *, cpp_hashnode *, void *); 59 static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
60 static void dump_queued_macros (cpp_reader *); 60 static void dump_queued_macros (cpp_reader *);
61 61
62 static bool print_line_1 (source_location, const char*, FILE *); 62 static bool print_line_1 (location_t, const char*, FILE *);
63 static bool print_line (source_location, const char *); 63 static bool print_line (location_t, const char *);
64 static bool maybe_print_line_1 (source_location, FILE *); 64 static bool maybe_print_line_1 (location_t, FILE *);
65 static bool maybe_print_line (source_location); 65 static bool maybe_print_line (location_t);
66 static bool do_line_change (cpp_reader *, const cpp_token *, 66 static bool do_line_change (cpp_reader *, const cpp_token *,
67 source_location, int); 67 location_t, int);
68 68
69 /* Callback routines for the parser. Most of these are active only 69 /* Callback routines for the parser. Most of these are active only
70 in specific modes. */ 70 in specific modes. */
71 static void cb_line_change (cpp_reader *, const cpp_token *, int); 71 static void cb_line_change (cpp_reader *, const cpp_token *, int);
72 static void cb_define (cpp_reader *, source_location, cpp_hashnode *); 72 static void cb_define (cpp_reader *, location_t, cpp_hashnode *);
73 static void cb_undef (cpp_reader *, source_location, cpp_hashnode *); 73 static void cb_undef (cpp_reader *, location_t, cpp_hashnode *);
74 static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *); 74 static void cb_used_define (cpp_reader *, location_t, cpp_hashnode *);
75 static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *); 75 static void cb_used_undef (cpp_reader *, location_t, cpp_hashnode *);
76 static void cb_include (cpp_reader *, source_location, const unsigned char *, 76 static void cb_include (cpp_reader *, location_t, const unsigned char *,
77 const char *, int, const cpp_token **); 77 const char *, int, const cpp_token **);
78 static void cb_ident (cpp_reader *, source_location, const cpp_string *); 78 static void cb_ident (cpp_reader *, location_t, const cpp_string *);
79 static void cb_def_pragma (cpp_reader *, source_location); 79 static void cb_def_pragma (cpp_reader *, location_t);
80 static void cb_read_pch (cpp_reader *pfile, const char *name, 80 static void cb_read_pch (cpp_reader *pfile, const char *name,
81 int fd, const char *orig_name); 81 int fd, const char *orig_name);
82 82
83 /* Preprocess and output. */ 83 /* Preprocess and output. */
84 void 84 void
149 cb->used_define = cb_used_define; 149 cb->used_define = cb_used_define;
150 cb->used_undef = cb_used_undef; 150 cb->used_undef = cb_used_undef;
151 } 151 }
152 152
153 cb->has_attribute = c_common_has_attribute; 153 cb->has_attribute = c_common_has_attribute;
154 cb->has_builtin = c_common_has_builtin;
154 cb->get_source_date_epoch = cb_get_source_date_epoch; 155 cb->get_source_date_epoch = cb_get_source_date_epoch;
155 cb->remap_filename = remap_macro_filename; 156 cb->remap_filename = remap_macro_filename;
156 157
157 /* Initialize the print structure. */ 158 /* Initialize the print structure. */
158 print.src_line = 1; 159 print.src_line = 1;
177 bool line_marker_emitted = false; 178 bool line_marker_emitted = false;
178 179
179 print.source = NULL; 180 print.source = NULL;
180 for (;;) 181 for (;;)
181 { 182 {
182 source_location loc; 183 location_t loc;
183 const cpp_token *token = cpp_get_token_with_location (pfile, &loc); 184 const cpp_token *token = cpp_get_token_with_location (pfile, &loc);
184 185
185 if (token->type == CPP_PADDING) 186 if (token->type == CPP_PADDING)
186 { 187 {
187 avoid_paste = true; 188 avoid_paste = true;
334 different line to the current one, output the required newlines or 335 different line to the current one, output the required newlines or
335 a line marker. If a line marker was emitted, return TRUE otherwise 336 a line marker. If a line marker was emitted, return TRUE otherwise
336 return FALSE. */ 337 return FALSE. */
337 338
338 static bool 339 static bool
339 maybe_print_line_1 (source_location src_loc, FILE *stream) 340 maybe_print_line_1 (location_t src_loc, FILE *stream)
340 { 341 {
341 bool emitted_line_marker = false; 342 bool emitted_line_marker = false;
342 int src_line = LOCATION_LINE (src_loc); 343 int src_line = LOCATION_LINE (src_loc);
343 const char *src_file = LOCATION_FILE (src_loc); 344 const char *src_file = LOCATION_FILE (src_loc);
344 345
371 different line to the current one, output the required newlines or 372 different line to the current one, output the required newlines or
372 a line marker. If a line marker was emitted, return TRUE otherwise 373 a line marker. If a line marker was emitted, return TRUE otherwise
373 return FALSE. */ 374 return FALSE. */
374 375
375 static bool 376 static bool
376 maybe_print_line (source_location src_loc) 377 maybe_print_line (location_t src_loc)
377 { 378 {
378 if (cpp_get_options (parse_in)->debug) 379 if (cpp_get_options (parse_in)->debug)
379 linemap_dump_location (line_table, src_loc, 380 linemap_dump_location (line_table, src_loc,
380 print.outf); 381 print.outf);
381 return maybe_print_line_1 (src_loc, print.outf); 382 return maybe_print_line_1 (src_loc, print.outf);
384 /* Output a line marker for logical line LINE. Special flags are "1" 385 /* Output a line marker for logical line LINE. Special flags are "1"
385 or "2" indicating entering or leaving a file. If the line marker 386 or "2" indicating entering or leaving a file. If the line marker
386 was effectively emitted, return TRUE otherwise return FALSE. */ 387 was effectively emitted, return TRUE otherwise return FALSE. */
387 388
388 static bool 389 static bool
389 print_line_1 (source_location src_loc, const char *special_flags, FILE *stream) 390 print_line_1 (location_t src_loc, const char *special_flags, FILE *stream)
390 { 391 {
391 bool emitted_line_marker = false; 392 bool emitted_line_marker = false;
392 393
393 /* End any previous line of text. */ 394 /* End any previous line of text. */
394 if (print.printed) 395 if (print.printed)
433 /* Output a line marker for logical line LINE. Special flags are "1" 434 /* Output a line marker for logical line LINE. Special flags are "1"
434 or "2" indicating entering or leaving a file. Return TRUE if a 435 or "2" indicating entering or leaving a file. Return TRUE if a
435 line marker was effectively emitted, FALSE otherwise. */ 436 line marker was effectively emitted, FALSE otherwise. */
436 437
437 static bool 438 static bool
438 print_line (source_location src_loc, const char *special_flags) 439 print_line (location_t src_loc, const char *special_flags)
439 { 440 {
440 if (cpp_get_options (parse_in)->debug) 441 if (cpp_get_options (parse_in)->debug)
441 linemap_dump_location (line_table, src_loc, 442 linemap_dump_location (line_table, src_loc,
442 print.outf); 443 print.outf);
443 return print_line_1 (src_loc, special_flags, print.outf); 444 return print_line_1 (src_loc, special_flags, print.outf);
445 446
446 /* Helper function for cb_line_change and scan_translation_unit. 447 /* Helper function for cb_line_change and scan_translation_unit.
447 Return TRUE if a line marker is emitted, FALSE otherwise. */ 448 Return TRUE if a line marker is emitted, FALSE otherwise. */
448 static bool 449 static bool
449 do_line_change (cpp_reader *pfile, const cpp_token *token, 450 do_line_change (cpp_reader *pfile, const cpp_token *token,
450 source_location src_loc, int parsing_args) 451 location_t src_loc, int parsing_args)
451 { 452 {
452 bool emitted_line_marker = false; 453 bool emitted_line_marker = false;
453 if (define_queue || undef_queue) 454 if (define_queue || undef_queue)
454 dump_queued_macros (pfile); 455 dump_queued_macros (pfile);
455 456
485 { 486 {
486 do_line_change (pfile, token, token->src_loc, parsing_args); 487 do_line_change (pfile, token, token->src_loc, parsing_args);
487 } 488 }
488 489
489 static void 490 static void
490 cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, 491 cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line,
491 const cpp_string *str) 492 const cpp_string *str)
492 { 493 {
493 maybe_print_line (line); 494 maybe_print_line (line);
494 fprintf (print.outf, "#ident %s\n", str->text); 495 fprintf (print.outf, "#ident %s\n", str->text);
495 print.src_line++; 496 print.src_line++;
496 } 497 }
497 498
498 static void 499 static void
499 cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node) 500 cb_define (cpp_reader *pfile, location_t line, cpp_hashnode *node)
500 { 501 {
501 const line_map_ordinary *map; 502 const line_map_ordinary *map;
502 503
503 maybe_print_line (line); 504 maybe_print_line (line);
504 fputs ("#define ", print.outf); 505 fputs ("#define ", print.outf);
518 if (LINEMAP_LINE (map) != 0) 519 if (LINEMAP_LINE (map) != 0)
519 print.src_line++; 520 print.src_line++;
520 } 521 }
521 522
522 static void 523 static void
523 cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, 524 cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line,
524 cpp_hashnode *node) 525 cpp_hashnode *node)
525 { 526 {
526 maybe_print_line (line); 527 maybe_print_line (line);
527 fprintf (print.outf, "#undef %s\n", NODE_NAME (node)); 528 fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
528 print.src_line++; 529 print.src_line++;
529 } 530 }
530 531
531 static void 532 static void
532 cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED, 533 cb_used_define (cpp_reader *pfile, location_t line ATTRIBUTE_UNUSED,
533 cpp_hashnode *node) 534 cpp_hashnode *node)
534 { 535 {
535 if (cpp_user_macro_p (node)) 536 if (cpp_user_macro_p (node))
536 { 537 {
537 macro_queue *q; 538 macro_queue *q;
542 } 543 }
543 } 544 }
544 545
545 static void 546 static void
546 cb_used_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, 547 cb_used_undef (cpp_reader *pfile ATTRIBUTE_UNUSED,
547 source_location line ATTRIBUTE_UNUSED, 548 location_t line ATTRIBUTE_UNUSED,
548 cpp_hashnode *node) 549 cpp_hashnode *node)
549 { 550 {
550 macro_queue *q; 551 macro_queue *q;
551 q = XNEW (macro_queue); 552 q = XNEW (macro_queue);
552 q->macro = xstrdup ((const char *) NODE_NAME (node)); 553 q->macro = xstrdup ((const char *) NODE_NAME (node));
593 } 594 }
594 undef_queue = NULL; 595 undef_queue = NULL;
595 } 596 }
596 597
597 static void 598 static void
598 cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, 599 cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line,
599 const unsigned char *dir, const char *header, int angle_brackets, 600 const unsigned char *dir, const char *header, int angle_brackets,
600 const cpp_token **comments) 601 const cpp_token **comments)
601 { 602 {
602 maybe_print_line (line); 603 maybe_print_line (line);
603 if (angle_brackets) 604 if (angle_brackets)
674 } 675 }
675 } 676 }
676 677
677 /* Copy a #pragma directive to the preprocessed output. */ 678 /* Copy a #pragma directive to the preprocessed output. */
678 static void 679 static void
679 cb_def_pragma (cpp_reader *pfile, source_location line) 680 cb_def_pragma (cpp_reader *pfile, location_t line)
680 { 681 {
681 maybe_print_line (line); 682 maybe_print_line (line);
682 fputs ("#pragma ", print.outf); 683 fputs ("#pragma ", print.outf);
683 cpp_output_line (pfile, print.outf); 684 cpp_output_line (pfile, print.outf);
684 print.printed = false; 685 print.printed = false;