Skip to content

Commit

Permalink
refactor<archi>: reorganize execute archi + improve clang_tidy
Browse files Browse the repository at this point in the history
This commits should reorganize execute module. Plus, clang_tidy is now able to accept double line prototype functions and also ignore comment lines (// symbole only)
  • Loading branch information
ErwannLesech committed Jan 19, 2024
1 parent 31f62e6 commit 9656356
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 8 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/clang_tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ root_dir=$(git rev-parse --show-toplevel)

# C files check
for file in $(find "$root_dir/src" -type f -name '*.c'); do
function_count=$(grep -E '^(bool|int|char|double|void|float|struct [a-zA-Z][a-zA-Z_]*|unsigned|long)[[:space:]]+[*]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*\([^)]*\)[[:space:]]*' "$file" | wc -l)
function_count=$(grep -E '^(bool|int|char|double|void|float|struct [a-zA-Z][a-zA-Z_]*|unsigned|long)[[:space:]]+[*]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*\([^)]*[[:space:]]*' "$file" | wc -l)

# echo "$function_count"
# echo "Processing file: $file"

# Extract function prototypes and count parameters and lines
grep -E '^(bool|int|char|double|void|float|struct [a-zA-Z][a-zA-Z_]*|unsigned|long)[[:space:]]+[*]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*\([^)]*\)[[:space:]]*' "$file" | while IFS= read -r line; do
grep -E '^(bool|int|char|double|void|float|struct [a-zA-Z][a-zA-Z_]*|unsigned|long)[[:space:]]+[*]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*\([^)]*[[:space:]]*' "$file" | while IFS= read -r line; do
return_type=$(echo "$line" | awk '{print $1}')
function_name=$(echo "$line" | awk '{print $2}' | sed 's/([^)]*//g')

Expand All @@ -29,7 +31,7 @@ for file in $(find "$root_dir/src" -type f -name '*.c'); do


# Count the number of lines in the function (excluding blank and '{', '}' lines)
lines_in_function=$(sed -n "/$return_type $function_name/,/^}/p" "$file" | sed '/^$/d' | sed '/^[[:space:]]*{$/d' | sed '/^[[:space:]]*}$/d' | wc -l)
lines_in_function=$(sed -n "/$return_type $function_name/,/^}/p" "$file" | sed '/^$/d' | sed -n "/^\s*\/\/.*$/!p" | sed '/^[[:space:]]*{$/d' | sed '/^[[:space:]]*}$/d' | wc -l)
lines_in_function=$((lines_in_function-1))

if [[ "$parameters" -gt 4 ]]; then
Expand Down
9 changes: 6 additions & 3 deletions src/execute/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
lib_LIBRARIES = libexecute.a

libexecute_a_SOURCES = pipeline.c loop.c ast_eval.c ast_eval.h ../parser/parser.h \
builtin.c builtin.h \
../ast/ast.h hash_map/hash_map.c hash_map/hash_map.h hash_map/hash.c ast_variable.c
libexecute_a_SOURCES = ast_eval.c ast_eval.h \
../parser/parser.h ../ast/ast.h \
utils/builtin.c utils/builtin.h \
utils/pipeline.c utils/loop.c \
hash_map/hash_map.c hash_map/hash_map.h \
hash_map/hash.c utils/ast_variable.c


libexecute_a_CFLAGS = -Wall -Wextra -Werror -Wvla -pedantic -std=c99
Expand Down
2 changes: 1 addition & 1 deletion src/execute/ast_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <sys/wait.h>
#include <unistd.h>

#include "builtin.h"
#include "utils/builtin.h"
#include "parser/parser.h"

// true = 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ enum token_type parser_pop(struct lexer *lexer);
*/
struct ast_node *parse_variable(struct lexer *lexer);

#endif /* ! PARSER_H */
#endif /* ! PARSER_H */

0 comments on commit 9656356

Please sign in to comment.