void type_delete(struct type *t) { if(!t) return; type_delete(t->subtype); free(t); return; }
//delete a param_list void param_list_delete(struct param_list *p){ if(!p) return; param_list_delete(p->next); type_delete(p->type); free(p); }
void decl_delete( struct decl *d ) { if (!d) return; free( d-> name ); type_delete( d->type ); expr_delete( d->value ); stmt_delete( d->code ); decl_delete( d->next ); free( d ); }
void param_list_delete(struct param_list *p) { if (!p) return; // delete from end of list param_list_delete(p->next); // free node free(p->name); type_delete(p->type); free(p); }
DDS_ReturnCode_t DDS_DomainParticipant_unregister_type (DDS_DomainParticipant dp, DDS_TypeSupport ts, const char *type_name) { TopicType_t *typep; struct type_lookup_st lookup; DDS_ReturnCode_t ret; ctrc_begind (DCPS_ID, DCPS_DP_U_TYPE, &dp, sizeof (dp)); ctrc_contd (&ts, sizeof (ts)); ctrc_contd (type_name, strlen (type_name)); ctrc_endd (); prof_start (dcps_unreg_type); /* Validate some required arguments. */ if (!ts) return (DDS_RETCODE_BAD_PARAMETER); if (!domain_ptr (dp, 1, &ret)) return (ret); /* Search type name in participant type list. */ typep = type_lookup (dp, type_name); if (!typep || #if !defined DDS_TYPECODE typep->type_support != ts || #endif (typep->flags & EF_LOCAL) == 0) { lock_release (dp->lock); return (DDS_RETCODE_ALREADY_DELETED); } /* Type exists and is locally created. Check if there are local topics that are still using the type. */ lookup.type = typep; lookup.nusers = 0; sl_walk (&dp->participant.p_topics, topic_type_check_fct, &lookup); if (lookup.nusers) { if (typep->nrefs > lookup.nusers + 1) { ret = DDS_RETCODE_OK; typep->nrefs--; if (--typep->nlrefs == 0) { typep->flags &= ~EF_LOCAL; DDS_TypeSupport_delete(typep->type_support); } } else ret = DDS_RETCODE_PRECONDITION_NOT_MET; lock_release (dp->lock); /* Still in use! */ return (ret); } if (--typep->nlrefs == 0) { typep->flags &= ~EF_LOCAL; DDS_TypeSupport_delete(typep->type_support); typep->type_support = NULL; } type_delete (dp, typep); lock_release (dp->lock); prof_stop (dcps_unreg_type, 1); return (DDS_RETCODE_OK); }
void stmt_typecheck(struct stmt *s, struct type *ret, int *returned) { if(!s) return; switch(s -> kind) { struct type *expr; struct expr *curr; case STMT_DECL: decl_typecheck(s -> decl); break; case STMT_EXPR: // need to typecheck, but don't need type type_delete(expr_typecheck(s -> expr)); break; case STMT_IF_ELSE: expr = expr_typecheck(s -> expr); if(expr -> kind != TYPE_BOOLEAN) { fprintf(stderr, "TYPE_ERROR: cannot use a(n) "); type_fprint(stderr, expr); fprintf(stderr, " as the if statement expression (currently "); expr_fprint(stderr, s -> expr); fprintf(stderr, ") requires a boolean\n"); type_error_count++; } stmt_typecheck(s -> body, ret, returned); stmt_typecheck(s -> else_body, ret, returned); type_delete(expr); break; case STMT_FOR: type_delete(expr_typecheck(s -> init_expr)); expr = expr_typecheck(s -> expr); // need to check that the middle // expression is actually there if(expr && expr -> kind != TYPE_BOOLEAN) { fprintf(stderr, "TYPE_ERROR: cannot use a "); type_fprint(stderr, expr); fprintf(stderr, " as the middle expression requires a boolean (or an empty expression)\n"); type_error_count++; } type_delete(expr); type_delete(expr_typecheck(s -> next_expr)); stmt_typecheck(s -> body, ret, returned); break; case STMT_WHILE: break; case STMT_PRINT: curr = s -> expr; while(curr) { expr = expr_typecheck(curr); // pass type through new symbol if(!type_is_atomic(expr)) { fprintf(stderr, "TYPE_ERROR: cannot print (print "); expr_fprint(stderr, s -> expr); fprintf(stderr, ") a non-atomic value ("); type_fprint(stderr, expr); fprintf(stderr, ")\n"); type_error_count++; } switch(expr -> kind) { case TYPE_BOOLEAN: curr -> print_type = 1; break; case TYPE_CHARACTER: curr -> print_type = 2; break; case TYPE_INTEGER: curr -> print_type = 3; break; case TYPE_STRING: curr -> print_type = 4; break; case TYPE_ARRAY: curr -> print_type = 0; fprintf(stderr, "Bad entry into switch on type_kind in stmt_typecheck (case STMT_PRINT)\n"); exit(1); break; case TYPE_ARRAY_DECL: curr -> print_type = 0; fprintf(stderr, "Bad entry into switch on type_kind in stmt_typecheck (case STMT_PRINT)\n"); exit(1); break; case TYPE_FUNCTION: curr -> print_type = 0; fprintf(stderr, "Bad entry into switch on type_kind in stmt_typecheck (case STMT_PRINT)\n"); exit(1); break; case TYPE_VOID: curr -> print_type = 0; fprintf(stderr, "Bad entry into switch on type_kind in stmt_typecheck (case STMT_PRINT)\n"); exit(1); break; } type_delete(expr); curr = curr -> next; } break; case STMT_RET: // always set to 1 *returned = 1; expr = expr_typecheck(s -> expr); if(!s -> expr) { type_delete(expr); expr = type_create(TYPE_VOID, 0, 0, 0); } if(!type_compare(expr, ret)) { fprintf(stderr, "TYPE_ERROR: the return statement (return "); expr_fprint(stderr, s -> expr); fprintf(stderr, ") does not match the function return type ("); type_fprint(stderr, ret); fprintf(stderr, ")\n"); type_error_count++; } type_delete(expr); break; case STMT_BLOCK: stmt_typecheck(s -> body, ret, returned); break; } stmt_typecheck(s -> next, ret, returned); }