OSDN Git Service

Fix bad regexp
[pf3gnuchains/gcc-fork.git] / gcc / cppmacro.c
index c5bb71e..876506b 100644 (file)
@@ -64,7 +64,7 @@ static cpp_context *next_context PARAMS ((cpp_reader *));
 static const cpp_token *padding_token
   PARAMS ((cpp_reader *, const cpp_token *));
 static void expand_arg PARAMS ((cpp_reader *, macro_arg *));
-static const cpp_token *new_string_token PARAMS ((cpp_reader *, U_CHAR *,
+static const cpp_token *new_string_token PARAMS ((cpp_reader *, uchar *,
                                                  unsigned int));
 static const cpp_token *new_number_token PARAMS ((cpp_reader *, unsigned int));
 static const cpp_token *stringify_arg PARAMS ((cpp_reader *, macro_arg *));
@@ -143,7 +143,8 @@ builtin_macro (pfile, node)
   switch (node->value.builtin)
     {
     default:
-      cpp_ice (pfile, "invalid built-in macro \"%s\"", NODE_NAME (node));
+      cpp_error (pfile, DL_ICE, "invalid built-in macro \"%s\"",
+                NODE_NAME (node));
       return 0;
 
     case BT_FILE:
@@ -151,7 +152,7 @@ builtin_macro (pfile, node)
       {
        unsigned int len;
        const char *name;
-       U_CHAR *buf;
+       uchar *buf;
        const struct line_map *map = pfile->map;
 
        if (node->value.builtin == BT_BASE_FILE)
@@ -243,15 +244,15 @@ builtin_macro (pfile, node)
    backslashes and double quotes.  Non-printable characters are
    converted to octal.  DEST must be of sufficient size.  Returns
    a pointer to the end of the string.  */
-U_CHAR *
+uchar *
 cpp_quote_string (dest, src, len)
-     U_CHAR *dest;
-     const U_CHAR *src;
+     uchar *dest;
+     const uchar *src;
      unsigned int len;
 {
   while (len--)
     {
-      U_CHAR c = *src++;
+      uchar c = *src++;
 
       if (c == '\\' || c == '"')
        {
@@ -344,7 +345,8 @@ stringify_arg (pfile, arg)
   /* Ignore the final \ of invalid string literals.  */
   if (backslash_count & 1)
     {
-      cpp_warning (pfile, "invalid string literal, ignoring final '\\'");
+      cpp_error (pfile, DL_WARNING,
+                "invalid string literal, ignoring final '\\'");
       dest--;
     }
 
@@ -435,10 +437,10 @@ paste_all_tokens (pfile, lhs)
 
          /* Mandatory warning for all apart from assembler.  */
          if (CPP_OPTION (pfile, lang) != CLK_ASM)
-           cpp_warning (pfile,
+           cpp_error (pfile, DL_WARNING,
         "pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
-                        cpp_token_as_text (pfile, lhs),
-                        cpp_token_as_text (pfile, rhs));
+                      cpp_token_as_text (pfile, lhs),
+                      cpp_token_as_text (pfile, rhs));
          break;
        }
     }
@@ -555,7 +557,8 @@ collect_args (pfile, 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, "unterminated argument list invoking macro \"%s\"",
+      cpp_error (pfile, DL_ERROR,
+                "unterminated argument list invoking macro \"%s\"",
                 NODE_NAME (node));
       error = true;
     }
@@ -572,11 +575,12 @@ collect_args (pfile, node)
       if (argc + 1 == macro->paramc && macro->variadic)
        {
          if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
-           cpp_pedwarn (pfile, "ISO C99 requires rest arguments to be used");
+           cpp_error (pfile, DL_PEDWARN,
+                      "ISO C99 requires rest arguments to be used");
        }
       else
        {
-         cpp_error (pfile,
+         cpp_error (pfile, DL_ERROR,
                     "macro \"%s\" requires %u arguments, but only %u given",
                     NODE_NAME (node), macro->paramc, argc);
          error = true;
@@ -587,7 +591,7 @@ collect_args (pfile, node)
       /* Empty argument to a macro taking no arguments is OK.  */
       if (argc != 1 || arg->count)
        {
-         cpp_error (pfile,
+         cpp_error (pfile, DL_ERROR,
                     "macro \"%s\" passed %u arguments, but takes just %u",
                     NODE_NAME (node), argc, macro->paramc);
          error = true;
@@ -628,12 +632,17 @@ funlike_invocation_p (pfile, node)
       return collect_args (pfile, node);
     }
 
-  /* Back up.  We may have skipped padding, in which case backing up
-     more than one token when expanding macros is in general too
-     difficult.  We re-insert it in its own context.  */
-  _cpp_backup_tokens (pfile, 1);
-  if (padding)
-    push_token_context (pfile, NULL, padding, 1);
+  /* CPP_EOF can be the end of macro arguments, or the end of the
+     file.  We mustn't back up over the latter.  Ugh.  */
+  if (token->type != CPP_EOF || token == &pfile->eof)
+    {
+      /* Back up.  We may have skipped padding, in which case backing
+        up more than one token when expanding macros is in general
+        too difficult.  We re-insert it in its own context.  */
+      _cpp_backup_tokens (pfile, 1);
+      if (padding)
+       push_token_context (pfile, NULL, padding, 1);
+    }
 
   return NULL;
 }
@@ -670,9 +679,9 @@ enter_macro_context (pfile, node)
          if (buff == NULL)
            {
              if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr)
-               cpp_warning (pfile,
+               cpp_error (pfile, DL_WARNING,
  "function-like macro \"%s\" must be used with arguments in traditional C",
-                            NODE_NAME (node));
+                          NODE_NAME (node));
 
              return 0;
            }
@@ -1015,6 +1024,9 @@ cpp_get_token (pfile)
          return &pfile->avoid_paste;
        }
 
+      if (pfile->state.in_directive && result->type == CPP_COMMENT)
+       continue;
+
       if (result->type != CPP_NAME)
        break;
 
@@ -1062,12 +1074,16 @@ cpp_sys_macro_p (pfile)
   return node && node->value.macro && node->value.macro->syshdr;
 }
 
-/* Read each token in, until EOF.  Directives are transparently
-   processed.  */
+/* Read each token in, until end of the current file.  Directives are
+   transparently processed.  */
 void
 cpp_scan_nooutput (pfile)
      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;
+
   while (cpp_get_token (pfile)->type != CPP_EOF)
     ;
 }
@@ -1166,7 +1182,8 @@ save_parameter (pfile, macro, node)
   /* Constraint 6.10.3.6 - duplicate parameter names.  */
   if (node->arg_index)
     {
-      cpp_error (pfile, "duplicate macro parameter \"%s\"", NODE_NAME (node));
+      cpp_error (pfile, DL_ERROR, "duplicate macro parameter \"%s\"",
+                NODE_NAME (node));
       return 1;
     }
 
@@ -1194,14 +1211,22 @@ parse_params (pfile, macro)
       switch (token->type)
        {
        default:
-         cpp_error (pfile, "\"%s\" may not appear in macro parameter list",
+         /* Allow/ignore comments in parameter lists if we are
+            preserving comments in macro expansions.  */
+         if (token->type == CPP_COMMENT
+             && ! CPP_OPTION (pfile, discard_comments_in_macro_exp))
+           continue;
+
+         cpp_error (pfile, DL_ERROR,
+                    "\"%s\" may not appear in macro parameter list",
                     cpp_token_as_text (pfile, token));
          return 0;
 
        case CPP_NAME:
          if (prev_ident)
            {
-             cpp_error (pfile, "macro parameters must be comma-separated");
+             cpp_error (pfile, DL_ERROR,
+                        "macro parameters must be comma-separated");
              return 0;
            }
          prev_ident = 1;
@@ -1218,7 +1243,7 @@ parse_params (pfile, macro)
        case CPP_COMMA:
          if (!prev_ident)
            {
-             cpp_error (pfile, "parameter name missing");
+             cpp_error (pfile, DL_ERROR, "parameter name missing");
              return 0;
            }
          prev_ident = 0;
@@ -1231,11 +1256,12 @@ parse_params (pfile, macro)
              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_pedwarn (pfile,
-                    "anonymous variadic macros were introduced in C99");
+               cpp_error (pfile, DL_PEDWARN,
+                          "anonymous variadic macros were introduced in C99");
            }
          else if (CPP_OPTION (pfile, pedantic))
-           cpp_pedwarn (pfile, "ISO C does not permit named variadic macros");
+           cpp_error (pfile, DL_PEDWARN,
+                      "ISO C does not permit named variadic macros");
 
          /* We're at the end, and just expect a closing parenthesis.  */
          token = _cpp_lex_token (pfile);
@@ -1244,7 +1270,7 @@ parse_params (pfile, macro)
          /* Fall through.  */
 
        case CPP_EOF:
-         cpp_error (pfile, "missing ')' in macro parameter list");
+         cpp_error (pfile, DL_ERROR, "missing ')' in macro parameter list");
          return 0;
        }
     }
@@ -1318,11 +1344,12 @@ _cpp_create_definition (pfile, node)
        goto cleanup2;
 
       /* Success.  Commit the parameter array.  */
-      BUFF_FRONT (pfile->a_buff) = (U_CHAR *) &macro->params[macro->paramc];
+      BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
       macro->fun_like = 1;
     }
   else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE))
