Copyright updates for 2007.
[deliverable/binutils-gdb.git] / gdb / c-exp.y
index f11b93e3a2b434e2a0043ff097438d85aa3728e3..cda91774b16291b5ea35a72c18e031303ab8cca4 100644 (file)
@@ -1,7 +1,6 @@
 /* YACC parser for C expressions, for GDB.
-   Copyright 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2003, 2004
-   Free Software Foundation, Inc.
+   Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+   1998, 1999, 2000, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -17,7 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 /* Parse a C expression from text in a string,
    and return the result as a  struct expression  pointer.
@@ -53,9 +53,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "block.h"
 #include "cp-support.h"
 
-/* Flag indicating we're dealing with HP-compiled objects */ 
-extern int hp_som_som_object_present;
-
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
    yacc generated parsers in gdb.  Note that these are only the variables
@@ -259,6 +256,10 @@ exp        :       '-' exp    %prec UNARY
                        { write_exp_elt_opcode (UNOP_NEG); }
        ;
 
+exp    :       '+' exp    %prec UNARY
+                       { write_exp_elt_opcode (UNOP_PLUS); }
+       ;
+
 exp    :       '!' exp    %prec UNARY
                        { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
        ;
@@ -504,7 +505,7 @@ exp :       VARIABLE
 
 exp    :       SIZEOF '(' type ')'     %prec UNARY
                        { write_exp_elt_opcode (OP_LONG);
-                         write_exp_elt_type (builtin_type_int);
+                         write_exp_elt_type (builtin_type (current_gdbarch)->builtin_int);
                          CHECK_TYPEDEF ($3);
                          write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
                          write_exp_elt_opcode (OP_LONG); }
@@ -520,12 +521,12 @@ exp       :       STRING
                          while (count-- > 0)
                            {
                              write_exp_elt_opcode (OP_LONG);
-                             write_exp_elt_type (builtin_type_char);
+                             write_exp_elt_type (builtin_type (current_gdbarch)->builtin_char);
                              write_exp_elt_longcst ((LONGEST)(*sp++));
                              write_exp_elt_opcode (OP_LONG);
                            }
                          write_exp_elt_opcode (OP_LONG);
-                         write_exp_elt_type (builtin_type_char);
+                         write_exp_elt_type (builtin_type (current_gdbarch)->builtin_char);
                          write_exp_elt_longcst ((LONGEST)'\0');
                          write_exp_elt_opcode (OP_LONG);
                          write_exp_elt_opcode (OP_ARRAY);
@@ -537,14 +538,14 @@ exp       :       STRING
 /* C++.  */
 exp     :       TRUEKEYWORD    
                         { write_exp_elt_opcode (OP_LONG);
-                          write_exp_elt_type (builtin_type_bool);
+                          write_exp_elt_type (builtin_type (current_gdbarch)->builtin_bool);
                           write_exp_elt_longcst ((LONGEST) 1);
                           write_exp_elt_opcode (OP_LONG); }
        ;
 
 exp     :       FALSEKEYWORD   
                         { write_exp_elt_opcode (OP_LONG);
-                          write_exp_elt_type (builtin_type_bool);
+                          write_exp_elt_type (builtin_type (current_gdbarch)->builtin_bool);
                           write_exp_elt_longcst ((LONGEST) 0);
                           write_exp_elt_opcode (OP_LONG); }
        ;
@@ -655,8 +656,8 @@ variable:   qualified_name
                          if (msymbol != NULL)
                            {
                              write_exp_msymbol (msymbol,
-                                                lookup_function_type (builtin_type_int),
-                                                builtin_type_int);
+                                                lookup_function_type (builtin_type (current_gdbarch)->builtin_int),
+                                                builtin_type (current_gdbarch)->builtin_int);
                            }
                          else
                            if (!have_full_symbols () && !have_partial_symbols ())
@@ -711,8 +712,8 @@ variable:   name_not_typename
                              if (msymbol != NULL)
                                {
                                  write_exp_msymbol (msymbol,
-                                                    lookup_function_type (builtin_type_int),
-                                                    builtin_type_int);
+                                                    lookup_function_type (builtin_type (current_gdbarch)->builtin_int),
+                                                    builtin_type (current_gdbarch)->builtin_int);
                                }
                              else if (!have_full_symbols () && !have_partial_symbols ())
                                error ("No symbol table is loaded.  Use the \"file\" command.");
@@ -788,7 +789,7 @@ func_mod:   '(' ')'
                        { free ($2); $$ = 0; }
        ;
 
-/* We used to try to recognize more pointer to member types here, but
+/* We used to try to recognize pointer to member types here, but
    that didn't work (shift/reduce conflicts meant that these rules never
    got executed).  The problem is that
      int (foo::bar::baz::bizzle)
@@ -797,69 +798,67 @@ func_mod: '(' ')'
    is a pointer to member type.  Stroustrup loses again!  */
 
 type   :       ptype
