Move arglist_len et al to parser_state
authorTom Tromey <tom@tromey.com>
Mon, 25 Mar 2019 03:38:40 +0000 (21:38 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 5 Apr 2019 01:55:11 +0000 (19:55 -0600)
This moves arglist_len, start_arglist, and end_arglist to
parser_state.

gdb/ChangeLog
2019-04-04  Tom Tromey  <tom@tromey.com>

* parser-defs.h (struct parser_state) <start_arglist,
end_arglist>: New methods.
<arglist_len, m_funcall_chain>: New members.
(arglist_len, start_arglist, end_arglist): Don't declare.
* parse.c (arglist_len, funcall_chain): Remove global.
(start_arglist, end_arglist): Remove functions.
(parse_exp_in_context): Update.
* p-exp.y: Update rules.
* m2-exp.y: Update rules.
* go-exp.y: Update rules.
* f-exp.y: Update rules.
* d-exp.y: Update rules.
* c-exp.y: Update rules.

gdb/ChangeLog
gdb/c-exp.y
gdb/d-exp.y
gdb/f-exp.y
gdb/go-exp.y
gdb/m2-exp.y
gdb/p-exp.y
gdb/parse.c
gdb/parser-defs.h

index 629e555..7fc73d2 100644 (file)
@@ -1,5 +1,21 @@
 2019-04-04  Tom Tromey  <tom@tromey.com>
 
+       * parser-defs.h (struct parser_state) <start_arglist,
+       end_arglist>: New methods.
+       <arglist_len, m_funcall_chain>: New members.
+       (arglist_len, start_arglist, end_arglist): Don't declare.
+       * parse.c (arglist_len, funcall_chain): Remove global.
+       (start_arglist, end_arglist): Remove functions.
+       (parse_exp_in_context): Update.
+       * p-exp.y: Update rules.
+       * m2-exp.y: Update rules.
+       * go-exp.y: Update rules.
+       * f-exp.y: Update rules.
+       * d-exp.y: Update rules.
+       * c-exp.y: Update rules.
+
+2019-04-04  Tom Tromey  <tom@tromey.com>
+
        * rust-exp.y (struct rust_parser) <lex_hex, lex_escape,
        lex_operator, push_back>: New methods.
        Update all rules.
index c85bb31..cab5cd5 100644 (file)
@@ -534,11 +534,11 @@ msgarg    :       name ':' exp
 exp    :       exp '('
                        /* This is to save the value of arglist_len
                           being accumulated by an outer function call.  */
-                       { 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); }
        ;
 
@@ -546,10 +546,10 @@ exp       :       exp '('
    "func()::static_var" further below, which uses
    function_method_void.  */
 exp    :       exp '(' ')' %prec ARROW
-                       { start_arglist ();
+                       { pstate->start_arglist ();
                          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); }
        ;
 
@@ -569,30 +569,30 @@ exp       :       UNKNOWN_CPP_NAME '('
                        /* This is to save the value of arglist_len
                           being accumulated by an outer function call.  */
 
-                         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);
                        }
        ;
 
 lcurly :       '{'
-                       { start_arglist (); }
+                       { pstate->start_arglist (); }
        ;
 
 arglist        :
        ;
 
 arglist        :       exp
-                       { arglist_len = 1; }
+                       { pstate->arglist_len = 1; }
        ;
 
 arglist        :       arglist ',' exp   %prec ABOVE_COMMA
-                       { arglist_len++; }
+                       { pstate->arglist_len++; }
        ;
 
 function_method:       exp '(' parameter_typelist ')' const_or_volatile
@@ -645,7 +645,7 @@ exp     :       function_method_void_or_typelist COLONCOLON name
        ;
 
 rcurly :       '}'
-                       { $$ = end_arglist () - 1; }
+                       { $$ = pstate->end_arglist () - 1; }
        ;
 exp    :       lcurly arglist rcurly   %prec ARROW
                        { write_exp_elt_opcode (pstate, OP_ARRAY);
index 9addf6c..c14c2d6 100644 (file)
@@ -366,32 +366,32 @@ PostfixExpression:
 
 ArgumentList:
        AssignExpression
-               { arglist_len = 1; }
+               { pstate->arglist_len = 1; }
 |      ArgumentList ',' AssignExpression
-               { arglist_len++; }
+               { pstate->arglist_len++; }
 ;
 
 ArgumentList_opt:
        /* EMPTY */
-               { arglist_len = 0; }
+               { pstate->arglist_len = 0; }
 |      ArgumentList
 ;
 
 CallExpression:
        PostfixExpression '('
-               { start_arglist (); }
+               { pstate->start_arglist (); }
        ArgumentList_opt ')'
                { write_exp_elt_opcode (pstate, OP_FUNCALL);
-                 write_exp_elt_longcst (pstate, (LONGEST) end_arglist ());
+                 write_exp_elt_longcst (pstate, pstate->end_arglist ());
                  write_exp_elt_opcode (pstate, OP_FUNCALL); }
 ;
 
 IndexExpression:
        PostfixExpression '[' ArgumentList ']'
-               { if (arglist_len > 0)
+               { if (pstate->arglist_len > 0)
                    {
                      write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT);
-                     write_exp_elt_longcst (pstate, (LONGEST) arglist_len);
+                     write_exp_elt_longcst (pstate, pstate->arglist_len);
                      write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT);
                    }
                  else
@@ -558,7 +558,7 @@ PrimaryExpression:
 
 ArrayLiteral:
        '[' ArgumentList_opt ']'
-               { $$ = arglist_len; }
+               { $$ = pstate->arglist_len; }
 ;
 
 IdentifierExp:
index fce90b4..da47322 100644 (file)
@@ -245,12 +245,12 @@ exp       :       KIND '(' exp ')'       %prec UNARY
    later in eval.c.  */
 
 exp    :       exp '(' 
-                       { start_arglist (); }
+                       { pstate->start_arglist (); }
                arglist ')'     
                        { write_exp_elt_opcode (pstate,
                                                OP_F77_UNDETERMINED_ARGLIST);
                          write_exp_elt_longcst (pstate,
-                                                (LONGEST) end_arglist ());
+                                                pstate->end_arglist ());
                          write_exp_elt_opcode (pstate,
                                              OP_F77_UNDETERMINED_ARGLIST); }
        ;
@@ -263,15 +263,15 @@ arglist   :
        ;
 
 arglist        :       exp
-                       { arglist_len = 1; }
+                       { pstate->arglist_len = 1; }
        ;
 
 arglist :      subrange
-                       { arglist_len = 1; }
+                       { pstate->arglist_len = 1; }
        ;
    
 arglist        :       arglist ',' exp   %prec ABOVE_COMMA
-                       { arglist_len++; }
+                       { pstate->arglist_len++; }
        ;
 
 /* There are four sorts of subrange types in F90.  */
index 6754d52..358fd53 100644 (file)
@@ -269,31 +269,31 @@ exp       :       exp '[' exp1 ']'
 exp    :       exp '('
                        /* This is to save the value of arglist_len
                           being accumulated by an outer function call.  */
-                       { start_arglist (); }
+                       { pstate->start_arglist (); }
                arglist ')'     %prec LEFT_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); }
        ;
 
 lcurly :       '{'
-                       { start_arglist (); }
+                       { pstate->start_arglist (); }
        ;
 
 arglist        :
        ;
 
 arglist        :       exp
-                       { arglist_len = 1; }
+                       { pstate->arglist_len = 1; }
        ;
 
 arglist        :       arglist ',' exp   %prec ABOVE_COMMA
-                       { arglist_len++; }
+                       { pstate->arglist_len++; }
        ;
 
 rcurly :       '}'
-                       { $$ = end_arglist () - 1; }
+                       { $$ = pstate->end_arglist () - 1; }
        ;
 
 exp    :       lcurly type rcurly exp  %prec UNARY
index 6ba8eaf..3e4bc07 100644 (file)
@@ -298,11 +298,11 @@ exp     :       exp '['
                         /* This function just saves the number of arguments
                           that follow in the list.  It is *not* specific to
                           function types */
-                        { start_arglist(); }
+                        { pstate->start_arglist(); }
                 non_empty_arglist ']'  %prec DOT
                         { write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT);
                          write_exp_elt_longcst (pstate,
-                                                (LONGEST) end_arglist());
+                                                pstate->end_arglist());
                          write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); }
         ;
 
@@ -313,11 +313,11 @@ exp       :       exp '[' exp ']'
 exp    :       exp '('
                        /* This is to save the value of arglist_len
                           being accumulated by an outer function call.  */
-                       { start_arglist (); }
+                       { pstate->start_arglist (); }
                arglist ')'     %prec DOT
                        { 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); }
        ;
 
@@ -325,21 +325,21 @@ arglist   :
        ;
 
 arglist        :       exp
