* [RFA] Token cleanup in c-exp.y
@ 2009-08-24 23:06 Keith Seitz
2009-08-24 23:08 ` Tom Tromey
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Keith Seitz @ 2009-08-24 23:06 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 312 bytes --]
Hi,
The attached patch "fixes" two tokens in c-exp.y, "->*" and ".*", which
were not previously recognized as tokens.
Keith
ChangeLog
2009-08-24 Keith Seitz <keiths@redhat.com>
* c-exp.y (tokentab3): Add new token, ARROW_STAR. Changed all users.
(tokentab2): Add new token, DOT_STAR. Changed all users.
[-- Attachment #2: token-fix.patch --]
[-- Type: text/plain, Size: 1535 bytes --]
Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.59
diff -u -p -r1.59 c-exp.y
--- c-exp.y 7 Jul 2009 21:33:48 -0000 1.59
+++ c-exp.y 24 Aug 2009 20:41:09 -0000
@@ -232,7 +232,7 @@ static int parse_number (char *, int, in
%left '+' '-'
%left '*' '/' '%'
%right UNARY INCREMENT DECREMENT
-%right ARROW '.' '[' '('
+%right ARROW ARROW_STAR '.' DOT_STAR '[' '('
%token <ssym> BLOCKNAME
%token <bval> FILENAME
%type <bval> block
@@ -333,7 +333,7 @@ exp : exp ARROW qualified_name
write_exp_elt_opcode (STRUCTOP_MPTR); }
;
-exp : exp ARROW '*' exp
+exp : exp ARROW_STAR exp
{ write_exp_elt_opcode (STRUCTOP_MPTR); }
;
@@ -368,7 +368,7 @@ exp : exp '.' qualified_name
write_exp_elt_opcode (STRUCTOP_MEMBER); }
;
-exp : exp '.' '*' exp
+exp : exp DOT_STAR exp
{ write_exp_elt_opcode (STRUCTOP_MEMBER); }
;
@@ -1664,7 +1664,8 @@ struct token
static const struct token tokentab3[] =
{
{">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
- {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0}
+ {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
+ {"->*", ARROW_STAR, BINOP_END, 1}
};
static const struct token tokentab2[] =
@@ -1688,7 +1689,8 @@ static const struct token tokentab2[] =
{"==", EQUAL, BINOP_END, 0},
{"!=", NOTEQUAL, BINOP_END, 0},
{"<=", LEQ, BINOP_END, 0},
- {">=", GEQ, BINOP_END, 0}
+ {">=", GEQ, BINOP_END, 0},
+ {".*", DOT_STAR, BINOP_END, 0}
};
/* Identifier-like tokens. */
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-24 23:06 [RFA] Token cleanup in c-exp.y Keith Seitz
@ 2009-08-24 23:08 ` Tom Tromey
2009-08-25 5:03 ` Keith Seitz
2009-08-25 15:28 ` Matt Rice
2009-08-25 15:47 ` Tom Tromey
2 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2009-08-24 23:08 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches
>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:
Keith> 2009-08-24 Keith Seitz <keiths@redhat.com>
Keith> * c-exp.y (tokentab3): Add new token, ARROW_STAR. Changed all users.
Keith> (tokentab2): Add new token, DOT_STAR. Changed all users.
This is ok, thanks.
Tom
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-24 23:08 ` Tom Tromey
@ 2009-08-25 5:03 ` Keith Seitz
2009-08-25 13:45 ` Pierre Muller
0 siblings, 1 reply; 12+ messages in thread
From: Keith Seitz @ 2009-08-25 5:03 UTC (permalink / raw)
To: tromey; +Cc: gdb-patches
On 08/24/2009 04:05 PM, Tom Tromey wrote:
> This is ok, thanks.
Checked in. Thank you for looking.
Keith
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [RFA] Token cleanup in c-exp.y
2009-08-25 5:03 ` Keith Seitz
@ 2009-08-25 13:45 ` Pierre Muller
2009-08-25 14:10 ` Jiang Jilin
0 siblings, 1 reply; 12+ messages in thread
From: Pierre Muller @ 2009-08-25 13:45 UTC (permalink / raw)
To: 'Keith Seitz', tromey; +Cc: gdb-patches
Just for information:
doesn't this mean that
the parser that previously accepted
'-> *' with spaces between the arrow and the star,
will now reject such patterns?
Is this also what a C compile would do?
The behavior of GDB did change indeed:
Old behavior:
(top-gdb) p current_objfile->*gdb_stderr
non-pointer-to-member value used in pointer-to-member construct
(top-gdb) p current_objfile-> *gdb_stderr
non-pointer-to-member value used in pointer-to-member construct
New behavior:
(top-gdb) p current_objfile->*gdb_stderr
non-pointer-to-member value used in pointer-to-member construct
(top-gdb) p current_objfile-> *gdb_stderr
A syntax error in expression, near `*gdb_stderr'.
The problem is that I have
no idea what it stands for...
and I never saw '->*' nor '.*' in any C sources.
Please forgive the question if it is silly,
and remember that my knowledge of C is limited
to what I learned to be able to contribute to the GDB project...
Pierre Muller
Pascal language support maintainer for GDB
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-25 13:45 ` Pierre Muller
@ 2009-08-25 14:10 ` Jiang Jilin
2009-08-25 15:11 ` Andreas Schwab
0 siblings, 1 reply; 12+ messages in thread
From: Jiang Jilin @ 2009-08-25 14:10 UTC (permalink / raw)
To: Pierre Muller; +Cc: Keith Seitz, tromey, gdb-patches
On Tue, Aug 25, 2009 at 5:40 PM, Pierre Muller<muller@ics.u-strasbg.fr> wrote:
> Just for information:
> doesn't this mean that
> the parser that previously accepted
> '-> *' with spaces between the arrow and the star,
> will now reject such patterns?
> Is this also what a C compile would do?
Personally, I think '->*' is _not_ really a single token or
operation like '++' in ISO C Standard, so the patch is _not_ correct.
> The problem is that I have
> no idea what it stands for...
> and I never saw '->*' nor '.*' in any C sources.
Indeed, we should never see '->*' nor '.*' in C sources, you know, we
can use '->' or '.' to operate any member of a structure directly, so
why do we need '*' to dereference it?
In compiler principle, I think '->*' should result in a syntax error.
Here is a sample:
struct a {
int a;
int b;
};
int main(int argc, char **argv)
{
struct a test;
test.a = 10;
test.*a = 2;
}
$ gcc main.c
main.c: In function 'main':
main.c:10: error: expected identifier before '*' token
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-25 14:10 ` Jiang Jilin
@ 2009-08-25 15:11 ` Andreas Schwab
0 siblings, 0 replies; 12+ messages in thread
From: Andreas Schwab @ 2009-08-25 15:11 UTC (permalink / raw)
To: Jiang Jilin; +Cc: Pierre Muller, Keith Seitz, tromey, gdb-patches
Jiang Jilin <freephp@gmail.com> writes:
> On Tue, Aug 25, 2009 at 5:40 PM, Pierre Muller<muller@ics.u-strasbg.fr> wrote:
>> Just for information:
>> doesn't this mean that
>> the parser that previously accepted
>> '-> *' with spaces between the arrow and the star,
>> will now reject such patterns?
>> Is this also what a C compile would do?
>
> Personally, I think '->*' is _not_ really a single token or
> operation like '++' in ISO C Standard, so the patch is _not_ correct.
In C++ both `.*' and `->*' are single tokens. In C, in a valid
expression, `*' can never follow `.' or `->'.
Andreas.
--
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E
"And now for something completely different."
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-24 23:06 [RFA] Token cleanup in c-exp.y Keith Seitz
2009-08-24 23:08 ` Tom Tromey
@ 2009-08-25 15:28 ` Matt Rice
2009-08-25 15:46 ` Tom Tromey
2009-08-25 15:47 ` Tom Tromey
2 siblings, 1 reply; 12+ messages in thread
From: Matt Rice @ 2009-08-25 15:28 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches
On Mon, Aug 24, 2009 at 3:27 PM, Keith Seitz<keiths@redhat.com> wrote:
> Hi,
>
> The attached patch "fixes" two tokens in c-exp.y, "->*" and ".*", which were
> not previously recognized as tokens.
>
looks like it should also apply to objc-exp.y, as it too contains all
the lines removed from c-exp.y.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-25 15:28 ` Matt Rice
@ 2009-08-25 15:46 ` Tom Tromey
0 siblings, 0 replies; 12+ messages in thread
From: Tom Tromey @ 2009-08-25 15:46 UTC (permalink / raw)
To: Matt Rice; +Cc: Keith Seitz, gdb-patches
>>>>> "Matt" == Matt Rice <ratmice@gmail.com> writes:
>> The attached patch "fixes" two tokens in c-exp.y, "->*" and ".*", which were
>> not previously recognized as tokens.
Matt> looks like it should also apply to objc-exp.y, as it too contains all
Matt> the lines removed from c-exp.y.
objc-exp.y has diverged a lot from c-exp.y.
This isn't the only patch that hasn't gone into both.
I think it would be best to merge the two. Ideally someone would
volunteer to be the ObjC maintainer and do this :-) From the ChangeLogs
it looks like the current ObjC maintainer hasn't checked in a patch
since 2003.
Tom
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-24 23:06 [RFA] Token cleanup in c-exp.y Keith Seitz
2009-08-24 23:08 ` Tom Tromey
2009-08-25 15:28 ` Matt Rice
@ 2009-08-25 15:47 ` Tom Tromey
2009-08-25 18:07 ` Keith Seitz
2 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2009-08-25 15:47 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches
>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:
Keith> + {".*", DOT_STAR, BINOP_END, 0}
After reading the follow-up comments I realized that this needs a couple
little changes.
The last field should be 1 here, and then the tokentab2 and tokentab3
logic in yylex needs the same cxx_only treatment as ident_tokens.
I suppose that the "::" operator also needs to be C++-only.
I can do this tomorrow, unless you'd prefer to do it.
Tom
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-25 15:47 ` Tom Tromey
@ 2009-08-25 18:07 ` Keith Seitz
2009-08-25 18:41 ` Tom Tromey
0 siblings, 1 reply; 12+ messages in thread
From: Keith Seitz @ 2009-08-25 18:07 UTC (permalink / raw)
To: tromey; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 934 bytes --]
On 08/25/2009 08:45 AM, Tom Tromey wrote:
>>>>>> "Keith" == Keith Seitz<keiths@redhat.com> writes:
>
> Keith> + {".*", DOT_STAR, BINOP_END, 0}
>
> After reading the follow-up comments I realized that this needs a couple
> little changes.
>
> The last field should be 1 here, and then the tokentab2 and tokentab3
> logic in yylex needs the same cxx_only treatment as ident_tokens.
Yes, indeed. I've fixed that
> I suppose that the "::" operator also needs to be C++-only.
I don't think we can do that. "::" is also used by gdb for non-language
constructs like filename::function and function::variable. There are
several scattered tests on this already.
New patch attached.
Keith
2009-08-25 Keith Seitz <keiths@redhat.com>
* c-exp.y (tokentab3): Add new token, ARROW_STAR. Changed all users.
(tokentab2): Add new token, DOT_STAR. Changed all users.
(yylex): Add cxx_only check for tokentab2 and tokentab3 searches.
[-- Attachment #2: token-fix2.patch --]
[-- Type: text/plain, Size: 1659 bytes --]
Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.60
diff -u -p -r1.60 c-exp.y
--- c-exp.y 25 Aug 2009 00:23:07 -0000 1.60
+++ c-exp.y 25 Aug 2009 17:35:52 -0000
@@ -1683,6 +1683,8 @@ static const struct token tokentab2[] =
{"->", ARROW, BINOP_END, 0},
{"&&", ANDAND, BINOP_END, 0},
{"||", OROR, BINOP_END, 0},
+ /* "::" is *not* only C++: gdb overrides its meaning in several
+ different ways, e.g., 'filename'::func, function::variable. */
{"::", COLONCOLON, BINOP_END, 0},
{"<<", LSH, BINOP_END, 0},
{">>", RSH, BINOP_END, 0},
@@ -1690,7 +1692,7 @@ static const struct token tokentab2[] =
{"!=", NOTEQUAL, BINOP_END, 0},
{"<=", LEQ, BINOP_END, 0},
{">=", GEQ, BINOP_END, 0},
- {".*", DOT_STAR, BINOP_END, 0}
+ {".*", DOT_STAR, BINOP_END, 1}
};
/* Identifier-like tokens. */
@@ -1849,6 +1851,10 @@ yylex (void)
for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
{
+ if (tokentab3[i].cxx_only
+ && parse_language->la_language != language_cplus)
+ break;
+
lexptr += 3;
yylval.opcode = tokentab3[i].opcode;
return tokentab3[i].token;
@@ -1858,6 +1864,10 @@ yylex (void)
for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
{
+ if (tokentab2[i].cxx_only
+ && parse_language->la_language != language_cplus)
+ break;
+
lexptr += 2;
yylval.opcode = tokentab2[i].opcode;
if (in_parse_field && tokentab2[i].token == ARROW)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-25 18:07 ` Keith Seitz
@ 2009-08-25 18:41 ` Tom Tromey
2009-08-25 18:42 ` Keith Seitz
0 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2009-08-25 18:41 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches
>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:
Tom> The last field should be 1 here, and then the tokentab2 and tokentab3
Tom> logic in yylex needs the same cxx_only treatment as ident_tokens.
Keith> Yes, indeed. I've fixed that
Thanks.
Tom> I suppose that the "::" operator also needs to be C++-only.
Keith> I don't think we can do that. "::" is also used by gdb for
Keith> non-language constructs like filename::function and
Keith> function::variable. There are several scattered tests on this already.
Thanks for looking into this and adding the comment.
Keith> New patch attached.
This is ok.
Tom
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFA] Token cleanup in c-exp.y
2009-08-25 18:41 ` Tom Tromey
@ 2009-08-25 18:42 ` Keith Seitz
0 siblings, 0 replies; 12+ messages in thread
From: Keith Seitz @ 2009-08-25 18:42 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 08/25/2009 11:07 AM, Tom Tromey wrote:
> Keith> New patch attached.
>
> This is ok.
I've committed this.
Keith
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2009-08-25 18:41 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-24 23:06 [RFA] Token cleanup in c-exp.y Keith Seitz
2009-08-24 23:08 ` Tom Tromey
2009-08-25 5:03 ` Keith Seitz
2009-08-25 13:45 ` Pierre Muller
2009-08-25 14:10 ` Jiang Jilin
2009-08-25 15:11 ` Andreas Schwab
2009-08-25 15:28 ` Matt Rice
2009-08-25 15:46 ` Tom Tromey
2009-08-25 15:47 ` Tom Tromey
2009-08-25 18:07 ` Keith Seitz
2009-08-25 18:41 ` Tom Tromey
2009-08-25 18:42 ` Keith Seitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox