From 165efe942e2994e72cf89754acffc513740405fe Mon Sep 17 00:00:00 2001 From: Nathan R Date: Sun, 22 Aug 2021 16:53:34 +0200 Subject: [PATCH] fixed identation and added a way to know if a list is empty --- ccmeta.leg | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ccmeta.leg b/ccmeta.leg index 8018d29..05c5641 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -637,32 +637,38 @@ oop new_C_parameter(oop paramSpecifiers, oop declarator) { OopStack listOfLists= BUFFER_INITIALISER; oop currentList= 0; +int isEmpty = 0; void listBegin(void) { OopStack_push(&listOfLists, currentList); currentList= makeMap(); + isEmpty = 1; } void listAppend(oop obj) { assert(currentList); map_append(currentList, obj); + isEmpty = 0; } void listAppend2(oop obj1, oop obj2) { assert(currentList); map_append(currentList, obj1); map_append(currentList, obj2); + isEmpty = 0; } void listWith(oop obj) { listBegin(); listAppend(obj); + isEmpty = 0; } oop listEnd(void) { + if(isEmpty) return null; assert(currentList); oop list= currentList; currentList= OopStack_pop(&listOfLists); @@ -3871,7 +3877,6 @@ void outputTree(oop node, int depth) printf("\n"); return; } - printSpace(depth); switch (getType(node)) { case Undefined: return; @@ -3905,9 +3910,10 @@ void outputTree(oop node, int depth) } // proto_number is the enum version of the proto symbol proto_t proto_number= get(map_get(proto, __name___symbol), Symbol, prototype); + printSpace(depth); switch (proto_number) { #define CASE(NAME) case t_##NAME:printf("%s:\n", #NAME); -#define OUT(NAME) outputTree(map_get(node, text_symbol), depth+DELTA); +#define OUT(NAME) printSpace(depth+DELTA) ; outputTree(map_get(node, text_symbol), 0); CASE(Comment) OUT(Comment); break; @@ -3920,7 +3926,7 @@ void outputTree(oop node, int depth) /** C terminal nodes */ #define CASE(NAME) case t_C_##NAME:printf("%s:\n", #NAME); -#define OUT(NAME) outputTree(map_get(node, NAME##_symbol), depth+DELTA); +#define OUT(NAME) printSpace(depth+DELTA) ; outputTree(map_get(node, NAME##_symbol), 0); CASE(int) OUT(text); break; @@ -3959,7 +3965,7 @@ void outputTree(oop node, int depth) /** C nodes */ #define CASE(NAME) case t_C_##NAME:printf("%s:\n", #NAME); -#define OUT(NAME) printSpace(depth+DELTA); printf("(%s)\n", #NAME); outputTree(map_get(node, NAME##_symbol), depth+2*DELTA); +#define OUT(NAME) printSpace(depth+DELTA) ; printf("(%s)\n", #NAME); outputTree(map_get(node, NAME##_symbol), depth+2*DELTA); CASE(if) OUT(ifTok); OUT(lparen);