gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / p-exp.y
index a1c78bf06da8be10525e69cfcdfca70bc4921ac5..6403e410571656d971faea7f3a6ce1bc17467995 100644 (file)
@@ -1,5 +1,5 @@
 /* YACC parser for Pascal expressions, for GDB.
-   Copyright (C) 2000-2015 Free Software Foundation, Inc.
+   Copyright (C) 2000-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "block.h"
 #include "completer.h"
 
-#define parse_type(ps) builtin_type (parse_gdbarch (ps))
-
-/* 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
-   produced by yacc.  If other parser generators (bison, byacc, etc) produce
-   additional global names that conflict at link time, then those parser
-   generators need to be fixed instead of adding those names to this list.  */
-
-#define        yymaxdepth pascal_maxdepth
-#define        yyparse pascal_parse_internal
-#define        yylex   pascal_lex
-#define        yyerror pascal_error
-#define        yylval  pascal_lval
-#define        yychar  pascal_char
-#define        yydebug pascal_debug
-#define        yypact  pascal_pact
-#define        yyr1    pascal_r1
-#define        yyr2    pascal_r2
-#define        yydef   pascal_def
-#define        yychk   pascal_chk
-#define        yypgo   pascal_pgo
-#define        yyact   pascal_act
-#define        yyexca  pascal_exca
-#define yyerrflag pascal_errflag
-#define yynerrs        pascal_nerrs
-#define        yyps    pascal_ps
-#define        yypv    pascal_pv
-#define        yys     pascal_s
-#define        yy_yys  pascal_yys
-#define        yystate pascal_state
-#define        yytmp   pascal_tmp
-#define        yyv     pascal_v
-#define        yy_yyv  pascal_yyv
-#define        yyval   pascal_val
-#define        yylloc  pascal_lloc
-#define yyreds pascal_reds             /* With YYDEBUG defined */
-#define yytoks pascal_toks             /* With YYDEBUG defined */
-#define yyname pascal_name             /* With YYDEBUG defined */
-#define yyrule pascal_rule             /* With YYDEBUG defined */
-#define yylhs  pascal_yylhs
-#define yylen  pascal_yylen
-#define yydefred pascal_yydefred
-#define yydgoto        pascal_yydgoto
-#define yysindex pascal_yysindex
-#define yyrindex pascal_yyrindex
-#define yygindex pascal_yygindex
-#define yytable         pascal_yytable
-#define yycheck         pascal_yycheck
-#define yyss   pascal_yyss
-#define yysslim        pascal_yysslim
-#define yyssp  pascal_yyssp
-#define yystacksize pascal_yystacksize
-#define yyvs   pascal_yyvs
-#define yyvsp  pascal_yyvsp
-
-#ifndef YYDEBUG
-#define        YYDEBUG 1               /* Default to yydebug support */
-#endif
-
-#define YYFPRINTF parser_fprintf
+#define parse_type(ps) builtin_type (ps->gdbarch ())
+
+/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
+   etc).  */
+#define GDB_YY_REMAP_PREFIX pascal_
+#include "yy-remap.h"
 
 /* The state of the parser, used internally when we are parsing the
    expression.  */
 
 static struct parser_state *pstate = NULL;
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
 int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+static void yyerror (const char *);
 
 static char *uptok (const char *, int);
 %}
@@ -144,7 +92,7 @@ static char *uptok (const char *, int);
       struct type *type;
     } typed_val_int;
     struct {
-      DOUBLEST dval;
+      gdb_byte val[16];
       struct type *type;
     } typed_val_float;
     struct symbol *sym;
@@ -213,7 +161,7 @@ static int search_field;
 /* Special type cases, put in to allow the parser to distinguish different
    legal basetypes.  */
 
-%token <voidval> VARIABLE
+%token <voidval> DOLLAR_VARIABLE
 
 
 /* Object pascal */
