This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA] Better parsing of const/volatile types
- To: gdb-patches at sources dot redhat dot com, dberlin at cgsoftware dot com, jimb at redhat dot com, taylor at candd dot org
- Subject: Re: [RFA] Better parsing of const/volatile types
- From: Michael Snyder <msnyder at cygnus dot com>
- Date: Thu, 27 Sep 2001 14:11:03 -0700
- Organization: Red Hat
- References: <3BAA9E22.EDF05C48@cygnus.com>
Michael Snyder wrote:
>
> These changes greatly increase GDB's ability to parse type expressions
> containg 'const' and/or 'volatile'. For instance, we can now parse the
> expression (const int * volatile * const *) foo.
Having heard no objections, I will now check this in.
>
> I'm working on a new test script, which I'll submit separately.
>
> Michael
>
> ----------------------------------------------------------------------------------------------------
> Index: parse.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/parse.c,v
> retrieving revision 1.15
> diff -c -3 -p -r1.15 parse.c
> *** parse.c 2001/08/01 18:39:23 1.15
> --- parse.c 2001/09/21 01:41:31
> *************** struct type *
> *** 1255,1260 ****
> --- 1256,1263 ----
> follow_types (struct type *follow_type)
> {
> int done = 0;
> + int make_const = 0;
> + int make_volatile = 0;
> int array_size;
> struct type *range_type;
>
> *************** follow_types (struct type *follow_type)
> *** 1263,1274 ****
> --- 1266,1305 ----
> {
> case tp_end:
> done = 1;
> + if (make_const)
> + follow_type = make_cv_type (make_const,
> + TYPE_VOLATILE (follow_type),
> + follow_type, 0);
> + if (make_volatile)
> + follow_type = make_cv_type (TYPE_CONST (follow_type),
> + make_volatile,
> + follow_type, 0);
> break;
> + case tp_const:
> + make_const = 1;
> + break;
> + case tp_volatile:
> + make_volatile = 1;
> + break;
> case tp_pointer:
> follow_type = lookup_pointer_type (follow_type);
> + if (make_const)
> + follow_type = make_cv_type (make_const,
> + TYPE_VOLATILE (follow_type),
> + follow_type, 0);
> + if (make_volatile)
> + follow_type = make_cv_type (TYPE_CONST (follow_type),
> + make_volatile,
> + follow_type, 0);
> + make_const = make_volatile = 0;
> break;
> case tp_reference:
> follow_type = lookup_reference_type (follow_type);
> + if (make_const)
> + follow_type = make_cv_type (make_const, TYPE_VOLATILE (follow_type), follow_type, 0);
> + if (make_volatile)
> + follow_type = make_cv_type (TYPE_CONST (follow_type), make_volatile, follow_type, 0);
> + make_const = make_volatile = 0;
> break;
> case tp_array:
> array_size = pop_type_int ();
> 2001-09-20 Michael Snyder <msnyder@redhat.com>
> Changes by Daniel Berlin <dan@cgsoftware.com>, to support
> better parsing of const and volatile type expressions.
> * c-exp.y (const_and_volatile, const_or_volatile_noopt,
> const_or_volatile): New non-terminals.
> (ptype): Use new rule for const_or_volatile.
> (typebase): Use new rule for const_or_volatile_noopt.
> * parser-defs.h (enum type_pieces): New values tp_const, tp_volatile.
> * parse.c (follow_types): Handle tp_const and tp_volatile on the
> type stack: call make_cv_type to create new const/volatile type.
>
> Index: parser-defs.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/parser-defs.h,v
> retrieving revision 1.4
> diff -c -3 -p -r1.4 parser-defs.h
> *** parser-defs.h 2001/08/01 18:39:23 1.4
> --- parser-defs.h 2001/09/21 01:41:31
> *************** struct symtoken
> *** 84,90 ****
> An array should be preceded in the list by the size of the array. */
> enum type_pieces
> {
> ! tp_end = -1, tp_pointer, tp_reference, tp_array, tp_function
> };
> /* The stack can contain either an enum type_pieces or an int. */
> union type_stack_elt
> --- 84,96 ----
> An array should be preceded in the list by the size of the array. */
> enum type_pieces
> {
> ! tp_end = -1,
> ! tp_pointer,
> ! tp_reference,
> ! tp_array,
> ! tp_function,
> ! tp_const,
> ! tp_volatile
> };
> /* The stack can contain either an enum type_pieces or an int. */
> union type_stack_elt
> Index: c-exp.y
> ===================================================================
> RCS file: /cvs/src/src/gdb/c-exp.y,v
> retrieving revision 1.4
> diff -c -3 -p -r1.4 c-exp.y
> *** c-exp.y 2001/03/06 08:21:06 1.4
> --- c-exp.y 2001/09/21 01:41:31
> *************** variable: name_not_typename
> *** 720,740 ****
>
>
> ptype : typebase
> ! /* "const" and "volatile" are curently ignored. A type qualifier
> ! before the type is currently handled in the typebase rule.
> ! The reason for recognizing these here (shift/reduce conflicts)
> ! might be obsolete now that some pointer to member rules have
> ! been deleted. */
> ! | typebase CONST_KEYWORD
> ! | typebase VOLATILE_KEYWORD
> ! | typebase abs_decl
> { $$ = follow_types ($1); }
> - | typebase CONST_KEYWORD abs_decl
> - { $$ = follow_types ($1); }
> - | typebase VOLATILE_KEYWORD abs_decl
> - { $$ = follow_types ($1); }
> ;
> !
> abs_decl: '*'
> { push_type (tp_pointer); $$ = 0; }
> | '*' abs_decl
> --- 720,741 ----
>
>
> ptype : typebase
> ! | ptype const_or_volatile abs_decl const_or_volatile
> { $$ = follow_types ($1); }
> ;
> ! const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
> ! | VOLATILE_KEYWORD CONST_KEYWORD
> ! ;
> ! const_or_volatile_noopt: const_and_volatile
> ! { push_type (tp_const); push_type (tp_volatile);}
> ! | CONST_KEYWORD
> ! { push_type (tp_const);}
> ! | VOLATILE_KEYWORD
> ! { push_type (tp_volatile); }
> ! ;
> ! const_or_volatile: const_or_volatile_noopt
> ! |
> ! ;
> abs_decl: '*'
> { push_type (tp_pointer); $$ = 0; }
> | '*' abs_decl
> *************** typebase /* Implements (approximately):
> *** 847,857 ****
> { $$ = lookup_template_type(copy_name($2), $4,
> expression_context_block);
> }
> ! /* "const" and "volatile" are curently ignored. A type qualifier
> ! after the type is handled in the ptype rule. I think these could
> ! be too. */
> ! | CONST_KEYWORD typebase { $$ = $2; }
> ! | VOLATILE_KEYWORD typebase { $$ = $2; }
> ;
>
> typename: TYPENAME
> --- 848,855 ----
> { $$ = lookup_template_type(copy_name($2), $4,
> expression_context_block);
> }
> ! | const_or_volatile_noopt typebase { $$ = follow_types ($2); }
> ! | typebase const_or_volatile_noopt { $$ = follow_types ($1); }
> ;
>
> typename: TYPENAME