X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ast_t.h;h=fb677084c604851ad396616d3ed56d7dac4c9075;hb=3486fabdf20fb345ac0b0098071c0cfc56005568;hp=cbd689af436566c698ba73324ea83a82d7ba3ace;hpb=9e29e9c33f6511c4583e5b8ed83194d433e82c45;p=cparser diff --git a/ast_t.h b/ast_t.h index cbd689a..fb67708 100644 --- a/ast_t.h +++ b/ast_t.h @@ -3,7 +3,7 @@ #include "ast.h" #include "symbol.h" -#include "lexer_t.h" +#include "token_t.h" #include "type.h" #include "adt/obst.h" @@ -20,8 +20,19 @@ typedef enum { EXPR_SELECT, EXPR_ARRAY_ACCESS, EXPR_SIZEOF, + + EXPR_FUNCTION, + EXPR_PRETTY_FUNCTION, + EXPR_STATEMENT } expresion_type_t; +struct context_t { + declaration_t *declarations; + compound_type_t *structs; + compound_type_t *unions; + enum_type_t *enums; +}; + struct expression_t { expresion_type_t type; type_t *datatype; @@ -39,14 +50,9 @@ struct string_literal_t { }; struct reference_expression_t { - expression_t expression; - symbol_t *symbol; - union { - variable_declaration_statement_t *variable; - method_t *method; - global_variable_t *global_variable; - method_parameter_t *method_parameter; - } r; + expression_t expression; + symbol_t *symbol; + declaration_t *declaration; }; struct call_argument_t { @@ -111,7 +117,8 @@ typedef enum { BINEXPR_SHIFTRIGHT_ASSIGN, BINEXPR_BITWISE_AND_ASSIGN, BINEXPR_BITWISE_XOR_ASSIGN, - BINEXPR_BITWISE_OR_ASSIGN + BINEXPR_BITWISE_OR_ASSIGN, + BINEXPR_COMMA } binary_expression_type_t; struct binary_expression_t { @@ -122,11 +129,11 @@ struct binary_expression_t { }; struct select_expression_t { - expression_t expression; - expression_t *compound; - symbol_t *symbol; + expression_t expression; + expression_t *compound; + symbol_t *symbol; - compound_entry_t *compound_entry; + declaration_t *compound_entry; }; struct array_access_expression_t { @@ -137,10 +144,8 @@ struct array_access_expression_t { struct sizeof_expression_t { expression_t expression; - union { - type_t *type; - expression_t *size_expression; - } v; + type_t *type; + expression_t *size_expression; }; struct conditional_expression_t { @@ -150,25 +155,49 @@ struct conditional_expression_t { expression_t *false_expression; }; -struct expression_list_element_t { - expression_t *expression; - expression_t *next; +struct statement_expression_t { + expression_t expression; + statement_t *statement; }; -struct comma_expression_t { - expression_t expression; - expression_list_element_t *expressions; +typedef enum { + STORAGE_CLASS_NONE, + STORAGE_CLASS_TYPEDEF, + STORAGE_CLASS_EXTERN, + STORAGE_CLASS_STATIC, + STORAGE_CLASS_AUTO, + STORAGE_CLASS_REGISTER, + STORAGE_CLASS_ENUM_ENTRY +} storage_class_t; + +struct declaration_t { + storage_class_t storage_class; + type_t *type; + symbol_t *symbol; + statement_t *statement; + expression_t *initializer; + source_position_t source_position; + context_t context; + + declaration_t *next; }; typedef enum { STATEMENT_INVALID, - STATEMENT_BLOCK, + STATEMENT_COMPOUND, STATEMENT_RETURN, - STATEMENT_VARIABLE_DECLARATION, + STATEMENT_DECLARATION, STATEMENT_IF, + STATEMENT_SWITCH, STATEMENT_EXPRESSION, + STATEMENT_CONTINUE, + STATEMENT_BREAK, STATEMENT_GOTO, - STATEMENT_LABEL + STATEMENT_LABEL, + STATEMENT_CASE_LABEL, + STATEMENT_WHILE, + STATEMENT_DO_WHILE, + STATEMENT_FOR } statement_type_t; struct statement_t { @@ -182,18 +211,19 @@ struct return_statement_t { expression_t *return_value; }; -struct block_statement_t { +struct compound_statement_t { statement_t statement; - statement_t *first_statement; + statement_t *statements; + context_t context; }; -struct variable_declaration_statement_t { - statement_t statement; - type_t *type; - symbol_t *symbol; +struct declaration_statement_t { + statement_t statement; + declaration_t *declarations_begin; + declaration_t *declarations_end; - int value_number; /**< filled in by semantic phase */ - int refs; + int value_number; /**< filled in by semantic phase */ + int refs; }; struct if_statement_t { @@ -203,12 +233,23 @@ struct if_statement_t { statement_t *false_statement; }; +struct switch_statement_t { + statement_t statement; + expression_t *expression; + statement_t *body; +}; + struct goto_statement_t { statement_t statement; symbol_t *label_symbol; label_statement_t *label; }; +struct case_label_statement_t { + statement_t statement; + expression_t *expression; +}; + struct label_statement_t { statement_t statement; symbol_t *symbol; @@ -219,42 +260,29 @@ struct expression_statement_t { expression_t *expression; }; -enum namespace_entry_type_t { - NAMESPACE_ENTRY_INVALID, - NAMESPACE_ENTRY_METHOD, - NAMESPACE_ENTRY_VARIABLE, -}; - -struct namespace_entry_t { - namespace_entry_type_t type; - namespace_entry_t *next; - source_position_t source_position; -}; - -struct method_parameter_t { - method_parameter_t *next; - symbol_t *symbol; - type_t *type; - int num; +struct while_statement_t { + statement_t statement; + expression_t *condition; + statement_t *body; }; -struct method_t { - namespace_entry_t namespace_entry; - symbol_t *symbol; - method_type_t *type; - method_parameter_t *parameters; - - statement_t *statement; +struct do_while_statement_t { + statement_t statement; + expression_t *condition; + statement_t *body; }; -struct global_variable_t { - namespace_entry_t namespace_entry; - symbol_t *symbol; - type_t *type; +struct for_statement_t { + statement_t statement; + expression_t *initialisation; + expression_t *condition; + expression_t *step; + statement_t *body; + context_t context; }; -struct namespace_t { - namespace_entry_t *entries; +struct translation_unit_t { + context_t context; }; static inline