summaryrefslogtreecommitdiff
path: root/build-aux/measurestack/app_plugins.py
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux/measurestack/app_plugins.py')
-rw-r--r--build-aux/measurestack/app_plugins.py56
1 files changed, 30 insertions, 26 deletions
diff --git a/build-aux/measurestack/app_plugins.py b/build-aux/measurestack/app_plugins.py
index eb1db09..0bd5486 100644
--- a/build-aux/measurestack/app_plugins.py
+++ b/build-aux/measurestack/app_plugins.py
@@ -55,15 +55,21 @@ class CmdPlugin:
return False
+re_comment = re.compile(r"/\*.*?\*/")
+re_ws = re.compile(r"\s+")
+re_lo_iface = re.compile(r"^\s*#\s*define\s+(?P<name>\S+)_LO_IFACE")
+re_lo_func = re.compile(r"LO_FUNC *\([^,]*, *(?P<name>[^,) ]+) *[,)]")
+re_lo_implementation = re.compile(
+ r"^LO_IMPLEMENTATION_[HC]\s*\(\s*(?P<iface>[^, ]+)\s*,\s*(?P<impl_typ>[^,]+)\s*,\s*(?P<impl_name>[^, ]+)\s*[,)].*"
+)
+re_call_objcall = re.compile(r"LO_CALL\((?P<obj>[^,]+), (?P<meth>[^,)]+)[,)].*")
+
+
class LibObjPlugin:
objcalls: dict[str, set[QName]] # method_name => {method_impls}
def __init__(self, arg_c_fnames: typing.Collection[str]) -> None:
ifaces: dict[str, set[str]] = {} # iface_name => {method_names}
- re_comment = re.compile(r"/\*.*?\*/")
- re_ws = re.compile(r"\s+")
- re_lo_iface = re.compile(r"^\s*#\s*define\s+(?P<name>\S+)_LO_IFACE")
- re_lo_func = re.compile(r"LO_FUNC *\([^,]*, *(?P<name>[^,) ]+) *[,)]")
for fname in arg_c_fnames:
with open(fname, "r", encoding="utf-8") as fh:
while line := fh.readline():
@@ -82,9 +88,6 @@ class LibObjPlugin:
implementations: dict[str, set[str]] = {} # iface_name => {impl_names}
for iface_name in ifaces:
implementations[iface_name] = set()
- re_lo_implementation = re.compile(
- r"^LO_IMPLEMENTATION_[HC]\s*\(\s*(?P<iface>[^, ]+)\s*,\s*(?P<impl_typ>[^,]+)\s*,\s*(?P<impl_name>[^, ]+)\s*[,)].*"
- )
for fname in arg_c_fnames:
with open(fname, "r", encoding="utf-8") as fh:
for line in fh:
@@ -116,7 +119,6 @@ class LibObjPlugin:
def indirect_callees(
self, loc: str, line: str
) -> tuple[typing.Collection[QName], bool] | None:
- re_call_objcall = re.compile(r"LO_CALL\((?P<obj>[^,]+), (?P<meth>[^,)]+)[,)].*")
if "/3rd-party/" in loc:
return None
@@ -254,6 +256,15 @@ class LibCRIPCPlugin:
return False
+re_tmessage_handler = re.compile(
+ r"^\s*\[LIB9P_TYP_T[^]]+\]\s*=\s*\(tmessage_handler\)\s*(?P<handler>\S+),\s*$"
+)
+re_lib9p_msg_entry = re.compile(r"^\s*_MSG_(?:[A-Z]+)\((?P<typ>\S+)\),$")
+re_lib9p_caller = re.compile(
+ r"^lib9p_(?P<grp>[TR])msg_(?P<meth>validate|unmarshal|marshal)$"
+)
+
+
class Lib9PPlugin:
tmessage_handlers: set[QName] | None
lib9p_msgs: set[str]
@@ -303,9 +314,6 @@ class Lib9PPlugin:
tmessage_handlers: set[QName] | None = None
if lib9p_srv_c_fname:
- re_tmessage_handler = re.compile(
- r"^\s*\[LIB9P_TYP_T[^]]+\]\s*=\s*\(tmessage_handler\)\s*(?P<handler>\S+),\s*$"
- )
tmessage_handlers = set()
with open(lib9p_srv_c_fname, "r", encoding="utf-8") as fh:
for line in fh:
@@ -316,7 +324,6 @@ class Lib9PPlugin:
lib9p_msgs: set[str] = set()
if lib9p_generated_c_fname:
- re_lib9p_msg_entry = re.compile(r"^\s*_MSG_(?:[A-Z]+)\((?P<typ>\S+)\),$")
with open(lib9p_generated_c_fname, "r", encoding="utf-8") as fh:
for line in fh:
line = line.rstrip()
@@ -373,12 +380,9 @@ class Lib9PPlugin:
for c in chain[-self.CONFIG_9P_SRV_MAX_DEPTH :]
):
return True
- re_msg_meth = re.compile(
- r"^lib9p_(?P<grp>[TR])msg_(?P<meth>validate|unmarshal|marshal)$"
- )
- wrapper = next((c for c in chain if re_msg_meth.match(str(c))), None)
+ wrapper = next((c for c in chain if re_lib9p_caller.match(str(c))), None)
if wrapper:
- m = re_msg_meth.match(str(wrapper))
+ m = re_lib9p_caller.match(str(wrapper))
assert m
deny = m.group("meth") + "_" + ("R" if m.group("grp") == "T" else "T")
if str(call.base()).startswith(deny):
@@ -717,6 +721,15 @@ class PicoSDKPlugin:
return ret
+re_tud_class = re.compile(
+ r"^\s*#\s*define\s+(?P<k>CFG_TUD_(?:\S{3}|AUDIO|VIDEO|MIDI|VENDOR|USBTMC|DFU_RUNTIME|ECM_RNDIS))\s+(?P<v>\S+).*"
+)
+re_tud_entry = re.compile(r"^\s+\.(?P<meth>\S+)\s*=\s*(?P<impl>[a-zA-Z0-9_]+)(?:,.*)?")
+re_tud_if1 = re.compile(r"^\s*#\s*if (\S+)\s*")
+re_tud_if2 = re.compile(r"^\s*#\s*if (\S+)\s*\|\|\s*(\S+)\s*")
+re_tud_endif = re.compile(r"^\s*#\s*endif\s*")
+
+
class TinyUSBDevicePlugin:
tud_drivers: dict[str, set[QName]] # method_name => {method_impls}
@@ -734,9 +747,6 @@ class TinyUSBDevicePlugin:
return
assert tusb_config_h_fname
- re_tud_class = re.compile(
- r"^\s*#\s*define\s+(?P<k>CFG_TUD_(?:\S{3}|AUDIO|VIDEO|MIDI|VENDOR|USBTMC|DFU_RUNTIME|ECM_RNDIS))\s+(?P<v>\S+).*"
- )
tusb_config: dict[str, bool] = {}
with open(tusb_config_h_fname, "r", encoding="utf-8") as fh:
in_table = False
@@ -748,12 +758,6 @@ class TinyUSBDevicePlugin:
tusb_config[k] = bool(int(v))
tud_drivers: dict[str, set[QName]] = {}
- re_tud_entry = re.compile(
- r"^\s+\.(?P<meth>\S+)\s*=\s*(?P<impl>[a-zA-Z0-9_]+)(?:,.*)?"
- )
- re_tud_if1 = re.compile(r"^\s*#\s*if (\S+)\s*")
- re_tud_if2 = re.compile(r"^\s*#\s*if (\S+)\s*\|\|\s*(\S+)\s*")
- re_tud_endif = re.compile(r"^\s*#\s*endif\s*")
with open(usbd_c_fname, "r", encoding="utf-8") as fh:
in_table = False
enabled = True