X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ast_t.h;h=10a96b83ef13af1fa1b0054deecf99ccb25d9b12;hb=0e980ea5a6538fcb6ae620141404b4cb6805d6e4;hp=cb8d4e97636e790ec070e70221ee28483acc6bdb;hpb=1b580cf22ca849edc62afa24304ff0432954877a;p=cparser diff --git a/ast_t.h b/ast_t.h index cb8d4e9..10a96b8 100644 --- a/ast_t.h +++ b/ast_t.h @@ -62,15 +62,15 @@ typedef enum precedence_t { * Expression kinds. */ typedef enum expression_kind_t { - EXPR_UNKNOWN = 0, - EXPR_INVALID, + EXPR_ERROR = 1, EXPR_REFERENCE, - EXPR_REFERENCE_ENUM_VALUE, - EXPR_CONST, - EXPR_CHARACTER_CONSTANT, - EXPR_WIDE_CHARACTER_CONSTANT, + EXPR_ENUM_CONSTANT, + EXPR_LITERAL_BOOLEAN, + EXPR_LITERAL_INTEGER, + EXPR_LITERAL_FLOATINGPOINT, + EXPR_LITERAL_CHARACTER, + EXPR_LITERAL_MS_NOOP, /**< MS __noop extension */ EXPR_STRING_LITERAL, - EXPR_WIDE_STRING_LITERAL, EXPR_COMPOUND_LITERAL, EXPR_CALL, EXPR_CONDITIONAL, @@ -102,7 +102,6 @@ typedef enum expression_kind_t { EXPR_UNARY_PREFIX_INCREMENT, EXPR_UNARY_PREFIX_DECREMENT, EXPR_UNARY_CAST, - EXPR_UNARY_CAST_IMPLICIT, /**< compiler generated cast */ EXPR_UNARY_ASSUME, /**< MS __assume() */ EXPR_UNARY_DELETE, EXPR_UNARY_DELETE_ARRAY, @@ -158,73 +157,78 @@ typedef enum funcname_kind_t { } funcname_kind_t; /* convenience macros */ -#define EXPR_BINARY_CASES \ - case EXPR_BINARY_ADD: \ - case EXPR_BINARY_SUB: \ - case EXPR_BINARY_MUL: \ - case EXPR_BINARY_DIV: \ - case EXPR_BINARY_MOD: \ - case EXPR_BINARY_EQUAL: \ - case EXPR_BINARY_NOTEQUAL: \ - case EXPR_BINARY_LESS: \ - case EXPR_BINARY_LESSEQUAL: \ - case EXPR_BINARY_GREATER: \ - case EXPR_BINARY_GREATEREQUAL: \ - case EXPR_BINARY_BITWISE_AND: \ - case EXPR_BINARY_BITWISE_OR: \ - case EXPR_BINARY_BITWISE_XOR: \ - case EXPR_BINARY_LOGICAL_AND: \ - case EXPR_BINARY_LOGICAL_OR: \ - case EXPR_BINARY_SHIFTLEFT: \ - case EXPR_BINARY_SHIFTRIGHT: \ - case EXPR_BINARY_ASSIGN: \ - case EXPR_BINARY_MUL_ASSIGN: \ - case EXPR_BINARY_DIV_ASSIGN: \ - case EXPR_BINARY_MOD_ASSIGN: \ - case EXPR_BINARY_ADD_ASSIGN: \ - case EXPR_BINARY_SUB_ASSIGN: \ - case EXPR_BINARY_SHIFTLEFT_ASSIGN: \ - case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \ - case EXPR_BINARY_BITWISE_AND_ASSIGN: \ - case EXPR_BINARY_BITWISE_XOR_ASSIGN: \ - case EXPR_BINARY_BITWISE_OR_ASSIGN: \ - case EXPR_BINARY_COMMA: \ - case EXPR_BINARY_ISGREATER: \ - case EXPR_BINARY_ISGREATEREQUAL: \ - case EXPR_BINARY_ISLESS: \ - case EXPR_BINARY_ISLESSEQUAL: \ - case EXPR_BINARY_ISLESSGREATER: \ - case EXPR_BINARY_ISUNORDERED: +#define EXPR_BINARY_CASES \ + EXPR_BINARY_ADD: \ + case EXPR_BINARY_SUB: \ + case EXPR_BINARY_MUL: \ + case EXPR_BINARY_DIV: \ + case EXPR_BINARY_MOD: \ + case EXPR_BINARY_EQUAL: \ + case EXPR_BINARY_NOTEQUAL: \ + case EXPR_BINARY_LESS: \ + case EXPR_BINARY_LESSEQUAL: \ + case EXPR_BINARY_GREATER: \ + case EXPR_BINARY_GREATEREQUAL: \ + case EXPR_BINARY_BITWISE_AND: \ + case EXPR_BINARY_BITWISE_OR: \ + case EXPR_BINARY_BITWISE_XOR: \ + case EXPR_BINARY_LOGICAL_AND: \ + case EXPR_BINARY_LOGICAL_OR: \ + case EXPR_BINARY_SHIFTLEFT: \ + case EXPR_BINARY_SHIFTRIGHT: \ + case EXPR_BINARY_ASSIGN: \ + case EXPR_BINARY_MUL_ASSIGN: \ + case EXPR_BINARY_DIV_ASSIGN: \ + case EXPR_BINARY_MOD_ASSIGN: \ + case EXPR_BINARY_ADD_ASSIGN: \ + case EXPR_BINARY_SUB_ASSIGN: \ + case EXPR_BINARY_SHIFTLEFT_ASSIGN: \ + case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \ + case EXPR_BINARY_BITWISE_AND_ASSIGN: \ + case EXPR_BINARY_BITWISE_XOR_ASSIGN: \ + case EXPR_BINARY_BITWISE_OR_ASSIGN: \ + case EXPR_BINARY_COMMA: \ + case EXPR_BINARY_ISGREATER: \ + case EXPR_BINARY_ISGREATEREQUAL: \ + case EXPR_BINARY_ISLESS: \ + case EXPR_BINARY_ISLESSEQUAL: \ + case EXPR_BINARY_ISLESSGREATER: \ + case EXPR_BINARY_ISUNORDERED /** * unary expression with mandatory operand */ -#define EXPR_UNARY_CASES_MANDATORY \ - case EXPR_UNARY_NEGATE: \ - case EXPR_UNARY_PLUS: \ - case EXPR_UNARY_BITWISE_NEGATE: \ - case EXPR_UNARY_NOT: \ - case EXPR_UNARY_DEREFERENCE: \ - case EXPR_UNARY_TAKE_ADDRESS: \ - case EXPR_UNARY_POSTFIX_INCREMENT: \ - case EXPR_UNARY_POSTFIX_DECREMENT: \ - case EXPR_UNARY_PREFIX_INCREMENT: \ - case EXPR_UNARY_PREFIX_DECREMENT: \ - case EXPR_UNARY_CAST: \ - case EXPR_UNARY_CAST_IMPLICIT: \ - case EXPR_UNARY_ASSUME: \ - case EXPR_UNARY_DELETE: \ - case EXPR_UNARY_DELETE_ARRAY: +#define EXPR_UNARY_CASES_MANDATORY \ + EXPR_UNARY_NEGATE: \ + case EXPR_UNARY_PLUS: \ + case EXPR_UNARY_BITWISE_NEGATE: \ + case EXPR_UNARY_NOT: \ + case EXPR_UNARY_DEREFERENCE: \ + case EXPR_UNARY_TAKE_ADDRESS: \ + case EXPR_UNARY_POSTFIX_INCREMENT: \ + case EXPR_UNARY_POSTFIX_DECREMENT: \ + case EXPR_UNARY_PREFIX_INCREMENT: \ + case EXPR_UNARY_PREFIX_DECREMENT: \ + case EXPR_UNARY_CAST: \ + case EXPR_UNARY_ASSUME: \ + case EXPR_UNARY_DELETE: \ + case EXPR_UNARY_DELETE_ARRAY /** * unary expression with optional operand */ #define EXPR_UNARY_CASES_OPTIONAL \ - case EXPR_UNARY_THROW: \ + EXPR_UNARY_THROW -#define EXPR_UNARY_CASES \ - EXPR_UNARY_CASES_MANDATORY \ - EXPR_UNARY_CASES_OPTIONAL +#define EXPR_UNARY_CASES \ + EXPR_UNARY_CASES_MANDATORY: \ + case EXPR_UNARY_CASES_OPTIONAL + +#define EXPR_LITERAL_CASES \ + EXPR_LITERAL_BOOLEAN: \ + case EXPR_LITERAL_INTEGER: \ + case EXPR_LITERAL_FLOATINGPOINT: \ + case EXPR_LITERAL_MS_NOOP /** * The base class of every expression. @@ -237,37 +241,36 @@ struct expression_base_t { #ifndef NDEBUG bool transformed : 1; /**< Set if this expression was transformed. */ #endif + bool implicit : 1; /**< compiler generated expression. + Examples: + select into anonymous structs + implicit casts + */ }; /** - * A constant. + * integer, float and boolean constants */ -struct const_expression_t { - expression_base_t base; - union { - long long int_value; - long double float_value; - string_t character; - wide_string_t wide_character; - } v; - bool is_ms_noop; /**< True, if this constant is the result - of an microsoft __noop operator */ +struct literal_expression_t { + expression_base_t base; + string_t value; + char const *suffix; /**< Start of the suffix in value. */ + + /* ast2firm data */ + ir_tarval *target_value; }; +/** + * string and character literals + */ struct string_literal_expression_t { - expression_base_t base; - string_t value; + expression_base_t base; + string_t value; }; struct funcname_expression_t { expression_base_t base; funcname_kind_t kind; - string_t value; /**< the value once assigned. */ -}; - -struct wide_string_literal_expression_t { - expression_base_t base; - wide_string_t value; }; struct compound_literal_expression_t { @@ -323,8 +326,6 @@ struct select_expression_t { expression_base_t base; expression_t *compound; entity_t *compound_entry; - bool implicit : 1; /**< compiler generated select - (for anonymous struct/union) */ }; struct array_access_expression_t { @@ -356,7 +357,7 @@ struct offsetof_expression_t { struct va_start_expression_t { expression_base_t base; expression_t *ap; - variable_t *parameter; + expression_t *parameter; }; struct va_arg_expression_t { @@ -395,10 +396,9 @@ struct label_address_expression_t { union expression_t { expression_kind_t kind; expression_base_t base; - const_expression_t conste; + literal_expression_t literal; + string_literal_expression_t string_literal; funcname_expression_t funcname; - string_literal_expression_t string; - wide_string_literal_expression_t wide_string; compound_literal_expression_t compound_literal; builtin_constant_expression_t builtin_constant; builtin_types_compatible_expression_t builtin_types_compatible; @@ -423,7 +423,6 @@ typedef enum initializer_kind_t { INITIALIZER_VALUE, INITIALIZER_LIST, INITIALIZER_STRING, - INITIALIZER_WIDE_STRING, INITIALIZER_DESIGNATOR } initializer_kind_t; @@ -442,16 +441,6 @@ struct initializer_list_t { initializer_t *initializers[]; }; -struct initializer_string_t { - initializer_base_t base; - string_t string; -}; - -struct initializer_wide_string_t { - initializer_base_t base; - wide_string_t string; -}; - struct initializer_designator_t { initializer_base_t base; designator_t *designator; @@ -462,16 +451,21 @@ union initializer_t { initializer_base_t base; initializer_value_t value; initializer_list_t list; - initializer_string_t string; - initializer_wide_string_t wide_string; initializer_designator_t designator; }; +static inline string_literal_expression_t const *get_init_string(initializer_t const *const init) +{ + assert(init->kind == INITIALIZER_STRING); + assert(init->value.value->kind == EXPR_STRING_LITERAL); + return &init->value.value->string_literal; +} + /** * The statement kinds. */ typedef enum statement_kind_t { - STATEMENT_INVALID, + STATEMENT_ERROR = 1, STATEMENT_EMPTY, STATEMENT_COMPOUND, STATEMENT_RETURN, @@ -481,6 +475,7 @@ typedef enum statement_kind_t { STATEMENT_EXPRESSION, STATEMENT_CONTINUE, STATEMENT_BREAK, + STATEMENT_COMPUTED_GOTO, STATEMENT_GOTO, STATEMENT_LABEL, STATEMENT_CASE_LABEL, @@ -506,14 +501,6 @@ struct statement_base_t { #endif }; -struct invalid_statement_t { - statement_base_t base; -}; - -struct empty_statement_t { - statement_base_t base; -}; - struct return_statement_t { statement_base_t base; expression_t *value; /**< The return value if any. */ @@ -534,6 +521,7 @@ struct declaration_statement_t { struct if_statement_t { statement_base_t base; + scope_t scope; expression_t *condition; statement_t *true_statement; statement_t *false_statement; @@ -541,20 +529,24 @@ struct if_statement_t { struct switch_statement_t { statement_base_t base; + scope_t scope; expression_t *expression; statement_t *body; - case_label_statement_t *first_case, *last_case; /**< List of all cases, including default. */ - case_label_statement_t *default_label; /**< The default label if existent. */ - unsigned long default_proj_nr; /**< The Proj-number for the default Proj. */ + case_label_statement_t *first_case, *last_case; /**< List of all cases, including default. */ + case_label_statement_t *default_label; /**< The default label if existent. */ }; struct goto_statement_t { statement_base_t base; label_t *label; /**< The destination label. */ - expression_t *expression; /**< The expression for an assigned goto. */ goto_statement_t *next; /**< links all goto statements of a function */ }; +struct computed_goto_statement_t { + statement_base_t base; + expression_t *expression; /**< The expression for the computed goto. */ +}; + struct case_label_statement_t { statement_base_t base; expression_t *expression; /**< The case label expression, NULL for default label. */ @@ -565,6 +557,7 @@ struct case_label_statement_t { long last_case; /**< The folded value of end_range. */ bool is_bad; /**< If set marked as bad to suppress warnings. */ bool is_empty_range; /**< If set marked this as an empty range. */ + long pn; }; struct label_statement_t { @@ -581,23 +574,25 @@ struct expression_statement_t { struct while_statement_t { statement_base_t base; + scope_t scope; expression_t *condition; statement_t *body; }; struct do_while_statement_t { statement_base_t base; + scope_t scope; expression_t *condition; statement_t *body; }; struct for_statement_t { statement_base_t base; + scope_t scope; expression_t *initialisation; expression_t *condition; expression_t *step; statement_t *body; - scope_t scope; bool condition_reachable:1; bool step_reachable:1; }; @@ -635,23 +630,24 @@ struct leave_statement_t { }; union statement_t { - statement_kind_t kind; - statement_base_t base; - return_statement_t returns; - compound_statement_t compound; - declaration_statement_t declaration; - if_statement_t ifs; - switch_statement_t switchs; - goto_statement_t gotos; - case_label_statement_t case_label; - label_statement_t label; - expression_statement_t expression; - while_statement_t whiles; - do_while_statement_t do_while; - for_statement_t fors; - asm_statement_t asms; - ms_try_statement_t ms_try; - leave_statement_t leave; + statement_kind_t kind; + statement_base_t base; + return_statement_t returns; + compound_statement_t compound; + declaration_statement_t declaration; + if_statement_t ifs; + switch_statement_t switchs; + computed_goto_statement_t computed_goto; + goto_statement_t gotos; + case_label_statement_t case_label; + label_statement_t label; + expression_statement_t expression; + while_statement_t whiles; + do_while_statement_t do_while; + for_statement_t fors; + asm_statement_t asms; + ms_try_statement_t ms_try; + leave_statement_t leave; }; struct translation_unit_t { @@ -659,21 +655,18 @@ struct translation_unit_t { statement_t *global_asm; }; -static inline void *_allocate_ast(size_t size) -{ - return obstack_alloc(&ast_obstack, size); -} - -static inline bool is_invalid_expression(expression_t *expression) -{ - return expression->base.kind == EXPR_INVALID; -} - -static inline bool is_invalid_statement(statement_t *statement) +/** + * Allocate an AST node with given size and + * initialize all fields with zero. + */ +static inline void *allocate_ast_zero(size_t size) { - return statement->base.kind == STATEMENT_INVALID; + return memset(obstack_alloc(&ast_obstack, size), 0, size); } -#define allocate_ast(size) _allocate_ast(size) +/** If set, implicit casts are printed. */ +extern bool print_implicit_casts; +/** If set parenthesis are printed to indicate operator precedence. */ +extern bool print_parenthesis; #endif