OSDN Git Service

* internal.h: Update references to Cpp lib filenames.
[pf3gnuchains/gcc-fork.git] / libcpp / macro.c
index cfc42b4..e3824cb 100644 (file)
@@ -109,10 +109,8 @@ static const char * const monthnames[] =
   "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)
 {
@@ -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
-   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)
@@ -263,6 +261,13 @@ builtin_macro (cpp_reader *pfile, cpp_hashnode *node)
        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;
     }
 
@@ -919,7 +924,7 @@ next_context (cpp_reader *pfile)
 
   if (result == 0)
     {
-      result = xnew (cpp_context);
+      result = XNEW (cpp_context);
       result->prev = pfile->context;
       result->next = 0;
       pfile->context->next = result;
@@ -1408,8 +1413,16 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
       if (!ok)
        return false;
 
-      /* Success.  Commit the parameter array.  */
-      BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
+      /* 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;
+       }
+      else
+       BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
       macro->fun_like = 1;
     }
   else if (ctoken->type != CPP_EOF && !(ctoken->flags & PREV_WHITE))
@@ -1472,6 +1485,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
     }
 
   macro->exp.tokens = (cpp_token *) BUFF_FRONT (pfile->a_buff);
+  macro->traditional = 0;
 
   /* Don't count the CPP_EOF.  */
   macro->count--;
@@ -1480,8 +1494,16 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
   if (macro->count)
     macro->exp.tokens[0].flags &= ~PREV_WHITE;
 
-  /* Commit the memory.  */
-  BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->exp.tokens[macro->count];
+  /* Commit or allocate the memory.  */
+  if (pfile->hash_table->alloc_subobject)
+    {
+      cpp_token *tokns = pfile->hash_table->alloc_subobject (sizeof (cpp_token)
+                                                            * macro->count);
+      memcpy (tokns, macro->exp.tokens, sizeof (cpp_token) * macro->count);
+      macro->exp.tokens = tokns;
+    }
+  else
+    BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->exp.tokens[macro->count];
 
   return true;
 }
@@ -1494,7 +1516,10 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
   unsigned int i;
   bool ok;
 
-  macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
+  if (pfile->hash_table->alloc_subobject)
+    macro = pfile->hash_table->alloc_subobject (sizeof (cpp_macro));
+  else
+    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
   macro->line = pfile->directive_line;
   macro->params = 0;
   macro->paramc = 0;
@@ -1515,7 +1540,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
-        cpplib.c.
+        directives.c.
 
         Longer term we should lex the whole line before coming here,
         and just copy the expansion.  */