From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13951 invoked by alias); 17 Feb 2010 15:46:00 -0000 Received: (qmail 13933 invoked by uid 22791); 17 Feb 2010 15:45:58 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 17 Feb 2010 15:45:52 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1HFjmwq023487 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 17 Feb 2010 10:45:49 -0500 Received: from miki.localnet (vpn-234-27.phx2.redhat.com [10.3.234.27]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1HFjctf004969 for ; Wed, 17 Feb 2010 10:45:41 -0500 From: =?iso-8859-1?q?S=E9rgio_Durigan_J=FAnior?= To: gdb-patches@sourceware.org Subject: [PATCH] Function-like cast notation support Date: Wed, 17 Feb 2010 15:46:00 -0000 User-Agent: KMail/1.12.4 (Linux/2.6.31.12-174.2.3.fc12.x86_64; KDE/4.3.5; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1615915.6bobz2tFSg"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201002171345.36988.sergiodj@redhat.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-02/txt/msg00425.txt.bz2 --nextPart1615915.6bobz2tFSg Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-length: 5821 Hello, The following patch adds support for function-like cast notation on GDB.=20= =20 Currently it only works for primitive data type (int, char, double, etc), b= ut=20 I intend to send another patch soon that will implement this feature for=20 classes as well. A brief explanation of what this specific cast notation means: While on C you do: (long) (5 + 6); C++ allows you to do: long (5 + 6); Regards, --=20 S=E9rgio Durigan J=FAnior Debugger Engineer -- Red Hat Inc. gdb/ChangeLog: 2010-02-17 Sergio Durigan Junior * c-exp.y: Add new rule to recognize a function-like cast notation. (typebase_single): New rule to match single tokens like `int', `char', etc. (typebase): Modify existing rule in order to use `typebase_single'. gdb/testsuite/ChangeLog: 2010-02-17 Sergio Durigan Junior * gdb.base/function-like-cast-notation.exp: New file. diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 845771c..a42a032 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -162,7 +162,7 @@ static struct stoken operator_stoken (const char *); =20 %type exp exp1 type_exp start variable qualified_name lcurly %type rcurly -%type type typebase qualified_type +%type type typebase qualified_type typebase_single %type nonempty_typelist /* %type block */ =20 @@ -440,6 +440,12 @@ exp : '(' type ')' exp %prec UNARY write_exp_elt_opcode (UNOP_CAST); } ; =20 +exp : typebase_single '(' exp ')' + { write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_type ($1); + write_exp_elt_opcode (UNOP_CAST); } + ; + exp : '(' exp1 ')' { } ; @@ -943,7 +949,7 @@ func_mod: '(' ')' type : ptype ; =20 -typebase /* Implements (approximately): (type-qualifier)* type-specifier = */ +typebase_single : TYPENAME { $$ =3D $1.type; } | INT_KEYWORD @@ -952,6 +958,17 @@ typebase /* Implements (approximately): (type- qualifier)* type-specifier */ { $$ =3D parse_type->builtin_long; } | SHORT { $$ =3D parse_type->builtin_short; } + | DOUBLE_KEYWORD + { $$ =3D parse_type->builtin_double; } + | UNSIGNED + { $$ =3D parse_type->builtin_unsigned_int; } + | SIGNED_KEYWORD + { $$ =3D parse_type->builtin_int; } + ; + + +typebase /* Implements (approximately): (type-qualifier)* type-specifier = */ + : typebase_single | LONG INT_KEYWORD { $$ =3D parse_type->builtin_long; } | LONG SIGNED_KEYWORD INT_KEYWORD @@ -998,8 +1015,6 @@ typebase /* Implements (approximately): (type- qualifier)* type-specifier */ { $$ =3D parse_type->builtin_unsigned_short; } | SHORT UNSIGNED INT_KEYWORD { $$ =3D parse_type->builtin_unsigned_short; } - | DOUBLE_KEYWORD - { $$ =3D parse_type->builtin_double; } | LONG DOUBLE_KEYWORD { $$ =3D parse_type->builtin_long_double; } | STRUCT name @@ -1018,14 +1033,10 @@ typebase /* Implements (approximately): (type- qualifier)* type-specifier */ { $$ =3D lookup_unsigned_typename (parse_language, parse_gdbarch, TYPE_NAME($2.type)); } - | UNSIGNED - { $$ =3D parse_type->builtin_unsigned_int; } | SIGNED_KEYWORD typename { $$ =3D lookup_signed_typename (parse_language, parse_gdbarch, TYPE_NAME($2.type)); } - | SIGNED_KEYWORD - { $$ =3D parse_type->builtin_int; } /* It appears that this rule for templates is never reduced; template recognition happens by lookahead in the token processing code in yylex. */=20=20=20=20= =20=20=20=20=20 diff --git a/gdb/testsuite/gdb.base/function-like-cast-notation.exp=20 b/gdb/testsuite/gdb.base/function-like-cast-notation.exp new file mode 100644 index 0000000..de31f63 --- /dev/null +++ b/gdb/testsuite/gdb.base/function-like-cast-notation.exp @@ -0,0 +1,62 @@ +# Copyright 2010 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 . + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +### +# Test for primitive types +### + +# This is the main variable of this testcase. It has elements +# which contain 4 fields inside each one. +# +# The order of the fields inside each element is: +# +# - The TYPE to be used in the `whatis' test. +# - The OUTPUT expected from the `whatis' test. +# - The VALUE (or EXPRESSION) to be used in the `print' test. +# - The OUTPUT expected to be printed in the `print' test. + +set test_data { { "char" "char" "97" "97 'a'" } + { "short" "short" "'a'" "97" } + { "int" "int" "97.1 + 18.0" "115" } + { "long" "long" "'a'" "97" } + { "signed" "int" "97.1 + 18.0" "115" } + { "unsigned" "unsigned int" "'a'" "97" } + { "float" "float" "'a'" "97" } + { "double" "double" "'a'" "97" } + { "void" "void" "'a'" "void" } +} + + +foreach tuple $test_data { + set type [lindex $tuple 0] + set out_t [lindex $tuple 1] + set val [lindex $tuple 2] + set out_v [lindex $tuple 3] + + set thistest "$type type `whatis'" + gdb_test "whatis $type ($val)" "type =3D $out_t" $thistest + + set thistest "$type type `print'" + gdb_test "print $type ($val)" " =3D $out_v" $thistest +} + +### +# Test for classes +### +## NOT IMPLEMENTED YET ## --nextPart1615915.6bobz2tFSg Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. Content-length: 836 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (GNU/Linux) iQIcBAABAgAGBQJLfA8gAAoJENDrdihl/F42eSUP/i/i25qGniDAU1MUe/WQuvnz 7hJsASYtf/zik7P+BwooUyOAJnqU1FavnBaDK2XrOPAr5uHr/hQ5lxoAgAlMytSl FDzLvHTIExi9sf/jBaUuM4dUuQJj/lJseIj6ESq7hG+zn2P6NqNZ+yrwEneAUGjM 5muf9+CHp5Ug+XS/ZHhHTaczIZxL3W1wibLvvHzRMs0uky6BXZJ1NeL4PmRDm2/U 5tJ+lvh5LzTbfyu3B/EfV+EefR9l+0C/tdt40sbQQ25Hz9k+RQ7DEGg6cHwMxmHG fprEfzepuDuxcd6MO4WD93GqCAQ3ZjnWADApR8+fkcNF55ecYHc1v2oGXrUd4ku9 8WCMMJuygpfK8AtqJVCEW+cdmKCVI3yWYhdTCJldpTWYestkOI6zyG13JXErxLXY nj2rJ0zr5ZutMGYrIW4a0bTbkuX4C3nrkHUUCDbPzVT3KY/s5flRIklQpnRF1gz+ 01/5t+Vbre3T0lkNwud0PT4bmVSPAJV9zmUtfwVJZLEWJV0dPXppJpUJboA114D4 3UlksiO4aKCVXvu2SMOT85IBKcLCeoU2bf60t2ElP4V6Oqq9BsONTEoH1eMHuXR0 WllboTomJTpQ7jZskSa4iiHuAShrj94RKwBTPnuL2FPr3lSdUYCqpBBmuvSx7wNS jvwcZ6BHVSQvWV7ZCKja =SVVn -----END PGP SIGNATURE----- --nextPart1615915.6bobz2tFSg--