summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-03-25 01:03:26 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2018-03-26 13:03:19 +0000
commitbb22df3db915f2141ce3c2477e7417781c5961f4 (patch)
tree8911726a0806152a32ace3c352e595fcd9d8615e
parent46145e80ec64f4941469debb8310be37fba69ded (diff)
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
-rwxr-xr-xcontrib/fsm-to-dot.py4
1 files changed, 4 insertions, 0 deletions
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()