diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-03-26 15:01:38 +0200 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2018-03-26 15:04:32 +0200 |
commit | 71f781c303bb4216d3328181d7798a28a15813c9 (patch) | |
tree | 337844d54cb809734e7ca18fa6c5cb9106bb49b1 /contrib | |
parent | 338d17439973a7f2f54efc75bb8d40f6b9b8ff40 (diff) |
contrib/fsm-to-dot: warn about identically named FSMs
FSMs with identical names confuse the script, so at least warn about them.
IMHO we should also have different names for each FSM, so not bothering to make
the script safe against identical naming.
Change-Id: I4fe7e85d2fdf23e2ba964f3b47be1954edc63cef
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/fsm-to-dot.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/contrib/fsm-to-dot.py b/contrib/fsm-to-dot.py index 96f7e005..85e2806f 100755 --- a/contrib/fsm-to-dot.py +++ b/contrib/fsm-to-dot.py @@ -262,7 +262,7 @@ class Fsm: def __str__(fsm): return 'Fsm(%r,%r)' % (fsm.struct_name, fsm.from_file) - def parse_states(fsm, src): + def parse_states(fsm, src, c_file): state = None started = None @@ -274,6 +274,15 @@ class Fsm: for line in lines: state_name = state_starts(line) if state_name: + state = fsm.find_state_by_name(state_name) + if state is not None: + if c_file is fsm.from_file: + print('ERROR: fsm %r has multiple definitions of state %r' % (fsm, state_name)) + else: + print('ERROR: it appears two FSMs with identical name %r exist in %r and %r' + % (fsm.struct_name, fsm.from_file, c_file)) + state = None + continue state = State() fsm.states.append(state) started = None @@ -664,7 +673,7 @@ class CFile(): states_struct_name = m.group(1) for fsm in fsms: if states_struct_name == fsm.states_struct_name: - fsm.parse_states(c_file.extract_block('{', '}', m.start())) + fsm.parse_states(c_file.extract_block('{', '}', m.start()), c_file) def parse_functions(c_file): funcs = {} @@ -787,6 +796,14 @@ fsms = [] for c_file in c_files: fsms.extend(c_file.find_fsms()) +for fsm1 in fsms: + for fsm2 in fsms: + if fsm1 is fsm2: + continue + if fsm1.states_struct_name == fsm2.states_struct_name: + print('ERROR: two distinct FSMs share the same states-struct name: %r and %r both use %r' + % (fsm1, fsm2, fsm1.states_struct_name)) + for c_file in c_files: c_file.find_fsm_states(fsms) c_file.find_event_sources(fsms) |