]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/godump.c
PR fortran/95090 - ICE: identifier overflow
[thirdparty/gcc.git] / gcc / godump.c
index b3eceff196e84e01945039522e547a3104948088..a7cd7edf7a48c9779e048150211d1e14f494d378 100644 (file)
@@ -1,5 +1,5 @@
 /* Output Go language descriptions of types.
-   Copyright (C) 2008-2015 Free Software Foundation, Inc.
+   Copyright (C) 2008-2020 Free Software Foundation, Inc.
    Written by Ian Lance Taylor <iant@google.com>.
 
 This file is part of GCC.
@@ -30,22 +30,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "diagnostic-core.h"
-#include "hash-set.h"
-#include "vec.h"
-#include "input.h"
-#include "alias.h"
-#include "symtab.h"
-#include "options.h"
-#include "inchash.h"
 #include "tree.h"
-#include "ggc.h"
-#include "hash-set.h"
-#include "obstack.h"
+#include "diagnostic-core.h"
 #include "debug.h"
-#include "wide-int-print.h"
 #include "stor-layout.h"
-#include "defaults.h"
 
 /* We dump this information from the debug hooks.  This gives us a
    stable and maintainable API to hook into.  In order to work
@@ -511,13 +499,20 @@ go_function_decl (tree decl)
   go_decl (decl);
 }
 
+static void
+go_early_global_decl (tree decl)
+{
+  go_decl (decl);
+  if (TREE_CODE (decl) != FUNCTION_DECL || DECL_STRUCT_FUNCTION (decl) != NULL)
+    real_debug_hooks->early_global_decl (decl);
+}
+
 /* A global variable decl.  */
 
 static void
-go_global_decl (tree decl)
+go_late_global_decl (tree decl)
 {
-  real_debug_hooks->global_decl (decl);
-  go_decl (decl);
+  real_debug_hooks->late_global_decl (decl);
 }
 
 /* A type declaration.  */
@@ -540,8 +535,9 @@ go_type_decl (tree decl, int local)
 /* A container for the data we pass around when generating information
    at the end of the compilation.  */
 
