-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.h
212 lines (157 loc) · 4.42 KB
/
tree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* ###############################################################
##
## C Tree Builder
##
## File: tree.h
##
## Programmer: Shawn Flisakowski
## Date: Jan 21, 1995
##
##
############################################################### */
#ifndef TREE_H
#define TREE_H
#include "config.h"
#include "nmetab.h"
BEGIN_HEADER
/* ############################################################### */
typedef enum {
TN_EMPTY,
TN_FUNC_DEF,
TN_FUNC_DECL,
TN_FUNC_CALL,
TN_BLOCK,
TN_DECL,
TN_ARRAY_DECL,
TN_TRANS_LIST,
TN_DECL_LIST,
TN_STEMNT_LIST,
TN_EXPR_LIST,
TN_NAME_LIST,
TN_ENUM_LIST,
TN_FIELD_LIST,
TN_PARAM_LIST,
TN_IDENT_LIST,
TN_DECLS,
/* Dumb, but I'm not sure what to do yet */
TN_COMP_DECL,
TN_BIT_FIELD,
TN_PNTR,
/* Stores a list of type specifiers/qualifers (int,const,etc) */
TN_TYPE_LIST,
TN_TYPE_NME,
/* Stores initial values for arrays */
TN_INIT_LIST,
TN_INIT_BLK,
TN_OBJ_DEF, /* Definition of struct, union, or enum */
TN_OBJ_REF, /* Reference to struct, union, or enum */
/* More vague */
TN_CAST,
TN_IF,
TN_ASSIGN,
TN_JUMP,
TN_FOR,
TN_WHILE,
TN_DOWHILE,
TN_SWITCH,
TN_LABEL,
TN_STEMNT,
TN_INDEX, /* Index with [] */
TN_ADDROF, /* Address of via & */
TN_DEREF, /* Dereference with * */
TN_SELECT, /* -> and . */
TN_EXPR,
TN_COND_EXPR,
TN_COMMENT,
TN_CPP,
TN_ELLIPSIS,
TN_IDENT,
TN_TYPE,
TN_STRING,
TN_INT,
TN_REAL,
// Parc extension
TN_PARBLOCK,
TN_PARBLOCK_EMPTY,
TN_PARFOR
} tn_t;
typedef enum {
NONE_T,
LEAF_T,
IF_T,
FOR_T,
NODE_T
} node_type;
/* ############################################################### */
struct common {
node_type which;
int line;
int col;
int tok;
tn_t type;
struct context *c_contxt;
};
typedef struct treenode {
struct common hdr;
struct treenode *lnode;
struct treenode *rnode;
} treenode;
#define TREENODE_SZE (sizeof(treenode))
/* ############################################################### */
typedef struct if_node {
struct common hdr;
struct treenode *cond;
struct treenode *then_n;
struct treenode *else_n;
} if_node;
#define IFNODE_SZE (sizeof(if_node))
/* ############################################################### */
typedef struct for_node {
struct common hdr;
struct treenode *init;
struct treenode *test;
struct treenode *incr;
struct treenode *stemnt;
} for_node;
#define FORNODE_SZE (sizeof(for_node))
/* ############################################################### */
struct type_item;
typedef struct leafnode {
struct common hdr;
/* The node in the symbol table. */
struct symentry *syment;
union {
int cval;
str_t *sval;
char *str;
int ival;
long int l_ival;
unsigned int u_ival;
unsigned long int ul_ival;
float fval;
double dval;
long double l_dval;
} data;
} leafnode;
#define LEAFNODE_SZE (sizeof(leafnode))
/* ############################################################### */
/* External Declarations */
typedef void (*FindFunction)(leafnode*, treenode*, treenode*);
char *name_of_node ARGS((tn_t));
char *name_of_nodetype ARGS((node_type));
leafnode *make_leaf ARGS((tn_t, struct context *));
if_node *make_if ARGS((tn_t, struct context *));
for_node *make_for ARGS((tn_t, struct context *));
treenode *make_node ARGS((tn_t, struct context *));
void free_tree ARGS((treenode*));
treenode *copy_tree ARGS((treenode*));
leafnode *leftmost ARGS((treenode*));
leafnode *rightmost ARGS((treenode*));
void find_typedef_name ARGS((treenode*,treenode*, FindFunction ));
void find_ident_name ARGS((treenode*,treenode*,treenode*, FindFunction));
leafnode *find_func_name ARGS((treenode*));
void find_params ARGS((treenode*, FindFunction));
void find_components ARGS((treenode*,treenode*,treenode*,FindFunction));
/* ############################################################### */
END_HEADER
#endif /* TREE_H */