* exec.c: #include "arch-utils.h"
[deliverable/binutils-gdb.git] / gdb / objc-exp.y
index c1971f77a8767203084e19cc007e25588e6437c2..a4a42d920a5bb9605fad842a8700882e636cb07b 100644 (file)
@@ -1,7 +1,7 @@
 /* YACC parser for C expressions, for GDB.
 
-   Copyright 1986, 1989, 1990, 1991, 1993, 1994, 2002 Free Software
-   Foundation, Inc.
+   Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 2002, 2006, 2007, 2008
+   Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,8 +15,8 @@
 
    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.  That structure contains arithmetic
@@ -52,6 +52,7 @@
 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols.  */
 #include "top.h"
 #include "completer.h" /* For skip_quoted().  */
+#include "block.h"
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
    etc), as well as gratuitiously global symbol names, so we can have
 #endif
 
 int
-yyparse PARAMS ((void));
+yyparse (void);
 
 static int
-yylex PARAMS ((void));
+yylex (void);
 
 void
-yyerror PARAMS ((char *));
+yyerror (char *);
 
 %}
 
@@ -150,7 +151,7 @@ yyerror PARAMS ((char *));
 %{
 /* YYSTYPE gets defined by %union.  */
 static int
-parse_number PARAMS ((char *, int, int, YYSTYPE *));
+parse_number (char *, int, int, YYSTYPE *);
 %}
 
 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
@@ -246,9 +247,11 @@ exp1       :       exp
 /* Expressions, not including the comma operator.  */
 exp    :       '*' exp    %prec UNARY
                        { write_exp_elt_opcode (UNOP_IND); }
+       ;
 
 exp    :       '&' exp    %prec UNARY
                        { write_exp_elt_opcode (UNOP_ADDR); }
+       ;
 
 exp    :       '-' exp    %prec UNARY
                        { write_exp_elt_opcode (UNOP_NEG); }
@@ -341,9 +344,9 @@ exp :       '[' TYPENAME
                          start_msglist();
                        }
                msglist ']'
-                       { write_exp_elt_opcode (OP_MSGCALL);
+                       { write_exp_elt_opcode (OP_OBJC_MSGCALL);
                          end_msglist();
-                         write_exp_elt_opcode (OP_MSGCALL); 
+                         write_exp_elt_opcode (OP_OBJC_MSGCALL); 
                        }
        ;
 
@@ -356,18 +359,18 @@ exp       :       '[' CLASSNAME
                          start_msglist();
                        }
                msglist ']'
