* c-exp.y (%union) <type_stack>: New field.
[deliverable/binutils-gdb.git] / gdb / c-exp.y
index 1e14337da42c7343842e4c91f9ddb27c99ced963..5ea57041d815c7f29509d37576c463282c959ee2 100644 (file)
@@ -157,6 +157,8 @@ void yyerror (char *);
     struct stoken_vector svec;
     struct type **tvec;
     int *ivec;
+
+    struct type_stack *type_stack;
   }
 
 %{
@@ -172,9 +174,11 @@ static struct stoken operator_stoken (const char *);
 /* %type <bval> block */
 
 /* Fancy type parsing.  */
-%type <voidval> func_mod direct_abs_decl abs_decl
 %type <tval> ptype
 %type <lval> array_mod
+%type <tval> conversion_type_id
+
+%type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
 
 %token <typed_val_int> INT
 %token <typed_val_float> FLOAT
@@ -931,9 +935,7 @@ variable:   name_not_typename
        ;
 
 space_identifier : '@' NAME
-               { push_type_address_space (copy_name ($2.stoken));
-                 push_type (tp_space_identifier);
-               }
+               { insert_type_address_space (copy_name ($2.stoken)); }
        ;
 
 const_or_volatile: const_or_volatile_noopt
@@ -952,14 +954,31 @@ const_or_volatile_or_space_identifier:
        |
        ;
 
-abs_decl:      '*'
-                       { push_type (tp_pointer); $$ = 0; }
-       |       '*' abs_decl
-                       { push_type (tp_pointer); $$ = $2; }
+ptr_operator:
+               ptr_operator '*'
+                       { insert_type (tp_pointer); }
+               const_or_volatile_or_space_identifier
+       |       '*' 
+                       { insert_type (tp_pointer); }
+               const_or_volatile_or_space_identifier
        |       '&'
-                       { push_type (tp_reference); $$ = 0; }
-       |       '&' abs_decl
-                       { push_type (tp_reference); $$ = $2; }
+                       { insert_type (tp_reference); }
+       |       '&' ptr_operator
+                       { insert_type (tp_reference); }
+       ;
+
+ptr_operator_ts: ptr_operator
+                       {
+                         $$ = get_type_stack ();
+                         /* This cleanup is eventually run by
+                            c_parse.  */
+                         make_cleanup (type_stack_cleanup, $$);
+                       }
+       ;
+
+abs_decl:      ptr_operator_ts direct_abs_decl
+                       { $$ = append_type_stack ($2, $1); }
+       |       ptr_operator_ts 
        |       direct_abs_decl
        ;
 
@@ -967,20 +986,29 @@ direct_abs_decl: '(' abs_decl ')'
                        { $$ = $2; }
        |       direct_abs_decl array_mod
                        {
+                         push_type_stack ($1);
                          push_type_int ($2);
                          push_type (tp_array);
+                         $$ = get_type_stack ();
                        }
        |       array_mod
                        {
                          push_type_int ($1);
                          push_type (tp_array);
-                         $$ = 0;
+                         $$ = get_type_stack ();
                        }
 
        |       direct_abs_decl func_mod
-                       { push_type (tp_function); }
+                       {
+                         push_type_stack ($1);
+                         push_type (tp_function);
+                         $$ = get_type_stack ();
+                       }
        |       func_mod
-                       { push_type (tp_function); }
+                       {
+                         push_type (tp_function);
+                         $$ = get_type_stack ();
+                       }
        ;
 
 array_mod:     '[' ']'
@@ -990,9 +1018,8 @@ array_mod: '[' ']'
        ;
 
 func_mod:      '(' ')'
-                       { $$ = 0; }
        |       '(' nonempty_typelist ')'
-                       { free ($2); $$ = 0; }
+                       { free ($2); }
        ;
 
 /* We used to try to recognize pointer to member types here, but
@@ -1203,32 +1230,43 @@ nonempty_typelist
        ;
 
 ptype  :       typebase
-       |       ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
+       |       ptype abs_decl
+               {
+                 push_type_stack ($2);
+                 $$ = follow_types ($1);
+               }
+       ;
+
+conversion_type_id: typebase conversion_declarator
                { $$ = follow_types ($1); }
        ;
 
+conversion_declarator:  /* Nothing.  */
+       | ptr_operator conversion_declarator
+       ;
+
 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); 
+                       { insert_type (tp_const);
+                         insert_type (tp_volatile); 
                        }
        |               CONST_KEYWORD
-                       { push_type (tp_const); }
+                       { insert_type (tp_const); }
        |               VOLATILE_KEYWORD
-                       { push_type (tp_volatile); }
+                       { insert_type (tp_volatile); }
        ;
 
 operator:      OPERATOR NEW
                        { $$ = operator_stoken (" new"); }
        |       OPERATOR DELETE
-                       { $$ = operator_stoken (" delete "); }
+                       { $$ = operator_stoken (" delete"); }
        |       OPERATOR NEW '[' ']'
                        { $$ = operator_stoken (" new[]"); }
        |       OPERATOR DELETE '[' ']'
-                       { $$ = operator_stoken (" delete[] "); }
+                       { $$ = operator_stoken (" delete[]"); }
        |       OPERATOR '+'
                        { $$ = operator_stoken ("+"); }
        |       OPERATOR '-'
@@ -1325,7 +1363,7 @@ operator: OPERATOR NEW
                        { $$ = operator_stoken ("()"); }
        |       OPERATOR '[' ']'
                        { $$ = operator_stoken ("[]"); }
-       |       OPERATOR ptype
+       |       OPERATOR conversion_type_id
                        { char *name;
                          long length;
                          struct ui_file *buf = mem_fileopen ();
This page took 0.025924 seconds and 4 git commands to generate.