summaryrefslogtreecommitdiff
path: root/src/icont/tree.c
blob: 535c62ad83073f04a22eddc16df6372ca2fbbcb4 (plain)
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
/*
 * tree.c -- functions for constructing parse trees
 */

#include "../h/gsupport.h"
#include "tproto.h"
#include "tree.h"

/*
 *  tree[1-6] construct parse tree nodes with specified values.
 *   Parameters a and b are line and column information,
 *   while parameters c through f are values to be assigned to n_field[0-3].
 *   Note that this could be done with a single routine; a separate routine
 *   for each node size is used for speed and simplicity.
 */

nodeptr tree1(type)
int type;
   {
   register nodeptr t;

   t = NewNode(0);
   t->n_type = type;
   return t;
   }

nodeptr tree2(type, loc_model)
int type;
nodeptr loc_model;
   {
   register nodeptr t;

   t = NewNode(0);
   t->n_type = type;
   t->n_file = loc_model->n_file;
   t->n_line = loc_model->n_line;
   t->n_col = loc_model->n_col;
   return t;
   }

nodeptr tree3(type, loc_model, c)
int type;
nodeptr loc_model;
nodeptr c;
   {
   register nodeptr t;

   t = NewNode(1);
   t->n_type = type;
   t->n_file = loc_model->n_file;
   t->n_line = loc_model->n_line;
   t->n_col = loc_model->n_col;
   t->n_field[0].n_ptr = c;
   return t;
   }

nodeptr tree4(type, loc_model, c, d)
int type;
nodeptr loc_model;
nodeptr c, d;
   {
   register nodeptr t;

   t = NewNode(2);
   t->n_type = type;
   t->n_file = loc_model->n_file;
   t->n_line = loc_model->n_line;
   t->n_col = loc_model->n_col;
   t->n_field[0].n_ptr = c;
   t->n_field[1].n_ptr = d;
   return t;
   }

nodeptr tree5(type, loc_model, c, d, e)
int type;
nodeptr loc_model;
nodeptr c, d, e;
   {
   register nodeptr t;

   t = NewNode(3);
   t->n_type = type;
   t->n_file = loc_model->n_file;
   t->n_line = loc_model->n_line;
   t->n_col = loc_model->n_col;
   t->n_field[0].n_ptr = c;
   t->n_field[1].n_ptr = d;
   t->n_field[2].n_ptr = e;
   return t;
   }

nodeptr tree6(type, loc_model, c, d, e, f)
int type;
nodeptr loc_model;
nodeptr c, d, e, f;
   {
   register nodeptr t;

   t = NewNode(4);
   t->n_type = type;
   t->n_file = loc_model->n_file;
   t->n_line = loc_model->n_line;
   t->n_col = loc_model->n_col;
   t->n_field[0].n_ptr = c;
   t->n_field[1].n_ptr = d;
   t->n_field[2].n_ptr = e;
   t->n_field[3].n_ptr = f;
   return t;
   }

nodeptr buildarray(a,lb,e,rb)
nodeptr a, lb, e, rb;
   {
   register nodeptr t, t2;
   if (e->n_type == N_Elist) {
      t2 = int_leaf(lb->n_type, lb, (int)lb->n_field[0].n_val);
      t = tree5(N_Binop, t2, t2, buildarray(a,lb,e->n_field[0].n_ptr,rb),
		e->n_field[1].n_ptr);
      free(e);
      }
   else
      t = tree5(N_Binop, lb, lb, a, e);
   return t;
   }

nodeptr int_leaf(type, loc_model, c)
int type;
nodeptr loc_model;
int c;
   {
   register nodeptr t;

   t = NewNode(1);
   t->n_type = type;
   t->n_file = loc_model->n_file;
   t->n_line = loc_model->n_line;
   t->n_col = loc_model->n_col;
   t->n_field[0].n_val = c;
   return t;
   }

nodeptr c_str_leaf(type, loc_model, c)
int type;
nodeptr loc_model;
char *c;
   {
   register nodeptr t;

   t = NewNode(1);
   t->n_type = type;
   t->n_file = loc_model->n_file;
   t->n_line = loc_model->n_line;
   t->n_col = loc_model->n_col;
   t->n_field[0].n_str = c;
   return t;
   }

nodeptr i_str_leaf(type, loc_model, c, d)
int type;
nodeptr loc_model;
char *c;
int d;
   {
   register nodeptr t;

   t = NewNode(2);
   t->n_type = type;
   t->n_file = loc_model->n_file;
   t->n_line = loc_model->n_line;
   t->n_col = loc_model->n_col;
   t->n_field[0].n_str = c;
   t->n_field[1].n_val = d;
   return t;
   }