Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [commit/ada+testsuite] print ada boolean expression results as true/false
@ 2007-12-28  6:36 Joel Brobecker
  2007-12-28 10:33 ` Mark Kettenis
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Brobecker @ 2007-12-28  6:36 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 937 bytes --]

This is a minor improvement, when printing the result of a boolean
expression. Right now, GDB prints:

    (gdb) print 1 = 2
    $1 = 0
    (gdb) print 3 = 3
    $2 = 1

The result should be of type boolean, which means either true or false.
So the expected output is:

    (gdb) print 1 = 2
    $1 = false
    (gdb) print 3 = 3
    $2 = true

The attached patches fixes it.

2007-12-27  Paul Hilfinger  <hilfinger@adacore.com>

        * ada-lang.c (ada_evaluate_subexp): Add cases for BINOP_LOGICAL_AND,
        BINOP_LOGICAL_OR, UNOP_LOGICAL_NOT, BINOP_BITWISE_IOR,
        BINOP_BITWISE_XOR, BINOP_BITWISE_AND.
        * language.c (lang_bool_type): Add Ada case.
    
Tested on x86-linux. Checked in.

In addition, I have written a small testcase for it:

2007-12-27  Joel Brobecker  <brobecker@adacore.com>

        * gdb.ada/boolean_expr.exp: New testcase.

Also tested on x86-linux. Fails without the ada-lang.c patch.

-- 
Joel

[-- Attachment #2: boolean-ada.diff --]
[-- Type: text/plain, Size: 1716 bytes --]

Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.112
diff -u -p -r1.112 ada-lang.c
--- ada-lang.c	24 Dec 2007 16:52:24 -0000	1.112
+++ ada-lang.c	28 Dec 2007 06:09:19 -0000
@@ -8151,6 +8151,24 @@ ada_evaluate_subexp (struct type *expect
       else
         return value_neg (arg1);
 
+    case BINOP_LOGICAL_AND:
+    case BINOP_LOGICAL_OR:
+    case UNOP_LOGICAL_NOT:
+      *pos -= 1;
+      return value_cast (LA_BOOL_TYPE, 
+			 evaluate_subexp_standard (expect_type, exp,
+						   pos, noside));
+
+    case BINOP_BITWISE_AND:
+    case BINOP_BITWISE_IOR:
+    case BINOP_BITWISE_XOR:
+      arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
+      *pos = pc;
+      return value_cast (value_type (arg1),
+			 evaluate_subexp_standard (expect_type, exp,
+						   pos, noside));
+			 
+
     case OP_VAR_VALUE:
       *pos -= 1;
       if (noside == EVAL_SKIP)
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.70
diff -u -p -r1.70 language.c
--- language.c	4 Dec 2007 23:33:00 -0000	1.70
+++ language.c	28 Dec 2007 06:09:19 -0000
@@ -801,6 +801,7 @@ lang_bool_type (void)
       return builtin_type_f_logical_s2;
     case language_cplus:
     case language_pascal:
+    case language_ada:
       if (current_language->la_language==language_cplus)
         {sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);}
       else
@@ -821,6 +822,7 @@ lang_bool_type (void)
 	    return type;
 	}
       return java_boolean_type;
+      
     default:
       return builtin_type_int;
     }

[-- Attachment #3: boolean_expr.exp --]
[-- Type: text/plain, Size: 1182 bytes --]

# Copyright 2007 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if $tracelevel then {
    strace $tracelevel
}

load_lib "ada.exp"

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

set any_nb "\[0-9\]+"
set any_addr "0x\[0-9a-zA-Z\]+"

# Force the language to Ada, as this will not happen automatically
# in this case (no test program).
gdb_test "set lang ada" \
         "" \
         "Changing the language to ada"

gdb_test "print 1 = 2" \
         "false" \
         "print 1 = 2"

gdb_test "print 3 = 3" \
         "true" \
         "print 3 = 3"


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit/ada+testsuite] print ada boolean expression results as true/false
  2007-12-28  6:36 [commit/ada+testsuite] print ada boolean expression results as true/false Joel Brobecker
@ 2007-12-28 10:33 ` Mark Kettenis
  2007-12-28 13:10   ` Joel Brobecker
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Kettenis @ 2007-12-28 10:33 UTC (permalink / raw)
  To: brobecker; +Cc: gdb-patches

> Date: Thu, 27 Dec 2007 22:15:13 -0800
> From: Joel Brobecker <brobecker@adacore.com>

Just a small nit:

> Index: ada-lang.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/ada-lang.c,v
> retrieving revision 1.112
> diff -u -p -r1.112 ada-lang.c
> --- ada-lang.c	24 Dec 2007 16:52:24 -0000	1.112
> +++ ada-lang.c	28 Dec 2007 06:09:19 -0000
> @@ -8151,6 +8151,24 @@ ada_evaluate_subexp (struct type *expect
>        else
>          return value_neg (arg1);
>  
> +    case BINOP_LOGICAL_AND:
> +    case BINOP_LOGICAL_OR:
> +    case UNOP_LOGICAL_NOT:
> +      *pos -= 1;
> +      return value_cast (LA_BOOL_TYPE, 
> +			 evaluate_subexp_standard (expect_type, exp,
> +						   pos, noside));

I think the fact that you need three lines here means that it makes
more sense to avoid the nested function calls and use a (temporary)
variable instead.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit/ada+testsuite] print ada boolean expression results as true/false
  2007-12-28 10:33 ` Mark Kettenis
@ 2007-12-28 13:10   ` Joel Brobecker
  2007-12-28 13:22     ` Joel Brobecker
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Brobecker @ 2007-12-28 13:10 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb-patches

Hi Mark!

Thanks for taking a look at the patch, this is always much appreciated.

> > +      *pos -= 1;
> > +      return value_cast (LA_BOOL_TYPE, 
> > +			 evaluate_subexp_standard (expect_type, exp,
> > +						   pos, noside));
> 
> I think the fact that you need three lines here means that it makes
> more sense to avoid the nested function calls and use a (temporary)
> variable instead.

Sure, that's a good idea. Fixed with the attached patch:

2007-12-28  Joel Brobecker  <brobecker@adacore.com>

        * ada-lang.c (ada_evaluate_subexp): Break two large expressions
        using temporary variables.

Tested on x86-linux, no regression. Checked in.

-- 
Joel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit/ada+testsuite] print ada boolean expression results as true/false
  2007-12-28 13:10   ` Joel Brobecker
@ 2007-12-28 13:22     ` Joel Brobecker
  0 siblings, 0 replies; 4+ messages in thread
From: Joel Brobecker @ 2007-12-28 13:22 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 300 bytes --]

> Sure, that's a good idea. Fixed with the attached patch:
> 
> 2007-12-28  Joel Brobecker  <brobecker@adacore.com>
> 
>         * ada-lang.c (ada_evaluate_subexp): Break two large expressions
>         using temporary variables.
> 
> Tested on x86-linux, no regression. Checked in.

Ahem.

-- 
Joel

[-- Attachment #2: temp.diff --]
[-- Type: text/plain, Size: 1246 bytes --]

Index: ada-lang.c
===================================================================
--- ada-lang.c	(revision 14)
+++ ada-lang.c	(revision 15)
@@ -8516,20 +8516,26 @@ ada_evaluate_subexp (struct type *expect
     case BINOP_LOGICAL_AND:
     case BINOP_LOGICAL_OR:
     case UNOP_LOGICAL_NOT:
-      *pos -= 1;
-      return value_cast (LA_BOOL_TYPE, 
-			 evaluate_subexp_standard (expect_type, exp,
-						   pos, noside));
+      {
+        struct value *val;
+
+        *pos -= 1;
+        val = evaluate_subexp_standard (expect_type, exp, pos, noside);
+        return value_cast (LA_BOOL_TYPE, val);
+      }
 
     case BINOP_BITWISE_AND:
     case BINOP_BITWISE_IOR:
     case BINOP_BITWISE_XOR:
-      arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
-      *pos = pc;
-      return value_cast (value_type (arg1),
-			 evaluate_subexp_standard (expect_type, exp,
-						   pos, noside));
-			 
+      {
+        struct value *val;
+
+        arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
+        *pos = pc;
+        val = evaluate_subexp_standard (expect_type, exp, pos, noside);
+
+        return value_cast (value_type (arg1), val);
+      }
 
     case OP_VAR_VALUE:
       *pos -= 1;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-12-28 13:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-28  6:36 [commit/ada+testsuite] print ada boolean expression results as true/false Joel Brobecker
2007-12-28 10:33 ` Mark Kettenis
2007-12-28 13:10   ` Joel Brobecker
2007-12-28 13:22     ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox