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 committed Nov 22, 2023
1 parent 2c77837 commit 42f30c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ARG CLANG_VERSION=14
# use this repo temporarily while the patches for misra fps are not in a new official version
ARG CPPCHECK_REPO=https://github.com/danmar/cppcheck.git
ARG CPPCHECK_VERSION=2.9
# repo for qmcalc tool
ARG QMCALC_REPO=https://github.com/dspinellis/cqmetrics.git

# install dependencies
RUN apt-get update && apt-get install -y \
Expand Down Expand Up @@ -40,6 +42,7 @@ RUN apt-get update && apt-get install -y \
pip3 install doorstop && \
pip3 install pyspellchecker && \
npm install -g cspell@latest && \
mkdir /opt/qmcalc && git clone $QMCALC_REPO --depth 1 /opt/qmcalc && make -C /opt/qmcalc/src && \
mkdir /opt/cppcheck && git clone $CPPCHECK_REPO --depth 1 --branch $CPPCHECK_VERSION /opt/cppcheck && make -C /opt/cppcheck FILESDIR=/usr/share/cppcheck && make -C /opt/cppcheck install FILESDIR=/usr/share/cppcheck && \
mkdir /opt/aarch64-toolchain && curl $AARCH64_TOOLCHAIN_LINK | tar xJ -C /opt/aarch64-toolchain --strip-components=1 && \
mkdir /opt/riscv-toolchain && curl $RISCV_TOOLCHAIN_LINK | tar xz -C /opt/riscv-toolchain --strip-components=1 && \
Expand Down
22 changes: 21 additions & 1 deletion his_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,29 @@

import sys
import argparse
import os

GOTO_THRESHOLD = 0

def process_goto(files):

"""Process number of goto statements in a function"""

metric_fail = 0
qmcalc_goto_index = 18
goto_tool = "qmcalc "
print("Checking the number of goto statements in each function")
for file in files.files:
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]) > GOTO_THRESHOLD:
print("At " + file + " there is a goto statement. No goto statements are allowed")
metric_fail += 1
print("Check done with " + str(metric_fail) + " error(s)\n")
return metric_fail

if __name__ == "__main__":
METRICS_LIST = []
METRICS_LIST = [process_goto]
CHECK_FAIL = 0
PARSER = argparse.ArgumentParser()
PARSER.add_argument("files", nargs="+", help="The files to process")
Expand Down

0 comments on commit 42f30c7

Please sign in to comment.