/* Preprocess only, using cpplib.
- Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
- Free Software Foundation, Inc.
+ Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007,
+ 2008 Free Software Foundation, Inc.
Written by Per Bothner, 1994-95.
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3, or (at your option) any
+ later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
file. */
static struct
{
- FILE *outf; /* Stream to write to. */
- const cpp_token *prev; /* Previous token. */
- const cpp_token *source; /* Source token for spacing. */
- int src_line; /* Line number currently being written. */
- unsigned char printed; /* Nonzero if something output at line. */
- bool first_time; /* pp_file_change hasn't been called yet. */
+ FILE *outf; /* Stream to write to. */
+ const cpp_token *prev; /* Previous token. */
+ const cpp_token *source; /* Source token for spacing. */
+ int src_line; /* Line number currently being written. */
+ unsigned char printed; /* Nonzero if something output at line. */
+ bool first_time; /* pp_file_change hasn't been called yet. */
} print;
/* General output routines. */
static void cb_define (cpp_reader *, source_location, cpp_hashnode *);
static void cb_undef (cpp_reader *, source_location, cpp_hashnode *);
static void cb_include (cpp_reader *, source_location, const unsigned char *,
- const char *, int, const cpp_token **);
+ const char *, int, const cpp_token **);
static void cb_ident (cpp_reader *, source_location, const cpp_string *);
static void cb_def_pragma (cpp_reader *, source_location);
#if 0
static void cb_read_pch (cpp_reader *pfile, const char *name,
- int fd, const char *orig_name);
+ int fd, const char *orig_name);
#endif
/* Preprocess and output. */
{
/* Scan -included buffers, then the main file. */
while (pfile->buffer->prev)
- cpp_scan_nooutput (pfile);
+ cpp_scan_nooutput (pfile);
cpp_scan_nooutput (pfile);
}
else if (cpp_get_options (pfile)->traditional)
{
cb->line_change = cb_line_change;
/* Don't emit #pragma or #ident directives if we are processing
- assembly language; the assembler may choke on them. */
+ assembly language; the assembler may choke on them. */
if (cpp_get_options (parse_in)->lang != CLK_ASM)
- {
- cb->ident = cb_ident;
- cb->def_pragma = cb_def_pragma;
- }
+ {
+ cb->ident = cb_ident;
+ cb->def_pragma = cb_def_pragma;
+ }
}
if (flag_dump_includes)
const cpp_token *token = cpp_get_token (pfile);
if (token->type == CPP_PADDING)
- {
- avoid_paste = true;
- if (print.source == NULL
- || (!(print.source->flags & PREV_WHITE)
- && token->val.source == NULL))
- print.source = token->val.source;
- continue;
- }
+ {
+ avoid_paste = true;
+ if (print.source == NULL
+ || (!(print.source->flags & PREV_WHITE)
+ && token->val.source == NULL))
+ print.source = token->val.source;
+ continue;
+ }
if (token->type == CPP_EOF)
- break;
+ break;
/* Subtle logic to output a space if and only if necessary. */
if (avoid_paste)
- {
- if (print.source == NULL)
- print.source = token;
- if (print.source->flags & PREV_WHITE
- || (print.prev
- && cpp_avoid_paste (pfile, print.prev, token))
- || (print.prev == NULL && token->type == CPP_HASH))
- putc (' ', print.outf);
- }
+ {
+ if (print.source == NULL)
+ print.source = token;
+ if (print.source->flags & PREV_WHITE
+ || (print.prev
+ && cpp_avoid_paste (pfile, print.prev, token))
+ || (print.prev == NULL && token->type == CPP_HASH))
+ putc (' ', print.outf);
+ }
else if (token->flags & PREV_WHITE)
- putc (' ', print.outf);
+ putc (' ', print.outf);
avoid_paste = false;
print.source = NULL;
cpp_output_token (token, print.outf);
if (token->type == CPP_COMMENT)
- account_for_newlines (token->val.str.text, token->val.str.len);
+ account_for_newlines (token->val.str.text, token->val.str.len);
}
}
fwrite (pfile->out.base, 1, len, print.outf);
print.printed = 1;
if (!CPP_OPTION (pfile, discard_comments))
- account_for_newlines (pfile->out.base, len);
+ account_for_newlines (pfile->out.base, len);
}
}
static void
maybe_print_line (source_location src_loc)
{
- const struct line_map *map = linemap_lookup (&line_table, src_loc);
+ const struct line_map *map = linemap_lookup (line_table, src_loc);
int src_line = SOURCE_LINE (map, src_loc);
/* End the previous line of text. */
if (print.printed)
if (src_line >= print.src_line && src_line < print.src_line + 8)
{
while (src_line > print.src_line)
- {
- putc ('\n', print.outf);
- print.src_line++;
- }
+ {
+ putc ('\n', print.outf);
+ print.src_line++;
+ }
}
else
print_line (src_loc, "");
if (!flag_no_line_commands)
{
- const struct line_map *map = linemap_lookup (&line_table, src_loc);
+ const struct line_map *map = linemap_lookup (line_table, src_loc);
size_t to_file_len = strlen (map->to_file);
unsigned char *to_file_quoted =
print.src_line = SOURCE_LINE (map, src_loc);
/* cpp_quote_string does not nul-terminate, so we have to do it
- ourselves. */
+ ourselves. */
p = cpp_quote_string (to_file_quoted,
- (unsigned char *) map->to_file, to_file_len);
+ (unsigned char *) map->to_file, to_file_len);
*p = '\0';
fprintf (print.outf, "# %u \"%s\"%s",
- print.src_line == 0 ? 1 : print.src_line,
- to_file_quoted, special_flags);
+ print.src_line == 0 ? 1 : print.src_line,
+ to_file_quoted, special_flags);
if (map->sysp == 2)
- fputs (" 3 4", print.outf);
+ fputs (" 3 4", print.outf);
else if (map->sysp == 1)
- fputs (" 3", print.outf);
+ fputs (" 3", print.outf);
putc ('\n', print.outf);
}
of the line, and at end of file will be CPP_EOF. */
static void
cb_line_change (cpp_reader *pfile, const cpp_token *token,
- int parsing_args)
+ int parsing_args)
{
source_location src_loc = token->src_loc;
ought to care. Some things do care; the fault lies with them. */
if (!CPP_OPTION (pfile, traditional))
{
- const struct line_map *map = linemap_lookup (&line_table, src_loc);
+ const struct line_map *map = linemap_lookup (line_table, src_loc);
int spaces = SOURCE_COLUMN (map, src_loc) - 2;
print.printed = 1;
while (-- spaces >= 0)
- putc (' ', print.outf);
+ putc (' ', print.outf);
}
}
static void
cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
- const cpp_string *str)
+ const cpp_string *str)
{
maybe_print_line (line);
fprintf (print.outf, "#ident %s\n", str->text);
/* 'D' is whole definition; 'N' is name only. */
if (flag_dump_macros == 'D')
fputs ((const char *) cpp_macro_definition (pfile, node),
- print.outf);
+ print.outf);
else
fputs ((const char *) NODE_NAME (node), print.outf);
putc ('\n', print.outf);
- if (linemap_lookup (&line_table, line)->to_line != 0)
+ if (linemap_lookup (line_table, line)->to_line != 0)
print.src_line++;
}
static void
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
- cpp_hashnode *node)
+ cpp_hashnode *node)
{
maybe_print_line (line);
fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
static void
cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
- const unsigned char *dir, const char *header, int angle_brackets,
- const cpp_token **comments)
+ const unsigned char *dir, const char *header, int angle_brackets,
+ const cpp_token **comments)
{
maybe_print_line (line);
if (angle_brackets)
if (comments != NULL)
{
while (*comments != NULL)
- {
- if ((*comments)->flags & PREV_WHITE)
- putc (' ', print.outf);
- cpp_output_token (*comments, print.outf);
- ++comments;
- }
+ {
+ if ((*comments)->flags & PREV_WHITE)
+ putc (' ', print.outf);
+ cpp_output_token (*comments, print.outf);
+ ++comments;
+ }
}
putc ('\n', print.outf);
if (map != NULL)
{
if (print.first_time)
- {
- /* Avoid printing foo.i when the main file is foo.c. */
- if (!cpp_get_options (parse_in)->preprocessed)
- print_line (map->start_location, flags);
- print.first_time = 0;
- }
+ {
+ /* Avoid printing foo.i when the main file is foo.c. */
+ if (!cpp_get_options (parse_in)->preprocessed)
+ print_line (map->start_location, flags);
+ print.first_time = 0;
+ }
else
- {
- /* Bring current file to correct line when entering a new file. */
- if (map->reason == LC_ENTER)
- {
- const struct line_map *from = INCLUDED_FROM (&line_table, map);
- maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
- }
- if (map->reason == LC_ENTER)
- flags = " 1";
- else if (map->reason == LC_LEAVE)
- flags = " 2";
- print_line (map->start_location, flags);
- }
+ {
+ /* Bring current file to correct line when entering a new file. */
+ if (map->reason == LC_ENTER)
+ {
+ const struct line_map *from = INCLUDED_FROM (line_table, map);
+ maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
+ }
+ if (map->reason == LC_ENTER)
+ flags = " 1";
+ else if (map->reason == LC_LEAVE)
+ flags = " 2";
+ print_line (map->start_location, flags);
+ }
}
}
{
fputs ("#define ", print.outf);
fputs ((const char *) cpp_macro_definition (pfile, node),
- print.outf);
+ print.outf);
putc ('\n', print.outf);
print.src_line++;
}
static void
cb_read_pch (cpp_reader *pfile, const char *name,
- int fd, const char *orig_name ATTRIBUTE_UNUSED)
+ int fd, const char *orig_name ATTRIBUTE_UNUSED)
{
c_common_read_pch (pfile, name, fd, orig_name);