record-full: Remove unused function netorder16
[deliverable/binutils-gdb.git] / gdb / rust-exp.y
index dffccd0605bb5ef6e2e9d25d8eabd248461a01d7..64b7c55efeb83a1f8fcdda1ad565fd93534c7625 100644 (file)
@@ -1,5 +1,5 @@
 /* Bison parser for Rust expressions, for GDB.
-   Copyright (C) 2016 Free Software Foundation, Inc.
+   Copyright (C) 2016-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -941,16 +941,15 @@ rust_concat3 (const char *s1, const char *s2, const char *s3)
 static const struct rust_op *
 crate_name (const struct rust_op *name)
 {
-  char *crate = rust_crate_for_block (expression_context_block);
+  std::string crate = rust_crate_for_block (expression_context_block);
   struct stoken result;
 
   gdb_assert (name->opcode == OP_VAR_VALUE);
 
-  if (crate == NULL)
+  if (crate.empty ())
     error (_("Could not find crate for current location"));
-  result = make_stoken (obconcat (&work_obstack, "::", crate, "::",
+  result = make_stoken (obconcat (&work_obstack, "::", crate.c_str (), "::",
                                  name->left.sval.ptr, (char *) NULL));
-  xfree (crate);
 
   return ast_path (result, name->right.params);
 }
@@ -974,15 +973,13 @@ super_name (const struct rust_op *ident, unsigned int n_supers)
     {
       int i;
       int len;
-      VEC (int) *offsets = NULL;
+      std::vector<int> offsets;
       unsigned int current_len;
-      struct cleanup *cleanup;
 
-      cleanup = make_cleanup (VEC_cleanup (int), &offsets);
       current_len = cp_find_first_component (scope);
       while (scope[current_len] != '\0')
        {
-         VEC_safe_push (int, offsets, current_len);
+         offsets.push_back (current_len);
          gdb_assert (scope[current_len] == ':');
          /* The "::".  */
          current_len += 2;
@@ -990,13 +987,11 @@ super_name (const struct rust_op *ident, unsigned int n_supers)
                                                  + current_len);
        }
 
-      len = VEC_length (int, offsets);
+      len = offsets.size ();
       if (n_supers >= len)
        error (_("Too many super:: uses from '%s'"), scope);
 
-      offset = VEC_index (int, offsets, len - n_supers);
-
-      do_cleanups (cleanup);
+      offset = offsets[len - n_supers];
     }
   else
     offset = strlen (scope);
@@ -1202,7 +1197,7 @@ starts_raw_string (const char *str)
 /* Return true if STR looks like the end of a raw string that had N
    hashes at the start.  */
 
-static int
+static bool
 ends_raw_string (const char *str, int n)
 {
   int i;
@@ -1210,8 +1205,8 @@ ends_raw_string (const char *str, int n)
   gdb_assert (str[0] == '"');
   for (i = 0; i < n; ++i)
     if (str[i + 1] != '#')
-      return 0;
-  return 1;
+      return false;
+  return true;
 }
 
 /* Lex a string constant.  */
@@ -1288,7 +1283,7 @@ lex_string (void)
 
 /* Return true if STRING starts with whitespace followed by a digit.  */
 
-static int
+static bool
 space_then_number (const char *string)
 {
   const char *p = string;
@@ -1296,14 +1291,14 @@ space_then_number (const char *string)
   while (p[0] == ' ' || p[0] == '\t')
     ++p;
   if (p == string)
-    return 0;
+    return false;
 
   return *p >= '0' && *p <= '9';
 }
 
 /* Return true if C can start an identifier.  */
 
