浏览代码

fixed identation and added a way to know if a list is empty

master
Nathan R 3 年前
父节点
当前提交
165efe942e
共有 1 个文件被更改,包括 10 次插入4 次删除
  1. +10
    -4
      ccmeta.leg

+ 10
- 4
ccmeta.leg 查看文件

@ -637,32 +637,38 @@ oop new_C_parameter(oop paramSpecifiers, oop declarator) {
OopStack listOfLists= BUFFER_INITIALISER; OopStack listOfLists= BUFFER_INITIALISER;
oop currentList= 0; oop currentList= 0;
int isEmpty = 0;
void listBegin(void) void listBegin(void)
{ {
OopStack_push(&listOfLists, currentList); OopStack_push(&listOfLists, currentList);
currentList= makeMap(); currentList= makeMap();
isEmpty = 1;
} }
void listAppend(oop obj) void listAppend(oop obj)
{ {
assert(currentList); assert(currentList);
map_append(currentList, obj); map_append(currentList, obj);
isEmpty = 0;
} }
void listAppend2(oop obj1, oop obj2) { void listAppend2(oop obj1, oop obj2) {
assert(currentList); assert(currentList);
map_append(currentList, obj1); map_append(currentList, obj1);
map_append(currentList, obj2); map_append(currentList, obj2);
isEmpty = 0;
} }
void listWith(oop obj) { void listWith(oop obj) {
listBegin(); listBegin();
listAppend(obj); listAppend(obj);
isEmpty = 0;
} }
oop listEnd(void) oop listEnd(void)
{ {
if(isEmpty) return null;
assert(currentList); assert(currentList);
oop list= currentList; oop list= currentList;
currentList= OopStack_pop(&listOfLists); currentList= OopStack_pop(&listOfLists);
@ -3871,7 +3877,6 @@ void outputTree(oop node, int depth)
printf("<null>\n"); printf("<null>\n");
return; return;
} }
printSpace(depth);
switch (getType(node)) { switch (getType(node)) {
case Undefined: case Undefined:
return; return;
@ -3905,9 +3910,10 @@ void outputTree(oop node, int depth)
} }
// proto_number is the enum version of the proto symbol // proto_number is the enum version of the proto symbol
proto_t proto_number= get(map_get(proto, __name___symbol), Symbol, prototype); proto_t proto_number= get(map_get(proto, __name___symbol), Symbol, prototype);
printSpace(depth);
switch (proto_number) { switch (proto_number) {
#define CASE(NAME) case t_##NAME:printf("%s:\n", #NAME); #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) CASE(Comment)
OUT(Comment); OUT(Comment);
break; break;
@ -3920,7 +3926,7 @@ void outputTree(oop node, int depth)
/** C terminal nodes */ /** C terminal nodes */
#define CASE(NAME) case t_C_##NAME:printf("%s:\n", #NAME); #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) CASE(int)
OUT(text); OUT(text);
break; break;
@ -3959,7 +3965,7 @@ void outputTree(oop node, int depth)
/** C nodes */ /** C nodes */
#define CASE(NAME) case t_C_##NAME:printf("%s:\n", #NAME); #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) CASE(if)
OUT(ifTok); OUT(ifTok);
OUT(lparen); OUT(lparen);

正在加载...
取消
保存