public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Remove accessor macros from linespec.c
@ 2024-06-06 14:45 Tom Tromey
  2024-06-06 14:45 ` [PATCH 1/6] Remove PARSER_STATE macro Tom Tromey
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Tom Tromey @ 2024-06-06 14:45 UTC (permalink / raw)
  To: gdb-patches

This series removes the accessor macros from linespec.c.  This kind of
macro was a staple of old-style gdb, but I don't think they provide
any real value over direct access to fields.

---
Tom Tromey (6):
      Remove PARSER_STATE macro
      Remove PARSER_RESULT macro
      Remove PARSER_EXPLICIT macro
      Remove PARSER_STREAM macro
      Remove LS_TOKEN_KEYWORD macro
      Remove LS_TOKEN_STOKEN macro

 gdb/linespec.c | 395 +++++++++++++++++++++++++++------------------------------
 1 file changed, 190 insertions(+), 205 deletions(-)
---
base-commit: 6ba072193126c833c4742e7dd5dfb6cff4b4ef18
change-id: 20240606-linespec-no-macros-7ef0939915b8

Best regards,
-- 
Tom Tromey <tromey@adacore.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/6] Remove PARSER_STATE macro
  2024-06-06 14:45 [PATCH 0/6] Remove accessor macros from linespec.c Tom Tromey
@ 2024-06-06 14:45 ` Tom Tromey
  2024-06-06 14:45 ` [PATCH 2/6] Remove PARSER_RESULT macro Tom Tromey
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2024-06-06 14:45 UTC (permalink / raw)
  To: gdb-patches

This removes the PARSER_STATE macro from linespec.c.
---
 gdb/linespec.c | 52 +++++++++++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index ca154d2dcba..0d7cb691e05 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -311,7 +311,6 @@ struct linespec_parser
 
   /* The state of the parse.  */
   struct linespec_state state {};
-#define PARSER_STATE(PPTR) (&(PPTR)->state)
 
   /* The result of the parse.  */
   linespec result;
@@ -680,7 +679,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
       char quote_char = *PARSER_STREAM (parser);
 
       /* Special case: Ada operators.  */
-      if (PARSER_STATE (parser)->language->la_language == language_ada
+      if (parser->state.language->la_language == language_ada
 	  && quote_char == '\"')
 	{
 	  int len = is_ada_operator (PARSER_STREAM (parser));
@@ -820,7 +819,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	      /* Don't interpret 'operator<' / 'operator<<' as a
 		 template parameter list though.  */
 	      if (*PARSER_STREAM (parser) == '<'
-		  && (PARSER_STATE (parser)->language->la_language
+		  && (parser->state.language->la_language
 		      == language_cplus)
 		  && (PARSER_STREAM (parser) - start) >= CP_OPERATOR_LEN)
 		{
@@ -866,7 +865,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	     operator name.  */
 	  else if (*PARSER_STREAM (parser) == ',')
 	    {
-	      if ((PARSER_STATE (parser)->language->la_language
+	      if ((parser->state.language->la_language
 		   == language_cplus)
 		  && (PARSER_STREAM (parser) - start) > CP_OPERATOR_LEN)
 		{
@@ -1811,7 +1810,7 @@ linespec_parse_basic (linespec_parser *parser)
       std::vector<bound_minimal_symbol> minimal_symbols;
 
       /* Try looking it up as a function/method.  */
-      find_linespec_symbols (PARSER_STATE (parser),
+      find_linespec_symbols (&parser->state,
 			     PARSER_RESULT (parser)->file_symtabs, name.get (),
 			     PARSER_EXPLICIT (parser)->func_name_match_type,
 			     &symbols, &minimal_symbols);
@@ -1827,7 +1826,7 @@ linespec_parse_basic (linespec_parser *parser)
 	  /* NAME was not a function or a method.  So it must be a label
 	     name or user specified variable like "break foo.c:$zippo".  */
 	  std::vector<block_symbol> labels
-	    = find_label_symbols (PARSER_STATE (parser), {}, &symbols,
+	    = find_label_symbols (&parser->state, {}, &symbols,
 				  name.get ());
 
 	  if (!labels.empty ())
@@ -1842,7 +1841,7 @@ linespec_parse_basic (linespec_parser *parser)
 	    {
 	      /* User specified a convenience variable or history value.  */
 	      PARSER_EXPLICIT (parser)->line_offset
-		= linespec_parse_variable (PARSER_STATE (parser), name.get ());
+		= linespec_parse_variable (&parser->state, name.get ());
 
 	      if (PARSER_EXPLICIT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN)
 		{
@@ -1934,7 +1933,7 @@ linespec_parse_basic (linespec_parser *parser)
 	      /* Grab a copy of the label's name and look it up.  */
 	      name = copy_token_string (token);
 	      std::vector<block_symbol> labels
-		= find_label_symbols (PARSER_STATE (parser),
+		= find_label_symbols (&parser->state,
 				      PARSER_RESULT (parser)->function_symbols,
 				      &symbols, name.get ());
 
@@ -2482,14 +2481,14 @@ parse_linespec (linespec_parser *parser, const char *arg,
   PARSER_EXPLICIT (parser)->func_name_match_type = match_type;
 
   /* Initialize the default symtab and line offset.  */
-  initialize_defaults (&PARSER_STATE (parser)->default_symtab,
-		       &PARSER_STATE (parser)->default_line);
+  initialize_defaults (&parser->state.default_symtab,
+		       &parser->state.default_line);
 
   /* Objective-C shortcut.  */
   if (parser->completion_tracker == NULL)
     {
       std::vector<symtab_and_line> values
-	= decode_objc (PARSER_STATE (parser), PARSER_RESULT (parser), arg);
+	= decode_objc (&parser->state, PARSER_RESULT (parser), arg);
       if (!values.empty ())
 	return values;
     }
@@ -2518,7 +2517,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
       /* User specified a convenience variable or history value.  */
       gdb::unique_xmalloc_ptr<char> var = copy_token_string (token);
       PARSER_EXPLICIT (parser)->line_offset
-	= linespec_parse_variable (PARSER_STATE (parser), var.get ());
+	= linespec_parse_variable (&parser->state, var.get ());
 
       /* If a line_offset wasn't found (VAR is the name of a user
 	 variable/function), then skip to normal symbol processing.  */
@@ -2556,7 +2555,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
 	{
 	  PARSER_RESULT (parser)->file_symtabs
 	    = symtabs_from_filename (user_filename.get (),
-				     PARSER_STATE (parser)->search_pspace);
+				     parser->state.search_pspace);
 	}
       catch (gdb_exception_error &ex)
 	{
@@ -2635,7 +2634,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
 
   /* Convert the data in PARSER_RESULT to SALs.  */
   if (parser->completion_tracker == NULL)
-    return convert_linespec_to_sals (PARSER_STATE (parser),
+    return convert_linespec_to_sals (&parser->state,
 				     PARSER_RESULT (parser));
 
   return {};
@@ -2679,7 +2678,7 @@ linespec_parser::linespec_parser (int flags,
   PARSER_EXPLICIT (this)->func_name_match_type
     = symbol_name_match_type::WILD;
   PARSER_EXPLICIT (this)->line_offset.sign = LINE_OFFSET_UNKNOWN;
-  linespec_state_constructor (PARSER_STATE (this), flags, language,
+  linespec_state_constructor (&state, flags, language,
 			      search_pspace,
 			      default_symtab, default_line, canonical);
 }
@@ -2697,7 +2696,7 @@ linespec_state_destructor (struct linespec_state *self)
 
 linespec_parser::~linespec_parser ()
 {
-  linespec_state_destructor (PARSER_STATE (this));
+  linespec_state_destructor (&state);
 }
 
 /* See description in linespec.h.  */
@@ -2826,7 +2825,7 @@ complete_label (completion_tracker &tracker,
 {
   std::vector<block_symbol> label_function_symbols;
   std::vector<block_symbol> labels
-    = find_label_symbols (PARSER_STATE (parser),
+    = find_label_symbols (&parser->state,
 			  PARSER_RESULT (parser)->function_symbols,
 			  &label_function_symbols,
 			  label_name, true);
@@ -2854,7 +2853,7 @@ linespec_complete_label (completion_tracker &tracker,
 
   try
     {
-      convert_explicit_location_spec_to_linespec (PARSER_STATE (&parser),
+      convert_explicit_location_spec_to_linespec (&parser.state,
 						  PARSER_RESULT (&parser),
 						  source_filename,
 						  function_name,
@@ -2883,7 +2882,7 @@ linespec_complete (completion_tracker &tracker, const char *text,
   PARSER_STREAM (&parser) = text;
 
   parser.completion_tracker = &tracker;
-  PARSER_STATE (&parser)->is_linespec = 1;
+  parser.state.is_linespec = 1;
 
   /* Parse as much as possible.  parser.completion_word will hold
      furthest completion point we managed to parse to.  */
@@ -2934,7 +2933,7 @@ linespec_complete (completion_tracker &tracker, const char *text,
 
       std::vector<block_symbol> function_symbols;
       std::vector<bound_minimal_symbol> minimal_symbols;
-      find_linespec_symbols (PARSER_STATE (&parser),
+      find_linespec_symbols (&parser.state,
 			     PARSER_RESULT (&parser)->file_symtabs,
 			     func_name, match_type,
 			     &function_symbols, &minimal_symbols);
@@ -3075,7 +3074,7 @@ location_spec_to_sals (linespec_parser *parser,
     case LINESPEC_LOCATION_SPEC:
       {
 	const linespec_location_spec *ls = as_linespec_location_spec (locspec);
-	PARSER_STATE (parser)->is_linespec = 1;
+	parser->state.is_linespec = 1;
 	result = parse_linespec (parser, ls->spec_string.get (),
 				 ls->match_type);
       }
@@ -3091,13 +3090,13 @@ location_spec_to_sals (linespec_parser *parser,
 	if (addr_string != NULL)
 	  {
 	    addr = linespec_expression_to_pc (&addr_string);
-	    if (PARSER_STATE (parser)->canonical != NULL)
-	      PARSER_STATE (parser)->canonical->locspec	= locspec->clone ();
+	    if (parser->state.canonical != NULL)
+	      parser->state.canonical->locspec	= locspec->clone ();
 	  }
 	else
 	  addr = addr_spec->address;
 
-	result = convert_address_location_to_sals (PARSER_STATE (parser),
+	result = convert_address_location_to_sals (&parser->state,
 						   addr);
       }
       break;
@@ -3106,7 +3105,7 @@ location_spec_to_sals (linespec_parser *parser,
       {
 	const explicit_location_spec *explicit_locspec
 	  = as_explicit_location_spec (locspec);
-	result = convert_explicit_location_spec_to_sals (PARSER_STATE (parser),
+	result = convert_explicit_location_spec_to_sals (&parser->state,
 							 PARSER_RESULT (parser),
 							 explicit_locspec);
       }
@@ -3135,7 +3134,6 @@ decode_line_full (struct location_spec *locspec, int flags,
 		  const char *filter)
 {
   std::vector<const char *> filters;
-  struct linespec_state *state;
 
   gdb_assert (canonical != NULL);
   /* The filter only makes sense for 'all'.  */
@@ -3154,7 +3152,7 @@ decode_line_full (struct location_spec *locspec, int flags,
 
   std::vector<symtab_and_line> result = location_spec_to_sals (&parser,
 							       locspec);
-  state = PARSER_STATE (&parser);
+  linespec_state *state = &parser.state;
 
   if (result.size () == 0)
     throw_error (NOT_SUPPORTED_ERROR, _("Location %s not available"),

-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/6] Remove PARSER_RESULT macro
  2024-06-06 14:45 [PATCH 0/6] Remove accessor macros from linespec.c Tom Tromey
  2024-06-06 14:45 ` [PATCH 1/6] Remove PARSER_STATE macro Tom Tromey
@ 2024-06-06 14:45 ` Tom Tromey
  2024-06-06 14:45 ` [PATCH 3/6] Remove PARSER_EXPLICIT macro Tom Tromey
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2024-06-06 14:45 UTC (permalink / raw)
  To: gdb-patches

This removes the PARSER_RESULT macro from linespec.c.
---
 gdb/linespec.c | 56 +++++++++++++++++++++++++-------------------------------
 1 file changed, 25 insertions(+), 31 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 0d7cb691e05..2ad4b9fe812 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -314,7 +314,6 @@ struct linespec_parser
 
   /* The result of the parse.  */
   linespec result;
-#define PARSER_RESULT(PPTR) (&(PPTR)->result)
 
   /* What the parser believes the current word point should complete
      to.  */
@@ -342,7 +341,7 @@ struct linespec_parser
 
 /* A convenience macro for accessing the explicit location spec result
    of the parser.  */
-#define PARSER_EXPLICIT(PPTR) (&PARSER_RESULT ((PPTR))->explicit_loc)
+#define PARSER_EXPLICIT(PPTR) (&((PPTR)->result).explicit_loc)
 
 /* Prototypes for local functions.  */
 
@@ -1811,14 +1810,14 @@ linespec_parse_basic (linespec_parser *parser)
 
       /* Try looking it up as a function/method.  */
       find_linespec_symbols (&parser->state,
-			     PARSER_RESULT (parser)->file_symtabs, name.get (),
+			     parser->result.file_symtabs, name.get (),
 			     PARSER_EXPLICIT (parser)->func_name_match_type,
 			     &symbols, &minimal_symbols);
 
       if (!symbols.empty () || !minimal_symbols.empty ())
 	{
-	  PARSER_RESULT (parser)->function_symbols = std::move (symbols);
-	  PARSER_RESULT (parser)->minimal_symbols = std::move (minimal_symbols);
+	  parser->result.function_symbols = std::move (symbols);
+	  parser->result.minimal_symbols = std::move (minimal_symbols);
 	  PARSER_EXPLICIT (parser)->function_name = std::move (name);
 	}
       else
