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