-    cpp_pedwarn (pfile, "ISO C requires whitespace after the macro name");
+    cpp_error (pfile, DL_PEDWARN,
+              "ISO C requires whitespace after the macro name");
 
   saved_cur_token = pfile->cur_token;
 
@@ -1352,7 +1379,8 @@ _cpp_create_definition (pfile, node)
          else if (CPP_OPTION (pfile, lang) != CLK_ASM)
            {
              ok = 0;
-             cpp_error (pfile, "'#' is not followed by a macro parameter");
+             cpp_error (pfile, DL_ERROR,
+                        "'#' is not followed by a macro parameter");
              goto cleanup1;
            }
        }
@@ -1371,7 +1399,7 @@ _cpp_create_definition (pfile, node)
          if (macro->count == 0 || token->type == CPP_EOF)
            {
              ok = 0;
-             cpp_error (pfile,
+             cpp_error (pfile, DL_ERROR,
                         "'##' cannot appear at either end of a macro expansion");
              goto cleanup1;
            }
@@ -1392,7 +1420,7 @@ _cpp_create_definition (pfile, node)
     macro->expansion[0].flags &= ~PREV_WHITE;
 
   /* Commit the memory.  */
-  BUFF_FRONT (pfile->a_buff) = (U_CHAR *) &macro->expansion[macro->count];
+  BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->expansion[macro->count];
 
   /* Implement the macro-defined-to-itself optimisation.  */
   if (macro->count == 1 && !macro->fun_like
@@ -1407,11 +1435,11 @@ _cpp_create_definition (pfile, node)
     {
       if (warn_of_redefinition (node, macro))
        {
-         cpp_pedwarn_with_line (pfile, pfile->directive_line, 0,
-                                "\"%s\" redefined", NODE_NAME (node));
+         cpp_error_with_line (pfile, DL_PEDWARN, pfile->directive_line, 0,
+                              "\"%s\" redefined", NODE_NAME (node));
 
          if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
-           cpp_pedwarn_with_line (pfile, node->value.macro->line, 0,
+           cpp_error_with_line (pfile, DL_PEDWARN, node->value.macro->line, 0,
                            "this is the location of the previous definition");
        }
       _cpp_free_definition (node);
@@ -1450,7 +1478,7 @@ check_trad_stringification (pfile, macro, string)
      const cpp_string *string;
 {
   unsigned int i, len;
-  const U_CHAR *p, *q, *limit = string->text + string->len;
+  const uchar *p, *q, *limit = string->text + string->len;
   
   /* Loop over the string.  */
   for (p = string->text; p < limit; p = q)
@@ -1475,9 +1503,9 @@ check_trad_stringification (pfile, macro, string)
          if (NODE_LEN (node) == len
              && !memcmp (p, NODE_NAME (node), len))
            {
-             cpp_warning (pfile,
+             cpp_error (pfile, DL_WARNING,
           "macro argument \"%s\" would be stringified in traditional C",
-                          NODE_NAME (node));
+                        NODE_NAME (node));
              break;
            }
        }
@@ -1500,7 +1528,8 @@ cpp_macro_definition (pfile, node)
 
   if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN))
     {
-      cpp_ice (pfile, "invalid hash type %d in cpp_macro_definition", node->type);
+      cpp_error (pfile, DL_ICE,
+                "invalid hash type %d in cpp_macro_definition", node->type);
       return 0;
     }
 
@@ -1508,10 +1537,10 @@ cpp_macro_definition (pfile, node)
   len = NODE_LEN (node) + 1;                   /* ' ' */
   if (macro->fun_like)
     {
-      len += 3;                /* "()" plus possible final "." of named
-                          varargs (we have + 2 below).  */
+      len += 4;                /* "()" plus possible final ".." of named
+                          varargs (we have + 1 below).  */
       for (i = 0; i < macro->paramc; i++)
-       len += NODE_LEN (macro->params[i]) + 2; /* ", " */
+       len += NODE_LEN (macro->params[i]) + 1; /* "," */
     }
 
   for (i = 0; i < macro->count; i++)
@@ -1530,7 +1559,7 @@ cpp_macro_definition (pfile, node)
 
   if (len > pfile->macro_buffer_len)
     {
-      pfile->macro_buffer = (U_CHAR *) xrealloc (pfile->macro_buffer, len);
+      pfile->macro_buffer = (uchar *) xrealloc (pfile->macro_buffer, len);
       pfile->macro_buffer_len = len;
     }
 
@@ -1554,17 +1583,23 @@ cpp_macro_definition (pfile, node)
            }
 
          if (i + 1 < macro->paramc)
-           *buffer++ = ',', *buffer++ = ' ';
+            /* Don't emit a space after the comma here; we're trying
+               to emit a Dwarf-friendly definition, and the Dwarf spec
+               forbids spaces in the argument list.  */
+           *buffer++ = ',';
          else if (macro->variadic)
            *buffer++ = '.', *buffer++ = '.', *buffer++ = '.';
        }
       *buffer++ = ')';
     }
 
+  /* The Dwarf spec requires a space after the macro name, even if the
+     definition is the empty string.  */
+  *buffer++ = ' ';
+
   /* Expansion tokens.  */
   if (macro->count)
     {
-      *buffer++ = ' ';
       for (i = 0; i < macro->count; i++)
        {
          cpp_token *token = &macro->expansion[i];