[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 18/28: [troff]: Refactor `charinfo` class (2/2).
From: |
G. Branden Robinson |
Subject: |
[groff] 18/28: [troff]: Refactor `charinfo` class (2/2). |
Date: |
Sun, 25 Aug 2024 23:03:31 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit d32cc9eb45943aaee34e547ab14eb8d96ff42c99
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Aug 25 17:53:54 2024 -0500
[troff]: Refactor `charinfo` class (2/2).
* src/roff/troff/charinfo.h (class charinfo): Rename enumeration
constants.
`BREAK_BEFORE` -> `ALLOWS_BREAK_BEFORE`
`BREAK_AFTER` -> `ALLOWS_BREAK_AFTER`
`TRANSPARENT` -> `IS_TRANSPARENT_TO_END_OF_SENTENCE`
`IGNORE_HCODES` -> `IGNORES_SURROUNDING_HYPHENATION_CODES`
`DONT_BREAK_BEFORE` -> `PROHIBITS_BREAK_BEFORE`
`DONT_BREAK_AFTER` -> `PROHIBITS_BREAK_AFTER`
`INTER_CHAR_SPACE` -> `IS_INTERWORD_SPACE`
Rename member functions.
`can_break_before()` -> `allows_break_before()`
`can_break_after()` -> `allows_break_after()`
`transparent()` -> `is_transparent()`
`ignore_hcodes()` -> `ignores_surrounding_hyphenation_codes()`
`prohibit_break_before()` -> `prohibits_break_before()`
`prohibit_break_after()` -> `prohibits_break_after()`
`inter_char_space()` -> `is_interword_space()`
`numbered()` -> `is_numbered()`
Demote the return types of the foregoing and `ends_sentence()`,
`overlaps_vertically()`, `overlaps_horizontally()`,
`first_time_not_found()`, `is_normal()`, `is_fallback()`, and
`is_special()` from `int` to `bool`. Update inline definitions.
Parenthesize complex `return` expressions.
* src/roff/troff/input.cpp (init_charset_table): Migrate to new
enumeration constants.
* src/roff/troff/node.cpp: Rename constants in `enum` `break_char_type`
to match those in "charinfo.h".
(troff_output_file::put_char_width, troff_output_file::put_char)
(charinfo_node::ends_sentence, break_char_node::add_self)
(make_glyph_node, node::add_char): Migrate to new enumeration constant
and member function names.
---
ChangeLog | 36 +++++++++++++++
src/roff/troff/charinfo.h | 110 ++++++++++++++++++++++++----------------------
src/roff/troff/input.cpp | 24 +++++-----
src/roff/troff/node.cpp | 62 ++++++++++++++------------
4 files changed, 138 insertions(+), 94 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 918d4ddcc..46c5292e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2024-08-25 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [troff]: Further refactor `charinfo` class.
+
+ * src/roff/troff/charinfo.h (class charinfo): Rename enumeration
+ constants.
+ `BREAK_BEFORE` -> `ALLOWS_BREAK_BEFORE`
+ `BREAK_AFTER` -> `ALLOWS_BREAK_AFTER`
+ `TRANSPARENT` -> `IS_TRANSPARENT_TO_END_OF_SENTENCE`
+ `IGNORE_HCODES` -> `IGNORES_SURROUNDING_HYPHENATION_CODES`
+ `DONT_BREAK_BEFORE` -> `PROHIBITS_BREAK_BEFORE`
+ `DONT_BREAK_AFTER` -> `PROHIBITS_BREAK_AFTER`
+ `INTER_CHAR_SPACE` -> `IS_INTERWORD_SPACE`
+ Rename member functions.
+ `can_break_before()` -> `allows_break_before()`
+ `can_break_after()` -> `allows_break_after()`
+ `transparent()` -> `is_transparent()`
+ `ignore_hcodes()` -> `ignores_surrounding_hyphenation_codes()`
+ `prohibit_break_before()` -> `prohibits_break_before()`
+ `prohibit_break_after()` -> `prohibits_break_after()`
+ `inter_char_space()` -> `is_interword_space()`
+ `numbered()` -> `is_numbered()`
+ Demote the return types of the foregoing and `ends_sentence()`,
+ `overlaps_vertically()`, `overlaps_horizontally()`,
+ `first_time_not_found()`, `is_normal()`, `is_fallback()`, and
+ `is_special()` from `int` to `bool`. Update inline definitions.
+ Parenthesize complex `return` expressions.
+ * src/roff/troff/input.cpp (init_charset_table): Migrate to new
+ enumeration constants.
+ * src/roff/troff/node.cpp: Rename constants in `enum`
+ `break_char_type` to match those in "charinfo.h".
+ (troff_output_file::put_char_width, troff_output_file::put_char)
+ (charinfo_node::ends_sentence, break_char_node::add_self)
+ (make_glyph_node, node::add_char): Migrate to new enumeration
+ constant and member function names.
+
2024-08-24 G. Branden Robinson <g.branden.robinson@gmail.com>
[troff]: Trivially refactor. Boolify `charinfo` class, renaming
diff --git a/src/roff/troff/charinfo.h b/src/roff/troff/charinfo.h
index 74f040ac1..531c35638 100644
--- a/src/roff/troff/charinfo.h
+++ b/src/roff/troff/charinfo.h
@@ -41,18 +41,22 @@ class charinfo : glyph {
std::vector<std::pair<int, int> > ranges;
std::vector<charinfo *> nested_classes;
public:
- enum { // Values for the flags bitmask. See groff
- // manual, description of the '.cflags' request.
+ // Values for the flags bitmask. See groff manual, description of the
+ // '.cflags' request.
+ //
+ // Keep these symbol names in sync with the subset used in the `enum`
+ // `break_char_type`; see "node.cpp".
+ enum {
ENDS_SENTENCE = 0x01,
- BREAK_BEFORE = 0x02,
- BREAK_AFTER = 0x04,
+ ALLOWS_BREAK_BEFORE = 0x02,
+ ALLOWS_BREAK_AFTER = 0x04,
OVERLAPS_HORIZONTALLY = 0x08,
OVERLAPS_VERTICALLY = 0x10,
- TRANSPARENT = 0x20,
- IGNORE_HCODES = 0x40,
- DONT_BREAK_BEFORE = 0x80,
- DONT_BREAK_AFTER = 0x100,
- INTER_CHAR_SPACE = 0x200
+ IS_TRANSPARENT_TO_END_OF_SENTENCE = 0x20,
+ IGNORES_SURROUNDING_HYPHENATION_CODES = 0x40,
+ PROHIBITS_BREAK_BEFORE = 0x80,
+ PROHIBITS_BREAK_AFTER = 0x100,
+ IS_INTERWORD_SPACE = 0x200
};
enum {
TRANSLATE_NONE,
@@ -64,16 +68,16 @@ public:
symbol nm;
charinfo(symbol);
glyph *as_glyph();
- int ends_sentence();
- int overlaps_vertically();
- int overlaps_horizontally();
- int can_break_before();
- int can_break_after();
- int transparent();
- int ignore_hcodes();
- int prohibit_break_before();
- int prohibit_break_after();
- int inter_char_space();
+ bool ends_sentence();
+ bool overlaps_vertically();
+ bool overlaps_horizontally();
+ bool allows_break_before();
+ bool allows_break_after();
+ bool is_transparent_to_end_of_sentence();
+ bool ignores_surrounding_hyphenation_codes();
+ bool prohibits_break_before();
+ bool prohibits_break_after();
+ bool is_interword_space();
unsigned char get_hyphenation_code();
unsigned char get_ascii_code();
unsigned char get_asciify_code();
@@ -92,13 +96,13 @@ public:
macro *set_macro(macro *);
macro *setx_macro(macro *, char_mode);
macro *get_macro();
- int first_time_not_found();
+ bool first_time_not_found();
void set_number(int);
int get_number();
- int numbered();
- int is_normal();
- int is_fallback();
- int is_special();
+ bool is_numbered();
+ bool is_normal();
+ bool is_fallback();
+ bool is_special();
symbol *get_symbol();
void add_to_class(int);
void add_to_class(int, int);
@@ -113,94 +117,94 @@ charinfo *get_charinfo(symbol);
extern charinfo *charset_table[];
charinfo *get_charinfo_by_number(int);
-inline int charinfo::overlaps_horizontally()
+inline bool charinfo::overlaps_horizontally()
{
if (using_character_classes)
::get_flags();
- return flags & OVERLAPS_HORIZONTALLY;
+ return (flags & OVERLAPS_HORIZONTALLY);
}
-inline int charinfo::overlaps_vertically()
+inline bool charinfo::overlaps_vertically()
{
if (using_character_classes)
::get_flags();
- return flags & OVERLAPS_VERTICALLY;
+ return (flags & OVERLAPS_VERTICALLY);
}
-inline int charinfo::can_break_before()
+inline bool charinfo::allows_break_before()
{
if (using_character_classes)
::get_flags();
- return flags & BREAK_BEFORE;
+ return (flags & ALLOWS_BREAK_BEFORE);
}
-inline int charinfo::can_break_after()
+inline bool charinfo::allows_break_after()
{
if (using_character_classes)
::get_flags();
- return flags & BREAK_AFTER;
+ return (flags & ALLOWS_BREAK_AFTER);
}
-inline int charinfo::ends_sentence()
+inline bool charinfo::ends_sentence()
{
if (using_character_classes)
::get_flags();
- return flags & ENDS_SENTENCE;
+ return (flags & ENDS_SENTENCE);
}
-inline int charinfo::transparent()
+inline bool charinfo::is_transparent_to_end_of_sentence()
{
if (using_character_classes)
::get_flags();
- return flags & TRANSPARENT;
+ return (flags & IS_TRANSPARENT_TO_END_OF_SENTENCE);
}
-inline int charinfo::ignore_hcodes()
+inline bool charinfo::ignores_surrounding_hyphenation_codes()
{
if (using_character_classes)
::get_flags();
- return flags & IGNORE_HCODES;
+ return (flags & IGNORES_SURROUNDING_HYPHENATION_CODES);
}
-inline int charinfo::prohibit_break_before()
+inline bool charinfo::prohibits_break_before()
{
if (using_character_classes)
::get_flags();
- return flags & DONT_BREAK_BEFORE;
+ return (flags & PROHIBITS_BREAK_BEFORE);
}
-inline int charinfo::prohibit_break_after()
+inline bool charinfo::prohibits_break_after()
{
if (using_character_classes)
::get_flags();
- return flags & DONT_BREAK_AFTER;
+ return (flags & PROHIBITS_BREAK_AFTER);
}
-inline int charinfo::inter_char_space()
+inline bool charinfo::is_interword_space()
{
if (using_character_classes)
::get_flags();
- return flags & INTER_CHAR_SPACE;
+ return (flags & IS_INTERWORD_SPACE);
}
-inline int charinfo::numbered()
+inline bool charinfo::is_numbered()
{
- return number >= 0;
+ return (number >= 0);
}
-inline int charinfo::is_normal()
+inline bool charinfo::is_normal()
{
- return mode == CHAR_NORMAL;
+ return (mode == CHAR_NORMAL);
}
-inline int charinfo::is_fallback()
+inline bool charinfo::is_fallback()
{
- return mode == CHAR_FALLBACK;
+ return (mode == CHAR_FALLBACK);
}
-inline int charinfo::is_special()
+inline bool charinfo::is_special()
{
- return mode == CHAR_SPECIAL;
+ return (mode == CHAR_SPECIAL);
}
inline charinfo *charinfo::get_translation(bool for_transparent_throughput)
@@ -257,7 +261,7 @@ inline macro *charinfo::get_macro()
return mac;
}
-inline int charinfo::first_time_not_found()
+inline bool charinfo::first_time_not_found()
{
if (is_not_found)
return false;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index d1cddc149..9dc1d5de3 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7272,18 +7272,18 @@ static void init_charset_table()
charset_table['.']->set_flags(charinfo::ENDS_SENTENCE);
charset_table['?']->set_flags(charinfo::ENDS_SENTENCE);
charset_table['!']->set_flags(charinfo::ENDS_SENTENCE);
- charset_table['-']->set_flags(charinfo::BREAK_AFTER);
- charset_table['"']->set_flags(charinfo::TRANSPARENT);
- charset_table['\'']->set_flags(charinfo::TRANSPARENT);
- charset_table[')']->set_flags(charinfo::TRANSPARENT);
- charset_table[']']->set_flags(charinfo::TRANSPARENT);
- charset_table['*']->set_flags(charinfo::TRANSPARENT);
- get_charinfo(symbol("dg"))->set_flags(charinfo::TRANSPARENT);
- get_charinfo(symbol("dd"))->set_flags(charinfo::TRANSPARENT);
- get_charinfo(symbol("rq"))->set_flags(charinfo::TRANSPARENT);
- get_charinfo(symbol("cq"))->set_flags(charinfo::TRANSPARENT);
- get_charinfo(symbol("em"))->set_flags(charinfo::BREAK_AFTER);
- get_charinfo(symbol("hy"))->set_flags(charinfo::BREAK_AFTER);
+ charset_table['-']->set_flags(charinfo::ALLOWS_BREAK_AFTER);
+ charset_table['"']->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+ charset_table['\'']->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+ charset_table[')']->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+ charset_table[']']->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+ charset_table['*']->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+
get_charinfo(symbol("dg"))->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+
get_charinfo(symbol("dd"))->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+
get_charinfo(symbol("rq"))->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+
get_charinfo(symbol("cq"))->set_flags(charinfo::IS_TRANSPARENT_TO_END_OF_SENTENCE);
+ get_charinfo(symbol("em"))->set_flags(charinfo::ALLOWS_BREAK_AFTER);
+ get_charinfo(symbol("hy"))->set_flags(charinfo::ALLOWS_BREAK_AFTER);
get_charinfo(symbol("ul"))->set_flags(charinfo::OVERLAPS_HORIZONTALLY);
get_charinfo(symbol("rn"))->set_flags(charinfo::OVERLAPS_HORIZONTALLY);
get_charinfo(symbol("radicalex"))->set_flags(charinfo::OVERLAPS_HORIZONTALLY);
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 887c5db65..0b3cbaaea 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -1079,7 +1079,7 @@ void troff_output_file::put_char_width(charinfo *ci,
tfont *tf,
flush_tbuf();
do_motion();
check_charinfo(tf, ci);
- if (ci->numbered()) {
+ if (ci->is_numbered()) {
put('N');
put(ci->get_number());
}
@@ -1156,7 +1156,7 @@ void troff_output_file::put_char(charinfo *ci, tfont *tf,
fill_color(fcol);
flush_tbuf();
do_motion();
- if (ci->numbered()) {
+ if (ci->is_numbered()) {
put('N');
put(ci->get_number());
}
@@ -1857,7 +1857,7 @@ int charinfo_node::ends_sentence()
{
if (ci->ends_sentence())
return 1;
- else if (ci->transparent())
+ else if (ci->is_transparent_to_end_of_sentence())
return 2;
return 0;
}
@@ -2856,30 +2856,33 @@ int break_char_node::ends_sentence()
return ch->ends_sentence();
}
+// Keep these symbol names in sync with the superset used in an
+// anonymous `enum` in "charinfo.h".
enum break_char_type {
- CAN_BREAK_BEFORE = 0x01,
- CAN_BREAK_AFTER = 0x02,
- IGNORE_HCODES = 0x04,
- PROHIBIT_BREAK_BEFORE = 0x08,
- PROHIBIT_BREAK_AFTER = 0x10,
- INTER_CHAR_SPACE = 0x20
+ ALLOWS_BREAK_BEFORE = 0x01,
+ ALLOWS_BREAK_AFTER = 0x02,
+ IGNORES_SURROUNDING_HYPHENATION_CODES = 0x04,
+ PROHIBITS_BREAK_BEFORE = 0x08,
+ PROHIBITS_BREAK_AFTER = 0x10,
+ IS_INTERWORD_SPACE = 0x20
};
node *break_char_node::add_self(node *n, hyphen_list **p)
{
bool have_space_node = false;
assert((*p)->hyphenation_code == 0);
- if (break_code & CAN_BREAK_BEFORE) {
- if ((*p)->is_breakable || break_code & IGNORE_HCODES) {
+ if (break_code & ALLOWS_BREAK_BEFORE) {
+ if (((*p)->is_breakable)
+ || (break_code & IGNORES_SURROUNDING_HYPHENATION_CODES)) {
n = new space_node(H0, col, n);
n->freeze_space();
have_space_node = true;
}
}
if (!have_space_node) {
- if (prev_break_code & INTER_CHAR_SPACE
- || prev_break_code & PROHIBIT_BREAK_AFTER) {
- if (break_code & PROHIBIT_BREAK_BEFORE)
+ if ((prev_break_code & IS_INTERWORD_SPACE)
+ || (prev_break_code & PROHIBITS_BREAK_AFTER)) {
+ if (break_code & PROHIBITS_BREAK_BEFORE)
// stretchable zero-width space not implemented yet
;
else {
@@ -2891,8 +2894,9 @@ node *break_char_node::add_self(node *n, hyphen_list **p)
}
next = n;
n = this;
- if (break_code & CAN_BREAK_AFTER) {
- if ((*p)->is_breakable || break_code & IGNORE_HCODES) {
+ if (break_code & ALLOWS_BREAK_AFTER) {
+ if (((*p)->is_breakable)
+ || (break_code & IGNORES_SURROUNDING_HYPHENATION_CODES)) {
n = new space_node(H0, col, n);
n->freeze_space();
}
@@ -4980,7 +4984,7 @@ static node *make_glyph_node(charinfo *s, environment
*env,
macro *mac = s->get_macro();
if ((mac != 0 /* nullptr */) && s->is_fallback())
return make_composite_node(s, env);
- if (s->numbered()) {
+ if (s->is_numbered()) {
if (want_warnings)
warning(WARN_CHAR, "character code %1 not defined in current"
" font", s->get_number());
@@ -5163,18 +5167,18 @@ node *node::add_char(charinfo *ci, environment *env,
}
}
int break_code = 0;
- if (ci->can_break_before())
- break_code = CAN_BREAK_BEFORE;
- if (ci->can_break_after())
- break_code |= CAN_BREAK_AFTER;
- if (ci->ignore_hcodes())
- break_code |= IGNORE_HCODES;
- if (ci->prohibit_break_before())
- break_code = PROHIBIT_BREAK_BEFORE;
- if (ci->prohibit_break_after())
- break_code |= PROHIBIT_BREAK_AFTER;
- if (ci->inter_char_space())
- break_code |= INTER_CHAR_SPACE;
+ if (ci->allows_break_before())
+ break_code = ALLOWS_BREAK_BEFORE;
+ if (ci->allows_break_after())
+ break_code |= ALLOWS_BREAK_AFTER;
+ if (ci->ignores_surrounding_hyphenation_codes())
+ break_code |= IGNORES_SURROUNDING_HYPHENATION_CODES;
+ if (ci->prohibits_break_before())
+ break_code = PROHIBITS_BREAK_BEFORE;
+ if (ci->prohibits_break_after())
+ break_code |= PROHIBITS_BREAK_AFTER;
+ if (ci->is_interword_space())
+ break_code |= IS_INTERWORD_SPACE;
if (break_code) {
node *next1 = res->next;
res->next = 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 18/28: [troff]: Refactor `charinfo` class (2/2).,
G. Branden Robinson <=