diff libcpp/pch.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
line wrap: on
line diff
--- a/libcpp/pch.c	Tue May 25 18:58:51 2010 +0900
+++ b/libcpp/pch.c	Tue Mar 22 17:18:12 2011 +0900
@@ -1,5 +1,5 @@
 /* Part of CPP library.  (Precompiled header reading/writing.)
-   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify it
@@ -58,7 +58,9 @@
 	return 1;
 
     case NT_MACRO:
-      if ((hn->flags & NODE_BUILTIN))
+      if ((hn->flags & NODE_BUILTIN)
+	  && (!pfile->cb.user_builtin_macro
+	      || !pfile->cb.user_builtin_macro (pfile, hn)))
 	return 1;
 
       {
@@ -397,8 +399,6 @@
   size_t i;
   struct def_pragma_macro *p;
   size_t nlen;
-  cpp_hashnode *h = NULL;
-  cpp_macro *m;
   uchar *defn;
   size_t defnlen;
 
@@ -411,49 +411,35 @@
       if (fread (&nlen, sizeof (nlen), 1, f) != 1)
 	return 0;
       p = XNEW (struct def_pragma_macro);
+      memset (p, 0, sizeof (struct def_pragma_macro));
       p->name = XNEWVAR (char, nlen + 1);
       p->name[nlen] = 0;
       if (fread (p->name, nlen, 1, f) != 1)
 	return 0;
-      /* Save old state.  */
-      m = cpp_push_definition (r, p->name);
       if (fread (&defnlen, sizeof (defnlen), 1, f) != 1)
 	return 0;
-      defn = XNEWVAR (uchar, defnlen + 2);
-      defn[defnlen] = '\n';
-      defn[defnlen + 1] = 0;
+      if (defnlen == 0)
+        p->is_undef = 1;
+      else
+        {
+	  defn = XNEWVEC (uchar, defnlen + 1);
+	  defn[defnlen] = 0;
 
-      if (fread (defn, defnlen, 1, f) != 1)
-	return 0;
-      cpp_pop_definition (r, p->name, NULL);
-      {
-	size_t namelen;
-	uchar *dn;
-
-	namelen = ustrcspn (defn, "( \n");
-	h = cpp_lookup (r, defn, namelen);
-	dn = defn + namelen;
+	  if (fread (defn, defnlen, 1, f) != 1)
+	    return 0;
 
-	h->type = NT_VOID;
-	h->flags &= ~(NODE_POISONED|NODE_BUILTIN|NODE_DISABLED|NODE_USED);
-	if (cpp_push_buffer (r, dn, ustrchr (dn, '\n') - dn, true)
-	    != NULL)
-	  {
-	    _cpp_clean_line (r);
-	    if (!_cpp_create_definition (r, h))
-	      abort ();
-	    _cpp_pop_buffer (r);
-	  }
-	else
-	  abort ();
-      }
-      p->value = cpp_push_definition (r, p->name);
+	  p->definition = defn;
+	  if (fread (&(p->line), sizeof (source_location), 1, f) != 1)
+	    return 0;
+	  defnlen = 0;
+	  if (fread (&defnlen, sizeof (defnlen), 1, f) != 1)
+	    return 0;
+	  p->syshdr = ((defnlen & 1) != 0 ? 1 : 0);
+	  p->used =  ((defnlen & 2) != 0 ? 1 : 0);
+	}
 
-      free (defn);
       p->next = r->pushed_macros;
       r->pushed_macros = p;
-      /* Restore current state.  */
-      cpp_pop_definition (r, p->name, m);
     }
   return 1;
 }
@@ -464,10 +450,7 @@
   size_t count_saved = 0;
   size_t i;
   struct def_pragma_macro *p,**pp;
-  cpp_hashnode *node;
-  cpp_macro *m;
   size_t defnlen;
-  const uchar *defn;
 
   /* Get count. */
   p = r->pushed_macros;
@@ -494,22 +477,30 @@
     }
   for (i = 0; i < count_saved; i++)
     {
-      /* Save old state.  */
-      m = cpp_push_definition (r, pp[i]->name);
-      /* Set temporary macro name to saved state.  */
-      cpp_pop_definition (r, pp[i]->name, pp[i]->value);
-      node = _cpp_lex_identifier (r, pp[i]->name);
       defnlen = strlen (pp[i]->name);
       if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1
 	  || fwrite (pp[i]->name, defnlen, 1, f) != 1)
 	return 0;
-      defn = cpp_macro_definition (r, node);
-      defnlen = ustrlen (defn);
-      if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1
-	  || fwrite (defn, defnlen, 1, f) != 1)
-	return 0;
-      /* Restore current state.  */
-      cpp_pop_definition (r, pp[i]->name, m);
+      if (pp[i]->is_undef)
+	{
+	  defnlen = 0;
+	  if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1)
+	    return 0;
+	}
+      else
+        {
+	  defnlen = ustrlen (pp[i]->definition);
+	  if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1
+	      || fwrite (pp[i]->definition, defnlen, 1, f) != 1)
+	    return 0;
+	  if (fwrite (&(pp[i]->line), sizeof (source_location), 1, f) != 1)
+	    return 0;
+	  defnlen = 0;
+	  defnlen |= (pp[i]->syshdr != 0 ? 1 : 0);
+	  defnlen |= (pp[i]->used != 0 ? 2 : 0);
+	  if (fwrite (&defnlen, sizeof (defnlen), 1, f) != 1)
+	    return 0;
+	}
     }
   return 1;
 }
@@ -759,6 +750,12 @@
 save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
 {
   struct save_macro_data *data = (struct save_macro_data *)data_p;
+
+  if ((h->flags & NODE_BUILTIN)
+      && h->type == NT_MACRO
+      && r->cb.user_builtin_macro)
+    r->cb.user_builtin_macro (r, h);
+
   if (h->type != NT_VOID
       && (h->flags & NODE_BUILTIN) == 0)
     {