Re: New scope checking patch

Rob Quill
2008-01-11T00:52:59Z

Hi,

Please find attached the revised and much simpler patch. One of the
drawbacks of the new patch is that you cannot check the scope of
structure members, which is quite inconvenient, but I can't really fix
that without resorting to the old style of patch.

I think that for the moment this patch is sufficient and definitely
provides and improvement, but I think in future it would be good to be
able to check arbitrary expressions, but as you say in your previous
email, this requires some significant reworking of the patch. It also
depends on how much people will find it useful. Michael, how do you
feel about this? (As you seemed interested in the previous attempt) If
there is enough interest then I am more than happy to spend some time
reworking the old patch at a later date.

Rob

2008-01-11 Rob Quill <rob.quill@gmail.com>
* c-exp.y : Add $in_scope as a type of expression.

Index: gdb/c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.42
diff -r1.42 c-exp.y
210a211,212
> /* $in_scope opperator */
> %left IN_SCOPE
253a256,296
> exp : IN_SCOPE '(' name_not_typename ')'
> {
> YYSTYPE val;
> struct symbol *sym = $3.sym;
>
> if (sym)
> {
> parse_number ("1", 1, 0, &val);
> write_exp_elt_opcode (OP_LONG);
> write_exp_elt_type (val.typed_val_int.type);
> write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
> write_exp_elt_opcode (OP_LONG);
> }
> else
> {
> struct minimal_symbol *msymbol;
> char *arg = copy_name ($3.stoken);
>
> msymbol = lookup_minimal_symbol (arg, NULL, NULL);
> if (msymbol != NULL)
> {
> parse_number ("1", 1, 0, &val);
> write_exp_elt_opcode (OP_LONG);
> write_exp_elt_type (val.typed_val_int.type);
> write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
> write_exp_elt_opcode (OP_LONG);
> }
> else if (!have_full_symbols () && !have_partial_symbols ())
> error ("No symbol table is loaded. Use the \"file\" command.");
> else
> {
> parse_number ("0", 1, 0, &val);
> write_exp_elt_opcode (OP_LONG);
> write_exp_elt_type (val.typed_val_int.type);
> write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
> write_exp_elt_opcode (OP_LONG);
> }
> }
> }
> ;
>
1313a1357,1361
> static const struct token tokentab9[] =
> {
> {"$in_scope", IN_SCOPE, BINOP_END}
> };
>
1375a1424,1432
> /* Code for recognising the $in_scope token. */
> /* See if it is a special token of length 9. */
> for (i = 0; i < sizeof tokentab9 / sizeof tokentab9[0]; i++)
> if (strncmp (tokstart, tokentab9[i].operator, 9) == 0)
> {
> lexptr += 9;
> yylval.opcode = tokentab9[i].opcode;
> return tokentab9[i].token;
> }