summaryrefslogtreecommitdiff
path: root/gcc/c-ppoutput.c
diff options
context:
space:
mode:
authoraaw <aaw@138bc75d-0d04-0410-961f-82ee72b054a4>2007-07-30 18:29:20 +0000
committeraaw <aaw@138bc75d-0d04-0410-961f-82ee72b054a4>2007-07-30 18:29:20 +0000
commitfcde64dc3abc672d1353e44993b839c4db1d5758 (patch)
treebb584ffda6bfb46d8b03b533da0e2f408e0bbd23 /gcc/c-ppoutput.c
parent81a410b1e4f861bb1eb31c7fa7daedf6bf70abc4 (diff)
downloadgcc-fcde64dc3abc672d1353e44993b839c4db1d5758.tar.gz
libcpp/
* directives-only.c: New file. * internal.h (struct _cpp_dir_only_callbacks): New. (_cpp_preprocess_dir_only): New function. * directives.c (_cpp_handle_directive): Check directives_only before disabling execution of indented directives. * files.c (_cpp_stack_file): Add directives_only check. * include/cpplib.h (struct cpp_options): Add directives_only. (cpp_init_special_builtins): New function. * init.c (cpp_init_special_builtins): New function. (cpp_init_builtins): Move builtin_array initialization to cpp_init_special_builtins. (post_options): Check directives_only before setting pfile->state.prevent_expansion = 1. * macro.c (_cpp_builtin_macro_text): Print an error if __COUNTER__ is expanded inside a directive while -fdirectives-only is enabled. * Makefile.in (libcpp_a_OBJS): Add directives-only.o. (libcpp_a_SOURCES): Add directives-only.c. gcc/ * c-ppoutput.c (print_lines_directives_only): New function. (scan_translation_unit_directives_only): New function. (preprocess_file): Add call to scan_translation_unit_directives_only. * c-opts.c (c_common_handle_option): Add OPT_fdirectives_only. (sanitize_cpp_opts): Add default flag_dump_macros setting for -fdirectives-only. Add errors for -fdirectives-only conflict with -Wunused-macros and -traditional. (finish_options): Add builtin macro initialization for -fdirectives-only + -fpreprocessed. * c.opt (fdirectives-only): New. * doc/cppopts.texi (fdirectives-only): New. gcc/testsuite/ * gcc.dg/cpp/counter-2.c: New test. * gcc.dg/cpp/counter-3.c: New test. * gcc.dg/cpp/dir-only-1.c: New test. * gcc.dg/cpp/dir-only-1.h: New file. * gcc.dg/cpp/dir-only-2.c: New test. * gcc.dg/cpp/dir-only-3.c: New test. * gcc.dg/cpp/dir-only-3a.h: New file. * gcc.dg/cpp/dir-only-3b.h: New file. * gcc.dg/cpp/dir-only-4.c: New test. * gcc.dg/cpp/dir-only-5.c: New test. * gcc.dg/cpp/dir-only-6.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127066 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-ppoutput.c')
-rw-r--r--gcc/c-ppoutput.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/c-ppoutput.c b/gcc/c-ppoutput.c
index 6c440954d94..22ee0f6a887 100644
--- a/gcc/c-ppoutput.c
+++ b/gcc/c-ppoutput.c
@@ -41,6 +41,8 @@ static struct
/* General output routines. */
static void scan_translation_unit (cpp_reader *);
+static void print_lines_directives_only (int, const void *, size_t);
+static void scan_translation_unit_directives_only (cpp_reader *);
static void scan_translation_unit_trad (cpp_reader *);
static void account_for_newlines (const unsigned char *, size_t);
static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
@@ -75,6 +77,9 @@ preprocess_file (cpp_reader *pfile)
}
else if (cpp_get_options (pfile)->traditional)
scan_translation_unit_trad (pfile);
+ else if (cpp_get_options (pfile)->directives_only
+ && !cpp_get_options (pfile)->preprocessed)
+ scan_translation_unit_directives_only (pfile);
else
scan_translation_unit (pfile);
@@ -179,6 +184,26 @@ scan_translation_unit (cpp_reader *pfile)
}
}
+static void
+print_lines_directives_only (int lines, const void *buf, size_t size)
+{
+ print.src_line += lines;
+ fwrite (buf, 1, size, print.outf);
+}
+
+/* Writes out the preprocessed file, handling spacing and paste
+ avoidance issues. */
+static void
+scan_translation_unit_directives_only (cpp_reader *pfile)
+{
+ struct _cpp_dir_only_callbacks cb;
+
+ cb.print_lines = print_lines_directives_only;
+ cb.maybe_print_line = maybe_print_line;
+
+ _cpp_preprocess_dir_only (pfile, &cb);
+}
+
/* Adjust print.src_line for newlines embedded in output. */
static void
account_for_newlines (const unsigned char *str, size_t len)