OSDN Git Service

ch:
[pf3gnuchains/gcc-fork.git] / gcc / cpplex.c
index 0c31560..426e82d 100644 (file)
@@ -52,6 +52,7 @@ static const cpp_token eof_token = {0, 0, CPP_EOF, 0 UNION_INIT_ZERO};
 #define CONTEXT_PASTER (1 << 1) /* An argument context on RHS of ##.  */
 #define CONTEXT_RAW    (1 << 2) /* If argument tokens already expanded.  */
 #define CONTEXT_ARG    (1 << 3) /* If an argument context.  */
+#define CONTEXT_VARARGS        (1 << 4) /* If a varargs argument context.  */
 
 typedef struct cpp_context cpp_context;
 struct cpp_context
@@ -161,10 +162,6 @@ TOKEN_LEN (token)
 
 #define IS_ARG_CONTEXT(c) ((c)->flags & CONTEXT_ARG)
 #define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context)
-#define ON_REST_ARG(c) \
- (((c)->u.list->flags & VAR_ARGS) \
-  && (c)->u.list->tokens[(c)->posn - 1].val.aux \
-      == (unsigned int) ((c)->u.list->paramc - 1))
 
 #define ASSIGN_FLAGS_AND_POS(d, s) \
   do {(d)->flags = (s)->flags & (PREV_WHITE | BOL | PASTE_LEFT); \
@@ -572,7 +569,7 @@ skip_block_comment (pfile)
      cpp_reader *pfile;
 {
   cpp_buffer *buffer = pfile->buffer;
-  cppchar_t c = EOF, prevc;
+  cppchar_t c = EOF, prevc = EOF;
 
   pfile->state.lexing_comment = 1;
   while (buffer->cur != buffer->rlimit)
@@ -1209,9 +1206,8 @@ lex_token (pfile, result)
             irrespective of conformance mode, because lots of
             broken systems do that and trying to clean it up in
             fixincludes is a nightmare.  */
-         if (!CPP_IN_SYSTEM_HEADER (pfile)
-             && CPP_OPTION (pfile, c89) && CPP_PEDANTIC (pfile)
-             && !buffer->warned_cplusplus_comments)
+         if (CPP_OPTION (pfile, c89) && CPP_PEDANTIC (pfile)
+             && ! buffer->warned_cplusplus_comments)
            {
              cpp_pedwarn (pfile,
                           "C++ style comments are not allowed in ISO C89");
@@ -1220,6 +1216,7 @@ lex_token (pfile, result)
              buffer->warned_cplusplus_comments = 1;
            }
 
+         /* Skip_line_comment updates buffer->read_ahead.  */
          if (skip_line_comment (pfile))
            cpp_warning_with_line (pfile, result->line, result->col,
                                   "multi-line comment");
@@ -1836,6 +1833,7 @@ is_macro_disabled (pfile, expansion, token)
       pfile->no_expand_level = context - pfile->contexts;
       next = _cpp_get_token (pfile);
       restore_macro_expansion (pfile, prev_nme);
+
       if (next->type != CPP_OPEN_PAREN)
        {
          _cpp_push_token (pfile, next);
@@ -1990,9 +1988,7 @@ parse_args (pfile, hp, args)
        {
          /* Duplicate the placemarker.  Then we can set its flags and
              position and safely be using more than one.  */
-         cpp_token *pm = duplicate_token (pfile, &placemarker_token);
-         pm->flags = VOID_REST;
-         save_token (args, pm);
+         save_token (args, duplicate_token (pfile, &placemarker_token));
          args->ends[argc] = total + 1;
 
          if (CPP_OPTION (pfile, c99) && CPP_PEDANTIC (pfile))
@@ -2002,7 +1998,8 @@ parse_args (pfile, hp, args)
        }
       else
        {
-         cpp_error (pfile, "not enough arguments for macro \"%s\"", hp->name);
+         cpp_error (pfile, "%u arguments is not enough for macro \"%s\"",
+                    argc, hp->name);
          return 1;
        }
     }
@@ -2010,7 +2007,8 @@ parse_args (pfile, hp, args)
   else if (argc > macro->paramc
           && !(macro->paramc == 0 && argc == 1 && empty_argument (args, 0)))
     {
-      cpp_error (pfile, "too many arguments for macro \"%s\"", hp->name);
+      cpp_error (pfile, "%u arguments is too many for macro \"%s\"",
+                argc, hp->name);
       return 1;
     }
 
@@ -2302,6 +2300,7 @@ maybe_paste_with_next (pfile, token)
       pfile->paste_level = pfile->cur_context;
       second = _cpp_get_token (pfile);
       pfile->paste_level = 0;
+      context = CURRENT_CONTEXT (pfile);
 
       /* Ignore placemarker argument tokens (cannot be from an empty
         macro since macros are not expanded).  */
@@ -2313,7 +2312,7 @@ maybe_paste_with_next (pfile, token)
             a varargs parameter: the comma disappears if b was given
             no actual arguments (not merely if b is an empty
             argument).  */
-         if (token->type == CPP_COMMA && second->flags & VOID_REST)
+         if (token->type == CPP_COMMA && (context->flags & CONTEXT_VARARGS))
            pasted = duplicate_token (pfile, second);
          else
            pasted = duplicate_token (pfile, token);
@@ -2332,8 +2331,7 @@ maybe_paste_with_next (pfile, token)
                     the author probably intended the ## to trigger
                     the special extended semantics (see above).  */
                  if (token->type == CPP_COMMA
-                     && IS_ARG_CONTEXT (CURRENT_CONTEXT (pfile))
-                     && ON_REST_ARG (CURRENT_CONTEXT (pfile) - 1))
+                     && (context->flags & CONTEXT_VARARGS))
                    /* no warning */;
                  else
                    cpp_warning (pfile,
@@ -2397,7 +2395,6 @@ maybe_paste_with_next (pfile, token)
       /* See if there is another token to be pasted onto the one we just
         constructed.  */
       token = pasted;
-      context = CURRENT_CONTEXT (pfile);
       /* and loop */
     }
   return token;
@@ -2578,6 +2575,9 @@ push_arg_context (pfile, token)
   context->posn = 0;
   context->level = args->level;
   context->flags = CONTEXT_ARG | CONTEXT_RAW;
+  if ((context[-1].u.list->flags & VAR_ARGS)
+      && token->val.aux + 1 == (unsigned) context[-1].u.list->paramc)
+    context->flags |= CONTEXT_VARARGS;
   context->pushed_token = 0;
 
   /* Set the flags of the first token.  There is one.  */