gbranden pushed a commit to branch master
in repository groff.

commit 08500c4a803c2d27caee915b50138a0ef866a4b0
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Apr 23 16:08:52 2025 -0500

    [troff]: Fix code style nit (`static_cast`).
    
    Favor C++-style `static_cast` over C-style omnipotent casts.
    
    * src/roff/troff/column.cpp (vjustify_node::same) [0]:
    * src/roff/troff/dictionary.cpp (object_dictionary::lookup)
      (object_dictionary::rename)
      (object_dictionary::remove)
      (object_dictionary::alias):
    * src/roff/troff/env.cpp (hyphen_trie::do_match)
      (hyphen_trie::do_match):
    * src/roff/troff/input.cpp
      (non_interpreted_char_node::is_same_as)
      (lookup_color)
      (token_node::is_same_as)
      (interpolate_macro) (do_define_string)
      (non_interpreted_node::is_same_as)
      (get_charinfo_by_index):
    * src/roff/troff/node.cpp (dbreak_node::merge_glyph_node)
      (suppress_node::is_same_as)
      (tag_node::is_same_as)
      (get_register)
      (get_string)
      (draw_node::is_same_as)
      (extra_size_node::is_same_as)
      (vertical_size_node::is_same_as)
      (hmotion_node::is_same_as)
      (space_char_hmotion_node::is_same_as)
      (vmotion_node::is_same_as)
      (hline_node::is_same_as)
      (vline_node::is_same_as)
      (italic_corrected_node::is_same_as)
      (left_italic_corrected_node::is_same_as)
      (composite_node::is_same_as)
      (glyph_node::is_same_as)
      (kern_pair_node::is_same_as)
      (break_char_node::is_same_as)
      (space_node::is_same_as)
      (word_space_node::is_same_as): Do it.
---
 ChangeLog                     | 27 +++++++++++++
 src/roff/troff/column.cpp     |  2 +-
 src/roff/troff/dictionary.cpp | 10 ++---
 src/roff/troff/env.cpp        |  4 +-
 src/roff/troff/input.cpp      | 19 +++++----
 src/roff/troff/node.cpp       | 93 ++++++++++++++++++++++---------------------
 6 files changed, 94 insertions(+), 61 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a35e60c78..274ef8621 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2025-04-24  G. Branden Robinson <[email protected]>
+
+       [troff]: Favor C++-style `static_cast` over C-style omnipotent
+       casts.
+
+       * src/roff/troff/column.cpp (vjustify_node::same) [0]:
+       * src/roff/troff/dictionary.cpp (object_dictionary::lookup)
+       (object_dictionary::rename, object_dictionary::remove)
+       (object_dictionary::alias):
+       * src/roff/troff/env.cpp (hyphen_trie::do_match)
+       (hyphen_trie::do_match):
+       * src/roff/troff/input.cpp
+       (non_interpreted_char_node::is_same_as, lookup_color)
+       (token_node::is_same_as, interpolate_macro, do_define_string)
+       (non_interpreted_node::is_same_as, get_charinfo_by_index):
+       * src/roff/troff/node.cpp (dbreak_node::merge_glyph_node)
+       (suppress_node::is_same_as, tag_node::is_same_as, get_register)
+       (get_string, draw_node::is_same_as, extra_size_node::is_same_as)
+       (vertical_size_node::is_same_as, hmotion_node::is_same_as)
+       (space_char_hmotion_node::is_same_as, vmotion_node::is_same_as)
+       (hline_node::is_same_as, vline_node::is_same_as)
+       (italic_corrected_node::is_same_as)
+       (left_italic_corrected_node::is_same_as)
+       (composite_node::is_same_as, glyph_node::is_same_as)
+       (kern_pair_node::is_same_as, break_char_node::is_same_as)
+       (space_node::is_same_as, word_space_node::is_same_as): Do it.
+
 2025-04-23  G. Branden Robinson <[email protected]>
 
        * src/include/stringclass.h (operator+): Fix code style nit:
diff --git a/src/roff/troff/column.cpp b/src/roff/troff/column.cpp
index 1ae2e1c71..af6e26396 100644
--- a/src/roff/troff/column.cpp
+++ b/src/roff/troff/column.cpp
@@ -674,7 +674,7 @@ const char *vjustify_node::type()
 
 int vjustify_node::same(node *nd)
 {
-  return typ == ((vjustify_node *)nd)->typ;
+  return typ == static_cast<vjustify_node *>(nd)->typ;
 }
 
 bool vjustify_node::need_reread(bool *bolp)
diff --git a/src/roff/troff/dictionary.cpp b/src/roff/troff/dictionary.cpp
index 0eade7be1..ea1da1760 100644
--- a/src/roff/troff/dictionary.cpp
+++ b/src/roff/troff/dictionary.cpp
@@ -173,14 +173,14 @@ object *object_dictionary::lookup(symbol nm)
 void object_dictionary::define(symbol nm, object *obj)
 {
   obj->add_reference();
-  obj = (object *)d.lookup(nm, obj);
+  obj = static_cast<object *>(d.lookup(nm, obj));
   if (obj)
     obj->remove_reference();
 }
 
 void object_dictionary::rename(symbol oldnm, symbol newnm)
 {
-  object *obj = (object *)d.remove(oldnm);
+  object *obj = static_cast<object *>(d.remove(oldnm));
   if (obj) {
     obj = (object *)d.lookup(newnm, obj);
     if (obj)
@@ -190,7 +190,7 @@ void object_dictionary::rename(symbol oldnm, symbol newnm)
 
 void object_dictionary::remove(symbol nm)
 {
-  object *obj = (object *)d.remove(nm);
+  object *obj = static_cast<object *>(d.remove(nm));
   if (obj)
     obj->remove_reference();
 }
@@ -199,10 +199,10 @@ void object_dictionary::remove(symbol nm)
 
 bool object_dictionary::alias(symbol newnm, symbol oldnm)
 {
-  object *obj = (object *)d.lookup(oldnm);
+  object *obj = static_cast<object *>(d.lookup(oldnm));
   if (obj) {
     obj->add_reference();
-    obj = (object *)d.lookup(newnm, obj);
+    obj = static_cast<object *>(d.lookup(newnm, obj));
     if (obj)
       obj->remove_reference();
     return true;
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 7a2601692..3604515e6 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -3987,7 +3987,7 @@ inline int max(int m, int n)
 
 void hyphen_trie::do_match(int i, void *v)
 {
-  operation *op = (operation *)v;
+  operation *op = static_cast<operation *>(v);
   while (op != 0) {
     h[i - op->distance] = max(h[i - op->distance], op->num);
     op = op->next;
@@ -3996,7 +3996,7 @@ void hyphen_trie::do_match(int i, void *v)
 
 void hyphen_trie::do_delete(void *v)
 {
-  operation *op = (operation *)v;
+  operation *op = static_cast<operation *>(v);
   while (op) {
     operation *tem = op;
     op = tem->next;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 7c53a0edc..f60c78fe4 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -1297,7 +1297,7 @@ public:
 
 bool non_interpreted_char_node::is_same_as(node *nd)
 {
-  return c == ((non_interpreted_char_node *)nd)->c;
+  return c == static_cast<non_interpreted_char_node *>(nd)->c;
 }
 
 const char *non_interpreted_char_node::type()
@@ -1345,7 +1345,7 @@ static color *lookup_color(symbol nm)
   assert(!nm.is_null());
   if (nm == default_symbol)
     return &default_color;
-  color *c = (color *)color_dictionary.lookup(nm);
+  color *c = static_cast<color *>(color_dictionary.lookup(nm));
   if (0 == c /* nullptr */)
     warning(WARN_COLOR, "color '%1' not defined", nm.contents());
   return c;
@@ -1894,7 +1894,7 @@ token_node *token_node::get_token_node()
 
 bool token_node::is_same_as(node *nd)
 {
-  return tk == ((token_node *)nd)->tk;
+  return (tk == static_cast<token_node *>(nd)->tk);
 }
 
 const char *token_node::type()
@@ -4159,7 +4159,7 @@ bool operator==(const macro &m1, const macro &m2)
 static void interpolate_macro(symbol nm, bool do_not_want_next_token)
 {
   request_or_macro *p
-    = (request_or_macro *)request_dictionary.lookup(nm);
+    = static_cast<request_or_macro *>(request_dictionary.lookup(nm));
   if (0 /* nullptr */ == p) {
     bool was_warned = false;
     const char *s = nm.contents();
@@ -4169,7 +4169,8 @@ static void interpolate_macro(symbol nm, bool 
do_not_want_next_token)
       buf[0] = s[0];
       buf[1] = s[1];
       buf[2] = '\0';
-      r = (request_or_macro *)request_dictionary.lookup(symbol(buf));
+      r = static_cast<request_or_macro *>
+         (request_dictionary.lookup(symbol(buf)));
       if (r) {
        macro *m = r->to_macro();
        if ((0 /* nullptr */ == m) || !m->is_empty()) {
@@ -4593,7 +4594,8 @@ void do_define_string(define_mode mode, comp_mode comp)
   if (c == '"')
     c = get_copy(&n);
   macro mac;
-  request_or_macro *rm = (request_or_macro *)request_dictionary.lookup(nm);
+  request_or_macro *rm
+    = static_cast<request_or_macro *>(request_dictionary.lookup(nm));
   macro *mm = rm ? rm->to_macro() : 0 /* nullptr */;
   if (mode == DEFINE_APPEND && mm)
     mac = *mm;
@@ -6008,7 +6010,7 @@ int non_interpreted_node::ends_sentence()
 
 bool non_interpreted_node::is_same_as(node *nd)
 {
-  return mac == ((non_interpreted_node *)nd)->mac;
+  return (mac == static_cast<non_interpreted_node *>(nd)->mac);
 }
 
 const char *non_interpreted_node::type()
@@ -10364,7 +10366,8 @@ static charinfo *get_charinfo_by_index(int n, bool 
suppress_creation)
   }
   else {
     symbol ns(i_to_a(n));
-    charinfo *ci = (charinfo *)indexed_charinfo_dictionary.lookup(ns);
+    charinfo *ci =
+      static_cast<charinfo *>(indexed_charinfo_dictionary.lookup(ns));
     if ((0 /*nullptr */ == ci) && !suppress_creation) {
       ci = new charinfo(UNNAMED_SYMBOL);
       ci->set_number(n);
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 9db1912b7..161844f6d 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -2374,7 +2374,7 @@ dbreak_node::dbreak_node(node *n, node *p, statem *s, int 
divlevel,
 
 node *dbreak_node::merge_glyph_node(glyph_node *gn)
 {
-  glyph_node *gn2 = (glyph_node *)gn->copy();
+  glyph_node *gn2 = static_cast<glyph_node *>(gn->copy());
   node *new_none = none ? none->merge_glyph_node(gn) : 0 /* nullptr */;
   node *new_post = post ? post->merge_glyph_node(gn2) : 0 /* nullptr */;
   if ((0 /* nullptr */ == new_none) && (0 /* nullptr */ == new_post)) {
@@ -4314,11 +4314,11 @@ void suppress_node::dump_properties()
 
 bool suppress_node::is_same_as(node *n)
 {
-  return ((is_on == ((suppress_node *)n)->is_on)
-         && (emit_limits == ((suppress_node *)n)->emit_limits)
-         && (filename == ((suppress_node *)n)->filename)
-         && (position == ((suppress_node *)n)->position)
-         && (image_id == ((suppress_node *)n)->image_id));
+  return ((is_on == static_cast<suppress_node *>(n)->is_on)
+         && (emit_limits == static_cast<suppress_node *>(n)->emit_limits)
+         && (filename == static_cast<suppress_node *>(n)->filename)
+         && (position == static_cast<suppress_node *>(n)->position)
+         && (image_id == static_cast<suppress_node *>(n)->image_id));
 }
 
 const char *suppress_node::type()
@@ -4375,8 +4375,8 @@ void tag_node::tprint(troff_output_file *out)
 
 bool tag_node::is_same_as(node *nd)
 {
-  return tag_string == ((tag_node *)nd)->tag_string
-        && delayed == ((tag_node *)nd)->delayed;
+  return ((tag_string == static_cast<tag_node *>(nd)->tag_string)
+         && (delayed == static_cast<tag_node *>(nd)->delayed));
 }
 
 const char *tag_node::type()
@@ -4404,7 +4404,7 @@ int tag_node::ends_sentence()
 static int get_register(const char *p)
 {
   assert(p != 0 /* nullptr */);
-  reg *r = (reg *)register_dictionary.lookup(p);
+  reg *r = static_cast<reg *>(register_dictionary.lookup(p));
   assert(r != 0 /* nullptr */);
   units value;
   assert(r->get_value(&value));
@@ -4416,7 +4416,7 @@ static int get_register(const char *p)
 static const char *get_string(const char *p)
 {
   assert(p != 0 /* nullptr */);
-  reg *r = (reg *)register_dictionary.lookup(p);
+  reg *r = static_cast<reg *>(register_dictionary.lookup(p));
   assert(r != 0 /* nullptr */);
   return r->get_string();
 }
@@ -4942,7 +4942,7 @@ void draw_node::dump_properties()
 
 bool draw_node::is_same_as(node *n)
 {
-  draw_node *nd = (draw_node *)n;
+  draw_node *nd = static_cast<draw_node *>(n);
   if (code != nd->code || npoints != nd->npoints || sz != nd->sz
       || gcol != nd->gcol || fcol != nd->fcol)
     return false;
@@ -5614,7 +5614,7 @@ int same_node_list(node *n1, node *n2)
 
 bool extra_size_node::is_same_as(node *nd)
 {
-  return n == ((extra_size_node *)nd)->n;
+  return (n == static_cast<extra_size_node *>(nd)->n);
 }
 
 const char *extra_size_node::type()
@@ -5634,7 +5634,7 @@ bool extra_size_node::is_tag()
 
 bool vertical_size_node::is_same_as(node *nd)
 {
-  return n == ((vertical_size_node *)nd)->n;
+  return (n == static_cast<vertical_size_node *>(nd)->n);
 }
 
 const char *vertical_size_node::type()
@@ -5659,8 +5659,8 @@ bool vertical_size_node::is_tag()
 
 bool hmotion_node::is_same_as(node *nd)
 {
-  return n == ((hmotion_node *)nd)->n
-        && col == ((hmotion_node *)nd)->col;
+  return ((n == static_cast<hmotion_node *>(nd)->n)
+         && (col == static_cast<hmotion_node *>(nd)->col));
 }
 
 const char *hmotion_node::type()
@@ -5700,8 +5700,8 @@ hyphen_list *hmotion_node::get_hyphen_list(hyphen_list 
*tail, int *)
 
 bool space_char_hmotion_node::is_same_as(node *nd)
 {
-  return n == ((space_char_hmotion_node *)nd)->n
-        && col == ((space_char_hmotion_node *)nd)->col;
+  return ((n == static_cast<space_char_hmotion_node *>(nd)->n
+         && col == static_cast<space_char_hmotion_node *>(nd)->col));
 }
 
 const char *space_char_hmotion_node::type()
@@ -5736,8 +5736,8 @@ hyphen_list 
*space_char_hmotion_node::get_hyphen_list(hyphen_list *tail,
 
 bool vmotion_node::is_same_as(node *nd)
 {
-  return n == ((vmotion_node *)nd)->n
-        && col == ((vmotion_node *)nd)->col;
+  return ((n == static_cast<vmotion_node *>(nd)->n)
+         && col == static_cast<vmotion_node *>(nd)->col);
 }
 
 const char *vmotion_node::type()
@@ -5757,8 +5757,8 @@ bool vmotion_node::is_tag()
 
 bool hline_node::is_same_as(node *nd)
 {
-  return x == ((hline_node *)nd)->x
-              && same_node(nodes, ((hline_node *)nd)->nodes);
+  return ((x == static_cast<hline_node *>(nd)->x)
+         && same_node(nodes, static_cast<hline_node *>(nd)->nodes));
 }
 
 const char *hline_node::type()
@@ -5778,8 +5778,8 @@ bool hline_node::is_tag()
 
 bool vline_node::is_same_as(node *nd)
 {
-  return x == ((vline_node *)nd)->x
-              && same_node(nodes, ((vline_node *)nd)->nodes);
+  return ((x == static_cast<vline_node *>(nd)->x)
+         && same_node(nodes, static_cast<vline_node *>(nd)->nodes));
 }
 
 const char *vline_node::type()
@@ -5864,8 +5864,9 @@ bool zero_width_node::is_tag()
 
 bool italic_corrected_node::is_same_as(node *nd)
 {
-  return (x == ((italic_corrected_node *)nd)->x
-         && same_node(nodes, ((italic_corrected_node *)nd)->nodes));
+  return ((x == static_cast<italic_corrected_node *>(nd)->x)
+         && same_node(nodes,
+              static_cast<italic_corrected_node *>(nd)->nodes));
 }
 
 const char *italic_corrected_node::type()
@@ -5959,9 +5960,9 @@ bool left_italic_corrected_node::is_tag()
 
 bool left_italic_corrected_node::is_same_as(node *nd)
 {
-  return (x == ((left_italic_corrected_node *)nd)->x
+  return ((x == static_cast<left_italic_corrected_node *>(nd)->x)
          && same_node(nodes,
-                       ((left_italic_corrected_node *)nd)->nodes));
+              static_cast<left_italic_corrected_node *>(nd)->nodes));
 }
 
 void left_italic_corrected_node::ascii_print(ascii_output_file *out)
@@ -6120,8 +6121,9 @@ bool bracket_node::is_tag()
 
 bool composite_node::is_same_as(node *nd)
 {
-  return ci == ((composite_node *)nd)->ci
-    && same_node_list(nodes, ((composite_node *)nd)->nodes);
+  return ((ci == static_cast<composite_node *>(nd)->ci)
+         && same_node(nodes,
+                      static_cast<composite_node *>(nd)->nodes));
 }
 
 const char *composite_node::type()
@@ -6141,10 +6143,10 @@ bool composite_node::is_tag()
 
 bool glyph_node::is_same_as(node *nd)
 {
-  return ci == ((glyph_node *)nd)->ci
-        && tf == ((glyph_node *)nd)->tf
-        && gcol == ((glyph_node *)nd)->gcol
-        && fcol == ((glyph_node *)nd)->fcol;
+  return ((ci == static_cast<glyph_node *>(nd)->ci)
+         && (tf == static_cast<glyph_node *>(nd)->tf)
+         && (gcol == static_cast<glyph_node *>(nd)->gcol)
+         && (fcol == static_cast<glyph_node *>(nd)->fcol));
 }
 
 const char *glyph_node::type()
@@ -6186,9 +6188,9 @@ bool ligature_node::is_tag()
 
 bool kern_pair_node::is_same_as(node *nd)
 {
-  return (amount == ((kern_pair_node *)nd)->amount
-         && same_node(n1, ((kern_pair_node *)nd)->n1)
-         && same_node(n2, ((kern_pair_node *)nd)->n2));
+  return ((amount == static_cast<kern_pair_node *>(nd)->amount)
+         && same_node(n1, static_cast<kern_pair_node *>(nd)->n1)
+         && same_node(n2, static_cast<kern_pair_node *>(nd)->n2));
 }
 
 const char *kern_pair_node::type()
@@ -6253,9 +6255,10 @@ void dbreak_node::dump_node()
 
 bool break_char_node::is_same_as(node *nd)
 {
-  return break_code == ((break_char_node *)nd)->break_code
-        && col == ((break_char_node *)nd)->col
-        && same_node(nodes, ((break_char_node *)nd)->nodes);
+  return (break_code == static_cast<break_char_node *>(nd)->break_code)
+        && (col == static_cast<break_char_node *>(nd)->col)
+        && (same_node(nodes,
+                      static_cast<break_char_node *>(nd)->nodes));
 }
 
 const char *break_char_node::type()
@@ -6300,9 +6303,9 @@ bool line_start_node::is_tag()
 
 bool space_node::is_same_as(node *nd)
 {
-  return n == ((space_node *)nd)->n
-             && set == ((space_node *)nd)->set
-             && col == ((space_node *)nd)->col;
+  return ((n == static_cast<space_node *>(nd)->n)
+         && (set == static_cast<space_node *>(nd)->set)
+         && (col == static_cast<space_node *>(nd)->col));
 }
 
 const char *space_node::type()
@@ -6312,9 +6315,9 @@ const char *space_node::type()
 
 bool word_space_node::is_same_as(node *nd)
 {
-  return n == ((word_space_node *)nd)->n
-        && set == ((word_space_node *)nd)->set
-        && col == ((word_space_node *)nd)->col;
+  return ((n == static_cast<word_space_node *>(nd)->n)
+         && (set == static_cast<word_space_node *>(nd)->set)
+         && (col == static_cast<word_space_node *>(nd)->col));
 }
 
 const char *word_space_node::type()

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to