OSDN Git Service

* semantics.c (perform_deferred_access_checks): Don't discard
[pf3gnuchains/gcc-fork.git] / gcc / cp / repo.c
index 50fc9f8..603b04e 100644 (file)
@@ -1,21 +1,22 @@
 /* Code to maintain a C++ template repository.
-   Copyright (C) 1995 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003
+   Free Software Foundation, Inc.
    Contributed by Jason Merrill (jason@cygnus.com)
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify
+GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
-GNU CC is distributed in the hope that it will be useful,
+GCC is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING.  If not, write to
+along with GCC; see the file COPYING.  If not, write to
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
@@ -25,36 +26,41 @@ Boston, MA 02111-1307, USA.  */
    The results of the automatic process should be easily reproducible with
    explicit code.  */
 
-#include <stdio.h>
 #include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "tree.h"
 #include "cp-tree.h"
 #include "input.h"
 #include "obstack.h"
-
-extern char * rindex ();
-extern char * getenv ();
-extern char * getpwd ();
-
-static tree pending_repo;
-static tree original_repo;
+#include "toplev.h"
+#include "diagnostic.h"
+
+static tree repo_get_id (tree);
+static char *extract_string (char **);
+static const char *get_base_filename (const char *);
+static void open_repo_file (const char *);
+static char *afgets (FILE *);
+static void reopen_repo_file_for_write (void);
+
+static GTY(()) tree pending_repo;
+static GTY(()) tree original_repo;
 static char *repo_name;
 static FILE *repo_file;
 
-extern int flag_use_repository;
-extern int errorcount, sorrycount;
-extern struct obstack temporary_obstack;
-extern struct obstack permanent_obstack;
+static const char *old_args, *old_dir, *old_main;
+
+static struct obstack temporary_obstack;
 
 #define IDENTIFIER_REPO_USED(NODE)   (TREE_LANG_FLAG_3 (NODE))
 #define IDENTIFIER_REPO_CHOSEN(NODE) (TREE_LANG_FLAG_4 (NODE))
 
+#if 0
 /* Record the flags used to compile this translation unit.  */
 
 void
-repo_compile_flags (argc, argv)
-     int argc;
-     char **argv;
+repo_compile_flags (int argc, char **argv)
 {
 }
 
@@ -63,33 +69,40 @@ repo_compile_flags (argc, argv)
    definition at link time.  */
 
 void
-repo_template_declared (t)
-     tree t;
+repo_template_declared (tree t)
 {}
 
 /* Note where the definition of a template lives so that instantiations can
    be generated later.  */
 
 void
-repo_template_defined (t)
-     tree t;
+repo_template_defined (tree t)
 {}
 
 /* Note where the definition of a class lives to that template
    instantiations can use it.  */
 
 void
-repo_class_defined (t)
-     tree t;
+repo_class_defined (tree t)
 {}
+#endif
 
-tree
-repo_get_id (t)
-     tree t;
+static tree
+repo_get_id (tree t)
 {
-  if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
+  if (TYPE_P (t))
     {
-      t = TYPE_BINFO_VTABLE (t);
+      tree vtable;
+
+      /* If we're not done setting up the class, we may not have set up
+        the vtable, so going ahead would give the wrong answer.
+         See g++.pt/instantiate4.C.  */
+      if (!COMPLETE_TYPE_P (t) || TYPE_BEING_DEFINED (t))
+       abort ();
+
+      vtable = get_vtbl_decl_for_binfo (TYPE_BINFO (t));
+
+      t = vtable;
       if (t == NULL_TREE)
        return t;
     }
@@ -97,11 +110,10 @@ repo_get_id (t)
 }
 
 /* Note that a template has been used.  If we can see the definition, offer
-   to emit it. */
+   to emit it.  */
 
 void
-repo_template_used (t)
-     tree t;
+repo_template_used (tree t)
 {
   tree id;
 
@@ -112,71 +124,75 @@ repo_template_used (t)
   if (id == NULL_TREE)
     return;
   
-  if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
+  if (TYPE_P (t))
     {
       if (IDENTIFIER_REPO_CHOSEN (id))
        mark_class_instantiated (t, 0);
     }
-  else if (TREE_CODE_CLASS (TREE_CODE (t)) == 'd')
+  else if (DECL_P (t))
     {
       if (IDENTIFIER_REPO_CHOSEN (id))
-       mark_function_instantiated (t, 0);
+       /* It doesn't make sense to instantiate a clone, so we
+          instantiate the cloned function instead.  Note that this
+          approach will not work correctly if collect2 assigns
+          different clones to different files -- but it shouldn't.  */
+       mark_decl_instantiated (DECL_CLONED_FUNCTION_P (t)
+                               ? DECL_CLONED_FUNCTION (t) : t, 
+                               0);
     }
   else
-    my_friendly_abort (1);
+    abort ();
 
   if (! IDENTIFIER_REPO_USED (id))
     {
       IDENTIFIER_REPO_USED (id) = 1;
-      pending_repo = perm_tree_cons (NULL_TREE, id, pending_repo);
+      pending_repo = tree_cons (NULL_TREE, id, pending_repo);
     }
 }
 
+#if 0
 /* Note that the vtable for a class has been used, and offer to emit it.  */
 
-void
-repo_vtable_used (t)
-     tree t;
+static void
+repo_vtable_used (tree t)
 {
   if (! flag_use_repository)
     return;
 
-  pending_repo = perm_tree_cons (NULL_TREE, t, pending_repo);
+  pending_repo = tree_cons (NULL_TREE, t, pending_repo);
 }
 
 /* Note that an inline with external linkage has been used, and offer to
    emit it.  */
 
 void
-repo_inline_used (fn)
-     tree fn;
+repo_inline_used (tree fn)
 {
   if (! flag_use_repository)
     return;
 
   /* Member functions of polymorphic classes go with their vtables.  */
-  if (DECL_FUNCTION_MEMBER_P (fn) && TYPE_VIRTUAL_P (DECL_CLASS_CONTEXT (fn)))
+  if (DECL_FUNCTION_MEMBER_P (fn) 
+      && TYPE_POLYMORPHIC_P (DECL_CONTEXT (fn)))
     {
-      repo_vtable_used (DECL_CLASS_CONTEXT (fn));
+      repo_vtable_used (DECL_CONTEXT (fn));
       return;
     }
 
-  pending_repo = perm_tree_cons (NULL_TREE, fn, pending_repo);
+  pending_repo = tree_cons (NULL_TREE, fn, pending_repo);
 }
 
 /* Note that a particular typeinfo node has been used, and offer to
    emit it.  */
 
 void
-repo_tinfo_used (ti)
-     tree ti;
+repo_tinfo_used (tree ti)
 {
 }
+#endif
 
 void
-repo_template_instantiated (t, extern_p)
-     tree t;
-     int extern_p;
+repo_template_instantiated (tree t, bool extern_p)
 {
   if (! extern_p)
     {
@@ -186,43 +202,53 @@ repo_template_instantiated (t, extern_p)
     }
 }
 
+/* Parse a reasonable subset of shell quoting syntax.  */
+
 static char *
-save_string (s, len)
-     char *s;
-     int len;
+extract_string (char **pp)
 {
-  return obstack_copy0 (&temporary_obstack, s, len);
+  char *p = *pp;
+  int backquote = 0;
+  int inside = 0;
+
+  for (;;)
+    {
+      char c = *p;
+      if (c == '\0')
+       break;
+      ++p;
+      if (backquote)
+       obstack_1grow (&temporary_obstack, c);
+      else if (! inside && c == ' ')
+       break;
+      else if (! inside && c == '\\')
+       backquote = 1;
+      else if (c == '\'')
+       inside = !inside;
+      else
+       obstack_1grow (&temporary_obstack, c);
+    }
+
+  obstack_1grow (&temporary_obstack, '\0');
+  *pp = p;
+  return obstack_finish (&temporary_obstack);
 }
 
-static char *
-get_base_filename (filename)
-     char *filename;
+const char *
+get_base_filename (const char *filename)
 {
   char *p = getenv ("COLLECT_GCC_OPTIONS");
-  char *output = 0;
+  char *output = NULL;
   int compiling = 0;
 
-  if (p)
-    while (*p)
-      {
-       char *q = p;
-       while (*q && *q != ' ') q++;
-       if (*p == '-' && p[1] == 'o')
-         {
-           p += 2;
-           if (p == q)
-             {
-               p++; q++;
-               if (*q)
-                 while (*q && *q != ' ') q++;
-             }
+  while (p && *p)
+    {
+      char *q = extract_string (&p);
 
-           output = save_string (p, q - p);
-         }
-       else if (*p == '-' && p[1] == 'c')
-         compiling = 1;
-       if (*q) q++;
-       p = q;
+      if (strcmp (q, "-o") == 0)
+       output = extract_string (&p);
+      else if (strcmp (q, "-c") == 0)
+       compiling = 1;
       }
 
   if (compiling && output)
@@ -235,39 +261,32 @@ get_base_filename (filename)
       return NULL;
     }
 
-  p = rindex (filename, '/');
-  if (p)
-    return p+1;
-  else
-    return filename;
+  return lbasename (filename);
 }        
 
 static void
-open_repo_file (filename)
-     char *filename;
+open_repo_file (const char *filename)
 {
-  register char *p, *q;
-  char *s = get_base_filename (filename);
+  register const char *p;
+  const char *s = get_base_filename (filename);
 
   if (s == NULL)
     return;
 
-  p = rindex (s, '/');
-  if (! p)
-    p = s;
-  p = rindex (p, '.');
+  p = lbasename (s);
+  p = strrchr (p, '.');
   if (! p)
     p = s + strlen (s);
 
-  obstack_grow (&permanent_obstack, s, p - s);
-  repo_name = obstack_copy0 (&permanent_obstack, ".rpo", 4);
+  repo_name = xmalloc (p - s + 5);
+  memcpy (repo_name, s, p - s);
+  memcpy (repo_name + (p - s), ".rpo", 5);
 
   repo_file = fopen (repo_name, "r");
 }
 
 static char *
-afgets (stream)
-     FILE *stream;
+afgets (FILE *stream)
 {
   int c;
   while ((c = getc (stream)) != EOF && c != '\n')
@@ -279,26 +298,32 @@ afgets (stream)
 }
 
 void
-init_repo (filename)
-     char *filename;
+init_repo (const char *filename)
 {
   char *buf;
 
   if (! flag_use_repository)
     return;
 
+  gcc_obstack_init (&temporary_obstack);
+
   open_repo_file (filename);
 
   if (repo_file == 0)
     return;
 
-  while (buf = afgets (repo_file))
+  while ((buf = afgets (repo_file)))
     {
       switch (buf[0])
        {
        case 'A':
+         old_args = ggc_strdup (buf + 2);
+         break;
        case 'D':
+         old_dir = ggc_strdup (buf + 2);
+         break;
        case 'M':
+         old_main = ggc_strdup (buf + 2);
          break;
        case 'C':
        case 'O':
@@ -314,7 +339,7 @@ init_repo (filename)
            else
              orig = NULL_TREE;
 
-           original_repo = perm_tree_cons (orig, id, original_repo);
+           original_repo = tree_cons (orig, id, original_repo);
          }
          break;
        default:
@@ -325,7 +350,7 @@ init_repo (filename)
 }
 
 static void
-reopen_repo_file_for_write ()
+reopen_repo_file_for_write (void)
 {
   if (repo_file)
     fclose (repo_file);
@@ -341,13 +366,13 @@ reopen_repo_file_for_write ()
 /* Emit any pending repos.  */
 
 void
-finish_repo ()
+finish_repo (void)
 {
   tree t;
-  char *p;
-  int repo_changed = 0;
+  bool repo_changed = false;
+  char *dir, *args;
 
-  if (! flag_use_repository)
+  if (!flag_use_repository)
     return;
 
   /* Do we have to write out a new info file?  */
@@ -357,10 +382,10 @@ finish_repo ()
   
   for (t = original_repo; t; t = TREE_CHAIN (t))
     {
-      if (! IDENTIFIER_REPO_USED (TREE_VALUE (t))
-         || (! TREE_PURPOSE (t) && IDENTIFIER_REPO_CHOSEN (TREE_VALUE (t))))
+      if (!IDENTIFIER_REPO_USED (TREE_VALUE (t))
+         || (!TREE_PURPOSE (t) && IDENTIFIER_REPO_CHOSEN (TREE_VALUE (t))))
        {
-         repo_changed = 1;
+         repo_changed = true;
          break;
        }
       IDENTIFIER_REPO_USED (TREE_VALUE (t)) = 0;
@@ -368,17 +393,27 @@ finish_repo ()
 
   /* Are there any templates that are newly used?  */
   
-  if (! repo_changed)
+  if (!repo_changed)
     for (t = pending_repo; t; t = TREE_CHAIN (t))
       {
        if (IDENTIFIER_REPO_USED (TREE_VALUE (t)))
          {
-           repo_changed = 1;
+           repo_changed = true;
            break;
          }
       }
 
-  if (! repo_changed || errorcount || sorrycount)
+  dir = getpwd ();
+  args = getenv ("COLLECT_GCC_OPTIONS");
+
+  if (!repo_changed && pending_repo)
+    if (strcmp (old_main, main_input_filename) != 0
+       || strcmp (old_dir, dir) != 0
+       || (args == NULL) != (old_args == NULL)
+       || (args && strcmp (old_args, args) != 0))
+      repo_changed = true;
+
+  if (!repo_changed || errorcount || sorrycount)
     goto out;
 
   reopen_repo_file_for_write ();
@@ -387,13 +422,9 @@ finish_repo ()
     goto out;
 
   fprintf (repo_file, "M %s\n", main_input_filename);
-
-  p = getpwd ();
-  fprintf (repo_file, "D %s\n", p);
-
-  p = getenv ("COLLECT_GCC_OPTIONS");
-  if (p != 0)
-    fprintf (repo_file, "A %s\n", p);
+  fprintf (repo_file, "D %s\n", dir);
+  if (args)
+    fprintf (repo_file, "A %s\n", args);
 
   for (t = pending_repo; t; t = TREE_CHAIN (t))
     {
@@ -407,3 +438,5 @@ finish_repo ()
   if (repo_file)
     fclose (repo_file);
 }
+
+#include "gt-cp-repo.h"