📄 util.c
字号:
}IDL_tree IDL_type_wide_string_new (IDL_tree positive_int_const){ IDL_tree p = IDL_node_new (IDLN_TYPE_WIDE_STRING); __IDL_assign_up_node (p, positive_int_const); IDL_TYPE_WIDE_STRING (p).positive_int_const = positive_int_const; return p;}IDL_tree IDL_type_array_new (IDL_tree ident, IDL_tree size_list){ IDL_tree p = IDL_node_new (IDLN_TYPE_ARRAY); __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, size_list); __IDL_assign_location (p, ident); IDL_TYPE_ARRAY (p).ident = ident; IDL_TYPE_ARRAY (p).size_list = size_list; return p;}IDL_tree IDL_type_sequence_new (IDL_tree simple_type_spec, IDL_tree positive_int_const){ IDL_tree p = IDL_node_new (IDLN_TYPE_SEQUENCE); __IDL_assign_up_node (p, simple_type_spec); __IDL_assign_up_node (p, positive_int_const); IDL_TYPE_SEQUENCE (p).simple_type_spec = simple_type_spec; IDL_TYPE_SEQUENCE (p).positive_int_const = positive_int_const; return p;}IDL_tree IDL_type_struct_new (IDL_tree ident, IDL_tree member_list){ IDL_tree p = IDL_node_new (IDLN_TYPE_STRUCT); __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, member_list); __IDL_assign_location (p, ident); IDL_TYPE_STRUCT (p).ident = ident; IDL_TYPE_STRUCT (p).member_list = member_list; return p;}IDL_tree IDL_type_union_new (IDL_tree ident, IDL_tree switch_type_spec, IDL_tree switch_body){ IDL_tree p = IDL_node_new (IDLN_TYPE_UNION); __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, switch_type_spec); __IDL_assign_up_node (p, switch_body); __IDL_assign_location (p, ident); IDL_TYPE_UNION (p).ident = ident; IDL_TYPE_UNION (p).switch_type_spec = switch_type_spec; IDL_TYPE_UNION (p).switch_body = switch_body; return p;}IDL_tree IDL_type_enum_new (IDL_tree ident, IDL_tree enumerator_list){ IDL_tree p = IDL_node_new (IDLN_TYPE_ENUM); __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, enumerator_list); __IDL_assign_location (p, ident); IDL_TYPE_ENUM (p).ident = ident; IDL_TYPE_ENUM (p).enumerator_list = enumerator_list; return p;}IDL_tree IDL_case_stmt_new (IDL_tree labels, IDL_tree element_spec){ IDL_tree p = IDL_node_new (IDLN_CASE_STMT); __IDL_assign_up_node (p, labels); __IDL_assign_up_node (p, element_spec); IDL_CASE_STMT (p).labels = labels; IDL_CASE_STMT (p).element_spec = element_spec; return p;}IDL_tree IDL_interface_new (IDL_tree ident, IDL_tree inheritance_spec, IDL_tree body){ IDL_tree p = IDL_node_new (IDLN_INTERFACE); /* Make sure the up node points to the interface */ if (ident && IDL_NODE_UP (ident) && IDL_NODE_TYPE (IDL_NODE_UP (ident)) != IDLN_INTERFACE) IDL_NODE_UP (ident) = NULL; __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, inheritance_spec); __IDL_assign_up_node (p, body); IDL_INTERFACE (p).ident = ident; IDL_INTERFACE (p).inheritance_spec = inheritance_spec; IDL_INTERFACE (p).body = body; return p;}IDL_tree IDL_module_new (IDL_tree ident, IDL_tree definition_list){ IDL_tree p = IDL_node_new (IDLN_MODULE); __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, definition_list); __IDL_assign_location (p, ident); IDL_MODULE (p).ident = ident; IDL_MODULE (p).definition_list = definition_list; return p;}IDL_tree IDL_binop_new (enum IDL_binop op, IDL_tree left, IDL_tree right){ IDL_tree p = IDL_node_new (IDLN_BINOP); __IDL_assign_up_node (p, left); __IDL_assign_up_node (p, right); IDL_BINOP (p).op = op; IDL_BINOP (p).left = left; IDL_BINOP (p).right = right; return p;}IDL_tree IDL_unaryop_new (enum IDL_unaryop op, IDL_tree operand){ IDL_tree p = IDL_node_new (IDLN_UNARYOP); __IDL_assign_up_node (p, operand); IDL_UNARYOP (p).op = op; IDL_UNARYOP (p).operand = operand; return p;}IDL_tree IDL_codefrag_new (char *desc, GSList *lines){ IDL_tree p = IDL_node_new (IDLN_CODEFRAG); IDL_CODEFRAG (p).desc = desc; IDL_CODEFRAG (p).lines = lines; return p;}IDL_tree IDL_const_dcl_new (IDL_tree const_type, IDL_tree ident, IDL_tree const_exp){ IDL_tree p = IDL_node_new (IDLN_CONST_DCL); __IDL_assign_up_node (p, const_type); __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, const_exp); __IDL_assign_location (p, ident); IDL_CONST_DCL (p).const_type = const_type; IDL_CONST_DCL (p).ident = ident; IDL_CONST_DCL (p).const_exp = const_exp; return p;}IDL_tree IDL_except_dcl_new (IDL_tree ident, IDL_tree members){ IDL_tree p = IDL_node_new (IDLN_EXCEPT_DCL); __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, members); __IDL_assign_location (p, ident); IDL_EXCEPT_DCL (p).ident = ident; IDL_EXCEPT_DCL (p).members = members; return p;}IDL_tree IDL_attr_dcl_new (unsigned f_readonly, IDL_tree param_type_spec, IDL_tree simple_declarations){ IDL_tree p = IDL_node_new (IDLN_ATTR_DCL); __IDL_assign_up_node (p, param_type_spec); __IDL_assign_up_node (p, simple_declarations); __IDL_assign_location (p, IDL_LIST (simple_declarations).data); IDL_ATTR_DCL (p).f_readonly = f_readonly; IDL_ATTR_DCL (p).param_type_spec = param_type_spec; IDL_ATTR_DCL (p).simple_declarations = simple_declarations; return p;}IDL_tree IDL_op_dcl_new (unsigned f_oneway, IDL_tree op_type_spec, IDL_tree ident, IDL_tree parameter_dcls, IDL_tree raises_expr, IDL_tree context_expr){ IDL_tree p = IDL_node_new (IDLN_OP_DCL); __IDL_assign_up_node (p, op_type_spec); __IDL_assign_up_node (p, ident); __IDL_assign_up_node (p, parameter_dcls); __IDL_assign_up_node (p, raises_expr); __IDL_assign_up_node (p, context_expr); __IDL_assign_location (p, ident); IDL_OP_DCL (p).f_oneway = f_oneway; IDL_OP_DCL (p).op_type_spec = op_type_spec; IDL_OP_DCL (p).ident = ident; IDL_OP_DCL (p).parameter_dcls = parameter_dcls; IDL_OP_DCL (p).raises_expr = raises_expr; IDL_OP_DCL (p).context_expr = context_expr; return p;}IDL_tree IDL_param_dcl_new (enum IDL_param_attr attr, IDL_tree param_type_spec, IDL_tree simple_declarator){ IDL_tree p = IDL_node_new (IDLN_PARAM_DCL); __IDL_assign_up_node (p, param_type_spec); __IDL_assign_up_node (p, simple_declarator); __IDL_assign_location (p, simple_declarator); IDL_PARAM_DCL (p).attr = attr; IDL_PARAM_DCL (p).param_type_spec = param_type_spec; IDL_PARAM_DCL (p).simple_declarator = simple_declarator; return p;}IDL_tree IDL_forward_dcl_new (IDL_tree ident){ IDL_tree p = IDL_node_new (IDLN_FORWARD_DCL); __IDL_assign_up_node (p, ident); __IDL_assign_location (p, ident); IDL_FORWARD_DCL (p).ident = ident; return p;}IDL_tree IDL_check_type_cast (const IDL_tree tree, IDL_tree_type type, const char *file, int line, const char *function){ if (__IDL_check_type_casts) { if (tree == NULL) { g_warning ("file %s: line %d: (%s) invalid type cast attempt," " NULL tree to %s\n", file, line, function, IDL_tree_type_names[type]); } else if (IDL_NODE_TYPE (tree) != type) { g_warning ("file %s: line %d: (%s) expected IDL tree type %s," " but got %s\n", file, line, function, IDL_tree_type_names[type], IDL_NODE_TYPE_NAME (tree)); } } return tree;}IDL_tree IDL_gentree_chain_sibling (IDL_tree from, IDL_tree data){ IDL_tree p; if (from == NULL) return NULL; p = IDL_gentree_new_sibling (from, data); IDL_NODE_UP (p) = IDL_NODE_UP (from); return p;}IDL_tree IDL_gentree_chain_child (IDL_tree from, IDL_tree data){ IDL_tree p; if (from == NULL) return NULL; p = IDL_gentree_new (IDL_GENTREE (from).hash_func, IDL_GENTREE (from).key_compare_func, data); IDL_NODE_UP (p) = from; g_hash_table_insert (IDL_GENTREE (from).children, data, p); return p;}IDL_tree IDL_get_parent_node (IDL_tree p, IDL_tree_type type, int *levels){ int count = 0; if (p == NULL) return NULL; if (type == IDLN_ANY) return IDL_NODE_UP (p); while (p != NULL && IDL_NODE_TYPE (p) != type) { if (IDL_NODE_IS_SCOPED (p)) ++count; p = IDL_NODE_UP (p); } if (p != NULL) if (levels != NULL) *levels = count; return p;}IDL_tree IDL_tree_get_scope (IDL_tree p){ g_return_val_if_fail (p != NULL, NULL); if (IDL_NODE_TYPE (p) == IDLN_GENTREE) return p; if (!IDL_NODE_IS_SCOPED (p)) { g_warning ("Node type %s isn't scoped", IDL_NODE_TYPE_NAME (p)); return NULL; } switch (IDL_NODE_TYPE (p)) { case IDLN_IDENT: return IDL_IDENT_TO_NS (p); case IDLN_INTERFACE: return IDL_IDENT_TO_NS (IDL_INTERFACE (p).ident); case IDLN_MODULE: return IDL_IDENT_TO_NS (IDL_MODULE (p).ident); case IDLN_EXCEPT_DCL: return IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (p).ident); case IDLN_OP_DCL: return IDL_IDENT_TO_NS (IDL_OP_DCL (p).ident); case IDLN_TYPE_ENUM: return IDL_IDENT_TO_NS (IDL_TYPE_ENUM (p).ident); case IDLN_TYPE_STRUCT: return IDL_IDENT_TO_NS (IDL_TYPE_STRUCT (p).ident); case IDLN_TYPE_UNION: return IDL_IDENT_TO_NS (IDL_TYPE_UNION (p).ident); default: return NULL; }}typedef struct { IDL_tree_func pre_tree_func; IDL_tree_func post_tree_func; gpointer user_data;} IDLTreeWalkRealData;static void IDL_tree_walk_real (IDL_tree_func_data *tfd, IDLTreeWalkRealData *data){ IDL_tree_func_data down_tfd; gboolean recurse = TRUE; IDL_tree p, q; if (tfd->tree == NULL) return; tfd->state->bottom = tfd; tfd->step = 0; tfd->data = NULL; if (data->pre_tree_func) recurse = (*data->pre_tree_func) (tfd, data->user_data); ++tfd->step; down_tfd.state = tfd->state; down_tfd.up = tfd; p = tfd->tree; if (recurse) switch (IDL_NODE_TYPE (p)) { case IDLN_INTEGER: case IDLN_STRING: case IDLN_CHAR: case IDLN_FIXED: case IDLN_FLOAT: case IDLN_BOOLEAN: case IDLN_IDENT: case IDLN_TYPE_WIDE_CHAR: case IDLN_TYPE_BOOLEAN: case IDLN_TYPE_OCTET: case IDLN_TYPE_ANY: case IDLN_TYPE_OBJECT: case IDLN_TYPE_TYPECODE: case IDLN_TYPE_FLOAT: case IDLN_TYPE_INTEGER: case IDLN_TYPE_CHAR: case IDLN_CODEFRAG: break; case IDLN_LIST: for (q = p; q; q = IDL_LIST (q).next) { down_tfd.tree = IDL_LIST (q).data; IDL_tree_walk_real (&down_tfd, data); } break; case IDLN_GENTREE: g_error ("IDLN_GENTREE walk not implemented!"); break; case IDLN_MEMBER: down_tfd.tree = IDL_MEMBER (p).type_spec; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_MEMBER (p).dcls; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_NATIVE: down_tfd.tree = IDL_NATIVE (p).ident; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_DCL: down_tfd.tree = IDL_TYPE_DCL (p).type_spec; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_TYPE_DCL (p).dcls; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_CONST_DCL: down_tfd.tree = IDL_CONST_DCL (p).const_type; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_CONST_DCL (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_CONST_DCL (p).const_exp; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_EXCEPT_DCL: down_tfd.tree = IDL_EXCEPT_DCL (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_EXCEPT_DCL (p).members; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_ATTR_DCL: down_tfd.tree = IDL_ATTR_DCL (p).param_type_spec; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_ATTR_DCL (p).simple_declarations; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_OP_DCL: down_tfd.tree = IDL_OP_DCL (p).op_type_spec; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_OP_DCL (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_OP_DCL (p).parameter_dcls; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_OP_DCL (p).raises_expr; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_OP_DCL (p).context_expr; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_PARAM_DCL: down_tfd.tree = IDL_PARAM_DCL (p).param_type_spec; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_PARAM_DCL (p).simple_declarator; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_FORWARD_DCL: down_tfd.tree = IDL_FORWARD_DCL (p).ident; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_FIXED: down_tfd.tree = IDL_TYPE_FIXED (p).positive_int_const; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_TYPE_FIXED (p).integer_lit; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_STRING: down_tfd.tree = IDL_TYPE_STRING (p).positive_int_const; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_WIDE_STRING: down_tfd.tree = IDL_TYPE_WIDE_STRING (p).positive_int_const; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_ENUM: down_tfd.tree = IDL_TYPE_ENUM (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_TYPE_ENUM (p).enumerator_list; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_SEQUENCE: down_tfd.tree = IDL_TYPE_SEQUENCE (p).simple_type_spec; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_TYPE_SEQUENCE (p).positive_int_const; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_ARRAY: down_tfd.tree = IDL_TYPE_ARRAY (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_TYPE_ARRAY (p).size_list; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_STRUCT: down_tfd.tree = IDL_TYPE_STRUCT (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_TYPE_STRUCT (p).member_list; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_TYPE_UNION: down_tfd.tree = IDL_TYPE_UNION (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_TYPE_UNION (p).switch_type_spec; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_TYPE_UNION (p).switch_body; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_CASE_STMT: down_tfd.tree = IDL_CASE_STMT (p).labels; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_CASE_STMT (p).element_spec; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_INTERFACE: down_tfd.tree = IDL_INTERFACE (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_INTERFACE (p).inheritance_spec; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_INTERFACE (p).body; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_MODULE: down_tfd.tree = IDL_MODULE (p).ident; IDL_tree_walk_real (&down_tfd, data); down_tfd.tree = IDL_MODULE (p).definition_list; IDL_tree_walk_real (&down_tfd, data); break; case IDLN_BINOP:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -