comparison gcc/c-ppoutput.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents a06113de4d67
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
1 /* Preprocess only, using cpplib. 1 /* Preprocess only, using cpplib.
2 Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2 Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007,
3 2008 Free Software Foundation, Inc. 3 2008, 2009 Free Software Foundation, Inc.
4 Written by Per Bothner, 1994-95. 4 Written by Per Bothner, 1994-95.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the 7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any 8 Free Software Foundation; either version 3, or (at your option) any
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 void print_line (source_location, const char *); 62 static void print_line (source_location, const char *);
63 static void maybe_print_line (source_location); 63 static void maybe_print_line (source_location);
64 static void do_line_change (cpp_reader *, const cpp_token *,
65 source_location, int);
64 66
65 /* Callback routines for the parser. Most of these are active only 67 /* Callback routines for the parser. Most of these are active only
66 in specific modes. */ 68 in specific modes. */
67 static void cb_line_change (cpp_reader *, const cpp_token *, int); 69 static void cb_line_change (cpp_reader *, const cpp_token *, int);
68 static void cb_define (cpp_reader *, source_location, cpp_hashnode *); 70 static void cb_define (cpp_reader *, source_location, cpp_hashnode *);
158 avoidance issues. */ 160 avoidance issues. */
159 static void 161 static void
160 scan_translation_unit (cpp_reader *pfile) 162 scan_translation_unit (cpp_reader *pfile)
161 { 163 {
162 bool avoid_paste = false; 164 bool avoid_paste = false;
165 bool do_line_adjustments
166 = cpp_get_options (parse_in)->lang != CLK_ASM
167 && !flag_no_line_commands;
168 bool in_pragma = false;
163 169
164 print.source = NULL; 170 print.source = NULL;
165 for (;;) 171 for (;;)
166 { 172 {
167 const cpp_token *token = cpp_get_token (pfile); 173 source_location loc;
174 const cpp_token *token = cpp_get_token_with_location (pfile, &loc);
168 175
169 if (token->type == CPP_PADDING) 176 if (token->type == CPP_PADDING)
170 { 177 {
171 avoid_paste = true; 178 avoid_paste = true;
172 if (print.source == NULL 179 if (print.source == NULL
180 break; 187 break;
181 188
182 /* Subtle logic to output a space if and only if necessary. */ 189 /* Subtle logic to output a space if and only if necessary. */
183 if (avoid_paste) 190 if (avoid_paste)
184 { 191 {
192 const struct line_map *map
193 = linemap_lookup (line_table, loc);
194 int src_line = SOURCE_LINE (map, loc);
195
185 if (print.source == NULL) 196 if (print.source == NULL)
186 print.source = token; 197 print.source = token;
187 if (print.source->flags & PREV_WHITE 198
188 || (print.prev 199 if (src_line != print.src_line
189 && cpp_avoid_paste (pfile, print.prev, token)) 200 && do_line_adjustments
190 || (print.prev == NULL && token->type == CPP_HASH)) 201 && !in_pragma)
202 {
203 do_line_change (pfile, token, loc, false);
204 putc (' ', print.outf);
205 }
206 else if (print.source->flags & PREV_WHITE
207 || (print.prev
208 && cpp_avoid_paste (pfile, print.prev, token))
209 || (print.prev == NULL && token->type == CPP_HASH))
191 putc (' ', print.outf); 210 putc (' ', print.outf);
192 } 211 }
193 else if (token->flags & PREV_WHITE) 212 else if (token->flags & PREV_WHITE)
194 putc (' ', print.outf); 213 {
214 const struct line_map *map
215 = linemap_lookup (line_table, loc);
216 int src_line = SOURCE_LINE (map, loc);
217
218 if (src_line != print.src_line
219 && do_line_adjustments
220 && !in_pragma)
221 do_line_change (pfile, token, loc, false);
222 putc (' ', print.outf);
223 }
195 224
196 avoid_paste = false; 225 avoid_paste = false;
197 print.source = NULL; 226 print.source = NULL;
198 print.prev = token; 227 print.prev = token;
199 if (token->type == CPP_PRAGMA) 228 if (token->type == CPP_PRAGMA)
207 if (space) 236 if (space)
208 fprintf (print.outf, "%s %s", space, name); 237 fprintf (print.outf, "%s %s", space, name);
209 else 238 else
210 fprintf (print.outf, "%s", name); 239 fprintf (print.outf, "%s", name);
211 print.printed = 1; 240 print.printed = 1;
241 in_pragma = true;
212 } 242 }
213 else if (token->type == CPP_PRAGMA_EOL) 243 else if (token->type == CPP_PRAGMA_EOL)
214 maybe_print_line (token->src_loc); 244 {
245 maybe_print_line (token->src_loc);
246 in_pragma = false;
247 }
215 else 248 else
216 cpp_output_token (token, print.outf); 249 cpp_output_token (token, print.outf);
217 250
218 if (token->type == CPP_COMMENT) 251 if (token->type == CPP_COMMENT)
219 account_for_newlines (token->val.str.text, token->val.str.len); 252 account_for_newlines (token->val.str.text, token->val.str.len);
329 362
330 putc ('\n', print.outf); 363 putc ('\n', print.outf);
331 } 364 }
332 } 365 }
333 366
334 /* Called when a line of output is started. TOKEN is the first token 367 /* Helper function for cb_line_change and scan_translation_unit. */
335 of the line, and at end of file will be CPP_EOF. */ 368 static void
336 static void 369 do_line_change (cpp_reader *pfile, const cpp_token *token,
337 cb_line_change (cpp_reader *pfile, const cpp_token *token, 370 source_location src_loc, int parsing_args)
338 int parsing_args) 371 {
339 {
340 source_location src_loc = token->src_loc;
341
342 if (define_queue || undef_queue) 372 if (define_queue || undef_queue)
343 dump_queued_macros (pfile); 373 dump_queued_macros (pfile);
344 374
345 if (token->type == CPP_EOF || parsing_args) 375 if (token->type == CPP_EOF || parsing_args)
346 return; 376 return;
361 print.printed = 1; 391 print.printed = 1;
362 392
363 while (-- spaces >= 0) 393 while (-- spaces >= 0)
364 putc (' ', print.outf); 394 putc (' ', print.outf);
365 } 395 }
396 }
397
398 /* Called when a line of output is started. TOKEN is the first token
399 of the line, and at end of file will be CPP_EOF. */
400 static void
401 cb_line_change (cpp_reader *pfile, const cpp_token *token,
402 int parsing_args)
403 {
404 do_line_change (pfile, token, token->src_loc, parsing_args);
366 } 405 }
367 406
368 static void 407 static void
369 cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, 408 cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
370 const cpp_string *str) 409 const cpp_string *str)
519 if (flag_no_line_commands) 558 if (flag_no_line_commands)
520 return; 559 return;
521 560
522 if (map != NULL) 561 if (map != NULL)
523 { 562 {
563 input_location = map->start_location;
524 if (print.first_time) 564 if (print.first_time)
525 { 565 {
526 /* Avoid printing foo.i when the main file is foo.c. */ 566 /* Avoid printing foo.i when the main file is foo.c. */
527 if (!cpp_get_options (parse_in)->preprocessed) 567 if (!cpp_get_options (parse_in)->preprocessed)
528 print_line (map->start_location, flags); 568 print_line (map->start_location, flags);