public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 06/10] gdb: Convert language_data::c_style_arrays to a method
Date: Thu,  9 Jul 2020 12:37:03 +0100	[thread overview]
Message-ID: <7411e0bef85e1c566d287b974fca3539881a49cc.1594293733.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1594293732.git.andrew.burgess@embecosm.com>

Convert language_data::c_style_arrays member variable to a virtual
method language_defn::c_style_arrays_p.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove c_style_arrays
	initializer.
	(ada_language::c_style_arrays_p): New member fuction.
	* c-lang.c (c_language_data): Remove c_style_arrays
	initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* eval.c (ptrmath_type_p): Update call to c_style_arrays_p.
	* f-lang.c (f_language_data): Remove c_style_arrays initializer.
	(f_language::c_style_arrays_p): New member function.
	* go-lang.c (go_language_data): Remove c_style_arrays initializer.
	* infcall.c (value_arg_coerce): Update call to c_style_arrays_p.
	* language.c (unknown_language_data): Remove c_style_arrays
	initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Remove c_style_arrays field.
	(language_defn::c_style_arrays_p): New member function.
	* m2-lang.c (m2_language_data): Remove c_style_arrays initializer.
	(m2_language::c_style_arrays_p): New member function.
	* objc-lang.c (objc_language_data): Remove c_style_arrays
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	* valarith.c (value_subscript): Update call to c_style_arrays_p,
	and update local variable to a bool.
	* valops.c (value_cast): Update call to c_style_arrays_p.
	(value_array): Likewise.
	* value.c (coerce_array): Likewise.
---
 gdb/ChangeLog     | 34 ++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  6 +++++-
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/eval.c        |  2 +-
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  1 -
 gdb/infcall.c     |  2 +-
 gdb/language.c    |  2 --
 gdb/language.h    | 13 ++++++++-----
 gdb/m2-lang.c     |  6 +++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/valarith.c    |  6 +++---
 gdb/valops.c      |  4 ++--
 gdb/value.c       |  2 +-
 18 files changed, 65 insertions(+), 28 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 64511d0eec3..0323b525577 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13674,7 +13674,6 @@ extern const struct language_data ada_language_data =
   &ada_exp_descriptor,
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_op_print_tab,             /* expression operators for printing */
-  0,                            /* c-style arrays */
   1,                            /* String lower bound */
   &ada_varobj_ops,
 };
@@ -14158,6 +14157,11 @@ class ada_language : public language_defn
   const char *struct_too_deep_ellipsis () const override
   { return "(...)"; }
 
+  /* See language.h.  */
+
+  bool c_style_arrays_p () const override
+  { return false; }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index d8d66c24103..41eac2d43a3 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -882,7 +882,6 @@ extern const struct language_data c_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &c_varobj_ops,
 };
@@ -990,7 +989,6 @@ extern const struct language_data cplus_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &cplus_varobj_ops,
 };
@@ -1201,7 +1199,6 @@ extern const struct language_data asm_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
@@ -1270,7 +1267,6 @@ extern const struct language_data minimal_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 34af2588269..8cf61722fdc 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -135,7 +135,6 @@ extern const struct language_data d_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_op_print_tab,		/* Expression operators for printing.  */
-  1,				/* C-style arrays.  */
   0,				/* String lower bound.  */
   &default_varobj_ops,
 };
diff --git a/gdb/eval.c b/gdb/eval.c
index f9750816216..1066fd46bb3 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -622,7 +622,7 @@ ptrmath_type_p (const struct language_defn *lang, struct type *type)
       return 1;
 
     case TYPE_CODE_ARRAY:
-      return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays;
+      return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays_p ();
 
     default:
       return 0;
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 0e8b7a7e526..7c2d43d854b 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -493,7 +493,6 @@ extern const struct language_data f_language_data =
   &exp_descriptor_f,
   false,			/* la_store_sym_names_in_linkage_form_p */
   f_op_print_tab,		/* expression operators for printing */
