OSDN Git Service

PR c/13519
[pf3gnuchains/gcc-fork.git] / gcc / gengtype.c
index 101b378..804ef70 100644 (file)
@@ -1,5 +1,5 @@
 /* Process source files and output type information.
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -308,6 +308,16 @@ create_array (type_p t, const char *len)
   return v;
 }
 
+/* Return an options structure with name NAME and info INFO.  */
+options_p
+create_option (const char *name, void *info)
+{
+  options_p o = xmalloc (sizeof (*o));
+  o->name = name;
+  o->info = info;
+  return o;
+}
+
 /* Add a variable named S of type T with options O defined at POS,
    to `variables'.  */
 
@@ -371,7 +381,7 @@ write_rtx_next (void)
       oprintf (f, "  0,\n");
     else
       oprintf (f,
-              "  offsetof (struct rtx_def, fld) + %d * sizeof (rtunion),\n",
+              "  RTX_HDR_SIZE + %d * sizeof (rtunion),\n",
               rtx_next_new[i]);
   oprintf (f, "};\n");
 }
@@ -395,10 +405,10 @@ adjust_field_rtx_def (type_p t, options_p opt ATTRIBUTE_UNUSED)
 #undef DEF_RTL_EXPR
   };
 
-  if (t->kind != TYPE_ARRAY)
+  if (t->kind != TYPE_UNION)
     {
       error_at_line (&lexer_line,
-                    "special `rtx_def' must be applied to an array");
+                    "special `rtx_def' must be applied to a union");
       return &string_type;
     }
 
@@ -450,6 +460,7 @@ adjust_field_rtx_def (type_p t, options_p opt ATTRIBUTE_UNUSED)
            break;
 
          case NOTE_INSN_EXPECTED_VALUE:
+         case NOTE_INSN_VAR_LOCATION:
            note_flds->name = "rtx";
            note_flds->type = rtx_tp;
            break;
@@ -578,7 +589,7 @@ adjust_field_rtx_def (type_p t, options_p opt ATTRIBUTE_UNUSED)
          subfields = xmalloc (sizeof (*subfields));
          subfields->next = old_subf;
          subfields->type = t;
-         subfields->name = xasprintf ("[%lu].%s", (unsigned long)aindex,
+         subfields->name = xasprintf (".fld[%lu].%s", (unsigned long)aindex,
                                       subname);
          subfields->line.file = __FILE__;
          subfields->line.line = __LINE__;
@@ -643,7 +654,6 @@ adjust_field_tree_exp (type_p t, options_p opt ATTRIBUTE_UNUSED)
     { "GOTO_SUBROUTINE_EXPR", 0, 2 },
     { "RTL_EXPR", 0, 2 },
     { "WITH_CLEANUP_EXPR", 2, 1 },
-    { "METHOD_CALL_EXPR", 3, 1 }
   };
 
   if (t->kind != TYPE_ARRAY)
@@ -981,7 +991,7 @@ static outf_p output_files;
 
 /* The output header file that is included into pretty much every
    source file.  */
-outf_p header_file;
+static outf_p header_file;
 
 /* Number of files specified in gtfiles.  */
 #define NUM_GT_FILES (ARRAY_SIZE (all_files) - 1)
@@ -1085,11 +1095,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",
+      "config.h", "system.h", "coretypes.h", "tm.h", "varray.h", 
       "hashtab.h", "splay-tree.h", "bitmap.h", "tree.h", "rtl.h",
       "function.h", "insn-config.h", "expr.h", "hard-reg-set.h",
-      "basic-block.h", "cselib.h", "insn-addr.h", "ssa.h", "optabs.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",
       NULL
     };
     const char *const *ifp;
