Skip to content

Commit

Permalink
feat(HIS): add goto statement checker
Browse files Browse the repository at this point in the history
Signed-off-by: Afonso Santos <[email protected]>
  • Loading branch information
AfonsoSantos96 authored and danielRep committed Feb 27, 2024
1 parent 27fec24 commit 929ee95
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions his_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import sys
import argparse
import os

def process_calling(files, threshold):
"""
Expand Down Expand Up @@ -39,12 +40,38 @@ def process_comf(files, threshold):

def process_goto(files, threshold):
"""
Process the goto metric
Process number of 'goto' statements. This function checks each function in the provided files
for 'goto' statements. If the number of 'goto' statements in a function exceeds the defined
threshold, an error message is printed and the error count is incremented.
Args:
files: A list of file paths to check for 'goto' statements.
threshold: The maximum number of 'goto' statements allowed in a function.
Returns:
The number of files that exceed the 'goto' statement threshold.
"""

print(f"Processing GOTO metric with threshold {threshold} for files: {', '.join(files)}")
metric_fail = 0
qmcalc_goto_index = 18
goto_tool = "qmcalc "

print("--------------------------------------------")
print(f"Processing GOTO metric with threshold >{threshold}")
print("--------------------------------------------")

# Process each file
for file in files:
# Run 'qmcalc' on the file and split the output into lines
sline = os.popen(goto_tool + str(file)).read().split('\n')

for fields in [line.split('\t') for line in sline[:-1]]:
if int(fields[qmcalc_goto_index]) > threshold:
print("At " + file + " there is " + fields[qmcalc_goto_index] + " goto statements")
metric_fail += 1

return metric_fail

return 0

def process_level(files, threshold):
"""
Expand Down Expand Up @@ -206,6 +233,11 @@ def process_v_g(files, threshold):

# Add the number of failures for the metric to the total failure count
CHECK_FAIL += metric_function(ARGS.files, val)
print("--------------------------------------------")
if CHECK_FAIL:
print(f"{metric} metric failed with {CHECK_FAIL} error(s)\n")
else:
print(f"{metric} metric passed")

# If there were any failures, exit with an error code
if CHECK_FAIL:
Expand Down

0 comments on commit 929ee95

Please sign in to comment.