scp_result resolve_operator_type(sc_memory_context *context, scp_operand *oper, scp_operand *type) { scp_operand arc; MAKE_DEFAULT_ARC_ASSIGN(arc); MAKE_DEFAULT_NODE_ASSIGN((*type)); oper->param_type = SCP_FIXED; scp_iterator3 *it = scp_iterator3_new(context, type, &arc, oper); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it, type, &arc, oper)) { //! TODO Remove temporary check if (SCP_RESULT_TRUE != ifVarAssign(context, type)) continue; type->param_type = SCP_FIXED; if (SCP_RESULT_TRUE == searchElStr3(context, &scp_operator_atomic_type, &arc, type)) { scp_iterator3_free(it); return SCP_RESULT_TRUE; } type->param_type = SCP_ASSIGN; } scp_iterator3_free(it); return SCP_RESULT_FALSE; }
void delete_vars_from_relation(sc_memory_context *context, scp_operand *set, GHashTable *non_erasable_vars) { scp_operand arc1, arc2, elem, rel_elem; scp_iterator5 *it; scp_iterator3 *it0; MAKE_DEFAULT_ARC_ASSIGN(arc1); MAKE_DEFAULT_ARC_ASSIGN(arc2); MAKE_DEFAULT_OPERAND_ASSIGN(elem); MAKE_DEFAULT_OPERAND_ASSIGN(rel_elem); elem.erase = SCP_TRUE; rel_elem.erase = SCP_TRUE; it0 = scp_iterator3_new(context, set, &arc1, &rel_elem); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it0, set, &arc1, &rel_elem)) { rel_elem.param_type = SCP_FIXED; it = scp_iterator5_new(context, &rel_elem, &arc1, &elem, &arc2, &rrel_scp_var); while (SCP_RESULT_TRUE == scp_iterator5_next(context, it, &rel_elem, &arc1, &elem, &arc2, &rrel_scp_var)) { elem.param_type = SCP_FIXED; if (non_erasable_vars != nullptr && FALSE == g_hash_table_contains(non_erasable_vars, MAKE_HASH(elem))) { eraseEl(context, &elem); } elem.param_type = SCP_ASSIGN; } scp_iterator5_free(it); eraseEl(context, &rel_elem); rel_elem.param_type = SCP_ASSIGN; } scp_iterator3_free(it0); }
void cantorize_set(sc_memory_context *context, scp_operand *set) { GHashTable *table; scp_operand elem, arc; MAKE_DEFAULT_ARC_ASSIGN(arc); arc.erase = SCP_TRUE; MAKE_DEFAULT_OPERAND_ASSIGN(elem); table = g_hash_table_new(NULL, NULL); scp_iterator3 *it = scp_iterator3_new(context, set, &arc, &elem); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it, set, &arc, &elem)) { if (TRUE == g_hash_table_contains(table, MAKE_HASH(elem))) { arc.param_type = SCP_FIXED; eraseEl(context, &arc); arc.param_type = SCP_ASSIGN; } else { g_hash_table_add(table, MAKE_HASH(elem)); } } scp_iterator3_free(it); g_hash_table_destroy(table); }
scp_result resolve_ordinal_set_rrel(sc_memory_context *context, scp_operand *arc_param, scp_operand *result) { scp_operand arc; scp_iterator3 *it; MAKE_DEFAULT_ARC_ASSIGN(arc); MAKE_DEFAULT_NODE_ASSIGN((*result)); arc_param->param_type = SCP_FIXED; it = scp_iterator3_new(context, result, &arc, arc_param); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it, result, &arc, arc_param)) { result->param_type = SCP_FIXED; if (SCP_RESULT_TRUE == searchElStr3(context, &ordinal_set_rrel, &arc, result)) { scp_iterator3_free(it); return SCP_RESULT_TRUE; } result->param_type = SCP_ASSIGN; } scp_iterator3_free(it); return SCP_RESULT_FALSE; }
void load_set_to_hash(sc_memory_context *context, scp_operand *set, GHashTable *table) { scp_operand arc1, elem; scp_iterator3 *it; MAKE_DEFAULT_ARC_ASSIGN(arc1); MAKE_DEFAULT_OPERAND_ASSIGN(elem); it = scp_iterator3_new(context, set, &arc1, &elem); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it, set, &arc1, &elem)) { g_hash_table_add(table, MAKE_HASH(elem)); } scp_iterator3_free(it); }
scp_result get_set_power(sc_memory_context *context, scp_operand *set, scp_uint32 *result) { scp_operand arc, node; scp_iterator3 *it; MAKE_DEFAULT_ARC_ASSIGN(arc); MAKE_DEFAULT_OPERAND_ASSIGN(node); (*result) = 0; it = scp_iterator3_new(context, set, &arc, &node); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it, set, &arc, &node)) { (*result)++; } scp_iterator3_free(it); return SCP_RESULT_TRUE; }
scp_result is_procedure_operator_breakpoint(scp_operand *scp_operator) { if (SCP_RESULT_TRUE != find_breakpoints_set()) { return SCP_RESULT_FALSE; } scp_operand arc; MAKE_DEFAULT_ARC_ASSIGN(arc); scp_iterator3 *it = scp_iterator3_new(s_default_ctx, ¤t_breakpoints_set, &arc, &scp_operator); if (SCP_RESULT_TRUE != scp_iterator3_next(s_default_ctx, it, ¤t_breakpoints_set, &arc, &scp_operator)) { printf("Procedure operator "); printEl(s_default_ctx, scp_operator); printf(" isn't breakpoint\n"); return SCP_RESULT_FALSE; } scp_iterator3_free(it); printf("Procedure operator "); printEl(s_default_ctx, scp_operator); printf(" is breakpoint\n"); return SCP_RESULT_TRUE; }
void append_all_relation_elements_to_hash_with_modifiers(sc_memory_context *context, GHashTable *table, scp_operand *set, scp_operand *parameter_set, scp_operand *const_set, scp_operand *vars_set) { scp_operand arc1, arc2, curr_operand, operand_arc, modifier, modifier_arc, operand_element, operand_element_arc, operand_element_modifier, operand_element_modifier_arc; scp_iterator3 *it1, *it2, *it3; MAKE_DEFAULT_ARC_ASSIGN(arc1); MAKE_DEFAULT_ARC_ASSIGN(arc2); MAKE_DEFAULT_ARC_ASSIGN(operand_arc); MAKE_DEFAULT_ARC_ASSIGN(modifier_arc); MAKE_DEFAULT_ARC_ASSIGN(operand_element_arc); MAKE_DEFAULT_ARC_ASSIGN(operand_element_modifier_arc); modifier_arc.erase = SCP_TRUE; operand_element_modifier_arc.erase = SCP_TRUE; MAKE_DEFAULT_OPERAND_ASSIGN(curr_operand); MAKE_DEFAULT_OPERAND_ASSIGN(operand_element); MAKE_DEFAULT_OPERAND_ASSIGN(operand_element_modifier); MAKE_DEFAULT_OPERAND_ASSIGN(modifier); // Operands loop it1 = scp_iterator3_new(context, set, &arc1, &curr_operand); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it1, set, &operand_arc, &curr_operand)) { curr_operand.param_type = SCP_FIXED; operand_arc.param_type = SCP_FIXED; append_to_hash(table, &curr_operand); append_to_hash(table, &operand_arc); // Operand modifiers loop it2 = scp_iterator3_new(context, &modifier, &arc1, &operand_arc); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it2, &modifier, &modifier_arc, &operand_arc)) { modifier.param_type = SCP_FIXED; modifier_arc.param_type = SCP_FIXED; append_to_hash(table, &modifier_arc); modifier_arc.param_type = SCP_ASSIGN; modifier.param_type = SCP_ASSIGN; } scp_iterator3_free(it2); // Operand elements loop it2 = scp_iterator3_new(context, &curr_operand, &operand_element_arc, &operand_element); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it2, &curr_operand, &operand_element_arc, &operand_element)) { operand_element.param_type = SCP_FIXED; operand_element_arc.param_type = SCP_FIXED; append_to_hash(table, &operand_element); append_to_hash(table, &operand_element_arc); // Operand element modifiers loop it3 = scp_iterator3_new(context, &operand_element_modifier, &operand_element_modifier_arc, &operand_element_arc); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it3, &operand_element_modifier, &operand_element_modifier_arc, &operand_element_arc)) { operand_element_modifier.param_type = SCP_FIXED; operand_element_modifier_arc.param_type = SCP_FIXED; // Variable case if (SCP_RESULT_TRUE == ifCoin(context, &rrel_scp_var, &operand_element_modifier)) { if (SCP_RESULT_TRUE == searchElStr5(context, parameter_set, &arc1, &operand_element, &arc2, &rrel_in)) { if (SCP_RESULT_TRUE == ifVarAssign(context, &modifier_arc)) { eraseEl(context, &operand_element_modifier_arc); } genElStr3(context, &rrel_scp_const, &arc1, &operand_element_arc); arc1.param_type = SCP_FIXED; append_to_hash(table, &arc1); arc1.param_type = SCP_ASSIGN; genElStr3(context, const_set, &arc1, &operand_element); } else { append_to_hash(table, &operand_element_modifier_arc); genElStr3(context, vars_set, &arc1, &operand_element); } } else { append_to_hash(table, &operand_element_modifier_arc); // Constant case if (SCP_RESULT_TRUE == ifCoin(context, &rrel_scp_const, &operand_element_modifier)) { genElStr3(context, const_set, &arc1, &operand_element); } } operand_element_modifier_arc.param_type = SCP_ASSIGN; operand_element_modifier.param_type = SCP_ASSIGN; } scp_iterator3_free(it3); operand_element_arc.param_type = SCP_ASSIGN; operand_element.param_type = SCP_ASSIGN; } scp_iterator3_free(it2); operand_arc.param_type = SCP_ASSIGN; curr_operand.param_type = SCP_ASSIGN; } scp_iterator3_free(it1); }
scp_result gen_system_structures(sc_memory_context *context, scp_operand *operator_set, scp_operand *parameter_set, scp_operand *vars_set, scp_operand *const_set, scp_operand *copying_consts_set, scp_operand *operators_copying_pattern) { scp_operand arc1, arc2, curr_operator, operator_arc, operator_type, operator_input, curr_operand, operand_arc, modifier, modifier_arc, operand_arc_pattern; scp_iterator3 *it, *it1, *it2; GHashTable *table = g_hash_table_new(NULL, NULL); scp_bool cop_const = SCP_FALSE, is_const = SCP_FALSE, order_rel = SCP_FALSE; MAKE_DEFAULT_ARC_ASSIGN(arc1); MAKE_DEFAULT_ARC_ASSIGN(arc2); MAKE_DEFAULT_ARC_ASSIGN(operator_arc); MAKE_DEFAULT_OPERAND_ASSIGN(operand_arc); MAKE_DEFAULT_ARC_ASSIGN(modifier_arc); modifier_arc.erase = SCP_TRUE; MAKE_DEFAULT_OPERAND_ASSIGN(curr_operator); MAKE_DEFAULT_OPERAND_ASSIGN(curr_operand); MAKE_DEFAULT_OPERAND_ASSIGN(operator_arc); MAKE_DEFAULT_OPERAND_ASSIGN(operator_type); MAKE_DEFAULT_OPERAND_ASSIGN(operator_input); MAKE_DEFAULT_OPERAND_ASSIGN(modifier); MAKE_DEFAULT_OPERAND_FIXED(operand_arc_pattern); operand_arc_pattern.element_type = scp_type_arc_common | scp_type_const; append_to_hash(table, operator_set); it = scp_iterator3_new(context, operator_set, &operator_arc, &curr_operator); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it, operator_set, &operator_arc, &curr_operator)) { curr_operator.param_type = SCP_FIXED; operator_arc.param_type = SCP_FIXED; if (SCP_RESULT_TRUE == searchElStr3(context, &rrel_init, &arc1, &operator_arc)) { append_to_hash(table, &arc1); } append_to_hash(table, &curr_operator); append_to_hash(table, &operator_arc); // Operator type loop operator_type.param_type = SCP_ASSIGN; operator_input.param_type = SCP_ASSIGN; it1 = scp_iterator3_new(context, &operator_input, &arc1, &curr_operator); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it1, &operator_input, &arc1, &curr_operator)) { operator_input.param_type = SCP_FIXED; if (SCP_RESULT_TRUE == searchElStr3(context, &scp_operator_atomic_type, &arc2, &operator_input)) { append_to_hash(table, &arc1); operator_type.addr = operator_input.addr; operator_input.param_type = SCP_ASSIGN; continue; } if (SCP_RESULT_TRUE == ifCoin(context, &scp_operator_executable_after_all_previous, &operator_input) || SCP_RESULT_TRUE == ifCoin(context, &scp_operator_executable_after_one_of_previous, &operator_input)) { append_to_hash(table, &arc1); operator_input.param_type = SCP_ASSIGN; continue; } operator_input.param_type = SCP_ASSIGN; } scp_iterator3_free(it1); operator_type.param_type = SCP_FIXED; // Operands loop it1 = scp_iterator3_new(context, &curr_operator, &operand_arc, &curr_operand); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it1, &curr_operator, &operand_arc, &curr_operand)) { curr_operand.param_type = SCP_FIXED; operand_arc.param_type = SCP_FIXED; cop_const = SCP_FALSE; is_const = SCP_FALSE; order_rel = SCP_FALSE; //Order relation case operand_arc_pattern.addr = operand_arc.addr; if (SCP_TRUE == ifType(context, &operand_arc_pattern)) { if (SCP_TRUE != searchElStr3(context, operator_set, &arc1, &curr_operand)) { operand_arc.param_type = SCP_ASSIGN; curr_operand.param_type = SCP_ASSIGN; continue; } else { order_rel = SCP_TRUE; } } append_to_hash(table, &curr_operand); append_to_hash(table, &operand_arc); // Operand modifiers loop it2 = scp_iterator3_new(context, &modifier, &modifier_arc, &operand_arc); while (SCP_RESULT_TRUE == scp_iterator3_next(context, it2, &modifier, &modifier_arc, &operand_arc)) { modifier.param_type = SCP_FIXED; modifier_arc.param_type = SCP_FIXED; if (SCP_TRUE == order_rel) { if (SCP_TRUE == ifCoin(context, &nrel_goto, &modifier) || SCP_TRUE == ifCoin(context, &nrel_else, &modifier) || SCP_TRUE == ifCoin(context, &nrel_then, &modifier) || SCP_TRUE == ifCoin(context, &nrel_error, &modifier)) { append_to_hash(table, &modifier_arc); modifier_arc.param_type = SCP_ASSIGN; modifier.param_type = SCP_ASSIGN; break; } else { modifier_arc.param_type = SCP_ASSIGN; modifier.param_type = SCP_ASSIGN; continue; } } if (SCP_RESULT_TRUE == ifCoin(context, &operator_type, &op_call) && SCP_RESULT_TRUE == ifCoin(context, &modifier, ordinal_rrels + 2)) { cop_const = SCP_TRUE; append_all_set_elements_to_hash_with_modifiers(context, table, &curr_operand, parameter_set, const_set, vars_set); } if (((SCP_RESULT_TRUE == ifCoin(context, &operator_type, &op_sys_gen)) || (SCP_RESULT_TRUE == ifCoin(context, &operator_type, &op_sys_search))) && ((SCP_RESULT_TRUE == ifCoin(context, &modifier, ordinal_rrels + 2)) || (SCP_RESULT_TRUE == ifCoin(context, &modifier, ordinal_rrels + 3)))) { cop_const = SCP_TRUE; append_all_relation_elements_to_hash_with_modifiers(context, table, &curr_operand, parameter_set, const_set, vars_set); } // Variable case if (SCP_RESULT_TRUE == ifCoin(context, &rrel_scp_var, &modifier)) { if (SCP_RESULT_TRUE == searchElStr5(context, parameter_set, &arc1, &curr_operand, &arc2, &rrel_in)) { if (SCP_RESULT_TRUE == ifVarAssign(context, &modifier_arc)) { eraseEl(context, &modifier_arc); } genElStr3(context, &rrel_scp_const, &arc1, &operand_arc); arc1.param_type = SCP_FIXED; append_to_hash(table, &arc1); arc1.param_type = SCP_ASSIGN; genElStr3(context, const_set, &arc1, &curr_operand); } else { append_to_hash(table, &modifier_arc); genElStr3(context, vars_set, &arc1, &curr_operand); } } else { //!TODO Check unnesseccary arcs append_to_hash(table, &modifier_arc); // Constant case if (SCP_RESULT_TRUE == ifCoin(context, &rrel_scp_const, &modifier)) { is_const = SCP_TRUE; } } modifier_arc.param_type = SCP_ASSIGN; modifier.param_type = SCP_ASSIGN; } scp_iterator3_free(it2); if (SCP_TRUE == order_rel) { operand_arc.param_type = SCP_ASSIGN; curr_operand.param_type = SCP_ASSIGN; continue; } if (is_const == SCP_TRUE) { if (cop_const == SCP_TRUE) { genElStr3(context, copying_consts_set, &arc1, &curr_operand); } else { genElStr3(context, const_set, &arc1, &curr_operand); } } operand_arc.param_type = SCP_ASSIGN; curr_operand.param_type = SCP_ASSIGN; } scp_iterator3_free(it1); operator_arc.param_type = SCP_ASSIGN; curr_operator.param_type = SCP_ASSIGN; } scp_iterator3_free(it); cantorize_set(context, const_set); cantorize_set(context, copying_consts_set); cantorize_set(context, vars_set); //printEl(copying_consts_set); //printEl(context, vars_set);printEl(context, vars_set); //printEl(context, const_set); //printf("SIZE: %d\n", g_hash_table_size(table)); gen_set_from_hash(table, operators_copying_pattern); g_hash_table_destroy(table); return SCP_RESULT_TRUE; }
sc_result destroy_scp_process(const sc_event *event, sc_addr arg) { scp_operand arc1, arc2, node1, curr_operator, node3, scp_process_node, operator_type, question_node, call_parameters; scp_iterator3 *it; GHashTable *params = nullptr; scp_result params_found; MAKE_DEFAULT_OPERAND_FIXED(arc1); MAKE_DEFAULT_NODE_ASSIGN(scp_process_node); arc1.addr = arg; arc1.element_type = scp_type_arc_pos_const_perm; if (SCP_RESULT_TRUE != ifType(s_default_ctx, &arc1)) { return SC_RESULT_OK; } MAKE_DEFAULT_OPERAND_ASSIGN(node1); if (SCP_RESULT_TRUE != searchElStr3(s_default_ctx, &node1, &arc1, &scp_process_node)) { return SC_RESULT_ERROR; } MAKE_DEFAULT_ARC_ASSIGN(arc1); scp_process_node.param_type = SCP_FIXED; MAKE_DEFAULT_ARC_ASSIGN(arc2); MAKE_DEFAULT_OPERAND_ASSIGN(curr_operator); MAKE_DEFAULT_OPERAND_ASSIGN(question_node); MAKE_DEFAULT_OPERAND_ASSIGN(call_parameters); MAKE_DEFAULT_OPERAND_ASSIGN(node3); node1.erase = SCP_TRUE; curr_operator.erase = SCP_TRUE; node3.erase = SCP_TRUE; MAKE_DEFAULT_OPERAND_ASSIGN(question_node); MAKE_COMMON_ARC_ASSIGN(arc1); params_found = searchElStr5(s_default_ctx, &question_node, &arc1, &scp_process_node, &arc2, &nrel_scp_process); question_node.param_type = SCP_FIXED; MAKE_DEFAULT_ARC_ASSIGN(arc1); if (params_found == SCP_RESULT_TRUE) { MAKE_DEFAULT_OPERAND_ASSIGN(call_parameters); params_found = searchElStr5(s_default_ctx, &question_node, &arc1, &call_parameters, &arc2, &ordinal_rrels[2]); call_parameters.param_type = SCP_FIXED; if (params_found == SCP_RESULT_TRUE) { params = g_hash_table_new(NULL, NULL); load_set_to_hash(s_default_ctx, &call_parameters, params); } } MAKE_DEFAULT_NODE_ASSIGN(operator_type); it = scp_iterator3_new(s_default_ctx, &scp_process_node, &arc1, &curr_operator); while (SCP_RESULT_TRUE == scp_iterator3_next(s_default_ctx, it, &scp_process_node, &arc1, &curr_operator)) { curr_operator.param_type = SCP_FIXED; if (SCP_RESULT_TRUE != resolve_operator_type(s_default_ctx, &curr_operator, &operator_type)) { curr_operator.param_type = SCP_ASSIGN; delete_vars_from_set(s_default_ctx, &curr_operator, params); eraseEl(s_default_ctx, &curr_operator); continue; } operator_type.param_type = SCP_FIXED; if (SCP_RESULT_TRUE == ifCoin(s_default_ctx, &operator_type, &op_call)) { //printf("OPERATOR CALL\n"); if (SCP_RESULT_TRUE == searchElStr5(s_default_ctx, &curr_operator, &arc1, &node3, &arc2, &(ordinal_rrels[2]))) { node3.param_type = SCP_FIXED; delete_vars_from_set(s_default_ctx, &node3, params); eraseEl(s_default_ctx, &node3); node3.param_type = SCP_ASSIGN; } delete_vars_from_set(s_default_ctx, &curr_operator, params); eraseEl(s_default_ctx, &curr_operator); operator_type.param_type = SCP_ASSIGN; curr_operator.param_type = SCP_ASSIGN; continue; } if (SCP_RESULT_TRUE == ifCoin(s_default_ctx, &operator_type, &op_sys_gen) || SCP_RESULT_TRUE == ifCoin(s_default_ctx, &operator_type, &op_sys_search)) { if (SCP_RESULT_TRUE == searchElStr5(s_default_ctx, &curr_operator, &arc1, &node3, &arc2, &(ordinal_rrels[2]))) { node3.param_type = SCP_FIXED; delete_vars_from_relation(s_default_ctx, &node3, params); eraseEl(s_default_ctx, &node3); node3.param_type = SCP_ASSIGN; } if (SCP_RESULT_TRUE == searchElStr5(s_default_ctx, &curr_operator, &arc1, &node3, &arc2, &(ordinal_rrels[3]))) { node3.param_type = SCP_FIXED; delete_vars_from_relation(s_default_ctx, &node3, params); eraseEl(s_default_ctx, &node3); node3.param_type = SCP_ASSIGN; } delete_vars_from_set(s_default_ctx, &curr_operator, params); eraseEl(s_default_ctx, &curr_operator); operator_type.param_type = SCP_ASSIGN; curr_operator.param_type = SCP_ASSIGN; continue; } delete_vars_from_set(s_default_ctx, &curr_operator, params); eraseEl(s_default_ctx, &curr_operator); operator_type.param_type = SCP_ASSIGN; curr_operator.param_type = SCP_ASSIGN; } scp_iterator3_free(it); scp_process_node.erase = SCP_TRUE; eraseEl(s_default_ctx, &scp_process_node); if (SCP_RESULT_TRUE == params_found) { g_hash_table_destroy(params); } //printf("PROCESS DESTROYED SUCCESSFULLY\n"); return SC_RESULT_OK; }