@@ -1481,12 +1492,13 @@ output_escaped_param (struct walk_type_data *d, const char *param,
 /* Call D->PROCESS_FIELD for every field (or subfield) of D->VAL,
    which is of type T.  Write code to D->OF to constrain execution (at
    the point that D->PROCESS_FIELD is called) to the appropriate
-   cases.  D->PREV_VAL lists the objects containing the current object,
-   D->OPT is a list of options to apply, D->INDENT is the current
-   indentation level, D->LINE is used to print error messages,
-   D->BITMAP indicates which languages to print the structure for, and
-   D->PARAM is the current parameter (from an enclosing param_is
-   option).  */
+   cases.  Call D->PROCESS_FIELD on subobjects before calling it on
+   pointers to those objects.  D->PREV_VAL lists the objects
+   containing the current object, D->OPT is a list of options to
+   apply, D->INDENT is the current indentation level, D->LINE is used
+   to print error messages, D->BITMAP indicates which languages to
+   print the structure for, and D->PARAM is the current parameter
+   (from an enclosing param_is option).  */
 
 static void
 walk_type (type_p t, struct walk_type_data *d)
@@ -1497,6 +1509,7 @@ walk_type (type_p t, struct walk_type_data *d)
   int use_param_num = -1;
   int use_params_p = 0;
   options_p oo;
+  const struct nested_ptr_data *nested_ptr_d = NULL;
 
   d->needs_cast_p = 0;
   for (oo = d->opt; oo; oo = oo->next)
@@ -1511,6 +1524,8 @@ walk_type (type_p t, struct walk_type_data *d)
       use_params_p = 1;
     else if (strcmp (oo->name, "desc") == 0)
       desc = (const char *)oo->info;
+    else if (strcmp (oo->name, "nested_ptr") == 0)
+      nested_ptr_d = (const struct nested_ptr_data *)oo->info ;
     else if (strcmp (oo->name, "dot") == 0)
       ;
     else if (strcmp (oo->name, "tag") == 0)
@@ -1611,7 +1626,48 @@ walk_type (type_p t, struct walk_type_data *d)
                break;
              }
 
-           d->process_field (t->u.p, d);
+           if (nested_ptr_d)
+             {
+               const char *oldprevval2 = d->prev_val[2];
+
+               if (! UNION_OR_STRUCT_P (nested_ptr_d->type))
+                 {
+                   error_at_line (d->line,
+                                  "field `%s' has invalid "
+                                  "option `nested_ptr'\n",
+                                  d->val);
+                   return;
+                 }
+
+               d->prev_val[2] = d->val;
+               oprintf (d->of, "%*s{\n", d->indent, "");
+               d->indent += 2;
+               d->val = xasprintf ("x%d", d->counter++);
+               oprintf (d->of, "%*s%s %s * %s =\n", d->indent, "",
+                        (nested_ptr_d->type->kind == TYPE_UNION 
+                         ? "union" : "struct"), 
+                        nested_ptr_d->type->u.s.tag, d->val);
+               oprintf (d->of, "%*s", d->indent + 2, "");
+               output_escaped_param (d, nested_ptr_d->convert_from,
+                                     "nested_ptr");
+               oprintf (d->of, ";\n");
+
+               d->process_field (nested_ptr_d->type, d);
+
+               oprintf (d->of, "%*s%s = ", d->indent, "",
+                        d->prev_val[2]);
+               d->prev_val[2] = d->val;
+               output_escaped_param (d, nested_ptr_d->convert_to,
+                                     "nested_ptr");
+               oprintf (d->of, ";\n");
+
+               d->indent -= 2;
+               oprintf (d->of, "%*s}\n", d->indent, "");
+               d->val = d->prev_val[2];
+               d->prev_val[2] = oldprevval2;
+             }
+           else
+             d->process_field (t->u.p, d);
          }
        else
          {
@@ -1623,7 +1679,6 @@ 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);
-           d->process_field(t, d);
            oprintf (d->of, "%*sfor (i%d = 0; i%d < (size_t)(", d->indent, "",
                     loopcounter, loopcounter);
            output_escaped_param (d, length, "length");
@@ -1639,6 +1694,7 @@ walk_type (type_p t, struct walk_type_data *d)
            d->used_length = 0;
            d->indent -= 2;
            oprintf (d->of, "%*s}\n", d->indent, "");
+           d->process_field(t, d);
            d->indent -= 2;
            oprintf (d->of, "%*s}\n", d->indent, "");
          }
@@ -1911,8 +1967,8 @@ write_types_process_field (type_p f, const struct walk_type_data *d)
 */
 
 static void
-write_func_for_structure  (type_p orig_s, type_p s, type_p *param,
-                          const struct write_types_data *wtd)
+write_func_for_structure (type_p orig_s, type_p s, type_p *param,
+                         const struct write_types_data *wtd)
 {
   const char *fn = s->u.s.line.file;
   int i;
@@ -1947,7 +2003,7 @@ write_func_for_structure  (type_p orig_s, type_p s, type_p *param,
   d.bitmap = s->u.s.bitmap;
   d.param = param;
   d.prev_val[0] = "*x";
-  d.prev_val[1] = "not valid postage";  /* guarantee an error */
+  d.prev_val[1] = "not valid postage";  /* Guarantee an error.  */
   d.prev_val[3] = "x";
   d.val = "(*x)";
 
@@ -2200,7 +2256,7 @@ write_local_func_for_structure (type_p orig_s, type_p s, type_p *param)
   d.bitmap = s->u.s.bitmap;
   d.param = param;
   d.prev_val[0] = d.prev_val[2] = "*x";
-  d.prev_val[1] = "not valid postage";  /* guarantee an error */
+  d.prev_val[1] = "not valid postage";  /* Guarantee an error.  */
   d.prev_val[3] = "x";
   d.val = "(*x)";
 
@@ -2306,7 +2362,7 @@ write_local (type_p structures, type_p param_structs)
 /* Write out the 'enum' definition for gt_types_enum.  */
 
 static void
-write_enum_defn  (type_p structures, type_p param_structs)
+write_enum_defn (type_p structures, type_p param_structs)
 {
   type_p s;
 
@@ -2623,12 +2679,11 @@ write_array (outf_p f, pair_p v, const struct write_types_data *wtd)
       oprintf (f, "static void gt_%sa_%s\n", wtd->param_prefix, v->name);
       oprintf (f,
        "    (void *, void *, gt_pointer_operator, void *);\n");
-      oprintf (f, "static void gt_%sa_%s (this_obj, x_p, op, cookie)\n",
+      oprintf (f, "static void gt_%sa_%s (void *this_obj ATTRIBUTE_UNUSED,\n",
               wtd->param_prefix, v->name);
-      oprintf (d.of, "      void *this_obj ATTRIBUTE_UNUSED;\n");
-      oprintf (d.of, "      void *x_p ATTRIBUTE_UNUSED;\n");
-      oprintf (d.of, "      gt_pointer_operator op ATTRIBUTE_UNUSED;\n");
-      oprintf (d.of, "      void *cookie ATTRIBUTE_UNUSED;\n");
+      oprintf (d.of, "      void *x_p ATTRIBUTE_UNUSED,\n");
+      oprintf (d.of, "      gt_pointer_operator op ATTRIBUTE_UNUSED,\n");
+      oprintf (d.of, "      void *cookie ATTRIBUTE_UNUSED)\n");
       oprintf (d.of, "{\n");
       d.prev_val[0] = d.prev_val[1] = d.prev_val[2] = d.val = v->name;
       d.process_field = write_types_local_process_field;
@@ -2639,9 +2694,8 @@ write_array (outf_p f, pair_p v, const struct write_types_data *wtd)
   d.opt = v->opt;
   oprintf (f, "static void gt_%sa_%s (void *);\n",
           wtd->prefix, v->name);
-  oprintf (f, "static void\ngt_%sa_%s (x_p)\n",
+  oprintf (f, "static void\ngt_%sa_%s (void *x_p ATTRIBUTE_UNUSED)\n",
           wtd->prefix, v->name);
-  oprintf (f, "      void *x_p ATTRIBUTE_UNUSED;\n");
   oprintf (f, "{\n");
   d.prev_val[0] = d.prev_val[1] = d.prev_val[2] = d.val = v->name;
   d.process_field = write_types_process_field;
@@ -2916,10 +2970,10 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
   do_scalar_typedef ("uint8", &pos);
   do_scalar_typedef ("jword", &pos);
   do_scalar_typedef ("JCF_u2", &pos);
+  do_scalar_typedef ("void", &pos);
+
+  do_typedef ("PTR", create_pointer (resolve_typedef ("void", &pos)), &pos);
 
-  do_typedef ("PTR", create_pointer (create_scalar_type ("void",
-                                                        strlen ("void"))),
-             &pos);
   do_typedef ("HARD_REG_SET", create_array (
              create_scalar_type ("unsigned long", strlen ("unsigned long")),
              "2"), &pos);