c-ppoutput.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /* Preprocess only, using cpplib.
  2. Copyright (C) 1995-2015 Free Software Foundation, Inc.
  3. Written by Per Bothner, 1994-95.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 3, or (at your option) any
  7. later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #include "config.h"
  16. #include "system.h"
  17. #include "coretypes.h"
  18. #include "cpplib.h"
  19. #include "../libcpp/internal.h"
  20. #include "hash-set.h"
  21. #include "machmode.h"
  22. #include "vec.h"
  23. #include "double-int.h"
  24. #include "input.h"
  25. #include "alias.h"
  26. #include "symtab.h"
  27. #include "options.h"
  28. #include "wide-int.h"
  29. #include "inchash.h"
  30. #include "tree.h"
  31. #include "c-common.h" /* For flags. */
  32. #include "c-pragma.h" /* For parse_in. */
  33. /* Encapsulates state used to convert a stream of tokens into a text
  34. file. */
  35. static struct
  36. {
  37. FILE *outf; /* Stream to write to. */
  38. const cpp_token *prev; /* Previous token. */
  39. const cpp_token *source; /* Source token for spacing. */
  40. int src_line; /* Line number currently being written. */
  41. unsigned char printed; /* Nonzero if something output at line. */
  42. bool first_time; /* pp_file_change hasn't been called yet. */
  43. const char *src_file; /* Current source file. */
  44. bool prev_was_system_token; /* True if the previous token was a
  45. system token.*/
  46. } print;
  47. /* Defined and undefined macros being queued for output with -dU at
  48. the next newline. */
  49. typedef struct macro_queue
  50. {
  51. struct macro_queue *next; /* Next macro in the list. */
  52. char *macro; /* The name of the macro if not
  53. defined, the full definition if
  54. defined. */
  55. } macro_queue;
  56. static macro_queue *define_queue, *undef_queue;
  57. /* General output routines. */
  58. static void scan_translation_unit (cpp_reader *);
  59. static void print_lines_directives_only (int, const void *, size_t);
  60. static void scan_translation_unit_directives_only (cpp_reader *);
  61. static void scan_translation_unit_trad (cpp_reader *);
  62. static void account_for_newlines (const unsigned char *, size_t);
  63. static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
  64. static void dump_queued_macros (cpp_reader *);
  65. static bool print_line_1 (source_location, const char*, FILE *);
  66. static bool print_line (source_location, const char *);
  67. static bool maybe_print_line_1 (source_location, FILE *);
  68. static bool maybe_print_line (source_location);
  69. static bool do_line_change (cpp_reader *, const cpp_token *,
  70. source_location, int);
  71. /* Callback routines for the parser. Most of these are active only
  72. in specific modes. */
  73. static void cb_line_change (cpp_reader *, const cpp_token *, int);
  74. static void cb_define (cpp_reader *, source_location, cpp_hashnode *);
  75. static void cb_undef (cpp_reader *, source_location, cpp_hashnode *);
  76. static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *);
  77. static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *);
  78. static void cb_include (cpp_reader *, source_location, const unsigned char *,
  79. const char *, int, const cpp_token **);
  80. static void cb_ident (cpp_reader *, source_location, const cpp_string *);
  81. static void cb_def_pragma (cpp_reader *, source_location);
  82. static void cb_read_pch (cpp_reader *pfile, const char *name,
  83. int fd, const char *orig_name);
  84. /* Preprocess and output. */
  85. void
  86. preprocess_file (cpp_reader *pfile)
  87. {
  88. /* A successful cpp_read_main_file guarantees that we can call
  89. cpp_scan_nooutput or cpp_get_token next. */
  90. if (flag_no_output && pfile->buffer)
  91. {
  92. /* Scan -included buffers, then the main file. */
  93. while (pfile->buffer->prev)
  94. cpp_scan_nooutput (pfile);
  95. cpp_scan_nooutput (pfile);
  96. }
  97. else if (cpp_get_options (pfile)->traditional)
  98. scan_translation_unit_trad (pfile);
  99. else if (cpp_get_options (pfile)->directives_only
  100. && !cpp_get_options (pfile)->preprocessed)
  101. scan_translation_unit_directives_only (pfile);
  102. else
  103. scan_translation_unit (pfile);
  104. /* -dM command line option. Should this be elsewhere? */
  105. if (flag_dump_macros == 'M')
  106. cpp_forall_identifiers (pfile, dump_macro, NULL);
  107. /* Flush any pending output. */
  108. if (print.printed)
  109. putc ('\n', print.outf);
  110. }
  111. /* Set up the callbacks as appropriate. */
  112. void
  113. init_pp_output (FILE *out_stream)
  114. {
  115. cpp_callbacks *cb = cpp_get_callbacks (parse_in);
  116. if (!flag_no_output)
  117. {
  118. cb->line_change = cb_line_change;
  119. /* Don't emit #pragma or #ident directives if we are processing
  120. assembly language; the assembler may choke on them. */
  121. if (cpp_get_options (parse_in)->lang != CLK_ASM)
  122. {
  123. cb->ident = cb_ident;
  124. cb->def_pragma = cb_def_pragma;
  125. }
  126. }
  127. if (flag_dump_includes)
  128. cb->include = cb_include;
  129. if (flag_pch_preprocess)
  130. {
  131. cb->valid_pch = c_common_valid_pch;
  132. cb->read_pch = cb_read_pch;
  133. }
  134. if (flag_dump_macros == 'N' || flag_dump_macros == 'D')
  135. {
  136. cb->define = cb_define;
  137. cb->undef = cb_undef;
  138. }
  139. if (flag_dump_macros == 'U')
  140. {
  141. cb->before_define = dump_queued_macros;
  142. cb->used_define = cb_used_define;
  143. cb->used_undef = cb_used_undef;
  144. }
  145. cb->has_attribute = c_common_has_attribute;
  146. /* Initialize the print structure. */
  147. print.src_line = 1;
  148. print.printed = 0;
  149. print.prev = 0;
  150. print.outf = out_stream;
  151. print.first_time = 1;
  152. print.src_file = "";
  153. print.prev_was_system_token = false;
  154. }
  155. /* Writes out the preprocessed file, handling spacing and paste
  156. avoidance issues. */
  157. static void
  158. scan_translation_unit (cpp_reader *pfile)
  159. {
  160. bool avoid_paste = false;
  161. bool do_line_adjustments
  162. = cpp_get_options (parse_in)->lang != CLK_ASM
  163. && !flag_no_line_commands;
  164. bool in_pragma = false;
  165. bool line_marker_emitted = false;
  166. print.source = NULL;
  167. for (;;)
  168. {
  169. source_location loc;
  170. const cpp_token *token = cpp_get_token_with_location (pfile, &loc);
  171. if (token->type == CPP_PADDING)
  172. {
  173. avoid_paste = true;
  174. if (print.source == NULL
  175. || (!(print.source->flags & PREV_WHITE)
  176. && token->val.source == NULL))
  177. print.source = token->val.source;
  178. continue;
  179. }
  180. if (token->type == CPP_EOF)
  181. break;
  182. /* Subtle logic to output a space if and only if necessary. */
  183. if (avoid_paste)
  184. {
  185. int src_line = LOCATION_LINE (loc);
  186. if (print.source == NULL)
  187. print.source = token;
  188. if (src_line != print.src_line
  189. && do_line_adjustments
  190. && !in_pragma)
  191. {
  192. line_marker_emitted = do_line_change (pfile, token, loc, false);
  193. putc (' ', print.outf);
  194. }
  195. else if (print.source->flags & PREV_WHITE
  196. || (print.prev
  197. && cpp_avoid_paste (pfile, print.prev, token))
  198. || (print.prev == NULL && token->type == CPP_HASH))
  199. putc (' ', print.outf);
  200. }
  201. else if (token->flags & PREV_WHITE)
  202. {
  203. int src_line = LOCATION_LINE (loc);
  204. if (src_line != print.src_line
  205. && do_line_adjustments
  206. && !in_pragma)
  207. line_marker_emitted = do_line_change (pfile, token, loc, false);
  208. putc (' ', print.outf);
  209. }
  210. avoid_paste = false;
  211. print.source = NULL;
  212. print.prev = token;
  213. if (token->type == CPP_PRAGMA)
  214. {
  215. const char *space;
  216. const char *name;
  217. line_marker_emitted = maybe_print_line (token->src_loc);
  218. fputs ("#pragma ", print.outf);
  219. c_pp_lookup_pragma (token->val.pragma, &space, &name);
  220. if (space)
  221. fprintf (print.outf, "%s %s", space, name);
  222. else
  223. fprintf (print.outf, "%s", name);
  224. print.printed = 1;
  225. in_pragma = true;
  226. }
  227. else if (token->type == CPP_PRAGMA_EOL)
  228. {
  229. maybe_print_line (token->src_loc);
  230. in_pragma = false;
  231. }
  232. else
  233. {
  234. if (cpp_get_options (parse_in)->debug)
  235. linemap_dump_location (line_table, token->src_loc,
  236. print.outf);
  237. if (do_line_adjustments
  238. && !in_pragma
  239. && !line_marker_emitted
  240. && print.prev_was_system_token != !!in_system_header_at(loc)
  241. && !is_location_from_builtin_token (loc))
  242. /* The system-ness of this token is different from the one
  243. of the previous token. Let's emit a line change to
  244. mark the new system-ness before we emit the token. */
  245. {
  246. do_line_change (pfile, token, loc, false);
  247. print.prev_was_system_token = !!in_system_header_at(loc);
  248. }
  249. cpp_output_token (token, print.outf);
  250. line_marker_emitted = false;
  251. }
  252. /* CPP_COMMENT tokens and raw-string literal tokens can
  253. have embedded new-line characters. Rather than enumerating
  254. all the possible token types just check if token uses
  255. val.str union member. */
  256. if (cpp_token_val_index (token) == CPP_TOKEN_FLD_STR)
  257. account_for_newlines (token->val.str.text, token->val.str.len);
  258. }
  259. }
  260. static void
  261. print_lines_directives_only (int lines, const void *buf, size_t size)
  262. {
  263. print.src_line += lines;
  264. fwrite (buf, 1, size, print.outf);
  265. }
  266. /* Writes out the preprocessed file, handling spacing and paste
  267. avoidance issues. */
  268. static void
  269. scan_translation_unit_directives_only (cpp_reader *pfile)
  270. {
  271. struct _cpp_dir_only_callbacks cb;
  272. cb.print_lines = print_lines_directives_only;
  273. cb.maybe_print_line = (void (*) (source_location)) maybe_print_line;
  274. _cpp_preprocess_dir_only (pfile, &cb);
  275. }
  276. /* Adjust print.src_line for newlines embedded in output. */
  277. static void
  278. account_for_newlines (const unsigned char *str, size_t len)
  279. {
  280. while (len--)
  281. if (*str++ == '\n')
  282. print.src_line++;
  283. }
  284. /* Writes out a traditionally preprocessed file. */
  285. static void
  286. scan_translation_unit_trad (cpp_reader *pfile)
  287. {
  288. while (_cpp_read_logical_line_trad (pfile))
  289. {
  290. size_t len = pfile->out.cur - pfile->out.base;
  291. maybe_print_line (pfile->out.first_line);
  292. fwrite (pfile->out.base, 1, len, print.outf);
  293. print.printed = 1;
  294. if (!CPP_OPTION (pfile, discard_comments))
  295. account_for_newlines (pfile->out.base, len);
  296. }
  297. }
  298. /* If the token read on logical line LINE needs to be output on a
  299. different line to the current one, output the required newlines or
  300. a line marker. If a line marker was emitted, return TRUE otherwise
  301. return FALSE. */
  302. static bool
  303. maybe_print_line_1 (source_location src_loc, FILE *stream)
  304. {
  305. bool emitted_line_marker = false;
  306. int src_line = LOCATION_LINE (src_loc);
  307. const char *src_file = LOCATION_FILE (src_loc);
  308. /* End the previous line of text. */
  309. if (print.printed)
  310. {
  311. putc ('\n', stream);
  312. print.src_line++;
  313. print.printed = 0;
  314. }
  315. if (!flag_no_line_commands
  316. && src_line >= print.src_line
  317. && src_line < print.src_line + 8
  318. && strcmp (src_file, print.src_file) == 0)
  319. {
  320. while (src_line > print.src_line)
  321. {
  322. putc ('\n', stream);
  323. print.src_line++;
  324. }
  325. }
  326. else
  327. emitted_line_marker = print_line_1 (src_loc, "", stream);
  328. return emitted_line_marker;
  329. }
  330. /* If the token read on logical line LINE needs to be output on a
  331. different line to the current one, output the required newlines or
  332. a line marker. If a line marker was emitted, return TRUE otherwise
  333. return FALSE. */
  334. static bool
  335. maybe_print_line (source_location src_loc)
  336. {
  337. if (cpp_get_options (parse_in)->debug)
  338. linemap_dump_location (line_table, src_loc,
  339. print.outf);
  340. return maybe_print_line_1 (src_loc, print.outf);
  341. }
  342. /* Output a line marker for logical line LINE. Special flags are "1"
  343. or "2" indicating entering or leaving a file. If the line marker
  344. was effectively emitted, return TRUE otherwise return FALSE. */
  345. static bool
  346. print_line_1 (source_location src_loc, const char *special_flags, FILE *stream)
  347. {
  348. bool emitted_line_marker = false;
  349. /* End any previous line of text. */
  350. if (print.printed)
  351. putc ('\n', stream);
  352. print.printed = 0;
  353. if (!flag_no_line_commands)
  354. {
  355. const char *file_path = LOCATION_FILE (src_loc);
  356. int sysp;
  357. size_t to_file_len = strlen (file_path);
  358. unsigned char *to_file_quoted =
  359. (unsigned char *) alloca (to_file_len * 4 + 1);
  360. unsigned char *p;
  361. print.src_line = LOCATION_LINE (src_loc);
  362. print.src_file = file_path;
  363. /* cpp_quote_string does not nul-terminate, so we have to do it
  364. ourselves. */
  365. p = cpp_quote_string (to_file_quoted,
  366. (const unsigned char *) file_path,
  367. to_file_len);
  368. *p = '\0';
  369. fprintf (stream, "# %u \"%s\"%s",
  370. print.src_line == 0 ? 1 : print.src_line,
  371. to_file_quoted, special_flags);
  372. sysp = in_system_header_at (src_loc);
  373. if (sysp == 2)
  374. fputs (" 3 4", stream);
  375. else if (sysp == 1)
  376. fputs (" 3", stream);
  377. putc ('\n', stream);
  378. emitted_line_marker = true;
  379. }
  380. return emitted_line_marker;
  381. }
  382. /* Output a line marker for logical line LINE. Special flags are "1"
  383. or "2" indicating entering or leaving a file. Return TRUE if a
  384. line marker was effectively emitted, FALSE otherwise. */
  385. static bool
  386. print_line (source_location src_loc, const char *special_flags)
  387. {
  388. if (cpp_get_options (parse_in)->debug)
  389. linemap_dump_location (line_table, src_loc,
  390. print.outf);
  391. return print_line_1 (src_loc, special_flags, print.outf);
  392. }
  393. /* Helper function for cb_line_change and scan_translation_unit.
  394. Return TRUE if a line marker is emitted, FALSE otherwise. */
  395. static bool
  396. do_line_change (cpp_reader *pfile, const cpp_token *token,
  397. source_location src_loc, int parsing_args)
  398. {
  399. bool emitted_line_marker = false;
  400. if (define_queue || undef_queue)
  401. dump_queued_macros (pfile);
  402. if (token->type == CPP_EOF || parsing_args)
  403. return false;
  404. emitted_line_marker = maybe_print_line (src_loc);
  405. print.prev = 0;
  406. print.source = 0;
  407. /* Supply enough spaces to put this token in its original column,
  408. one space per column greater than 2, since scan_translation_unit
  409. will provide a space if PREV_WHITE. Don't bother trying to
  410. reconstruct tabs; we can't get it right in general, and nothing
  411. ought to care. Some things do care; the fault lies with them. */
  412. if (!CPP_OPTION (pfile, traditional))
  413. {
  414. int spaces = LOCATION_COLUMN (src_loc) - 2;
  415. print.printed = 1;
  416. while (-- spaces >= 0)
  417. putc (' ', print.outf);
  418. }
  419. return emitted_line_marker;
  420. }
  421. /* Called when a line of output is started. TOKEN is the first token
  422. of the line, and at end of file will be CPP_EOF. */
  423. static void
  424. cb_line_change (cpp_reader *pfile, const cpp_token *token,
  425. int parsing_args)
  426. {
  427. do_line_change (pfile, token, token->src_loc, parsing_args);
  428. }
  429. static void
  430. cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
  431. const cpp_string *str)
  432. {
  433. maybe_print_line (line);
  434. fprintf (print.outf, "#ident %s\n", str->text);
  435. print.src_line++;
  436. }
  437. static void
  438. cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
  439. {
  440. const struct line_map *map;
  441. maybe_print_line (line);
  442. fputs ("#define ", print.outf);
  443. /* 'D' is whole definition; 'N' is name only. */
  444. if (flag_dump_macros == 'D')
  445. fputs ((const char *) cpp_macro_definition (pfile, node),
  446. print.outf);
  447. else
  448. fputs ((const char *) NODE_NAME (node), print.outf);
  449. putc ('\n', print.outf);
  450. linemap_resolve_location (line_table, line,
  451. LRK_MACRO_DEFINITION_LOCATION,
  452. &map);
  453. if (LINEMAP_LINE (map) != 0)
  454. print.src_line++;
  455. }
  456. static void
  457. cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
  458. cpp_hashnode *node)
  459. {
  460. maybe_print_line (line);
  461. fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
  462. print.src_line++;
  463. }
  464. static void
  465. cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED,
  466. cpp_hashnode *node)
  467. {
  468. macro_queue *q;
  469. if (node->flags & NODE_BUILTIN)
  470. return;
  471. q = XNEW (macro_queue);
  472. q->macro = xstrdup ((const char *) cpp_macro_definition (pfile, node));
  473. q->next = define_queue;
  474. define_queue = q;
  475. }
  476. static void
  477. cb_used_undef (cpp_reader *pfile ATTRIBUTE_UNUSED,
  478. source_location line ATTRIBUTE_UNUSED,
  479. cpp_hashnode *node)
  480. {
  481. macro_queue *q;
  482. q = XNEW (macro_queue);
  483. q->macro = xstrdup ((const char *) NODE_NAME (node));
  484. q->next = undef_queue;
  485. undef_queue = q;
  486. }
  487. static void
  488. dump_queued_macros (cpp_reader *pfile ATTRIBUTE_UNUSED)
  489. {
  490. macro_queue *q;
  491. /* End the previous line of text. */
  492. if (print.printed)
  493. {
  494. putc ('\n', print.outf);
  495. print.src_line++;
  496. print.printed = 0;
  497. }
  498. for (q = define_queue; q;)
  499. {
  500. macro_queue *oq;
  501. fputs ("#define ", print.outf);
  502. fputs (q->macro, print.outf);
  503. putc ('\n', print.outf);
  504. print.src_line++;
  505. oq = q;
  506. q = q->next;
  507. free (oq->macro);
  508. free (oq);
  509. }
  510. define_queue = NULL;
  511. for (q = undef_queue; q;)
  512. {
  513. macro_queue *oq;
  514. fprintf (print.outf, "#undef %s\n", q->macro);
  515. print.src_line++;
  516. oq = q;
  517. q = q->next;
  518. free (oq->macro);
  519. free (oq);
  520. }
  521. undef_queue = NULL;
  522. }
  523. static void
  524. cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
  525. const unsigned char *dir, const char *header, int angle_brackets,
  526. const cpp_token **comments)
  527. {
  528. maybe_print_line (line);
  529. if (angle_brackets)
  530. fprintf (print.outf, "#%s <%s>", dir, header);
  531. else
  532. fprintf (print.outf, "#%s \"%s\"", dir, header);
  533. if (comments != NULL)
  534. {
  535. while (*comments != NULL)
  536. {
  537. if ((*comments)->flags & PREV_WHITE)
  538. putc (' ', print.outf);
  539. cpp_output_token (*comments, print.outf);
  540. ++comments;
  541. }
  542. }
  543. putc ('\n', print.outf);
  544. print.src_line++;
  545. }
  546. /* Callback called when -fworking-director and -E to emit working
  547. directory in cpp output file. */
  548. void
  549. pp_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
  550. {
  551. size_t to_file_len = strlen (dir);
  552. unsigned char *to_file_quoted =
  553. (unsigned char *) alloca (to_file_len * 4 + 1);
  554. unsigned char *p;
  555. /* cpp_quote_string does not nul-terminate, so we have to do it ourselves. */
  556. p = cpp_quote_string (to_file_quoted, (const unsigned char *) dir, to_file_len);
  557. *p = '\0';
  558. fprintf (print.outf, "# 1 \"%s//\"\n", to_file_quoted);
  559. }
  560. /* The file name, line number or system header flags have changed, as
  561. described in MAP. */
  562. void
  563. pp_file_change (const struct line_map *map)
  564. {
  565. const char *flags = "";
  566. if (flag_no_line_commands)
  567. return;
  568. if (map != NULL)
  569. {
  570. input_location = map->start_location;
  571. if (print.first_time)
  572. {
  573. /* Avoid printing foo.i when the main file is foo.c. */
  574. if (!cpp_get_options (parse_in)->preprocessed)
  575. print_line (map->start_location, flags);
  576. print.first_time = 0;
  577. }
  578. else
  579. {
  580. /* Bring current file to correct line when entering a new file. */
  581. if (map->reason == LC_ENTER)
  582. {
  583. const struct line_map *from = INCLUDED_FROM (line_table, map);
  584. maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
  585. }
  586. if (map->reason == LC_ENTER)
  587. flags = " 1";
  588. else if (map->reason == LC_LEAVE)
  589. flags = " 2";
  590. print_line (map->start_location, flags);
  591. }
  592. }
  593. }
  594. /* Copy a #pragma directive to the preprocessed output. */
  595. static void
  596. cb_def_pragma (cpp_reader *pfile, source_location line)
  597. {
  598. maybe_print_line (line);
  599. fputs ("#pragma ", print.outf);
  600. cpp_output_line (pfile, print.outf);
  601. print.src_line++;
  602. }
  603. /* Dump out the hash table. */
  604. static int
  605. dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED)
  606. {
  607. if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
  608. {
  609. fputs ("#define ", print.outf);
  610. fputs ((const char *) cpp_macro_definition (pfile, node),
  611. print.outf);
  612. putc ('\n', print.outf);
  613. print.src_line++;
  614. }
  615. return 1;
  616. }
  617. /* Load in the PCH file NAME, open on FD. It was originally searched for
  618. by ORIG_NAME. Also, print out a #include command so that the PCH
  619. file can be loaded when the preprocessed output is compiled. */
  620. static void
  621. cb_read_pch (cpp_reader *pfile, const char *name,
  622. int fd, const char *orig_name ATTRIBUTE_UNUSED)
  623. {
  624. c_common_read_pch (pfile, name, fd, orig_name);
  625. fprintf (print.outf, "#pragma GCC pch_preprocess \"%s\"\n", name);
  626. print.src_line++;
  627. }