diff options
author | Julian T <julian@jtle.dk> | 2020-10-12 16:26:42 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-10-12 16:54:48 +0200 |
commit | 4e05a55e373bd315e721d534a1711fec4c0054c5 (patch) | |
tree | 4fc0141760c2730ed79aaa4c7aa60ea45cc66cc0 /sem3/osc/miniproject/cnasm/ast.c | |
parent | b7f9cf43c8a9ab3400cbb30d5e1cadb0c6c2cf23 (diff) |
Moved to linux kernel inspired clang-format
Diffstat (limited to 'sem3/osc/miniproject/cnasm/ast.c')
-rw-r--r-- | sem3/osc/miniproject/cnasm/ast.c | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/sem3/osc/miniproject/cnasm/ast.c b/sem3/osc/miniproject/cnasm/ast.c index badf090..cc53e24 100644 --- a/sem3/osc/miniproject/cnasm/ast.c +++ b/sem3/osc/miniproject/cnasm/ast.c @@ -4,101 +4,101 @@ #include <string.h> #include <stdio.h> -static ast_node_t *create_empty_node() { - ast_node_t *n = malloc(sizeof(ast_node_t)); - memset(n, 0, sizeof(ast_node_t)); +static ast_node_t *create_empty_node() +{ + ast_node_t *n = malloc(sizeof(ast_node_t)); + memset(n, 0, sizeof(ast_node_t)); } -ast_node_t *insert_ctrl(enum ntype t, cond_t *c, ast_node_t *iftrue, ast_node_t *iffalse) +ast_node_t *insert_ctrl(enum ntype t, cond_t *c, ast_node_t *iftrue, + ast_node_t *iffalse) { - ast_node_t *n = create_empty_node(); + ast_node_t *n = create_empty_node(); - n->t = t; - n->flowctrl.condition = c; - n->flowctrl.iftrue = iftrue; - n->flowctrl.iffalse = iffalse; + n->t = t; + n->flowctrl.condition = c; + n->flowctrl.iftrue = iftrue; + n->flowctrl.iffalse = iffalse; - return n; + return n; } ast_node_t *insert_for(char *pre, cond_t *c, char *inc, ast_node_t *stuff) { - ast_node_t *n = create_empty_node(); + ast_node_t *n = create_empty_node(); - n->t = TFOR; - n->forloop.condition = c; - n->forloop.pre = pre; - n->forloop.inc = inc; - n->forloop.stuff = stuff; + n->t = TFOR; + n->forloop.condition = c; + n->forloop.pre = pre; + n->forloop.inc = inc; + n->forloop.stuff = stuff; - return n; + return n; } ast_node_t *insert_stm(ast_node_t *stm, ast_node_t *stm_list) { - ast_node_t *n = create_empty_node(); + ast_node_t *n = create_empty_node(); - n->t = TSTM_LIST; - n->list.children[0] = stm_list; - n->list.children[1] = stm; + n->t = TSTM_LIST; + n->list.children[0] = stm_list; + n->list.children[1] = stm; - return n; + return n; } ast_node_t *insert_ident(char *ident) { - ast_node_t *n = create_empty_node(); + ast_node_t *n = create_empty_node(); - n->t = TIDENT; - n->ident = ident; + n->t = TIDENT; + n->ident = ident; - return n; + return n; } cond_t *insert_cond(uint8_t cmp, char *a, char *b) { - cond_t *c = malloc( sizeof(cond_t)); + cond_t *c = malloc(sizeof(cond_t)); - c->cmp = cmp; - c->a = a; - c->b = b; + c->cmp = cmp; + c->a = a; + c->b = b; } void node_print(ast_node_t *node) { - if ( !node ){ - printf("Nil"); - return; - } - switch (node->t) { - case TSTM_LIST: - printf("Stm_list("); - node_print(node->list.children[0]); - printf(","); - node_print(node->list.children[1]); - printf(")"); - break; - case TIF: - printf("If"); - printf("(%s %c %s) {", node->flowctrl.condition->a, - node->flowctrl.condition->cmp, - node->flowctrl.condition->b); - node_print(node->flowctrl.iftrue); - printf("}{"); - node_print(node->flowctrl.iffalse); - printf("}"); - break; - case TIDENT: - printf("%s", node->ident); - break; - case TWHILE: - printf("while"); - printf("(%s %c %s) {", node->flowctrl.condition->a, - node->flowctrl.condition->cmp, - node->flowctrl.condition->b); - node_print(node->flowctrl.iftrue); - printf("}"); - break; - default: - printf("invalid"); - } + if (!node) { + printf("Nil"); + return; + } + switch (node->t) { + case TSTM_LIST: + printf("Stm_list("); + node_print(node->list.children[0]); + printf(","); + node_print(node->list.children[1]); + printf(")"); + break; + case TIF: + printf("If"); + printf("(%s %c %s) {", node->flowctrl.condition->a, + node->flowctrl.condition->cmp, node->flowctrl.condition->b); + node_print(node->flowctrl.iftrue); + printf("}{"); + node_print(node->flowctrl.iffalse); + printf("}"); + break; + case TIDENT: + printf("%s", node->ident); + break; + case TWHILE: + printf("while"); + printf("(%s %c %s) {", node->flowctrl.condition->a, + node->flowctrl.condition->cmp, node->flowctrl.condition->b); + node_print(node->flowctrl.iftrue); + printf("}"); + break; + default: + printf("invalid"); + } } |