OSDN Git Service

PR c++/15463
[pf3gnuchains/gcc-fork.git] / gcc / cppmacro.c
index 87ad592..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,8 +80,8 @@ _cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node,
       cpp_macro *macro = node->value.macro;
 
       if (!macro->used
-         && MAIN_FILE_P (lookup_line (&pfile->line_maps, macro->line)))
-       cpp_error_with_line (pfile, DL_WARNING, macro->line, 0,
+         && 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,13 +116,14 @@ 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;
 
   switch (node->value.builtin)
     {
     default:
-      cpp_error (pfile, DL_ICE, "invalid built-in macro \"%s\"",
+      cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
                 NODE_NAME (node));
       break;
 
@@ -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;
@@ -217,7 +219,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
            }
          else
            {
-             cpp_errno (pfile, DL_WARNING,
+             cpp_errno (pfile, CPP_DL_WARNING,
                         "could not determine date and time");
                
              pfile->date = U"\"??? ?? ????\"";
@@ -270,14 +272,14 @@ builtin_macro (cpp_reader *pfile, cpp_hashnode *node)
   memcpy (nbuf, buf, len);
   nbuf[len]='\n';
 
-  cpp_push_buffer (pfile, (uchar *) nbuf, len, /* from_stage3 */ true, 1);
+  cpp_push_buffer (pfile, (uchar *) nbuf, len, /* from_stage3 */ true);
   _cpp_clean_line (pfile);
 
   /* Set pfile->cur_token as required by _cpp_lex_direct.  */
   pfile->cur_token = _cpp_temp_token (pfile);
   push_token_context (pfile, NULL, _cpp_lex_direct (pfile), 1);
   if (pfile->buffer->cur != pfile->buffer->rlimit)
-    cpp_error (pfile, DL_ICE, "invalid built-in macro \"%s\"",
+    cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
               NODE_NAME (node));
   _cpp_pop_buffer (pfile);
 
@@ -389,7 +391,7 @@ stringify_arg (cpp_reader *pfile, macro_arg *arg)
   /* Ignore the final \ of invalid string literals.  */
   if (backslash_count & 1)
     {
-      cpp_error (pfile, DL_WARNING,
+      cpp_error (pfile, CPP_DL_WARNING,
                 "invalid string literal, ignoring final '\\'");
       dest--;
     }
@@ -414,7 +416,7 @@ paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs)
 
   lhs = *plhs;
   len = cpp_token_len (lhs) + cpp_token_len (rhs) + 1;
-  buf = (unsigned char *) alloca (len);
+  buf = alloca (len);
   end = cpp_spell_token (pfile, lhs, buf);
 
   /* Avoid comment headers, since they are still processed in stage 3.
@@ -426,7 +428,7 @@ paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs)
   end = cpp_spell_token (pfile, rhs, end);
   *end = '\n';
 
-  cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true, 1);
+  cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true);
   _cpp_clean_line (pfile);
 
   /* Set pfile->cur_token as required by _cpp_lex_direct.  */
@@ -472,7 +474,7 @@ paste_all_tokens (cpp_reader *pfile, const cpp_token *lhs)
 
          /* Mandatory error for all apart from assembler.  */
          if (CPP_OPTION (pfile, lang) != CLK_ASM)
-           cpp_error (pfile, DL_ERROR,
+           cpp_error (pfile, CPP_DL_ERROR,
         "pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
                       cpp_token_as_text (pfile, lhs),
                       cpp_token_as_text (pfile, rhs));
@@ -510,17 +512,17 @@ _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node
       if (argc + 1 == macro->paramc && macro->variadic)
        {
          if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
-           cpp_error (pfile, DL_PEDWARN,
+           cpp_error (pfile, CPP_DL_PEDWARN,
                       "ISO C99 requires rest arguments to be used");
          return true;
        }
 
-      cpp_error (pfile, DL_ERROR,
+      cpp_error (pfile, CPP_DL_ERROR,
                 "macro \"%s\" requires %u arguments, but only %u given",
                 NODE_NAME (node), macro->paramc, argc);
     }
   else
-    cpp_error (pfile, DL_ERROR,
+    cpp_error (pfile, CPP_DL_ERROR,
               "macro \"%s\" passed %u arguments, but takes just %u",
               NODE_NAME (node), argc, macro->paramc);
 
@@ -631,7 +633,7 @@ collect_args (cpp_reader *pfile, const cpp_hashnode *node)
         callers at the end of an -include-d file.  */
       if (pfile->context->prev || pfile->state.in_directive)
        _cpp_backup_tokens (pfile, 1);
-      cpp_error (pfile, DL_ERROR,
+      cpp_error (pfile, CPP_DL_ERROR,
                 "unterminated argument list invoking macro \"%s\"",
                 NODE_NAME (node));
     }
@@ -734,7 +736,7 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node)
          if (buff == NULL)
            {
              if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr)
-               cpp_error (pfile, DL_WARNING,
+               cpp_error (pfile, CPP_DL_WARNING,
  "function-like macro \"%s\" must be used with arguments in traditional C",
                           NODE_NAME (node));
 
@@ -991,8 +993,7 @@ expand_arg (cpp_reader *pfile, macro_arg *arg)
 
   /* Loop, reading in the arguments.  */
   capacity = 256;
-  arg->expanded = (const cpp_token **)
-    xmalloc (capacity * sizeof (cpp_token *));
+  arg->expanded = xmalloc (capacity * sizeof (cpp_token *));
 
   push_ptoken_context (pfile, NULL, NULL, arg->first, arg->count + 1);
   for (;;)
@@ -1002,8 +1003,8 @@ expand_arg (cpp_reader *pfile, macro_arg *arg)
       if (arg->expanded_count + 1 >= capacity)
        {
          capacity *= 2;
-         arg->expanded = (const cpp_token **)
-           xrealloc (arg->expanded, capacity * sizeof (cpp_token *));
+         arg->expanded = xrealloc (arg->expanded,
+                                   capacity * sizeof (cpp_token *));
        }
 
       token = cpp_get_token (pfile);
@@ -1243,7 +1244,7 @@ _cpp_save_parameter (cpp_reader *pfile, cpp_macro *macro, cpp_hashnode *node)
   /* Constraint 6.10.3.6 - duplicate parameter names.  */
   if (node->flags & NODE_MACRO_ARG)
     {
-      cpp_error (pfile, DL_ERROR, "duplicate macro parameter \"%s\"",
+      cpp_error (pfile, CPP_DL_ERROR, "duplicate macro parameter \"%s\"",
                 NODE_NAME (node));
       return true;
     }
@@ -1257,7 +1258,7 @@ _cpp_save_parameter (cpp_reader *pfile, cpp_macro *macro, cpp_hashnode *node)
   len = macro->paramc * sizeof (union _cpp_hashnode_value);
   if (len > pfile->macro_buffer_len)
     {
-      pfile->macro_buffer = (uchar *) xrealloc (pfile->macro_buffer, len);
+      pfile->macro_buffer = xrealloc (pfile->macro_buffer, len);
       pfile->macro_buffer_len = len;
     }
   ((union _cpp_hashnode_value *) pfile->macro_buffer)[macro->paramc - 1]
@@ -1287,7 +1288,7 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
              && ! CPP_OPTION (pfile, discard_comments_in_macro_exp))
            continue;
 
-         cpp_error (pfile, DL_ERROR,
+         cpp_error (pfile, CPP_DL_ERROR,
                     "\"%s\" may not appear in macro parameter list",
                     cpp_token_as_text (pfile, token));
          return false;
@@ -1295,7 +1296,7 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
        case CPP_NAME:
          if (prev_ident)
            {
-             cpp_error (pfile, DL_ERROR,
+             cpp_error (pfile, CPP_DL_ERROR,
                         "macro parameters must be comma-separated");
              return false;
            }
@@ -1313,7 +1314,7 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
        case CPP_COMMA:
          if (!prev_ident)
            {
-             cpp_error (pfile, DL_ERROR, "parameter name missing");
+             cpp_error (pfile, CPP_DL_ERROR, "parameter name missing");
              return false;
            }
          prev_ident = 0;
@@ -1326,12 +1327,15 @@ 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))
-               cpp_error (pfile, DL_PEDWARN,
+             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))
-           cpp_error (pfile, DL_PEDWARN,
+         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");
 
          /* We're at the end, and just expect a closing parenthesis.  */
@@ -1341,7 +1345,7 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
          /* Fall through.  */
 
        case CPP_EOF:
-         cpp_error (pfile, DL_ERROR, "missing ')' in macro parameter list");
+         cpp_error (pfile, CPP_DL_ERROR, "missing ')' in macro parameter list");
          return false;
        }
     }
@@ -1403,7 +1407,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
       macro->fun_like = 1;
     }
   else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE))
-    cpp_error (pfile, DL_PEDWARN,
+    cpp_error (pfile, CPP_DL_PEDWARN,
               "ISO C requires whitespace after the macro name");
 
   if (macro->fun_like)
@@ -1431,7 +1435,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
          /* Let assembler get away with murder.  */
          else if (CPP_OPTION (pfile, lang) != CLK_ASM)
            {
-             cpp_error (pfile, DL_ERROR,
+             cpp_error (pfile, CPP_DL_ERROR,
                         "'#' is not followed by a macro parameter");
              return false;
            }
@@ -1450,7 +1454,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
 
          if (macro->count == 0 || token->type == CPP_EOF)
            {
-             cpp_error (pfile, DL_ERROR,
+             cpp_error (pfile, CPP_DL_ERROR,
                 "'##' cannot appear at either end of a macro expansion");
              return false;
            }
@@ -1493,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);
@@ -1534,11 +1538,11 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
 
       if (warn_of_redefinition (pfile, node, macro))
        {
-         cpp_error_with_line (pfile, DL_PEDWARN, pfile->directive_line, 0,
+         cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->directive_line, 0,
                               "\"%s\" redefined", NODE_NAME (node));
 
          if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
-           cpp_error_with_line (pfile, DL_PEDWARN,
+           cpp_error_with_line (pfile, CPP_DL_PEDWARN,
                                 node->value.macro->line, 0,
                         "this is the location of the previous definition");
        }
@@ -1589,7 +1593,7 @@ check_trad_stringification (cpp_reader *pfile, const cpp_macro *macro,
          if (NODE_LEN (node) == len
              && !memcmp (p, NODE_NAME (node), len))
            {
-             cpp_error (pfile, DL_WARNING,
+             cpp_error (pfile, CPP_DL_WARNING,
           "macro argument \"%s\" would be stringified in traditional C",
                         NODE_NAME (node));
              break;
@@ -1612,7 +1616,7 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node)
 
   if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN))
     {
-      cpp_error (pfile, DL_ICE,
+      cpp_error (pfile, CPP_DL_ICE,
                 "invalid hash type %d in cpp_macro_definition", node->type);
       return 0;
     }
@@ -1648,7 +1652,7 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node)
 
   if (len > pfile->macro_buffer_len)
     {
-      pfile->macro_buffer = (uchar *) xrealloc (pfile->macro_buffer, len);
+      pfile->macro_buffer = xrealloc (pfile->macro_buffer, len);
       pfile->macro_buffer_len = len;
     }