Mercurial > hg > CbC > old > device
view mc-tree.c @ 18:df7fa8cee67b
pass -Wall
add ifdef
author | kono |
---|---|
date | Sat, 01 Feb 2003 22:19:29 +0900 |
parents | 0529f5abe9d0 |
children | 8500dbb69dd9 |
line wrap: on
line source
/* Micro-C tree print routine */ /* $Id$ */ #define EXTERN /**/ #include "mc.h" extern void tree_print(int e); extern void tree_parse(int e); extern int car(int); typedef struct tree_node { int tree_type; char *tree_name; char *tree_args; } tree_node_type; static tree_node_type tree_nodes[] = { {(-1),"INT",""}, {(-2),"CHAR",""}, {(-3),"UNSIGNED",""}, {(-4),"POINTER","t"}, {(-5),"ARRAY","tv"}, {(-6),"STRUCT","vt"}, {(-7),"UNION",""}, {(-8),"FUNCTION","t"}, {(-9),"EMPTY",""}, {(-10),"STATIC",""}, {(-11),"GOTO",""}, {(-12),"RETURN",""}, {(-13),"BREAK",""}, {(-14),"CONTINUE",""}, {(-15),"IF",""}, {(-16),"ELSE",""}, {(-17),"FOR",""}, {(-18),"DO",""}, {(-19),"WHILE",""}, {(-20),"SWITCH",""}, {(-21),"CASE",""}, {(-22),"DEFAULT",""}, {(-23),"RESERVE",""}, {(-24),"TAG",""}, {(-25),"FIELD",""}, {(-26),"IDENT",""}, {(-27),"STRING",""}, {(-28),"MACRO",""}, {(-29),"BLABEL",""}, {(-30),"FLABEL",""}, {(-31),"TYPEDEF",""}, {(-32),"SIZEOF",""}, {(-33),"TYPE",""}, {(-34),"LONG",""}, {(-35),"SHORT",""}, {(-36),"EXTERN",""}, {(-37),"VOID",""}, {(-38),"REGISTER",""}, {(-39),"CODE",""}, {(-40),"ENVIRONMENT",""}, {(-41),"DEFINED",""}, {1,"GVAR","vs"}, {2,"RGVAR","vs"}, {3,"CRGVAR","vs"}, {4,"LVAR","v"}, {5,"RLVAR","v"}, {6,"CRLVAR","v"}, {7,"CONST","v"}, {8,"FNAME","n"}, {9,"INDIRECT","e"}, {10,"RINDIRECT","e"}, {11,"CRINDIRECT","e"}, {12,"ADDRESS","e"}, {13,"MINUS","e"}, {14,"LNOT","e"}, {15,"BNOT","e"}, {16,"INC",""}, {17,"POSTINC","e"}, {18,"PREINC","e"}, {19,"CPOSTINC","e"}, {20,"CPREINC","e"}, {21,"DEC",""}, {22,"CPOSTDEC","e"}, {23,"CPREDEC","e"}, {24,"MUL","ee"}, {25,"UMUL","ee"}, {26,"DIV","ee"}, {27,"UDIV","ee"}, {28,"MOD","ee"}, {29,"UMOD","ee"}, {30,"ADD","ee"}, {31,"SUB","ee"}, {32,"RSHIFT","ee"}, {33,"URSHIFT","ee"}, {34,"LSHIFT","ee"}, {35,"ULSHIFT","ee"}, {36,"GT","ee"}, {37,"UGT","ee"}, {38,"GE","ee"}, {39,"UGE","ee"}, {40,"LT","ee"}, {41,"ULT","ee"}, {42,"LE","ee"}, {43,"ULE","ee"}, {44,"EQ","ee"}, {45,"NEQ","ee"}, {46,"BAND","ee"}, {47,"EOR","ee"}, {48,"BOR","ee"}, {49,"LAND","ee"}, {50,"LOR","ee"}, {51,"COND","eee"}, {52,"ASS","ee"}, {53,"CASS","ee"}, {54,"ASSOP","eev"}, {55,"CASSOP","eev"}, {56,"COMMA","ee"}, {57,"LPAR",""}, {58,"RPAR",""}, {59,"LBRA",""}, {60,"RBRA",""}, {61,"LC",""}, {62,"RC",""}, {63,"COLON","ee"}, {64,"SM",""}, {65,"PERIOD",""}, {66,"ARROW",""}, {66,"CNAME",""}, {100,"AS",""} }; void tree_print(int e) { printf("* generate code on type:\n* "); tree_parse(type); printf("\n* expr:\n* "); tree_parse(e); printf("\n"); } static int tree_level; void tree_parse(int e) { tree_node_type *t; int i,j; char *s; if(e<0) { for(t=tree_nodes;t->tree_type!=100;t++) { if(t->tree_type==e) { for(j=0;j<tree_level;j++) putchar(' '); printf("list(%s)",t->tree_name); break; } } } else { i = car(e); for(t=tree_nodes;t->tree_type!=100;t++) { if(t->tree_type==i) { tree_level++; for(j=0;j<tree_level;j++) putchar(' '); printf("list(%s",t->tree_name); for(i=1,s=t->tree_args;*s;s++,i++) { switch(*s) { case 'e': case 't': printf(",\n*"); tree_parse(heap[e+i]); break; case 'v': printf(",%d",heap[e+i]); break; case 'n': printf(",%s",((NMTBL *)heap[e+i])->nm); break; case 's': printf(",%s",(char *)heap[e+i]); break; case 'i': printf(",%d",heap[e+i]); break; } } tree_level--; printf(")"); break; } } } }