#ifndef _PLY_TYPE_H #define _PLY_TYPE_H #include #include struct ttdef { char *name; struct type *type; }; struct tscalar { size_t size; int is_signed:1; char *name; }; struct tptr { struct type *type; }; struct tarray { struct type *type; size_t len; }; struct tmap { struct type *vtype; struct type *ktype; size_t len; }; struct tfield { char *name; struct type *type; /* function arguments */ int optional:1; }; #define tfields_foreach(_f, _fields) \ for ((_f) = (_fields); (_f)->type->ttype != T_VOID; (_f)++) struct tstruct { char *name; int packed:1; struct tfield *fields; }; struct tfunc { struct type *type; struct tfield *args; }; enum ttype { T_VOID, T_TYPEDEF, T_SCALAR, T_POINTER, T_ARRAY, T_MAP, T_STRUCT, /* T_UNION, TODO */ T_FUNC, }; struct type { enum ttype ttype; union { struct ttdef tdef; struct tscalar scalar; struct tptr ptr; struct tarray array; struct tmap map; struct tstruct sou; struct tfunc func; }; }; int type_equal (struct type *a, struct type *b); int type_compatible(struct type *a, struct type *b); void type_dump (struct type *t, const char *name, FILE *fp); void type_dump_decl(struct type *t, FILE *fp); ssize_t type_alignof(struct type *t); ssize_t type_offsetof(struct type *t, const char *field); ssize_t type_sizeof(struct type *t); int type_add(struct type *t); int type_add_list(struct type **ts); struct type *type_array_of(struct type *type, size_t len); struct type *type_map_of(struct type *ktype, struct type *vtype); struct type *type_ptr_of(struct type *type); /* built-in types */ extern struct type t_void; extern struct type t_char; extern struct type t_schar; extern struct type t_uchar; extern struct type t_short; extern struct type t_sshort; extern struct type t_ushort; extern struct type t_int; extern struct type t_sint; extern struct type t_uint; extern struct type t_long; extern struct type t_slong; extern struct type t_ulong; extern struct type t_llong; extern struct type t_sllong; extern struct type t_ullong; #endif /* _PLY_TYPE_H */