-       |       typebase COLONCOLON '*'
-                       { $$ = lookup_member_type (builtin_type_int, $1); }
        ;
 
 typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
        :       TYPENAME
                        { $$ = $1.type; }
        |       INT_KEYWORD
-                       { $$ = builtin_type_int; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_int; }
        |       LONG
-                       { $$ = builtin_type_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long; }
        |       SHORT
-                       { $$ = builtin_type_short; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_short; }
        |       LONG INT_KEYWORD
-                       { $$ = builtin_type_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long; }
        |       LONG SIGNED_KEYWORD INT_KEYWORD
-                       { $$ = builtin_type_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long; }
        |       LONG SIGNED_KEYWORD
-                       { $$ = builtin_type_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long; }
        |       SIGNED_KEYWORD LONG INT_KEYWORD
-                       { $$ = builtin_type_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long; }
        |       UNSIGNED LONG INT_KEYWORD
-                       { $$ = builtin_type_unsigned_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long; }
        |       LONG UNSIGNED INT_KEYWORD
-                       { $$ = builtin_type_unsigned_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long; }
        |       LONG UNSIGNED
-                       { $$ = builtin_type_unsigned_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long; }
        |       LONG LONG
-                       { $$ = builtin_type_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long_long; }
        |       LONG LONG INT_KEYWORD
-                       { $$ = builtin_type_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long_long; }
        |       LONG LONG SIGNED_KEYWORD INT_KEYWORD
-                       { $$ = builtin_type_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long_long; }
        |       LONG LONG SIGNED_KEYWORD
-                       { $$ = builtin_type_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long_long; }
        |       SIGNED_KEYWORD LONG LONG
-                       { $$ = builtin_type_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long_long; }
        |       SIGNED_KEYWORD LONG LONG INT_KEYWORD
-                       { $$ = builtin_type_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long_long; }
        |       UNSIGNED LONG LONG
-                       { $$ = builtin_type_unsigned_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long_long; }
        |       UNSIGNED LONG LONG INT_KEYWORD
-                       { $$ = builtin_type_unsigned_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long_long; }
        |       LONG LONG UNSIGNED
-                       { $$ = builtin_type_unsigned_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long_long; }
        |       LONG LONG UNSIGNED INT_KEYWORD
-                       { $$ = builtin_type_unsigned_long_long; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_long_long; }
        |       SHORT INT_KEYWORD
-                       { $$ = builtin_type_short; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_short; }
        |       SHORT SIGNED_KEYWORD INT_KEYWORD
-                       { $$ = builtin_type_short; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_short; }
        |       SHORT SIGNED_KEYWORD
-                       { $$ = builtin_type_short; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_short; }
        |       UNSIGNED SHORT INT_KEYWORD
-                       { $$ = builtin_type_unsigned_short; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_short; }
        |       SHORT UNSIGNED 
-                       { $$ = builtin_type_unsigned_short; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_short; }
        |       SHORT UNSIGNED INT_KEYWORD
-                       { $$ = builtin_type_unsigned_short; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_short; }
        |       DOUBLE_KEYWORD
-                       { $$ = builtin_type_double; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_double; }
        |       LONG DOUBLE_KEYWORD
-                       { $$ = builtin_type_long_double; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_long_double; }
        |       STRUCT name
                        { $$ = lookup_struct (copy_name ($2),
                                              expression_context_block); }
