type.h


    1 #ifndef XCC_TYPE_H
    2 #define XCC_TYPE_H
    3 enum PrimType {
    4 	PRIM_TYPE_VOID,
    5 	PRIM_TYPE_INT,
    6 	PRIM_TYPE_CHAR
    7 };
    8 
    9 enum TypeKind {
   10 	TYPE_KIND_PRIM,
   11 	TYPE_KIND_FUNCTION,
   12 	TYPE_KIND_POINTER
   13 };
   14 
   15 struct Type {
   16 	enum TypeKind kind;
   17 	int size;
   18 	char *id;
   19 	union {
   20 		struct {
   21 			enum PrimType ptype;
   22 		} t_prim;
   23 		struct {
   24 			struct Type *type;
   25 		} t_pointer;
   26 		struct {
   27 			struct Type *ret_type;
   28 			int arg_num;
   29 			char **arg_name;
   30 			struct Type **arg_type;
   31 		} t_function;
   32 	} u;
   33 };
   34 
   35 struct Types {
   36 	struct Type *t_void;
   37 	struct Type *t_int;
   38 	struct Type *t_char;
   39 	struct Type *t_char_p;
   40 };
   41 
   42 struct Type *create_prim_type(enum PrimType ptype);
   43 struct Type *create_pointer_type(struct Type *pointedto_type);
   44 struct Type *type_analyze_declarator(struct AST *ast_decr, struct Type *type);
   45 struct Type *type_add(struct Type *type1, struct Type *type2);
   46 struct Type *type_sub(struct Type *type1, struct Type *type2);
   47 struct Type *type_check_pointer_deref(struct AST *ast, struct Type *type);
   48 void type_dump(struct Type *type);
   49 extern struct Types types;
   50 #endif /* XCC_TYPE_H */