Remove paren_depth global
authorTom Tromey <tom@tromey.com>
Sun, 24 Mar 2019 17:33:10 +0000 (11:33 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 5 Apr 2019 01:55:10 +0000 (19:55 -0600)
This removes the "paren_depth" global.  In most cases, it is made into
a static global in a given parser.  I consider this a slight
improvement, because it makes it clear that the variable isn't used
for communication between different modules of gdb.  The one exception
is the Rust parser, which already incorporates all local state into a
transient object; in this case the parser depth is now a member.

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

* rust-exp.y (struct rust_parser) <paren_depth>: New member.
(rustyylex, rust_lex_test_init, rust_lex_test_one)
(rust_lex_test_sequence, rust_lex_test_push_back): Update.
* parser-defs.h (paren_depth): Don't declare.
* parse.c (paren_depth): Remove global.
(parse_exp_in_context): Update.
* p-exp.y (paren_depth): New global.
(pascal_parse): Initialize it.
* m2-exp.y (paren_depth): New global.
(m2_parse): Initialize it.
* go-exp.y (paren_depth): New global.
(go_parse): Initialize it.
* f-exp.y (paren_depth): New global.
(f_parse): Initialize it.
* d-exp.y (paren_depth): New global.
(d_parse): Initialize it.
* c-exp.y (paren_depth): New global.
(c_parse): Initialize it.
* ada-lex.l (paren_depth): New global.
(lexer_init): Initialize it.

gdb/ChangeLog
gdb/ada-lex.l
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
gdb/rust-exp.y

index fec79ebb493a232ef9bb7b25501ed45fb8f90789..3e03604528bb6b1d89deb16bbccc71f4841a5e15 100644 (file)
@@ -1,3 +1,26 @@
+2019-04-04  Tom Tromey  <tom@tromey.com>
+
+       * rust-exp.y (struct rust_parser) <paren_depth>: New member.
+       (rustyylex, rust_lex_test_init, rust_lex_test_one)
+       (rust_lex_test_sequence, rust_lex_test_push_back): Update.
+       * parser-defs.h (paren_depth): Don't declare.
+       * parse.c (paren_depth): Remove global.
+       (parse_exp_in_context): Update.
+       * p-exp.y (paren_depth): New global.
+       (pascal_parse): Initialize it.
+       * m2-exp.y (paren_depth): New global.
+       (m2_parse): Initialize it.
+       * go-exp.y (paren_depth): New global.
+       (go_parse): Initialize it.
+       * f-exp.y (paren_depth): New global.
+       (f_parse): Initialize it.
+       * d-exp.y (paren_depth): New global.
+       (d_parse): Initialize it.
+       * c-exp.y (paren_depth): New global.
+       (c_parse): Initialize it.
+       * ada-lex.l (paren_depth): New global.
+       (lexer_init): Initialize it.
+
 2019-04-04  Tom Tromey  <tom@tromey.com>
 
        * rust-exp.y (rust_parser::crate_name, rust_parser::super_name)
index 17ac7e5d3d5d099b73904216089406b481a320d7..6163405545d4c4c10d2c92f26bfa3ecd5a7cd2d1 100644 (file)
@@ -84,6 +84,9 @@ static void rewind_to_char (int);
 
 static int find_dot_all (const char *);
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
 %}
 
 %option case-insensitive interactive nodefault
@@ -305,6 +308,7 @@ static void
 lexer_init (FILE *inp)
 {
   BEGIN INITIAL;
+  paren_depth = 0;
   yyrestart (inp);
 }
 
index e6d6c208f159beb87b9c336a57d52913299603b5..cb9e9e002c74c7c749564ac75c0dcf03e0014321 100644 (file)
@@ -2527,6 +2527,9 @@ static int saw_name_at_eof;
    operator -- either '.' or ARROW.  */
 static bool last_was_structop;
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
 /* Read one token, getting characters through lexptr.  */
 
 static int
@@ -3315,6 +3318,7 @@ c_parse (struct parser_state *par_state)
   /* Initialize some state used by the lexer.  */
   last_was_structop = false;
   saw_name_at_eof = 0;
+  paren_depth = 0;
 
   token_fifo.clear ();
   popping = 0;
index a701c2541d3fdfe75e7b25e7433a00e50946290b..c15199535214abc79a0e7b7e1d0c34a8abdbcb5c 100644 (file)
@@ -1020,6 +1020,9 @@ static int saw_name_at_eof;
    This is used only when parsing to do field name completion.  */
 static int last_was_structop;
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
 /* Read one token, getting characters through lexptr.  */
 
 static int
@@ -1619,6 +1622,7 @@ d_parse (struct parser_state *par_state)
   /* Initialize some state used by the lexer.  */
   last_was_structop = 0;
   saw_name_at_eof = 0;
+  paren_depth = 0;
 
   token_fifo.clear ();
   popping = 0;
index 5670136b2a6714a7dea700db4ab6719ed1f5036e..100a3bbec145a84643711ad23ba3ffbdda95490c 100644 (file)
@@ -68,6 +68,9 @@
 
 static struct parser_state *pstate = NULL;
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
 int yyparse (void);
 
 static int yylex (void);
@@ -1328,6 +1331,7 @@ f_parse (struct parser_state *par_state)
                                                        parser_debug);
   gdb_assert (par_state != NULL);
   pstate = par_state;
+  paren_depth = 0;
 
   return yyparse ();
 }
index d112a73f21a7957128897ef3fe66f84f27f6f1e6..aaffe3d45a063a23025339fee12a1111a22cf6ce 100644 (file)
@@ -1001,6 +1001,9 @@ static int saw_name_at_eof;
    do field name completion.  */
 static int last_was_structop;
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
 /* Read one token, getting characters through lexptr.  */
 
 static int
@@ -1566,6 +1569,7 @@ go_parse (struct parser_state *par_state)
   /* Initialize some state used by the lexer.  */
   last_was_structop = 0;
   saw_name_at_eof = 0;
+  paren_depth = 0;
 
   token_fifo.clear ();
   popping = 0;
index c1418c751f1486081b31ba0f429bca68bab9a950..c0f5e75be2a9f09bd00fda96161272dc5ffbedda 100644 (file)
@@ -763,6 +763,9 @@ static struct keyword keytab[] =
 };
 
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
 /* Read one token, getting characters through lexptr.  */
 
 /* This is where we will check to make sure that the language and the
@@ -1039,6 +1042,7 @@ m2_parse (struct parser_state *par_state)
   scoped_restore pstate_restore = make_scoped_restore (&pstate);
   gdb_assert (par_state != NULL);
   pstate = par_state;
+  paren_depth = 0;
 
   return yyparse ();
 }
index dbccf358d5c58564efc4025d73cdf095a364e96a..768f302592198a1405c76d468d2065c880067b6c 100644 (file)
@@ -68,6 +68,9 @@
 
 static struct parser_state *pstate = NULL;
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
 int yyparse (void);
 
 static int yylex (void);
@@ -1723,6 +1726,7 @@ pascal_parse (struct parser_state *par_state)
   scoped_restore pstate_restore = make_scoped_restore (&pstate);
   gdb_assert (par_state != NULL);
   pstate = par_state;
+  paren_depth = 0;
 
   return yyparse ();
 }
index d76aeb1d853f7611c90e58382dee16ed1189c4fa..4ac79faaeae3e6cf5215bb5071554fbea0b5c3c0 100644 (file)
@@ -71,7 +71,6 @@ int arglist_len;
 static struct type_stack type_stack;
 const char *lexptr;
 const char *prev_lexptr;
-int paren_depth;
 int comma_terminates;
 
 /* True if parsing an expression to attempt completion.  */
@@ -1117,7 +1116,6 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
   lexptr = *stringptr;
   prev_lexptr = NULL;
 
-  paren_depth = 0;
   type_stack.elements.clear ();
   expout_last_struct = -1;
   expout_tag_completion_type = TYPE_CODE_UNDEF;
index f895a552879837061fc6eacfa6d0a041fa746400..6fb0f8e5533503f292089ee5b080736d2c455d21 100644 (file)
@@ -356,10 +356,6 @@ extern const char *lexptr;
    Currently used only for error reporting.  */
 extern const char *prev_lexptr;
 
-/* Current depth in parentheses within the expression.  */
-
-extern int paren_depth;
-
 /* Nonzero means stop parsing on first comma (if not within parentheses).  */
 
 extern int comma_terminates;
index 1b7e33e617249ef3fd5be801b69ca30fbf9e3e87..9d3083ead929ff42e3aa2ea427e1a23dab150b72 100644 (file)
@@ -300,6 +300,9 @@ struct rust_parser
 
   /* The parser state gdb gave us.  */
   struct parser_state *pstate;
+
+  /* Depth of parentheses.  */
+  int paren_depth = 0;
 };
 
 /* Rust AST operations.  We build a tree of these; then lower them to
@@ -1664,14 +1667,14 @@ rustyylex (YYSTYPE *lvalp, rust_parser *parser)
   else if (lexptr[0] == '}' || lexptr[0] == ']')
     {
       /* Falls through to lex_operator.  */
-      --paren_depth;
+      --parser->paren_depth;
     }
   else if (lexptr[0] == '(' || lexptr[0] == '{')
     {
       /* Falls through to lex_operator.  */
-      ++paren_depth;
+      ++parser->paren_depth;
     }
-  else if (lexptr[0] == ',' && comma_terminates && paren_depth == 0)
+  else if (lexptr[0] == ',' && comma_terminates && parser->paren_depth == 0)
     return 0;
 
   return lex_operator (lvalp);
@@ -2552,11 +2555,11 @@ rustyyerror (rust_parser *parser, const char *msg)
 /* Initialize the lexer for testing.  */
 
 static void
-rust_lex_test_init (const char *input)
+rust_lex_test_init (rust_parser *parser, const char *input)
 {
   prev_lexptr = NULL;
   lexptr = input;
-  paren_depth = 0;
+  parser->paren_depth = 0;
 }
 
 /* A test helper that lexes a string, expecting a single token.  It
@@ -2568,7 +2571,7 @@ rust_lex_test_one (rust_parser *parser, const char *input, int expected)
   int token;
   RUSTSTYPE result;
 
-  rust_lex_test_init (input);
+  rust_lex_test_init (parser, input);
 
   token = rustyylex (&result, parser);
   SELF_CHECK (token == expected);
@@ -2632,7 +2635,7 @@ rust_lex_test_sequence (rust_parser *parser, const char *input, int len,
   int i;
 
   lexptr = input;
-  paren_depth = 0;
+  parser->paren_depth = 0;
 
   for (i = 0; i < len; ++i)
     {
@@ -2686,7 +2689,7 @@ rust_lex_test_push_back (rust_parser *parser)
   int token;
   RUSTSTYPE lval;
 
-  rust_lex_test_init (">>=");
+  rust_lex_test_init (parser, ">>=");
 
   token = rustyylex (&lval, parser);
   SELF_CHECK (token == COMPOUND_ASSIGN);
This page took 0.035512 seconds and 4 git commands to generate.