2003-09-25 David Carlton <carlton@kealia.com>
[deliverable/binutils-gdb.git] / gdb / p-exp.y
index d52747b072eda4d5860b868658a35bc4af836bee..6132e6eb10c8fdb79e5017d7890a174e7b51ffd8 100644 (file)
@@ -56,6 +56,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "bfd.h" /* Required by objfiles.h.  */
 #include "symfile.h" /* Required by objfiles.h.  */
 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
+#include "block.h"
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -157,8 +158,8 @@ parse_number (char *, int, int, YYSTYPE *);
 
 static struct type *current_type;
 
-static void push_current_type ();
-static void pop_current_type ();
+static void push_current_type (void);
+static void pop_current_type (void);
 static int search_field;
 %}
 
@@ -205,7 +206,7 @@ static int search_field;
 
 /* Object pascal */
 %token THIS
-%token <lval> TRUE FALSE
+%token <lval> TRUEKEYWORD FALSEKEYWORD
 
 %left ','
 %left ABOVE_COMMA
@@ -293,7 +294,7 @@ exp :       exp '.' { search_field = 1; }
                            { while (TYPE_CODE (current_type) == TYPE_CODE_PTR)
                                current_type = TYPE_TARGET_TYPE (current_type);
                              current_type = lookup_struct_elt_type (
-                               current_type, $4.ptr, false); };
+                               current_type, $4.ptr, 0); };
                         } ; 
 exp    :       exp '['
                        /* We need to save the current_type value */
@@ -342,7 +343,15 @@ arglist    :
        ;
 
 exp    :       type '(' exp ')' %prec UNARY
-                       { write_exp_elt_opcode (UNOP_CAST);
+                       { if (current_type)
+                           {
+                             /* Allow automatic dereference of classes.  */
+                             if ((TYPE_CODE (current_type) == TYPE_CODE_PTR)
+                                 && (TYPE_CODE (TYPE_TARGET_TYPE (current_type)) == TYPE_CODE_CLASS)
+                                 && (TYPE_CODE ($1) == TYPE_CODE_CLASS))
+                               write_exp_elt_opcode (UNOP_IND);
+                           }
+                         write_exp_elt_opcode (UNOP_CAST);
                          write_exp_elt_type ($1);
                          write_exp_elt_opcode (UNOP_CAST); 
                          current_type = $1; }
@@ -426,13 +435,13 @@ exp       :       exp ASSIGN exp
                        { write_exp_elt_opcode (BINOP_ASSIGN); }
        ;
 
-exp    :       TRUE
+exp    :       TRUEKEYWORD
                        { write_exp_elt_opcode (OP_BOOL);
                          write_exp_elt_longcst ((LONGEST) $1);
                          write_exp_elt_opcode (OP_BOOL); }
        ;
 
-exp    :       FALSE
+exp    :       FALSEKEYWORD
                        { write_exp_elt_opcode (OP_BOOL);
                          write_exp_elt_longcst ((LONGEST) $1);
                          write_exp_elt_opcode (OP_BOOL); }
@@ -504,8 +513,28 @@ exp        :       STRING
 
 /* Object pascal  */
 exp    :       THIS
-                       { write_exp_elt_opcode (OP_THIS);
-                         write_exp_elt_opcode (OP_THIS); }
+                       { 
+                         struct value * this_val;
+                         struct type * this_type;
+                         write_exp_elt_opcode (OP_THIS);
+                         write_exp_elt_opcode (OP_THIS); 
+                         /* we need type of this */
+                         this_val = value_of_this (0); 
+                         if (this_val)
+                           this_type = this_val->type;
+                         else
+                           this_type = NULL;
+                         if (this_type)
+                           {
+                             if (TYPE_CODE (this_type) == TYPE_CODE_PTR)
+                               {
+                                 this_type = TYPE_TARGET_TYPE (this_type);
+                                 write_exp_elt_opcode (UNOP_IND);
+                               }
+                           }
+               
+                         current_type = this_type;
+                       }
        ;
 
 /* end of object pascal.  */
@@ -530,7 +559,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.",
@@ -541,7 +570,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.",
@@ -578,7 +607,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)
                            {
@@ -649,14 +678,14 @@ variable: name_not_typename
                              if (this_type)
                                current_type = lookup_struct_elt_type (
                                  this_type,
-                                 $1.stoken.ptr, false);
+                                 copy_name ($1.stoken), 0);
                              else
                                current_type = NULL; 
                            }
                          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);
