Skip to content

Commit 2074723

Browse files
walacglemco
authored andcommitted
rv/rvgen: extract node marker string to class constant
Add a node_marker class constant to the Automata class to replace the hardcoded "{node" string literal used throughout the DOT file parsing logic. This follows the existing pattern established by the init_marker and invalid_state_str class constants in the same class. The "{node" string is used as a marker to identify node declaration lines in DOT files during state variable extraction and cursor positioning. Extracting it to a named constant improves code maintainability and makes the marker's purpose explicit. Signed-off-by: Wander Lairson Costa <wander@redhat.com> Reviewed-by: Gabriele Monaco <gmonaco@redhat.com> Link: https://lore.kernel.org/r/20260223162407.147003-17-wander@redhat.com Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
1 parent 8aee49c commit 2074723

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

tools/verification/rvgen/rvgen/automata.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Automata:
4444

4545
invalid_state_str = "INVALID_STATE"
4646
init_marker = "__init_"
47+
node_marker = "{node"
4748
# val can be numerical, uppercase (constant or macro), lowercase (parameter or function)
4849
# only numerical values should have units
4950
constraint_rule = re.compile(r"""
@@ -112,7 +113,7 @@ def __get_cursor_begin_states(self) -> int:
112113
for cursor, line in enumerate(self.__dot_lines):
113114
split_line = line.split()
114115

115-
if len(split_line) and split_line[0] == "{node":
116+
if len(split_line) and split_line[0] == self.node_marker:
116117
return cursor
117118

118119
raise AutomataError("Could not find a beginning state")
@@ -127,9 +128,9 @@ def __get_cursor_begin_events(self) -> int:
127128
continue
128129

129130
if state == 0:
130-
if line[0] == "{node":
131+
if line[0] == self.node_marker:
131132
state = 1
132-
elif line[0] != "{node":
133+
elif line[0] != self.node_marker:
133134
break
134135
else:
135136
raise AutomataError("Could not find beginning event")
@@ -151,7 +152,7 @@ def __get_state_variables(self) -> tuple[list[str], str, list[str]]:
151152
# process nodes
152153
for line in islice(self.__dot_lines, cursor, None):
153154
split_line = line.split()
154-
if not split_line or split_line[0] != "{node":
155+
if not split_line or split_line[0] != self.node_marker:
155156
break
156157

157158
raw_state = split_line[-1]

0 commit comments

Comments
 (0)