function void ast_remove(AST *node){ AST_Parent *l = node->parent; assert(l); if (l->first==l->last){ assert(node==l->last); l->first=l->last=0; } else if (l->last==node){ l->last=l->last->prev; l->last->next=0; } else if (l->first==node){ l->first=l->first->next; l->first->prev=0; } else { node->prev->next=node->next; node->next->prev=node->prev; } node->parent=0; node->prev=0; node->next=0; } function void ast_push_last(AST_Parent *l, AST *node){ if (l->first==0){ l->first=l->last=node; node->prev=0; node->next=0; } else { l->last->next=node; node->prev=l->last; node->next=0; l->last=node; } node->parent=l; } function void ast_push_first(AST_Parent *l, AST *node){ if(l->first == 0){ l->first = l->last = node; node->prev = 0; node->next = 0; } else { node->next = l->first; l->first->prev = node; node->prev = 0; l->first = node; } node->parent = l; } function void ast_push_after(AST *in_list, AST *node){ AST_Parent *parent = in_list->parent; assert(parent); assert(parent->first && parent->last); node->prev = in_list; if(in_list == parent->last){ in_list->next = node; parent->last = node; } else { node->next = in_list->next; in_list->next = node; node->next->prev = node; } node->parent=parent; } function void ast_push_before(AST *in_list, AST *node){ AST_Parent *parent = in_list->parent; assert(parent); assert(parent->first && parent->last); node->next = in_list; if(parent->first == in_list){ in_list->prev = node; parent->first = node; } else{ node->prev = in_list->prev; in_list->prev = node; node->prev->next = node; } node->parent = parent; }