diff --git a/his_checker.py b/his_checker.py index 94e66e3..22ddc98 100755 --- a/his_checker.py +++ b/his_checker.py @@ -71,8 +71,34 @@ def process_calls(files): print(f"== Check done with {metric_fail} error(s) ==\n") return metric_fail +def process_recursive(files): + + """Detect if there are any recursive functions.""" + + metric_fail = 0 + cflow = "cflow -l -r " + print("== Checking the number of recursive functions ==") + pattern = r'\{\s*(\d+)\}\s+(.+?)\s+<(.+?)\sat\s(.+):(\d+)> \(R\)' + pattern_re = re.compile(pattern) + for file in files.files: + if file.endswith(".c"): + cflow_output = os.popen(f"{cflow} {file}").read() + matches = pattern_re.findall(cflow_output) + for match in matches: + depth = int(match[0]) + if depth == 0: + file_path = match[3] + function = match[2] + line_number = match[4] + print(f"At {file_path.split('src', 1)[1]} ({line_number}): " + f"{function} is a recursive function. " + f"Recursive functions are not allowed.") + metric_fail += 1 + print(f"== Check done with {metric_fail} error(s) ==\n") + return metric_fail + if __name__ == "__main__": - METRICS_LIST = [process_complexity, process_calls] + METRICS_LIST = [process_complexity, process_calls, process_recursive] CHECK_FAIL = 0 PARSER = argparse.ArgumentParser() PARSER.add_argument("files", nargs="+", help="The files to process")