From 7a8ddf06de96f99264193dda34f1f7dc9decb0b5 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sat, 30 Nov 2019 18:24:06 +0100 Subject: [PATCH] qa/coccinelle: flag check for setter and getter WHen adding something like /* coccinelle: AppLayerParserStateIssetFlag():4,2:APP_LAYER_PARSER_ */ the coccinelle check will consider that AppLayerParserStateIssetFlag is taking 4 parameters and that the second one is a flag that needs to be checked against APP_LAYER_PARSER_. --- qa/coccinelle/struct-flags.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/qa/coccinelle/struct-flags.py b/qa/coccinelle/struct-flags.py index 93377bd9bb..38c40b33e4 100755 --- a/qa/coccinelle/struct-flags.py +++ b/qa/coccinelle/struct-flags.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import re from os import listdir +from string import Template SRC_DIR = "../../src/" @@ -81,3 +82,36 @@ p1 << flags.p1; print "Invalid usage of flags field at %s:%s, flags value is incorrect (wrong family)." % (p1[0].file, p1[0].line) import sys sys.exit(1)""") + +i = 1 +setter_template = """ +@settergetter${i}@ +identifier SetterGetter =~ "${function}"; +identifier f_flags =~ "^(?!${value}).+"; +identifier ${params_line}; +position p1; +@@ + +SetterGetter@p1(${prefix_param}f_flags${suffix_param}) + +@script:python@ +p1 << settergetter${i}.p1; +@@ +print "Invalid usage of ${function} at %s:%s, flags value is incorrect (wrong family)." % (p1[0].file, p1[0].line) +import sys +sys.exit(1) +""" + +for sg in setter_getter_list: + prefix_param = "" + for index in list(range(1, sg.params[1])): + prefix_param += "param%d, " % (index) + if sg.params[1] < sg.params[0]: + suffix_param = ", " + ", ".join(["param%d" % (index + 1) for index in list(range(sg.params[1], sg.params[0]))]) + else: + suffix_param = "" + params_elts = list(range(1, sg.params[1])) + list(range(sg.params[1] + 1, sg.params[0] + 1)) + params_line = ", ".join(["param%d" % (x) for x in params_elts]) + print(Template(setter_template).substitute(i=i, function=sg.function, value=sg.value, + prefix_param=prefix_param, suffix_param=suffix_param, params_line=params_line)) + i += 1