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 262a681
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 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,41 @@ 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.
Returns:
The number of functions 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(f"--------------------------------------------")
print(f"Processing GOTO metric with threshold >{threshold}")
print(f"--------------------------------------------")
print("Checking the number of goto statements in each function (Limit: " + str(threshold)
+ ")")

# 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

print("GOTO metric finish with " + str(metric_fail) + " error(s)\n")

return metric_fail

return 0

def process_level(files, threshold):
"""
Expand Down

0 comments on commit 262a681

Please sign in to comment.