Don't write to inferior_ptid in corelow.c
[deliverable/binutils-gdb.git] / gdb / compile / compile-c-types.c
index bfc6ccf1bb26ad2bcd7e399b0c33747d93dc306d..aad35887666865dc9980de34700fd3d4984dba1d 100644 (file)
@@ -1,6 +1,6 @@
 /* Convert types from GDB to GCC
 
-   Copyright (C) 2014-2018 Free Software Foundation, Inc.
+   Copyright (C) 2014-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "compile-c.h"
 #include "objfiles.h"
 
-/* An object that maps a gdb type to a gcc type.  */
-
-struct type_map_instance
-{
-  /* The gdb type.  */
-
-  struct type *type;
-
-  /* The corresponding gcc type handle.  */
-
-  gcc_type gcc_type_handle;
-};
-
-/* Hash a type_map_instance.  */
-
-static hashval_t
-hash_type_map_instance (const void *p)
-{
-  const struct type_map_instance *inst = (const struct type_map_instance *) p;
-
-  return htab_hash_pointer (inst->type);
-}
-
-/* Check two type_map_instance objects for equality.  */
-
-static int
-eq_type_map_instance (const void *a, const void *b)
-{
-  const struct type_map_instance *insta = (const struct type_map_instance *) a;
-  const struct type_map_instance *instb = (const struct type_map_instance *) b;
-
-  return insta->type == instb->type;
-}
-
-/* Constructor for compile_instance.  */
-
-compile_instance::compile_instance (struct gcc_base_context *gcc_fe,
-                                   const char *options)
-  : m_gcc_fe (gcc_fe), m_gcc_target_options (options),
-    m_symbol_err_map (NULL)
-{
-  m_type_map = htab_create_alloc (10, hash_type_map_instance,
-                                 eq_type_map_instance,
-                                 xfree, xcalloc, xfree);
-}
-
-\f
-
-/* See compile-internal.h.  */
-
-bool
-compile_instance::get_cached_type (struct type *type, gcc_type &ret) const
-{
-  struct type_map_instance inst, *found;
-
-  inst.type = type;
-  found = (struct type_map_instance *) htab_find (m_type_map, &inst);
-  if (found != NULL)
-    {
-      ret = found->gcc_type_handle;
-      return true;
-    }
-
-  return false;
-}
-
-/* See compile-internal.h.  */
-
-void
-compile_instance::insert_type (struct type *type, gcc_type gcc_type)
-{
-  struct type_map_instance inst, *add;
-  void **slot;
-
-  inst.type = type;
-  inst.gcc_type_handle = gcc_type;
-  slot = htab_find_slot (m_type_map, &inst, INSERT);
-
-  add = (struct type_map_instance *) *slot;
-  /* The type might have already been inserted in order to handle
-     recursive types.  */
-  if (add != NULL && add->gcc_type_handle != gcc_type)
-    error (_("Unexpected type id from GCC, check you use recent enough GCC."));
-
-  if (add == NULL)
-    {
-      add = XNEW (struct type_map_instance);
-      *add = inst;
-      *slot = add;
-    }
-}
-
 /* Convert a pointer type to its gcc representation.  */
 
 static gcc_type
@@ -132,7 +40,7 @@ static gcc_type
 convert_array (compile_c_instance *context, struct type *type)
 {
   gcc_type element_type;
-  struct type *range = TYPE_INDEX_TYPE (type);
+  struct type *range = type->index_type ();
 
   element_type = context->convert_type (TYPE_TARGET_TYPE (type));
 
@@ -186,23 +94,23 @@ convert_struct_or_union (compile_c_instance *context, struct type *type)
 
   /* First we create the resulting type and enter it into our hash
      table.  This lets recursive types work.  */
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+  if (type->code () == TYPE_CODE_STRUCT)
     result = context->plugin ().build_record_type ();
   else
     {
-      gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
+      gdb_assert (type->code () == TYPE_CODE_UNION);
       result = context->plugin ().build_union_type ();
     }
   context->insert_type (type, result);
 
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (i = 0; i < type->num_fields (); ++i)
     {
       gcc_type field_type;
       unsigned long bitsize = TYPE_FIELD_BITSIZE (type, i);
 
-      field_type = context->convert_type (TYPE_FIELD_TYPE (type, i));
+      field_type = context->convert_type (type->field (i).type ());
       if (bitsize == 0)
-       bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, i));
+       bitsize = 8 * TYPE_LENGTH (type->field (i).type ());
       context->plugin ().build_add_field (result,
                                          TYPE_FIELD_NAME (type, i),
                                          field_type,
@@ -226,7 +134,7 @@ convert_enum (compile_c_instance *context, struct type *type)
                                             TYPE_LENGTH (type));
 
   result = context->plugin ().build_enum_type (int_type);
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (i = 0; i < type->num_fields (); ++i)
     {
       context->plugin ().build_add_enum_constant
        (result, TYPE_FIELD_NAME (type, i), TYPE_FIELD_ENUMVAL (type, i));
@@ -267,10 +175,10 @@ convert_func (compile_c_instance *context, struct type *type)
      types.  Those are impossible in C, though.  */
   return_type = context->convert_type (target_type);
 
-  array.n_elements = TYPE_NFIELDS (type);
-  array.elements = XNEWVEC (gcc_type, TYPE_NFIELDS (type));
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
-    array.elements[i] = context->convert_type (TYPE_FIELD_TYPE (type, i));
+  array.n_elements = type->num_fields ();
+  array.elements = XNEWVEC (gcc_type, type->num_fields ());
+  for (i = 0; i < type->num_fields (); ++i)
+    array.elements[i] = context->convert_type (type->field (i).type ());
 
   result = context->plugin ().build_function_type (return_type,
                                                   &array, is_varargs);
@@ -293,7 +201,7 @@ convert_int (compile_c_instance *context, struct type *type)
        }
       return context->plugin ().int_type (TYPE_UNSIGNED (type),
                                          TYPE_LENGTH (type),
-                                         TYPE_NAME (type));
+                                         type->name ());
     }
   else
     return context->plugin ().int_type_v0 (TYPE_UNSIGNED (type),
@@ -307,7 +215,7 @@ convert_float (compile_c_instance *context, struct type *type)
 {
   if (context->plugin ().version () >= GCC_C_FE_VERSION_1)
     return context->plugin ().float_type (TYPE_LENGTH (type),
-                                         TYPE_NAME (type));
+                                         type->name ());
   else
     return context->plugin ().float_type_v0 (TYPE_LENGTH (type));
 }
@@ -374,7 +282,7 @@ convert_type_basic (compile_c_instance *context, struct type *type)
                                     | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
     return convert_qualified (context, type);
 
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_PTR:
       return convert_pointer (context, type);
@@ -445,7 +353,7 @@ compile_c_instance::convert_type (struct type *type)
   type = check_typedef (type);
 
   gcc_type result;
-  if (get_cached_type (type, result))
+  if (get_cached_type (type, &result))
     return result;
 
   result = convert_type_basic (this, type);
This page took 0.027504 seconds and 4 git commands to generate.