ELF: Add run-time tests for -z now
[deliverable/binutils-gdb.git] / gdb / cp-name-parser.y
index 5278c05afe91ef64f4e7b88cecc4a78955537586..78745cb5c7e4a6693bbd9e7ed6bb9d76d178bfe5 100644 (file)
@@ -173,7 +173,7 @@ static struct demangle_component *d_binary (const char *,
 
 int yyparse (void);
 static int yylex (void);
-static void yyerror (char *);
+static void yyerror (const char *);
 
 /* Enable yydebug for the stand-alone parser.  */
 #ifdef TEST_CPNAMES
@@ -196,15 +196,6 @@ fill_comp (enum demangle_component_type d_type, struct demangle_component *lhs,
   return ret;
 }
 
-static struct demangle_component *
-make_empty (enum demangle_component_type d_type)
-{
-  struct demangle_component *ret = d_grab ();
-  ret->type = d_type;
-  ret->d_printing = 0;
-  return ret;
-}
-
 static struct demangle_component *
 make_operator (const char *name, int args)
 {
@@ -433,9 +424,7 @@ function
 
 demangler_special
                :       DEMANGLER_SPECIAL start
-                       { $$ = make_empty ((enum demangle_component_type) $1);
-                         d_left ($$) = $2;
-                         d_right ($$) = NULL; }
+                       { $$ = fill_comp ((enum demangle_component_type) $1, $2, NULL); }
                |       CONSTRUCTION_VTABLE start CONSTRUCTION_IN start
                        { $$ = fill_comp (DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE, $2, $4); }
                ;
@@ -600,30 +589,22 @@ ext_only_name     :       nested_name unqualified_name
                ;
 
 nested_name    :       NAME COLONCOLON
-                       { $$.comp = make_empty (DEMANGLE_COMPONENT_QUAL_NAME);
-                         d_left ($$.comp) = $1;
-                         d_right ($$.comp) = NULL;
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $1, NULL);
                          $$.last = $$.comp;
                        }
                |       nested_name NAME COLONCOLON
                        { $$.comp = $1.comp;
-                         d_right ($1.last) = make_empty (DEMANGLE_COMPONENT_QUAL_NAME);
+                         d_right ($1.last) = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $2, NULL);
                          $$.last = d_right ($1.last);
-                         d_left ($$.last) = $2;
-                         d_right ($$.last) = NULL;
                        }
                |       templ COLONCOLON
-                       { $$.comp = make_empty (DEMANGLE_COMPONENT_QUAL_NAME);
-                         d_left ($$.comp) = $1;
-                         d_right ($$.comp) = NULL;
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $1, NULL);
                          $$.last = $$.comp;
                        }
                |       nested_name templ COLONCOLON
                        { $$.comp = $1.comp;
-                         d_right ($1.last) = make_empty (DEMANGLE_COMPONENT_QUAL_NAME);
+                         d_right ($1.last) = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $2, NULL);
                          $$.last = d_right ($1.last);
-                         d_left ($$.last) = $2;
-                         d_right ($$.last) = NULL;
                        }
                ;
 
@@ -761,41 +742,34 @@ builtin_type      :       int_seq
                ;
 
 ptr_operator   :       '*' qualifiers_opt
-                       { $$.comp = make_empty (DEMANGLE_COMPONENT_POINTER);
-                         $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL;
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_POINTER, NULL, NULL);
                          $$.last = &d_left ($$.comp);
                          $$.comp = d_qualify ($$.comp, $2, 0); }
                /* g++ seems to allow qualifiers after the reference?  */
                |       '&'
-                       { $$.comp = make_empty (DEMANGLE_COMPONENT_REFERENCE);
-                         $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL;
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_REFERENCE, NULL, NULL);
+                         $$.last = &d_left ($$.comp); }
+               |       ANDAND
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_RVALUE_REFERENCE, NULL, NULL);
                          $$.last = &d_left ($$.comp); }
                |       nested_name '*' qualifiers_opt
-                       { $$.comp = make_empty (DEMANGLE_COMPONENT_PTRMEM_TYPE);
-                         $$.comp->u.s_binary.left = $1.comp;
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_PTRMEM_TYPE, $1.comp, NULL);
                          /* Convert the innermost DEMANGLE_COMPONENT_QUAL_NAME to a DEMANGLE_COMPONENT_NAME.  */
                          *$1.last = *d_left ($1.last);
-                         $$.comp->u.s_binary.right = NULL;
                          $$.last = &d_right ($$.comp);
                          $$.comp = d_qualify ($$.comp, $3, 0); }
                |       COLONCOLON nested_name '*' qualifiers_opt