-                       { write_exp_elt_opcode (OP_MSGCALL);
+                       { write_exp_elt_opcode (OP_OBJC_MSGCALL);
                          end_msglist();
-                         write_exp_elt_opcode (OP_MSGCALL); 
+                         write_exp_elt_opcode (OP_OBJC_MSGCALL); 
                        }
        ;
 
 exp    :       '[' exp
                        { start_msglist(); }
                msglist ']'
-                       { write_exp_elt_opcode (OP_MSGCALL);
+                       { write_exp_elt_opcode (OP_OBJC_MSGCALL);
                          end_msglist();
-                         write_exp_elt_opcode (OP_MSGCALL); 
+                         write_exp_elt_opcode (OP_OBJC_MSGCALL); 
                        }
        ;
 
@@ -565,9 +568,10 @@ exp        :       VARIABLE
 
 exp    :       SELECTOR 
                        {
-                         write_exp_elt_opcode (OP_SELECTOR);
+                         write_exp_elt_opcode (OP_OBJC_SELECTOR);
                          write_exp_string ($1);
-                         write_exp_elt_opcode (OP_SELECTOR); }
+                         write_exp_elt_opcode (OP_OBJC_SELECTOR); }
+       ;
 
 exp    :       SIZEOF '(' type ')'     %prec UNARY
                        { write_exp_elt_opcode (OP_LONG);
@@ -605,9 +609,9 @@ exp :       STRING
 exp     :      NSSTRING        /* ObjC NextStep NSString constant
                                 * of the form '@' '"' string '"'.
                                 */
-                       { write_exp_elt_opcode (OP_NSSTRING);
+                       { write_exp_elt_opcode (OP_OBJC_NSSTRING);
                          write_exp_string ($1);
-                         write_exp_elt_opcode (OP_NSSTRING); }
+                         write_exp_elt_opcode (OP_OBJC_NSSTRING); }
        ;
 
 block  :       BLOCKNAME
@@ -630,7 +634,7 @@ block       :       BLOCKNAME
 block  :       block COLONCOLON name
                        { struct symbol *tem
                            = lookup_symbol (copy_name ($3), $1,
-                                            VAR_NAMESPACE, (int *) NULL,
+                                            VAR_DOMAIN, (int *) NULL,
                                             (struct symtab **) NULL);
                          if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
                            error ("No function \"%s\" in specified context.",
@@ -641,7 +645,7 @@ block       :       block COLONCOLON name
 variable:      block COLONCOLON name
                        { struct symbol *sym;
                          sym = lookup_symbol (copy_name ($3), $1,
-                                              VAR_NAMESPACE, (int *) NULL,
+                                              VAR_DOMAIN, (int *) NULL,
                                               (struct symtab **) NULL);
                          if (sym == 0)
                            error ("No symbol \"%s\" in specified context.",
@@ -676,7 +680,7 @@ qualified_name:     typebase COLONCOLON name
                            error ("`%s' is not defined as an aggregate type.",
                                   TYPE_NAME (type));
 
-                         if (!STREQ (type_name_no_tag (type), $4.ptr))
+                         if (!DEPRECATED_STREQ (type_name_no_tag (type), $4.ptr))
                            error ("invalid destructor `%s::~%s'",
                                   type_name_no_tag (type), $4.ptr);
 
@@ -701,7 +705,7 @@ variable:   qualified_name
 
                          sym =
                            lookup_symbol (name, (const struct block *) NULL,
-                                          VAR_NAMESPACE, (int *) NULL,
+                                          VAR_DOMAIN, (int *) NULL,
                                           (struct symtab **) NULL);
                          if (sym)
                            {
@@ -756,8 +760,8 @@ variable:   name_not_typename
                              if (innermost_block == 0 || 
                                  contained_in (block_found, innermost_block))
                                innermost_block = block_found;
-                             write_exp_elt_opcode (OP_SELF);
-                             write_exp_elt_opcode (OP_SELF);
+                             write_exp_elt_opcode (OP_OBJC_SELF);
+                             write_exp_elt_opcode (OP_OBJC_SELF);
                              write_exp_elt_opcode (STRUCTOP_PTR);
                              write_exp_string ($1.stoken);
                              write_exp_elt_opcode (STRUCTOP_PTR);
@@ -765,7 +769,7 @@ variable:   name_not_typename
                          else
                            {
                              struct minimal_symbol *msymbol;
-                             register char *arg = copy_name ($1.stoken);
+                             char *arg = copy_name ($1.stoken);
 
                              msymbol =
                                lookup_minimal_symbol (arg, NULL, NULL);
@@ -842,7 +846,7 @@ array_mod:  '[' ']'
 func_mod:      '(' ')'
                        { $$ = 0; }
        |       '(' nonempty_typelist ')'
-                       { free ((PTR)$2); $$ = 0; }
+                       { free ($2); $$ = 0; }
        ;
 
 /* We used to try to recognize more pointer to member types here, but
@@ -854,8 +858,6 @@ 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.  */
@@ -988,21 +990,21 @@ name_not_typename :       NAME
 
 static int
 parse_number (p, len, parsed_float, putithere)
-     register char *p;
-     register int len;
+     char *p;
+     int len;
      int parsed_float;
      YYSTYPE *putithere;
 {
   /* FIXME: Shouldn't these be unsigned?  We don't deal with negative
      values here, and we do kind of silly things like cast to
      unsigned.  */
-  register LONGEST n = 0;
-  register LONGEST prevn = 0;
+  LONGEST n = 0;
+  LONGEST prevn = 0;
   unsigned LONGEST un;
 
-  register int i = 0;
-  register int c;
-  register int base = input_radix;
+  int i = 0;
+  int c;
+  int base = input_radix;
   int unsigned_p = 0;
 
   /* Number of "L" suffixes encountered.  */
@@ -1021,23 +1023,8 @@ parse_number (p, len, parsed_float, putithere)
 
       /* It's a float since it contains a point or an exponent.  */
 
-      if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
-       sscanf (p, "%g", &putithere->typed_val_float.dval);
-      else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
-       sscanf (p, "%lg", &putithere->typed_val_float.dval);
-      else
-       {
-#ifdef PRINTF_HAS_LONG_DOUBLE
-         sscanf (p, "%Lg", &putithere->typed_val_float.dval);
-#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;
-         sscanf (p, "%lg", &temp);
-         putithere->typed_val_float.dval = temp;
-#endif
-       }
+      sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%c",
+             &putithere->typed_val_float.dval, &c);
 
       /* See if it has `f' or `l' suffix (float or long double).  */
 
@@ -1147,16 +1134,16 @@ parse_number (p, len, parsed_float, putithere)
      shift it right and see whether anything remains.  Note that we
      can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
      operation, because many compilers will warn about such a shift
-     (which always produces a zero result).  Sometimes TARGET_INT_BIT
-     or TARGET_LONG_BIT will be that big, sometimes not.  To deal with
+     (which always produces a zero result).  Sometimes gdbarch_int_bit
+     or gdbarch_long_int will be that big, sometimes not.  To deal with
      the case where it is we just always shift the value more than
      once, with fewer bits each time.  */
 
   un = (unsigned LONGEST)n >> 2;
   if (long_p == 0
-      && (un >> (TARGET_INT_BIT - 2)) == 0)
+      && (un >> (gdbarch_int_bit (current_gdbarch) - 2)) == 0)
     {
-      high_bit = ((unsigned LONGEST)1) << (TARGET_INT_BIT-1);
+      high_bit = ((unsigned LONGEST)1) << (gdbarch_int_bit (current_gdbarch) - 1);
 
       /* A large decimal (not hex or octal) constant (between INT_MAX
         and UINT_MAX) is a long or unsigned long, according to ANSI,
@@ -1168,16 +1155,16 @@ parse_number (p, len, parsed_float, putithere)
       signed_type = builtin_type_int;
     }
   else if (long_p <= 1
-          && (un >> (TARGET_LONG_BIT - 2)) == 0)
+          && (un >> (gdbarch_long_bit (current_gdbarch) - 2)) == 0)
     {
-      high_bit = ((unsigned LONGEST)1) << (TARGET_LONG_BIT-1);
+      high_bit = ((unsigned LONGEST)1) << (gdbarch_long_bit (current_gdbarch) - 1);
       unsigned_type = builtin_type_unsigned_long;
       signed_type = builtin_type_long;
     }
   else
     {
       high_bit = (((unsigned LONGEST)1)
-                 << (TARGET_LONG_LONG_BIT - 32 - 1)
+                 << (gdbarch_long_long_bit (current_gdbarch) - 32 - 1)
                  << 16
                  << 16);
       if (high_bit == 0)
@@ -1261,7 +1248,7 @@ yylex ()
   tokstart = lexptr;
   /* See if it is a special token of length 3.  */
   for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
-    if (STREQN (tokstart, tokentab3[i].operator, 3))
+    if (DEPRECATED_STREQN (tokstart, tokentab3[i].operator, 3))
       {
        lexptr += 3;
        yylval.opcode = tokentab3[i].opcode;
@@ -1270,13 +1257,14 @@ yylex ()
 
   /* See if it is a special token of length 2.  */
   for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
-    if (STREQN (tokstart, tokentab2[i].operator, 2))
+    if (DEPRECATED_STREQN (tokstart, tokentab2[i].operator, 2))
       {
        lexptr += 2;
        yylval.opcode = tokentab2[i].opcode;
        return tokentab2[i].token;
       }
 
+  c = 0;
   switch (tokchr = *tokstart)
     {
     case 0:
@@ -1305,9 +1293,7 @@ yylex ()
       c = *lexptr++;
       if (c != '\'')
        {
-         namelen = skip_quoted (tokstart, 
-                                get_gdb_completer_word_break_characters())
-           - tokstart;
+         namelen = skip_quoted (tokstart) - tokstart;
          if (namelen > 2)
            {
              lexptr = tokstart + namelen;
@@ -1359,7 +1345,7 @@ yylex ()
        /* It's a number.  */
        int got_dot = 0, got_e = 0, toktype = FLOAT;
        /* Initialize toktype to anything other than ERROR.  */
-       register char *p = tokstart;
+       char *p = tokstart;
        int hex = input_radix > 10;
        int local_radix = input_radix;
        if (tokchr == '0' && (p[1] == 'x' || p[1] == 'X'))
@@ -1586,43 +1572,43 @@ yylex ()
   switch (namelen)
     {
     case 8:
-      if (STREQN (tokstart, "unsigned", 8))
+      if (DEPRECATED_STREQN (tokstart, "unsigned", 8))
        return UNSIGNED;
       if (current_language->la_language == language_cplus
-         && STREQN (tokstart, "template", 8))
+         && strncmp (tokstart, "template", 8) == 0)
        return TEMPLATE;
-      if (STREQN (tokstart, "volatile", 8))
+      if (DEPRECATED_STREQN (tokstart, "volatile", 8))
        return VOLATILE_KEYWORD;
       break;
     case 6:
-      if (STREQN (tokstart, "struct", 6))
+      if (DEPRECATED_STREQN (tokstart, "struct", 6))
        return STRUCT;
-      if (STREQN (tokstart, "signed", 6))
+      if (DEPRECATED_STREQN (tokstart, "signed", 6))
        return SIGNED_KEYWORD;
-      if (STREQN (tokstart, "sizeof", 6))      
+      if (DEPRECATED_STREQN (tokstart, "sizeof", 6))      
        return SIZEOF;
-      if (STREQN (tokstart, "double", 6))      
+      if (DEPRECATED_STREQN (tokstart, "double", 6))      
        return DOUBLE_KEYWORD;
       break;
     case 5:
       if ((current_language->la_language == language_cplus)
-         && STREQN (tokstart, "class", 5))
+         && strncmp (tokstart, "class", 5) == 0)
        return CLASS;
-      if (STREQN (tokstart, "union", 5))
+      if (DEPRECATED_STREQN (tokstart, "union", 5))
        return UNION;
-      if (STREQN (tokstart, "short", 5))
+      if (DEPRECATED_STREQN (tokstart, "short", 5))
        return SHORT;
-      if (STREQN (tokstart, "const", 5))
+      if (DEPRECATED_STREQN (tokstart, "const", 5))
        return CONST_KEYWORD;
       break;
     case 4:
-      if (STREQN (tokstart, "enum", 4))
+      if (DEPRECATED_STREQN (tokstart, "enum", 4))
        return ENUM;
-      if (STREQN (tokstart, "long", 4))
+      if (DEPRECATED_STREQN (tokstart, "long", 4))
        return LONG;
       break;
     case 3:
-      if (STREQN (tokstart, "int", 3))
+      if (DEPRECATED_STREQN (tokstart, "int", 3))
        return INT_KEYWORD;
       break;
     default:
@@ -1656,7 +1642,7 @@ yylex ()
       need_this = (int *) NULL;
 
     sym = lookup_symbol (tmp, expression_context_block,
-                        VAR_NAMESPACE,
+                        VAR_DOMAIN,
                         need_this,
                         (struct symtab **) NULL);
     /* Call lookup_symtab, not lookup_partial_symtab, in case there
@@ -1735,7 +1721,7 @@ yylex ()
                      tmp1[p - namestart] = '\0';
                      cur_sym = lookup_symbol (ncopy, 
                                               expression_context_block,
-                                              VAR_NAMESPACE, (int *) NULL,
+                                              VAR_DOMAIN, (int *) NULL,
                                               (struct symtab **) NULL);
                      if (cur_sym)
                        {
@@ -1763,8 +1749,11 @@ yylex ()
 #endif /* not 0 */
          return TYPENAME;
         }
-    if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
-       return TYPENAME;
+    yylval.tsym.type
+      = language_lookup_primitive_type_by_name (current_language,
+                                               current_gdbarch, tmp);
+    if (yylval.tsym.type != NULL)
+      return TYPENAME;
 
     /* See if it's an ObjC classname.  */
     if (!sym)
@@ -1772,7 +1761,6 @@ yylex ()
        CORE_ADDR Class = lookup_objc_class(tmp);
        if (Class)
          {
-           extern struct symbol *lookup_struct_typedef();
            yylval.class.class = Class;
            if ((sym = lookup_struct_typedef (tmp, 
                                              expression_context_block, 
This page took 0.030706 seconds and 4 git commands to generate.