Add libcc1 v1 compatibility to C compile feature
[binutils-gdb.git] / gdb / compile / compile-c-types.c
index 2bfa72d2b8cdb1a742b6f2b84bc60799c18eb24c..212cfe66bef4b478f721d3b474a847ab84cdb72c 100644 (file)
@@ -1,6 +1,6 @@
 /* Convert types from GDB to GCC
 
-   Copyright (C) 2014-2017 Free Software Foundation, Inc.
+   Copyright (C) 2014-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -207,9 +207,9 @@ convert_enum (struct compile_c_instance *context, struct type *type)
   int i;
   struct gcc_c_context *ctx = C_CTX (context);
 
-  int_type = ctx->c_ops->int_type (ctx,
-                                  TYPE_UNSIGNED (type),
-                                  TYPE_LENGTH (type));
+  int_type = ctx->c_ops->int_type_v0 (ctx,
+                                     TYPE_UNSIGNED (type),
+                                     TYPE_LENGTH (type));
 
   result = ctx->c_ops->build_enum_type (ctx, int_type);
   for (i = 0; i < TYPE_NFIELDS (type); ++i)
@@ -273,9 +273,22 @@ convert_func (struct compile_c_instance *context, struct type *type)
 static gcc_type
 convert_int (struct compile_c_instance *context, struct type *type)
 {
-  return C_CTX (context)->c_ops->int_type (C_CTX (context),
-                                          TYPE_UNSIGNED (type),
-                                          TYPE_LENGTH (type));
+  if (C_CTX (context)->c_ops->c_version >= GCC_C_FE_VERSION_1)
+    {
+      if (TYPE_NOSIGN (type))
+       {
+         gdb_assert (TYPE_LENGTH (type) == 1);
+         return C_CTX (context)->c_ops->char_type (C_CTX (context));
+       }
+      return C_CTX (context)->c_ops->int_type (C_CTX (context),
+                                              TYPE_UNSIGNED (type),
+                                              TYPE_LENGTH (type),
+                                              TYPE_NAME (type));
+    }
+  else
+    return C_CTX (context)->c_ops->int_type_v0 (C_CTX (context),
+                                               TYPE_UNSIGNED (type),
+                                               TYPE_LENGTH (type));
 }
 
 /* Convert a floating-point type to its gcc representation.  */
@@ -283,8 +296,13 @@ convert_int (struct compile_c_instance *context, struct type *type)
 static gcc_type
 convert_float (struct compile_c_instance *context, struct type *type)
 {
-  return C_CTX (context)->c_ops->float_type (C_CTX (context),
-                                            TYPE_LENGTH (type));
+  if (C_CTX (context)->c_ops->c_version >= GCC_C_FE_VERSION_1)
+    return C_CTX (context)->c_ops->float_type (C_CTX (context),
+                                              TYPE_LENGTH (type),
+                                              TYPE_NAME (type));
+  else
+    return C_CTX (context)->c_ops->float_type_v0 (C_CTX (context),
+                                                 TYPE_LENGTH (type));
 }
 
 /* Convert the 'void' type to its gcc representation.  */
@@ -383,6 +401,21 @@ convert_type_basic (struct compile_c_instance *context, struct type *type)
 
     case TYPE_CODE_COMPLEX:
       return convert_complex (context, type);
+
+    case TYPE_CODE_ERROR:
+      {
+       /* Ideally, if we get here due to a cast expression, we'd use
+          the cast-to type as the variable's type, like GDB's
+          built-in parser does.  For now, assume "int" like GDB's
+          built-in parser used to do, but at least warn.  */
+       struct type *fallback;
+       if (TYPE_OBJFILE_OWNED (type))
+         fallback = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
+       else
+         fallback = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
+       warning (_("variable has unknown type; assuming int"));
+       return convert_int (context, fallback);
+      }
     }
 
   return C_CTX (context)->c_ops->error (C_CTX (context),