Reset terminal styles
[deliverable/binutils-gdb.git] / gdb / f-exp.y
index 7e9e234bf68fc309f85726dfcbe83fd12f69d52c..390bd45081b7b44944b2d4c7813432b3d50680a2 100644 (file)
@@ -1,6 +1,6 @@
 
 /* YACC parser for Fortran expressions, for GDB.
-   Copyright (C) 1986-2017 Free Software Foundation, Inc.
+   Copyright (C) 1986-2018 Free Software Foundation, Inc.
 
    Contributed by Motorola.  Adapted from the C parser by Farooq Butt
    (fmbutt@engage.sps.mot.com).
@@ -72,7 +72,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 static void growbuf_by_size (int);
 
@@ -91,7 +91,10 @@ static int match_string_literal (void);
       LONGEST val;
       struct type *type;
     } typed_val;
-    DOUBLEST dval;
+    struct {
+      gdb_byte val[16];
+      struct type *type;
+    } typed_val_float;
     struct symbol *sym;
     struct type *tval;
     struct stoken sval;
@@ -122,7 +125,7 @@ static int parse_number (struct parser_state *, const char *, int,
 %type <tval> ptype
 
 %token <typed_val> INT
-%token <dval> FLOAT
+%token <typed_val_float> FLOAT
 
 /* Both NAME and TYPENAME tokens represent symbols in the input,
    and both convey their data as strings.
@@ -414,12 +417,10 @@ exp       :       NAME_OR_INT
        ;
 
 exp    :       FLOAT
-                       { write_exp_elt_opcode (pstate, OP_DOUBLE);
-                         write_exp_elt_type (pstate,
-                                             parse_f_type (pstate)
-                                             ->builtin_real_s8);
-                         write_exp_elt_dblcst (pstate, $1);
-                         write_exp_elt_opcode (pstate, OP_DOUBLE); }
+                       { write_exp_elt_opcode (pstate, OP_FLOAT);
+                         write_exp_elt_type (pstate, $1.type);
+                         write_exp_elt_floatcst (pstate, $1.val);
+                         write_exp_elt_opcode (pstate, OP_FLOAT); }
        ;
 
 exp    :       variable
@@ -460,12 +461,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);
                              write_exp_elt_sym (pstate, sym.symbol);
@@ -647,16 +643,22 @@ parse_number (struct parser_state *par_state,
   if (parsed_float)
     {
       /* It's a float since it contains a point or an exponent.  */
-      /* [dD] is not understood as an exponent by atof, change it to 'e'.  */
+      /* [dD] is not understood as an exponent by parse_float,
+        change it to 'e'.  */
       char *tmp, *tmp2;
 
       tmp = xstrdup (p);
       for (tmp2 = tmp; *tmp2; ++tmp2)
        if (*tmp2 == 'd' || *tmp2 == 'D')
          *tmp2 = 'e';
-      putithere->dval = atof (tmp);
+
+      /* FIXME: Should this use different types?  */
+      putithere->typed_val_float.type = parse_f_type (pstate)->builtin_real_s8;
+      bool parsed = parse_float (tmp, len,
+                                putithere->typed_val_float.type,
+                                putithere->typed_val_float.val);
       free (tmp);
-      return FLOAT;
+      return parsed? FLOAT : ERROR;
     }
 
   /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
@@ -921,7 +923,7 @@ yylex (void)
 {
   int c;
   int namelen;
-  unsigned int i,token;
+  unsigned int token;
   const char *tokstart;
   
  retry:
@@ -935,7 +937,7 @@ yylex (void)
   
   if (*lexptr == '.')
     { 
-      for (i = 0; boolean_values[i].name != NULL; i++)
+      for (int i = 0; boolean_values[i].name != NULL; i++)
        {
          if (strncmp (tokstart, boolean_values[i].name,
                       strlen (boolean_values[i].name)) == 0)
@@ -949,7 +951,7 @@ yylex (void)
   
   /* See if it is a special .foo. operator.  */
   
-  for (i = 0; dot_ops[i].oper != NULL; i++)
+  for (int i = 0; dot_ops[i].oper != NULL; i++)
     if (strncmp (tokstart, dot_ops[i].oper,
                 strlen (dot_ops[i].oper)) == 0)
       {
@@ -1006,7 +1008,7 @@ yylex (void)
       /* Might be a floating point number.  */
       if (lexptr[1] < '0' || lexptr[1] > '9')
        goto symbol;            /* Nope, must be a symbol.  */
-      /* FALL THRU into number case.  */
+      /* FALL THRU.  */
       
     case '0':
     case '1':
@@ -1118,7 +1120,7 @@ yylex (void)
   
   /* Catch specific keywords.  */
   
-  for (i = 0; f77_keywords[i].oper != NULL; i++)
+  for (int i = 0; f77_keywords[i].oper != NULL; i++)
     if (strlen (f77_keywords[i].oper) == namelen
        && strncmp (tokstart, f77_keywords[i].oper, namelen) == 0)
       {
@@ -1149,10 +1151,9 @@ yylex (void)
       VAR_DOMAIN,
       MODULE_DOMAIN
     };
-    int i;
     int hextype;
 
-    for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
+    for (int i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
       {
        /* Initialize this in case we *don't* use it in this call; that
           way we can refer to it unconditionally below.  */
@@ -1206,23 +1207,19 @@ yylex (void)
 int
 f_parse (struct parser_state *par_state)
 {
-  int result;
-  struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
-
   /* Setting up the parser state.  */
+  scoped_restore pstate_restore = make_scoped_restore (&pstate);
   gdb_assert (par_state != NULL);
   pstate = par_state;
 
-  result = yyparse ();
-  do_cleanups (c);
-  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.027116 seconds and 4 git commands to generate.