@@ -1831,9 +1830,8 @@ linespec_parse_basic (linespec_parser *parser)
 
 	  if (!labels.empty ())
 	    {
-	      PARSER_RESULT (parser)->labels.label_symbols = std::move (labels);
-	      PARSER_RESULT (parser)->labels.function_symbols
-		  = std::move (symbols);
+	      parser->result.labels.label_symbols = std::move (labels);
+	      parser->result.labels.function_symbols = std::move (symbols);
 	      PARSER_EXPLICIT (parser)->label_name = std::move (name);
 	    }
 	  else if (token.type == LSTOKEN_STRING
@@ -1934,15 +1932,13 @@ linespec_parse_basic (linespec_parser *parser)
 	      name = copy_token_string (token);
 	      std::vector<block_symbol> labels
 		= find_label_symbols (&parser->state,
-				      PARSER_RESULT (parser)->function_symbols,
+				      parser->result.function_symbols,
 				      &symbols, name.get ());
 
 	      if (!labels.empty ())
 		{
-		  PARSER_RESULT (parser)->labels.label_symbols
-		    = std::move (labels);
-		  PARSER_RESULT (parser)->labels.function_symbols
-		    = std::move (symbols);
+		  parser->result.labels.label_symbols = std::move (labels);
+		  parser->result.labels.function_symbols = std::move (symbols);
 		  PARSER_EXPLICIT (parser)->label_name = std::move (name);
 		}
 	      else
@@ -2488,7 +2484,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
   if (parser->completion_tracker == NULL)
     {
       std::vector<symtab_and_line> values
-	= decode_objc (&parser->state, PARSER_RESULT (parser), arg);
+	= decode_objc (&parser->state, &parser->result, arg);
       if (!values.empty ())
 	return values;
     }
@@ -2512,7 +2508,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
     {
       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
       if (parser->completion_tracker == NULL)
-	PARSER_RESULT (parser)->file_symtabs.push_back (nullptr);
+	parser->result.file_symtabs.push_back (nullptr);
 
       /* User specified a convenience variable or history value.  */
       gdb::unique_xmalloc_ptr<char> var = copy_token_string (token);
@@ -2553,7 +2549,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
       /* Check if the input is a filename.  */
       try
 	{
-	  PARSER_RESULT (parser)->file_symtabs
+	  parser->result.file_symtabs
 	    = symtabs_from_filename (user_filename.get (),
 				     parser->state.search_pspace);
 	}
@@ -2576,7 +2572,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
       else
 	{
 	  /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
-	  PARSER_RESULT (parser)->file_symtabs.push_back (nullptr);
+	  parser->result.file_symtabs.push_back (nullptr);
 	}
     }
   /* If the next token is not EOI, KEYWORD, or COMMA, issue an error.  */
@@ -2592,17 +2588,17 @@ parse_linespec (linespec_parser *parser, const char *arg,
   else
     {
       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
-      PARSER_RESULT (parser)->file_symtabs.push_back (nullptr);
+      parser->result.file_symtabs.push_back (nullptr);
     }
 
   /* Parse the rest of the linespec.  */
   linespec_parse_basic (parser);
 
   if (parser->completion_tracker == NULL
-      && PARSER_RESULT (parser)->function_symbols.empty ()
-      && PARSER_RESULT (parser)->labels.label_symbols.empty ()
+      && parser->result.function_symbols.empty ()
+      && parser->result.labels.label_symbols.empty ()
       && PARSER_EXPLICIT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN
-      && PARSER_RESULT (parser)->minimal_symbols.empty ())
+      && parser->result.minimal_symbols.empty ())
     {
       /* The linespec didn't parse.  Re-throw the file exception if
 	 there was one.  */
@@ -2632,10 +2628,9 @@ parse_linespec (linespec_parser *parser, const char *arg,
       parser->complete_what = linespec_complete_what::EXPRESSION;
     }
 
-  /* Convert the data in PARSER_RESULT to SALs.  */
+  /* Convert the data in the parser's result to SALs.  */
   if (parser->completion_tracker == NULL)
-    return convert_linespec_to_sals (&parser->state,
-				     PARSER_RESULT (parser));
+    return convert_linespec_to_sals (&parser->state, &parser->result);
 
   return {};
 }
@@ -2826,7 +2821,7 @@ complete_label (completion_tracker &tracker,
   std::vector<block_symbol> label_function_symbols;
   std::vector<block_symbol> labels
     = find_label_symbols (&parser->state,
-			  PARSER_RESULT (parser)->function_symbols,
+			  parser->result.function_symbols,
 			  &label_function_symbols,
 			  label_name, true);
 
@@ -2854,7 +2849,7 @@ linespec_complete_label (completion_tracker &tracker,
   try
     {
       convert_explicit_location_spec_to_linespec (&parser.state,
-						  PARSER_RESULT (&parser),
+						  &parser.result,
 						  source_filename,
 						  function_name,
 						  func_name_match_type,
@@ -2934,13 +2929,12 @@ linespec_complete (completion_tracker &tracker, const char *text,
       std::vector<block_symbol> function_symbols;
       std::vector<bound_minimal_symbol> minimal_symbols;
       find_linespec_symbols (&parser.state,
-			     PARSER_RESULT (&parser)->file_symtabs,
+			     parser.result.file_symtabs,
 			     func_name, match_type,
 			     &function_symbols, &minimal_symbols);
 
-      PARSER_RESULT (&parser)->function_symbols = std::move (function_symbols);
-      PARSER_RESULT (&parser)->minimal_symbols = std::move (minimal_symbols);
-
+      parser.result.function_symbols = std::move (function_symbols);
+      parser.result.minimal_symbols = std::move (minimal_symbols);
       complete_label (tracker, &parser, parser.completion_word);
     }
   else if (parser.complete_what == linespec_complete_what::FUNCTION)
@@ -3106,7 +3100,7 @@ location_spec_to_sals (linespec_parser *parser,
 	const explicit_location_spec *explicit_locspec
 	  = as_explicit_location_spec (locspec);
 	result = convert_explicit_location_spec_to_sals (&parser->state,
-							 PARSER_RESULT (parser),
+							 &parser->result,
 							 explicit_locspec);
       }
       break;

-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/6] Remove PARSER_EXPLICIT macro
  2024-06-06 14:45 [PATCH 0/6] Remove accessor macros from linespec.c Tom Tromey
  2024-06-06 14:45 ` [PATCH 1/6] Remove PARSER_STATE macro Tom Tromey
  2024-06-06 14:45 ` [PATCH 2/6] Remove PARSER_RESULT macro Tom Tromey
@ 2024-06-06 14:45 ` Tom Tromey
  2024-06-06 14:45 ` [PATCH 4/6] Remove PARSER_STREAM macro Tom Tromey
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2024-06-06 14:45 UTC (permalink / raw)
  To: gdb-patches

This removes the PARSER_EXPLICIT macro from linespec.c.
---
 gdb/linespec.c | 63 ++++++++++++++++++++++++++++------------------------------
 1 file changed, 30 insertions(+), 33 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 2ad4b9fe812..32b620ab116 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -339,10 +339,6 @@ struct linespec_parser
   struct completion_tracker *completion_tracker = nullptr;
 };
 
-/* A convenience macro for accessing the explicit location spec result
-   of the parser.  */
-#define PARSER_EXPLICIT(PPTR) (&((PPTR)->result).explicit_loc)
-
 /* Prototypes for local functions.  */
 
 static void iterate_over_file_blocks
@@ -1730,7 +1726,7 @@ linespec_parse_basic (linespec_parser *parser)
 
       /* Record the line offset and get the next token.  */
       name = copy_token_string (token);
-      PARSER_EXPLICIT (parser)->line_offset
+      parser->result.explicit_loc.line_offset
 	= linespec_parse_line_offset (name.get ());
 
       /* Get the next token.  */
@@ -1781,9 +1777,9 @@ linespec_parse_basic (linespec_parser *parser)
 	{
 	  completion_tracker tmp_tracker (false);
 	  const char *source_filename
-	    = PARSER_EXPLICIT (parser)->source_filename.get ();
+	    = parser->result.explicit_loc.source_filename.get ();
 	  symbol_name_match_type match_type
-	    = PARSER_EXPLICIT (parser)->func_name_match_type;
+	    = parser->result.explicit_loc.func_name_match_type;
 
 	  linespec_complete_function (tmp_tracker,
 				      parser->completion_word,
@@ -1801,7 +1797,7 @@ linespec_parse_basic (linespec_parser *parser)
 	    }
 	}
 
-      PARSER_EXPLICIT (parser)->function_name = std::move (name);
+      parser->result.explicit_loc.function_name = std::move (name);
     }
   else
     {
@@ -1811,14 +1807,14 @@ linespec_parse_basic (linespec_parser *parser)
       /* Try looking it up as a function/method.  */
       find_linespec_symbols (&parser->state,
 			     parser->result.file_symtabs, name.get (),
-			     PARSER_EXPLICIT (parser)->func_name_match_type,
+			     parser->result.explicit_loc.func_name_match_type,
 			     &symbols, &minimal_symbols);
 
       if (!symbols.empty () || !minimal_symbols.empty ())
 	{
 	  parser->result.function_symbols = std::move (symbols);
 	  parser->result.minimal_symbols = std::move (minimal_symbols);
-	  PARSER_EXPLICIT (parser)->function_name = std::move (name);
+	  parser->result.explicit_loc.function_name = std::move (name);
 	}
       else
 	{
@@ -1832,20 +1828,21 @@ linespec_parse_basic (linespec_parser *parser)
 	    {
 	      parser->result.labels.label_symbols = std::move (labels);
 	      parser->result.labels.function_symbols = std::move (symbols);
-	      PARSER_EXPLICIT (parser)->label_name = std::move (name);
+	      parser->result.explicit_loc.label_name = std::move (name);
 	    }
 	  else if (token.type == LSTOKEN_STRING
 		   && *LS_TOKEN_STOKEN (token).ptr == '$')
 	    {
 	      /* User specified a convenience variable or history value.  */
-	      PARSER_EXPLICIT (parser)->line_offset
+	      parser->result.explicit_loc.line_offset
 		= linespec_parse_variable (&parser->state, name.get ());
 
-	      if (PARSER_EXPLICIT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN)
+	      if (parser->result.explicit_loc.line_offset.sign
+		  == LINE_OFFSET_UNKNOWN)
 		{
 		  /* The user-specified variable was not valid.  Do not
 		     throw an error here.  parse_linespec will do it for us.  */
-		  PARSER_EXPLICIT (parser)->function_name = std::move (name);
+		  parser->result.explicit_loc.function_name = std::move (name);
 		  return;
 		}
 	    }
@@ -1855,7 +1852,7 @@ linespec_parse_basic (linespec_parser *parser)
 		 an error here.  parse_linespec will do it for us.  */
 
 	      /* Save a copy of the name we were trying to lookup.  */
-	      PARSER_EXPLICIT (parser)->function_name = std::move (name);
+	      parser->result.explicit_loc.function_name = std::move (name);
 	      return;
 	    }
 	}
@@ -1883,7 +1880,7 @@ linespec_parse_basic (linespec_parser *parser)
 	  set_completion_after_number (parser, linespec_complete_what::KEYWORD);
 
 	  name = copy_token_string (token);
-	  PARSER_EXPLICIT (parser)->line_offset
+	  parser->result.explicit_loc.line_offset
 	    = linespec_parse_line_offset (name.get ());
 
 	  /* Get the next token.  */
@@ -1939,13 +1936,13 @@ linespec_parse_basic (linespec_parser *parser)
 		{
 		  parser->result.labels.label_symbols = std::move (labels);
 		  parser->result.labels.function_symbols = std::move (symbols);
-		  PARSER_EXPLICIT (parser)->label_name = std::move (name);
+		  parser->result.explicit_loc.label_name = std::move (name);
 		}
 	      else
 		{
 		  /* We don't know what it was, but it isn't a label.  */
 		  undefined_label_error
-		    (PARSER_EXPLICIT (parser)->function_name.get (),
+		    (parser->result.explicit_loc.function_name.get (),
 		     name.get ());
 		}
 
@@ -1965,7 +1962,7 @@ linespec_parse_basic (linespec_parser *parser)
 	      /* Record the line offset and get the next token.  */
 	      name = copy_token_string (token);
 
-	      PARSER_EXPLICIT (parser)->line_offset
+	      parser->result.explicit_loc.line_offset
 		= linespec_parse_line_offset (name.get ());
 
 	      /* Get the next token.  */
@@ -2474,7 +2471,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
   parser->lexer.stream = arg;
   parser->completion_word = arg;
   parser->complete_what = linespec_complete_what::FUNCTION;
-  PARSER_EXPLICIT (parser)->func_name_match_type = match_type;
+  parser->result.explicit_loc.func_name_match_type = match_type;
 
   /* Initialize the default symtab and line offset.  */
   initialize_defaults (&parser->state.default_symtab,
@@ -2512,12 +2509,12 @@ parse_linespec (linespec_parser *parser, const char *arg,
 
       /* User specified a convenience variable or history value.  */
       gdb::unique_xmalloc_ptr<char> var = copy_token_string (token);
-      PARSER_EXPLICIT (parser)->line_offset
+      parser->result.explicit_loc.line_offset
 	= linespec_parse_variable (&parser->state, var.get ());
 
       /* If a line_offset wasn't found (VAR is the name of a user
 	 variable/function), then skip to normal symbol processing.  */
-      if (PARSER_EXPLICIT (parser)->line_offset.sign != LINE_OFFSET_UNKNOWN)
+      if (parser->result.explicit_loc.line_offset.sign != LINE_OFFSET_UNKNOWN)
 	{
 	  /* Consume this token.  */
 	  linespec_lexer_consume_token (parser);
@@ -2561,7 +2558,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
       if (file_exception.reason >= 0)
 	{
 	  /* Symtabs were found for the file.  Record the filename.  */
-	  PARSER_EXPLICIT (parser)->source_filename = std::move (user_filename);
+	  parser->result.explicit_loc.source_filename = std::move (user_filename);
 
 	  /* Get the next token.  */
 	  token = linespec_lexer_consume_token (parser);
@@ -2597,7 +2594,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
   if (parser->completion_tracker == NULL
       && parser->result.function_symbols.empty ()
       && parser->result.labels.label_symbols.empty ()
-      && PARSER_EXPLICIT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN
+      && parser->result.explicit_loc.line_offset.sign == LINE_OFFSET_UNKNOWN
       && parser->result.minimal_symbols.empty ())
     {
       /* The linespec didn't parse.  Re-throw the file exception if
@@ -2607,8 +2604,8 @@ parse_linespec (linespec_parser *parser, const char *arg,
 
       /* Otherwise, the symbol is not found.  */
       symbol_not_found_error
-	(PARSER_EXPLICIT (parser)->function_name.get (),
-	 PARSER_EXPLICIT (parser)->source_filename.get ());
+	(parser->result.explicit_loc.function_name.get (),
+	 parser->result.explicit_loc.source_filename.get ());
     }
 
  convert_to_sals:
@@ -2670,9 +2667,9 @@ linespec_parser::linespec_parser (int flags,
 				  struct linespec_result *canonical)
 {
   lexer.current.type = LSTOKEN_CONSUMED;
-  PARSER_EXPLICIT (this)->func_name_match_type
+  result.explicit_loc.func_name_match_type
     = symbol_name_match_type::WILD;
-  PARSER_EXPLICIT (this)->line_offset.sign = LINE_OFFSET_UNKNOWN;
+  result.explicit_loc.line_offset.sign = LINE_OFFSET_UNKNOWN;
   linespec_state_constructor (&state, flags, language,
 			      search_pspace,
 			      default_symtab, default_line, canonical);
@@ -2771,7 +2768,7 @@ complete_linespec_component (linespec_parser *parser,
       completion_list fn_list;
 
       symbol_name_match_type match_type
-	= PARSER_EXPLICIT (parser)->func_name_match_type;
+	= parser->result.explicit_loc.func_name_match_type;
       linespec_complete_function (tracker, text, match_type, source_filename);
       if (source_filename == NULL)
 	{
@@ -2873,7 +2870,7 @@ linespec_complete (completion_tracker &tracker, const char *text,
 
   linespec_parser parser (0, current_language, NULL, NULL, 0, NULL);
   parser.lexer.saved_arg = text;
-  PARSER_EXPLICIT (&parser)->func_name_match_type = match_type;
+  parser.result.explicit_loc.func_name_match_type = match_type;
   PARSER_STREAM (&parser) = text;
 
   parser.completion_tracker = &tracker;
@@ -2924,7 +2921,7 @@ linespec_complete (completion_tracker &tracker, const char *text,
     {
       parser.complete_what = linespec_complete_what::NOTHING;
 
-      const char *func_name = PARSER_EXPLICIT (&parser)->function_name.get ();
+      const char *func_name = parser.result.explicit_loc.function_name.get ();
 
       std::vector<block_symbol> function_symbols;
       std::vector<bound_minimal_symbol> minimal_symbols;
@@ -2984,7 +2981,7 @@ linespec_complete (completion_tracker &tracker, const char *text,
 	(&parser, tracker,
 	 parser.completion_word,
 	 linespec_complete_what::FUNCTION,
-	 PARSER_EXPLICIT (&parser)->source_filename.get ());
+	 parser.result.explicit_loc.source_filename.get ());
 
       parser.complete_what = linespec_complete_what::NOTHING;
 
@@ -3028,7 +3025,7 @@ linespec_complete (completion_tracker &tracker, const char *text,
     (&parser, tracker,
      parser.completion_word,
      parser.complete_what,
-     PARSER_EXPLICIT (&parser)->source_filename.get ());
+     parser.result.explicit_loc.source_filename.get ());
 
   /* If we're past the "filename:function:label:offset" linespec, and
      didn't find any match, then assume the user might want to create

-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/6] Remove PARSER_STREAM macro
  2024-06-06 14:45 [PATCH 0/6] Remove accessor macros from linespec.c Tom Tromey
                   ` (2 preceding siblings ...)
  2024-06-06 14:45 ` [PATCH 3/6] Remove PARSER_EXPLICIT macro Tom Tromey
@ 2024-06-06 14:45 ` Tom Tromey
  2024-06-06 14:45 ` [PATCH 5/6] Remove LS_TOKEN_KEYWORD macro Tom Tromey
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2024-06-06 14:45 UTC (permalink / raw)
  To: gdb-patches

This removes the PARSER_STREAM macro from linespec.c.
---
 gdb/linespec.c | 175 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 87 insertions(+), 88 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 32b620ab116..b85d57c13c2 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -300,7 +300,6 @@ struct linespec_parser
 
     /* Head of the input stream.  */
     const char *stream;
-#define PARSER_STREAM(P) ((P)->lexer.stream)
 
     /* The current token.  */
     linespec_token current;
@@ -429,29 +428,29 @@ linespec_lexer_lex_number (linespec_parser *parser, linespec_token *tokenp)
 {
   tokenp->type = LSTOKEN_NUMBER;
   LS_TOKEN_STOKEN (*tokenp).length = 0;
-  LS_TOKEN_STOKEN (*tokenp).ptr = PARSER_STREAM (parser);
+  LS_TOKEN_STOKEN (*tokenp).ptr = parser->lexer.stream;
 
   /* Keep any sign at the start of the stream.  */
-  if (*PARSER_STREAM (parser) == '+' || *PARSER_STREAM (parser) == '-')
+  if (*parser->lexer.stream == '+' || *parser->lexer.stream == '-')
     {
       ++LS_TOKEN_STOKEN (*tokenp).length;
-      ++(PARSER_STREAM (parser));
+      ++(parser->lexer.stream);
     }
 
-  while (isdigit (*PARSER_STREAM (parser)))
+  while (isdigit (*parser->lexer.stream))
     {
       ++LS_TOKEN_STOKEN (*tokenp).length;
-      ++(PARSER_STREAM (parser));
+      ++(parser->lexer.stream);
     }
 
   /* If the next character in the input buffer is not a space, comma,
      quote, or colon, this input does not represent a number.  */
-  if (*PARSER_STREAM (parser) != '\0'
-      && !isspace (*PARSER_STREAM (parser)) && *PARSER_STREAM (parser) != ','
-      && *PARSER_STREAM (parser) != ':'
-      && !strchr (linespec_quote_characters, *PARSER_STREAM (parser)))
+  if (*parser->lexer.stream != '\0'
+      && !isspace (*parser->lexer.stream) && *parser->lexer.stream != ','
+      && *parser->lexer.stream != ':'
+      && !strchr (linespec_quote_characters, *parser->lexer.stream))
     {
-      PARSER_STREAM (parser) = LS_TOKEN_STOKEN (*tokenp).ptr;
+      parser->lexer.stream = LS_TOKEN_STOKEN (*tokenp).ptr;
       return 0;
     }
 
@@ -662,30 +661,30 @@ static linespec_token
 linespec_lexer_lex_string (linespec_parser *parser)
 {
   linespec_token token;
-  const char *start = PARSER_STREAM (parser);
+  const char *start = parser->lexer.stream;
 
   token.type = LSTOKEN_STRING;
 
   /* If the input stream starts with a quote character, skip to the next
      quote character, regardless of the content.  */
-  if (strchr (linespec_quote_characters, *PARSER_STREAM (parser)))
+  if (strchr (linespec_quote_characters, *parser->lexer.stream))
     {
       const char *end;
-      char quote_char = *PARSER_STREAM (parser);
+      char quote_char = *parser->lexer.stream;
 
       /* Special case: Ada operators.  */
       if (parser->state.language->la_language == language_ada
 	  && quote_char == '\"')
 	{
-	  int len = is_ada_operator (PARSER_STREAM (parser));
+	  int len = is_ada_operator (parser->lexer.stream);
 
 	  if (len != 0)
 	    {
 	      /* The input is an Ada operator.  Return the quoted string
 		 as-is.  */
-	      LS_TOKEN_STOKEN (token).ptr = PARSER_STREAM (parser);
+	      LS_TOKEN_STOKEN (token).ptr = parser->lexer.stream;
 	      LS_TOKEN_STOKEN (token).length = len;
-	      PARSER_STREAM (parser) += len;
+	      parser->lexer.stream += len;
 	      return token;
 	    }
 
@@ -694,13 +693,13 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	}
 
       /* Skip past the beginning quote.  */
-      ++(PARSER_STREAM (parser));
+      ++(parser->lexer.stream);
 
       /* Mark the start of the string.  */
-      LS_TOKEN_STOKEN (token).ptr = PARSER_STREAM (parser);
+      LS_TOKEN_STOKEN (token).ptr = parser->lexer.stream;
 
       /* Skip to the ending quote.  */
-      end = skip_quote_char (PARSER_STREAM (parser), quote_char);
+      end = skip_quote_char (parser->lexer.stream, quote_char);
 
       /* This helps the completer mode decide whether we have a
 	 complete string.  */
@@ -717,15 +716,15 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	  /* In completion mode, we'll try to complete the incomplete
 	     token.  */
 	  token.type = LSTOKEN_STRING;
-	  while (*PARSER_STREAM (parser) != '\0')
-	    PARSER_STREAM (parser)++;
-	  LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - 1 - start;
+	  while (*parser->lexer.stream != '\0')
+	    parser->lexer.stream++;
+	  LS_TOKEN_STOKEN (token).length = parser->lexer.stream - 1 - start;
 	}
       else
 	{
 	  /* Skip over the ending quote and mark the length of the string.  */
-	  PARSER_STREAM (parser) = (char *) ++end;
-	  LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - 2 - start;
+	  parser->lexer.stream = (char *) ++end;
+	  LS_TOKEN_STOKEN (token).length = parser->lexer.stream - 2 - start;
 	}
     }
   else
@@ -742,9 +741,9 @@ linespec_lexer_lex_string (linespec_parser *parser)
 
       while (1)
 	{
-	  if (isspace (*PARSER_STREAM (parser)))
+	  if (isspace (*parser->lexer.stream))
 	    {
-	      p = skip_spaces (PARSER_STREAM (parser));
+	      p = skip_spaces (parser->lexer.stream);
 	      /* When we get here we know we've found something followed by
 		 a space (we skip over parens and templates below).
 		 So if we find a keyword now, we know it is a keyword and not,
@@ -753,31 +752,31 @@ linespec_lexer_lex_string (linespec_parser *parser)
 		{
 		  LS_TOKEN_STOKEN (token).ptr = start;
 		  LS_TOKEN_STOKEN (token).length
-		    = PARSER_STREAM (parser) - start;
+		    = parser->lexer.stream - start;
 		  return token;
 		}
 
 	      /* Advance past the whitespace.  */
-	      PARSER_STREAM (parser) = p;
+	      parser->lexer.stream = p;
 	    }
 
 	  /* If the next character is EOI or (single) ':', the
 	     string is complete;  return the token.  */
-	  if (*PARSER_STREAM (parser) == 0)
+	  if (*parser->lexer.stream == 0)
 	    {
 	      LS_TOKEN_STOKEN (token).ptr = start;
-	      LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
+	      LS_TOKEN_STOKEN (token).length = parser->lexer.stream - start;
 	      return token;
 	    }
-	  else if (PARSER_STREAM (parser)[0] == ':')
+	  else if (parser->lexer.stream[0] == ':')
 	    {
 	      /* Do not tokenize the C++ scope operator. */
-	      if (PARSER_STREAM (parser)[1] == ':')
-		++(PARSER_STREAM (parser));
+	      if (parser->lexer.stream[1] == ':')
+		++(parser->lexer.stream);
 
 	      /* Do not tokenize ABI tags such as "[abi:cxx11]".  */
-	      else if (PARSER_STREAM (parser) - start > 4
-		       && startswith (PARSER_STREAM (parser) - 4, "[abi"))
+	      else if (parser->lexer.stream - start > 4
+		       && startswith (parser->lexer.stream - 4, "[abi"))
 		{
 		  /* Nothing.  */
 		}
@@ -786,39 +785,39 @@ linespec_lexer_lex_string (linespec_parser *parser)
 		 (i.e, a single-letter drive name) and the next character
 		 is a directory separator.  This allows Windows-style
 		 paths to be recognized as filenames without quoting it.  */
-	      else if ((PARSER_STREAM (parser) - start) != 1
-		       || !IS_DIR_SEPARATOR (PARSER_STREAM (parser)[1]))
+	      else if ((parser->lexer.stream - start) != 1
+		       || !IS_DIR_SEPARATOR (parser->lexer.stream[1]))
 		{
 		  LS_TOKEN_STOKEN (token).ptr = start;
 		  LS_TOKEN_STOKEN (token).length
-		    = PARSER_STREAM (parser) - start;
+		    = parser->lexer.stream - start;
 		  return token;
 		}
 	    }
 	  /* Special case: permit quote-enclosed linespecs.  */
 	  else if (parser->is_quote_enclosed
 		   && strchr (linespec_quote_characters,
-			      *PARSER_STREAM (parser))
-		   && is_closing_quote_enclosed (PARSER_STREAM (parser)))
+			      *parser->lexer.stream)
+		   && is_closing_quote_enclosed (parser->lexer.stream))
 	    {
 	      LS_TOKEN_STOKEN (token).ptr = start;
-	      LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
+	      LS_TOKEN_STOKEN (token).length = parser->lexer.stream - start;
 	      return token;
 	    }
 	  /* Because commas may terminate a linespec and appear in
 	     the middle of valid string input, special cases for
 	     '<' and '(' are necessary.  */
-	  else if (*PARSER_STREAM (parser) == '<'
-		   || *PARSER_STREAM (parser) == '(')
+	  else if (*parser->lexer.stream == '<'
+		   || *parser->lexer.stream == '(')
 	    {
 	      /* Don't interpret 'operator<' / 'operator<<' as a
 		 template parameter list though.  */
-	      if (*PARSER_STREAM (parser) == '<'
+	      if (*parser->lexer.stream == '<'
 		  && (parser->state.language->la_language
 		      == language_cplus)
-		  && (PARSER_STREAM (parser) - start) >= CP_OPERATOR_LEN)
+		  && (parser->lexer.stream - start) >= CP_OPERATOR_LEN)
 		{
-		  const char *op = PARSER_STREAM (parser);
+		  const char *op = parser->lexer.stream;
 
 		  while (op > start && isspace (op[-1]))
 		    op--;
@@ -830,16 +829,16 @@ linespec_lexer_lex_string (linespec_parser *parser)
 			      || !(isalnum (op[-1]) || op[-1] == '_')))
 			{
 			  /* This is an operator name.  Keep going.  */
-			  ++(PARSER_STREAM (parser));
-			  if (*PARSER_STREAM (parser) == '<')
-			    ++(PARSER_STREAM (parser));
+			  ++(parser->lexer.stream);
+			  if (*parser->lexer.stream == '<')
+			    ++(parser->lexer.stream);
 			  continue;
 			}
 		    }
 		}
 
-	      const char *end = find_parameter_list_end (PARSER_STREAM (parser));
-	      PARSER_STREAM (parser) = end;
+	      const char *end = find_parameter_list_end (parser->lexer.stream);
+	      parser->lexer.stream = end;
 
 	      /* Don't loop around to the normal \0 case above because
 		 we don't want to misinterpret a potential keyword at
@@ -850,7 +849,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
 		{
 		  LS_TOKEN_STOKEN (token).ptr = start;
 		  LS_TOKEN_STOKEN (token).length
-		    = PARSER_STREAM (parser) - start;
+		    = parser->lexer.stream - start;
 		  return token;
 		}
 	      else
@@ -858,31 +857,31 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	    }
 	  /* Commas are terminators, but not if they are part of an
 	     operator name.  */
-	  else if (*PARSER_STREAM (parser) == ',')
+	  else if (*parser->lexer.stream == ',')
 	    {
 	      if ((parser->state.language->la_language
 		   == language_cplus)
-		  && (PARSER_STREAM (parser) - start) > CP_OPERATOR_LEN)
+		  && (parser->lexer.stream - start) > CP_OPERATOR_LEN)
 		{
 		  const char *op = strstr (start, CP_OPERATOR_STR);
 
 		  if (op != NULL && is_operator_name (op))
 		    {
 		      /* This is an operator name.  Keep going.  */
-		      ++(PARSER_STREAM (parser));
+		      ++(parser->lexer.stream);
 		      continue;
 		    }
 		}
 
 	      /* Comma terminates the string.  */
 	      LS_TOKEN_STOKEN (token).ptr = start;
-	      LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
+	      LS_TOKEN_STOKEN (token).length = parser->lexer.stream - start;
 	      return token;
 	    }
 
 	  /* Advance the stream.  */
-	  gdb_assert (*(PARSER_STREAM (parser)) != '\0');
-	  ++(PARSER_STREAM (parser));
+	  gdb_assert (*(parser->lexer.stream) != '\0');
+	  ++(parser->lexer.stream);
 	}
     }
 
@@ -899,10 +898,10 @@ linespec_lexer_lex_one (linespec_parser *parser)
   if (parser->lexer.current.type == LSTOKEN_CONSUMED)
     {
       /* Skip any whitespace.  */
-      PARSER_STREAM (parser) = skip_spaces (PARSER_STREAM (parser));
+      parser->lexer.stream = skip_spaces (parser->lexer.stream);
 
       /* Check for a keyword, they end the linespec.  */
-      keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
+      keyword = linespec_lexer_lex_keyword (parser->lexer.stream);
       if (keyword != NULL)
 	{
 	  parser->lexer.current.type = LSTOKEN_KEYWORD;
@@ -910,13 +909,13 @@ linespec_lexer_lex_one (linespec_parser *parser)
 	  /* We do not advance the stream here intentionally:
 	     we would like lexing to stop when a keyword is seen.
 
-	     PARSER_STREAM (parser) +=  strlen (keyword);  */
+	     parser->lexer.stream +=  strlen (keyword);  */
 
 	  return parser->lexer.current;
 	}
 
       /* Handle other tokens.  */
-      switch (*PARSER_STREAM (parser))
+      switch (*parser->lexer.stream)
 	{
 	case 0:
 	  parser->lexer.current.type = LSTOKEN_EOI;
@@ -932,21 +931,21 @@ linespec_lexer_lex_one (linespec_parser *parser)
 	case ':':
 	  /* If we have a scope operator, lex the input as a string.
 	     Otherwise, return LSTOKEN_COLON.  */
-	  if (PARSER_STREAM (parser)[1] == ':')
+	  if (parser->lexer.stream[1] == ':')
 	    parser->lexer.current = linespec_lexer_lex_string (parser);
 	  else
 	    {
 	      parser->lexer.current.type = LSTOKEN_COLON;
-	      ++(PARSER_STREAM (parser));
+	      ++(parser->lexer.stream);
 	    }
 	  break;
 
 	case '\'': case '\"':
 	  /* Special case: permit quote-enclosed linespecs.  */
 	  if (parser->is_quote_enclosed
-	      && is_closing_quote_enclosed (PARSER_STREAM (parser)))
+	      && is_closing_quote_enclosed (parser->lexer.stream))
 	    {
-	      ++(PARSER_STREAM (parser));
+	      ++(parser->lexer.stream);
 	      parser->lexer.current.type = LSTOKEN_EOI;
 	    }
 	  else
@@ -956,9 +955,9 @@ linespec_lexer_lex_one (linespec_parser *parser)
 	case ',':
 	  parser->lexer.current.type = LSTOKEN_COMMA;
 	  LS_TOKEN_STOKEN (parser->lexer.current).ptr
-	    = PARSER_STREAM (parser);
+	    = parser->lexer.stream;
 	  LS_TOKEN_STOKEN (parser->lexer.current).length = 1;
-	  ++(PARSER_STREAM (parser));
+	  ++(parser->lexer.stream);
 	  break;
 
 	default:
@@ -982,7 +981,7 @@ linespec_lexer_consume_token (linespec_parser *parser)
   gdb_assert (parser->lexer.current.type != LSTOKEN_EOI);
 
   bool advance_word = (parser->lexer.current.type != LSTOKEN_STRING
-		       || *PARSER_STREAM (parser) != '\0');
+		       || *parser->lexer.stream != '\0');
 
   /* If we're moving past a string to some other token, it must be the
      quote was terminated.  */
@@ -992,7 +991,7 @@ linespec_lexer_consume_token (linespec_parser *parser)
 
       /* If the string was the last (non-EOI) token, we're past the
 	 quote, but remember that for later.  */
-      if (*PARSER_STREAM (parser) != '\0')
+      if (*parser->lexer.stream != '\0')
 	{
 	  parser->completion_quote_char = '\0';
 	  parser->completion_quote_end = NULL;;
@@ -1011,7 +1010,7 @@ linespec_lexer_consume_token (linespec_parser *parser)
   else if (advance_word)
     {
       /* Advance the completion word past any whitespace.  */
-      parser->completion_word = PARSER_STREAM (parser);
+      parser->completion_word = parser->lexer.stream;
     }
 
   return parser->lexer.current;
@@ -1023,14 +1022,14 @@ static linespec_token
 linespec_lexer_peek_token (linespec_parser *parser)
 {
   linespec_token next;
-  const char *saved_stream = PARSER_STREAM (parser);
+  const char *saved_stream = parser->lexer.stream;
   linespec_token saved_token = parser->lexer.current;
   int saved_completion_quote_char = parser->completion_quote_char;
   const char *saved_completion_quote_end = parser->completion_quote_end;
   const char *saved_completion_word = parser->completion_word;
 
   next = linespec_lexer_consume_token (parser);
-  PARSER_STREAM (parser) = saved_stream;
+  parser->lexer.stream = saved_stream;
   parser->lexer.current = saved_token;
   parser->completion_quote_char = saved_completion_quote_char;
   parser->completion_quote_end = saved_completion_quote_end;
@@ -1645,7 +1644,7 @@ static linespec_token
 save_stream_and_consume_token (linespec_parser *parser)
 {
   if (linespec_lexer_peek_token (parser).type != LSTOKEN_EOI)
-    parser->completion_word = PARSER_STREAM (parser);
+    parser->completion_word = parser->lexer.stream;
   return linespec_lexer_consume_token (parser);
 }
 
@@ -1686,14 +1685,14 @@ static void
 set_completion_after_number (linespec_parser *parser,
 			     linespec_complete_what next)
 {
-  if (*PARSER_STREAM (parser) == ' ')
+  if (*parser->lexer.stream == ' ')
     {
-      parser->completion_word = skip_spaces (PARSER_STREAM (parser) + 1);
+      parser->completion_word = skip_spaces (parser->lexer.stream + 1);
       parser->complete_what = next;
     }
   else
     {
-      parser->completion_word = PARSER_STREAM (parser);
+      parser->completion_word = parser->lexer.stream;
       parser->complete_what = linespec_complete_what::NOTHING;
     }
 }
@@ -1773,7 +1772,7 @@ linespec_parse_basic (linespec_parser *parser)
 	 it part of the function name/token.  */
 
       if (!parser->completion_quote_char
-	  && strcmp (PARSER_STREAM (parser), ":") == 0)
+	  && strcmp (parser->lexer.stream, ":") == 0)
 	{
 	  completion_tracker tmp_tracker (false);
 	  const char *source_filename
@@ -1788,11 +1787,11 @@ linespec_parse_basic (linespec_parser *parser)
 
 	  if (tmp_tracker.have_completions ())
 	    {
-	      PARSER_STREAM (parser)++;
+	      parser->lexer.stream++;
 	      LS_TOKEN_STOKEN (token).length++;
 
 	      name.reset (savestring (parser->completion_word,
-				      (PARSER_STREAM (parser)
+				      (parser->lexer.stream
 				       - parser->completion_word)));
 	    }
 	}
@@ -1907,7 +1906,7 @@ linespec_parse_basic (linespec_parser *parser)
 		  if (ptr[i] == ' ')
 		    {
 		      LS_TOKEN_STOKEN (token).length = i;
-		      PARSER_STREAM (parser) = skip_spaces (ptr + i + 1);
+		      parser->lexer.stream = skip_spaces (ptr + i + 1);
 		      break;
 		    }
 		}
@@ -1915,9 +1914,9 @@ linespec_parse_basic (linespec_parser *parser)
 
 	  if (parser->completion_tracker != NULL)
 	    {
-	      if (PARSER_STREAM (parser)[-1] == ' ')
+	      if (parser->lexer.stream[-1] == ' ')
 		{
-		  parser->completion_word = PARSER_STREAM (parser);
+		  parser->completion_word = parser->lexer.stream;
 		  parser->complete_what = linespec_complete_what::KEYWORD;
 		}
 	    }
@@ -2621,7 +2620,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
 	 advances past a keyword automatically, so skip it
 	 manually.  */
       parser->completion_word
-	= skip_spaces (skip_to_space (PARSER_STREAM (parser)));
+	= skip_spaces (skip_to_space (parser->lexer.stream));
       parser->complete_what = linespec_complete_what::EXPRESSION;
     }
 
@@ -2704,7 +2703,7 @@ linespec_lex_to_end (const char **stringp)
 
   linespec_parser parser (0, current_language, NULL, NULL, 0, NULL);
   parser.lexer.saved_arg = *stringp;
-  PARSER_STREAM (&parser) = orig = *stringp;
+  parser.lexer.stream = orig = *stringp;
 
   do
     {
@@ -2717,7 +2716,7 @@ linespec_lex_to_end (const char **stringp)
     }
   while (token.type != LSTOKEN_EOI && token.type != LSTOKEN_KEYWORD);
 
-  *stringp += PARSER_STREAM (&parser) - orig;
+  *stringp += parser.lexer.stream - orig;
 }
 
 /* See linespec.h.  */
@@ -2871,7 +2870,7 @@ linespec_complete (completion_tracker &tracker, const char *text,
   linespec_parser parser (0, current_language, NULL, NULL, 0, NULL);
   parser.lexer.saved_arg = text;
   parser.result.explicit_loc.func_name_match_type = match_type;
-  PARSER_STREAM (&parser) = text;
+  parser.lexer.stream = text;
 
   parser.completion_tracker = &tracker;
   parser.state.is_linespec = 1;

-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/6] Remove LS_TOKEN_KEYWORD macro
  2024-06-06 14:45 [PATCH 0/6] Remove accessor macros from linespec.c Tom Tromey
                   ` (3 preceding siblings ...)
  2024-06-06 14:45 ` [PATCH 4/6] Remove PARSER_STREAM macro Tom Tromey
@ 2024-06-06 14:45 ` Tom Tromey
  2024-06-06 14:45 ` [PATCH 6/6] Remove LS_TOKEN_STOKEN macro Tom Tromey
  2024-06-12 16:03 ` [PATCH 0/6] Remove accessor macros from linespec.c Keith Seitz
  6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2024-06-06 14:45 UTC (permalink / raw)
  To: gdb-patches

This removes the LS_TOKEN_KEYWORD macro from linespec.c.
---
 gdb/linespec.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index b85d57c13c2..3db00300a58 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -276,7 +276,6 @@ struct linespec_token
 };
 
 #define LS_TOKEN_STOKEN(TOK) (TOK).data.string
-#define LS_TOKEN_KEYWORD(TOK) (TOK).data.keyword
 
 /* An instance of the linespec parser.  */
 
@@ -572,7 +571,7 @@ copy_token_string (linespec_token token)
   const char *str, *s;
 
   if (token.type == LSTOKEN_KEYWORD)
-    return make_unique_xstrdup (LS_TOKEN_KEYWORD (token));
+    return make_unique_xstrdup (token.data.keyword);
 
   str = LS_TOKEN_STOKEN (token).ptr;
   s = remove_trailing_whitespace (str, str + LS_TOKEN_STOKEN (token).length);
@@ -905,7 +904,7 @@ linespec_lexer_lex_one (linespec_parser *parser)
       if (keyword != NULL)
 	{
 	  parser->lexer.current.type = LSTOKEN_KEYWORD;
-	  LS_TOKEN_KEYWORD (parser->lexer.current) = keyword;
+	  parser->lexer.current.data.keyword = keyword;
 	  /* We do not advance the stream here intentionally:
 	     we would like lexing to stop when a keyword is seen.
 

-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 6/6] Remove LS_TOKEN_STOKEN macro
  2024-06-06 14:45 [PATCH 0/6] Remove accessor macros from linespec.c Tom Tromey
                   ` (4 preceding siblings ...)
  2024-06-06 14:45 ` [PATCH 5/6] Remove LS_TOKEN_KEYWORD macro Tom Tromey
@ 2024-06-06 14:45 ` Tom Tromey
  2024-06-12 16:03 ` [PATCH 0/6] Remove accessor macros from linespec.c Keith Seitz
  6 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2024-06-06 14:45 UTC (permalink / raw)
  To: gdb-patches

This removes the LS_TOKEN_STOKEN macro from linespec.c.
---
 gdb/linespec.c | 68 ++++++++++++++++++++++++++++------------------------------
 1 file changed, 33 insertions(+), 35 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 3db00300a58..7a1fbc2ebec 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -275,8 +275,6 @@ struct linespec_token
   } data;
 };
 
-#define LS_TOKEN_STOKEN(TOK) (TOK).data.string
-
 /* An instance of the linespec parser.  */
 
 struct linespec_parser
@@ -426,19 +424,19 @@ static int
 linespec_lexer_lex_number (linespec_parser *parser, linespec_token *tokenp)
 {
   tokenp->type = LSTOKEN_NUMBER;
-  LS_TOKEN_STOKEN (*tokenp).length = 0;
-  LS_TOKEN_STOKEN (*tokenp).ptr = parser->lexer.stream;
+  tokenp->data.string.length = 0;
+  tokenp->data.string.ptr = parser->lexer.stream;
 
   /* Keep any sign at the start of the stream.  */
   if (*parser->lexer.stream == '+' || *parser->lexer.stream == '-')
     {
-      ++LS_TOKEN_STOKEN (*tokenp).length;
+      ++tokenp->data.string.length;
       ++(parser->lexer.stream);
     }
 
   while (isdigit (*parser->lexer.stream))
     {
-      ++LS_TOKEN_STOKEN (*tokenp).length;
+      ++tokenp->data.string.length;
       ++(parser->lexer.stream);
     }
 
@@ -449,7 +447,7 @@ linespec_lexer_lex_number (linespec_parser *parser, linespec_token *tokenp)
       && *parser->lexer.stream != ':'
       && !strchr (linespec_quote_characters, *parser->lexer.stream))
     {
-      parser->lexer.stream = LS_TOKEN_STOKEN (*tokenp).ptr;
+      parser->lexer.stream = tokenp->data.string.ptr;
       return 0;
     }
 
@@ -573,8 +571,8 @@ copy_token_string (linespec_token token)
   if (token.type == LSTOKEN_KEYWORD)
     return make_unique_xstrdup (token.data.keyword);
 
-  str = LS_TOKEN_STOKEN (token).ptr;
-  s = remove_trailing_whitespace (str, str + LS_TOKEN_STOKEN (token).length);
+  str = token.data.string.ptr;
+  s = remove_trailing_whitespace (str, str + token.data.string.length);
 
   return gdb::unique_xmalloc_ptr<char> (savestring (str, s - str));
 }
@@ -681,8 +679,8 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	    {
 	      /* The input is an Ada operator.  Return the quoted string
 		 as-is.  */
-	      LS_TOKEN_STOKEN (token).ptr = parser->lexer.stream;
-	      LS_TOKEN_STOKEN (token).length = len;
+	      token.data.string.ptr = parser->lexer.stream;
+	      token.data.string.length = len;
 	      parser->lexer.stream += len;
 	      return token;
 	    }
@@ -695,7 +693,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
       ++(parser->lexer.stream);
 
       /* Mark the start of the string.  */
-      LS_TOKEN_STOKEN (token).ptr = parser->lexer.stream;
+      token.data.string.ptr = parser->lexer.stream;
 
       /* Skip to the ending quote.  */
       end = skip_quote_char (parser->lexer.stream, quote_char);
@@ -717,13 +715,13 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	  token.type = LSTOKEN_STRING;
 	  while (*parser->lexer.stream != '\0')
 	    parser->lexer.stream++;
-	  LS_TOKEN_STOKEN (token).length = parser->lexer.stream - 1 - start;
+	  token.data.string.length = parser->lexer.stream - 1 - start;
 	}
       else
 	{
 	  /* Skip over the ending quote and mark the length of the string.  */
 	  parser->lexer.stream = (char *) ++end;
-	  LS_TOKEN_STOKEN (token).length = parser->lexer.stream - 2 - start;
+	  token.data.string.length = parser->lexer.stream - 2 - start;
 	}
     }
   else
@@ -749,8 +747,8 @@ linespec_lexer_lex_string (linespec_parser *parser)
 		 say, a function name.  */
 	      if (linespec_lexer_lex_keyword (p) != NULL)
 		{
-		  LS_TOKEN_STOKEN (token).ptr = start;
-		  LS_TOKEN_STOKEN (token).length
+		  token.data.string.ptr = start;
+		  token.data.string.length
 		    = parser->lexer.stream - start;
 		  return token;
 		}
@@ -763,8 +761,8 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	     string is complete;  return the token.  */
 	  if (*parser->lexer.stream == 0)
 	    {
-	      LS_TOKEN_STOKEN (token).ptr = start;
-	      LS_TOKEN_STOKEN (token).length = parser->lexer.stream - start;
+	      token.data.string.ptr = start;
+	      token.data.string.length = parser->lexer.stream - start;
 	      return token;
 	    }
 	  else if (parser->lexer.stream[0] == ':')
@@ -787,8 +785,8 @@ linespec_lexer_lex_string (linespec_parser *parser)
 	      else if ((parser->lexer.stream - start) != 1
 		       || !IS_DIR_SEPARATOR (parser->lexer.stream[1]))
 		{
-		  LS_TOKEN_STOKEN (token).ptr = start;
-		  LS_TOKEN_STOKEN (token).length
+		  token.data.string.ptr = start;
+		  token.data.string.length
 		    = parser->lexer.stream - start;
 		  return token;
 		}
@@ -799,8 +797,8 @@ linespec_lexer_lex_string (linespec_parser *parser)
 			      *parser->lexer.stream)
 		   && is_closing_quote_enclosed (parser->lexer.stream))
 	    {
-	      LS_TOKEN_STOKEN (token).ptr = start;
-	      LS_TOKEN_STOKEN (token).length = parser->lexer.stream - start;
+	      token.data.string.ptr = start;
+	      token.data.string.length = parser->lexer.stream - start;
 	      return token;
 	    }
 	  /* Because commas may terminate a linespec and appear in
@@ -846,8 +844,8 @@ linespec_lexer_lex_string (linespec_parser *parser)
 		 function(thread<tab>" in completion mode.  */
 	      if (*end == '\0')
 		{
-		  LS_TOKEN_STOKEN (token).ptr = start;
-		  LS_TOKEN_STOKEN (token).length
+		  token.data.string.ptr = start;
+		  token.data.string.length
 		    = parser->lexer.stream - start;
 		  return token;
 		}
@@ -873,8 +871,8 @@ linespec_lexer_lex_string (linespec_parser *parser)
 		}
 
 	      /* Comma terminates the string.  */
-	      LS_TOKEN_STOKEN (token).ptr = start;
-	      LS_TOKEN_STOKEN (token).length = parser->lexer.stream - start;
+	      token.data.string.ptr = start;
+	      token.data.string.length = parser->lexer.stream - start;
 	      return token;
 	    }
 
@@ -953,9 +951,9 @@ linespec_lexer_lex_one (linespec_parser *parser)
 
 	case ',':
 	  parser->lexer.current.type = LSTOKEN_COMMA;
-	  LS_TOKEN_STOKEN (parser->lexer.current).ptr
+	  parser->lexer.current.data.string.ptr
 	    = parser->lexer.stream;
-	  LS_TOKEN_STOKEN (parser->lexer.current).length = 1;
+	  parser->lexer.current.data.string.length = 1;
 	  ++(parser->lexer.stream);
 	  break;
 
@@ -1004,7 +1002,7 @@ linespec_lexer_consume_token (linespec_parser *parser)
     {
       /* Advance the completion word past a potential initial
 	 quote-char.  */
-      parser->completion_word = LS_TOKEN_STOKEN (parser->lexer.current).ptr;
+      parser->completion_word = parser->lexer.current.data.string.ptr;
     }
   else if (advance_word)
     {
@@ -1787,7 +1785,7 @@ linespec_parse_basic (linespec_parser *parser)
 	  if (tmp_tracker.have_completions ())
 	    {
 	      parser->lexer.stream++;
-	      LS_TOKEN_STOKEN (token).length++;
+	      token.data.string.length++;
 
 	      name.reset (savestring (parser->completion_word,
 				      (parser->lexer.stream
@@ -1829,7 +1827,7 @@ linespec_parse_basic (linespec_parser *parser)
 	      parser->result.explicit_loc.label_name = std::move (name);
 	    }
 	  else if (token.type == LSTOKEN_STRING
-		   && *LS_TOKEN_STOKEN (token).ptr == '$')
+		   && *token.data.string.ptr == '$')
 	    {
 	      /* User specified a convenience variable or history value.  */
 	      parser->result.explicit_loc.line_offset
@@ -1899,12 +1897,12 @@ linespec_parse_basic (linespec_parser *parser)
 	     garbage.  */
 	  if (parser->completion_quote_char == '\0')
 	    {
-	      const char *ptr = LS_TOKEN_STOKEN (token).ptr;
-	      for (size_t i = 0; i < LS_TOKEN_STOKEN (token).length; i++)
+	      const char *ptr = token.data.string.ptr;
+	      for (size_t i = 0; i < token.data.string.length; i++)
 		{
 		  if (ptr[i] == ' ')
 		    {
-		      LS_TOKEN_STOKEN (token).length = i;
+		      token.data.string.length = i;
 		      parser->lexer.stream = skip_spaces (ptr + i + 1);
 		      break;
 		    }
@@ -2499,7 +2497,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
   linespec_token token = linespec_lexer_consume_token (parser);
 
   /* It must be either LSTOKEN_STRING or LSTOKEN_NUMBER.  */
-  if (token.type == LSTOKEN_STRING && *LS_TOKEN_STOKEN (token).ptr == '$')
+  if (token.type == LSTOKEN_STRING && *token.data.string.ptr == '$')
     {
       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
       if (parser->completion_tracker == NULL)

-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/6] Remove accessor macros from linespec.c
  2024-06-06 14:45 [PATCH 0/6] Remove accessor macros from linespec.c Tom Tromey
                   ` (5 preceding siblings ...)
  2024-06-06 14:45 ` [PATCH 6/6] Remove LS_TOKEN_STOKEN macro Tom Tromey
@ 2024-06-12 16:03 ` Keith Seitz
  6 siblings, 0 replies; 8+ messages in thread
From: Keith Seitz @ 2024-06-12 16:03 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 6/6/24 7:45 AM, Tom Tromey wrote:
> This series removes the accessor macros from linespec.c.  This kind of
> macro was a staple of old-style gdb, but I don't think they provide
> any real value over direct access to fields.

Agreed. Thank you for the linespec TLC!

Reviewed-by: Keith Seitz <keiths@redhat.com>

Keith


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-06-12 16:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-06 14:45 [PATCH 0/6] Remove accessor macros from linespec.c Tom Tromey
2024-06-06 14:45 ` [PATCH 1/6] Remove PARSER_STATE macro Tom Tromey
2024-06-06 14:45 ` [PATCH 2/6] Remove PARSER_RESULT macro Tom Tromey
2024-06-06 14:45 ` [PATCH 3/6] Remove PARSER_EXPLICIT macro Tom Tromey
2024-06-06 14:45 ` [PATCH 4/6] Remove PARSER_STREAM macro Tom Tromey
2024-06-06 14:45 ` [PATCH 5/6] Remove LS_TOKEN_KEYWORD macro Tom Tromey
2024-06-06 14:45 ` [PATCH 6/6] Remove LS_TOKEN_STOKEN macro Tom Tromey
2024-06-12 16:03 ` [PATCH 0/6] Remove accessor macros from linespec.c Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).