📄 parser.y
字号:
IDL_tree_node node; IDL_tree p, dcl; $$ = $3; node.properties = $1; for (p = IDL_TYPE_DCL ($3).dcls; p; p = IDL_LIST (p).next) { dcl = IDL_LIST (p).data; IDL_tree_properties_copy (&node, dcl); } __IDL_free_properties (node.properties);}| struct_type| union_type| enum_type| z_props TOK_NATIVE simple_declarator { $$ = IDL_native_new ($3); assign_props (IDL_NATIVE ($$).ident, $1);}| z_props TOK_NATIVE simple_declarator '(' { /* Enable native type scanning */ if (__IDL_flags & IDLF_XPIDL) __IDL_flagsi |= IDLFP_NATIVE; else { yyerror ("Native syntax not enabled"); YYABORT; }} TOK_NATIVE_TYPE { $$ = IDL_native_new ($3); IDL_NATIVE ($$).user_type = $6; assign_props (IDL_NATIVE ($$).ident, $1);} ;type_declarator: type_spec declarator_list { $$ = IDL_type_dcl_new ($1, $2); } ;type_spec: simple_type_spec| constr_type_spec ;simple_type_spec: base_type_spec| template_type_spec| scoped_name ;constr_type_spec: struct_type| union_type| enum_type ;z_new_ident_catch: /* empty */ { yyerrorv ("Missing identifier in %s definition", $<str>0); YYABORT;}| new_ident ;z_new_scope_catch: /* empty */ { yyerrorv ("Missing identifier in %s definition", $<str>0); YYABORT;}| new_scope ;struct_type: z_props TOK_STRUCT { $<str>$ = "struct"; } z_new_scope_catch '{' { g_hash_table_insert (__IDL_structunion_ht, $4, $4); $$ = IDL_type_struct_new ($4, NULL);} member_list '}' pop_scope { g_hash_table_remove (__IDL_structunion_ht, $4); $$ = $<tree>6; __IDL_assign_up_node ($$, $7); IDL_TYPE_STRUCT ($$).member_list = $7; assign_props (IDL_TYPE_STRUCT ($$).ident, $1);} ;union_type: z_props TOK_UNION { $<str>$ = "union"; } z_new_scope_catch TOK_SWITCH '(' switch_type_spec ')' '{' { g_hash_table_insert (__IDL_structunion_ht, $4, $4); $$ = IDL_type_union_new ($4, $7, NULL);} switch_body '}' pop_scope { g_hash_table_remove (__IDL_structunion_ht, $4); $$ = $<tree>10; __IDL_assign_up_node ($$, $11); IDL_TYPE_UNION ($$).switch_body = $11; assign_props (IDL_TYPE_UNION ($$).ident, $1);} ;switch_type_spec: integer_type| char_type| boolean_type| enum_type| scoped_name ;switch_body: case_stmt_list ;case_stmt_list: case_stmt { $$ = list_start ($1, TRUE); }| case_stmt_list case_stmt { $$ = list_chain ($1, $2, TRUE); } ;case_stmt: case_label_list element_spec check_semicolon { $$ = IDL_case_stmt_new ($1, $2); } ;element_spec: type_spec declarator { char *s; $$ = IDL_member_new ($1, list_start ($2, TRUE)); if (IDL_NODE_TYPE ($1) == IDLN_IDENT && g_hash_table_lookup (__IDL_structunion_ht, $1)) { s = IDL_ns_ident_to_qstring ($2, "::", 0); yyerrorv ("Member `%s'", s); do_token_error (IDL_NODE_UP ($1), "recurses", TRUE); g_free (s); }} ;case_label_list: case_label { $$ = list_start ($1, FALSE); }| case_label_list case_label { $$ = list_chain ($1, $2, FALSE); } ;case_label: TOK_CASE const_exp ':' { $$ = $2; }| TOK_DEFAULT ':' { $$ = NULL; } ;const_dcl: z_declspec const_dcl_def { $$ = $2; assign_declspec ($$, $1);} ;const_dcl_def: TOK_CONST const_type new_ident '=' const_exp { $$ = IDL_const_dcl_new ($2, $3, $5); /* Should probably do some type checking here... */} ;except_dcl: z_declspec except_dcl_def { $$ = $2; assign_declspec ($$, $1);} ;except_dcl_def: TOK_EXCEPTION new_scope '{' member_zlist '}' pop_scope { $$ = IDL_except_dcl_new ($2, $4); } ;member_zlist: /* empty */ { $$ = NULL; }| member_zlist member { $$ = zlist_chain ($1, $2, TRUE); } ;is_readonly: /* empty */ { $$ = FALSE; }| TOK_READONLY { $$ = TRUE; } ;attr_dcl: z_declspec attr_dcl_def { $$ = $2; assign_declspec ($$, $1);} ;attr_dcl_def: z_props is_readonly TOK_ATTRIBUTE { $<str>$ = "attribute"; } param_type_spec simple_declarator_list { IDL_tree_node node; IDL_tree p, dcl; $$ = IDL_attr_dcl_new ($2, $5, $6); node.properties = $1; for (p = $6; p; p = IDL_LIST (p).next) { dcl = IDL_LIST (p).data; IDL_tree_properties_copy (&node, dcl); } __IDL_free_properties (node.properties);} ;param_type_spec: op_param_type_spec| TOK_VOID { yyerrorv ("Illegal type `void' for %s", $<str>0); $$ = NULL;} ;op_param_type_spec_illegal: sequence_type| constr_type_spec ;op_param_type_spec: base_type_spec| string_type| wide_string_type| fixed_pt_type| scoped_name| op_param_type_spec_illegal { illegal_context_type_error ($1, $<str>0); $$ = $1;} ;is_oneway: /* empty */ { $$ = FALSE; }| TOK_ONEWAY { $$ = TRUE; } ;op_dcl: z_declspec op_dcl_def { $$ = $2; assign_declspec ($$, $1);} ;op_dcl_def: z_props is_oneway op_type_spec new_scope parameter_dcls pop_scope is_raises_expr is_context_expr { $$ = IDL_op_dcl_new ($2, $3, $4, $5.tree, $7, $8); IDL_OP_DCL ($$).f_varargs = GPOINTER_TO_INT ($5.data); assign_props (IDL_OP_DCL ($$).ident, $1);} ;op_type_spec: { $<str>$ = "operation return value"; } op_param_type_spec { $$ = $2; }| TOK_VOID { $$ = NULL; } ;is_varargs: /* empty */ { $$ = FALSE; }| TOK_VARARGS { $$ = TRUE; } ;is_cvarargs: /* empty */ { $$ = FALSE; }| ',' TOK_VARARGS { $$ = TRUE; } ;parameter_dcls: '(' param_dcl_list is_cvarargs ')' { $$.tree = $2; $$.data = GINT_TO_POINTER ($3);}| '(' is_varargs ')' { $$.tree = NULL; $$.data = GINT_TO_POINTER ($2);} ;param_dcl_list: param_dcl { $$ = list_start ($1, TRUE); }| param_dcl_list check_comma param_dcl { $$ = list_chain ($1, $3, TRUE); } ;param_dcl: z_props param_attribute { $<str>$ = "parameter"; } param_type_spec simple_declarator { $$ = IDL_param_dcl_new ($2, $4, $5); assign_props (IDL_PARAM_DCL ($$).simple_declarator, $1);} ;param_attribute: TOK_IN { $$ = IDL_PARAM_IN; }| TOK_OUT { $$ = IDL_PARAM_OUT; }| TOK_INOUT { $$ = IDL_PARAM_INOUT; }| param_type_spec { yyerrorv ("Missing direction attribute (in, out, inout) before parameter"); IDL_tree_free ($1);} ;is_raises_expr: /* empty */ { $$ = NULL; }| raises_expr ;is_context_expr: /* empty */ { $$ = NULL; }| context_expr ;raises_expr: TOK_RAISES '(' scoped_name_list ')' { $$ = $3; } ;context_expr: TOK_CONTEXT '(' string_lit_list ')' { $$ = $3; } ;const_type: integer_type| char_type| wide_char_type| boolean_type| floating_pt_type| string_type| wide_string_type| fixed_pt_const_type| scoped_name ;const_exp: or_expr ;or_expr: xor_expr| or_expr '|' xor_expr { do_binop ($$, IDL_BINOP_OR, $1, $3); } ;xor_expr: and_expr| xor_expr '^' and_expr { do_binop ($$, IDL_BINOP_XOR, $1, $3); } ;and_expr: shift_expr| and_expr '&' shift_expr { do_binop ($$, IDL_BINOP_AND, $1, $3); } ;shift_expr: add_expr| shift_expr TOK_OP_SHR add_expr { do_binop ($$, IDL_BINOP_SHR, $1, $3); }| shift_expr TOK_OP_SHL add_expr { do_binop ($$, IDL_BINOP_SHL, $1, $3); } ;add_expr: mult_expr| add_expr '+' mult_expr { do_binop ($$, IDL_BINOP_ADD, $1, $3); }| add_expr '-' mult_expr { do_binop ($$, IDL_BINOP_SUB, $1, $3); } ;mult_expr: unary_expr| mult_expr '*' unary_expr { do_binop ($$, IDL_BINOP_MULT, $1, $3); }| mult_expr '/' unary_expr { do_binop ($$, IDL_BINOP_DIV, $1, $3); }| mult_expr '%' unary_expr { do_binop ($$, IDL_BINOP_MOD, $1, $3); } ;unary_expr: unary_op primary_expr { do_unaryop ($$, $1, $2); }| primary_expr ;unary_op: '-' { $$ = IDL_UNARYOP_MINUS; }| '+' { $$ = IDL_UNARYOP_PLUS; }| '~' { $$ = IDL_UNARYOP_COMPLEMENT; } ;primary_expr: scoped_name { IDL_tree p, literal; assert (IDL_NODE_TYPE ($1) == IDLN_IDENT); p = IDL_NODE_UP ($1); if ((literal = IDL_resolve_const_exp ($1, IDLN_ANY))) { ++IDL_NODE_REFS (literal); $$ = literal; IDL_tree_free ($1); } else $$ = $1;}| literal| '(' const_exp ')' { $$ = $2; } ;literal: integer_lit| string_lit| char_lit| fixed_pt_lit| floating_pt_lit| boolean_lit ;enum_type: z_props TOK_ENUM { $<str>$ = "enum"; } z_new_ident_catch '{' enumerator_list '}' { $$ = IDL_type_enum_new ($4, $6); assign_props (IDL_TYPE_ENUM ($$).ident, $1);} ;scoped_name: ns_scoped_name { assert ($1 != NULL); assert (IDL_NODE_TYPE ($1) == IDLN_GENTREE); assert (IDL_NODE_TYPE (IDL_GENTREE ($1).data) == IDLN_IDENT); $$ = IDL_GENTREE ($1).data;} ;ns_scoped_name: ns_prev_ident| TOK_OP_SCOPE ns_global_ident { $$ = $2; }| ns_scoped_name TOK_OP_SCOPE ident { IDL_tree p; assert (IDL_NODE_TYPE ($1) == IDLN_GENTREE); assert (IDL_NODE_TYPE ($3) == IDLN_IDENT);#ifdef YYDEBUG if (yydebug) printf ("looking in %s\n", IDL_IDENT (IDL_GENTREE ($1).data).str);#endif if ((p = IDL_ns_lookup_this_scope (__IDL_root_ns, $1, $3, NULL)) == NULL) {#ifdef YYDEBUG if (yydebug) printf ("'%s'\n", IDL_IDENT ($3).str);#endif yyerrorv ("`%s' undeclared identifier", IDL_IDENT ($3).str); IDL_tree_free ($3); YYABORT; } IDL_tree_free ($3);#ifdef REF_IDENTS ++IDL_NODE_REFS (IDL_GENTREE (p).data);#endif $$ = p;} ;enumerator_list: new_ident { $$ = list_start ($1, TRUE); }| enumerator_list check_comma new_ident { $$ = list_chain ($1, $3, TRUE); } ;member_list: member { $$ = list_start ($1, TRUE); }| member_list member { $$ = list_chain ($1, $2, TRUE); } ;member: type_spec declarator_list check_semicolon { char *s; $$ = IDL_member_new ($1, $2); if (IDL_NODE_TYPE ($1) == IDLN_IDENT && g_hash_table_lookup (__IDL_structunion_ht, $1)) { s = IDL_ns_ident_to_qstring (IDL_LIST ($2).data, "::", 0); yyerrorv ("Member `%s'", s); do_token_error (IDL_NODE_UP ($1), "recurses", TRUE); g_free (s); }} ;base_type_spec: floating_pt_type| integer_type| char_type| wide_char_type| boolean_type| octet_type| any_type| object_type| typecode_type ;template_type_spec: sequence_type| string_type| wide_string_type| fixed_pt_type ;sequence_type: TOK_SEQUENCE '<' simple_type_spec ',' positive_int_const '>' { $$ = IDL_type_sequence_new ($3, $5); }| TOK_SEQUENCE '<' simple_type_spec '>' { $$ = IDL_type_sequence_new ($3, NULL); } ;floating_pt_type: TOK_FLOAT { $$ = IDL_type_float_new (IDL_FLOAT_TYPE_FLOAT); }| TOK_DOUBLE { $$ = IDL_type_float_new (IDL_FLOAT_TYPE_DOUBLE); }| TOK_LONG TOK_DOUBLE { $$ = IDL_type_float_new (IDL_FLOAT_TYPE_LONGDOUBLE); } ;fixed_pt_type: TOK_FIXED '<' positive_int_const ',' integer_lit '>' { $$ = IDL_type_fixed_new ($3, $5); } ;fixed_pt_const_type: TOK_FIXED { $$ = IDL_type_fixed_new (NULL, NULL); } ;integer_type: signed_int { $$ = IDL_type_integer_new (TRUE, $1); }| unsigned_int { $$ = IDL_type_integer_new (FALSE, $1); } ;signed_int: signed_short_int { $$ = IDL_INTEGER_TYPE_SHORT; }| signed_long_int { $$ = IDL_INTEGER_TYPE_LONG; }| signed_longlong_int { $$ = IDL_INTEGER_TYPE_LONGLONG; } ;signed_short_int: TOK_SHORT ;signed_long_int: TOK_LONG ;signed_longlong_int: TOK_LONG TOK_LONG ;unsigned_int: unsigned_short_int { $$ = IDL_INTEGER_TYPE_SHORT; }| unsigned_long_int { $$ = IDL_INTEGER_TYPE_LONG; }| unsigned_longlong_int { $$ = IDL_INTEGER_TYPE_LONGLONG; } ;unsigned_short_int: TOK_UNSIGNED TOK_SHORT ;unsigned_long_int: TOK_UNSIGNED TOK_LONG ;unsigned_longlong_int: TOK_UNSIGNED TOK_LONG TOK_LONG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -