groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 06/08: [troff]: Refactor some internal functions.


From: G. Branden Robinson
Subject: [groff] 06/08: [troff]: Refactor some internal functions.
Date: Thu, 29 Jul 2021 05:29:30 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 2e11babd9c0639003b43236fca71b3133a531525
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Jul 29 10:21:39 2021 +1000

    [troff]: Refactor some internal functions.
    
    * src/roff/troff/node.cpp: Rename two functions that have only one
      caller.
      - get_reg_int -> get_register
      - get_reg_str -> get_string
    
      We now have:
    
      (get_register, get_string): Use `assert()` aggressively because these
      are deeply internal and validation is imperative.  Get rid of
      diagnostic messages (one of which perpetuated the dubious "number
      register" nomenclature) accordingly.
    
      (fetch_register): Also rename `prev_value`, misleadingly specific and
      semmingly copy-and-pasted out of a context where an auto-increment or
      -decrement might have been applied.  It's just the `value`.
    
      (suppress_node::tprint): Update call site.
---
 ChangeLog               | 19 +++++++++++++++++++
 src/roff/troff/node.cpp | 33 ++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 34abd4d..113cbb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2021-07-29  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       [troff]: Refactor some internal functions.
+
+       * src/roff/troff/node.cpp: Rename two functions that have only
+       one caller.
+         - get_reg_int -> get_register
+         - get_reg_str -> get_string
+       We now have:
+       (get_register, get_string): Use `assert()` aggressively because
+       these are deeply internal and validation is imperative.  Get rid
+       of diagnostic messages (one of which perpetuated the dubious
+       "number register" nomenclature) accordingly.
+       (fetch_register): Also rename `prev_value`, misleadingly
+       specific and semmingly copy-and-pasted out of a context where an
+       auto-increment or -decrement might have been applied.  It's just
+       the `value`.
+       (suppress_node::tprint): Update call site.
+
+2021-07-29  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        [troff]: Refactor `get_value` member functions.  Given their
        names and popular "getter/setter" paradigms from many OO
        languages, the return type is misleading.  Change it from `int`
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 83d4e9e..daf342d 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -4018,25 +4018,24 @@ int tag_node::ends_sentence()
   return 2;
 }
 
-int get_reg_int(const char *p)
+// Get contents of register `p`--used only by suppress_node::tprint().
+static int get_register(const char *p)
 {
+  assert(0 != p);
   reg *r = (reg *)number_reg_dictionary.lookup(p);
-  units prev_value;
-  if (r && (r->get_value(&prev_value)))
-    return (int)prev_value;
-  else
-    warning(WARN_REG, "number register '%1' not defined", p);
-  return 0;
+  assert(0 != r);
+  units value;
+  assert(r->get_value(&value));
+  return (int)value;
 }
 
-const char *get_reg_str(const char *p)
+// Get contents of string `p`--used only by suppress_node::tprint().
+static const char *get_string(const char *p)
 {
+  assert(0 != p);
   reg *r = (reg *)number_reg_dictionary.lookup(p);
-  if (r)
-    return r->get_string();
-  else
-    warning(WARN_REG, "register '%1' not defined", p);
-  return 0;
+  assert(0 != r);
+  return r->get_string();
 }
 
 void suppress_node::put(troff_output_file *out, const char *s)
@@ -4181,11 +4180,11 @@ void suppress_node::tprint(troff_output_file *out)
        fprintf(stderr,
                "grohtml-info:page %d  %d  %d  %d  %d  %d  %s  %d  %d  %s\n",
                topdiv->get_page_number(),
-               get_reg_int("opminx"), get_reg_int("opminy"),
-               get_reg_int("opmaxx"), get_reg_int("opmaxy"),
+               get_register("opminx"), get_register("opminy"),
+               get_register("opmaxx"), get_register("opmaxy"),
                // page offset + line length
-               get_reg_int(".o") + get_reg_int(".l"),
-               name, hresolution, vresolution, get_reg_str(".F"));
+               get_register(".o") + get_register(".l"),
+               name, hresolution, vresolution, get_string(".F"));
        fflush(stderr);
       }
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]