Identation

This commit is contained in:
petermlm
2016-04-19 23:26:20 +01:00
parent e99b35796c
commit 0037648c49

182
mpc.c
View File

@@ -2811,126 +2811,126 @@ mpc_ast_t *mpc_ast_get_child_lb(mpc_ast_t *ast, const char *tag, int lb) {
mpc_ast_trav_t *mpc_ast_traverse_start(mpc_ast_t *ast, mpc_ast_trav_t *mpc_ast_traverse_start(mpc_ast_t *ast,
mpc_ast_trav_order_t order) mpc_ast_trav_order_t order)
{ {
mpc_ast_trav_t *trav, *n_trav; mpc_ast_trav_t *trav, *n_trav;
mpc_ast_t *cnode = ast; mpc_ast_t *cnode = ast;
/* Create the traversal structure */ /* Create the traversal structure */
trav = malloc(sizeof(mpc_ast_trav_t)); trav = malloc(sizeof(mpc_ast_trav_t));
trav->curr_node = cnode; trav->curr_node = cnode;
trav->parent = NULL; trav->parent = NULL;
trav->curr_child = 0; trav->curr_child = 0;
trav->order = order; trav->order = order;
/* Get start node */ /* Get start node */
switch(order) { switch(order) {
case mpc_ast_trav_order_pre: case mpc_ast_trav_order_pre:
/* Nothing else is needed for pre order start */ /* Nothing else is needed for pre order start */
break; break;
case mpc_ast_trav_order_post: case mpc_ast_trav_order_post:
while(cnode->children_num > 0) { while(cnode->children_num > 0) {
cnode = cnode->children[0]; cnode = cnode->children[0];
n_trav = malloc(sizeof(mpc_ast_trav_t)); n_trav = malloc(sizeof(mpc_ast_trav_t));
n_trav->curr_node = cnode; n_trav->curr_node = cnode;
n_trav->parent = trav; n_trav->parent = trav;
n_trav->curr_child = 0; n_trav->curr_child = 0;
n_trav->order = order; n_trav->order = order;
trav = n_trav; trav = n_trav;
} }
break; break;
default: default:
/* Unreachable, but compiler complaints */ /* Unreachable, but compiler complaints */
break; break;
} }
return trav; return trav;
} }
mpc_ast_t *mpc_ast_traverse_next(mpc_ast_trav_t **trav) { mpc_ast_t *mpc_ast_traverse_next(mpc_ast_trav_t **trav) {
mpc_ast_trav_t *n_trav, *to_free; mpc_ast_trav_t *n_trav, *to_free;
mpc_ast_t *ret = NULL; mpc_ast_t *ret = NULL;
int cchild; int cchild;
/* The end of traversal was reached */ /* The end of traversal was reached */
if(*trav == NULL) return NULL; if(*trav == NULL) return NULL;
switch((*trav)->order) { switch((*trav)->order) {
case mpc_ast_trav_order_pre: case mpc_ast_trav_order_pre:
ret = (*trav)->curr_node; ret = (*trav)->curr_node;
/* If there aren't any more children, go up */ /* If there aren't any more children, go up */
while(*trav != NULL && while(*trav != NULL &&
(*trav)->curr_child >= (*trav)->curr_node->children_num) (*trav)->curr_child >= (*trav)->curr_node->children_num)
{ {
to_free = *trav; to_free = *trav;
*trav = (*trav)->parent; *trav = (*trav)->parent;
free(to_free); free(to_free);
} }
/* If trav is NULL, the end was reached */ /* If trav is NULL, the end was reached */
if(*trav == NULL) { if(*trav == NULL) {
break; break;
} }
/* Go to next child */ /* Go to next child */
n_trav = malloc(sizeof(mpc_ast_trav_t)); n_trav = malloc(sizeof(mpc_ast_trav_t));
cchild = (*trav)->curr_child; cchild = (*trav)->curr_child;
n_trav->curr_node = (*trav)->curr_node->children[cchild]; n_trav->curr_node = (*trav)->curr_node->children[cchild];
n_trav->parent = *trav; n_trav->parent = *trav;
n_trav->curr_child = 0; n_trav->curr_child = 0;
n_trav->order = (*trav)->order; n_trav->order = (*trav)->order;
(*trav)->curr_child++; (*trav)->curr_child++;
*trav = n_trav; *trav = n_trav;
break; break;
case mpc_ast_trav_order_post: case mpc_ast_trav_order_post:
ret = (*trav)->curr_node; ret = (*trav)->curr_node;
/* Move up tree to the parent If the parent doesn't have any more /* Move up tree to the parent If the parent doesn't have any more nodes,
* nodes, then this is the current node. If it does, move down to * then this is the current node. If it does, move down to its left most
* its left most child. Also, free the previous traversal node */ * child. Also, free the previous traversal node */
to_free = *trav; to_free = *trav;
*trav = (*trav)->parent; *trav = (*trav)->parent;
free(to_free); free(to_free);
if(*trav == NULL) if(*trav == NULL)
break; break;
/* Next child */ /* Next child */
(*trav)->curr_child++; (*trav)->curr_child++;
/* If there aren't any more children, this is the next node */ /* If there aren't any more children, this is the next node */
if((*trav)->curr_child >= (*trav)->curr_node->children_num) { if((*trav)->curr_child >= (*trav)->curr_node->children_num) {
break; break;
} }
/* If there are still more children, find the leftmost child from /* If there are still more children, find the leftmost child from this
* this node */ * node */
while((*trav)->curr_node->children_num > 0) { while((*trav)->curr_node->children_num > 0) {
n_trav = malloc(sizeof(mpc_ast_trav_t)); n_trav = malloc(sizeof(mpc_ast_trav_t));
cchild = (*trav)->curr_child; cchild = (*trav)->curr_child;
n_trav->curr_node = (*trav)->curr_node->children[cchild]; n_trav->curr_node = (*trav)->curr_node->children[cchild];
n_trav->parent = *trav; n_trav->parent = *trav;
n_trav->curr_child = 0; n_trav->curr_child = 0;
n_trav->order = (*trav)->order; n_trav->order = (*trav)->order;
*trav = n_trav; *trav = n_trav;
} }
default: default:
/* Unreachable, but compiler complaints */ /* Unreachable, but compiler complaints */
break; break;
} }
return ret; return ret;
} }
mpc_val_t *mpcf_fold_ast(int n, mpc_val_t **xs) { mpc_val_t *mpcf_fold_ast(int n, mpc_val_t **xs) {