-static int
+static bool
 rust_identifier_start_p (char c)
 {
   return ((c >= 'a' && c <= 'z')
@@ -1424,13 +1419,11 @@ lex_number (void)
   int is_integer = 0;
   int could_be_decimal = 1;
   int implicit_i32 = 0;
-  char *type_name = NULL;
+  const char *type_name = NULL;
   struct type *type;
   int end_index;
   int type_index = -1;
-  int i, out;
-  char *number;
-  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
+  int i;
 
   match = regexec (&number_regex, lexptr, ARRAY_SIZE (subexps), subexps, 0);
   /* Failure means the regexp is broken.  */
@@ -1492,29 +1485,28 @@ lex_number (void)
     }
 
   /* Compute the type name if we haven't already.  */
+  std::string type_name_holder;
   if (type_name == NULL)
     {
       gdb_assert (type_index != -1);
-      type_name = xstrndup (lexptr + subexps[type_index].rm_so,
-                          (subexps[type_index].rm_eo
-                           - subexps[type_index].rm_so));
-      make_cleanup (xfree, type_name);
+      type_name_holder = std::string (lexptr + subexps[type_index].rm_so,
+                                     (subexps[type_index].rm_eo
+                                      - subexps[type_index].rm_so));
+      type_name = type_name_holder.c_str ();
     }
 
   /* Look up the type.  */
   type = rust_type (type_name);
 
   /* Copy the text of the number and remove the "_"s.  */
-  number = xstrndup (lexptr, end_index);
-  make_cleanup (xfree, number);
-  for (i = out = 0; number[i]; ++i)
+  std::string number;
+  for (i = 0; i < end_index && lexptr[i]; ++i)
     {
-      if (number[i] == '_')
+      if (lexptr[i] == '_')
        could_be_decimal = 0;
       else
-       number[out++] = number[i];
+       number.push_back (lexptr[i]);
     }
-  number[out] = '\0';
 
   /* Advance past the match.  */
   lexptr += subexps[0].rm_eo;
@@ -1524,6 +1516,8 @@ lex_number (void)
     {
       uint64_t value;
       int radix = 10;
+      int offset = 0;
+
       if (number[0] == '0')
        {
          if (number[1] == 'x')
@@ -1534,12 +1528,12 @@ lex_number (void)
            radix = 2;
          if (radix != 10)
            {
-             number += 2;
+             offset = 2;
              could_be_decimal = 0;
            }
        }
 
-      value = strtoul (number, NULL, radix);
+      value = strtoul (number.c_str () + offset, NULL, radix);
       if (implicit_i32 && value >= ((uint64_t) 1) << 31)
        type = rust_type ("i64");
 
@@ -1548,11 +1542,10 @@ lex_number (void)
     }
   else
     {
-      rustyylval.typed_val_float.dval = strtod (number, NULL);
+      rustyylval.typed_val_float.dval = strtod (number.c_str (), NULL);
       rustyylval.typed_val_float.type = type;
     }
 
-  do_cleanups (cleanup);
   return is_integer ? (could_be_decimal ? DECIMAL_INTEGER : INTEGER) : FLOAT;
 }
 
