aboutsummaryrefslogtreecommitdiff
path: root/macro.h
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-04 11:25:37 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-05 18:06:13 +0100
commitdc8474d9034d9281463bb69f7f7a922e3ea713ee (patch)
treec3b870ada88f7aaa48918c4eb8b5d865f2f82019 /macro.h
parentWork on propper memmory management for linked lists. (diff)
downloadcalp-dc8474d9034d9281463bb69f7f7a922e3ea713ee.tar.gz
calp-dc8474d9034d9281463bb69f7f7a922e3ea713ee.tar.xz
Normalize and improve INIT & FREE macros.
Diffstat (limited to 'macro.h')
-rw-r--r--macro.h44
1 files changed, 13 insertions, 31 deletions
diff --git a/macro.h b/macro.h
index a62d12d1..82b8e558 100644
--- a/macro.h
+++ b/macro.h
@@ -24,44 +24,26 @@
#define NEW_HELPER(T, ARG_COUNT) \
TP3(T, _init_, ARG_COUNT)
-/*
- * TODO rename all the constructor macros to something clearer and
- * shorter.
- */
+/* Constructor type name */
+#define __INIT_T(T, C) TP3(T, __init__, C)
-/*
- * Constructor type name
- */
-#define CONSTRUCTOR_T(T, C) TP3(T, __init__, C)
-
-#define CONSTRUCTOR_GEN(parent, child, C) \
- CONSTRUCTOR_T(parent ## __ ## child, C)
-
-/*
- * Returns full type of constructor
- */
-#define CONSTRUCTOR_DECL(T, ...) \
- CONSTRUCTOR_T(T, VA_ARGS_NUM(__VA_ARGS__)) (T* this __VA_OPT__(,) __VA_ARGS__)
+/* Returns full type of constructor */
+#define INIT_F(T, ...) \
+ int __INIT_T(T, VA_ARGS_NUM(__VA_ARGS__)) (T* this __VA_OPT__(,) __VA_ARGS__)
-/*
- * Call the constructor of an object
- */
-#define CONSTRUCT(T, N, ...) \
- CONSTRUCTOR_T(T, VA_ARGS_NUM(__VA_ARGS__)) (N __VA_OPT__(,) __VA_ARGS__)
+/* Call the constructor of an object */
+#define INIT(T, N, ...) \
+ __INIT_T(T, VA_ARGS_NUM(__VA_ARGS__)) (N __VA_OPT__(,) __VA_ARGS__)
-/*
- * Allocate a new object on the HEAP
- */
+/* Allocate a new object on the HEAP */
#define NEW(T, N, ...) \
T* N = malloc(sizeof(*N)); \
- CONSTRUCT(T, N, __VA_ARGS__);
+ INIT(T, N, __VA_ARGS__);
-/*
- * Allocate a new object on the STACK
- */
+/* Allocate a new object on the STACK */
#define SNEW(T, N, ...) \
T N; \
- CONSTRUCT(T, & N, __VA_ARGS__);
+ INIT(T, & N, __VA_ARGS__);
/* Destructor for type */
#define FREE(T) TP(T, __free)
@@ -70,7 +52,7 @@
#define FFREE(T, N) do { FREE(T)(N); free(N); } while (0)
/* Declare destructor */
-#define FREE_DECL(T) TP(T, __free) (T* this)
+#define FREE_F(T) int TP(T, __free) (T* this)
#define DEEP_COPY(T) TP(deep_copy__, T)
#define RESOLVE(T) TP(resolve__, T)