@@ -693,7 +722,9 @@ type        :       ptype
        ;
 
 typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
-       :       TYPENAME
+       :       '^' typebase
+                       { $$ = lookup_pointer_type ($2); }
+       |       TYPENAME
                        { $$ = $1.type; }
        |       STRUCT name
                        { $$ = lookup_struct (copy_name ($2),
@@ -733,20 +764,20 @@ 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;
   ULONGEST 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.  */
@@ -961,7 +992,8 @@ struct type_push
 
 static struct type_push *tp_top = NULL;
 
-static void push_current_type ()
+static void
+push_current_type (void)
 {
   struct type_push *tpnew;
   tpnew = (struct type_push *) malloc (sizeof (struct type_push));
@@ -971,7 +1003,8 @@ static void push_current_type ()
   tp_top = tpnew; 
 }
 
-static void pop_current_type ()
+static void
+pop_current_type (void)
 {
   struct type_push *tp = tp_top;
   if (tp)
@@ -1156,7 +1189,7 @@ yylex ()
       {
        /* It's a number.  */
        int got_dot = 0, got_e = 0, toktype;
-       register char *p = tokstart;
+       char *p = tokstart;
        int hex = input_radix > 10;
 
        if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
@@ -1349,14 +1382,14 @@ yylex ()
       if (STREQ (uptokstart, "FALSE"))
        {
           yylval.lval = 0;
-          return FALSE;
+          return FALSEKEYWORD;
         }
       break;
     case 4:
       if (STREQ (uptokstart, "TRUE"))
        {
           yylval.lval = 1;
-         return TRUE;
+         return TRUEKEYWORD;
         }
       if (STREQ (uptokstart, "SELF"))
         {
@@ -1365,7 +1398,7 @@ yylex ()
          static const char this_name[] = "this";
 
          if (lookup_symbol (this_name, expression_context_block,
-                            VAR_NAMESPACE, (int *) NULL,
+                            VAR_DOMAIN, (int *) NULL,
                             (struct symtab **) NULL))
            return THIS;
        }
@@ -1406,7 +1439,7 @@ yylex ()
       sym = NULL;
     else
       sym = lookup_symbol (tmp, expression_context_block,
-                          VAR_NAMESPACE,
+                          VAR_DOMAIN,
                           &is_a_field_of_this,
                           (struct symtab **) NULL);
     /* second chance uppercased (as Free Pascal does).  */
@@ -1423,7 +1456,7 @@ yylex ()
         sym = NULL;
        else
         sym = lookup_symbol (tmp, expression_context_block,
-                        VAR_NAMESPACE,
+                        VAR_DOMAIN,
                         &is_a_field_of_this,
                         (struct symtab **) NULL);
        if (sym || is_a_field_of_this || is_a_field)
@@ -1453,7 +1486,7 @@ yylex ()
         sym = NULL;
        else
         sym = lookup_symbol (tmp, expression_context_block,
-                         VAR_NAMESPACE,
+                         VAR_DOMAIN,
                          &is_a_field_of_this,
                          (struct symtab **) NULL);
        if (sym || is_a_field_of_this || is_a_field)
@@ -1550,7 +1583,7 @@ yylex ()
                      memcpy (tmp1, namestart, p - namestart);
                      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)
                        {
This page took 0.031195 seconds and 4 git commands to generate.