From 720e55bfcc022fad90645c9c22b6e49e03c8755a Mon Sep 17 00:00:00 2001 From: Leonardo Vencovsky Date: Tue, 26 May 2020 15:32:34 -0300 Subject: [PATCH] Moved params to core and some code cleanup --- Makefile | 25 +++++------------------ autogen.py | 2 +- src/cmc/treeset.h | 7 +++---- src/cor/core.h | 45 ++++++++++++++++++++++++++++++++++++++++- src/cor/params.h | 51 ----------------------------------------------- 5 files changed, 53 insertions(+), 77 deletions(-) delete mode 100644 src/cor/params.h diff --git a/Makefile b/Makefile index 971ce61..ecbba47 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,13 @@ # This file is useful to format all the source files and header in this library using clang-format -.PHONY: all cmc dev sac utl tests FORCE +ARGS = --verbose -all: cmc cor dev ext sac utl tests +all: src tests -cmc: FORCE - clang-format --style=file -i ./src/cmc/*.h - -cor: FORCE - clang-format --style=file -i ./src/cor/*.h - -dev: FORCE - clang-format --style=file -i ./src/dev/*.h - -ext: FORCE - clang-format --style=file -i ./src/ext/**/*.h - -sac: FORCE - clang-format --style=file -i ./src/sac/*.h - -utl: FORCE - clang-format --style=file -i ./src/utl/*.h +src: FORCE + find ./src/ -iname *.h | xargs clang-format --style=file --verbose -i tests: FORCE - clang-format --style=file -i ./tests/main/unt/*.c ./tests/main/main.c ./tests/*.c + find ./tests/ -iname *.c -o -iname *.h | xargs clang-format --style=file --verbose -i FORCE: diff --git a/autogen.py b/autogen.py index 73124b2..fe8b08d 100644 --- a/autogen.py +++ b/autogen.py @@ -95,5 +95,5 @@ os.remove(TMP_FILE) # Format all files print('Formating files...') -subprocess.call(['clang-format', '--style=file', '-i', f'{OUTPUT_DIR}/*.c']) +subprocess.call(['clang-format', '--style=file', '-i', f'{OUTPUT_DIR}/*.c', '--verbose']) print('Done') diff --git a/src/cmc/treeset.h b/src/cmc/treeset.h index eb853e3..9d4ed3e 100644 --- a/src/cmc/treeset.h +++ b/src/cmc/treeset.h @@ -676,10 +676,9 @@ static const char *cmc_cmc_string_fmt_treeset = "struct %s<%s> " { \ if (_set_->f_val->cpy) \ CMC_(PFX, _insert) \ - (result, \ - _set_->f_val->cpy(CMC_(PFX, _iter_value)(&iter))); \ - else \ - CMC_(PFX, _insert)(result, CMC_(PFX, _iter_value)(&iter)); \ + (result, _set_->f_val->cpy(CMC_(PFX, _iter_value)(&iter))); \ + else CMC_(PFX, _insert)(result, \ + CMC_(PFX, _iter_value)(&iter)); \ } \ } \ \ diff --git a/src/cor/core.h b/src/cor/core.h index 36d0bd9..8eca039 100644 --- a/src/cor/core.h +++ b/src/cor/core.h @@ -10,6 +10,13 @@ /** * Core includes and macros for the entire library. + * + * Here you will find: + * - CMC_ + * - CMC_TO_STRING + * - CMC_INTERNAL_PREFIX_[ITER|NODE|ENTRY|FKEY|FVAL] + * - CMC_DEF_[ITER|NODE|ENTRY|FKEY|FVAL] + * - CMC_PARAM_[PFX|SNAME|SIZE|K|V] */ #ifndef CMC_COR_CORE_H @@ -25,7 +32,6 @@ #include "alloc.h" #include "callbacks.h" #include "flags.h" -#include "params.h" #define CMC__(A, B) A##B #define CMC_(A, B) CMC__(A, B) @@ -53,6 +59,43 @@ #define CMC_DEF_FVAL(SNAME) CMC_(SNAME, CMC_INTERNAL_PREFIX_FVAL) #define CMC_DEF_FKEY(SNAME) CMC_(SNAME, CMC_INTERNAL_PREFIX_FKEY) +/** + * A PARAM is a unified way to pass arguments to all macros that generate code. + * It is a tuple that contains the following parameters in order: + * + * PFX - Functions prefix + * SNAME - `struct` name + * SIZE - Size for SAC library + * K - Key type + * V - Value type + * + * PARAM := (PFX, SNAME, SIZE, K, V) + */ + +// clang-format off +/* +for i in range(5): + print(f"#define CMC_TUP_{i}_({', '.join(chr(x) for x in range(65, 65 + i + 1))}, ...) {chr(65 + i)}\n#define CMC_TUP_{i}(TUP) CMC_TUP_{i}_ TUP") +*/ +// clang-format on + +#define CMC_TUP_0_(A, ...) A +#define CMC_TUP_0(TUP) CMC_TUP_0_ TUP +#define CMC_TUP_1_(A, B, ...) B +#define CMC_TUP_1(TUP) CMC_TUP_1_ TUP +#define CMC_TUP_2_(A, B, C, ...) C +#define CMC_TUP_2(TUP) CMC_TUP_2_ TUP +#define CMC_TUP_3_(A, B, C, D, ...) D +#define CMC_TUP_3(TUP) CMC_TUP_3_ TUP +#define CMC_TUP_4_(A, B, C, D, E, ...) E +#define CMC_TUP_4(TUP) CMC_TUP_4_ TUP + +#define CMC_PARAM_PFX CMC_TUP_0 +#define CMC_PARAM_SNAME CMC_TUP_1 +#define CMC_PARAM_SIZE CMC_TUP_2 +#define CMC_PARAM_K CMC_TUP_3 +#define CMC_PARAM_V CMC_TUP_4 + /** * struct cmc_string * diff --git a/src/cor/params.h b/src/cor/params.h deleted file mode 100644 index 61d6091..0000000 --- a/src/cor/params.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - * params.h - * - * Creation Date: 25/05/2020 - * - * Authors: - * Leonardo Vencovsky (https://github.com/LeoVen) - * - */ - -/** - * A PARAM is a unified way to pass arguments to all macros that generate code. - * It is a tuple that contains the following parameters in order: - * - * PFX - Functions prefix - * SNAME - `struct` name - * SIZE - Size for SAC library - * K - Key type - * V - Value type - * - * PARAM := (PFX, SNAME, SIZE, K, V) - */ - -#ifndef CMC_COR_PARAMS_H -#define CMC_COR_PARAMS_H - -// clang-format off -/* -for i in range(5): - print(f"#define CMC_TUP_{i}_({', '.join(chr(x) for x in range(65, 65 + i + 1))}, ...) {chr(65 + i)}\n#define CMC_TUP_{i}(TUP) CMC_TUP_{i}_ TUP") -*/ -// clang-format on - -#define CMC_TUP_0_(A, ...) A -#define CMC_TUP_0(TUP) CMC_TUP_0_ TUP -#define CMC_TUP_1_(A, B, ...) B -#define CMC_TUP_1(TUP) CMC_TUP_1_ TUP -#define CMC_TUP_2_(A, B, C, ...) C -#define CMC_TUP_2(TUP) CMC_TUP_2_ TUP -#define CMC_TUP_3_(A, B, C, D, ...) D -#define CMC_TUP_3(TUP) CMC_TUP_3_ TUP -#define CMC_TUP_4_(A, B, C, D, E, ...) E -#define CMC_TUP_4(TUP) CMC_TUP_4_ TUP - -#define CMC_PARAM_PFX CMC_TUP_0 -#define CMC_PARAM_SNAME CMC_TUP_1 -#define CMC_PARAM_SIZE CMC_TUP_2 -#define CMC_PARAM_K CMC_TUP_3 -#define CMC_PARAM_V CMC_TUP_4 - -#endif /* CMC_COR_PARAMS_H */