Moved params to core and some code cleanup

This commit is contained in:
Leonardo Vencovsky committed 2020-05-26 15:32:34 -03:00
1 parent 8e0183a7d7
commit 720e55bfcc
5 files changed
+53 -77

No files matched your search

+3 -4
View File
@@ -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)); \
} \
} \
\
+44 -1
View File
@@ -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
*
-51
View File
@@ -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 */