gbranden pushed a commit to branch master
in repository groff.
commit 6dcbaa0a7a9bf86370b22d604a71c6b5f2215898
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Dec 19 14:57:45 2025 -0600
[troff]: Refactor.
...to use the C++ default argument force. Merge function
`get_number_rigidly()` into `read_measurement(), which differed by one
line out of a dozen, by extending the latter's signature with a default
argument `is_mandatory` of type `bool`. This coincidentally made GCC's
overload resolver more sensitive to arguments of ambiguous integral
type, so take this opportunity to stop punning between character
literals and `unsigned char`, in favor of the explicitness we'll need
anyway for GNU troff's planned wider fundamental character type.
* src/roff/troff/token.h: Drop declaration of `get_number_rigidly()`.
Update declaration of `read_measurement()` with `bool`-valued 3rd
argument defaulting `false`.
* src/roff/troff/input.cpp (read_color_channel_value)
(do_expr_test, read_size, do_register)
(is_conditional_expression_true, evaluate_expression):
* src/roff/troff/reg.cpp (define_register_request): Explicitly construct
literal of `unsigned char` type as argument to `read_measurement()`.
* src/roff/troff/input.cpp (do_expr_test): Migrate only call site of
`get_number_rigidly()` to `read_measurement()` with an explicit `true`
3rd argument.
* src/roff/troff/number.cpp (get_number_rigidly): Delete.
(read_measurement): Accept third argument, `is_mandatory`, of type
`bool`. Pass it to `is_valid_expression()`, which is already prepared
for same.
Continues the long process of fixing Savannah #67735.
---
ChangeLog | 32 ++++++++++++++++++++++++++++++++
src/roff/troff/input.cpp | 20 ++++++++++++--------
src/roff/troff/number.cpp | 5 +++--
src/roff/troff/reg.cpp | 6 ++++--
src/roff/troff/token.h | 6 +++---
5 files changed, 54 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index efff63002..64b12a3b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2025-12-19 G. Branden Robinson <[email protected]>
+
+ [troff]: Refactor to use the C++ default argument force. Merge
+ function `get_number_rigidly()` into `read_measurement(), which
+ differed by one line out of a dozen, by extending the latter's
+ signature with a default argument `is_mandatory` of type `bool`.
+ This coincidentally made GCC's overload resolver more sensitive
+ to arguments of ambiguous integral type, so take this
+ opportunity to stop punning between character literals and
+ `unsigned char`, in favor of the explicitness we'll need anyway
+ for GNU troff's planned wider fundamental character type.
+
+ * src/roff/troff/token.h: Drop declaration of
+ `get_number_rigidly()`. Update declaration of
+ `read_measurement()` with `bool`-valued 3rd argument defaulting
+ `false`.
+ * src/roff/troff/input.cpp (read_color_channel_value)
+ (do_expr_test, read_size, do_register)
+ (is_conditional_expression_true, evaluate_expression):
+ * src/roff/troff/reg.cpp (define_register_request):
+ Explicitly construct literal of `unsigned char` type as argument
+ to `read_measurement()`.
+ * src/roff/troff/input.cpp (do_expr_test): Migrate only call
+ site of `get_number_rigidly()` to `read_measurement()` with an
+ explicit `true` 3rd argument.
+ * src/roff/troff/number.cpp (get_number_rigidly): Delete.
+ (read_measurement): Accept third argument, `is_mandatory`, of
+ type `bool`. Pass it to `is_valid_expression()`, which is
+ already prepared for same.
+
+ Continues the long process of fixing Savannah #67735.
+
2025-12-19 G. Branden Robinson <[email protected]>
* src/roff/troff/number.cpp: Fix code style nits. Replace
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index b53ab799f..6ab580b61 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -1410,7 +1410,7 @@ static unsigned int read_color_channel_value(const char
*scheme,
const char *col)
{
units val;
- if (!read_measurement(&val, 'f')) {
+ if (!read_measurement(&val, (unsigned char)('f'))) { // TODO: grochar
warning(WARN_COLOR, "%1 in %2 definition set to 0", col, scheme);
tok.next();
return 0;
@@ -1843,11 +1843,13 @@ static const char *do_expr_test() // \B
warning_mask = 0;
want_errors_inhibited = true;
int dummy;
- bool result = get_number_rigidly(&dummy, 'u');
+ // TODO: grochar
+ bool result = read_measurement(&dummy, (unsigned char)('u'),
+ true /* is_mandatory */);
warning_mask = saved_warning_mask;
want_errors_inhibited = saved_want_errors_inhibited;
- // get_number_rigidly() has left `token` pointing at the input
- // character after the end of the expression.
+ // read_measurement() has left `token` pointing at the input character
+ // after the end of the expression.
if (tok == start_token && input_stack::get_level() == start_level)
return (result ? "1" : "0");
// There may be garbage after the expression but before the closing
@@ -6173,7 +6175,7 @@ static bool read_size(int *x) // \s
inc = (c == '+') ? 1 : -1;
tok.next();
}
- if (!read_measurement(&val, 'z'))
+ if (!read_measurement(&val, (unsigned char)('z'))) // TODO: grochar
return false;
// safely compares to char literals; TODO: grochar
int s = start.ch();
@@ -6338,7 +6340,8 @@ static void do_register() // \R
if ((0 /* nullptr */ == r) || !r->get_value(&prev_value))
prev_value = 0;
int val;
- if (!read_measurement(&val, 'u', prev_value))
+ // TODO: grochar
+ if (!read_measurement(&val, (unsigned char)('u'), prev_value))
return;
// token::description() writes to static, class-wide storage, so we
// must allocate a copy of it before issuing the next diagnostic.
@@ -7217,7 +7220,7 @@ static bool is_conditional_expression_true()
else {
// Evaluate numeric expression.
units n;
- if (!read_measurement(&n, 'u')) {
+ if (!read_measurement(&n, (unsigned char)('u'))) { // TODO: grochar
skip_branch();
return false;
}
@@ -9647,7 +9650,8 @@ static int evaluate_expression(const char *expr, units
*res)
{
input_stack::push(make_temp_iterator(expr));
tok.next();
- int success = read_measurement(res, 'u');
+ // TODO: grochar
+ int success = read_measurement(res, (unsigned char)('u'));
while (input_stack::get(0 /* nullptr */) != EOF)
;
return success;
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index b271b2e9e..c4393fd3d 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -86,12 +86,13 @@ bool get_number_rigidly(units *res, unsigned char si)
return false;
}
-bool read_measurement(units *res, unsigned char si)
+bool read_measurement(units *res, unsigned char si, bool is_mandatory)
{
if (!is_valid_expression_start())
return false;
units x;
- if (is_valid_expression(&x, si, false /* is_parenthesized */)) {
+ if (is_valid_expression(&x, si, false /* is_parenthesized */,
+ is_mandatory)) {
*res = x;
return true;
}
diff --git a/src/roff/troff/reg.cpp b/src/roff/troff/reg.cpp
index d57b6928c..90c1edfdd 100644
--- a/src/roff/troff/reg.cpp
+++ b/src/roff/troff/reg.cpp
@@ -351,14 +351,16 @@ static void define_register_request()
skip_line();
return;
}
- if (read_measurement(&v, 'u', prev_value)) {
+ // TODO: grochar
+ if (read_measurement(&v, (unsigned char)('u'), prev_value)) {
if (0 /* nullptr */ == r) {
r = new number_reg;
register_dictionary.define(nm, r);
}
r->set_value(v);
if (tok.is_space()) {
- if (has_arg() && read_measurement(&v, 'u'))
+ // TODO: grochar
+ if (has_arg() && read_measurement(&v, (unsigned char)('u')))
r->set_increment(v);
}
else if (has_arg() && !tok.is_tab())
diff --git a/src/roff/troff/token.h b/src/roff/troff/token.h
index 6b16b4e6b..3fc74ab08 100644
--- a/src/roff/troff/token.h
+++ b/src/roff/troff/token.h
@@ -146,9 +146,9 @@ extern void define_character(char_mode,
class hunits;
extern void read_title_parts(node **part, hunits *part_width);
-extern bool get_number_rigidly(units *result, unsigned char si);
-
-extern bool read_measurement(units *result, unsigned char si);
+extern bool read_measurement(units * /* result */,
+ unsigned char /* scale indicator */,
+ bool /* is_mandatory */ = false);
extern bool read_integer(int *result);
extern bool read_measurement(units *result, unsigned char si,
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit