Reorganize build system
[qemu/aliguori.git] / variant.h
bloba07f91df8123489c690808b118b99c8e6a277937
1 #ifndef VARIANT_H
2 #define VARIANT_H
4 #include <stdint.h>
5 #include <stdbool.h>
7 #define strify_i(a) # a
8 #define strify(a) strify_i(a)
10 #define typeis(lhs, rhs) \
11 __builtin_types_compatible_p(lhs, rhs)
13 #define typename_check(lhs, rhs, name) \
14 if (typeis(lhs, rhs)) { \
15 v = strify(rhs); \
16 } else
18 typedef void (GenericEtter)(void);
20 typedef void (EtterTrampoline)(Plug *, const char *, GenericEtter *, Visitor *, Error **);
23 #include "variants-gen.h"
25 #define setter_compatible(type, fn) \
26 __builtin_types_compatible_p(typeof(fn), void (*)(Plug *, type))
28 #define getter_compatible(type, fn) \
29 __builtin_types_compatible_p(typeof(fn), type (*)(Plug *))
31 #define BUILD_ASSERT(cond) do { (void)sizeof(int[!!(cond)-1]); } while (0)
33 #define plug_add_property(plug, name, type, getter, setter) do { \
34 BUILD_ASSERT(getter_compatible(type, getter)); \
35 BUILD_ASSERT(setter_compatible(type, setter)); \
36 plug_add_property_full(plug, name, typename(type), plug_getter_lookup(typename(type)), plug_setter_lookup(typename(type))); \
37 } while (0)
39 #endif