#ifndef RT_STRUCT_H
#define RT_STRUCT_H
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <time.h>
typedef enum rts_type_tag rts_type_tag;
typedef enum rts_member_type rts_member_type;
typedef struct rts_type rts_type;
typedef struct rts_member rts_member;
enum rts_type_tag {
TAG_UINT,
TAG_SINT,
TAG_INT = TAG_SINT,
TAG_UCHAR,
TAG_SCHAR,
TAG_CHAR,
TAG_USHORT,
TAG_SSHORT,
TAG_SHORT = TAG_SSHORT,
TAG_ULONG,
TAG_SLONG,
TAG_LONG = TAG_SLONG,
TAG_ULONGLONG,
TAG_SLONGLONG,
TAG_LONGLONG = TAG_SLONGLONG,
TAG_FLOAT,
TAG_DOUBLE,
TAG_LONGDOUBLE,
TAG_TIME,
TAG_SIZE,
TAG_SSIZE,
TAG_UINT8,
TAG_INT8,
TAG_UINT16,
TAG_INT16,
TAG_UINT32,
TAG_INT32,
TAG_UINT64,
TAG_INT64,
TAG_POINTER,
TAG_STRUCT,
TAG_UNION,
NUM_TAG
};
enum rts_member_type {
MBR_NORMAL,
MBR_ARRAY,
MBR_ARRAY_NEG1,
MBR_ARRAY_ZERO,
MBR_ARRAY_NULL,
MBR_PTR,
MBR_PTR_ARRAY,
MBR_PTR_ARRAY_NEG1,
MBR_PTR_ARRAY_ZERO,
MBR_PTR_ARRAY_NULL,
};
struct rts_type {
rts_type_tag tag;
char *name;
int is_packed;
size_t alignment;
size_t size;
rts_member **members;
size_t *offsets;
};
struct rts_member {
char *name;
rts_member_type mbr_type;
int dim_count;
size_t *dim_sizes;
rts_type *type;
};
#define TYPEDEF_RTS(name, type) \
struct _align_##name { \
char c; \
type x; \
}; \
static const rts_type RTS_TYPE_##name = { \
TAG_##name, \
NULL, \
0, \
offsetof(struct _align_##name, x), \
sizeof(type), \
NULL, NULL \
} \
TYPEDEF_RTS(UINT, unsigned int);
TYPEDEF_RTS(SINT, signed int);
TYPEDEF_RTS(INT, int);
TYPEDEF_RTS(UCHAR, unsigned char);
TYPEDEF_RTS(SCHAR, signed char);
TYPEDEF_RTS(CHAR, char);
TYPEDEF_RTS(USHORT, unsigned short);
TYPEDEF_RTS(SSHORT, signed short);
TYPEDEF_RTS(SHORT, short);
TYPEDEF_RTS(ULONG, unsigned long);
TYPEDEF_RTS(SLONG, signed long);
TYPEDEF_RTS(LONG, long);
TYPEDEF_RTS(ULONGLONG, unsigned long long);
TYPEDEF_RTS(SLONGLONG, signed long long);
TYPEDEF_RTS(LONGLONG, long long);
TYPEDEF_RTS(FLOAT, float);
TYPEDEF_RTS(DOUBLE, double);
TYPEDEF_RTS(LONGDOUBLE, long double);
TYPEDEF_RTS(TIME, time_t);
TYPEDEF_RTS(SIZE, size_t);
TYPEDEF_RTS(SSIZE, ssize_t);
TYPEDEF_RTS(UINT8, uint8_t);
TYPEDEF_RTS(INT8, int8_t);
TYPEDEF_RTS(UINT16, uint16_t);
TYPEDEF_RTS(INT16, int16_t);
TYPEDEF_RTS(UINT32, uint32_t);
TYPEDEF_RTS(INT32, int32_t);
TYPEDEF_RTS(UINT64, uint64_t);
TYPEDEF_RTS(INT64, int64_t);
TYPEDEF_RTS(POINTER, void *);
#undef TYPEDEF_RTS
extern int create_rts(rts_type *type);
#endif