/* gramm: cmm.g -> cmm_parser.cpp */ #include "cmm_parser.hpp" OPEN_NAMESPACE /* set_1 : LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast */ const unsigned char set_1 [15] = { 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0 }; /* set_2 : LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void */ const unsigned char set_2 [15] = { 0, 0, 0, 0, 0, 0, 0, 192, 255, 1, 0, 0, 0, 0, 0 }; /* set_3 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, LITERAL_this, LITERAL_operator */ const unsigned char set_3 [15] = { 62, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 128, 0 }; /* set_4 : IDENT, SCOPE, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_register, LITERAL_const, LITERAL_volatile, LITERAL_operator */ const unsigned char set_4 [15] = { 2, 32, 0, 0, 0, 0, 0, 224, 255, 1, 0, 60, 2, 140, 0 }; /* set_5 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, SCOPE, LOG_NOT, BIT_NOT, INC, DEC, STAR, PLUS, MINUS, BIT_AND, LITERAL_this, LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast, LITERAL_typeid, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_sizeof, LITERAL_new, LITERAL_delete, LITERAL_operator, LITERAL_throw */ const unsigned char set_5 [15] = { 62, 224, 147, 1, 2, 0, 128, 255, 255, 15, 0, 0, 0, 128, 4 }; /* set_6 : LPAREN, LBRACKET, DOT, ARROW, INC, DEC */ const unsigned char set_6 [15] = { 160, 24, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* set_7 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, LITERAL_this, LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast, LITERAL_typeid, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_operator */ const unsigned char set_7 [15] = { 62, 0, 0, 0, 0, 0, 128, 255, 255, 1, 0, 0, 0, 128, 0 }; /* set_8 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, SCOPE, LOG_NOT, BIT_NOT, INC, DEC, STAR, PLUS, MINUS, BIT_AND, LITERAL_this, LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast, LITERAL_typeid, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_sizeof, LITERAL_new, LITERAL_delete, LITERAL_operator */ const unsigned char set_8 [15] = { 62, 224, 147, 1, 2, 0, 128, 255, 255, 15, 0, 0, 0, 128, 0 }; /* set_9 : IDENT, SCOPE, SEMICOLON, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_extern, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_namespace, LITERAL_using, LITERAL_asm, LITERAL_register, LITERAL_typedef, LITERAL_friend, LITERAL_inline, LITERAL_virtual, LITERAL_explicit, LITERAL_mutable, LITERAL_static, LITERAL_auto, LITERAL_const, LITERAL_volatile, LITERAL_operator */ const unsigned char set_9 [15] = { 2, 32, 0, 0, 0, 0, 16, 224, 255, 1, 0, 253, 255, 143, 0 }; /* set_10 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, LBRACE, SCOPE, LOG_NOT, BIT_NOT, INC, DEC, STAR, PLUS, MINUS, BIT_AND, SEMICOLON, LITERAL_this, LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast, LITERAL_typeid, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_sizeof, LITERAL_new, LITERAL_delete, LITERAL_case, LITERAL_default, LITERAL_if, LITERAL_switch, LITERAL_while, LITERAL_do, LITERAL_for, LITERAL_break, LITERAL_continue, LITERAL_return, LITERAL_goto, LITERAL_extern, LITERAL_try, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_namespace, LITERAL_using, LITERAL_asm, LITERAL_register, LITERAL_typedef, LITERAL_friend, LITERAL_inline, LITERAL_virtual, LITERAL_explicit, LITERAL_mutable, LITERAL_static, LITERAL_auto, LITERAL_const, LITERAL_volatile, LITERAL_operator, LITERAL_throw */ const unsigned char set_10 [15] = { 62, 226, 147, 1, 2, 0, 144, 255, 255, 127, 255, 255, 255, 143, 4 }; /* set_11 : IDENT, SCOPE, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_extern, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_register, LITERAL_typedef, LITERAL_friend, LITERAL_inline, LITERAL_virtual, LITERAL_explicit, LITERAL_mutable, LITERAL_static, LITERAL_auto, LITERAL_const, LITERAL_volatile, LITERAL_operator */ const unsigned char set_11 [15] = { 2, 32, 0, 0, 0, 0, 0, 224, 255, 1, 0, 61, 254, 143, 0 }; /* set_12 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, SCOPE, LOG_NOT, BIT_NOT, INC, DEC, STAR, PLUS, MINUS, BIT_AND, LITERAL_this, LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast, LITERAL_typeid, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_sizeof, LITERAL_new, LITERAL_delete, LITERAL_extern, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_register, LITERAL_typedef, LITERAL_friend, LITERAL_inline, LITERAL_virtual, LITERAL_explicit, LITERAL_mutable, LITERAL_static, LITERAL_auto, LITERAL_const, LITERAL_volatile, LITERAL_operator, LITERAL_throw */ const unsigned char set_12 [15] = { 62, 224, 147, 1, 2, 0, 128, 255, 255, 15, 0, 61, 254, 143, 4 }; /* set_13 : IDENT, LPAREN, SCOPE, BIT_NOT, STAR, BIT_AND, SEMICOLON, LITERAL_template, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_extern, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_namespace, LITERAL_using, LITERAL_asm, LITERAL_register, LITERAL_typedef, LITERAL_friend, LITERAL_inline, LITERAL_virtual, LITERAL_explicit, LITERAL_mutable, LITERAL_static, LITERAL_auto, LITERAL_const, LITERAL_volatile, LITERAL_operator, LITERAL_export */ const unsigned char set_13 [15] = { 34, 160, 16, 0, 2, 0, 80, 224, 255, 1, 0, 253, 255, 143, 1 }; /* set_14 : IDENT, LPAREN, SCOPE, BIT_NOT, STAR, BIT_AND, LITERAL_inline, LITERAL_virtual, LITERAL_explicit, LITERAL_operator */ const unsigned char set_14 [15] = { 34, 160, 16, 0, 2, 0, 0, 0, 0, 0, 0, 0, 112, 128, 0 }; /* set_15 : IDENT, LPAREN, SCOPE, STAR, BIT_AND, LITERAL_operator */ const unsigned char set_15 [15] = { 34, 32, 16, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0 }; /* set_16 : LITERAL_extern, LITERAL_register, LITERAL_typedef, LITERAL_friend, LITERAL_inline, LITERAL_virtual, LITERAL_explicit, LITERAL_mutable, LITERAL_static, LITERAL_auto, LITERAL_const, LITERAL_volatile */ const unsigned char set_16 [15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 254, 15, 0 }; /* set_17 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, SCOPE, LOG_NOT, BIT_NOT, INC, DEC, STAR, PLUS, MINUS, BIT_AND, DOTS, LITERAL_this, LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast, LITERAL_typeid, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_sizeof, LITERAL_new, LITERAL_delete, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_register, LITERAL_const, LITERAL_volatile, LITERAL_operator, LITERAL_throw */ const unsigned char set_17 [15] = { 62, 224, 147, 1, 2, 0, 160, 255, 255, 15, 0, 60, 2, 140, 4 }; /* set_18 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, LBRACE, SCOPE, LOG_NOT, BIT_NOT, INC, DEC, STAR, PLUS, MINUS, BIT_AND, LITERAL_this, LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast, LITERAL_typeid, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_sizeof, LITERAL_new, LITERAL_delete, LITERAL_operator, LITERAL_throw */ const unsigned char set_18 [15] = { 62, 226, 147, 1, 2, 0, 128, 255, 255, 15, 0, 0, 0, 128, 4 }; /* set_19 : IDENT, LPAREN, SCOPE, BIT_NOT, STAR, BIT_AND, SEMICOLON, LITERAL_template, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_extern, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_using, LITERAL_register, LITERAL_typedef, LITERAL_friend, LITERAL_inline, LITERAL_virtual, LITERAL_explicit, LITERAL_mutable, LITERAL_static, LITERAL_auto, LITERAL_const, LITERAL_volatile, LITERAL_private, LITERAL_protected, LITERAL_public, LITERAL_operator, LITERAL_export */ const unsigned char set_19 [15] = { 34, 160, 16, 0, 2, 0, 80, 224, 255, 1, 0, 189, 254, 255, 1 }; /* set_20 : IDENT, SCOPE, LITERAL_template, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_register, LITERAL_const, LITERAL_volatile, LITERAL_operator */ const unsigned char set_20 [15] = { 2, 32, 0, 0, 0, 0, 64, 224, 255, 1, 0, 60, 2, 140, 0 }; /* set_21 : IDENT, NUMBER, CHAR_LITERAL, STRING_LITERAL, LPAREN, SCOPE, LOG_NOT, BIT_NOT, INC, DEC, STAR, PLUS, MINUS, BIT_AND, LITERAL_this, LITERAL_dynamic_cast, LITERAL_static_cast, LITERAL_const_cast, LITERAL_reinterpret_cast, LITERAL_typeid, LITERAL_typename, LITERAL_signed, LITERAL_unsigned, LITERAL_short, LITERAL_long, LITERAL_bool, LITERAL_char, LITERAL_wchar_t, LITERAL_int, LITERAL_float, LITERAL_double, LITERAL_void, LITERAL_sizeof, LITERAL_new, LITERAL_delete, LITERAL_enum, LITERAL_class, LITERAL_struct, LITERAL_union, LITERAL_register, LITERAL_const, LITERAL_volatile, LITERAL_operator */ const unsigned char set_21 [15] = { 62, 224, 147, 1, 2, 0, 128, 255, 255, 15, 0, 60, 2, 140, 0 }; /* CmmParser */ string CmmParser::identifier () { return recall_identifier (); } string CmmParser::numeric_literal () { return recall_numeric_literal (); } string CmmParser::char_literal () { return recall_char_literal (); } string CmmParser::string_literal () { return recall_string_literal (); } void CmmParser::base_subst (CmmName * p_result) { assert (p_result != NULL); p_result->location [0] = getLocation (); p_result->id = identifier (); } void CmmParser::base_name (CmmName * p_result) { assert (p_result != NULL); if (symbol (LITERAL_operator)) p_result->spec = special_function (); else if (symbol (IDENT)) base_subst (p_result); else stop (); } void CmmParser::base_args (CmmName * p_result) { assert (p_result != NULL); if ((symbol (LESS)) && is_template_arg (p_result)) p_result->template_args = template_arg_list (); } CmmContName * CmmParser::cont_item () { CmmContName * result = new CmmContName; result->location [0] = getLocation (); match (SCOPE); cont_name (result); add_name (result); cont_args (result); return result; } void CmmParser::cont_subst (CmmContName * p_result) { assert (p_result != NULL); p_result->location [1] = getLocation (); p_result->id = identifier (); } void CmmParser::cont_name (CmmContName * p_result) { assert (p_result != NULL); if (symbol (BIT_NOT)) { p_result->location [2] = getLocation (); match (BIT_NOT); p_result->a_destructor = true; } else if (symbol (LITERAL_template)) { p_result->location [3] = getLocation (); match (LITERAL_template); p_result->a_template = true; } if (symbol (LITERAL_operator)) p_result->spec = special_function (); else if (symbol (IDENT)) cont_subst (p_result); else stop (); } void CmmParser::cont_args (CmmContName * p_result) { assert (p_result != NULL); if ((symbol (LESS)) && is_cont_template_arg (p_result)) p_result->template_args = template_arg_list (); } void CmmParser::compound_name (CmmName * p_result) { assert (p_result != NULL); open_name (p_result); base_name (p_result); start_name (p_result); base_args (p_result); while (symbol (SCOPE)) { p_result->add (cont_item ()); } close_name (p_result); } void CmmParser::simple_name (CmmName * p_result) { assert (p_result != NULL); open_name (p_result); base_name (p_result); start_name (p_result); close_name (p_result); } void CmmParser::global_mark (CmmName * p_result) { assert (p_result != NULL); if (symbol (SCOPE)) { p_result->location [1] = getLocation (); match (SCOPE); p_result->a_global = true; } } CmmName * CmmParser::qualified_name () { CmmName * result = new CmmName; compound_name (result); return result; } CmmName * CmmParser::global_name () { CmmName * result = new CmmName; global_mark (result); compound_name (result); return result; } CmmName * CmmParser::global_declaring_name () { CmmName * result = new CmmName; global_mark (result); compound_name (result); check_type (result); return result; } CmmName * CmmParser::global_type_name () { CmmName * result = new CmmName; open_type_name (result); global_mark (result); compound_name (result); close_type_name (result); check_type (result); return result; } CmmName * CmmParser::simple_new_name () { CmmName * result = new CmmName; open_new_name (result); simple_name (result); close_new_name (result); return result; } CmmName * CmmParser::global_new_name () { CmmName * result = new CmmName; open_new_name (result); global_mark (result); compound_name (result); close_new_name (result); return result; } CmmName * CmmParser::id_expr () { CmmName * result = NULL; result = qualified_name (); return result; } CmmExpr * CmmParser::primary_expr () { CmmExpr * result = NULL; if (symbol (NUMBER)) result = numeric_literal_expr (); else if (symbol (CHAR_LITERAL)) result = char_literal_expr (); else if (symbol (STRING_LITERAL)) result = string_literal_expr (); else if (symbol (LITERAL_this)) result = this_expr (); else if (symbol (LPAREN)) result = subexpr_expr (); else if (symbol (IDENT) || symbol (LITERAL_operator)) result = id_expr (); else stop (); return result; } CmmNumValue * CmmParser::numeric_literal_expr () { CmmNumValue * result = new CmmNumValue; result->location [0] = getLocation (); result->value = numeric_literal (); return result; } CmmCharValue * CmmParser::char_literal_expr () { CmmCharValue * result = new CmmCharValue; result->location [0] = getLocation (); result->value = char_literal (); return result; } CmmStringCont * CmmParser::string_literal_cont () { CmmStringCont * result = new CmmStringCont; result->location [0] = getLocation (); result->value = string_literal (); return result; } CmmStringValue * CmmParser::string_literal_expr () { CmmStringValue * result = new CmmStringValue; result->location [0] = getLocation (); result->value = string_literal (); while (symbol (STRING_LITERAL)) { result->add (string_literal_cont ()); } return result; } CmmThisExpr * CmmParser::this_expr () { CmmThisExpr * result = new CmmThisExpr; result->location [0] = getLocation (); match (LITERAL_this); return result; } CmmSubexprExpr * CmmParser::subexpr_expr () { CmmSubexprExpr * result = new CmmSubexprExpr; result->location [0] = getLocation (); match (LPAREN); result->param = expr (); result->location [1] = getLocation (); match (RPAREN); return result; } CmmExpr * CmmParser::postfix_start () { CmmExpr * result = NULL; if (test (set_1)) result = modern_cast_expr (); else if (symbol (LITERAL_typeid)) result = typeid_expr (); else if (symbol (LITERAL_typename)) result = typename_expr (); else if (test (set_2)) result = type_change_expr (); else if (test (set_3)) result = primary_expr (); else stop (); return result; } CmmModernCastExpr * CmmParser::modern_cast_expr () { CmmModernCastExpr * result = new CmmModernCastExpr; if (symbol (LITERAL_dynamic_cast)) { result->location [0] = getLocation (); match (LITERAL_dynamic_cast); result->kind = DynamicCast; } else if (symbol (LITERAL_static_cast)) { result->location [1] = getLocation (); match (LITERAL_static_cast); result->kind = StaticCast; } else if (symbol (LITERAL_const_cast)) { result->location [2] = getLocation (); match (LITERAL_const_cast); result->kind = ConstCast; } else if (symbol (LITERAL_reinterpret_cast)) { result->location [3] = getLocation (); match (LITERAL_reinterpret_cast); result->kind = ReinterpreterCast; } else stop (); result->location [4] = getLocation (); match (LESS); result->type = type_id (); result->location [5] = getLocation (); match (GREATER); result->location [6] = getLocation (); match (LPAREN); result->param = expr (); result->location [7] = getLocation (); match (RPAREN); return result; } CmmTypeidExpr * CmmParser::typeid_expr () { CmmTypeidExpr * result = new CmmTypeidExpr; result->location [0] = getLocation (); match (LITERAL_typeid); result->location [1] = getLocation (); match (LPAREN); if ((test (set_4)) && is_type ()) result->param1 = type_id (); else if (test (set_5)) result->param2 = expr (); else stop (); result->location [2] = getLocation (); match (RPAREN); return result; } CmmTypenameExpr * CmmParser::typename_expr () { CmmTypenameExpr * result = new CmmTypenameExpr; result->location [0] = getLocation (); match (LITERAL_typename); result->name = global_type_name (); result->location [1] = getLocation (); match (LPAREN); result->list = expr_list (); result->location [2] = getLocation (); match (RPAREN); return result; } CmmTypechangeExpr * CmmParser::type_change_expr () { CmmTypechangeExpr * result = new CmmTypechangeExpr; if (symbol (LITERAL_signed)) { result->location [0] = getLocation (); match (LITERAL_signed); result->a_signed = true; } else if (symbol (LITERAL_unsigned)) { result->location [1] = getLocation (); match (LITERAL_unsigned); result->a_unsigned = true; } else if (symbol (LITERAL_short)) { result->location [2] = getLocation (); match (LITERAL_short); result->a_short = true; } else if (symbol (LITERAL_long)) { result->location [3] = getLocation (); match (LITERAL_long); result->a_long = true; if (symbol (LITERAL_long)) { result->location [4] = getLocation (); match (LITERAL_long); result->a_long_long = true; } } else if (symbol (LITERAL_bool)) { result->location [5] = getLocation (); match (LITERAL_bool); result->a_bool = true; } else if (symbol (LITERAL_char)) { result->location [6] = getLocation (); match (LITERAL_char); result->a_char = true; } else if (symbol (LITERAL_wchar_t)) { result->location [7] = getLocation (); match (LITERAL_wchar_t); result->a_wchar = true; } else if (symbol (LITERAL_int)) { result->location [8] = getLocation (); match (LITERAL_int); result->a_int = true; } else if (symbol (LITERAL_float)) { result->location [9] = getLocation (); match (LITERAL_float); result->a_float = true; } else if (symbol (LITERAL_double)) { result->location [10] = getLocation (); match (LITERAL_double); result->a_double = true; } else if (symbol (LITERAL_void)) { result->location [11] = getLocation (); match (LITERAL_void); result->a_void = true; } else stop (); result->location [12] = getLocation (); match (LPAREN); result->list = expr_list (); result->location [13] = getLocation (); match (RPAREN); return result; } CmmExpr * CmmParser::postfix_expr () { CmmExpr * result = NULL; result = postfix_start (); while (test (set_6)) { if (symbol (LBRACKET)) result = index_expr (result); else if (symbol (LPAREN)) result = call_expr (result); else if (symbol (DOT)) result = field_expr (result); else if (symbol (ARROW)) result = ptr_field_expr (result); else if (symbol (INC)) result = post_inc_expr (result); else if (symbol (DEC)) result = post_dec_expr (result); } return result; } CmmIndexExpr * CmmParser::index_expr (CmmExpr * p_store) { CmmIndexExpr * result = new CmmIndexExpr; result->left = p_store; result->location [0] = getLocation (); match (LBRACKET); result->right = expr (); result->location [1] = getLocation (); match (RBRACKET); return result; } CmmCallExpr * CmmParser::call_expr (CmmExpr * p_store) { CmmCallExpr * result = new CmmCallExpr; result->param = p_store; result->location [0] = getLocation (); match (LPAREN); result->list = expr_list (); result->location [1] = getLocation (); match (RPAREN); return result; } CmmFieldExpr * CmmParser::field_expr (CmmExpr * p_store) { CmmFieldExpr * result = new CmmFieldExpr; result->param = p_store; result->location [0] = getLocation (); match (DOT); if (symbol (BIT_NOT)) { result->location [1] = getLocation (); match (BIT_NOT); result->destructor_name = true; } else if (symbol (LITERAL_template)) { result->location [2] = getLocation (); match (LITERAL_template); result->template_name = true; } open_field_template (result); result->name = id_expr (); close_field_template (result); return result; } CmmPtrFieldExpr * CmmParser::ptr_field_expr (CmmExpr * p_store) { CmmPtrFieldExpr * result = new CmmPtrFieldExpr; result->param = p_store; result->location [0] = getLocation (); match (ARROW); if (symbol (BIT_NOT)) { result->location [1] = getLocation (); match (BIT_NOT); result->destructor_name = true; } else if (symbol (LITERAL_template)) { result->location [2] = getLocation (); match (LITERAL_template); result->template_name = true; } open_ptr_field_template (result); result->name = id_expr (); close_ptr_field_template (result); return result; } CmmPostIncExpr * CmmParser::post_inc_expr (CmmExpr * p_store) { CmmPostIncExpr * result = new CmmPostIncExpr; result->param = p_store; result->location [0] = getLocation (); match (INC); return result; } CmmPostDecExpr * CmmParser::post_dec_expr (CmmExpr * p_store) { CmmPostDecExpr * result = new CmmPostDecExpr; result->param = p_store; result->location [0] = getLocation (); match (DEC); return result; } CmmExprList * CmmParser::expr_list () { CmmExprList * result = new CmmExprList; if (test (set_5)) { result->add (assignment_expr ()); while (symbol (COMMA)) { result->location [0] = getLocation (); match (COMMA); result->add (assignment_expr ()); } } return result; } CmmExpr * CmmParser::unary_expr () { CmmExpr * result = NULL; if (symbol (INC)) result = inc_expr (); else if (symbol (DEC)) result = dec_expr (); else if (symbol (STAR)) result = deref_expr (); else if (symbol (BIT_AND)) result = addr_expr (); else if (symbol (PLUS)) result = plus_expr (); else if (symbol (MINUS)) result = minus_expr (); else if (symbol (BIT_NOT)) result = bit_not_expr (); else if (symbol (LOG_NOT)) result = log_not_expr (); else if (symbol (SCOPE)) result = scope_expr (); else if (symbol (LITERAL_sizeof)) result = sizeof_expr (); else if (symbol (LITERAL_new)) result = allocation_expr (); else if (symbol (LITERAL_delete)) result = deallocation_expr (); else if (test (set_7)) result = postfix_expr (); else stop (); return result; } CmmUnaryExpr * CmmParser::inc_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (INC); result->kind = IncExp; result->param = cast_expr (); return result; } CmmUnaryExpr * CmmParser::dec_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (DEC); result->kind = DecExp; result->param = cast_expr (); return result; } CmmUnaryExpr * CmmParser::deref_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (STAR); result->kind = DerexExp; result->param = cast_expr (); return result; } CmmUnaryExpr * CmmParser::addr_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (BIT_AND); result->kind = AddrExp; result->param = cast_expr (); return result; } CmmUnaryExpr * CmmParser::plus_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (PLUS); result->kind = PlusExp; result->param = cast_expr (); return result; } CmmUnaryExpr * CmmParser::minus_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (MINUS); result->kind = MinusExp; result->param = cast_expr (); return result; } CmmUnaryExpr * CmmParser::bit_not_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (BIT_NOT); result->kind = BitNotExp; result->param = cast_expr (); return result; } CmmUnaryExpr * CmmParser::log_not_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (LOG_NOT); result->kind = LogNotExp; result->param = cast_expr (); return result; } CmmUnaryExpr * CmmParser::scope_expr () { CmmUnaryExpr * result = new CmmUnaryExpr; result->location [0] = getLocation (); match (SCOPE); result->kind = ScopeExp; result->param = cast_expr (); return result; } CmmSizeofExp * CmmParser::sizeof_expr () { CmmSizeofExp * result = new CmmSizeofExp; result->location [0] = getLocation (); match (LITERAL_sizeof); if ((symbol (LPAREN)) && is_type_in_parenthesis ()) { result->location [1] = getLocation (); match (LPAREN); result->param1 = type_id (); result->location [2] = getLocation (); match (RPAREN); } else if (test (set_8)) result->param2 = unary_expr (); else stop (); return result; } CmmNewExpr * CmmParser::allocation_expr () { CmmNewExpr * result = new CmmNewExpr; result->location [0] = getLocation (); match (LITERAL_new); if ((symbol (LPAREN)) && is_parenthesis_and_expression ()) result->placement = new_placement (); if (test (set_4)) result->type1 = new_type_id (); else if (symbol (LPAREN)) { result->location [1] = getLocation (); match (LPAREN); result->type2 = type_id (); result->location [2] = getLocation (); match (RPAREN); } else stop (); if (symbol (LPAREN)) { result->location [3] = getLocation (); match (LPAREN); result->init = expr_list (); result->location [4] = getLocation (); match (RPAREN); } return result; } CmmNewPlacement * CmmParser::new_placement () { CmmNewPlacement * result = new CmmNewPlacement; result->location [0] = getLocation (); match (LPAREN); result->list = expr_list (); result->location [1] = getLocation (); match (RPAREN); return result; } CmmNewTypeId * CmmParser::new_type_id () { CmmNewTypeId * result = new CmmNewTypeId; result->spec = type_specifiers (); result->ptr = ptr_specifier_list (); while (symbol (LBRACKET)) { result->add (allocation_array_limit ()); } return result; } CmmNewArrayLimit * CmmParser::allocation_array_limit () { CmmNewArrayLimit * result = new CmmNewArrayLimit; result->location [0] = getLocation (); match (LBRACKET); result->value = expr (); result->location [1] = getLocation (); match (RBRACKET); return result; } CmmDeleteExpr * CmmParser::deallocation_expr () { CmmDeleteExpr * result = new CmmDeleteExpr; result->location [0] = getLocation (); match (LITERAL_delete); if (symbol (LBRACKET)) { result->location [1] = getLocation (); match (LBRACKET); result->location [2] = getLocation (); match (RBRACKET); result->a_array = true; } result->param = cast_expr (); return result; } CmmExpr * CmmParser::cast_expr () { CmmExpr * result = NULL; if ((symbol (LPAREN)) && is_type_in_parenthesis ()) result = cast_formula (); else if (test (set_8)) result = unary_expr (); else stop (); return result; } CmmCastFormula * CmmParser::cast_formula () { CmmCastFormula * result = new CmmCastFormula; result->location [0] = getLocation (); match (LPAREN); result->type = type_id (); result->location [1] = getLocation (); match (RPAREN); result->param = cast_expr (); return result; } CmmExpr * CmmParser::pm_expr () { CmmExpr * result; result = cast_expr (); bool done = false; while (! done) { if (symbol (DOT_STAR)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = DotMemberExp; item->left = result; item->location [0] = getLocation (); next (); item->right = cast_expr (); result = item; } else if (symbol (ARROW_STAR)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = ArrowMemverExp; item->left = result; item->location [0] = getLocation (); next (); item->right = cast_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::multiplicative_expr () { CmmExpr * result; result = pm_expr (); bool done = false; while (! done) { if (symbol (STAR)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = MulExp; item->left = result; item->location [0] = getLocation (); next (); item->right = pm_expr (); result = item; } else if (symbol (SLASH)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = DivExp; item->left = result; item->location [0] = getLocation (); next (); item->right = pm_expr (); result = item; } else if (symbol (MOD)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = ModExp; item->left = result; item->location [0] = getLocation (); next (); item->right = pm_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::additive_expr () { CmmExpr * result; result = multiplicative_expr (); bool done = false; while (! done) { if (symbol (PLUS)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = AddExp; item->left = result; item->location [0] = getLocation (); next (); item->right = multiplicative_expr (); result = item; } else if (symbol (MINUS)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = SubExp; item->left = result; item->location [0] = getLocation (); next (); item->right = multiplicative_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::shift_expr () { CmmExpr * result; result = additive_expr (); bool done = false; while (! done) { if (symbol (SHL)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = ShlExp; item->left = result; item->location [0] = getLocation (); next (); item->right = additive_expr (); result = item; } else if (symbol (SHR)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = ShrExp; item->left = result; item->location [0] = getLocation (); next (); item->right = additive_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::relational_expr () { CmmExpr * result; result = shift_expr (); bool done = false; while (! done) { if (symbol (LESS)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = LtExp; item->left = result; item->location [0] = getLocation (); next (); item->right = shift_expr (); result = item; } else if (symbol (GREATER)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = GtExp; item->left = result; item->location [0] = getLocation (); next (); item->right = shift_expr (); result = item; } else if (symbol (LESS_OR_EQUAL)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = LeExp; item->left = result; item->location [0] = getLocation (); next (); item->right = shift_expr (); result = item; } else if (symbol (GREATER_OR_EQUAL)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = GeExp; item->left = result; item->location [0] = getLocation (); next (); item->right = shift_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::equality_expr () { CmmExpr * result; result = relational_expr (); bool done = false; while (! done) { if (symbol (EQUAL)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = EqExp; item->left = result; item->location [0] = getLocation (); next (); item->right = relational_expr (); result = item; } else if (symbol (UNEQUAL)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = NeExp; item->left = result; item->location [0] = getLocation (); next (); item->right = relational_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::and_expr () { CmmExpr * result; result = equality_expr (); bool done = false; while (! done) { if (symbol (BIT_AND)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = BitAndExp; item->left = result; item->location [0] = getLocation (); next (); item->right = equality_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::exclusive_or_expr () { CmmExpr * result; result = and_expr (); bool done = false; while (! done) { if (symbol (BIT_XOR)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = BitXorExp; item->left = result; item->location [0] = getLocation (); next (); item->right = and_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::inclusive_or_expr () { CmmExpr * result; result = exclusive_or_expr (); bool done = false; while (! done) { if (symbol (BIT_OR)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = BitOrExp; item->left = result; item->location [0] = getLocation (); next (); item->right = exclusive_or_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::logical_and_expr () { CmmExpr * result; result = inclusive_or_expr (); bool done = false; while (! done) { if (symbol (LOG_AND)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = LogAndExp; item->left = result; item->location [0] = getLocation (); next (); item->right = inclusive_or_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::logical_or_expr () { CmmExpr * result; result = logical_and_expr (); bool done = false; while (! done) { if (symbol (LOG_OR)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = LogOrExp; item->left = result; item->location [0] = getLocation (); next (); item->right = logical_and_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::conditional_expr () { CmmExpr * result = NULL; result = logical_or_expr (); if (symbol (QUESTION)) result = conditional_cont_expr (result); return result; } CmmCondExpr * CmmParser::conditional_cont_expr (CmmExpr * p_store) { CmmCondExpr * result = new CmmCondExpr; result->cond_expr = p_store; result->location [0] = getLocation (); match (QUESTION); result->then_expr = expr (); result->location [1] = getLocation (); match (COLON); result->else_expr = conditional_expr (); return result; } CmmExpr * CmmParser::assignment_expr () { CmmExpr * result = NULL; if (symbol (LITERAL_throw)) result = throw_expr (); else if (test (set_8)) result = simple_assignment_expr (); else stop (); return result; } CmmExpr * CmmParser::simple_assignment_expr () { CmmExpr * result; result = conditional_expr (); bool done = false; while (! done) { if (symbol (ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = AssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (PLUS_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = AddAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (MINUS_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = SubAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (MUL_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = MulAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (DIV_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = DivAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (MOD_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = ModAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (SHL_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = ShlAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (SHR_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = ShrAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (BIT_AND_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = AndAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (BIT_XOR_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = XorAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else if (symbol (BIT_OR_ASSIGN)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = OrAssignExp; item->left = result; item->location [0] = getLocation (); next (); item->right = conditional_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::expr () { CmmExpr * result; result = assignment_expr (); bool done = false; while (! done) { if (symbol (COMMA)) { CmmBinaryExpr * item = new CmmBinaryExpr; item->kind = CommaExp; item->left = result; item->location [0] = getLocation (); next (); item->right = assignment_expr (); result = item; } else done = true; } return result; } CmmExpr * CmmParser::const_expr () { CmmExpr * result = NULL; result = conditional_expr (); return result; } CmmStat * CmmParser::stat () { CmmStat * result = NULL; if ((symbol (IDENT)) && condition_1 ()) result = labeled_stat (); else if ((test (set_9)) && is_declaration ()) result = declaration_stat (); else if (test (set_5)) result = expression_stat (); else if (symbol (LBRACE)) result = compound_stat (); else if (symbol (LITERAL_case)) result = case_stat (); else if (symbol (LITERAL_default)) result = default_stat (); else if (symbol (LITERAL_if)) result = if_stat (); else if (symbol (LITERAL_switch)) result = switch_stat (); else if (symbol (LITERAL_while)) result = while_stat (); else if (symbol (LITERAL_do)) result = do_stat (); else if (symbol (LITERAL_for)) result = for_stat (); else if (symbol (LITERAL_break)) result = break_stat (); else if (symbol (LITERAL_continue)) result = continue_stat (); else if (symbol (LITERAL_return)) result = return_stat (); else if (symbol (LITERAL_goto)) result = goto_stat (); else if (symbol (LITERAL_try)) result = try_stat (); else if (symbol (SEMICOLON)) result = empty_stat (); else stop (); return result; } CmmStat * CmmParser::inner_stat () { CmmStat * result = NULL; result = stat (); return result; } CmmStat * CmmParser::tail_stat () { CmmStat * result = NULL; result = stat (); return result; } CmmStatSect * CmmParser::stat_list () { CmmStatSect * result = new CmmStatSect; while (test (set_10)) { result->add (stat ()); } return result; } CmmStatSect * CmmParser::inner_stat_list () { CmmStatSect * result = NULL; result = stat_list (); return result; } CmmDeclStat * CmmParser::declaration_stat () { CmmDeclStat * result = new CmmDeclStat; result->decl = block_declaration (); return result; } CmmLabeledStat * CmmParser::labeled_stat () { CmmLabeledStat * result = new CmmLabeledStat; result->location [0] = getLocation (); result->lab = identifier (); result->location [1] = getLocation (); match (COLON); result->body = stat (); return result; } CmmCaseStat * CmmParser::case_stat () { CmmCaseStat * result = new CmmCaseStat; result->location [0] = getLocation (); match (LITERAL_case); result->case_expr = expr (); result->location [1] = getLocation (); match (COLON); result->body = stat (); return result; } CmmDefaultStat * CmmParser::default_stat () { CmmDefaultStat * result = new CmmDefaultStat; result->location [0] = getLocation (); match (LITERAL_default); result->location [1] = getLocation (); match (COLON); result->body = stat (); return result; } CmmExprStat * CmmParser::expression_stat () { CmmExprStat * result = new CmmExprStat; result->inner_expr = expr (); result->location [0] = getLocation (); match (SEMICOLON); return result; } CmmEmptyStat * CmmParser::empty_stat () { CmmEmptyStat * result = new CmmEmptyStat; result->location [0] = getLocation (); match (SEMICOLON); return result; } CmmCompoundStat * CmmParser::compound_stat () { CmmCompoundStat * result = new CmmCompoundStat; open_block (); result->location [0] = getLocation (); match (LBRACE); read_block (); result->body = inner_stat_list (); result->location [1] = getLocation (); match (RBRACE); close_block (); return result; } CmmCondition * CmmParser::condition () { CmmCondition * result = new CmmCondition; if ((test (set_11)) && is_declaration ()) result->cond_decl = simple_declaration_content (); else if (test (set_5)) result->cond_expr = expr (); else stop (); return result; } CmmCondition * CmmParser::for_condition () { CmmCondition * result = new CmmCondition; if ((test (set_11)) && condition_2 ()) result->cond_decl = simple_declaration_content (); else if (test (set_5)) result->cond_expr = expr (); else stop (); return result; } CmmIfStat * CmmParser::if_stat () { CmmIfStat * result = new CmmIfStat; open_block (); result->location [0] = getLocation (); match (LITERAL_if); result->location [1] = getLocation (); match (LPAREN); result->cond = condition (); result->location [2] = getLocation (); match (RPAREN); result->then_stat = inner_stat (); if (symbol (LITERAL_else)) { result->location [3] = getLocation (); match (LITERAL_else); result->else_stat = tail_stat (); } close_block (); return result; } CmmSwitchStat * CmmParser::switch_stat () { CmmSwitchStat * result = new CmmSwitchStat; open_block (); result->location [0] = getLocation (); match (LITERAL_switch); result->location [1] = getLocation (); match (LPAREN); result->cond = condition (); result->location [2] = getLocation (); match (RPAREN); result->body = inner_stat (); close_block (); return result; } CmmWhileStat * CmmParser::while_stat () { CmmWhileStat * result = new CmmWhileStat; open_block (); result->location [0] = getLocation (); match (LITERAL_while); result->location [1] = getLocation (); match (LPAREN); result->cond = condition (); result->location [2] = getLocation (); match (RPAREN); result->body = inner_stat (); close_block (); return result; } CmmDoStat * CmmParser::do_stat () { CmmDoStat * result = new CmmDoStat; open_block (); result->location [0] = getLocation (); match (LITERAL_do); result->body = inner_stat (); result->location [1] = getLocation (); match (LITERAL_while); result->location [2] = getLocation (); match (LPAREN); result->cond_expr = expr (); result->location [3] = getLocation (); match (RPAREN); result->location [4] = getLocation (); match (SEMICOLON); close_block (); return result; } CmmForStat * CmmParser::for_stat () { CmmForStat * result = new CmmForStat; open_block (); result->location [0] = getLocation (); match (LITERAL_for); result->location [1] = getLocation (); match (LPAREN); if (test (set_12)) result->from_expr = for_condition (); result->location [2] = getLocation (); match (SEMICOLON); if (test (set_5)) result->to_expr = expr (); result->location [3] = getLocation (); match (SEMICOLON); if (test (set_5)) result->cond_expr = expr (); result->location [4] = getLocation (); match (RPAREN); result->body = inner_stat (); close_block (); return result; } CmmBreakStat * CmmParser::break_stat () { CmmBreakStat * result = new CmmBreakStat; result->location [0] = getLocation (); match (LITERAL_break); result->location [1] = getLocation (); match (SEMICOLON); return result; } CmmContinueStat * CmmParser::continue_stat () { CmmContinueStat * result = new CmmContinueStat; result->location [0] = getLocation (); match (LITERAL_continue); result->location [1] = getLocation (); match (SEMICOLON); return result; } CmmReturnStat * CmmParser::return_stat () { CmmReturnStat * result = new CmmReturnStat; result->location [0] = getLocation (); match (LITERAL_return); if (test (set_5)) result->return_expr = expr (); result->location [1] = getLocation (); match (SEMICOLON); return result; } CmmGotoStat * CmmParser::goto_stat () { CmmGotoStat * result = new CmmGotoStat; result->location [0] = getLocation (); match (LITERAL_goto); result->location [1] = getLocation (); result->goto_lab = identifier (); result->location [2] = getLocation (); match (SEMICOLON); return result; } CmmDeclSect * CmmParser::declaration_list () { CmmDeclSect * result = new CmmDeclSect; while (test (set_13)) { result->add (declaration ()); } return result; } CmmDecl * CmmParser::declaration () { CmmDecl * result = NULL; if ((symbol (LITERAL_extern)) && condition_3 ()) result = linkage_specification (); else if ((symbol (LITERAL_extern)) && condition_4 ()) result = extern_template_declaration (); else if ((test (set_14)) && is_constructor ()) result = constructor_declaration (); else if (test (set_11)) result = complex_declaration (); else if (symbol (SEMICOLON)) result = empty_declaration (); else if (symbol (LITERAL_namespace)) result = namespace_definition (); else if (symbol (LITERAL_using)) result = using_declaration (); else if (symbol (LITERAL_asm)) result = asm_declaration (); else if (symbol (LITERAL_template) || symbol (LITERAL_export)) result = template_declaration (); else stop (); return result; } CmmDecl * CmmParser::block_declaration () { CmmDecl * result = NULL; if (test (set_11)) result = simple_declaration (); else if (symbol (SEMICOLON)) result = empty_declaration (); else if (symbol (LITERAL_namespace)) result = namespace_definition (); else if (symbol (LITERAL_using)) result = using_declaration (); else if (symbol (LITERAL_asm)) result = asm_declaration (); else stop (); return result; } CmmSimpleDecl * CmmParser::simple_declaration () { CmmSimpleDecl * result = NULL; result = simple_declaration_content (); result->location [0] = getLocation (); match (SEMICOLON); return result; } CmmSimpleDecl * CmmParser::simple_declaration_content () { CmmSimpleDecl * result = new CmmSimpleDecl; result->spec = decl_specifiers (); open_simple_declaration (result); result->add (init_declarator ()); while (symbol (COMMA)) { result->location [1] = getLocation (); match (COMMA); result->add (init_declarator ()); } close_simple_declaration (result); return result; } CmmComplexDecl * CmmParser::complex_declaration () { CmmComplexDecl * result = new CmmComplexDecl; result->spec = decl_specifiers (); open_complex_declaration (result); if (symbol (COLON)) { result->location [0] = getLocation (); match (COLON); result->empty_width = conditional_expr (); result->location [1] = getLocation (); match (SEMICOLON); } else if (symbol (SEMICOLON)) { result->location [2] = getLocation (); match (SEMICOLON); result->empty = true; } else if (test (set_15)) { result->add (init_declarator ()); if (symbol (LBRACE) || symbol (COLON) || symbol (LITERAL_try)) result->func_body = function_body (); else if (symbol (COMMA) || symbol (SEMICOLON)) { while (symbol (COMMA)) { result->location [3] = getLocation (); match (COMMA); result->add (init_declarator ()); } result->location [4] = getLocation (); match (SEMICOLON); } else stop (); } else stop (); close_complex_declaration (result); return result; } CmmCtorHead * CmmParser::constructor_head () { CmmCtorHead * result = new CmmCtorHead; result->spec = constructor_decl_specifiers (); if (symbol (BIT_NOT)) { result->location [0] = getLocation (); match (BIT_NOT); result->destructor = true; } result->add (constructor_head_declarator ()); if (symbol (COLON)) { result->location [1] = getLocation (); match (COLON); result->init_values = true; } else if (symbol (LBRACE)) { result->location [2] = getLocation (); match (LBRACE); result->body = true; } else if (symbol (LITERAL_try)) { result->location [3] = getLocation (); match (LITERAL_try); result->try_block = true; } else if (symbol (SEMICOLON)) { result->location [4] = getLocation (); match (SEMICOLON); } else stop (); return result; } CmmDeclarator * CmmParser::constructor_head_declarator () { CmmDeclarator * result = new CmmDeclarator; open_declarator (result); result->name = global_new_name (); result->cont = constructor_head_specifier_list (); close_declarator (result); return result; } CmmContSpecifierSect * CmmParser::constructor_head_specifier_list () { CmmContSpecifierSect * result = new CmmContSpecifierSect; result->add (constructor_head_specifier ()); return result; } CmmContSpecifier * CmmParser::constructor_head_specifier () { CmmContSpecifier * result = NULL; result = function_specifier (); return result; } CmmCtorDecl * CmmParser::constructor_declaration () { CmmCtorDecl * result = new CmmCtorDecl; open_constructor_declaration (result); result->spec = constructor_decl_specifiers (); if (symbol (BIT_NOT)) { result->location [0] = getLocation (); match (BIT_NOT); result->destructor = true; } result->add (init_declarator ()); if (symbol (LBRACE) || symbol (COLON) || symbol (LITERAL_try)) result->func_body = function_body (); else if (symbol (SEMICOLON)) { result->location [1] = getLocation (); match (SEMICOLON); } else stop (); close_constructor_declaration (result); return result; } CmmFunctionBody * CmmParser::function_body () { CmmFunctionBody * result = new CmmFunctionBody; open_function (result); if (symbol (LBRACE) || symbol (COLON)) { if (symbol (COLON)) { result->location [0] = getLocation (); match (COLON); result->ctor_init = ctor_initializer (); } result->statements = compound_stat (); } else if (symbol (LITERAL_try)) { result->location [1] = getLocation (); match (LITERAL_try); if (symbol (COLON)) { result->location [2] = getLocation (); match (COLON); result->ctor_init = ctor_initializer (); } result->statements = compound_stat (); result->handlers = handler_list (); } else stop (); close_function (result); return result; } CmmEnumDecl * CmmParser::elaborated_enum_specifier () { CmmEnumDecl * result = new CmmEnumDecl; result->location [0] = getLocation (); match (LITERAL_enum); result->name = global_new_name (); return result; } CmmClassDecl * CmmParser::elaborated_class_specifier () { CmmClassDecl * result = new CmmClassDecl; if (symbol (LITERAL_class)) { result->location [0] = getLocation (); match (LITERAL_class); result->style = ClassStyle; } else if (symbol (LITERAL_struct)) { result->location [1] = getLocation (); match (LITERAL_struct); result->style = StructStyle; } else if (symbol (LITERAL_union)) { result->location [2] = getLocation (); match (LITERAL_union); result->style = UnionStyle; } else stop (); result->name = global_new_name (); return result; } CmmClassDecl * CmmParser::class_declaration () { CmmClassDecl * result = NULL; result = class_specifier (); result->location [3] = getLocation (); match (SEMICOLON); return result; } CmmEnumDecl * CmmParser::enum_declaration () { CmmEnumDecl * result = NULL; result = enum_specifier (); result->location [1] = getLocation (); match (SEMICOLON); return result; } CmmNamespaceDecl * CmmParser::namespace_definition () { CmmNamespaceDecl * result = new CmmNamespaceDecl; result->location [0] = getLocation (); match (LITERAL_namespace); if (symbol (IDENT) || symbol (LITERAL_operator)) { result->name = simple_new_name (); if (symbol (ASSIGN)) { result->location [1] = getLocation (); match (ASSIGN); result->value = global_name (); result->location [2] = getLocation (); match (SEMICOLON); add_namespace_alias (result); } else if (symbol (LBRACE)) namespace_body (result); else stop (); } else if (symbol (LBRACE)) namespace_body (result); else stop (); return result; } void CmmParser::namespace_body (CmmNamespaceDecl * p_result) { assert (p_result != NULL); open_namespace (p_result); p_result->location [3] = getLocation (); match (LBRACE); p_result->body = declaration_list (); close_namespace (p_result); p_result->location [4] = getLocation (); match (RBRACE); } CmmUsingDecl * CmmParser::using_declaration () { CmmUsingDecl * result = new CmmUsingDecl; result->location [0] = getLocation (); match (LITERAL_using); if (symbol (LITERAL_namespace)) { result->location [1] = getLocation (); match (LITERAL_namespace); result->a_namespace = true; } else if (symbol (LITERAL_typename)) { result->location [2] = getLocation (); match (LITERAL_typename); result->a_typename = true; } open_using (result); result->name = global_name (); close_using (result); result->location [3] = getLocation (); match (SEMICOLON); return result; } CmmExternDecl * CmmParser::linkage_specification () { CmmExternDecl * result = new CmmExternDecl; result->location [0] = getLocation (); match (LITERAL_extern); if (symbol (STRING_LITERAL)) { result->location [1] = getLocation (); result->language = string_literal (); if (symbol (LBRACE)) { result->location [2] = getLocation (); match (LBRACE); result->decl_list = declaration_list (); result->location [3] = getLocation (); match (RBRACE); } else if (test (set_13)) result->inner_decl = declaration (); else stop (); } else if (test (set_13)) result->inner_decl = declaration (); else stop (); return result; } CmmAsmDecl * CmmParser::asm_declaration () { CmmAsmDecl * result = new CmmAsmDecl; result->location [0] = getLocation (); match (LITERAL_asm); result->location [1] = getLocation (); match (LPAREN); result->location [2] = getLocation (); result->instruction = string_literal (); result->location [3] = getLocation (); match (RPAREN); result->location [4] = getLocation (); match (SEMICOLON); return result; } CmmEmptyDecl * CmmParser::empty_declaration () { CmmEmptyDecl * result = new CmmEmptyDecl; result->location [0] = getLocation (); match (SEMICOLON); return result; } CmmDeclSpec * CmmParser::decl_specifiers () { CmmDeclSpec * result = new CmmDeclSpec; open_decl_specifiers (result); simple_decl_specifiers (result); if (symbol (IDENT) || symbol (SCOPE) || symbol (LITERAL_operator)) result->basic_name = global_declaring_name (); else if (symbol (LITERAL_class) || symbol (LITERAL_struct) || symbol (LITERAL_union)) result->class_spec = class_specifier (); else if (symbol (LITERAL_enum)) result->enum_spec = enum_specifier (); else if (symbol (LITERAL_typename)) result->typename_spec = typename_specifier (); else if (test (set_2)) simple_type_specifiers (result); else stop (); simple_decl_specifiers (result); close_decl_specifiers (result); return result; } CmmDeclSpec * CmmParser::type_specifiers () { CmmDeclSpec * result = new CmmDeclSpec; simple_cv_specifiers (result); if (symbol (LITERAL_register)) { result->location [0] = getLocation (); match (LITERAL_register); result->a_register = true; } if (symbol (IDENT) || symbol (SCOPE) || symbol (LITERAL_operator)) result->basic_name = global_declaring_name (); else if (symbol (LITERAL_class) || symbol (LITERAL_struct) || symbol (LITERAL_union)) result->class_spec = elaborated_class_specifier (); else if (symbol (LITERAL_enum)) result->enum_spec = elaborated_enum_specifier (); else if (symbol (LITERAL_typename)) result->typename_spec = typename_specifier (); else if (test (set_2)) simple_type_specifiers (result); else stop (); simple_decl_specifiers (result); return result; } CmmTypenameSpec * CmmParser::typename_specifier () { CmmTypenameSpec * result = new CmmTypenameSpec; result->location [0] = getLocation (); match (LITERAL_typename); result->name = global_type_name (); return result; } void CmmParser::simple_decl_specifiers (CmmDeclSpec * p_result) { assert (p_result != NULL); while (test (set_16)) { if (symbol (LITERAL_typedef)) { p_result->location [1] = getLocation (); match (LITERAL_typedef); p_result->a_typedef = true; } else if (symbol (LITERAL_friend)) { p_result->location [2] = getLocation (); match (LITERAL_friend); p_result->a_friend = true; } else if (symbol (LITERAL_inline)) { p_result->location [3] = getLocation (); match (LITERAL_inline); p_result->a_inline = true; } else if (symbol (LITERAL_virtual)) { p_result->location [4] = getLocation (); match (LITERAL_virtual); p_result->a_virtual = true; } else if (symbol (LITERAL_explicit)) { p_result->location [5] = getLocation (); match (LITERAL_explicit); p_result->a_explicit = true; } else if (symbol (LITERAL_mutable)) { p_result->location [6] = getLocation (); match (LITERAL_mutable); p_result->a_mutable = true; } else if (symbol (LITERAL_extern)) { p_result->location [7] = getLocation (); match (LITERAL_extern); p_result->a_extern = true; } else if (symbol (LITERAL_static)) { p_result->location [8] = getLocation (); match (LITERAL_static); p_result->a_static = true; } else if (symbol (LITERAL_auto)) { p_result->location [9] = getLocation (); match (LITERAL_auto); p_result->a_auto = true; } else if (symbol (LITERAL_register)) { p_result->location [10] = getLocation (); match (LITERAL_register); p_result->a_register = true; } else if (symbol (LITERAL_const)) { p_result->location [11] = getLocation (); match (LITERAL_const); p_result->a_const = true; } else if (symbol (LITERAL_volatile)) { p_result->location [12] = getLocation (); match (LITERAL_volatile); p_result->a_volatile = true; } } } CmmDeclSpec * CmmParser::constructor_decl_specifiers () { CmmDeclSpec * result = new CmmDeclSpec; while (symbol (LITERAL_inline) || symbol (LITERAL_virtual) || symbol (LITERAL_explicit)) { if (symbol (LITERAL_inline)) { result->location [13] = getLocation (); match (LITERAL_inline); result->a_inline = true; } else if (symbol (LITERAL_virtual)) { result->location [14] = getLocation (); match (LITERAL_virtual); result->a_virtual = true; } else if (symbol (LITERAL_explicit)) { result->location [15] = getLocation (); match (LITERAL_explicit); result->a_explicit = true; } } return result; } void CmmParser::simple_cv_specifiers (CmmDeclSpec * p_result) { assert (p_result != NULL); while (symbol (LITERAL_const) || symbol (LITERAL_volatile)) { if (symbol (LITERAL_const)) { p_result->location [16] = getLocation (); match (LITERAL_const); p_result->a_const = true; } else if (symbol (LITERAL_volatile)) { p_result->location [17] = getLocation (); match (LITERAL_volatile); p_result->a_volatile = true; } } } void CmmParser::simple_type_specifiers (CmmDeclSpec * p_result) { assert (p_result != NULL); do { if (symbol (LITERAL_signed)) { p_result->location [18] = getLocation (); match (LITERAL_signed); p_result->a_signed = true; } else if (symbol (LITERAL_unsigned)) { p_result->location [19] = getLocation (); match (LITERAL_unsigned); p_result->a_unsigned = true; } else if (symbol (LITERAL_short)) { p_result->location [20] = getLocation (); match (LITERAL_short); p_result->a_short = true; } else if (symbol (LITERAL_long)) { p_result->location [21] = getLocation (); match (LITERAL_long); p_result->a_long = true; if (symbol (LITERAL_long)) { p_result->location [22] = getLocation (); match (LITERAL_long); p_result->a_long_long = true; } } else if (symbol (LITERAL_bool)) { p_result->location [23] = getLocation (); match (LITERAL_bool); p_result->a_bool = true; } else if (symbol (LITERAL_char)) { p_result->location [24] = getLocation (); match (LITERAL_char); p_result->a_char = true; } else if (symbol (LITERAL_wchar_t)) { p_result->location [25] = getLocation (); match (LITERAL_wchar_t); p_result->a_wchar = true; } else if (symbol (LITERAL_int)) { p_result->location [26] = getLocation (); match (LITERAL_int); p_result->a_int = true; } else if (symbol (LITERAL_float)) { p_result->location [27] = getLocation (); match (LITERAL_float); p_result->a_float = true; } else if (symbol (LITERAL_double)) { p_result->location [28] = getLocation (); match (LITERAL_double); p_result->a_double = true; } else if (symbol (LITERAL_void)) { p_result->location [29] = getLocation (); match (LITERAL_void); p_result->a_void = true; } else stop (); } while (test (set_2)); } CmmEnumDecl * CmmParser::enum_specifier () { CmmEnumDecl * result = new CmmEnumDecl; result->location [2] = getLocation (); match (LITERAL_enum); if (symbol (IDENT) || symbol (SCOPE) || symbol (LITERAL_operator)) { result->name = global_new_name (); if (symbol (LBRACE)) { enum_body (result); result->with_body = true; } else add_enum_forw (result); } else if (symbol (LBRACE)) enum_body (result); else stop (); return result; } void CmmParser::enum_body (CmmEnumDecl * p_result) { assert (p_result != NULL); open_enum_type (p_result); p_result->location [3] = getLocation (); match (LBRACE); p_result->items = enum_list (); p_result->location [4] = getLocation (); match (RBRACE); close_enum_type (p_result); } CmmEnumSect * CmmParser::enum_list () { CmmEnumSect * result = new CmmEnumSect; if (symbol (IDENT) || symbol (LITERAL_operator)) { result->add (enumerator ()); while (symbol (COMMA)) { result->location [0] = getLocation (); match (COMMA); result->add (flexible_enumerator ()); } } return result; } CmmEnumItem * CmmParser::enumerator () { CmmEnumItem * result = new CmmEnumItem; result->name = simple_new_name (); add_enum_item (result); if (symbol (ASSIGN)) { result->location [0] = getLocation (); match (ASSIGN); result->init = const_expr (); } return result; } CmmEnumItem * CmmParser::flexible_enumerator () { CmmEnumItem * result = new CmmEnumItem; if (symbol (IDENT) || symbol (LITERAL_operator)) { result->name = simple_new_name (); add_enum_item (result); if (symbol (ASSIGN)) { result->location [1] = getLocation (); match (ASSIGN); result->init = const_expr (); } } else { } return result; } CmmTypeId * CmmParser::type_id () { CmmTypeId * result = new CmmTypeId; result->spec = type_specifiers (); result->decl = abstract_declarator (); return result; } CmmTypeId * CmmParser::common_type_id () { CmmTypeId * result = new CmmTypeId; result->spec = type_specifiers (); result->decl = common_declarator (); return result; } CmmDeclarator * CmmParser::declarator () { CmmDeclarator * result = new CmmDeclarator; open_declarator (result); result->ptr = ptr_specifier_list (); if (symbol (IDENT) || symbol (SCOPE) || symbol (LITERAL_operator)) result->name = global_new_name (); else if (symbol (LPAREN)) { result->location [0] = getLocation (); match (LPAREN); result->inner = declarator (); result->location [1] = getLocation (); match (RPAREN); } else stop (); result->cont = cont_specifier_list (); close_declarator (result); return result; } CmmDeclarator * CmmParser::abstract_declarator () { CmmDeclarator * result = new CmmDeclarator; open_declarator (result); result->ptr = ptr_specifier_list (); if ((symbol (LPAREN)) && is_inner_abstract_declarator ()) { result->location [2] = getLocation (); match (LPAREN); result->inner = abstract_declarator (); result->location [3] = getLocation (); match (RPAREN); } result->cont = cont_specifier_list (); close_declarator (result); return result; } void CmmParser::common_declarator_name (CmmDeclarator * p_result) { assert (p_result != NULL); p_result->name = global_new_name (); } CmmDeclarator * CmmParser::common_declarator () { CmmDeclarator * result = new CmmDeclarator; open_declarator (result); result->ptr = ptr_specifier_list (); if ((symbol (LPAREN)) && is_inner_common_declarator ()) { result->location [4] = getLocation (); match (LPAREN); result->inner = common_declarator (); result->location [5] = getLocation (); match (RPAREN); } else if (symbol (IDENT) || symbol (SCOPE) || symbol (LITERAL_operator)) { common_declarator_name (result); result->empty_branch = true; } result->cont = cont_specifier_list (); close_declarator (result); return result; } CmmPtrSpecifierSect * CmmParser::ptr_specifier_list () { CmmPtrSpecifierSect * result = new CmmPtrSpecifierSect; while (symbol (STAR) || symbol (BIT_AND)) { result->add (ptr_specifier ()); } member_pointer_list (result); return result; } CmmPtrSpecifier * CmmParser::ptr_specifier () { CmmPtrSpecifier * result = new CmmPtrSpecifier; if (symbol (STAR)) { result->location [0] = getLocation (); match (STAR); result->pointer = true; ptr_cv_specifier_list (result); } else if (symbol (BIT_AND)) { result->location [1] = getLocation (); match (BIT_AND); result->reference = true; ptr_cv_specifier_list (result); } else stop (); return result; } CmmPtrSpecifier * CmmParser::member_specifier () { CmmPtrSpecifier * result = new CmmPtrSpecifier; result->area = global_name (); member_specifier_tail (result); return result; } void CmmParser::member_specifier_tail (CmmPtrSpecifier * p_result) { assert (p_result != NULL); p_result->location [2] = getLocation (); match (SCOPE); p_result->location [3] = getLocation (); match (STAR); p_result->member_pointer = true; ptr_cv_specifier_list (p_result); } void CmmParser::ptr_cv_specifier_list (CmmPtrSpecifier * p_result) { assert (p_result != NULL); while (symbol (LITERAL_const) || symbol (LITERAL_volatile)) { if (symbol (LITERAL_const)) { p_result->location [4] = getLocation (); match (LITERAL_const); p_result->cv_const = true; } else if (symbol (LITERAL_volatile)) { p_result->location [5] = getLocation (); match (LITERAL_volatile); p_result->cv_volatile = true; } } } CmmContSpecifierSect * CmmParser::cont_specifier_list () { CmmContSpecifierSect * result = new CmmContSpecifierSect; while (symbol (LPAREN) || symbol (LBRACKET)) { result->add (cont_specifier ()); } return result; } CmmContSpecifier * CmmParser::cont_specifier () { CmmContSpecifier * result = NULL; if (symbol (LPAREN)) result = function_specifier (); else if (symbol (LBRACKET)) result = array_specifier (); else stop (); return result; } CmmFunctionSpecifier * CmmParser::function_specifier () { CmmFunctionSpecifier * result = new CmmFunctionSpecifier; open_parameters (result); result->location [0] = getLocation (); match (LPAREN); result->parameters = parameter_declaration_list (); result->location [1] = getLocation (); match (RPAREN); while (symbol (LITERAL_const) || symbol (LITERAL_volatile)) { if (symbol (LITERAL_const)) { result->location [2] = getLocation (); match (LITERAL_const); result->cv_const = true; } else if (symbol (LITERAL_volatile)) { result->location [3] = getLocation (); match (LITERAL_volatile); result->cv_volatile = true; } } if (symbol (LITERAL_throw)) result->exception_spec = exception_specification (); close_parameters (result); return result; } CmmArraySpecifier * CmmParser::array_specifier () { CmmArraySpecifier * result = new CmmArraySpecifier; result->location [0] = getLocation (); match (LBRACKET); if (test (set_5)) result->lim = expr (); result->location [1] = getLocation (); match (RBRACKET); return result; } CmmParamSect * CmmParser::parameter_declaration_list () { CmmParamSect * result = new CmmParamSect; if (test (set_17)) { result->add (parameter_declaration ()); while (symbol (COMMA)) { result->location [0] = getLocation (); match (COMMA); result->add (parameter_declaration ()); } } return result; } CmmParamItem * CmmParser::parameter_declaration () { CmmParamItem * result = new CmmParamItem; if ((test (set_4)) && is_parameter ()) { result->type = common_type_id (); read_param_init (); parameter_initialization (result); if (symbol (DOTS)) { result->location [0] = getLocation (); match (DOTS); result->following_dots = true; } } else if ((test (set_5)) && is_initializer_acceptable ()) result->value = expr (); else if (symbol (DOTS)) { result->location [1] = getLocation (); match (DOTS); result->dots = true; } else stop (); add_parameter (result); return result; } void CmmParser::parameter_initialization (CmmParamItem * p_result) { assert (p_result != NULL); if (symbol (ASSIGN)) { p_result->location [2] = getLocation (); match (ASSIGN); p_result->init = assignment_expr (); } } CmmDeclarator * CmmParser::init_declarator () { CmmDeclarator * result = NULL; result = declarator (); add_declarator (result); if ((symbol (COLON)) && is_width_acceptable (result)) { result->location [6] = getLocation (); match (COLON); result->width = conditional_expr (); } read_initializer (); if (symbol (ASSIGN)) result->init = initializer (); return result; } CmmInitializer * CmmParser::initializer () { CmmInitializer * result = new CmmInitializer; result->location [0] = getLocation (); match (ASSIGN); result->value = initializer_item (); return result; } CmmInitItem * CmmParser::initializer_item () { CmmInitItem * result = NULL; if (test (set_5)) result = simple_initializer (); else if (symbol (LBRACE)) result = initializer_list (); else stop (); return result; } CmmInitItem * CmmParser::flexible_initializer_item () { CmmInitItem * result = NULL; if (symbol (LBRACE)) result = initializer_list (); else if (test (set_5)) result = simple_initializer (); else result = empty_initializer (); return result; } CmmInitEmpty * CmmParser::empty_initializer () { CmmInitEmpty * result = new CmmInitEmpty; return result; } CmmInitSimple * CmmParser::simple_initializer () { CmmInitSimple * result = new CmmInitSimple; result->expr = assignment_expr (); return result; } CmmInitList * CmmParser::initializer_list () { CmmInitList * result = new CmmInitList; result->location [0] = getLocation (); match (LBRACE); if (test (set_18)) { result->add (initializer_item ()); while (symbol (COMMA)) { result->location [1] = getLocation (); match (COMMA); result->add (flexible_initializer_item ()); } } result->location [2] = getLocation (); match (RBRACE); return result; } CmmClassDecl * CmmParser::class_specifier () { CmmClassDecl * result = new CmmClassDecl; if (symbol (LITERAL_class)) { result->location [4] = getLocation (); match (LITERAL_class); result->style = ClassStyle; } else if (symbol (LITERAL_struct)) { result->location [5] = getLocation (); match (LITERAL_struct); result->style = StructStyle; } else if (symbol (LITERAL_union)) { result->location [6] = getLocation (); match (LITERAL_union); result->style = UnionStyle; } else stop (); if (symbol (IDENT) || symbol (SCOPE) || symbol (LITERAL_operator)) { result->name = global_new_name (); if (symbol (LBRACE) || symbol (COLON)) { class_body (result); result->with_body = true; } else add_class_forw (result); } else if (symbol (LBRACE) || symbol (COLON)) class_body (result); else stop (); return result; } void CmmParser::class_body (CmmClassDecl * p_result) { assert (p_result != NULL); open_class (p_result); if (symbol (COLON)) { p_result->location [7] = getLocation (); match (COLON); p_result->base_list = base_specifier_list (); } p_result->location [8] = getLocation (); match (LBRACE); p_result->members = member_list (); p_result->location [9] = getLocation (); match (RBRACE); close_class (p_result); } CmmMemberVisibility * CmmParser::member_visibility () { CmmMemberVisibility * result = new CmmMemberVisibility; if (symbol (LITERAL_private)) { result->location [0] = getLocation (); match (LITERAL_private); result->access = PrivateAccess; } else if (symbol (LITERAL_protected)) { result->location [1] = getLocation (); match (LITERAL_protected); result->access = ProtectedAccess; } else if (symbol (LITERAL_public)) { result->location [2] = getLocation (); match (LITERAL_public); result->access = PublicAccess; } else stop (); result->location [3] = getLocation (); match (COLON); add_visibility (result); return result; } CmmDecl * CmmParser::member_item () { CmmDecl * result = NULL; if (symbol (LITERAL_private) || symbol (LITERAL_protected) || symbol (LITERAL_public)) result = member_visibility (); else if ((test (set_14)) && is_constructor ()) result = constructor_declaration (); else if (test (set_11)) result = complex_declaration (); else if (symbol (SEMICOLON)) result = empty_declaration (); else if (symbol (LITERAL_using)) result = using_declaration (); else if (symbol (LITERAL_template) || symbol (LITERAL_export)) result = template_declaration (); else stop (); return result; } CmmDeclSect * CmmParser::member_list () { CmmDeclSect * result = new CmmDeclSect; while (test (set_19)) { result->add (member_item ()); } return result; } CmmBaseSect * CmmParser::base_specifier_list () { CmmBaseSect * result = new CmmBaseSect; result->add (base_specifier ()); while (symbol (COMMA)) { result->location [0] = getLocation (); match (COMMA); result->add (base_specifier ()); } return result; } CmmBaseItem * CmmParser::base_specifier () { CmmBaseItem * result = new CmmBaseItem; if (symbol (LITERAL_virtual)) { result->location [0] = getLocation (); match (LITERAL_virtual); result->a_virtual = true; if (symbol (LITERAL_private)) { result->location [1] = getLocation (); match (LITERAL_private); result->access = PrivateAccess; } else if (symbol (LITERAL_protected)) { result->location [2] = getLocation (); match (LITERAL_protected); result->access = ProtectedAccess; } else if (symbol (LITERAL_public)) { result->location [3] = getLocation (); match (LITERAL_public); result->access = PublicAccess; } else result->access = NoAccess; } else if (symbol (LITERAL_private)) { result->location [4] = getLocation (); match (LITERAL_private); result->access = PrivateAccess; if (symbol (LITERAL_virtual)) { result->location [5] = getLocation (); match (LITERAL_virtual); result->a_virtual = true; } } else if (symbol (LITERAL_protected)) { result->location [6] = getLocation (); match (LITERAL_protected); result->access = ProtectedAccess; if (symbol (LITERAL_virtual)) { result->location [7] = getLocation (); match (LITERAL_virtual); result->a_virtual = true; } } else if (symbol (LITERAL_public)) { result->location [8] = getLocation (); match (LITERAL_public); result->access = PublicAccess; if (symbol (LITERAL_virtual)) { result->location [9] = getLocation (); match (LITERAL_virtual); result->a_virtual = true; } } else result->access = NoAccess; result->from = global_type_name (); add_base (result); return result; } CmmCtorInitializer * CmmParser::ctor_initializer () { CmmCtorInitializer * result = new CmmCtorInitializer; result->add (member_initializer ()); while (symbol (COMMA)) { result->location [0] = getLocation (); match (COMMA); result->add (member_initializer ()); } return result; } CmmMemberInitializer * CmmParser::member_initializer () { CmmMemberInitializer * result = new CmmMemberInitializer; result->name = global_name (); result->location [0] = getLocation (); match (LPAREN); read_member_initializer (); result->params = expr_list (); result->location [1] = getLocation (); match (RPAREN); return result; } CmmDeclSpec * CmmParser::conversion_specifiers () { CmmDeclSpec * result = NULL; open_conversion (); result = type_specifiers (); result->ptr = ptr_specifier_list (); close_conversion (); return result; } CmmSpecialFuction * CmmParser::special_function () { CmmSpecialFuction * result = new CmmSpecialFuction; result->location [0] = getLocation (); match (LITERAL_operator); if (test (set_4)) result->conv = conversion_specifiers (); else if (symbol (LITERAL_new)) { result->location [1] = getLocation (); match (LITERAL_new); result->spec_new = true; if ((symbol (LBRACKET)) && condition_5 ()) { result->location [2] = getLocation (); match (LBRACKET); result->location [3] = getLocation (); match (RBRACKET); result->spec_new_array = true; } } else if (symbol (LITERAL_delete)) { result->location [4] = getLocation (); match (LITERAL_delete); result->spec_delete = true; if ((symbol (LBRACKET)) && condition_6 ()) { result->location [5] = getLocation (); match (LBRACKET); result->location [6] = getLocation (); match (RBRACKET); result->spec_delete_array = true; } } else if (symbol (PLUS)) { result->location [7] = getLocation (); match (PLUS); result->spec_add = true; } else if (symbol (MINUS)) { result->location [8] = getLocation (); match (MINUS); result->spec_sub = true; } else if (symbol (STAR)) { result->location [9] = getLocation (); match (STAR); result->spec_mul = true; } else if (symbol (SLASH)) { result->location [10] = getLocation (); match (SLASH); result->spec_div = true; } else if (symbol (MOD)) { result->location [11] = getLocation (); match (MOD); result->spec_mod = true; } else if (symbol (BIT_XOR)) { result->location [12] = getLocation (); match (BIT_XOR); result->spec_xor = true; } else if (symbol (BIT_AND)) { result->location [13] = getLocation (); match (BIT_AND); result->spec_and = true; } else if (symbol (BIT_OR)) { result->location [14] = getLocation (); match (BIT_OR); result->spec_or = true; } else if (symbol (BIT_NOT)) { result->location [15] = getLocation (); match (BIT_NOT); result->spec_not = true; } else if (symbol (LOG_NOT)) { result->location [16] = getLocation (); match (LOG_NOT); result->spec_log_not = true; } else if (symbol (ASSIGN)) { result->location [17] = getLocation (); match (ASSIGN); result->spec_assign = true; } else if (symbol (LESS)) { result->location [18] = getLocation (); match (LESS); result->spec_lt = true; } else if (symbol (GREATER)) { result->location [19] = getLocation (); match (GREATER); result->spec_gt = true; } else if (symbol (PLUS_ASSIGN)) { result->location [20] = getLocation (); match (PLUS_ASSIGN); result->spec_add_assign = true; } else if (symbol (MINUS_ASSIGN)) { result->location [21] = getLocation (); match (MINUS_ASSIGN); result->spec_sub_assign = true; } else if (symbol (MUL_ASSIGN)) { result->location [22] = getLocation (); match (MUL_ASSIGN); result->spec_mul_assign = true; } else if (symbol (DIV_ASSIGN)) { result->location [23] = getLocation (); match (DIV_ASSIGN); result->spec_div_assign = true; } else if (symbol (MOD_ASSIGN)) { result->location [24] = getLocation (); match (MOD_ASSIGN); result->spec_mod_assign = true; } else if (symbol (BIT_XOR_ASSIGN)) { result->location [25] = getLocation (); match (BIT_XOR_ASSIGN); result->spec_xor_assign = true; } else if (symbol (BIT_AND_ASSIGN)) { result->location [26] = getLocation (); match (BIT_AND_ASSIGN); result->spec_and_assign = true; } else if (symbol (BIT_OR_ASSIGN)) { result->location [27] = getLocation (); match (BIT_OR_ASSIGN); result->spec_or_assign = true; } else if (symbol (SHL)) { result->location [28] = getLocation (); match (SHL); result->spec_shl = true; } else if (symbol (SHR)) { result->location [29] = getLocation (); match (SHR); result->spec_shr = true; } else if (symbol (SHR_ASSIGN)) { result->location [30] = getLocation (); match (SHR_ASSIGN); result->spec_shl_assign = true; } else if (symbol (SHL_ASSIGN)) { result->location [31] = getLocation (); match (SHL_ASSIGN); result->spec_shr_assign = true; } else if (symbol (EQUAL)) { result->location [32] = getLocation (); match (EQUAL); result->spec_eq = true; } else if (symbol (UNEQUAL)) { result->location [33] = getLocation (); match (UNEQUAL); result->spec_ne = true; } else if (symbol (LESS_OR_EQUAL)) { result->location [34] = getLocation (); match (LESS_OR_EQUAL); result->spec_le = true; } else if (symbol (GREATER_OR_EQUAL)) { result->location [35] = getLocation (); match (GREATER_OR_EQUAL); result->spec_ge = true; } else if (symbol (LOG_AND)) { result->location [36] = getLocation (); match (LOG_AND); result->spec_log_and = true; } else if (symbol (LOG_OR)) { result->location [37] = getLocation (); match (LOG_OR); result->spec_log_or = true; } else if (symbol (INC)) { result->location [38] = getLocation (); match (INC); result->spec_inc = true; } else if (symbol (DEC)) { result->location [39] = getLocation (); match (DEC); result->spec_dec = true; } else if (symbol (COMMA)) { result->location [40] = getLocation (); match (COMMA); result->spec_comma = true; } else if (symbol (ARROW_STAR)) { result->location [41] = getLocation (); match (ARROW_STAR); result->spec_member_deref = true; } else if (symbol (ARROW)) { result->location [42] = getLocation (); match (ARROW); result->spec_deref = true; } else if (symbol (LPAREN)) { result->location [43] = getLocation (); match (LPAREN); result->location [44] = getLocation (); match (RPAREN); result->spec_call = true; } else if (symbol (LBRACKET)) { result->location [45] = getLocation (); match (LBRACKET); result->location [46] = getLocation (); match (RBRACKET); result->spec_index = true; } else stop (); return result; } CmmTemplateDecl * CmmParser::template_declaration () { CmmTemplateDecl * result = new CmmTemplateDecl; common_template_declaration (result); return result; } CmmExxternTemplateDecl * CmmParser::extern_template_declaration () { CmmExxternTemplateDecl * result = new CmmExxternTemplateDecl; result->location [0] = getLocation (); match (LITERAL_extern); common_template_declaration (result); return result; } void CmmParser::common_template_declaration (CmmTemplateDecl * p_result) { assert (p_result != NULL); open_template (p_result); template_specification (p_result); add_template (p_result); p_result->inner_decl = declaration (); close_template (p_result); } void CmmParser::template_specification (CmmTemplateDecl * p_result) { assert (p_result != NULL); if (symbol (LITERAL_export)) { p_result->location [0] = getLocation (); match (LITERAL_export); p_result->export_template = true; } p_result->location [1] = getLocation (); match (LITERAL_template); if (symbol (LESS)) { p_result->location [2] = getLocation (); match (LESS); if (test (set_20)) p_result->params = template_param_list (); else p_result->explicit_specialization = true; p_result->location [3] = getLocation (); match (GREATER); p_result->parameter_block = true; } else p_result->explicit_instatiation = true; } CmmTemplateParamSect * CmmParser::template_param_list () { CmmTemplateParamSect * result = new CmmTemplateParamSect; result->add (template_param ()); while (symbol (COMMA)) { result->location [0] = getLocation (); match (COMMA); result->add (template_param ()); } return result; } CmmTemplateParam * CmmParser::template_param () { CmmTemplateParam * result = NULL; if (symbol (LITERAL_template) || symbol (LITERAL_typename) || symbol (LITERAL_class)) result = template_type_param (); else if (test (set_4)) result = template_value_param (); else stop (); return result; } CmmTemplateTypeParam * CmmParser::template_type_param () { CmmTemplateTypeParam * result = new CmmTemplateTypeParam; if (symbol (LITERAL_template)) { result->location [0] = getLocation (); match (LITERAL_template); result->location [1] = getLocation (); match (LESS); result->params = template_param_list (); result->location [2] = getLocation (); match (GREATER); } if (symbol (LITERAL_class)) { result->location [3] = getLocation (); match (LITERAL_class); result->a_class = true; } else if (symbol (LITERAL_typename)) { result->location [4] = getLocation (); match (LITERAL_typename); result->a_typename = true; } else stop (); if (symbol (IDENT) || symbol (LITERAL_operator)) result->name = simple_new_name (); if (symbol (ASSIGN)) { result->location [5] = getLocation (); match (ASSIGN); result->value = type_id (); } add_template_type_param (result); return result; } CmmTemplateValueParam * CmmParser::template_value_param () { CmmTemplateValueParam * result = new CmmTemplateValueParam; result->type = common_type_id (); add_template_value_param (result); if (symbol (ASSIGN)) { result->location [0] = getLocation (); match (ASSIGN); result->init = shift_expr (); } return result; } CmmTemplateArgSect * CmmParser::template_arg_list () { CmmTemplateArgSect * result = new CmmTemplateArgSect; open_template_arguments (result); result->location [0] = getLocation (); match (LESS); if (test (set_21)) { result->add (template_arg ()); while (symbol (COMMA)) { result->location [1] = getLocation (); match (COMMA); result->add (template_arg ()); } } result->location [2] = getLocation (); match (GREATER); close_template_arguments (result); return result; } CmmTemplateArg * CmmParser::template_arg () { CmmTemplateArg * result = NULL; if ((test (set_4)) && is_type ()) result = template_type_arg (); else if (test (set_8)) result = template_value_arg (); else stop (); return result; } CmmTemplateTypeArg * CmmParser::template_type_arg () { CmmTemplateTypeArg * result = new CmmTemplateTypeArg; result->type = type_id (); return result; } CmmTemplateValueArg * CmmParser::template_value_arg () { CmmTemplateValueArg * result = new CmmTemplateValueArg; result->value = shift_expr (); return result; } CmmTryStat * CmmParser::try_stat () { CmmTryStat * result = new CmmTryStat; result->location [0] = getLocation (); match (LITERAL_try); result->body = compound_stat (); result->handlers = handler_list (); return result; } CmmHandlerSect * CmmParser::handler_list () { CmmHandlerSect * result = new CmmHandlerSect; result->add (handler ()); while (symbol (LITERAL_catch)) { result->add (handler ()); } return result; } CmmHandlerItem * CmmParser::handler () { CmmHandlerItem * result = new CmmHandlerItem; result->location [0] = getLocation (); match (LITERAL_catch); result->location [1] = getLocation (); match (LPAREN); if (test (set_4)) result->type = common_type_id (); else if (symbol (DOTS)) { result->location [2] = getLocation (); match (DOTS); result->dots = true; } else stop (); result->location [3] = getLocation (); match (RPAREN); result->body = compound_stat (); return result; } CmmThrowExpr * CmmParser::throw_expr () { CmmThrowExpr * result = new CmmThrowExpr; result->location [0] = getLocation (); match (LITERAL_throw); if (test (set_5)) result->expr = assignment_expr (); return result; } CmmExceptionSect * CmmParser::exception_specification () { CmmExceptionSect * result = new CmmExceptionSect; result->location [0] = getLocation (); match (LITERAL_throw); result->location [1] = getLocation (); match (LPAREN); if (test (set_4)) { result->add (exception_specification_item ()); while (symbol (COMMA)) { result->location [2] = getLocation (); match (COMMA); result->add (exception_specification_item ()); } } result->location [3] = getLocation (); match (RPAREN); return result; } CmmExceptionItem * CmmParser::exception_specification_item () { CmmExceptionItem * result = new CmmExceptionItem; result->type = type_id (); return result; } bool CmmParser::condition_1 () { bool answer = false; CmmMark inx = mark (); if (symbol (IDENT)) { next (); if (symbol (COLON)) answer = true; } rewind (inx); return answer; } bool CmmParser::condition_2 () { bool answer = true; CmmMark inx = mark (); save_trace (); try { simple_declaration_content (); match (SEMICOLON); } catch (IOException & e) { answer = false; } restore_trace (); rewind (inx); return answer; } bool CmmParser::condition_3 () { bool answer = false; CmmMark inx = mark (); if (symbol (LITERAL_extern)) { next (); if (symbol (STRING_LITERAL)) answer = true; } rewind (inx); return answer; } bool CmmParser::condition_4 () { bool answer = false; CmmMark inx = mark (); if (symbol (LITERAL_extern)) { next (); if (symbol (LITERAL_template)) answer = true; } rewind (inx); return answer; } bool CmmParser::condition_5 () { bool answer = false; CmmMark inx = mark (); if (symbol (LBRACKET)) { next (); if (symbol (RBRACKET)) answer = true; } rewind (inx); return answer; } bool CmmParser::condition_6 () { bool answer = false; CmmMark inx = mark (); if (symbol (LBRACKET)) { next (); if (symbol (RBRACKET)) answer = true; } rewind (inx); return answer; } CmmParser::CmmParser () { } CLOSE_NAMESPACE