-  0,				/* arrays are first-class (not c-style) */
   1,				/* String lower bound */
   &default_varobj_ops,
 };
@@ -720,6 +719,11 @@ class f_language : public language_defn
   const char *struct_too_deep_ellipsis () const override
   { return "(...)"; }
 
+  /* See language.h.  */
+
+  bool c_style_arrays_p () const override
+  { return false; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index ed7fcd1f425..c2724e3d7cc 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -515,7 +515,6 @@ extern const struct language_data go_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   go_op_print_tab,		/* Expression operators for printing.  */
-  1,				/* C-style arrays.  */
   0,				/* String lower bound.  */
   &default_varobj_ops,
 };
diff --git a/gdb/infcall.c b/gdb/infcall.c
index cdb30137c35..f27f713b3e7 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -219,7 +219,7 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
       /* Arrays are coerced to pointers to their first element, unless
          they are vectors, in which case we want to leave them alone,
          because they are passed by value.  */
-      if (current_language->c_style_arrays)
+      if (current_language->c_style_arrays_p ())
 	if (!TYPE_VECTOR (type))
 	  type = lookup_pointer_type (TYPE_TARGET_TYPE (type));
       break;
diff --git a/gdb/language.c b/gdb/language.c
index 55e8104132b..9a496ae8548 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -782,7 +782,6 @@ extern const struct language_data unknown_language_data =
   &exp_descriptor_standard,
   true,				/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
@@ -917,7 +916,6 @@ extern const struct language_data auto_language_data =
   &exp_descriptor_standard,
   false,			/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/language.h b/gdb/language.h
index 731b641d261..83014e47789 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -232,11 +232,6 @@ struct language_data
 
     const struct op_print *la_op_print_tab;
 
-    /* Zero if the language has first-class arrays.  True if there are no
-       array values, and array objects decay to pointers, as in C.  */
-
-    char c_style_arrays;
-
     /* Index to use for extracting the first element of a string.  */
     char string_lower_bound;
 
@@ -565,6 +560,14 @@ struct language_defn : language_data
   virtual const char *name_of_this () const
   { return nullptr; }
 
+  /* Return false if the language has first-class arrays.  Return true if
+     there are no array values, and array objects decay to pointers, as in
+     C.  The default is true as currently most supported languages behave
+     in this manor.  */
+
+  virtual bool c_style_arrays_p () const
+  { return true; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 94340b0d9b2..9dd557777c0 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -206,7 +206,6 @@ extern const struct language_data m2_language_data =
   &exp_descriptor_modula2,
   false,			/* la_store_sym_names_in_linkage_form_p */
   m2_op_print_tab,		/* expression operators for printing */
-  0,				/* arrays are first-class (not c-style) */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
@@ -436,6 +435,11 @@ class m2_language : public language_defn
 
     return false;
   }
+
+  /* See language.h.  */
+
+  bool c_style_arrays_p () const override
+  { return false; }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index f605c2194b0..66b7b50144b 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -330,7 +330,6 @@ extern const struct language_data objc_language_data =
   &exp_descriptor_standard,
   false,			/* la_store_sym_names_in_linkage_form_p */
   objc_op_print_tab,		/* Expression operators for printing */
-  1,				/* C-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 6a2df1a2e18..8f930294937 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1014,7 +1014,6 @@ extern const struct language_data opencl_language_data =
   &exp_descriptor_opencl,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index aef908c7dc6..66ba51ac8eb 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -259,7 +259,6 @@ extern const struct language_data pascal_language_data =
   &exp_descriptor_standard,
   false,			/* la_store_sym_names_in_linkage_form_p */
   pascal_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 4dd36eefbed..3b515fa003a 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1913,7 +1913,6 @@ extern const struct language_data rust_language_data =
   &exp_descriptor_rust,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/valarith.c b/gdb/valarith.c