@@ -875,11 +874,11 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
        |       UNSIGNED typename
                        { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
        |       UNSIGNED
-                       { $$ = builtin_type_unsigned_int; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_unsigned_int; }
        |       SIGNED_KEYWORD typename
                        { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
        |       SIGNED_KEYWORD
-                       { $$ = builtin_type_int; }
+                       { $$ = builtin_type (current_gdbarch)->builtin_int; }
                 /* It appears that this rule for templates is never
                    reduced; template recognition happens by lookahead
                    in the token processing code in yylex. */         
@@ -969,19 +968,19 @@ typename: TYPENAME
                {
                  $$.stoken.ptr = "int";
                  $$.stoken.length = 3;
-                 $$.type = builtin_type_int;
+                 $$.type = builtin_type (current_gdbarch)->builtin_int;
                }
        |       LONG
                {
                  $$.stoken.ptr = "long";
                  $$.stoken.length = 4;
-                 $$.type = builtin_type_long;
+                 $$.type = builtin_type (current_gdbarch)->builtin_long;
                }
        |       SHORT
                {
                  $$.stoken.ptr = "short";
                  $$.stoken.length = 5;
-                 $$.type = builtin_type_short;
+                 $$.type = builtin_type (current_gdbarch)->builtin_short;
                }
        ;
 
@@ -1073,43 +1072,32 @@ parse_number (p, len, parsed_float, putithere)
   if (parsed_float)
     {
       /* It's a float since it contains a point or an exponent.  */
-      char c;
+      char *s = malloc (len);
       int num = 0;     /* number of tokens scanned by scanf */
       char saved_char = p[len];
 
       p[len] = 0;      /* null-terminate the token */
-      if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
-       num = sscanf (p, "%g%c", (float *) &putithere->typed_val_float.dval,&c);
-      else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
-       num = sscanf (p, "%lg%c", (double *) &putithere->typed_val_float.dval,&c);
-      else
+      num = sscanf (p, DOUBLEST_SCAN_FORMAT "%s",
+                   &putithere->typed_val_float.dval, s);
+      p[len] = saved_char;     /* restore the input stream */
+
+      if (num == 1)
+       putithere->typed_val_float.type = 
+         builtin_type (current_gdbarch)->builtin_double;
+
+      if (num == 2 )
        {
-#ifdef SCANF_HAS_LONG_DOUBLE
-         num = sscanf (p, "%Lg%c", &putithere->typed_val_float.dval,&c);
-#else
-         /* Scan it into a double, then assign it to the long double.
-            This at least wins with values representable in the range
-            of doubles. */
-         double temp;
-         num = sscanf (p, "%lg%c", &temp,&c);
-         putithere->typed_val_float.dval = temp;
-#endif
+         /* See if it has any float suffix: 'f' for float, 'l' for long 
+            double.  */
+         if (!strcasecmp (s, "f"))
+           putithere->typed_val_float.type = 
+             builtin_type (current_gdbarch)->builtin_float;
+         else if (!strcasecmp (s, "l"))
+           putithere->typed_val_float.type = 
+             builtin_type (current_gdbarch)->builtin_long_double;
+         else
+           return ERROR;
        }
-      p[len] = saved_char;     /* restore the input stream */
-      if (num != 1)            /* check scanf found ONLY a float ... */
-       return ERROR;
-      /* See if it has `f' or `l' suffix (float or long double).  */
-
-      c = tolower (p[len - 1]);
-
-      if (c == 'f')
-       putithere->typed_val_float.type = builtin_type_float;
-      else if (c == 'l')
-       putithere->typed_val_float.type = builtin_type_long_double;
-      else if (isdigit (c) || c == '.')
-       putithere->typed_val_float.type = builtin_type_double;
-      else
-       return ERROR;
 
       return FLOAT;
     }
@@ -1223,15 +1211,15 @@ parse_number (p, len, parsed_float, putithere)
         int.  This probably should be fixed.  GCC gives a warning on
         such constants.  */
 
-      unsigned_type = builtin_type_unsigned_int;
-      signed_type = builtin_type_int;
+      unsigned_type = builtin_type (current_gdbarch)->builtin_unsigned_int;
+      signed_type = builtin_type (current_gdbarch)->builtin_int;
     }
   else if (long_p <= 1
           && (un >> (TARGET_LONG_BIT - 2)) == 0)
     {
       high_bit = ((ULONGEST)1) << (TARGET_LONG_BIT-1);
-      unsigned_type = builtin_type_unsigned_long;
-      signed_type = builtin_type_long;
+      unsigned_type = builtin_type (current_gdbarch)->builtin_unsigned_long;
+      signed_type = builtin_type (current_gdbarch)->builtin_long;
     }
   else
     {
@@ -1242,8 +1230,8 @@ parse_number (p, len, parsed_float, putithere)
       else
        shift = (TARGET_LONG_LONG_BIT - 1);
       high_bit = (ULONGEST) 1 << shift;
-      unsigned_type = builtin_type_unsigned_long_long;
-      signed_type = builtin_type_long_long;
+      unsigned_type = builtin_type (current_gdbarch)->builtin_unsigned_long_long;
+      signed_type = builtin_type (current_gdbarch)->builtin_long_long;
     }
 
    putithere->typed_val_int.val = n;
@@ -1395,7 +1383,7 @@ yylex ()
         }
 
       yylval.typed_val_int.val = c;
-      yylval.typed_val_int.type = builtin_type_char;
+      yylval.typed_val_int.type = builtin_type (current_gdbarch)->builtin_char;
 
       c = *lexptr++;
       if (c != '\'')
@@ -1773,7 +1761,10 @@ yylex ()
          yylval.tsym.type = SYMBOL_TYPE (sym);
          return TYPENAME;
         }
-    if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
+    yylval.tsym.type
+      = language_lookup_primitive_type_by_name (current_language,
+                                               current_gdbarch, tmp);
+    if (yylval.tsym.type != NULL)
       return TYPENAME;
 
     /* Input names that aren't symbols but ARE valid hex numbers,
This page took 0.030589 seconds and 4 git commands to generate.