@@ -1959,18 +1952,16 @@ static const char *convert_name (struct parser_state *state,
 /* Convert a vector of rust_ops representing types to a vector of
    types.  */
 
-static VEC (type_ptr) *
+static std::vector<struct type *>
 convert_params_to_types (struct parser_state *state, VEC (rust_op_ptr) *params)
 {
   int i;
   const struct rust_op *op;
-  VEC (type_ptr) *result = NULL;
-  struct cleanup *cleanup = make_cleanup (VEC_cleanup (type_ptr), &result);
+  std::vector<struct type *> result;
 
   for (i = 0; VEC_iterate (rust_op_ptr, params, i, op); ++i)
-    VEC_safe_push (type_ptr, result, convert_ast_to_type (state, op));
+    result.push_back (convert_ast_to_type (state, op));
 
-  discard_cleanups (cleanup);
   return result;
 }
 
@@ -2022,46 +2013,37 @@ convert_ast_to_type (struct parser_state *state,
 
     case TYPE_CODE_FUNC:
       {
-       VEC (type_ptr) *args
-         = convert_params_to_types (state, *operation->right.params);
-       struct cleanup *cleanup
-         = make_cleanup (VEC_cleanup (type_ptr), &args);
+       std::vector<struct type *> args
+         (convert_params_to_types (state, *operation->right.params));
        struct type **argtypes = NULL;
 
        type = convert_ast_to_type (state, operation->left.op);
-       if (!VEC_empty (type_ptr, args))
-         argtypes = VEC_address (type_ptr, args);
+       if (!args.empty ())
+         argtypes = args.data ();
 
        result
-         = lookup_function_type_with_arguments (type,
-                                                VEC_length (type_ptr, args),
+         = lookup_function_type_with_arguments (type, args.size (),
                                                 argtypes);
        result = lookup_pointer_type (result);
-
-       do_cleanups (cleanup);
       }
       break;
 
     case TYPE_CODE_STRUCT:
       {
-       VEC (type_ptr) *args
-         = convert_params_to_types (state, *operation->left.params);
-       struct cleanup *cleanup
-         = make_cleanup (VEC_cleanup (type_ptr), &args);
+       std::vector<struct type *> args
+         (convert_params_to_types (state, *operation->left.params));
        int i;
        struct type *type;
        const char *name;
 
        obstack_1grow (&work_obstack, '(');
-       for (i = 0; VEC_iterate (type_ptr, args, i, type); ++i)
+       for (i = 0; i < args.size (); ++i)
          {
-           char *type_name = type_to_string (type);
+           std::string type_name = type_to_string (args[i]);
 
            if (i > 0)
              obstack_1grow (&work_obstack, ',');
-           obstack_grow_str (&work_obstack, type_name);
-
-           xfree (type_name);
+           obstack_grow_str (&work_obstack, type_name.c_str ());
          }
 
        obstack_grow_str0 (&work_obstack, ")");
@@ -2072,8 +2054,6 @@ convert_ast_to_type (struct parser_state *state,
        result = rust_lookup_type (name, expression_context_block);
        if (result == NULL)
          error (_("could not find tuple type '%s'"), name);
-
-       do_cleanups (cleanup);
       }
       break;
 
@@ -2092,35 +2072,29 @@ convert_ast_to_type (struct parser_state *state,
 static const char *
 convert_name (struct parser_state *state, const struct rust_op *operation)
 {
-  VEC (type_ptr) *types;
-  struct cleanup *cleanup;
   int i;
-  struct type *type;
 
   gdb_assert (operation->opcode == OP_VAR_VALUE);
 
   if (operation->right.params == NULL)
     return operation->left.sval.ptr;
 
-  types = convert_params_to_types (state, *operation->right.params);
-  cleanup = make_cleanup (VEC_cleanup (type_ptr), &types);
+  std::vector<struct type *> types
+    (convert_params_to_types (state, *operation->right.params));
 
   obstack_grow_str (&work_obstack, operation->left.sval.ptr);
   obstack_1grow (&work_obstack, '<');
-  for (i = 0; VEC_iterate (type_ptr, types, i, type); ++i)
+  for (i = 0; i < types.size (); ++i)
     {
-      char *type_name = type_to_string (type);
+      std::string type_name = type_to_string (types[i]);
 
       if (i > 0)
        obstack_1grow (&work_obstack, ',');
 
-      obstack_grow_str (&work_obstack, type_name);
-      xfree (type_name);
+      obstack_grow_str (&work_obstack, type_name.c_str ());
     }
   obstack_grow_str0 (&work_obstack, ">");
 
-  do_cleanups (cleanup);
-
   return (const char *) obstack_finish (&work_obstack);
 }
 
@@ -2497,7 +2471,7 @@ rust_parse (struct parser_state *state)
 /* The parser error handler.  */
 
 void
-rustyyerror (char *msg)
+rustyyerror (const char *msg)
 {
   const char *where = prev_lexptr ? prev_lexptr : lexptr;
   error (_("%s in expression, near `%s'."), (msg ? msg : "Error"), where);
This page took 0.031489 seconds and 4 git commands to generate.