annotate mc-tree.c @ 680:f536897fa3cb

*** empty log message ***
author kono
date Sun, 29 Jul 2007 23:09:38 +0900
parents 3e1dba5758d8
children e16b34f2b386
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
0529f5abe9d0 *** empty log message ***
kono
parents: 0
diff changeset
1 /* Micro-C tree print routine */
607
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
2
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
3 /************************************************************************
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
4 ** Copyright (C) 2006 Shinji Kono
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
5 ** 連絡先: 琉球大学情報工学科 河野 真治
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
6 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
7 **
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
8 ** このソースのいかなる複写,改変,修正も許諾します。ただし、
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
9 ** その際には、誰が貢献したを示すこの部分を残すこと。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
10 ** 再配布や雑誌の付録などの問い合わせも必要ありません。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
11 ** 営利利用も上記に反しない範囲で許可します。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
12 ** バイナリの配布の際にはversion messageを保存することを条件とします。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
13 ** このプログラムについては特に何の保証もしない、悪しからず。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
14 **
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
15 ** Everyone is permitted to do anything on this program
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
16 ** including copying, modifying, improving,
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
17 ** as long as you don't try to pretend that you wrote it.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
18 ** i.e., the above copyright notice has to appear in all copies.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
19 ** Binary distribution requires original version messages.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
20 ** You don't have to ask before copying, redistribution or publishing.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
21 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
22 ***********************************************************************/
1
0529f5abe9d0 *** empty log message ***
kono
parents: 0
diff changeset
23
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 81
diff changeset
24 #include <stdio.h>
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
25 #include "mc.h"
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 81
diff changeset
26 #include "mc-parse.h"
596
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
27 #include "mc-codegen.h"
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
28
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
29 extern void tree_print(int e);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
30 extern void tree_parse(int e);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
31 extern void tree_print_t(int e,int t);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
32 extern void type_print(int type,NMTBL *n,FILE *out);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
33 extern void type_print1(int type,NMTBL *n,FILE *out,int cont);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
34 extern void sym_print(int type,FILE *out);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
35 static void print_function_call(int e, FILE *out);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
36 static void print_operator(int e, FILE *vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
37 static void print_statement(int e, FILE *vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
38
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
39 /* ascendant order for binary search */
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
40
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
41 typedef
d35df41eac69 Initial revision
kono
parents:
diff changeset
42 struct tree_node {
d35df41eac69 Initial revision
kono
parents:
diff changeset
43 int tree_type;
d35df41eac69 Initial revision
kono
parents:
diff changeset
44 char *tree_name;
d35df41eac69 Initial revision
kono
parents:
diff changeset
45 char *tree_args;
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
46 int tree_order;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
47 } tree_node_type;
d35df41eac69 Initial revision
kono
parents:
diff changeset
48
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
49 static int
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
50 tree_nodes(int id, char **name, char **args, int *order) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
51 int found = 1;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
52 switch(id%SOP) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
53 case DOTS: *name = "..."; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
54 case LMACRO: *name = "lmacro"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
55 case FMACRO: *name = "fmacro"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
56 case KONST: *name = "const"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
57 case DEFINED: *name = "defined"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
58 case ENVIRONMENT: *name = "environment"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
59 case CODE: *name = "code"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
60 case C_FILE: *name = "__FILE__"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
61 case C_FUNCTION: *name = "__FUNCTION__"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
62 case C_LINE: *name = "__LINE__"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
63 case REGISTER: *name = "register"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
64 case CAST: *name = "cast"; *args="e"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
65 case ASM: *name = "__asm__"; *args="eeee"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
66 case ST_ASM: *name = "__asm__"; *args="eeee"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
67 case VOID: *name = "void"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
68 case EXTRN: *name = "extern"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
69 case EXTRN1: *name = "extern"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
70 case SHORT: *name = "short"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
71 case USHORT: *name = "unsigned short"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
72 case LONG: *name = "long"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
73 case TYPE: *name = "type"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
74 case VOLATILE: *name = "volatile"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
75 case SIZEOF: *name = "sizeof"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
76 case TYPEDEF: *name = "typedef"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
77 case FLABEL: *name = "flabel"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
78 case BLABEL: *name = "blabel"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
79 case LABEL: *name = "label"; *args="e"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
80 case ST_LABEL: *name = "label"; *args="e"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
81 case MACRO: *name = "macro"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
82 case STRING: *name = "string"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
83 case IDENT: *name = "ident"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
84 case ENUM: *name = "enum"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
85 case FIELD: *name = "field"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
86 case TAG: *name = "tag"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
87 case RESERVE: *name = "reserve"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
88 case ST_DEFAULT: *name = "default"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
89 case ATTRIBUTE: *name = "__attribute__"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
90 case ST_CASE: *name = "case"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
91 case ST_SWITCH: *name = "switch"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
92 case ST_WHILE: *name = "while"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
93 case ST_DO: *name = "do"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
94 case ST_FOR: *name = "for"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
95 case ELSE: *name = "else"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
96 case ST_IF: *name = "if"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
97 case CONTINUE: *name = "continue"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
98 case BREAK: *name = "break"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
99 case ST_RETURN: *name = "return"; *args="e"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
100 case RETURN: *name = "return"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
101 case ST_GOTO: *name = "goto"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
102 case JUMP: *name = "goto"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
103 case STATIC: *name = "static"; *args=""; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
104 case EMPTY: *name = "empty"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
105 case FUNCTION: *name = "function"; *args="t"; *order=15; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
106 case UNION: *name = "union"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
107 case STRUCT: *name = "struct"; *args="vt"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
108 case ARRAY: *name = "array"; *args="tv"; *order=16; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
109 case POINTER: *name = "*"; *args="t"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
110 case UNSIGNED: *name = "unsigned"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
111 case INLINE: *name = "inline"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
112 case SIGNED: *name = "signed"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
113 case CHAR: *name = "char"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
114 case UCHAR: *name = "unsigned char"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
115 case INT: *name = "int"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
116 case FLOAT: *name = "float"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
117 case DOUBLE: *name = "double"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
118 case LONGLONG: *name = "long long"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
119 case ULONGLONG: *name = "unsigned long long"; *args=""; *order=-1; break;
37
412ad2e6c2a2 struct copy
kono
parents: 33
diff changeset
120
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
121 case GVAR: *name = "gvar"; *args="vs"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
122 case IVAR: *name = "ivar"; *args="vs"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
123 case RGVAR: *name = "rgvar"; *args="vs"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
124 case CRGVAR: *name = "crgvar"; *args="vs"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
125 case LVAR: *name = "lvar"; *args="v"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
126 case RLVAR: *name = "rlvar"; *args="v"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
127 case CRLVAR: *name = "crlvar"; *args="v"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
128 case CONST: *name = "const"; *args="v"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
129 case FNAME: *name = "fname"; *args="n"; *order=14; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
130 case MUL: *name = "*"; *args="e"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
131 case RINDIRECT: *name = "*"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
132 case CRINDIRECT: *name = "*"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
133 case ADDRESS: *name = "&"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
134 case BAND: *name = "&"; *args="e"; *order=7; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
135 case MINUS: *name = "-"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
136 case LNOT: *name = "!"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
137 case BNOT: *name = "~"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
138 case INC: *name = "++"; *args=""; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
139 case ALLOCA: *name = "alloca"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
140 case BUILTINP: *name = "__builtinp"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
141 case BUILTIN_EXPECT: *name = "__builtin_expect"; *args="ee"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
142 case BUILTIN_FABSF: *name = "__builtin_fabsf"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
143 case BUILTIN_FABS: *name = "__builtin_fbas"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
144 case BUILTIN_FABSL: *name = "__builtin_fbasl"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
145 case BUILTIN_INFF: *name = "__builtin_inff"; *args=""; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
146 case BUILTIN_INF: *name = "__builtin_inf"; *args=""; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
147 case BUILTIN_INFL: *name = "__builtin_infl"; *args=""; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
148 case POSTINC: *name = "++"; *args="ee"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
149 case BPOSTINC: *name = "++"; *args="ee"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
150 case PREINC: *name = "++"; *args="ee"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
151 case CPOSTINC: *name = "++"; *args="ee"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
152 case CPREINC: *name = "++"; *args="ee"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
153 case DEC: *name = "--"; *args="e"; *order=13; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
154 case DIV: *name = "/"; *args="ee"; *order=12; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
155 case UDIV: *name = "/"; *args="ee"; *order=12; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
156
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
157 case UMUL: *name = "*"; *args="ee"; *order=12; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
158 case MOD: *name = "%"; *args="ee"; *order=12; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
159 case UMOD: *name = "%"; *args="ee"; *order=12; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
160 case ADD: *name = "+"; *args="ee"; *order=11; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
161 case SUB: *name = "-"; *args="ee"; *order=11; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
162 case RSHIFT: *name = ">>"; *args="ee"; *order=10; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
163 case URSHIFT: *name = ">>"; *args="ee"; *order=10; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
164 case LSHIFT: *name = "<<"; *args="ee"; *order=10; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
165 case ULSHIFT: *name = "<<"; *args="ee"; *order=10; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
166 case GT: *name = ">"; *args="ee"; *order=9; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
167 case UGT: *name = ">"; *args="ee"; *order=9; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
168 case GE: *name = ">="; *args="ee"; *order=9; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
169 case UGE: *name = ">="; *args="ee"; *order=9; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
170 case LT: *name = "<"; *args="ee"; *order=9; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
171 case ULT: *name = "<"; *args="ee"; *order=9; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
172 case LE: *name = "<="; *args="ee"; *order=9; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
173 case ULE: *name = "<="; *args="ee"; *order=9; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
174 case EQ: *name = "=="; *args="ee"; *order=8; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
175 case NEQ: *name = "!="; *args="ee"; *order=8; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
176
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
177 case EOR: *name = "^"; *args="ee"; *order=6; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
178 case BOR: *name = "|"; *args="ee"; *order=5; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
179 case LAND: *name = "&&"; *args="ee"; *order=4; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
180 case LOR: *name = "||"; *args="ee"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
181 case COND: *name = "?"; *args="eee"; *order=2; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
182 case ASS: *name = "="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
183 case ASSOP: *name = "assop"; *args="eev"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
184 case CASSOP: *name = "cassop"; *args="eev"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
185 case COMMA: *name = "; *args=","ee"; *order=0; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
186 case LPAR: *name = "("; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
187 case RPAR: *name = ")"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
188 case LBRA: *name = "["; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
189 case RBRA: *name = "]"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
190 case LC: *name = "{"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
191 case RC: *name = "}"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
192 case COLON: *name = ":"; *args="ee"; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
193 case SM: *name = ";"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
194 case PERIOD: *name = "."; *args=""; *order=16; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
195 case ARROW: *name = "->"; *args=""; *order=16; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
196 case SASS: *name = "sass"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
197 case RSTRUCT: *name = "rstruct"; *args=""; *order=-1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
198 case AS+MUL: *name = "*="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
199 case AS+UMUL: *name = "*="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
200 case AS+DIV: *name = "/="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
201 case AS+UDIV: *name = "/="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
202 case AS+MOD: *name = "%="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
203 case AS+UMOD: *name = "%="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
204 case AS+ADD: *name = "+="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
205 case AS+MINUS: *name = "-="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
206 case AS+RSHIFT: *name = ">>="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
207 case AS+URSHIFT: *name = ">>="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
208 case AS+LSHIFT: *name = "<<="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
209 case AS+ULSHIFT: *name = "<<="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
210 case AS+BAND: *name = "&="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
211 case AS+EOR: *name = "^="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
212 case AS+BOR: *name = "|="; *args="ee"; *order=1; break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
213 default: found = 0;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
214 fprintf(stderr,"Unknown ID %d [%d]in find node\n",id,OP(id));
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
215
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
216 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
217 return found;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
218 }
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
219
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
220 static int
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
221 attr_print(int t)
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
222 {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
223 while (t>0 && car(t)==ATTRIBUTE) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
224 switch (caddr(t)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
225 case KONST: printf( "const"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
226 case VOLATILE: printf( "volatile"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
227 case RESTRICT: printf( "restrict"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
228 case INLINE: printf( "inline"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
229 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
230 t = cadr(t);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
231 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
232 return t;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
233 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
234
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
235 void
50
kono
parents: 37
diff changeset
236 tree_print_t(int e,int t)
kono
parents: 37
diff changeset
237 {
kono
parents: 37
diff changeset
238 printf("# type: ");
kono
parents: 37
diff changeset
239 tree_print(t);
kono
parents: 37
diff changeset
240 printf("expr: ");
kono
parents: 37
diff changeset
241 tree_print(e);
kono
parents: 37
diff changeset
242 printf("\n");
kono
parents: 37
diff changeset
243 }
kono
parents: 37
diff changeset
244
kono
parents: 37
diff changeset
245 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
246 tree_print(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
247 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
248 printf("* generate code on type:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
249 tree_parse(type);
d35df41eac69 Initial revision
kono
parents:
diff changeset
250 printf("\n* expr:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
251 tree_parse(e);
d35df41eac69 Initial revision
kono
parents:
diff changeset
252 printf("\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
253 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
254
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
255 static
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
256 int tree_level;
d35df41eac69 Initial revision
kono
parents:
diff changeset
257
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
258 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
259 tree_parse(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
260 {
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
261 tree_node_type node_type,*t;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
262 int i,j;
d35df41eac69 Initial revision
kono
parents:
diff changeset
263 char *s;
d35df41eac69 Initial revision
kono
parents:
diff changeset
264
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
265 t = &node_type; t->tree_type=e;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
266
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
267 if(e<0) {
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
268 if (tree_nodes(e,&t->tree_name,&t->tree_args,&t->tree_order)) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
269 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
270 printf("list(%s)",t->tree_name);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
271 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
272 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
273 i = car(e);
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
274 if (tree_nodes(e,&t->tree_name,&t->tree_args,&t->tree_order)) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
275 tree_level++;
254a0c576114 argument type list
kono
parents: 50
diff changeset
276 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
277 printf("list(%s",t->tree_name);
254a0c576114 argument type list
kono
parents: 50
diff changeset
278 for(i=1,s=t->tree_args;*s;s++,i++) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
279 switch(*s) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
280 case 'e':
254a0c576114 argument type list
kono
parents: 50
diff changeset
281 case 't':
254a0c576114 argument type list
kono
parents: 50
diff changeset
282 printf(",\n*");
254a0c576114 argument type list
kono
parents: 50
diff changeset
283 tree_parse(heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
284 case 'v':
254a0c576114 argument type list
kono
parents: 50
diff changeset
285 printf(",%d",heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
286 case 'n':
254a0c576114 argument type list
kono
parents: 50
diff changeset
287 printf(",%s",((NMTBL *)heap[e+i])->nm); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
288 case 's':
254a0c576114 argument type list
kono
parents: 50
diff changeset
289 printf(",%s",(char *)heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
290 case 'i':
254a0c576114 argument type list
kono
parents: 50
diff changeset
291 printf(",%d",heap[e+i]); break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
292 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
293 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
294 tree_level--;
254a0c576114 argument type list
kono
parents: 50
diff changeset
295 printf(")");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
296 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
297 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
298 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
299
254a0c576114 argument type list
kono
parents: 50
diff changeset
300 void struct_type_print(int type,FILE *out)
254a0c576114 argument type list
kono
parents: 50
diff changeset
301 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
302 NMTBL *n;
254a0c576114 argument type list
kono
parents: 50
diff changeset
303 int tags;
254a0c576114 argument type list
kono
parents: 50
diff changeset
304 if((n=(NMTBL*)cadddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
305 fprintf(out,"%s ",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
306 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
307 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
308 if((tags=caddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
309 fprintf(out,"{");
254a0c576114 argument type list
kono
parents: 50
diff changeset
310 while(tags) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
311 n=(NMTBL*)caddr(tags);
254a0c576114 argument type list
kono
parents: 50
diff changeset
312 type_print(car(tags),n,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
313 fprintf(out,";");
254a0c576114 argument type list
kono
parents: 50
diff changeset
314 tags = cadr(tags);
254a0c576114 argument type list
kono
parents: 50
diff changeset
315 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
316 fprintf(out,"}");
254a0c576114 argument type list
kono
parents: 50
diff changeset
317 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
318 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
319
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
320 void function_type_print1(int type,NMTBL *n,FILE *out,int cont)
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
321 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
322 int args;
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
323 type_print1(cadr(type),0,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
324 if(n) fprintf(out," %s",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
325 fprintf(out,"(");
254a0c576114 argument type list
kono
parents: 50
diff changeset
326 if((args=caddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
327 while (args) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
328 type_print(car(args),0,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
329 args=cadr(args);
254a0c576114 argument type list
kono
parents: 50
diff changeset
330 if (args) fprintf(out,",");
254a0c576114 argument type list
kono
parents: 50
diff changeset
331 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
332 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
333 fprintf(out,")");
254a0c576114 argument type list
kono
parents: 50
diff changeset
334 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
335
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
336 void function_type_print(int type,NMTBL *n,FILE *out)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
337 {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
338 function_type_print1(type,n,out,0);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
339 }
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
340
68
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
341 void sym_print(int sym,FILE *out)
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
342 {
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
343 tree_node_type tn;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
344 if (!(tree_nodes(sym,&tn.tree_name,&tn.tree_args,&tn.tree_order))) { error(-1); return; }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
345 fprintf(out,"%s",tn.tree_name);
68
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
346 }
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
347
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
348 NMTBL *
468
464e7480395c *** empty log message ***
kono
parents: 327
diff changeset
349 typedef_search(int t,int type)
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
350 {
2e84590720a6 typedef name
kono
parents: 69
diff changeset
351 while(t) {
2e84590720a6 typedef name
kono
parents: 69
diff changeset
352 if (((NMTBL*)car(t))->ty==type)
2e84590720a6 typedef name
kono
parents: 69
diff changeset
353 return (NMTBL*)car(t);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
354 t=cadr(t);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
355 }
2e84590720a6 typedef name
kono
parents: 69
diff changeset
356 return 0;
2e84590720a6 typedef name
kono
parents: 69
diff changeset
357 }
2e84590720a6 typedef name
kono
parents: 69
diff changeset
358
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
359 static void n_attr_print(int attr, FILE *out)
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
360 {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
361 for(;attr;attr=cadr(attr)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
362 switch(car(attr)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
363 case INLINE: fprintf(out,"inline "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
364 case CONST: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
365 case VOLATILE: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
366 case RESTRICT: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
367 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
368 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
369 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
370
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
371 void type_print1(int type,NMTBL *n,FILE *out,int cont)
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
372 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
373 int t;
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
374 tree_node_type *tn,tn0;
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
375 NMTBL *td;
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
376 int args;
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
377 tn = &tn0;
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
378
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
379 if (n) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
380 if (n->attr) n_attr_print(n->attr,out);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
381 while(type>0 && car(type)==ATTRIBUTE) type=cadr(type);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
382 } else
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
383 type = attr_print(type);
75
92dcf107a837 c code output
kono
parents: 74
diff changeset
384 if(type>0&&(td=typedef_search(typedefed,type))) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
385 if (!cont)
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
386 fprintf(out,"%s ",td->nm);
75
92dcf107a837 c code output
kono
parents: 74
diff changeset
387 } else if(type>0&&(td=typedef_search(gtypedefed,type))) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
388 if (!cont)
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
389 fprintf(out,"%s ",td->nm);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
390 } else if (type<0) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
391 t=type;
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
392 if (!(tree_nodes(t,&tn->tree_name,&tn->tree_args,&tn->tree_order))) { error(-1); return; }
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
393 if (!cont)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
394 fprintf(out,"%s ",tn->tree_name);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
395 } else if ((t=car(type))) {
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
396 if (!(tree_nodes(t,&tn->tree_name,&tn->tree_args,&tn->tree_order))) { error(-1); return; }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
397 if(t==STRUCT||t==UNION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
398 if (!cont) {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
399 fprintf(out,"%s ",tn->tree_name);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
400 struct_type_print(type,out);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
401 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
402 } else if(t==CODE) {
596
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
403 // if (!cont) { fprintf(out,"%s ",tn->tree_name); }
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
404 function_type_print1(type,n,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
405 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
406 } else if(t==FUNCTION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
407 function_type_print1(type,n,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
408 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
409 } else if(t==ARRAY) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
410 type_print1(cadr(type),n,out,cont);
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
411 if (caddr(type))
2e84590720a6 typedef name
kono
parents: 69
diff changeset
412 fprintf(out,"[%d]",caddr(type));
2e84590720a6 typedef name
kono
parents: 69
diff changeset
413 else
2e84590720a6 typedef name
kono
parents: 69
diff changeset
414 fprintf(out,"[]");
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
415 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
416 } else if(t==POINTER) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
417 t=cadr(type);
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
418 if(t<0) {
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
419 type_print1(t,0,out,cont);
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
420 fprintf(out,"*");
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
421 } else if(car(t)==FUNCTION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
422 type_print1(cadr(t),0,out,cont);
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
423 fprintf(out,"(*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
424 if(n) fprintf(out,"%s",n->nm);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
425 fprintf(out,")");
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
426 fprintf(out,"(");
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
427 if((args=caddr(t))) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
428 while (args) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
429 type_print(car(args),0,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
430 args=cadr(args);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
431 if (args) fprintf(out,",");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
432 }
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
433 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
434 fprintf(out,")");
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
435 return;
596
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
436 } else if(car(t)==CODE) {
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
437 type_print1(cadr(t),0,out,cont);
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
438 fprintf(out,"(*");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
439 if(n) fprintf(out,"%s",n->nm);
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
440 fprintf(out,")");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
441 fprintf(out,"(");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
442 if((args=caddr(t))) {
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
443 while (args) {
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
444 type_print(car(args),0,out);
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
445 args=cadr(args);
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
446 if (args) fprintf(out,",");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
447 }
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
448 }
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
449 fprintf(out,")");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
450 return;
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
451 } else if(car(t)==ARRAY) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
452 fprintf(out,"(*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
453 type_print(cadr(t),n,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
454 if (caddr(type))
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
455 fprintf(out,")[%d]",caddr(type));
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
456 else
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
457 fprintf(out,")[]");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
458 return;
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
459 } else {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
460 type_print1(t,0,out,cont);
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
461 fprintf(out,"*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
462 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
463 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
464 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
465 if(n) fprintf(out,"%s",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
466 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
467
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
468 void type_print(int type,NMTBL *n,FILE *out)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
469 {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
470 type_print1(type,n,out,0);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
471 }
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
472
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
473 /*
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
474 parse tree を印刷する
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
475
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
476 正しく括弧とかを付けるアルゴリズムが不明...
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
477 先読みして、優先順位を判別する必要があるはず。
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
478
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
479 そういえば、cast とかは、落ちて変換コードに変わっている
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
480 はず。cast を木にしないとだめか。
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
481 */
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
482
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
483 void
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
484 print_expr(int e, FILE *vout)
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
485 {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
486 NMTBL *nptr,*n;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
487
660
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
488 if (e==0) {
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
489 // can't happen in normal C language
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
490 fprintf(vout,"#");
660
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
491 return;
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
492 }
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
493 switch (car(e)%SOP) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
494 case LVAR:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
495 case RLVAR:
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
496 case URLVAR:
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
497 if ((nptr = (NMTBL*)caddr(e))) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
498 fprintf(vout,"%s",nptr->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
499 } else {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
500 // anonymous variable
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
501 fprintf(vout,"_%d",caddr(e));
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
502 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
503 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
504 case GVAR:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
505 case RGVAR:
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
506 case URGVAR:
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
507 if ((nptr = (NMTBL*)caddr(e))) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
508 fprintf(vout,"%s",nptr->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
509 } else {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
510 // anonymous variable
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
511 fprintf(vout,"_%d",caddr(e));
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
512 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
513 if (cadr(e)) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
514 // offset
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
515 // certainly this is wrong
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
516 fprintf(vout,"+%d",caddr(e));
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
517 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
518 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
519 case REGISTER:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
520 if ((nptr = (NMTBL*)caddr(e))) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
521 fprintf(vout,"%s",nptr->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
522 } else {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
523 // anonymous register variable
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
524 fprintf(vout,"_%d",caddr(e));
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
525 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
526 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
527 case IDENT:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
528 nptr = (NMTBL*)cadr(e);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
529 fprintf(vout,"%s",nptr->nm); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
530 case CONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
531 switch(car(e)) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
532 case CONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
533 fprintf(vout,"%d",cadr(e)); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
534 #if FLOAT_CODE
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
535 case FCONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
536 fprintf(vout,"%g",dcadr(e)); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
537 case DCONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
538 fprintf(vout,"%g",dcadr(e)); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
539 #endif
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
540 #if LONGLONG_CODE
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
541 case LCONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
542 fprintf(vout,"%lld",lcadr(e)); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
543 #endif
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
544 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
545 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
546 case ADDRESS:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
547 if (car(cadr(e))!=STRING) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
548 fprintf(vout,"&");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
549 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
550 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
551 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
552 case STRING:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
553 {
620
0e7281ec9007 *** empty log message ***
kono
parents: 609
diff changeset
554 int c; char *s; int i;
0e7281ec9007 *** empty log message ***
kono
parents: 609
diff changeset
555 nptr = (NMTBL*)cadr(e); s = nptr->nm;i=nptr->dsp;
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
556 fprintf(vout,"\"");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
557 while(--i>0) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
558 c=*s++;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
559 if(c=='\n') fprintf(vout,"\\n");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
560 else if(c=='\r') fprintf(vout,"\\r");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
561 else if(c=='\t') fprintf(vout,"\\t");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
562 else if(c=='\e') fprintf(vout,"\\e");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
563 else if(c=='"') fprintf(vout,"\\\"");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
564 else if(c=='\\') fprintf(vout,"\\\\");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
565 else if(!(' '<=c&&c<=0x7f)) fprintf(vout,"\\%03o",c);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
566 else fprintf(vout,"%c",c);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
567 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
568 fprintf(vout,"\"");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
569 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
570 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
571 case ARRAY:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
572 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
573 fprintf(vout,"[");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
574 print_expr(caddr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
575 fprintf(vout,"]");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
576 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
577 case PERIOD:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
578 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
579 n = (NMTBL*)caddr(e);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
580 fprintf(vout,".%s",n->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
581 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
582 case ARROW:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
583 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
584 n = (NMTBL*)caddr(e);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
585 fprintf(vout,"->%s",n->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
586 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
587 case INDIRECT:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
588 case RINDIRECT:
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
589 case URINDIRECT:
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
590 fprintf(vout,"*");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
591 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
592 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
593 case FNAME:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
594 n = (NMTBL*)cadr(e);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
595 fprintf(vout,"%s",n->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
596 break;
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
597 case FUNCTION:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
598 print_function_call(e,vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
599 break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
600 /*
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
601 case ADD:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
602 fprintf(vout,"(");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
603 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
604 fprintf(vout,"+");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
605 print_expr(caddr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
606 fprintf(vout,")");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
607 break;
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
608 */
660
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
609 case RSTRUCT:
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
610 print_expr(cadr(e),vout);
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
611 break;
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
612 default:
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
613 print_operator(e, vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
614 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
615 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
616
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
617 static void
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
618 print_expr_paren(int order,char *args,int e)
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
619 {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
620 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
621
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
622 static void
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
623 print_operator(int e, FILE *vout)
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
624 {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
625 char *name; char *args; int order ;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
626 if (tree_nodes(car(e), &name, &args, &order) ) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
627 if (order>0) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
628 int i = 0;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
629 for(;*args;args++,i++) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
630 print_expr_paren(order,args,heap[e+i]);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
631 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
632 } else {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
633 print_statement(e, vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
634 }
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
635 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
636 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
637
680
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
638 static void
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
639 print_decl(int e, FILE *vout)
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
640 {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
641 NMTBL *n = (NMTBL*)caddr(e);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
642 int e1 = cadddr(e);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
643 // int mode = car(e1);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
644 int stmode = cadr(e1);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
645 int ctmode = caddr(e1);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
646
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
647 if (n==&null_nptr) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
648 error(-1); // can't happen
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
649 return;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
650 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
651 if (stmode==STATIC) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
652 fprintf(vout,"static ",nptr->nm);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
653 } else if (stmode==EXTRN||stmode==EXTRN1) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
654 fprintf(vout,"extern ",nptr->nm);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
655 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
656 type_print(n->ty,n,vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
657 if (ctmode) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
658 fprintf(vout,"const ",nptr->nm);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
659 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
660 fprintf(vout,"%s; ",nptr->nm);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
661 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
662
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
663 static void
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
664 print_statement(int e, FILE *vout)
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
665 {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
666 int e1;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
667 NMTBL *n;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
668 for (;e!=0; e = cadr(e)) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
669 switch (car(e)) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
670 case ST_DECL:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
671 print_decl(e, vout); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
672 case ST_IF:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
673 fprintf(vout,"if "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
674 case ST_DO:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
675 fprintf(vout,"do "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
676 case ST_WHILE:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
677 fprintf(vout,"while "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
678 case ST_FOR:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
679 fprintf(vout,"for "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
680 case ST_SWITCH:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
681 fprintf(vout,"switch "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
682 case ST_COMP:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
683 fprintf(vout,"{");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
684 fprintf(vout,"}");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
685 break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
686 case ST_BREAK:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
687 fprintf(vout,"break; "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
688 case ST_CONTINUE:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
689 fprintf(vout,"continue; "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
690 case ST_CASE:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
691 for(e1 = caddr(e);e1;e1 = cadr(e1)) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
692 fprintf(vout,"case ");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
693 fprintf(vout,"%d: ",car(e1));
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
694 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
695 break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
696 case ST_DEFAULT:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
697 fprintf(vout,"default: "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
698 case ST_RETURN:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
699 fprintf(vout,"return ");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
700 if (( e1 = caddr(e))) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
701 print_expr(e1,vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
702 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
703 fprintf(vout,"; ");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
704 break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
705 case ST_GOTO:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
706 fprintf(vout,"goto "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
707 case ST_ASM:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
708 fprintf(vout,"__asm__ "); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
709 case ST_LABEL:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
710 n = (NMTBL*)(caddr(caddr(e)));
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
711 fprintf(vout,"%s:", n->nm); break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
712 case ST_OP:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
713 e1 = caddr(e);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
714 print_expr(list3(cadr(e),car(e1),cadr(e1)),vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
715 break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
716 case ST_COMMENT:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
717 fprintf(vout,"\n# %s\n",(char*)caddr(e));
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
718 break;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
719 default:
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
720 fprintf(stderr,"Unknown Statement ID %d\n",car(e));
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
721 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
722 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
723 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
724
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
725 static void
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
726 print_function_call(int e1,FILE *vout)
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
727 {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
728 int e2,e3;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
729 NMTBL *fn = 0;
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
730
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
731 e2 = cadr(e1);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
732 if (car(e2) == FNAME) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
733 fn=(NMTBL *)cadr(e2);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
734 fprintf(vout,"%s",fn->nm);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
735 } else {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
736 if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
737 fprintf(vout,"(");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
738 print_expr(e2,vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
739 fprintf(vout,")");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
740 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
741
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
742 fprintf(vout,"(");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
743 for (e3 = e1 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
744 print_expr(car(e3),vout);
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
745 if (cadr(e3)) {
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
746 fprintf(vout,",");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
747 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
748 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
749 fprintf(vout,")");
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
750 reverse0(e1); // make it normal order
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
751
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
752 }
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
753
f536897fa3cb *** empty log message ***
kono
parents: 660
diff changeset
754
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
755 /* end */