index a5779a3aff9..b13d762a40d 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -140,7 +140,7 @@ value_ptrdiff (struct value *arg1, struct value *arg2)
 struct value *
 value_subscript (struct value *array, LONGEST index)
 {
-  int c_style = current_language->c_style_arrays;
+  bool c_style = current_language->c_style_arrays_p ();
   struct type *tarray;
 
   array = coerce_ref (array);
@@ -156,7 +156,7 @@ value_subscript (struct value *array, LONGEST index)
       if (VALUE_LVAL (array) != lval_memory)
 	return value_subscripted_rvalue (array, index, lowerbound);
 
-      if (c_style == 0)
+      if (!c_style)
 	{
 	  if (index >= lowerbound && index <= upperbound)
 	    return value_subscripted_rvalue (array, index, lowerbound);
@@ -165,7 +165,7 @@ value_subscript (struct value *array, LONGEST index)
 	  if (upperbound > -1)
 	    warning (_("array or string index out of range"));
 	  /* fall doing C stuff */
-	  c_style = 1;
+	  c_style = true;
 	}
 
       index -= lowerbound;
diff --git a/gdb/valops.c b/gdb/valops.c
index 8dab121de9f..c2d0ce05f69 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -414,7 +414,7 @@ value_cast (struct type *type, struct value *arg2)
 	}
     }
 
-  if (current_language->c_style_arrays
+  if (current_language->c_style_arrays_p ()
       && type2->code () == TYPE_CODE_ARRAY
       && !TYPE_VECTOR (type2))
     arg2 = value_coerce_array (arg2);
@@ -1618,7 +1618,7 @@ value_array (int lowbound, int highbound, struct value **elemvec)
   arraytype = lookup_array_range_type (value_enclosing_type (elemvec[0]),
 				       lowbound, highbound);
 
-  if (!current_language->c_style_arrays)
+  if (!current_language->c_style_arrays_p ())
     {
       val = allocate_value (arraytype);
       for (idx = 0; idx < nelem; idx++)
diff --git a/gdb/value.c b/gdb/value.c
index 97a099ddbd3..bb3111531a5 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3667,7 +3667,7 @@ coerce_array (struct value *arg)
   switch (type->code ())
     {
     case TYPE_CODE_ARRAY:
-      if (!TYPE_VECTOR (type) && current_language->c_style_arrays)
+      if (!TYPE_VECTOR (type) && current_language->c_style_arrays_p ())
 	arg = value_coerce_array (arg);
       break;
     case TYPE_CODE_FUNC:
-- 
2.25.4


  parent reply	other threads:[~2020-07-09 11:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
2020-07-09 11:36 ` [PATCH 01/10] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
2020-07-09 11:36 ` [PATCH 02/10] gdb: Convert la_name_of_this " Andrew Burgess
2020-07-09 11:37 ` [PATCH 03/10] gdb: Convert la_name and la_natural_name to methods Andrew Burgess
2020-07-09 11:37 ` [PATCH 04/10] gdb: Convert la_filename_extensions to a method Andrew Burgess
2020-07-09 11:37 ` [PATCH 05/10] gdb: Move la_language into the language_defn class Andrew Burgess
2020-07-09 11:37 ` Andrew Burgess [this message]
2020-07-09 11:37 ` [PATCH 07/10] gdb: Fix an incorrect comment Andrew Burgess
2020-07-09 11:37 ` [PATCH 08/10] gdb: Convert language_data::string_lower_bound to a method Andrew Burgess
2020-07-09 11:37 ` [PATCH 09/10] gdb: Convert la_store_sym_names_in_linkage_form_p " Andrew Burgess
2020-07-09 11:37 ` [PATCH 10/10] gdb: Override store_sym_names_in_linkage_form_p for Go language Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7411e0bef85e1c566d287b974fca3539881a49cc.1594293733.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).