Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / go-exp.y
index f2f359609cd783b40f73f329619d674c585dbe3e..47570d59111bcd7851aa807371e897860fc9849b 100644 (file)
@@ -1,6 +1,6 @@
 /* YACC parser for Go expressions, for GDB.
 
-   Copyright (C) 2012-2017 Free Software Foundation, Inc.
+   Copyright (C) 2012-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -81,7 +81,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 %}
 
@@ -97,7 +97,7 @@ void yyerror (const char *);
       struct type *type;
     } typed_val_int;
     struct {
-      DOUBLEST dval;
+      gdb_byte val[16];
       struct type *type;
     } typed_val_float;
     struct stoken sval;
@@ -115,8 +115,6 @@ void yyerror (const char *);
 /* YYSTYPE gets defined by %union.  */
 static int parse_number (struct parser_state *,
                         const char *, int, int, YYSTYPE *);
-static int parse_go_float (struct gdbarch *gdbarch, const char *p, int len,
-                          DOUBLEST *d, struct type **t);
 %}
 
 %type <voidval> exp exp1 type_exp start variable lcurly
@@ -436,10 +434,10 @@ exp       :       NAME_OR_INT
 
 
 exp    :       FLOAT
-                       { write_exp_elt_opcode (pstate, OP_DOUBLE);
+                       { write_exp_elt_opcode (pstate, OP_FLOAT);
                          write_exp_elt_type (pstate, $1.type);
-                         write_exp_elt_dblcst (pstate, $1.dval);
-                         write_exp_elt_opcode (pstate, OP_DOUBLE); }
+                         write_exp_elt_floatcst (pstate, $1.val);
+                         write_exp_elt_opcode (pstate, OP_FLOAT); }
        ;
 
 exp    :       variable
@@ -554,12 +552,7 @@ variable:  name_not_typename
                          if (sym.symbol)
                            {
                              if (symbol_read_needs_frame (sym.symbol))
-                               {
-                                 if (innermost_block == 0
-                                     || contained_in (sym.block,
-                                                      innermost_block))
-                                   innermost_block = sym.block;
-                               }
+                               innermost_block.update (sym);
 
                              write_exp_elt_opcode (pstate, OP_VAR_VALUE);
                              write_exp_elt_block (pstate, sym.block);
@@ -634,24 +627,6 @@ name_not_typename
 
 %%
 
-/* Wrapper on parse_c_float to get the type right for Go.  */
-
-static int
-parse_go_float (struct gdbarch *gdbarch, const char *p, int len,
-               DOUBLEST *d, struct type **t)
-{
-  int result = parse_c_float (gdbarch, p, len, d, t);
-  const struct builtin_type *builtin_types = builtin_type (gdbarch);
-  const struct builtin_go_type *builtin_go_types = builtin_go_type (gdbarch);
-
-  if (*t == builtin_types->builtin_float)
-    *t = builtin_go_types->builtin_float32;
-  else if (*t == builtin_types->builtin_double)
-    *t = builtin_go_types->builtin_float64;
-
-  return result;
-}
-
 /* Take care of parsing a number (anything that starts with a digit).
    Set yylval and return the token type; update lexptr.
    LEN is the number of characters in it.  */
@@ -688,10 +663,34 @@ parse_number (struct parser_state *par_state,
 
   if (parsed_float)
     {
-      if (! parse_go_float (parse_gdbarch (par_state), p, len,
-                           &putithere->typed_val_float.dval,
-                           &putithere->typed_val_float.type))
-       return ERROR;
+      const struct builtin_go_type *builtin_go_types
+       = builtin_go_type (parse_gdbarch (par_state));
+
+      /* Handle suffixes: 'f' for float32, 'l' for long double.
+        FIXME: This appears to be an extension -- do we want this?  */
+      if (len >= 1 && tolower (p[len - 1]) == 'f')
+       {
+         putithere->typed_val_float.type
+           = builtin_go_types->builtin_float32;
+         len--;
+       }
+      else if (len >= 1 && tolower (p[len - 1]) == 'l')
+       {
+         putithere->typed_val_float.type
+           = parse_type (par_state)->builtin_long_double;
+         len--;
+       }
+      /* Default type for floating-point literals is float64.  */
+      else
+        {
+         putithere->typed_val_float.type
+           = builtin_go_types->builtin_float64;
+        }
+
+      if (!parse_float (p, len,
+                       putithere->typed_val_float.type,
+                       putithere->typed_val_float.val))
+        return ERROR;
       return FLOAT;
     }
 
@@ -1089,7 +1088,7 @@ lex_one_token (struct parser_state *par_state)
            last_was_structop = 1;
          goto symbol;          /* Nope, must be a symbol. */
        }
-      /* FALL THRU into number case.  */
+      /* FALL THRU.  */
 
     case '0':
     case '1':
@@ -1560,20 +1559,13 @@ yylex (void)
 int
 go_parse (struct parser_state *par_state)
 {
-  int result;
-  struct cleanup *back_to;
-
   /* Setting up the parser state.  */
+  scoped_restore pstate_restore = make_scoped_restore (&pstate);
   gdb_assert (par_state != NULL);
   pstate = par_state;
 
-  /* Note that parsing (within yyparse) freely installs cleanups
-     assuming they'll be run here (below).  */
-  back_to = make_cleanup (null_cleanup, NULL);
-
   scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
                                                        parser_debug);
-  make_cleanup_clear_parser_state (&pstate);
 
   /* Initialize some state used by the lexer.  */
   last_was_structop = 0;
@@ -1583,16 +1575,14 @@ go_parse (struct parser_state *par_state)
   popping = 0;
   name_obstack.clear ();
 
-  result = yyparse ();
-  do_cleanups (back_to);
-  return result;
+  return yyparse ();
 }
 
-void
+static void
 yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, lexptr);
 }
This page took 0.031349 seconds and 4 git commands to generate.