OSDN Git Service

PR c++/15463
[pf3gnuchains/gcc-fork.git] / gcc / cppmacro.c
index efae0f0..e3d0dc3 100644 (file)
@@ -1,6 +1,6 @@
 /* Part of CPP library.  (Macro and #define handling.)
    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    Written by Per Bothner, 1994.
    Based on CCCP program by Paul Rubin, June 1986
    Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -80,7 +80,7 @@ _cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node,
       cpp_macro *macro = node->value.macro;
 
       if (!macro->used
-         && MAIN_FILE_P (linemap_lookup (&pfile->line_maps, macro->line)))
+         && MAIN_FILE_P (linemap_lookup (pfile->line_table, macro->line)))
        cpp_error_with_line (pfile, CPP_DL_WARNING, macro->line, 0,
                             "macro \"%s\" is not used", NODE_NAME (node));
     }
@@ -116,6 +116,7 @@ static const char * const monthnames[] =
 const uchar *
 _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
 {
+  const struct line_map *map;
   const uchar *result = NULL;
   unsigned int number = 1;
 
@@ -132,11 +133,11 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
        unsigned int len;
        const char *name;
        uchar *buf;
-       const struct line_map *map = pfile->map;
+       map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line);
 
        if (node->value.builtin == BT_BASE_FILE)
          while (! MAIN_FILE_P (map))
-           map = INCLUDED_FROM (&pfile->line_maps, map);
+           map = INCLUDED_FROM (pfile->line_table, map);
 
        name = map->to_file;
        len = strlen (name);
@@ -153,18 +154,19 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
       /* The line map depth counts the primary source as level 1, but
         historically __INCLUDE_DEPTH__ has called the primary source
         level 0.  */
-      number = pfile->line_maps.depth - 1;
+      number = pfile->line_table->depth - 1;
       break;
 
     case BT_SPECLINE:
+      map = &pfile->line_table->maps[pfile->line_table->used-1];
       /* If __LINE__ is embedded in a macro, it must expand to the
         line of the macro's invocation, not its definition.
         Otherwise things like assert() will not work properly.  */
       if (CPP_OPTION (pfile, traditional))
-       number = pfile->line;
+       number = pfile->line_table->highest_line;
       else
-       number = pfile->cur_token[-1].line;
-      number = SOURCE_LINE (pfile->map, number);
+       number = pfile->cur_token[-1].src_loc;
+      number = SOURCE_LINE (map, number);
       break;
 
       /* __STDC__ has the value 1 under normal circumstances.
@@ -174,7 +176,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
         value 0.  */
     case BT_STDC:
       {
-       if (CPP_IN_SYSTEM_HEADER (pfile)
+       if (cpp_in_system_header (pfile)
            && CPP_OPTION (pfile, stdc_0_in_system_headers)
            && !CPP_OPTION (pfile,std))
          number = 0;
@@ -1136,6 +1138,10 @@ cpp_sys_macro_p (cpp_reader *pfile)
 void
 cpp_scan_nooutput (cpp_reader *pfile)
 {
+  /* Request a CPP_EOF token at the end of this file, rather than
+     transparently continuing with the including file.  */
+  pfile->buffer->return_at_eof = true;
+
   if (CPP_OPTION (pfile, traditional))
     while (_cpp_read_logical_line_trad (pfile))
       ;
@@ -1321,11 +1327,14 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
              _cpp_save_parameter (pfile, macro,
                                   pfile->spec_nodes.n__VA_ARGS__);
              pfile->state.va_args_ok = 1;
-             if (! CPP_OPTION (pfile, c99) && CPP_OPTION (pfile, pedantic))
+             if (! CPP_OPTION (pfile, c99)
+                 && CPP_OPTION (pfile, pedantic)
+                 && CPP_OPTION (pfile, warn_variadic_macros))
                cpp_error (pfile, CPP_DL_PEDWARN,
                           "anonymous variadic macros were introduced in C99");
            }
-         else if (CPP_OPTION (pfile, pedantic))
+         else if (CPP_OPTION (pfile, pedantic)
+                  && CPP_OPTION (pfile, warn_variadic_macros))
            cpp_error (pfile, CPP_DL_PEDWARN,
                       "ISO C does not permit named variadic macros");
 
@@ -1488,7 +1497,7 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
   macro->count = 0;
   macro->fun_like = 0;
   /* To suppress some diagnostics.  */
-  macro->syshdr = pfile->map->sysp != 0;
+  macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0;
 
   if (CPP_OPTION (pfile, traditional))
     ok = _cpp_create_trad_definition (pfile, macro);