OSDN Git Service

include/
[pf3gnuchains/gcc-fork.git] / libcpp / macro.c
index dc58b31..5e59669 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,
 /* Part of CPP library.  (Macro and #define handling.)
    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005 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
    Written by Per Bothner, 1994.
    Based on CCCP program by Paul Rubin, June 1986
    Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -109,10 +109,8 @@ static const char * const monthnames[] =
   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
-/* Handle builtin macros like __FILE__, and push the resulting token
-   on the context stack.  Also handles _Pragma, for which no new token
-   is created.  Returns 1 if it generates a new token context, 0 to
-   return the token to the caller.  */
+/* Helper function for builtin_macro.  Returns the text generated by
+   a builtin macro. */
 const uchar *
 _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
 {
 const uchar *
 _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
 {
@@ -245,8 +243,8 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
 }
 
 /* Convert builtin macros like __FILE__ to a token and push it on the
 }
 
 /* Convert builtin macros like __FILE__ to a token and push it on the
-   context stack.  Also handles _Pragma, for which no new token is
-   created.  Returns 1 if it generates a new token context, 0 to
+   context stack.  Also handles _Pragma, for which a new token may not
+   be created.  Returns 1 if it generates a new token context, 0 to
    return the token to the caller.  */
 static int
 builtin_macro (cpp_reader *pfile, cpp_hashnode *node)
    return the token to the caller.  */
 static int
 builtin_macro (cpp_reader *pfile, cpp_hashnode *node)
@@ -263,6 +261,13 @@ builtin_macro (cpp_reader *pfile, cpp_hashnode *node)
        return 0;
 
       _cpp_do__Pragma (pfile);
        return 0;
 
       _cpp_do__Pragma (pfile);
+      if (pfile->directive_result.type == CPP_PRAGMA) 
+       {
+         cpp_token *tok = _cpp_temp_token (pfile);
+         *tok = pfile->directive_result;
+         push_token_context (pfile, NULL, tok, 1);
+       }
+
       return 1;
     }
 
       return 1;
     }
 
@@ -905,7 +910,10 @@ padding_token (cpp_reader *pfile, const cpp_token *source)
   cpp_token *result = _cpp_temp_token (pfile);
 
   result->type = CPP_PADDING;
   cpp_token *result = _cpp_temp_token (pfile);
 
   result->type = CPP_PADDING;
-  result->val.source = source;
+
+  /* Data in GCed data structures cannot be made const so far, so we
+     need a cast here.  */
+  result->val.source = (cpp_token *) source;
   result->flags = 0;
   return result;
 }
   result->flags = 0;
   return result;
 }
@@ -919,7 +927,7 @@ next_context (cpp_reader *pfile)
 
   if (result == 0)
     {
 
   if (result == 0)
     {
-      result = xnew (cpp_context);
+      result = XNEW (cpp_context);
       result->prev = pfile->context;
       result->next = 0;
       pfile->context->next = result;
       result->prev = pfile->context;
       result->next = 0;
       pfile->context->next = result;
@@ -1411,10 +1419,11 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
       /* Success.  Commit or allocate the parameter array.  */
       if (pfile->hash_table->alloc_subobject)
        {
       /* Success.  Commit or allocate the parameter array.  */
       if (pfile->hash_table->alloc_subobject)
        {
-         cpp_token *tokns = pfile->hash_table->alloc_subobject
-           (sizeof (cpp_token) * macro->paramc);
-         memcpy (tokns, macro->params, sizeof (cpp_token) * macro->paramc);
-         macro->params = tokns;
+         cpp_hashnode **params = pfile->hash_table->alloc_subobject
+           (sizeof (cpp_hashnode *) * macro->paramc);
+         memcpy (params, macro->params,
+                 sizeof (cpp_hashnode *) * macro->paramc);
+         macro->params = params;
        }
       else
        BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
        }
       else
        BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
@@ -1535,7 +1544,7 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
 
       /* Restore lexer position because of games lex_expansion_token()
         plays lexing the macro.  We set the type for SEEN_EOL() in
 
       /* Restore lexer position because of games lex_expansion_token()
         plays lexing the macro.  We set the type for SEEN_EOL() in
-        cpplib.c.
+        directives.c.
 
         Longer term we should lex the whole line before coming here,
         and just copy the expansion.  */
 
         Longer term we should lex the whole line before coming here,
         and just copy the expansion.  */
@@ -1657,6 +1666,7 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node)
        len += NODE_LEN (macro->params[i]) + 1; /* "," */
     }
 
        len += NODE_LEN (macro->params[i]) + 1; /* "," */
     }
 
+  /* This should match below where we fill in the buffer.  */
   if (CPP_OPTION (pfile, traditional))
     len += _cpp_replacement_text_len (macro);
   else
   if (CPP_OPTION (pfile, traditional))
     len += _cpp_replacement_text_len (macro);
   else
@@ -1668,11 +1678,14 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node)
          if (token->type == CPP_MACRO_ARG)
            len += NODE_LEN (macro->params[token->val.arg_no - 1]);
          else
          if (token->type == CPP_MACRO_ARG)
            len += NODE_LEN (macro->params[token->val.arg_no - 1]);
          else
-           len += cpp_token_len (token) + 1; /* Includes room for ' '.  */
+           len += cpp_token_len (token);
+
          if (token->flags & STRINGIFY_ARG)
            len++;                      /* "#" */
          if (token->flags & PASTE_LEFT)
            len += 3;           /* " ##" */
          if (token->flags & STRINGIFY_ARG)
            len++;                      /* "#" */
          if (token->flags & PASTE_LEFT)
            len += 3;           /* " ##" */
+         if (token->flags & PREV_WHITE)
+           len++;              /* " " */
        }
     }
 
        }
     }
 
@@ -1732,10 +1745,10 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node)
 
          if (token->type == CPP_MACRO_ARG)
            {
 
          if (token->type == CPP_MACRO_ARG)
            {
-             len = NODE_LEN (macro->params[token->val.arg_no - 1]);
              memcpy (buffer,
              memcpy (buffer,
-                     NODE_NAME (macro->params[token->val.arg_no - 1]), len);
-             buffer += len;
+                     NODE_NAME (macro->params[token->val.arg_no - 1]),
+                     NODE_LEN (macro->params[token->val.arg_no - 1]));
+             buffer += NODE_LEN (macro->params[token->val.arg_no - 1]);
            }
          else
            buffer = cpp_spell_token (pfile, token, buffer);
            }
          else
            buffer = cpp_spell_token (pfile, token, buffer);