Thread (2 messages) 2 messages, 2 authors, 2025-07-15

Re: [PATCH v3 09/17] tools/dot2c: Fix generated files going over 100 column limit

From: Nam Cao <hidden>
Date: 2025-07-15 15:01:59
Also in: lkml

Possibly related (same subject, not in this thread)

On Tue, Jul 15, 2025 at 09:14:26AM +0200, Gabriele Monaco wrote:
From: Nam Cao <redacted>
You seem to take a slightly different solution. Feel free to take my name
off the author field, Co-developed-by: or Suggested-by: would be fine. It's
up to you, doesn't really matter to me.
quoted hunk ↗ jump to hunk
The dot2c.py script generates all states in a single line. This breaks the
100 column limit when the state machines are non-trivial.

Change dot2c.py to generate the states in separate lines in case the
generated line is going to be too long.

Co-authored-by: Gabriele Monaco [off-list ref]
Signed-off-by: Nam Cao <redacted>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
 tools/verification/rvgen/rvgen/dot2c.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/tools/verification/rvgen/rvgen/dot2c.py b/tools/verification/rvgen/rvgen/dot2c.py
index 6009caf568d92..5216d98ae21c8 100644
--- a/tools/verification/rvgen/rvgen/dot2c.py
+++ b/tools/verification/rvgen/rvgen/dot2c.py
@@ -152,28 +152,29 @@ class Dot2c(Automata):
         max_state_name = max(self.states, key = len).__len__()
         return max(max_state_name, self.invalid_state_str.__len__())
 
-    def __get_state_string_length(self):
-        maxlen = self.__get_max_strlen_of_states() + self.enum_suffix.__len__()
-        return "%" + str(maxlen) + "s"
-
     def get_aut_init_function(self):
         nr_states = self.states.__len__()
         nr_events = self.events.__len__()
         buff = []
 
-        strformat = self.__get_state_string_length()
-
+        maxlen = self.__get_max_strlen_of_states() + len(self.enum_suffix)
+        # account for tabs and spaces/punctuation for each event
+        linetoolong = 16 + (maxlen + 3) * nr_events >= self.line_length
I managed to figure out 16 is the indentation. But I failed to understand
where is this '3' from.

Can you please add some comments for these magic numbers? Or better, assign
them to variables with self-explanatory names.

Best regards,
Nam
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help