summaryrefslogtreecommitdiff
path: root/gcc/cpphash.c
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-02 20:14:32 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-02 20:14:32 +0000
commitd2e850c1ebd9bb4d8d5f9fed01bd3bce6a40130e (patch)
tree83b50be95e2db0783f35dfe9f8625210e9368a40 /gcc/cpphash.c
parent28e5f485b33df15cf6eca765f7f831d528c7af97 (diff)
downloadgcc-d2e850c1ebd9bb4d8d5f9fed01bd3bce6a40130e.tar.gz
* cppfiles.c (cpp_read_file): New function.
* cpphash.c (collect_expansion): Make sure to reset last_token to NORM when we hit a string. Handle trailing whitespace properly when the expansion is empty. (create_definition): Disable line commands while parsing the directive line. (dump_definition): If pfile->lineno == 0, output a line command ahead of the dump, and add a trailing newline. * cppinit.c (append_include_chain): Add fifth argument, which indicates whether or not system headers are C++ aware. (initialize_standard_includes): New function, broken out of read_and_prescan. Pass 'cxx_aware' value from the include_defaults_array on to append_include_chain. (dump_special_to_buffer): Const-ify char array. (builtin_array): Don't dump __BASE_FILE__. (cpp_start_read): Use cpp_read_file. Reorder code for clarity. Don't output line commands here for -D/-A/-U switches. Don't call deps_output for files included with -include or -imacros. * cpplib.c (do_define): Don't pay any attention to the second argument. (cpp_expand_to_buffer): Disable line commands while scanning. (output_line_command): Work in the file buffer. * cpplib.h: Remove no_record_file flag from struct cpp_reader. Fix formatting of comments. Prototype cpp_read_file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32293 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpphash.c')
-rw-r--r--gcc/cpphash.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/gcc/cpphash.c b/gcc/cpphash.c
index d44bdcb48c9..ae5df165468 100644
--- a/gcc/cpphash.c
+++ b/gcc/cpphash.c
@@ -424,6 +424,7 @@ collect_expansion (pfile, arglist)
continue;
maybe_trad_stringify:
+ last_token = NORM;
{
U_CHAR *base, *p, *limit;
struct reflist *tpat;
@@ -487,21 +488,31 @@ collect_expansion (pfile, arglist)
else if (last_token == PASTE)
cpp_error (pfile, "`##' at end of macro definition");
- /* Trim trailing white space from definition. */
- here = CPP_WRITTEN (pfile);
- while (here > last && is_hspace (pfile->token_buffer [here-1]))
- here--;
- CPP_SET_WRITTEN (pfile, here);
+ if (last_token == START)
+ {
+ /* Empty macro definition. */
+ exp = xstrdup ("\r \r ");
+ len = 1;
+ }
+ else
+ {
+ /* Trim trailing white space from definition. */
+ here = CPP_WRITTEN (pfile);
+ while (here > last && is_hspace (pfile->token_buffer [here-1]))
+ here--;
+ CPP_SET_WRITTEN (pfile, here);
- CPP_NUL_TERMINATE (pfile);
- len = CPP_WRITTEN (pfile) - start + 1;
- exp = xmalloc (len + 4); /* space for no-concat markers at either end */
- exp[0] = '\r';
- exp[1] = ' ';
- exp[len + 1] = '\r';
- exp[len + 2] = ' ';
- exp[len + 3] = '\0';
- memcpy (&exp[2], pfile->token_buffer + start, len - 1);
+ CPP_NUL_TERMINATE (pfile);
+ len = CPP_WRITTEN (pfile) - start + 1;
+ exp = xmalloc (len + 4); /* space for no-concat markers at either end */
+ exp[0] = '\r';
+ exp[1] = ' ';
+ exp[len + 1] = '\r';
+ exp[len + 2] = ' ';
+ exp[len + 3] = '\0';
+ memcpy (&exp[2], pfile->token_buffer + start, len - 1);
+ }
+
CPP_SET_WRITTEN (pfile, start);
defn = (DEFINITION *) xmalloc (sizeof (DEFINITION));
@@ -700,6 +711,7 @@ create_definition (pfile, funlike)
pfile->no_macro_expand++;
pfile->parsing_define_directive++;
CPP_OPTIONS (pfile)->discard_comments++;
+ CPP_OPTIONS (pfile)->no_line_commands++;
if (funlike)
{
@@ -719,12 +731,14 @@ create_definition (pfile, funlike)
pfile->no_macro_expand--;
pfile->parsing_define_directive--;
CPP_OPTIONS (pfile)->discard_comments--;
+ CPP_OPTIONS (pfile)->no_line_commands--;
return defn;
err:
pfile->no_macro_expand--;
pfile->parsing_define_directive--;
CPP_OPTIONS (pfile)->discard_comments--;
+ CPP_OPTIONS (pfile)->no_line_commands--;
return 0;
}
@@ -1560,6 +1574,9 @@ dump_definition (pfile, sym, len, defn)
long len;
DEFINITION *defn;
{
+ if (pfile->lineno == 0)
+ output_line_command (pfile, same_file);
+
CPP_RESERVE (pfile, len + sizeof "#define ");
CPP_PUTS_Q (pfile, "#define ", sizeof "#define " -1);
CPP_PUTS_Q (pfile, sym, len);
@@ -1573,7 +1590,6 @@ dump_definition (pfile, sym, len, defn)
So we need length-4 chars of space, plus one for the NUL. */
CPP_RESERVE (pfile, defn->length - 4 + 1);
CPP_PUTS_Q (pfile, defn->expansion + 2, defn->length - 4);
- CPP_NUL_TERMINATE_Q (pfile);
}
else
{
@@ -1644,6 +1660,9 @@ dump_definition (pfile, sym, len, defn)
i = defn->length - (x - defn->expansion) - 2;
if (*x == '\r') x += 2, i -= 2;
if (i > 0) CPP_PUTS (pfile, x, i);
- CPP_NUL_TERMINATE (pfile);
}
+
+ if (pfile->lineno == 0)
+ CPP_PUTC (pfile, '\n');
+ CPP_NUL_TERMINATE (pfile);
}