int slang_struct_construct (slang_struct *stru) { stru->a_name = SLANG_ATOM_NULL; stru->fields = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope)); if (stru->fields == NULL) return 0; if (!slang_variable_scope_construct (stru->fields)) { slang_alloc_free (stru->fields); return 0; } stru->structs = (slang_struct_scope *) slang_alloc_malloc (sizeof (slang_struct_scope)); if (stru->structs == NULL) { slang_variable_scope_destruct (stru->fields); slang_alloc_free (stru->fields); return 0; } if (!slang_struct_scope_construct (stru->structs)) { slang_variable_scope_destruct (stru->fields); slang_alloc_free (stru->fields); slang_alloc_free (stru->structs); return 0; } return 1; }
int slang_variable_scope_copy(slang_variable_scope * x, const slang_variable_scope * y) { slang_variable_scope z; unsigned int i; _slang_variable_scope_ctr(&z); z.variables = (slang_variable **) _slang_alloc(y->num_variables * sizeof(slang_variable *)); if (z.variables == NULL) { slang_variable_scope_destruct(&z); return 0; } for (z.num_variables = 0; z.num_variables < y->num_variables; z.num_variables++) { z.variables[z.num_variables] = slang_variable_new(); if (!z.variables[z.num_variables]) { slang_variable_scope_destruct(&z); return 0; } } for (i = 0; i < z.num_variables; i++) { if (!slang_variable_copy(z.variables[i], y->variables[i])) { slang_variable_scope_destruct(&z); return 0; } } z.outer_scope = y->outer_scope; slang_variable_scope_destruct(x); *x = z; return 1; }
int slang_variable_scope_copy (slang_variable_scope *x, const slang_variable_scope *y) { slang_variable_scope z; unsigned int i; if (!slang_variable_scope_construct (&z)) return 0; z.variables = (slang_variable *) slang_alloc_malloc (y->num_variables * sizeof (slang_variable)); if (z.variables == NULL) { slang_variable_scope_destruct (&z); return 0; } for (z.num_variables = 0; z.num_variables < y->num_variables; z.num_variables++) if (!slang_variable_construct (&z.variables[z.num_variables])) { slang_variable_scope_destruct (&z); return 0; } for (i = 0; i < z.num_variables; i++) if (!slang_variable_copy (&z.variables[i], &y->variables[i])) { slang_variable_scope_destruct (&z); return 0; } z.outer_scope = y->outer_scope; slang_variable_scope_destruct (x); *x = z; return 1; }
void slang_struct_destruct (slang_struct *stru) { slang_variable_scope_destruct (stru->fields); slang_alloc_free (stru->fields); slang_struct_scope_destruct (stru->structs); slang_alloc_free (stru->structs); }
void slang_function_destruct (slang_function *func) { slang_variable_destruct (&func->header); slang_variable_scope_destruct (func->parameters); slang_alloc_free (func->parameters); if (func->body != NULL) { slang_operation_destruct (func->body); slang_alloc_free (func->body); } slang_fixup_table_free (&func->fixups); }