1 |
#include <stdio.h> |
2 |
#include <stdlib.h> |
3 |
#include <string.h> |
4 |
|
5 |
#include "node_list.h" |
6 |
#include "make_nodes.h" |
7 |
|
8 |
/* |
9 |
walks to to the top of a stmt_list. Needed when assigning the |
10 |
statment list to a block of code. |
11 |
*/ |
12 |
|
13 |
struct node_tag* walk_to_top( struct node_tag* walk_me ){ |
14 |
|
15 |
while( walk_me->prev_stmt != NULL ){ |
16 |
walk_me = walk_me->prev_stmt; |
17 |
} |
18 |
return walk_me; |
19 |
} |
20 |
|
21 |
/* |
22 |
the next three functions are for creating and initialing the |
23 |
assignment statements. |
24 |
*/ |
25 |
|
26 |
struct node_tag* assign_i( char* lhs, int rhs ){ |
27 |
|
28 |
struct node_tag* the_node; |
29 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
30 |
|
31 |
the_node->type = ASSIGNMENT_STMT; |
32 |
the_node->index = 0; |
33 |
the_node->next_stmt = NULL; |
34 |
the_node->prev_stmt = NULL; |
35 |
the_node->stmt_list = NULL; |
36 |
|
37 |
the_node->the_data.asmt.type = INT_ASSN; |
38 |
the_node->the_data.asmt.identifier = lhs; |
39 |
the_node->the_data.asmt.rhs.i_val = rhs; |
40 |
|
41 |
return the_node; |
42 |
} |
43 |
|
44 |
struct node_tag* assign_d( char* lhs, double rhs ){ |
45 |
|
46 |
struct node_tag* the_node; |
47 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
48 |
|
49 |
the_node->type = ASSIGNMENT_STMT; |
50 |
the_node->index = 0; |
51 |
the_node->next_stmt = NULL; |
52 |
the_node->prev_stmt = NULL; |
53 |
the_node->stmt_list = NULL; |
54 |
|
55 |
the_node->the_data.asmt.type = DOUBLE_ASSN; |
56 |
the_node->the_data.asmt.identifier = lhs; |
57 |
the_node->the_data.asmt.rhs.d_val = rhs; |
58 |
|
59 |
return the_node; |
60 |
} |
61 |
|
62 |
struct node_tag* assign_s( char* lhs, char* rhs ){ |
63 |
|
64 |
struct node_tag* the_node; |
65 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
66 |
|
67 |
the_node->type = ASSIGNMENT_STMT; |
68 |
the_node->index = 0; |
69 |
the_node->next_stmt = NULL; |
70 |
the_node->prev_stmt = NULL; |
71 |
the_node->stmt_list = NULL; |
72 |
|
73 |
the_node->the_data.asmt.type = STR_ASSN; |
74 |
the_node->the_data.asmt.identifier = lhs; |
75 |
the_node->the_data.asmt.rhs.str_ptr = rhs; |
76 |
|
77 |
return the_node; |
78 |
} |
79 |
|
80 |
/* |
81 |
The next three functions deal with creating and initializing of the |
82 |
members statements used by the bonds, bends, and torsions. |
83 |
*/ |
84 |
|
85 |
struct node_tag* members_2( int a, int b ){ |
86 |
|
87 |
struct node_tag* the_node; |
88 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
89 |
|
90 |
the_node->type = MEMBER_STMT; |
91 |
the_node->index = 0; |
92 |
the_node->next_stmt = NULL; |
93 |
the_node->prev_stmt = NULL; |
94 |
the_node->stmt_list = NULL; |
95 |
|
96 |
the_node->the_data.mbr.a = a; |
97 |
the_node->the_data.mbr.b = b; |
98 |
the_node->the_data.mbr.c = 0; |
99 |
the_node->the_data.mbr.d = 0; |
100 |
|
101 |
return the_node; |
102 |
} |
103 |
|
104 |
struct node_tag* members_3( int a, int b, int c ){ |
105 |
|
106 |
struct node_tag* the_node; |
107 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
108 |
|
109 |
the_node->type = MEMBER_STMT; |
110 |
the_node->index = 0; |
111 |
the_node->next_stmt = NULL; |
112 |
the_node->prev_stmt = NULL; |
113 |
the_node->stmt_list = NULL; |
114 |
|
115 |
the_node->the_data.mbr.a = a; |
116 |
the_node->the_data.mbr.b = b; |
117 |
the_node->the_data.mbr.c = c; |
118 |
the_node->the_data.mbr.d = 0; |
119 |
|
120 |
return the_node; |
121 |
} |
122 |
|
123 |
struct node_tag* members_4( int a, int b, int c, int d ){ |
124 |
|
125 |
struct node_tag* the_node; |
126 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
127 |
|
128 |
the_node->type = MEMBER_STMT; |
129 |
the_node->index = 0; |
130 |
the_node->next_stmt = NULL; |
131 |
the_node->prev_stmt = NULL; |
132 |
the_node->stmt_list = NULL; |
133 |
|
134 |
the_node->the_data.mbr.a = a; |
135 |
the_node->the_data.mbr.b = b; |
136 |
the_node->the_data.mbr.c = c; |
137 |
the_node->the_data.mbr.d = d; |
138 |
|
139 |
return the_node; |
140 |
} |
141 |
|
142 |
/* |
143 |
This function does the C & I of the constraint statements |
144 |
*/ |
145 |
|
146 |
struct node_tag* constraint( double constraint_val ){ |
147 |
|
148 |
struct node_tag* the_node; |
149 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
150 |
|
151 |
the_node->type = CONSTRAINT_STMT; |
152 |
the_node->index = 0; |
153 |
the_node->next_stmt = NULL; |
154 |
the_node->prev_stmt = NULL; |
155 |
the_node->stmt_list = NULL; |
156 |
|
157 |
the_node->the_data.cnstr.constraint_val = constraint_val; |
158 |
|
159 |
return the_node; |
160 |
} |
161 |
|
162 |
/* |
163 |
This function does the C & I for the orientation statements |
164 |
*/ |
165 |
|
166 |
struct node_tag* orientation( double x, double y, double z ){ |
167 |
|
168 |
struct node_tag* the_node; |
169 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
170 |
|
171 |
the_node->type = ORIENTATION_STMT; |
172 |
the_node->index = 0; |
173 |
the_node->next_stmt = NULL; |
174 |
the_node->prev_stmt = NULL; |
175 |
the_node->stmt_list = NULL; |
176 |
|
177 |
the_node->the_data.pos.x = x; |
178 |
the_node->the_data.pos.y = y; |
179 |
the_node->the_data.pos.z = z; |
180 |
|
181 |
return the_node; |
182 |
} |
183 |
|
184 |
/* |
185 |
This function does the C & I for the position statements |
186 |
*/ |
187 |
|
188 |
struct node_tag* position( double x, double y, double z ){ |
189 |
|
190 |
struct node_tag* the_node; |
191 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
192 |
|
193 |
the_node->type = POSITION_STMT; |
194 |
the_node->index = 0; |
195 |
the_node->next_stmt = NULL; |
196 |
the_node->prev_stmt = NULL; |
197 |
the_node->stmt_list = NULL; |
198 |
|
199 |
the_node->the_data.pos.x = x; |
200 |
the_node->the_data.pos.y = y; |
201 |
the_node->the_data.pos.z = z; |
202 |
|
203 |
return the_node; |
204 |
} |
205 |
|
206 |
/* |
207 |
Does the C & I for the start_index statement |
208 |
*/ |
209 |
|
210 |
struct node_tag* start_index( struct integer_list_tag* the_list ){ |
211 |
|
212 |
struct node_tag* the_node; |
213 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
214 |
|
215 |
the_node->type = START_INDEX_STMT; |
216 |
the_node->index = 0; |
217 |
the_node->next_stmt = NULL; |
218 |
the_node->prev_stmt = NULL; |
219 |
the_node->stmt_list = NULL; |
220 |
|
221 |
the_node->the_data.il_head = the_list; |
222 |
|
223 |
return the_node; |
224 |
} |
225 |
|
226 |
/* |
227 |
The following six functions initialize the statement nodes |
228 |
coresponding to the different code block types. |
229 |
*/ |
230 |
|
231 |
struct node_tag* molecule_blk( struct node_tag* stmt_list ){ |
232 |
|
233 |
struct node_tag* the_node; |
234 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
235 |
|
236 |
the_node->type = MOLECULE_HEAD; |
237 |
the_node->index = 0; |
238 |
the_node->next_stmt = NULL; |
239 |
the_node->prev_stmt = NULL; |
240 |
the_node->stmt_list = walk_to_top( stmt_list ); |
241 |
|
242 |
return the_node; |
243 |
} |
244 |
|
245 |
struct node_tag* atom_blk( int index, struct node_tag* stmt_list ){ |
246 |
|
247 |
struct node_tag* the_node; |
248 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
249 |
|
250 |
the_node->type = ATOM_HEAD; |
251 |
the_node->index = index; |
252 |
the_node->next_stmt = NULL; |
253 |
the_node->prev_stmt = NULL; |
254 |
the_node->stmt_list = walk_to_top( stmt_list ); |
255 |
|
256 |
return the_node; |
257 |
} |
258 |
|
259 |
struct node_tag* bond_blk( int index, struct node_tag* stmt_list ){ |
260 |
|
261 |
struct node_tag* the_node; |
262 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
263 |
|
264 |
the_node->type = BOND_HEAD; |
265 |
the_node->index = index; |
266 |
the_node->next_stmt = NULL; |
267 |
the_node->prev_stmt = NULL; |
268 |
the_node->stmt_list = walk_to_top( stmt_list ); |
269 |
|
270 |
return the_node; |
271 |
} |
272 |
|
273 |
struct node_tag* bend_blk( int index, struct node_tag* stmt_list ){ |
274 |
|
275 |
struct node_tag* the_node; |
276 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
277 |
|
278 |
the_node->type = BEND_HEAD; |
279 |
the_node->index = index; |
280 |
the_node->next_stmt = NULL; |
281 |
the_node->prev_stmt = NULL; |
282 |
the_node->stmt_list = walk_to_top( stmt_list ); |
283 |
|
284 |
return the_node; |
285 |
} |
286 |
|
287 |
struct node_tag* torsion_blk( int index, struct node_tag* stmt_list ){ |
288 |
|
289 |
struct node_tag* the_node; |
290 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
291 |
|
292 |
the_node->type = TORSION_HEAD; |
293 |
the_node->index = index; |
294 |
the_node->next_stmt = NULL; |
295 |
the_node->prev_stmt = NULL; |
296 |
the_node->stmt_list = walk_to_top( stmt_list ); |
297 |
|
298 |
return the_node; |
299 |
} |
300 |
|
301 |
struct node_tag* component_blk( struct node_tag* stmt_list ){ |
302 |
|
303 |
struct node_tag* the_node; |
304 |
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
305 |
|
306 |
the_node->type = COMPONENT_HEAD; |
307 |
the_node->index = 0; |
308 |
the_node->next_stmt = NULL; |
309 |
the_node->prev_stmt = NULL; |
310 |
the_node->stmt_list = walk_to_top( stmt_list ); |
311 |
|
312 |
return the_node; |
313 |
} |
314 |
|
315 |
/* |
316 |
the next two functions handle the integer list nodes. |
317 |
*/ |
318 |
|
319 |
struct integer_list_tag* il_node( int the_int ){ |
320 |
|
321 |
struct integer_list_tag* the_il_node; |
322 |
the_il_node = ( struct integer_list_tag* )malloc( sizeof( integer_list ) ); |
323 |
|
324 |
the_il_node->prev = NULL; |
325 |
the_il_node->next = NULL; |
326 |
|
327 |
the_il_node->the_int = the_int; |
328 |
|
329 |
return the_il_node; |
330 |
} |
331 |
|
332 |
struct integer_list_tag* il_top( struct integer_list_tag* the_list ){ |
333 |
|
334 |
while( the_list->prev != NULL ){ |
335 |
the_list = the_list->prev; |
336 |
} |
337 |
return the_list; |
338 |
} |