From bb22df3db915f2141ce3c2477e7417781c5961f4 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Sun, 25 Mar 2018 01:03:26 +0100 Subject: contrib/fsm-to-dot: don't match on event names in comments Strip comments from function bodies before matching on event names. In osmo-bsc's gscon FSM, there often are event names in comments. The naive parsing of fsm-to-dot.py mistakes these as events causing state transitions, but the comments are just explaining how states interact. Makes me reconsider parsing the C with clang instead, but I got away with a dirty hack once more. Change-Id: I56d70ae14d363f7ca655dced16d93d795b3f940d --- contrib/fsm-to-dot.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'contrib') diff --git a/contrib/fsm-to-dot.py b/contrib/fsm-to-dot.py index 276fccc9..ce94a4eb 100755 --- a/contrib/fsm-to-dot.py +++ b/contrib/fsm-to-dot.py @@ -566,6 +566,8 @@ re_func = re.compile(r'(\b[a-z_][a-z_0-9]*\b)\([^)]*\)\W*^{', re.MULTILINE) re_state_trigger = re.compile(r'osmo_fsm_inst_state_chg\([^,]+,\W*([A-Z_][A-Z_0-9]*)\W*,', re.M) re_fsm_alloc = re.compile(r'osmo_fsm_inst_alloc[_child]*\(\W*&([a-z_][a-z_0-9]*),', re.M) re_fsm_event_dispatch = re.compile(r'osmo_fsm_inst_dispatch\(\W*[^,]+,\W*([A-Z_][A-Z_0-9]*)\W*,', re.M) +re_comment_multiline = re.compile(r'/\*.*?\*/', re.M | re.S) +re_comment_single_line = re.compile(r'//.*$', re.M | re.S) class CFile(): def __init__(c_file, path): @@ -625,6 +627,8 @@ class CFile(): for m in re_func.finditer(c_file.src): name = m.group(1) func_src = c_file.extract_block('{', '}', m.start()) + func_src = ''.join(re_comment_multiline.split(func_src)) + func_src = ''.join(re_comment_single_line.split(func_src)) funcs[name] = func_src c_file.funcs = funcs c_file.find_fsm_allocators() -- cgit v1.2.3