aboutsummaryrefslogtreecommitdiff
path: root/libcpp/lex.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2008-05-21 21:52:57 +0000
committerTom Tromey <tromey@redhat.com>2008-05-21 21:52:57 +0000
commite1f2abebc2fc1d3065043342d4f171ef24caf4be (patch)
treea31b212aa429bae765ecae0b494fda6a486c56a5 /libcpp/lex.c
parente3e606ee270e8aead6b16fd5f61ef38dce32f33e (diff)
gcc/testsuite
PR preprocessor/27777: * gcc.dg/cpp/pr27777.c: New file. libcpp PR preprocessor/27777: * lex.c (cpp_output_line_to_string): New function. * internal.h (_cpp_begin_message): Don't declare. * errors.c (_cpp_begin_message): Now static. * include/cpplib.h (cpp_output_line_to_string): Declare. * directives.c (do_diagnostic): Rewrote. Use cpp_output_line_to_string. Don't use _cpp_begin_message. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@135740 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/lex.c')
-rw-r--r--libcpp/lex.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 772a8701654..70897fd57db 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -1,5 +1,5 @@
/* CPP Library - lexical analysis.
- Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -1539,6 +1539,51 @@ cpp_output_line (cpp_reader *pfile, FILE *fp)
putc ('\n', fp);
}
+/* Return a string representation of all the remaining tokens on the
+ current line. The result is allocated using xmalloc and must be
+ freed by the caller. */
+unsigned char *
+cpp_output_line_to_string (cpp_reader *pfile, const unsigned char *dir_name)
+{
+ const cpp_token *token;
+ unsigned int out = dir_name ? ustrlen (dir_name) : 0;
+ unsigned int alloced = 120 + out;
+ unsigned char *result = (unsigned char *) xmalloc (alloced);
+
+ /* If DIR_NAME is empty, there are no initial contents. */
+ if (dir_name)
+ {
+ sprintf ((char *) result, "#%s ", dir_name);
+ out += 2;
+ }
+
+ token = cpp_get_token (pfile);
+ while (token->type != CPP_EOF)
+ {
+ unsigned char *last;
+ /* Include room for a possible space and the terminating nul. */
+ unsigned int len = cpp_token_len (token) + 2;
+
+ if (out + len > alloced)
+ {
+ alloced *= 2;
+ if (out + len > alloced)
+ alloced = out + len;
+ result = (unsigned char *) xrealloc (result, alloced);
+ }
+
+ last = cpp_spell_token (pfile, token, &result[out], 0);
+ out = last - result;
+
+ token = cpp_get_token (pfile);
+ if (token->flags & PREV_WHITE)
+ result[out++] = ' ';
+ }
+
+ result[out] = '\0';
+ return result;
+}
+
/* Memory buffers. Changing these three constants can have a dramatic
effect on performance. The values here are reasonable defaults,
but might be tuned. If you adjust them, be sure to test across a