This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Scope Checking Patch


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.
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;
>       }
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);
> 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]