-struct godump_container
+class godump_container
 {
+public:
   /* DECLs that we have already seen.  */
   hash_set<tree> decls_seen;
 
@@ -684,7 +680,7 @@ go_force_record_alignment (struct obstack *ob, const char *type_string,
    calls from go_format_type() itself.  */
 
 static bool
-go_format_type (struct godump_container *container, tree type,
+go_format_type (class godump_container *container, tree type,
                bool use_type_name, bool is_func_ok, unsigned int *p_art_i,
                bool is_anon_record_or_union)
 {
@@ -727,10 +723,6 @@ go_format_type (struct godump_container *container, tree type,
 
   switch (TREE_CODE (type))
     {
-    case ENUMERAL_TYPE:
-      obstack_grow (ob, "int", 3);
-      break;
-
     case TYPE_DECL:
       {
        void **slot;
@@ -746,6 +738,7 @@ go_format_type (struct godump_container *container, tree type,
       }
       break;
 
+    case ENUMERAL_TYPE:
     case INTEGER_TYPE:
       {
        const char *s;
@@ -898,6 +891,7 @@ go_format_type (struct godump_container *container, tree type,
     case UNION_TYPE:
       is_union = true;
       /* Fall through to RECORD_TYPE case.  */
+      gcc_fallthrough ();
     case RECORD_TYPE:
       {
        unsigned int prev_field_end;
@@ -968,7 +962,7 @@ go_format_type (struct godump_container *container, tree type,
                   unions.  */
                if (!is_anon_substructure)
                  {
-                   if ((DECL_NAME (field) == NULL))
+                   if (DECL_NAME (field) == NULL)
                      *p_art_i = go_append_artificial_name (ob, *p_art_i);
                    else
                      go_append_decl_name
@@ -1010,14 +1004,9 @@ go_format_type (struct godump_container *container, tree type,
              }
          }
        /* Padding.  */
-       {
-         unsigned int align_unit;
-
-         align_unit = (is_anon_record_or_union) ? 1 : TYPE_ALIGN_UNIT (type);
-         *p_art_i = go_append_padding
-           (ob, prev_field_end, TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type)),
-            align_unit, *p_art_i, &prev_field_end);
-       }
+       *p_art_i = go_append_padding (ob, prev_field_end,
+                                     TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type)),
+                                     1, *p_art_i, &prev_field_end);
        /* Alignment.  */
        if (!is_anon_record_or_union
            && known_alignment < TYPE_ALIGN_UNIT (type))
@@ -1103,7 +1092,7 @@ go_format_type (struct godump_container *container, tree type,
    it.  */
 
 static void
-go_output_type (struct godump_container *container)
+go_output_type (class godump_container *container)
 {
   struct obstack *ob;
 
@@ -1116,7 +1105,7 @@ go_output_type (struct godump_container *container)
 /* Output a function declaration.  */
 
 static void
-go_output_fndecl (struct godump_container *container, tree decl)
+go_output_fndecl (class godump_container *container, tree decl)
 {
   if (!go_format_type (container, TREE_TYPE (decl), false, true, NULL, false))
     fprintf (go_dump_file, "// ");
@@ -1130,7 +1119,7 @@ go_output_fndecl (struct godump_container *container, tree decl)
 /* Output a typedef or something like a struct definition.  */
 
 static void
-go_output_typedef (struct godump_container *container, tree decl)
+go_output_typedef (class godump_container *container, tree decl)
 {
   /* If we have an enum type, output the enum constants
      separately.  */
@@ -1171,7 +1160,7 @@ go_output_typedef (struct godump_container *container, tree decl)
            snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_UNSIGNED,
                      tree_to_uhwi (TREE_VALUE (element)));
          else
-           print_hex (element, buf);
+           print_hex (wi::to_wide (element), buf);
 
          mhval->value = xstrdup (buf);
          *slot = mhval;
@@ -1193,7 +1182,7 @@ go_output_typedef (struct godump_container *container, tree decl)
        return;
       *slot = CONST_CAST (void *, (const void *) type);
 
-      if (!go_format_type (container, TREE_TYPE (decl), false, false, NULL,
+      if (!go_format_type (container, TREE_TYPE (decl), true, false, NULL,
                           false))
        {
          fprintf (go_dump_file, "// ");
@@ -1257,7 +1246,7 @@ go_output_typedef (struct godump_container *container, tree decl)
 /* Output a variable.  */
 
 static void
-go_output_var (struct godump_container *container, tree decl)
+go_output_var (class godump_container *container, tree decl)
 {
   bool is_valid;
   tree type_name;
@@ -1346,7 +1335,7 @@ static const char * const keywords[] = {
 };
 
 static void
-keyword_hash_init (struct godump_container *container)
+keyword_hash_init (class godump_container *container)
 {
   size_t i;
   size_t count = sizeof (keywords) / sizeof (keywords[0]);
@@ -1366,7 +1355,7 @@ keyword_hash_init (struct godump_container *container)
 bool
 find_dummy_types (const char *const &ptr, godump_container *adata)
 {
-  struct godump_container *data = (struct godump_container *) adata;
+  class godump_container *data = (class godump_container *) adata;
   const char *type = (const char *) ptr;
   void **slot;
   void **islot;
@@ -1383,7 +1372,7 @@ find_dummy_types (const char *const &ptr, godump_container *adata)
 static void
 go_finish (const char *filename)
 {
-  struct godump_container container;
+  class godump_container container;
   unsigned int ix;
   tree decl;
 
@@ -1457,7 +1446,8 @@ dump_go_spec_init (const char *filename, const struct gcc_debug_hooks *hooks)
   go_debug_hooks.define = go_define;
   go_debug_hooks.undef = go_undef;
   go_debug_hooks.function_decl = go_function_decl;
-  go_debug_hooks.global_decl = go_global_decl;
+  go_debug_hooks.early_global_decl = go_early_global_decl;
+  go_debug_hooks.late_global_decl = go_late_global_decl;
   go_debug_hooks.type_decl = go_type_decl;
 
   macro_hash = htab_create (100, macro_hash_hashval, macro_hash_eq,