-                       { $$.comp = make_empty (DEMANGLE_COMPONENT_PTRMEM_TYPE);
-                         $$.comp->u.s_binary.left = $2.comp;
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_PTRMEM_TYPE, $2.comp, NULL);
                          /* Convert the innermost DEMANGLE_COMPONENT_QUAL_NAME to a DEMANGLE_COMPONENT_NAME.  */
                          *$2.last = *d_left ($2.last);
-                         $$.comp->u.s_binary.right = NULL;
                          $$.last = &d_right ($$.comp);
                          $$.comp = d_qualify ($$.comp, $4, 0); }
                ;
 
 array_indicator        :       '[' ']'
-                       { $$ = make_empty (DEMANGLE_COMPONENT_ARRAY_TYPE);
-                         d_left ($$) = NULL;
-                       }
+                       { $$ = fill_comp (DEMANGLE_COMPONENT_ARRAY_TYPE, NULL, NULL); }
                |       '[' INT ']'
-                       { $$ = make_empty (DEMANGLE_COMPONENT_ARRAY_TYPE);
-                         d_left ($$) = $2;
-                       }
+                       { $$ = fill_comp (DEMANGLE_COMPONENT_ARRAY_TYPE, $2, NULL); }
                ;
 
 /* Details of this approach inspired by the G++ < 3.4 parser.  */
@@ -948,8 +922,7 @@ direct_declarator
                          $$.last = &d_right ($2);
                        }
                |       colon_ext_name
-                       { $$.comp = make_empty (DEMANGLE_COMPONENT_TYPED_NAME);
-                         d_left ($$.comp) = $1;
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, NULL);
                          $$.last = &d_right ($$.comp);
                        }
                ;
@@ -965,8 +938,7 @@ declarator_1        :       ptr_operator declarator_1
                          $$.last = $1.last;
                          *$2.last = $1.comp; }
                |       colon_ext_name
-                       { $$.comp = make_empty (DEMANGLE_COMPONENT_TYPED_NAME);
-                         d_left ($$.comp) = $1;
+                       { $$.comp = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, NULL);
                          $$.last = &d_right ($$.comp);
                        }
                |       direct_declarator_1
@@ -1962,7 +1934,7 @@ yylex (void)
 }
 
 static void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   if (global_errmsg)
     return;
@@ -2057,10 +2029,9 @@ cp_merge_demangle_parse_infos (struct demangle_parse_info *dest,
 }
 
 /* Convert a demangled name to a demangle_component tree.  On success,
-   a structure containing the root of the new tree is returned; it must
-   be freed by calling cp_demangled_name_parse_free. On error, NULL is
-   returned, and an error message will be set in *ERRMSG (which does
-   not need to be freed).  */
+   a structure containing the root of the new tree is returned.  On
+   error, NULL is returned, and an error message will be set in
+   *ERRMSG (which does not need to be freed).  */
 
 struct std::unique_ptr<demangle_parse_info>
 cp_demangled_name_to_comp (const char *demangled_name, const char **errmsg)
@@ -2161,7 +2132,6 @@ main (int argc, char **argv)
   char buf[65536];
   int arg;
   const char *errmsg;
-  struct demangle_parse_info *result;
 
   arg = 1;
   if (argv[arg] && strcmp (argv[arg], "--debug") == 0)
@@ -2187,7 +2157,9 @@ main (int argc, char **argv)
              printf ("%s\n", buf);
            continue;
          }
-       result = cp_demangled_name_to_comp (str2, &errmsg);
+
+       std::unique_ptr<demangle_parse_info> result
+         = cp_demangled_name_to_comp (str2, &errmsg);
        if (result == NULL)
          {
            fputs (errmsg, stderr);
@@ -2196,7 +2168,6 @@ main (int argc, char **argv)
          }
 
        cp_print (result->tree);
-       cp_demangled_name_parse_free (result);
 
        free (str2);
        if (c)
@@ -2208,7 +2179,8 @@ main (int argc, char **argv)
       }
   else
     {
-      result = cp_demangled_name_to_comp (argv[arg], &errmsg);
+      std::unique_ptr<demangle_parse_info> result
+       = cp_demangled_name_to_comp (argv[arg], &errmsg);
       if (result == NULL)
        {
          fputs (errmsg, stderr);
@@ -2216,7 +2188,6 @@ main (int argc, char **argv)
          return 0;
        }
       cp_print (result->tree);
-      cp_demangled_name_parse_free (result);
       putchar ('\n');
     }
   return 0;
This page took 0.025902 seconds and 4 git commands to generate.