From: "Rob Quill" <rob.quill@gmail.com>
To: gdb@sourceware.org, gdb-patches@sourceware.org
Subject: Re: Scope Checking Patch
Date: Sun, 10 Jun 2007 20:55:00 -0000 [thread overview]
Message-ID: <baf6008d0706101355x168326f2xf16d780e48359af0@mail.gmail.com> (raw)
In-Reply-To: <baf6008d0706101354i701690d9ped8dc9ab6e3ccbcc@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 973 bytes --]
On 10/06/07, Rob Quill <rob.quill@gmail.com> wrote:
> Hi all,
>
> This is the first patch I have ever submitted to an open source
> project, so I'm a little bit unsure of the process. The patch adds the
> ability to check if a variable is in scope, as descibed here:
>
> http://sourceware.org/ml/gdb/2006-11/msg00149.html
>
> I have attached the diffs for the two files I've changed. However, I
> am seeing some regressions against the current cvs, which I can't
> understand, so I was wondering if a) the regressions happen for anyone
> esle? (which presumably it does), b) if anyone could offer any
> suggestions as to the cause, and c) give thier opinions on the patch.
>
> The patch allows the scope of constants, variables and variables in
> classes/structures, by using $in_scope(variable_name) as an
> expression, with value 1 if variable_name is in scope and 0 if it is
> not.
>
> Any help and thoughts you can offer is much appreciated.
...Diffs attached, sorry.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: c-exp.patch --]
[-- Type: text/x-patch; name="c-exp.patch", Size: 2625 bytes --]
103a104,106
> /* Global variable denoting whether we are only interested in scope, not value */
> int check_scope = 0;
>
203a207,208
> /* $in_scope opperator */
> %left IN_SCOPE
246a252,256
> exp : IN_SCOPE
> { check_scope = 1; }
> '(' exp ')'
> ;
>
586c596,602
< error ("No symbol \"%s\" in specified context.",
---
> {
> /* Case for scope checking. If scope is being checked and
> the symbol is not in scope, return an expresison of
> value 0. */
> if(check_scope == 0)
> {
> error ("No symbol \"%s\" in specified context.",
587a604,614
> }
> else
> {
> YYSTYPE val;
> 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);
> }
> }
666,667c693,708
< error ("No symbol \"%s\" in current context.", name);
< }
---
> {
> if(check_scope == 0)
> {
> error ("No symbol \"%s\" in current context.", name);
> }
> else
> {
> YYSTYPE val;
> 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);
> }
> }
> }
721,722c762,774
< error ("No symbol \"%s\" in current context.",
< copy_name ($1.stoken));
---
> {
> if(check_scope == 0)
> error ("No symbol \"%s\" in current context.", copy_name ($1.stoken));
> else
> {
> YYSTYPE val;
> 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);
> }
> }
1260a1313,1317
> static const struct token tokentab9[] =
> {
> {"$in_scope", IN_SCOPE, BINOP_END}
> };
>
1322a1380,1388
> /* 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;
> }
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: eval.patch --]
[-- Type: text/x-patch; name="eval.patch", Size: 1294 bytes --]
48a49,51
> /* Variable denoting is scope is being checked */
> extern int check_scope;
>
167c170,179
< return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
---
>
> /* Modifications so that if we are checking scope we can
> reset the value of the variable to 0, so we don't check
> scope when we don't want to */
> struct value *val = evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
>
> if(check_scope == 1)
> check_scope = 0;
>
> return val;
474a487,494
> /* Special case, if we are checking scope and a variable is
> in scope, return a expression of value 1. */
> if(check_scope == 0)
> return value_of_variable (exp->elts[pc + 2].symbol,
> exp->elts[pc + 1].block);
> else
> return value_from_longest (builtin_type_int, (LONGEST) 1);
>
1336c1356,1368
< arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
---
>
> /* Temporalily disable scope checking while we evaluate
> the subexpression, so that the correct type of value
> is returned */
> if(check_scope == 1)
> {
> check_scope = 0;
> arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
> check_scope = 1;
> }
> else
> arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
>
next prev parent reply other threads:[~2007-06-10 20:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-10 20:54 Rob Quill
2007-06-10 20:55 ` Rob Quill [this message]
2007-06-11 17:12 ` Jim Blandy
2007-06-11 17:31 ` Rob Quill
2007-06-13 13:33 ` Rob Quill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=baf6008d0706101355x168326f2xf16d780e48359af0@mail.gmail.com \
--to=rob.quill@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox