OSDN Git Service

Yet more Objective-C++...
[pf3gnuchains/gcc-fork.git] / gcc / gengtype.c
index 6cb89f0..519ff72 100644 (file)
@@ -1,5 +1,5 @@
 /* Process source files and output type information.
-   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -24,8 +24,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "tm.h"
 #include "gengtype.h"
 #include "gtyp-gen.h"
-#include "rtl.h"
-#undef abort
+#include "errors.h"
 
 /* Nonzero iff an error has occurred.  */
 static int hit_error = 0;
@@ -332,9 +331,25 @@ note_variable (const char *s, type_p t, options_p o, struct fileloc *pos)
   variables = n;
 }
 
-/* We really don't care how long a CONST_DOUBLE is.  */
+/* We don't care how long a CONST_DOUBLE is.  */
 #define CONST_DOUBLE_FORMAT "ww"
-const char * const rtx_format[NUM_RTX_CODE] = {
+/* We don't want to see codes that are only for generator files.  */
+#undef GENERATOR_FILE
+
+enum rtx_code {
+#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) ENUM ,
+#include "rtl.def"
+#undef DEF_RTL_EXPR
+  NUM_RTX_CODE
+};
+
+static const char * const rtx_name[NUM_RTX_CODE] = {
+#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   NAME ,
+#include "rtl.def"
+#undef DEF_RTL_EXPR
+};
+
+static const char * const rtx_format[NUM_RTX_CODE] = {
 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   FORMAT ,
 #include "rtl.def"
 #undef DEF_RTL_EXPR
@@ -342,6 +357,27 @@ const char * const rtx_format[NUM_RTX_CODE] = {
 
 static int rtx_next_new[NUM_RTX_CODE];
 
+/* We also need codes and names for insn notes (not register notes).
+   Note that we do *not* bias the note values here.  */
+enum insn_note {
+#define DEF_INSN_NOTE(NAME) NAME,
+#include "insn-notes.def"
+#undef DEF_INSN_NOTE
+
+  NOTE_INSN_MAX
+};
+
+/* We must allocate one more entry here, as we use NOTE_INSN_MAX as the
+   default field for line number notes.  */
+static const char *const note_insn_name[NOTE_INSN_MAX+1] = {
+#define DEF_INSN_NOTE(NAME) #NAME,
+#include "insn-notes.def"
+#undef DEF_INSN_NOTE
+};
+
+#undef CONST_DOUBLE_FORMAT
+#define GENERATOR_FILE
+
 /* Generate the contents of the rtx_next array.  This really doesn't belong
    in gengtype at all, but it's needed for adjust_field_rtx_def.  */
 
@@ -397,12 +433,6 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt))
   type_p rtx_tp, rtvec_tp, tree_tp, mem_attrs_tp, note_union_tp, scalar_tp;
   type_p bitmap_tp, basic_block_tp, reg_attrs_tp;
 
-  static const char * const rtx_name[NUM_RTX_CODE] = {
-#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   NAME ,
-#include "rtl.def"
-#undef DEF_RTL_EXPR
-  };
-
   if (t->kind != TYPE_UNION)
     {
       error_at_line (&lexer_line,
@@ -428,7 +458,7 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt))
     pair_p note_flds = NULL;
     int c;
 
-    for (c = NOTE_INSN_BIAS; c <= NOTE_INSN_MAX; c++)
+    for (c = 0; c <= NOTE_INSN_MAX; c++)
       {
        pair_p old_note_flds = note_flds;
 
@@ -438,7 +468,7 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt))
        note_flds->opt = XNEW (struct options);
        note_flds->opt->next = nodot;
        note_flds->opt->name = "tag";
-       note_flds->opt->info = xasprintf ("%d", c);
+       note_flds->opt->info = note_insn_name[c];
        note_flds->next = old_note_flds;
 
        switch (c)
@@ -1053,14 +1083,12 @@ open_base_files (void)
     /* The order of files here matters very much.  */
     static const char *const ifiles [] = {
       "config.h", "system.h", "coretypes.h", "tm.h", "varray.h", 
-      "hashtab.h", "splay-tree.h", "bitmap.h", "input.h", "tree.h", "rtl.h",
-      "function.h", "insn-config.h", "expr.h", "hard-reg-set.h",
-      "basic-block.h", "cselib.h", "insn-addr.h", "optabs.h",
-      "libfuncs.h", "debug.h", "ggc.h", "cgraph.h",
-      "tree-alias-type.h", "tree-flow.h", "reload.h",
-      "cpp-id-data.h",
-      "tree-chrec.h",
-      NULL
+      "hashtab.h", "splay-tree.h",  "obstack.h", "bitmap.h", "input.h",
+      "tree.h", "rtl.h", "function.h", "insn-config.h", "expr.h",
+      "hard-reg-set.h", "basic-block.h", "cselib.h", "insn-addr.h",
+      "optabs.h", "libfuncs.h", "debug.h", "ggc.h", "cgraph.h",
+      "tree-flow.h", "reload.h", "cpp-id-data.h", "tree-chrec.h",
+      "except.h", NULL
     };
     const char *const *ifp;
     outf_p gtype_desc_c;
@@ -1100,7 +1128,7 @@ get_file_basename (const char *f)
         {
           basename -= l2 + 1;
           if ((basename - f - 1) != srcdir_len)
-            abort (); /* Match is wrong - should be preceded by $srcdir.  */
+           fatal ("filename `%s' should be preceded by $srcdir", f);
           break;
         }
     }
@@ -1210,6 +1238,15 @@ get_output_file_with_visibility (const char *input_file)
     output_name = "gt-c-common.h", for_name = "c-common.c";
   else if (strcmp (basename, "c-tree.h") == 0)
     output_name = "gt-c-decl.h", for_name = "c-decl.c";
+  else if (strncmp (basename, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename[2])
+          && strcmp (basename + 3, "cp-tree.h") == 0)
+    output_name = "gt-cp-tree.h", for_name = "cp/tree.c";
+  else if (strncmp (basename, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename[2])
+          && strcmp (basename + 3, "decl.h") == 0)
+    output_name = "gt-cp-decl.h", for_name = "cp/decl.c";
+  else if (strncmp (basename, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename[2])
+          && strcmp (basename + 3, "name-lookup.h") == 0)
+    output_name = "gt-cp-name-lookup.h", for_name = "cp/name-lookup.c";
   else if (strncmp (basename, "objc", 4) == 0 && IS_DIR_SEPARATOR (basename[4])
           && strcmp (basename + 5, "objc-act.h") == 0)
     output_name = "gt-objc-objc-act.h", for_name = "objc/objc-act.c";
@@ -1414,7 +1451,7 @@ output_mangled_typename (outf_p of, type_p t)
       }
       break;
     case TYPE_ARRAY:
-      abort ();
+      gcc_unreachable ();
     }
 }
 
@@ -1580,7 +1617,7 @@ walk_type (type_p t, struct walk_type_data *d)
        if (maybe_undef_p
            && t->u.p->u.s.line.file == NULL)
          {
-           oprintf (d->of, "%*sif (%s) abort();\n", d->indent, "", d->val);
+           oprintf (d->of, "%*sgcc_assert (!%s);\n", d->indent, "", d->val);
            break;
          }
 
@@ -1653,7 +1690,7 @@ walk_type (type_p t, struct walk_type_data *d)
            oprintf (d->of, "%*sif (%s != NULL) {\n", d->indent, "", d->val);
            d->indent += 2;
            oprintf (d->of, "%*ssize_t i%d;\n", d->indent, "", loopcounter);
-           oprintf (d->of, "%*sfor (i%d = 0; i%d < (size_t)(", d->indent, "",
+           oprintf (d->of, "%*sfor (i%d = 0; i%d != (size_t)(", d->indent, "",
                     loopcounter, loopcounter);
            output_escaped_param (d, length, "length");
            oprintf (d->of, "); i%d++) {\n", loopcounter);
@@ -1689,7 +1726,7 @@ walk_type (type_p t, struct walk_type_data *d)
        oprintf (d->of, "%*s{\n", d->indent, "");
        d->indent += 2;
        oprintf (d->of, "%*ssize_t i%d;\n", d->indent, "", loopcounter);
-       oprintf (d->of, "%*sfor (i%d = 0; i%d < (size_t)(", d->indent, "",
+       oprintf (d->of, "%*sfor (i%d = 0; i%d != (size_t)(", d->indent, "",
                 loopcounter, loopcounter);
        if (length)
          output_escaped_param (d, length, "length");
@@ -1816,7 +1853,7 @@ walk_type (type_p t, struct walk_type_data *d)
            d->used_length = false;
 
            if (union_p && use_param_p && d->param == NULL)
-             oprintf (d->of, "%*sabort();\n", d->indent, "");
+             oprintf (d->of, "%*sgcc_unreachable ();\n", d->indent, "");
            else
              walk_type (f->type, d);
 
@@ -1872,7 +1909,7 @@ walk_type (type_p t, struct walk_type_data *d)
       break;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
 }
 
@@ -1900,6 +1937,21 @@ write_types_process_field (type_p f, const struct walk_type_data *d)
            }
          else
            oprintf (d->of, ", gt_%sa_%s", wtd->param_prefix, d->prev_val[0]);
+
+         if (f->u.p->kind == TYPE_PARAM_STRUCT
+             && f->u.p->u.s.line.file != NULL)
+           {
+             oprintf (d->of, ", gt_e_");
+             output_mangled_typename (d->of, f);
+           }
+         else if (UNION_OR_STRUCT_P (f)
+                  && f->u.p->u.s.line.file != NULL)
+           {
+             oprintf (d->of, ", gt_ggc_e_");
+             output_mangled_typename (d->of, f);
+           }
+         else
+           oprintf (d->of, ", gt_types_enum_last");
        }
       oprintf (d->of, ");\n");
       if (d->reorder_fn && wtd->reorder_note_routine)
@@ -1929,8 +1981,27 @@ write_types_process_field (type_p f, const struct walk_type_data *d)
       break;
 
     default:
-      abort ();
+      gcc_unreachable ();
+    }
+}
+
+/* A subroutine of write_func_for_structure.  Write the enum tag for S.  */
+
+static void
+output_type_enum (outf_p of, type_p s)
+{
+  if (s->kind == TYPE_PARAM_STRUCT && s->u.s.line.file != NULL)
+    {
+      oprintf (of, ", gt_e_");
+      output_mangled_typename (of, s);
+    }
+  else if (UNION_OR_STRUCT_P (s) && s->u.s.line.file != NULL)
+    {
+      oprintf (of, ", gt_ggc_e_");
+      output_mangled_typename (of, s);
     }
+  else
+    oprintf (of, ", gt_types_enum_last");
 }
 
 /* For S, a structure that's part of ORIG_S, and using parameters
@@ -2007,6 +2078,7 @@ write_func_for_structure (type_p orig_s, type_p s, type_p *param,
        {
          oprintf (d.of, ", x, gt_%s_", wtd->param_prefix);
          output_mangled_typename (d.of, orig_s);
+         output_type_enum (d.of, orig_s);
        }
       oprintf (d.of, "))\n");
     }
@@ -2017,6 +2089,7 @@ write_func_for_structure (type_p orig_s, type_p s, type_p *param,
        {
          oprintf (d.of, ", xlimit, gt_%s_", wtd->param_prefix);
          output_mangled_typename (d.of, orig_s);
+         output_type_enum (d.of, orig_s);
        }
       oprintf (d.of, "))\n");
       oprintf (d.of, "   xlimit = (");
@@ -2042,6 +2115,7 @@ write_func_for_structure (type_p orig_s, type_p s, type_p *param,
            {
              oprintf (d.of, ", xprev, gt_%s_", wtd->param_prefix);
              output_mangled_typename (d.of, orig_s);
+             output_type_enum (d.of, orig_s);
            }
          oprintf (d.of, ");\n");
          oprintf (d.of, "      }\n");
@@ -2199,7 +2273,7 @@ write_types_local_process_field (type_p f, const struct walk_type_data *d)
       break;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
 }
 
@@ -2978,7 +3052,7 @@ main(int ARG_UNUSED (argc), char ** ARG_UNUSED (argv))
         parse_file (all_files[i]);
 #ifndef USE_MAPPED_LOCATION
       /* temporary kludge - gengtype doesn't handle conditionals.
-        Manually add source_locus *after* we've processed input.h. */
+        Manually add source_locus *after* we've processed input.h.  */
       if (i == 0)
        do_typedef ("source_locus", create_pointer (resolve_typedef ("location_t", &pos)), &pos);
 #endif