[6/6] Use bool in linespec

Message ID 20250108-linespec-state-cxx-v1-6-a721e95ee050@tromey.com
State New
Headers
Series More linespec cleanups and C++-ification |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Tom Tromey Jan. 8, 2025, 7:23 a.m. UTC
  This changes various spots in linespec to use a bool rather than an
int.
---
 gdb/linespec.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)
  

Comments

Simon Marchi Jan. 9, 2025, 3:34 a.m. UTC | #1
On 2025-01-08 02:23, Tom Tromey wrote:
> This changes various spots in linespec to use a bool rather than an
> int.
> ---
>  gdb/linespec.c | 42 +++++++++++++++++++++---------------------
>  1 file changed, 21 insertions(+), 21 deletions(-)
> 
> diff --git a/gdb/linespec.c b/gdb/linespec.c
> index 9b1e1856eff349d567d4f918b85a79e8323e247f..6ee12ea56a8d5cb780614cac92a06d75fbcfb8f0 100644
> --- a/gdb/linespec.c
> +++ b/gdb/linespec.c
> @@ -170,8 +170,8 @@ struct linespec_state
>        search_pspace (search_pspace),
>        default_symtab (default_symtab),
>        default_line (default_line),
> -      funfirstline ((flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0),
> -      list_mode ((flags & DECODE_LINE_LIST_MODE) ? 1 : 0),
> +      funfirstline ((flags & DECODE_LINE_FUNFIRSTLINE) ? true : false),
> +      list_mode ((flags & DECODE_LINE_LIST_MODE) ? true : false),

I think you could get rid of the ternaries.

>        canonical (canonical)
>    {
>    }
> @@ -207,10 +207,10 @@ struct linespec_state
>  
>    /* The 'funfirstline' value that was passed in to decode_line_1 or
>       decode_line_full.  */
> -  int funfirstline;
> +  bool funfirstline;
>  
>    /* Nonzero if we are running in 'list' mode; see decode_line_list.  */

Nonzero -> true

Otherwise, LGTM.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  

Patch

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 9b1e1856eff349d567d4f918b85a79e8323e247f..6ee12ea56a8d5cb780614cac92a06d75fbcfb8f0 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -170,8 +170,8 @@  struct linespec_state
       search_pspace (search_pspace),
       default_symtab (default_symtab),
       default_line (default_line),
-      funfirstline ((flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0),
-      list_mode ((flags & DECODE_LINE_LIST_MODE) ? 1 : 0),
+      funfirstline ((flags & DECODE_LINE_FUNFIRSTLINE) ? true : false),
+      list_mode ((flags & DECODE_LINE_LIST_MODE) ? true : false),
       canonical (canonical)
   {
   }
@@ -207,10 +207,10 @@  struct linespec_state
 
   /* The 'funfirstline' value that was passed in to decode_line_1 or
      decode_line_full.  */
-  int funfirstline;
+  bool funfirstline;
 
   /* Nonzero if we are running in 'list' mode; see decode_line_list.  */
-  int list_mode;
+  bool list_mode;
 
   /* The 'canonical' value passed to decode_line_full, or NULL.  */
   struct linespec_result *canonical;
@@ -219,7 +219,7 @@  struct linespec_state
   std::vector<linespec_canonical_name> canonical_names;
 
   /* Are we building a linespec?  */
-  int is_linespec = 0;
+  bool is_linespec = false;
 
 private:
 
@@ -354,7 +354,7 @@  struct linespec_parser
   } lexer {};
 
   /* Is the entire linespec quote-enclosed?  */
-  int is_quote_enclosed = 0;
+  bool is_quote_enclosed = false;
 
   /* The state of the parse.  */
   struct linespec_state state;
@@ -422,8 +422,8 @@  static struct line_offset
      linespec_parse_variable (struct linespec_state *self,
 			      const char *variable);
 
-static int symbol_to_sal (struct symtab_and_line *result,
-			  int funfirstline, struct symbol *sym);
+static bool symbol_to_sal (struct symtab_and_line *result,
+			   bool funfirstline, struct symbol *sym);
 
 static void add_matching_symbols_to_info (const char *name,
 					  symbol_name_match_type name_match_type,
@@ -2013,7 +2013,7 @@  static std::vector<symtab_and_line>
 create_sals_line_offset (struct linespec_state *self,
 			 linespec *ls)
 {
-  int use_default = 0;
+  bool use_default = false;
 
   /* This is where we need to make sure we have good defaults.
      We must guarantee that this section of code is never executed
@@ -2032,7 +2032,7 @@  create_sals_line_offset (struct linespec_state *self,
       ls->file_symtabs
 	= collect_symtabs_from_filename (self->default_symtab->filename,
 					 self->search_pspace);
-      use_default = 1;
+      use_default = true;
     }
 
   symtab_and_line val;
@@ -2488,7 +2488,7 @@  parse_linespec (linespec_parser *parser, const char *arg,
   /* A special case to start.  It has become quite popular for
      IDEs to work around bugs in the previous parser by quoting
      the entire linespec, so we attempt to deal with this nicely.  */
-  parser->is_quote_enclosed = 0;
+  parser->is_quote_enclosed = false;
   if (parser->completion_tracker == NULL
       && !is_ada_operator (arg)
       && *arg != '\0'
@@ -2500,7 +2500,7 @@  parse_linespec (linespec_parser *parser, const char *arg,
 	  /* Here's the special case.  Skip ARG past the initial
 	     quote.  */
 	  ++arg;
-	  parser->is_quote_enclosed = 1;
+	  parser->is_quote_enclosed = true;
 	}
     }
 
@@ -2870,7 +2870,7 @@  linespec_complete (completion_tracker &tracker, const char *text,
   parser.lexer.stream = text;
 
   parser.completion_tracker = &tracker;
-  parser.state.is_linespec = 1;
+  parser.state.is_linespec = true;
 
   /* Parse as much as possible.  parser.completion_word will hold
      furthest completion point we managed to parse to.  */
@@ -3061,7 +3061,7 @@  location_spec_to_sals (linespec_parser *parser,
     case LINESPEC_LOCATION_SPEC:
       {
 	const linespec_location_spec *ls = as_linespec_location_spec (locspec);
-	parser->state.is_linespec = 1;
+	parser->state.is_linespec = true;
 	result = parse_linespec (parser, ls->spec_string.get (),
 				 ls->match_type);
       }
@@ -4131,7 +4131,7 @@  minsym_found (struct linespec_state *self, struct objfile *objfile,
 
 static void
 add_minsym (struct minimal_symbol *minsym, struct objfile *objfile,
-	    struct symtab *symtab, int list_mode,
+	    struct symtab *symtab, bool list_mode,
 	    std::vector<bound_minimal_symbol> *msyms)
 {
   if (symtab != NULL)
@@ -4319,14 +4319,14 @@  add_matching_symbols_to_info (const char *name,
 /* Now come some functions that are called from multiple places within
    decode_line_1.  */
 
-static int
+static bool
 symbol_to_sal (struct symtab_and_line *result,
-	       int funfirstline, struct symbol *sym)
+	       bool funfirstline, struct symbol *sym)
 {
   if (sym->aclass () == LOC_BLOCK)
     {
       *result = find_function_start_sal (sym, funfirstline);
-      return 1;
+      return true;
     }
   else
     {
@@ -4339,7 +4339,7 @@  symbol_to_sal (struct symtab_and_line *result,
 	  result->pc = sym->value_address ();
 	  result->pspace = result->symtab->compunit ()->objfile ()->pspace ();
 	  result->explicit_pc = 1;
-	  return 1;
+	  return true;
 	}
       else if (funfirstline)
 	{
@@ -4354,11 +4354,11 @@  symbol_to_sal (struct symtab_and_line *result,
 	  result->line = sym->line ();
 	  result->pc = sym->value_address ();
 	  result->pspace = result->symtab->compunit ()->objfile ()->pspace ();
-	  return 1;
+	  return true;
 	}
     }
 
-  return 0;
+  return false;
 }
 
 linespec_result::~linespec_result ()