@@ -309,7 +257,7 @@ exp :       field_exp FIELDNAME
                          search_field = 0;
                          if (current_type)
                            {
-                             while (TYPE_CODE (current_type)
+                             while (current_type->code ()
                                     == TYPE_CODE_PTR)
                                current_type =
                                  TYPE_TARGET_TYPE (current_type);
@@ -327,7 +275,7 @@ exp :       field_exp name
                          search_field = 0;
                          if (current_type)
                            {
-                             while (TYPE_CODE (current_type)
+                             while (current_type->code ()
                                     == TYPE_CODE_PTR)
                                current_type =
                                  TYPE_TARGET_TYPE (current_type);
@@ -337,14 +285,14 @@ exp       :       field_exp name
                        }
        ;
 exp    :       field_exp  name COMPLETE
-                       { mark_struct_expression (pstate);
+                       { pstate->mark_struct_expression ();
                          write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
                          write_exp_string (pstate, $2);
                          write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
        ;
 exp    :       field_exp COMPLETE
                        { struct stoken s;
-                         mark_struct_expression (pstate);
+                         pstate->mark_struct_expression ();
                          write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
                          s.ptr = "";
                          s.length = 0;
@@ -364,7 +312,7 @@ exp :       exp '['
                              struct stoken stringsval;
                              char *buf;
 
-                             buf = alloca (strlen (arrayname) + 1);
+                             buf = (char *) alloca (strlen (arrayname) + 1);
                              stringsval.ptr = buf;
                              stringsval.length = strlen (arrayname);
                              strcpy (buf, arrayname);
@@ -386,11 +334,11 @@ exp       :       exp '('
                        /* This is to save the value of arglist_len
                           being accumulated by an outer function call.  */
                        { push_current_type ();
-                         start_arglist (); }
+                         pstate->start_arglist (); }
                arglist ')'     %prec ARROW
                        { write_exp_elt_opcode (pstate, OP_FUNCALL);
                          write_exp_elt_longcst (pstate,
-                                                (LONGEST) end_arglist ());
+                                                pstate->end_arglist ());
                          write_exp_elt_opcode (pstate, OP_FUNCALL);
                          pop_current_type ();
                          if (current_type)
@@ -400,18 +348,18 @@ exp       :       exp '('
 
 arglist        :
          | exp
-                       { arglist_len = 1; }
+                       { pstate->arglist_len = 1; }
         | arglist ',' exp   %prec ABOVE_COMMA
-                       { arglist_len++; }
+                       { pstate->arglist_len++; }
        ;
 
 exp    :       type '(' exp ')' %prec UNARY
                        { 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_STRUCT)
-                                 && (TYPE_CODE ($1) == TYPE_CODE_STRUCT))
+                             if ((current_type->code () == TYPE_CODE_PTR)
+                                 && (TYPE_TARGET_TYPE (current_type)->code () == TYPE_CODE_STRUCT)
+                                 && (($1)->code () == TYPE_CODE_STRUCT))
                                write_exp_elt_opcode (pstate, UNOP_IND);
                            }
                          write_exp_elt_opcode (pstate, UNOP_CAST);
@@ -566,24 +514,24 @@ exp       :       NAME_OR_INT
 
 
 exp    :       FLOAT
-                       { write_exp_elt_opcode (pstate, OP_DOUBLE);
+                       { write_exp_elt_opcode (pstate, OP_FLOAT);
                          write_exp_elt_type (pstate, $1.type);
                          current_type = $1.type;
-                         write_exp_elt_dblcst (pstate, $1.dval);
-                         write_exp_elt_opcode (pstate, OP_DOUBLE); }
+                         write_exp_elt_floatcst (pstate, $1.val);
+                         write_exp_elt_opcode (pstate, OP_FLOAT); }
        ;
 
 exp    :       variable
        ;
 
-exp    :       VARIABLE
+exp    :       DOLLAR_VARIABLE
                        /* Already written by write_dollar_variable.
                           Handle current_type.  */
                        {  if (intvar) {
                             struct value * val, * mark;
 
                             mark = value_mark ();
-                            val = value_of_internalvar (parse_gdbarch (pstate),
+                            val = value_of_internalvar (pstate->gdbarch (),
                                                         intvar);
                             current_type = value_type (val);
                             value_release_to_mark (mark);
@@ -596,7 +544,7 @@ exp :       SIZEOF '(' type ')'     %prec UNARY
                          write_exp_elt_type (pstate,
                                            parse_type (pstate)->builtin_int);
                          current_type = parse_type (pstate)->builtin_int;
-                         CHECK_TYPEDEF ($3);
+                         $3 = check_typedef ($3);
                          write_exp_elt_longcst (pstate,
                                                 (LONGEST) TYPE_LENGTH ($3));
                          write_exp_elt_opcode (pstate, OP_LONG); }
@@ -646,14 +594,14 @@ exp       :       THIS
                          write_exp_elt_opcode (pstate, OP_THIS);
                          /* We need type of this.  */
                          this_val
-                           = value_of_this_silent (parse_language (pstate));
+                           = value_of_this_silent (pstate->language ());
                          if (this_val)
                            this_type = value_type (this_val);
                          else
                            this_type = NULL;
                          if (this_type)
                            {
-                             if (TYPE_CODE (this_type) == TYPE_CODE_PTR)
+                             if (this_type->code () == TYPE_CODE_PTR)
                                {
                                  this_type = TYPE_TARGET_TYPE (this_type);
                                  write_exp_elt_opcode (pstate, UNOP_IND);
@@ -668,54 +616,60 @@ exp       :       THIS
 
 block  :       BLOCKNAME
                        {
-                         if ($1.sym != 0)
-                             $$ = SYMBOL_BLOCK_VALUE ($1.sym);
+                         if ($1.sym.symbol != 0)
+                             $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol);
                          else
                            {
+                             std::string copy = copy_name ($1.stoken);
                              struct symtab *tem =
-                                 lookup_symtab (copy_name ($1.stoken));
+                                 lookup_symtab (copy.c_str ());
                              if (tem)
                                $$ = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (tem),
                                                        STATIC_BLOCK);
                              else
                                error (_("No file or function \"%s\"."),
-                                      copy_name ($1.stoken));
+                                      copy.c_str ());
                            }
                        }
        ;
 
 block  :       block COLONCOLON name
-                       { struct symbol *tem
-                           = lookup_symbol (copy_name ($3), $1,
-                                            VAR_DOMAIN, NULL);
+                       {
+                         std::string copy = copy_name ($3);
+                         struct symbol *tem
+                           = lookup_symbol (copy.c_str (), $1,
+                                            VAR_DOMAIN, NULL).symbol;
+
                          if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
                            error (_("No function \"%s\" in specified context."),
-                                  copy_name ($3));
+                                  copy.c_str ());
                          $$ = SYMBOL_BLOCK_VALUE (tem); }
        ;
 
 variable:      block COLONCOLON name
-                       { struct symbol *sym;
-                         sym = lookup_symbol (copy_name ($3), $1,
+                       { struct block_symbol sym;
+
+                         std::string copy = copy_name ($3);
+                         sym = lookup_symbol (copy.c_str (), $1,
                                               VAR_DOMAIN, NULL);
-                         if (sym == 0)
+                         if (sym.symbol == 0)
                            error (_("No symbol \"%s\" in specified context."),
-                                  copy_name ($3));
+                                  copy.c_str ());
 
                          write_exp_elt_opcode (pstate, OP_VAR_VALUE);
-                         /* block_found is set by lookup_symbol.  */
-                         write_exp_elt_block (pstate, block_found);
-                         write_exp_elt_sym (pstate, sym);
+                         write_exp_elt_block (pstate, sym.block);
+                         write_exp_elt_sym (pstate, sym.symbol);
                          write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
        ;
 
 qualified_name:        typebase COLONCOLON name
                        {
                          struct type *type = $1;
-                         if (TYPE_CODE (type) != TYPE_CODE_STRUCT
-                             && TYPE_CODE (type) != TYPE_CODE_UNION)
+
+                         if (type->code () != TYPE_CODE_STRUCT
+                             && type->code () != TYPE_CODE_UNION)
                            error (_("`%s' is not defined as an aggregate type."),
-                                  TYPE_NAME (type));
+                                  type->name ());
 
                          write_exp_elt_opcode (pstate, OP_SCOPE);
                          write_exp_elt_type (pstate, type);
@@ -727,13 +681,14 @@ qualified_name:   typebase COLONCOLON name
 variable:      qualified_name
        |       COLONCOLON name
                        {
-                         char *name = copy_name ($2);
+                         std::string name = copy_name ($2);
                          struct symbol *sym;
                          struct bound_minimal_symbol msymbol;
 
                          sym =
-                           lookup_symbol (name, (const struct block *) NULL,
-                                          VAR_DOMAIN, NULL);
+                           lookup_symbol (name.c_str (),
+                                          (const struct block *) NULL,
+                                          VAR_DOMAIN, NULL).symbol;
                          if (sym)
                            {
                              write_exp_elt_opcode (pstate, OP_VAR_VALUE);
@@ -743,7 +698,8 @@ variable:   qualified_name
                              break;
                            }
 
-                         msymbol = lookup_bound_minimal_symbol (name);
+                         msymbol
+                           = lookup_bound_minimal_symbol (name.c_str ());
                          if (msymbol.minsym != NULL)
                            write_exp_msymbol (pstate, msymbol);
                          else if (!have_full_symbols ()
@@ -752,31 +708,23 @@ variable: qualified_name
                                   "Use the \"file\" command."));
                          else
                            error (_("No symbol \"%s\" in current context."),
-                                  name);
+                                  name.c_str ());
                        }
        ;
 
 variable:      name_not_typename
-                       { struct symbol *sym = $1.sym;
+                       { struct block_symbol sym = $1.sym;
 
-                         if (sym)
+                         if (sym.symbol)
                            {
-                             if (symbol_read_needs_frame (sym))
-                               {
-                                 if (innermost_block == 0
-                                     || contained_in (block_found,
-                                                      innermost_block))
-                                   innermost_block = block_found;
-                               }
+                             if (symbol_read_needs_frame (sym.symbol))
+                               pstate->block_tracker->update (sym);
 
                              write_exp_elt_opcode (pstate, OP_VAR_VALUE);
-                             /* We want to use the selected frame, not
-                                another more inner frame which happens to
-                                be in the same block.  */
-                             write_exp_elt_block (pstate, NULL);
-                             write_exp_elt_sym (pstate, sym);
+                             write_exp_elt_block (pstate, sym.block);
+                             write_exp_elt_sym (pstate, sym.symbol);
                              write_exp_elt_opcode (pstate, OP_VAR_VALUE);
-                             current_type = sym->type; }
+                             current_type = sym.symbol->type; }
                          else if ($1.is_a_field_of_this)
                            {
                              struct value * this_val;
@@ -784,10 +732,7 @@ variable:  name_not_typename
                              /* Object pascal: it hangs off of `this'.  Must
                                 not inadvertently convert from a method call
                                 to data ref.  */
-                             if (innermost_block == 0
-                                 || contained_in (block_found,
-                                                  innermost_block))
-                               innermost_block = block_found;
+                             pstate->block_tracker->update (sym);
                              write_exp_elt_opcode (pstate, OP_THIS);
                              write_exp_elt_opcode (pstate, OP_THIS);
                              write_exp_elt_opcode (pstate, STRUCTOP_PTR);
@@ -795,7 +740,7 @@ variable:   name_not_typename
                              write_exp_elt_opcode (pstate, STRUCTOP_PTR);
                              /* We need type of this.  */
                              this_val
-                               = value_of_this_silent (parse_language (pstate));
+                               = value_of_this_silent (pstate->language ());
                              if (this_val)
                                this_type = value_type (this_val);
                              else
@@ -803,17 +748,17 @@ variable: name_not_typename
                              if (this_type)
                                current_type = lookup_struct_elt_type (
                                  this_type,
-                                 copy_name ($1.stoken), 0);
+                                 copy_name ($1.stoken).c_str (), 0);
                              else
                                current_type = NULL;
                            }
                          else
                            {
                              struct bound_minimal_symbol msymbol;
-                             char *arg = copy_name ($1.stoken);
+                             std::string arg = copy_name ($1.stoken);
 
                              msymbol =
-                               lookup_bound_minimal_symbol (arg);
+                               lookup_bound_minimal_symbol (arg.c_str ());
                              if (msymbol.minsym != NULL)
                                write_exp_msymbol (pstate, msymbol);
                              else if (!have_full_symbols ()
@@ -822,7 +767,7 @@ variable:   name_not_typename
                                       "Use the \"file\" command."));
                              else
                                error (_("No symbol \"%s\" in current context."),
-                                      copy_name ($1.stoken));
+                                      arg.c_str ());
                            }
                        }
        ;
@@ -848,11 +793,15 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
        |       TYPENAME
                        { $$ = $1.type; }
        |       STRUCT name
-                       { $$ = lookup_struct (copy_name ($2),
-                                             expression_context_block); }
+                       { $$
+                           = lookup_struct (copy_name ($2).c_str (),
+                                            pstate->expression_context_block);
+                       }
        |       CLASS name
-                       { $$ = lookup_struct (copy_name ($2),
-                                             expression_context_block); }
+                       { $$
+                           = lookup_struct (copy_name ($2).c_str (),
+                                            pstate->expression_context_block);
+                       }
        /* "const" and "volatile" are curently ignored.  A type qualifier
           after the type is handled in the ptype rule.  I think these could
           be too.  */
@@ -910,9 +859,30 @@ parse_number (struct parser_state *par_state,
 
   if (parsed_float)
     {
-      if (! parse_c_float (parse_gdbarch (par_state), p, len,
-                          &putithere->typed_val_float.dval,
-                          &putithere->typed_val_float.type))
+      /* Handle suffixes: 'f' for float, 'l' for long double.
+         FIXME: This appears to be an extension -- do we want this?  */
+      if (len >= 1 && tolower (p[len - 1]) == 'f')
+       {
+         putithere->typed_val_float.type
+           = parse_type (par_state)->builtin_float;
+         len--;
+       }
+      else if (len >= 1 && tolower (p[len - 1]) == 'l')
+       {
+         putithere->typed_val_float.type
+           = parse_type (par_state)->builtin_long_double;
+         len--;
+       }
+      /* Default type for floating-point literals is double.  */
+      else
+       {
+         putithere->typed_val_float.type
+           = parse_type (par_state)->builtin_double;
+       }
+
+      if (!parse_float (p, len,
+                       putithere->typed_val_float.type,
+                       putithere->typed_val_float.val))
        return ERROR;
       return FLOAT;
     }
@@ -1016,10 +986,10 @@ parse_number (struct parser_state *par_state,
 
   un = (ULONGEST)n >> 2;
   if (long_p == 0
-      && (un >> (gdbarch_int_bit (parse_gdbarch (par_state)) - 2)) == 0)
+      && (un >> (gdbarch_int_bit (par_state->gdbarch ()) - 2)) == 0)
     {
       high_bit
-       = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
+       = ((ULONGEST)1) << (gdbarch_int_bit (par_state->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,
@@ -1031,10 +1001,10 @@ parse_number (struct parser_state *par_state,
       signed_type = parse_type (par_state)->builtin_int;
     }
   else if (long_p <= 1
-          && (un >> (gdbarch_long_bit (parse_gdbarch (par_state)) - 2)) == 0)
+          && (un >> (gdbarch_long_bit (par_state->gdbarch ()) - 2)) == 0)
     {
       high_bit
-       = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch (par_state)) - 1);
+       = ((ULONGEST)1) << (gdbarch_long_bit (par_state->gdbarch ()) - 1);
       unsigned_type = parse_type (par_state)->builtin_unsigned_long;
       signed_type = parse_type (par_state)->builtin_long;
     }
@@ -1042,11 +1012,11 @@ parse_number (struct parser_state *par_state,
     {
       int shift;
       if (sizeof (ULONGEST) * HOST_CHAR_BIT
-         < gdbarch_long_long_bit (parse_gdbarch (par_state)))
+         < gdbarch_long_long_bit (par_state->gdbarch ()))
        /* A long long does not fit in a LONGEST.  */
        shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
       else
-       shift = (gdbarch_long_long_bit (parse_gdbarch (par_state)) - 1);
+       shift = (gdbarch_long_long_bit (par_state->gdbarch ()) - 1);
       high_bit = (ULONGEST) 1 << shift;
       unsigned_type = parse_type (par_state)->builtin_unsigned_long_long;
       signed_type = parse_type (par_state)->builtin_long_long;
@@ -1103,7 +1073,7 @@ pop_current_type (void)
 
 struct token
 {
-  char *operator;
+  const char *oper;
   int token;
   enum exp_opcode opcode;
 };
@@ -1155,7 +1125,6 @@ yylex (void)
 {
   int c;
   int namelen;
-  unsigned int i;
   const char *tokstart;
   char *uptokstart;
   const char *tokptr;
@@ -1165,33 +1134,33 @@ yylex (void)
 
  retry:
 
-  prev_lexptr = lexptr;
+  pstate->prev_lexptr = pstate->lexptr;
 
-  tokstart = lexptr;
-  explen = strlen (lexptr);
+  tokstart = pstate->lexptr;
+  explen = strlen (pstate->lexptr);
 
   /* See if it is a special token of length 3.  */
   if (explen > 2)
-    for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
-      if (strncasecmp (tokstart, tokentab3[i].operator, 3) == 0
-          && (!isalpha (tokentab3[i].operator[0]) || explen == 3
+    for (int i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
+      if (strncasecmp (tokstart, tokentab3[i].oper, 3) == 0
+          && (!isalpha (tokentab3[i].oper[0]) || explen == 3
               || (!isalpha (tokstart[3])
                  && !isdigit (tokstart[3]) && tokstart[3] != '_')))
         {
-          lexptr += 3;
+          pstate->lexptr += 3;
           yylval.opcode = tokentab3[i].opcode;
           return tokentab3[i].token;
         }
 
   /* See if it is a special token of length 2.  */
   if (explen > 1)
-  for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
-      if (strncasecmp (tokstart, tokentab2[i].operator, 2) == 0
-          && (!isalpha (tokentab2[i].operator[0]) || explen == 2
+  for (int i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
+      if (strncasecmp (tokstart, tokentab2[i].oper, 2) == 0
+          && (!isalpha (tokentab2[i].oper[0]) || explen == 2
               || (!isalpha (tokstart[2])
                  && !isdigit (tokstart[2]) && tokstart[2] != '_')))
         {
-          lexptr += 2;
+          pstate->lexptr += 2;
           yylval.opcode = tokentab2[i].opcode;
           return tokentab2[i].token;
         }
@@ -1199,7 +1168,7 @@ yylex (void)
   switch (c = *tokstart)
     {
     case 0:
-      if (search_field && parse_completion)
+      if (search_field && pstate->parse_completion)
        return COMPLETE;
       else
        return 0;
@@ -1207,31 +1176,31 @@ yylex (void)
     case ' ':
     case '\t':
     case '\n':
-      lexptr++;
+      pstate->lexptr++;
       goto retry;
 
     case '\'':
       /* We either have a character constant ('0' or '\177' for example)
         or we have a quoted symbol reference ('foo(int,int)' in object pascal
         for example).  */
-      lexptr++;
-      c = *lexptr++;
+      pstate->lexptr++;
+      c = *pstate->lexptr++;
       if (c == '\\')
-       c = parse_escape (parse_gdbarch (pstate), &lexptr);
+       c = parse_escape (pstate->gdbarch (), &pstate->lexptr);
       else if (c == '\'')
        error (_("Empty character constant."));
 
       yylval.typed_val_int.val = c;
       yylval.typed_val_int.type = parse_type (pstate)->builtin_char;
 
-      c = *lexptr++;
+      c = *pstate->lexptr++;
       if (c != '\'')
        {
          namelen = skip_quoted (tokstart) - tokstart;
          if (namelen > 2)
            {
-             lexptr = tokstart + namelen;
-             if (lexptr[-1] != '\'')
+             pstate->lexptr = tokstart + namelen;
+             if (pstate->lexptr[-1] != '\'')
                error (_("Unmatched single quote."));
              namelen -= 2;
               tokstart++;
@@ -1244,30 +1213,30 @@ yylex (void)
 
     case '(':
       paren_depth++;
-      lexptr++;
+      pstate->lexptr++;
       return c;
 
     case ')':
       if (paren_depth == 0)
        return 0;
       paren_depth--;
-      lexptr++;
+      pstate->lexptr++;
       return c;
 
     case ',':
-      if (comma_terminates && paren_depth == 0)
+      if (pstate->comma_terminates && paren_depth == 0)
        return 0;
-      lexptr++;
+      pstate->lexptr++;
       return c;
 
     case '.':
       /* Might be a floating point number.  */
-      if (lexptr[1] < '0' || lexptr[1] > '9')
+      if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9')
        {
          goto symbol;          /* Nope, must be a symbol.  */
        }
 
-      /* FALL THRU into number case.  */
+      /* FALL THRU.  */
 
     case '0':
     case '1':
@@ -1330,7 +1299,7 @@ yylex (void)
            err_copy[p - tokstart] = 0;
            error (_("Invalid number \"%s\"."), err_copy);
          }
-       lexptr = p;
+       pstate->lexptr = p;
        return toktype;
       }
 
@@ -1354,7 +1323,7 @@ yylex (void)
     case '{':
     case '}':
     symbol:
-      lexptr++;
+      pstate->lexptr++;
       return c;
 
     case '"':
@@ -1387,7 +1356,7 @@ yylex (void)
            break;
          case '\\':
            ++tokptr;
-           c = parse_escape (parse_gdbarch (pstate), &tokptr);
+           c = parse_escape (pstate->gdbarch (), &tokptr);
            if (c == -1)
              {
                continue;
@@ -1406,7 +1375,7 @@ yylex (void)
       tempbuf[tempbufindex] = '\0';    /* See note above.  */
       yylval.sval.ptr = tempbuf;
       yylval.sval.length = tempbufindex;
-      lexptr = tokptr;
+      pstate->lexptr = tokptr;
       return (STRING);
     }
 
@@ -1457,7 +1426,7 @@ yylex (void)
       return 0;
     }
 
-  lexptr += namelen;
+  pstate->lexptr += namelen;
 
   tryname:
 
@@ -1507,8 +1476,8 @@ yylex (void)
              inserted in FPC stabs debug info.  */
          static const char this_name[] = "this";
 
-         if (lookup_symbol (this_name, expression_context_block,
-                            VAR_DOMAIN, NULL))
+         if (lookup_symbol (this_name, pstate->expression_context_block,
+                            VAR_DOMAIN, NULL).symbol)
            {
              free (uptokstart);
              return THIS;
@@ -1531,12 +1500,12 @@ yylex (void)
         so in expression to enter hexadecimal values
         we still need to use C syntax with 0xff  */
       write_dollar_variable (pstate, yylval.sval);
-      tmp = alloca (namelen + 1);
+      tmp = (char *) alloca (namelen + 1);
       memcpy (tmp, tokstart, namelen);
       tmp[namelen] = '\0';
       intvar = lookup_only_internalvar (tmp + 1);
       free (uptokstart);
-      return VARIABLE;
+      return DOLLAR_VARIABLE;
     }
 
   /* Use token-type BLOCKNAME for symbols that happen to be defined as
@@ -1545,40 +1514,42 @@ yylex (void)
      currently as names of types; NAME for other symbols.
      The caller is not constrained to care about the distinction.  */
   {
-    char *tmp = copy_name (yylval.sval);
+    std::string tmp = copy_name (yylval.sval);
     struct symbol *sym;
     struct field_of_this_result is_a_field_of_this;
     int is_a_field = 0;
     int hextype;
 
-
+    is_a_field_of_this.type = NULL;
     if (search_field && current_type)
-      is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+      is_a_field = (lookup_struct_elt_type (current_type,
+                                           tmp.c_str (), 1) != NULL);
     if (is_a_field)
       sym = NULL;
     else
-      sym = lookup_symbol (tmpexpression_context_block,
-                          VAR_DOMAIN, &is_a_field_of_this);
+      sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
+                          VAR_DOMAIN, &is_a_field_of_this).symbol;
     /* second chance uppercased (as Free Pascal does).  */
     if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
       {
-       for (i = 0; i <= namelen; i++)
+       for (int i = 0; i <= namelen; i++)
          {
            if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
              tmp[i] -= ('a'-'A');
          }
        if (search_field && current_type)
-        is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+        is_a_field = (lookup_struct_elt_type (current_type,
+                                              tmp.c_str (), 1) != NULL);
        if (is_a_field)
         sym = NULL;
        else
-        sym = lookup_symbol (tmpexpression_context_block,
-                             VAR_DOMAIN, &is_a_field_of_this);
+        sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
+                             VAR_DOMAIN, &is_a_field_of_this).symbol;
       }
     /* Third chance Capitalized (as GPC does).  */
     if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
       {
-       for (i = 0; i <= namelen; i++)
+       for (int i = 0; i <= namelen; i++)
          {
            if (i == 0)
              {
@@ -1590,31 +1561,39 @@ yylex (void)
              tmp[i] -= ('A'-'a');
           }
        if (search_field && current_type)
-        is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+        is_a_field = (lookup_struct_elt_type (current_type,
+                                              tmp.c_str (), 1) != NULL);
        if (is_a_field)
         sym = NULL;
        else
-        sym = lookup_symbol (tmpexpression_context_block,
-                             VAR_DOMAIN, &is_a_field_of_this);
+        sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
+                             VAR_DOMAIN, &is_a_field_of_this).symbol;
       }
 
-    if (is_a_field)
+    if (is_a_field || (is_a_field_of_this.type != NULL))
       {
        tempbuf = (char *) realloc (tempbuf, namelen + 1);
-       strncpy (tempbuf, tmp, namelen);
+       strncpy (tempbuf, tmp.c_str (), namelen);
        tempbuf [namelen] = 0;
        yylval.sval.ptr = tempbuf;
        yylval.sval.length = namelen;
+       yylval.ssym.sym.symbol = NULL;
+       yylval.ssym.sym.block = NULL;
        free (uptokstart);
-       return FIELDNAME;
+        yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
+       if (is_a_field)
+         return FIELDNAME;
+       else
+         return NAME;
       }
     /* Call lookup_symtab, not lookup_partial_symtab, in case there are
        no psymtabs (coff, xcoff, or some future change to blow away the
        psymtabs once once symbols are read).  */
     if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
-        || lookup_symtab (tmp))
+        || lookup_symtab (tmp.c_str ()))
       {
-       yylval.ssym.sym = sym;
+       yylval.ssym.sym.symbol = sym;
+       yylval.ssym.sym.block = NULL;
        yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
        free (uptokstart);
        return BLOCKNAME;
@@ -1646,7 +1625,7 @@ yylex (void)
             us whether a type is nested), we just ignore the
             containing type.  */
 
-         p = lexptr;
+         p = pstate->lexptr;
          best_sym = sym;
          while (1)
            {
@@ -1670,24 +1649,28 @@ yylex (void)
                      struct symbol *cur_sym;
                      /* As big as the whole rest of the expression, which is
                         at least big enough.  */
-                     char *ncopy = alloca (strlen (tmp)+strlen (namestart)+3);
+                     char *ncopy
+                       = (char *) alloca (tmp.size () + strlen (namestart)
+                                          + 3);
                      char *tmp1;
 
                      tmp1 = ncopy;
-                     memcpy (tmp1, tmp, strlen (tmp));
-                     tmp1 += strlen (tmp);
+                     memcpy (tmp1, tmp.c_str (), tmp.size ());
+                     tmp1 += tmp.size ();
                      memcpy (tmp1, "::", 2);
                      tmp1 += 2;
                      memcpy (tmp1, namestart, p - namestart);
                      tmp1[p - namestart] = '\0';
-                     cur_sym = lookup_symbol (ncopy, expression_context_block,
-                                              VAR_DOMAIN, NULL);
+                     cur_sym
+                       = lookup_symbol (ncopy,
+                                        pstate->expression_context_block,
+                                        VAR_DOMAIN, NULL).symbol;
                      if (cur_sym)
                        {
                          if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
                            {
                              best_sym = cur_sym;
-                             lexptr = p;
+                             pstate->lexptr = p;
                            }
                          else
                            break;
@@ -1710,8 +1693,8 @@ yylex (void)
          return TYPENAME;
         }
     yylval.tsym.type
-      = language_lookup_primitive_type (parse_language (pstate),
-                                       parse_gdbarch (pstate), tmp);
+      = language_lookup_primitive_type (pstate->language (),
+                                       pstate->gdbarch (), tmp.c_str ());
     if (yylval.tsym.type != NULL)
       {
        free (uptokstart);
@@ -1729,7 +1712,8 @@ yylex (void)
        hextype = parse_number (pstate, tokstart, namelen, 0, &newlval);
        if (hextype == INT)
          {
-           yylval.ssym.sym = sym;
+           yylval.ssym.sym.symbol = sym;
+           yylval.ssym.sym.block = NULL;
            yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
            free (uptokstart);
            return NAME_OR_INT;
@@ -1738,8 +1722,8 @@ yylex (void)
 
     free(uptokstart);
     /* Any other kind of symbol.  */
-    yylval.ssym.sym = sym;
-    yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
+    yylval.ssym.sym.symbol = sym;
+    yylval.ssym.sym.block = NULL;
     return NAME;
   }
 }
@@ -1747,23 +1731,20 @@ yylex (void)
 int
 pascal_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;
+  paren_depth = 0;
 
-  result = yyparse ();
-  do_cleanups (c);
-  return result;
+  return yyparse ();
 }
 
-void
-yyerror (char *msg)
+static void
+yyerror (const char *msg)
 {
-  if (prev_lexptr)
-    lexptr = prev_lexptr;
+  if (pstate->prev_lexptr)
+    pstate->lexptr = pstate->prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
 }
This page took 0.050941 seconds and 4 git commands to generate.