void ast_clear(ast_t* ast) { if(ast->symtab != NULL) { symtab_free(ast->symtab); ast_scope(ast); } ast_t* child = ast->child; while(child != NULL) { ast_clear(child); child = child->sibling; } }
static bool capture_from_type(pass_opt_t* opt, ast_t* ctx, ast_t** def, ast_t* capture, ast_t** last_capture) { // Turn any free variables into fields. if(!ast_passes_type(def, opt, PASS_SCOPE)) return false; bool ok = true; ast_t* members = ast_childidx(*def, 4); for(ast_t* p = ast_child(members); p != NULL; p = ast_sibling(p)) { switch(ast_id(p)) { case TK_FUN: case TK_BE: { if(ast_id(ast_child(p)) != TK_AT) { ast_t* body = ast_childidx(p, 6); if(!capture_from_expr(opt, ctx, body, capture, last_capture)) ok = false; } break; } default: {} } } // Reset the scope. ast_clear(*def); return ok; }
void ast_delete(struct ast_t *a) { ast_clear(a); free(a); }