AST.h


    1 #ifndef XCC_AST_H
    2 #define XCC_AST_H
    3 enum AST_type {
    4 	AST_translation_unit_single,
    5 	AST_translation_unit_pair,
    6 	AST_external_declaration_func,
    7 	AST_external_declaration_dec,
    8 	AST_function_definition,
    9 	AST_declaration_list_null,
   10 	AST_declaration_list_pair,
   11 	AST_declaration,
   12 	AST_type_specifier_void,
   13 	AST_type_specifier_int,
   14 	AST_type_specifier_char,
   15 	AST_declarator_id,
   16 	AST_declarator_pointer,
   17 	AST_declarator_paren,
   18 	AST_declarator_func,
   19 	AST_declarator_func_null,
   20 	AST_parameter_list_single,
   21 	AST_parameter_list_pair,
   22 	AST_parameter_declaration,
   23 	AST_statement_list_single,
   24 	AST_statement_list_pair,
   25 	AST_statement_null,
   26 	AST_statement_exp,
   27 	AST_statement_comp,
   28 	AST_statement_if,
   29 	AST_statement_if_else,
   30 	AST_statement_while,
   31 	AST_statement_goto,
   32 	AST_statement_label,
   33 	AST_statement_return,
   34 	AST_statement_return_null,
   35 	AST_compound_statement,
   36 	AST_expression_id,
   37 	AST_expression_int,
   38 	AST_expression_char,
   39 	AST_expression_string,
   40 	AST_expression_assign,
   41 	AST_expression_lss,
   42 	AST_expression_gtr,
   43 	AST_expression_eq,
   44 	AST_expression_neq,
   45 	AST_expression_leq,
   46 	AST_expression_geq,
   47 	AST_expression_and,
   48 	AST_expression_or,
   49 	AST_expression_add,
   50 	AST_expression_sub,
   51 	AST_expression_mult,
   52 	AST_expression_div,
   53 	AST_expression_mod,
   54 	AST_expression_unary_address,
   55 	AST_expression_unary_deref,
   56 	AST_expression_unary_plus,
   57 	AST_expression_unary_minus,
   58 	AST_expression_unary_negative,
   59 	AST_expression_func,
   60 	AST_expression_func_null,
   61 	AST_expression_paren,
   62 	AST_argument_expression_list_single,
   63 	AST_argument_expression_list_pair,
   64 	AST_IDENTIFIER,
   65 	AST_dummy
   66 };
   67 
   68 struct AST {
   69 	enum AST_type ast_type;
   70 	struct AST *parent;
   71 	struct Type *type;
   72 	int nth;
   73 	int num_child;
   74 	union {
   75 		struct AST **child;
   76 		char *id;
   77 		int value;
   78 	} u;
   79 	union {
   80 		struct {
   81 			int frame_size;
   82 			struct Symbol *arg;
   83 			struct Symbol *label;
   84 			struct String *string;
   85 		} func;
   86 		struct Symbol *local;
   87 		int arg_size;
   88 	} u2;
   89 };
   90 
   91 char *get_string_label(char *data, struct AST *ast);
   92 char *get_id_index(char *name, struct AST *ast);
   93 struct AST *search_AST_bottom(struct AST *root, enum AST_type bottom, int *n);
   94 struct AST *create_AST(enum AST_type ast_type, int argp_len, ...);
   95 #endif /* XCC_AST_H */