[v2,4/7] Fortran: Ptype, print type extension.

Message ID 1542663530-140490-4-git-send-email-pwodkowski@pl.sii.eu
State New
Headers show
Series
  • [v2,1/7] DWARF: Don't add nameless modules to partial symbol table.
Related show

Commit Message

Paweł Wódkowski Nov. 19, 2018, 9:38 p.m.
From: Bernhard Heckel <bernhard.heckel@intel.com>


Print base-class of an extended type when doing a ptype.

2016-05-24 Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* gdb/f-typeprint.c (f_type_print_derivation_info): New.
	(f_type_print_base): Print baseclass info.

Changes from V1 to V2:
	clear commit message.
---
 gdb/f-typeprint.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

-- 
2.7.4

Comments

Andrew Burgess Feb. 1, 2019, 1:06 p.m. | #1
* Pawel Wodkowski <pwodkowski@pl.sii.eu> [2018-11-19 22:38:47 +0100]:

> From: Bernhard Heckel <bernhard.heckel@intel.com>

> 

> Print base-class of an extended type when doing a ptype.

> 

> 2016-05-24 Bernhard Heckel  <bernhard.heckel@intel.com>

> 

> gdb/Changelog:

> 	* gdb/f-typeprint.c (f_type_print_derivation_info): New.

> 	(f_type_print_base): Print baseclass info.


Could this patch have a test case please.  Also there's a minor
whitespace issue I've pointed out below.

Thanks,
Andrew

> 

> Changes from V1 to V2:

> 	clear commit message.

> ---

>  gdb/f-typeprint.c | 30 +++++++++++++++++++++++++++---

>  1 file changed, 27 insertions(+), 3 deletions(-)

> 

> diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c

> index 3f13c111ac56..133eaf9b9848 100644

> --- a/gdb/f-typeprint.c

> +++ b/gdb/f-typeprint.c

> @@ -256,6 +256,25 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,

>      }

>  }

>  

> +/* If TYPE is an extended type, then print out derivation information.

> +

> +   A typical output could look like this:

> +   "Type, extends(point) :: waypoint"

> +   "    Type point :: point"

> +   "    real(kind=4) :: angle"

> +   "End Type waypoint"

> + */

> +

> +static void

> +f_type_print_derivation_info (struct type *type, struct ui_file *stream)

> +{

> +  /* Fortran doesn't support multiple inheritance. */


Extra whitespace after '.'.

> +  int i = 0;

> +

> +  if (TYPE_N_BASECLASSES (type) > 0)

> +    fprintf_filtered (stream, ", extends(%s) ::", TYPE_NAME (TYPE_BASECLASS (type, i)));

> +}

> +

>  /* Print the name of the type (or the ultimate pointer target,

>     function value or array element), or the description of a

>     structure or union.

> @@ -372,10 +391,15 @@ f_type_print_base (struct type *type, struct ui_file *stream, int show,

>      case TYPE_CODE_STRUCT:

>      case TYPE_CODE_UNION:

>        if (TYPE_CODE (type) == TYPE_CODE_UNION)

> -	fprintfi_filtered (level, stream, "Type, C_Union :: ");

> +	fprintfi_filtered (level, stream, "Type, C_Union ::");

>        else

> -	fprintfi_filtered (level, stream, "Type ");

> -      fputs_filtered (TYPE_NAME (type), stream);

> +	fprintfi_filtered (level, stream, "Type");

> +

> +      if (show > 0)

> +	f_type_print_derivation_info (type, stream);

> +

> +      fprintf_filtered (stream, " %s", TYPE_NAME (type));

> +

>        /* According to the definition,

>           we only print structure elements in case show > 0.  */

>        if (show > 0)

> -- 

> 2.7.4

>

Patch

diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 3f13c111ac56..133eaf9b9848 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -256,6 +256,25 @@  f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
     }
 }
 
+/* If TYPE is an extended type, then print out derivation information.
+
+   A typical output could look like this:
+   "Type, extends(point) :: waypoint"
+   "    Type point :: point"
+   "    real(kind=4) :: angle"
+   "End Type waypoint"
+ */
+
+static void
+f_type_print_derivation_info (struct type *type, struct ui_file *stream)
+{
+  /* Fortran doesn't support multiple inheritance. */
+  int i = 0;
+
+  if (TYPE_N_BASECLASSES (type) > 0)
+    fprintf_filtered (stream, ", extends(%s) ::", TYPE_NAME (TYPE_BASECLASS (type, i)));
+}
+
 /* Print the name of the type (or the ultimate pointer target,
    function value or array element), or the description of a
    structure or union.
@@ -372,10 +391,15 @@  f_type_print_base (struct type *type, struct ui_file *stream, int show,
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
       if (TYPE_CODE (type) == TYPE_CODE_UNION)
-	fprintfi_filtered (level, stream, "Type, C_Union :: ");
+	fprintfi_filtered (level, stream, "Type, C_Union ::");
       else
-	fprintfi_filtered (level, stream, "Type ");
-      fputs_filtered (TYPE_NAME (type), stream);
+	fprintfi_filtered (level, stream, "Type");
+
+      if (show > 0)
+	f_type_print_derivation_info (type, stream);
+
+      fprintf_filtered (stream, " %s", TYPE_NAME (type));
+
       /* According to the definition,
          we only print structure elements in case show > 0.  */
       if (show > 0)