-                       { arglist_len = 1; }
+                       { pstate->arglist_len = 1; }
        ;
 
 arglist        :       arglist ',' exp   %prec ABOVE_COMMA
-                       { arglist_len++; }
+                       { pstate->arglist_len++; }
        ;
 
 non_empty_arglist
         :       exp
-                        { arglist_len = 1; }
+                        { pstate->arglist_len = 1; }
        ;
 
 non_empty_arglist
         :       non_empty_arglist ',' exp %prec ABOVE_COMMA
-                       { arglist_len++; }
+                       { pstate->arglist_len++; }
        ;
 
 /* GDB construct */
index 4487899..0f78126 100644 (file)
@@ -334,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)
@@ -348,9 +348,9 @@ 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
index 5692e23..6ee6157 100644 (file)
@@ -67,7 +67,6 @@ const struct exp_descriptor exp_descriptor_standard =
 \f
 /* Global variables declared in parser-defs.h (and commented there).  */
 innermost_block_tracker innermost_block;
-int arglist_len;
 static struct type_stack type_stack;
 
 /* True if parsing an expression to attempt completion.  */
@@ -128,33 +127,6 @@ innermost_block_tracker::update (const struct block *b,
     m_innermost_block = b;
 }
 
-/* Data structure for saving values of arglist_len for function calls whose
-   arguments contain other function calls.  */
-
-static std::vector<int> *funcall_chain;
-
-/* Begin counting arguments for a function call,
-   saving the data about any containing call.  */
-
-void
-start_arglist (void)
-{
-  funcall_chain->push_back (arglist_len);
-  arglist_len = 0;
-}
-
-/* Return the number of arguments in a function call just terminated,
-   and restore the data for the containing function call.  */
-
-int
-end_arglist (void)
-{
-  int val = arglist_len;
-  arglist_len = funcall_chain->back ();
-  funcall_chain->pop_back ();
-  return val;
-}
-
 \f
 
 /* See definition in parser-defs.h.  */
@@ -1119,10 +1091,6 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
   if (*stringptr == 0 || **stringptr == 0)
     error_no_arg (_("expression to compute"));
 
-  std::vector<int> funcalls;
-  scoped_restore save_funcall_chain = make_scoped_restore (&funcall_chain,
-                                                          &funcalls);
-
   const struct block *expression_context_block = block;
   CORE_ADDR expression_context_pc = 0;
 
index 66828e0..a015115 100644 (file)
@@ -101,6 +101,27 @@ struct parser_state : public expr_builder
 
   DISABLE_COPY_AND_ASSIGN (parser_state);
 
+  /* Begin counting arguments for a function call,
+     saving the data about any containing call.  */
+
+  void start_arglist ()
+  {
+    m_funcall_chain.push_back (arglist_len);
+    arglist_len = 0;
+  }
+
+  /* Return the number of arguments in a function call just terminated,
+     and restore the data for the containing function call.  */
+
+  int end_arglist ()
+  {
+    int val = arglist_len;
+    arglist_len = m_funcall_chain.back ();
+    m_funcall_chain.pop_back ();
+    return val;
+  }
+
+
   /* If this is nonzero, this block is used as the lexical context for
      symbol names.  */
 
@@ -125,6 +146,17 @@ struct parser_state : public expr_builder
   /* After a token has been recognized, this variable points to it.
      Currently used only for error reporting.  */
   const char *prev_lexptr = nullptr;
+
+  /* Number of arguments seen so far in innermost function call.  */
+
+  int arglist_len = 0;
+
+private:
+
+  /* Data structure for saving values of arglist_len for function calls whose
+     arguments contain other function calls.  */
+
+  std::vector<int> m_funcall_chain;
 };
 
 /* When parsing expressions we track the innermost block that was
@@ -185,9 +217,6 @@ private:
    once the parse is complete.  */
 extern innermost_block_tracker innermost_block;
 
-/* Number of arguments seen so far in innermost function call.  */
-extern int arglist_len;
-
 /* A string token, either a char-string or bit-string.  Char-strings are
    used, for example, for the names of symbols.  */
 
@@ -311,10 +340,6 @@ extern void mark_struct_expression (struct expr_builder *);
 
 extern const char *find_template_name_end (const char *);
 
-extern void start_arglist (void);
-
-extern int end_arglist (void);
-
 extern char *copy_name (struct stoken);
 
 extern void insert_type (enum type_pieces);