* doublest.h (DOUBLEST_PRINT_FORMAT): Remove % from string.
[deliverable/binutils-gdb.git] / gdb / c-exp.y
index b67c7e1a8db6a77381c1ec1ec705f63cb26b7d1c..b5207212f7d2e2ff582632deb37568bcd5ec52d2 100644 (file)
@@ -1,6 +1,7 @@
 /* YACC parser for C expressions, for GDB.
    Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
+   1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008
+   Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -52,6 +53,7 @@ Boston, MA 02110-1301, USA.  */
 #include "charset.h"
 #include "block.h"
 #include "cp-support.h"
+#include "dfp.h"
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -130,6 +132,10 @@ void yyerror (char *);
       DOUBLEST dval;
       struct type *type;
     } typed_val_float;
+    struct {
+      gdb_byte val[16];
+      struct type *type;
+    } typed_val_decfloat;
     struct symbol *sym;
     struct type *tval;
     struct stoken sval;
@@ -162,6 +168,7 @@ static int parse_number (char *, int, int, YYSTYPE *);
 
 %token <typed_val_int> INT
 %token <typed_val_float> FLOAT
+%token <typed_val_decfloat> DECFLOAT
 
 /* Both NAME and TYPENAME tokens represent symbols in the input,
    and both convey their data as strings.
@@ -496,6 +503,13 @@ exp        :       FLOAT
                          write_exp_elt_opcode (OP_DOUBLE); }
        ;
 
+exp    :       DECFLOAT
+                       { write_exp_elt_opcode (OP_DECFLOAT);
+                         write_exp_elt_type ($1.type);
+                         write_exp_elt_decfloatcst ($1.val);
+                         write_exp_elt_opcode (OP_DECFLOAT); }
+       ;
+
 exp    :       variable
        ;
 
@@ -1077,7 +1091,41 @@ parse_number (p, len, parsed_float, putithere)
       char saved_char = p[len];
 
       p[len] = 0;      /* null-terminate the token */
-      num = sscanf (p, DOUBLEST_SCAN_FORMAT "%s",
+
+      /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
+         point.  Return DECFLOAT.  */
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'f')
+       {
+         p[len - 2] = '\0';
+         putithere->typed_val_decfloat.type
+           = builtin_type (current_gdbarch)->builtin_decfloat;
+         decimal_from_string (putithere->typed_val_decfloat.val, 4, p);
+         p[len] = saved_char;
+         return (DECFLOAT);
+       }
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'd')
+       {
+         p[len - 2] = '\0';
+         putithere->typed_val_decfloat.type
+           = builtin_type (current_gdbarch)->builtin_decdouble;
+         decimal_from_string (putithere->typed_val_decfloat.val, 8, p);
+         p[len] = saved_char;
+         return (DECFLOAT);
+       }
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'l')
+       {
+         p[len - 2] = '\0';
+         putithere->typed_val_decfloat.type
+           = builtin_type (current_gdbarch)->builtin_declong;
+         decimal_from_string (putithere->typed_val_decfloat.val, 16, p);
+         p[len] = saved_char;
+         return (DECFLOAT);
+       }
+
+      num = sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%s",
                    &putithere->typed_val_float.dval, s);
       p[len] = saved_char;     /* restore the input stream */
 
@@ -1096,9 +1144,13 @@ parse_number (p, len, parsed_float, putithere)
            putithere->typed_val_float.type = 
              builtin_type (current_gdbarch)->builtin_long_double;
          else
-           return ERROR;
+           {
+             free (s);
+             return ERROR;
+           }
        }
 
+      free (s);
       return FLOAT;
     }
 
This page took 0.025375 seconds and 4 git commands to generate.