1 |
mmeineke |
377 |
#include <stdio.h> |
2 |
|
|
#include <stdlib.h> |
3 |
|
|
#include <string.h> |
4 |
|
|
|
5 |
mmeineke |
854 |
#include "node_list.h" |
6 |
|
|
#include "make_nodes.h" |
7 |
|
|
#include "simError.h" |
8 |
mmeineke |
377 |
|
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 |
mmeineke |
675 |
the next three functions are for creating and initializing the |
24 |
mmeineke |
377 |
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 |
gezelter |
988 |
the_node->type = MEMBERS_STMT; |
92 |
mmeineke |
377 |
the_node->index = 0; |
93 |
|
|
the_node->next_stmt = NULL; |
94 |
|
|
the_node->prev_stmt = NULL; |
95 |
|
|
the_node->stmt_list = NULL; |
96 |
|
|
|
97 |
gezelter |
988 |
the_node->the_data.mbrs.a = a; |
98 |
|
|
the_node->the_data.mbrs.b = b; |
99 |
|
|
the_node->the_data.mbrs.c = 0; |
100 |
|
|
the_node->the_data.mbrs.d = 0; |
101 |
mmeineke |
377 |
|
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 |
gezelter |
988 |
the_node->type = MEMBERS_STMT; |
111 |
mmeineke |
377 |
the_node->index = 0; |
112 |
|
|
the_node->next_stmt = NULL; |
113 |
|
|
the_node->prev_stmt = NULL; |
114 |
|
|
the_node->stmt_list = NULL; |
115 |
|
|
|
116 |
gezelter |
988 |
the_node->the_data.mbrs.a = a; |
117 |
|
|
the_node->the_data.mbrs.b = b; |
118 |
|
|
the_node->the_data.mbrs.c = c; |
119 |
|
|
the_node->the_data.mbrs.d = 0; |
120 |
mmeineke |
377 |
|
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 |
gezelter |
988 |
the_node->type = MEMBERS_STMT; |
130 |
mmeineke |
377 |
the_node->index = 0; |
131 |
|
|
the_node->next_stmt = NULL; |
132 |
|
|
the_node->prev_stmt = NULL; |
133 |
|
|
the_node->stmt_list = NULL; |
134 |
|
|
|
135 |
gezelter |
988 |
the_node->the_data.mbrs.a = a; |
136 |
|
|
the_node->the_data.mbrs.b = b; |
137 |
|
|
the_node->the_data.mbrs.c = c; |
138 |
|
|
the_node->the_data.mbrs.d = d; |
139 |
mmeineke |
377 |
|
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 |
|
|
The following six functions initialize the statement nodes |
209 |
|
|
coresponding to the different code block types. |
210 |
|
|
*/ |
211 |
|
|
|
212 |
|
|
struct node_tag* molecule_blk( struct node_tag* stmt_list ){ |
213 |
|
|
|
214 |
|
|
struct node_tag* the_node; |
215 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
216 |
|
|
|
217 |
|
|
the_node->type = MOLECULE_HEAD; |
218 |
|
|
the_node->index = 0; |
219 |
|
|
the_node->next_stmt = NULL; |
220 |
|
|
the_node->prev_stmt = NULL; |
221 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
222 |
|
|
|
223 |
|
|
return the_node; |
224 |
|
|
} |
225 |
|
|
|
226 |
gezelter |
957 |
struct node_tag* rigidbody_blk( int index, struct node_tag* stmt_list ){ |
227 |
|
|
|
228 |
|
|
struct node_tag* the_node; |
229 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
230 |
|
|
|
231 |
|
|
the_node->type = RIGIDBODY_HEAD; |
232 |
|
|
the_node->index = 0; |
233 |
|
|
the_node->next_stmt = NULL; |
234 |
|
|
the_node->prev_stmt = NULL; |
235 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
236 |
|
|
|
237 |
|
|
return the_node; |
238 |
|
|
} |
239 |
|
|
|
240 |
mmeineke |
377 |
struct node_tag* atom_blk( int index, struct node_tag* stmt_list ){ |
241 |
|
|
|
242 |
|
|
struct node_tag* the_node; |
243 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
244 |
|
|
|
245 |
|
|
the_node->type = ATOM_HEAD; |
246 |
|
|
the_node->index = index; |
247 |
|
|
the_node->next_stmt = NULL; |
248 |
|
|
the_node->prev_stmt = NULL; |
249 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
250 |
|
|
|
251 |
|
|
return the_node; |
252 |
|
|
} |
253 |
|
|
|
254 |
|
|
struct node_tag* bond_blk( int index, struct node_tag* stmt_list ){ |
255 |
|
|
|
256 |
|
|
struct node_tag* the_node; |
257 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
258 |
|
|
|
259 |
|
|
the_node->type = BOND_HEAD; |
260 |
|
|
the_node->index = index; |
261 |
|
|
the_node->next_stmt = NULL; |
262 |
|
|
the_node->prev_stmt = NULL; |
263 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
264 |
|
|
|
265 |
|
|
return the_node; |
266 |
|
|
} |
267 |
|
|
|
268 |
|
|
struct node_tag* bend_blk( int index, struct node_tag* stmt_list ){ |
269 |
|
|
|
270 |
|
|
struct node_tag* the_node; |
271 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
272 |
|
|
|
273 |
|
|
the_node->type = BEND_HEAD; |
274 |
|
|
the_node->index = index; |
275 |
|
|
the_node->next_stmt = NULL; |
276 |
|
|
the_node->prev_stmt = NULL; |
277 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
278 |
|
|
|
279 |
|
|
return the_node; |
280 |
|
|
} |
281 |
|
|
|
282 |
|
|
struct node_tag* torsion_blk( int index, struct node_tag* stmt_list ){ |
283 |
|
|
|
284 |
|
|
struct node_tag* the_node; |
285 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
286 |
|
|
|
287 |
|
|
the_node->type = TORSION_HEAD; |
288 |
|
|
the_node->index = index; |
289 |
|
|
the_node->next_stmt = NULL; |
290 |
|
|
the_node->prev_stmt = NULL; |
291 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
292 |
|
|
|
293 |
|
|
return the_node; |
294 |
|
|
} |
295 |
mmeineke |
675 |
|
296 |
gezelter |
988 |
struct node_tag* member_blk( int index, struct node_tag* stmt_list ){ |
297 |
|
|
|
298 |
|
|
struct node_tag* the_node; |
299 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
300 |
|
|
|
301 |
|
|
the_node->type = MEMBER_HEAD; |
302 |
|
|
the_node->index = index; |
303 |
|
|
the_node->next_stmt = NULL; |
304 |
|
|
the_node->prev_stmt = NULL; |
305 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
306 |
|
|
|
307 |
|
|
return the_node; |
308 |
|
|
} |
309 |
|
|
|
310 |
mmeineke |
675 |
struct node_tag* zconstraint_blk( int index, struct node_tag* stmt_list ){ |
311 |
|
|
|
312 |
|
|
struct node_tag* the_node; |
313 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
314 |
|
|
|
315 |
|
|
the_node->type = ZCONSTRAINT_HEAD; |
316 |
|
|
the_node->index = index; |
317 |
|
|
the_node->next_stmt = NULL; |
318 |
|
|
the_node->prev_stmt = NULL; |
319 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
320 |
|
|
|
321 |
|
|
return the_node; |
322 |
|
|
} |
323 |
mmeineke |
377 |
|
324 |
|
|
struct node_tag* component_blk( struct node_tag* stmt_list ){ |
325 |
|
|
|
326 |
|
|
struct node_tag* the_node; |
327 |
|
|
the_node = ( struct node_tag* )malloc( sizeof( node ) ); |
328 |
|
|
|
329 |
|
|
the_node->type = COMPONENT_HEAD; |
330 |
|
|
the_node->index = 0; |
331 |
|
|
the_node->next_stmt = NULL; |
332 |
|
|
the_node->prev_stmt = NULL; |
333 |
|
|
the_node->stmt_list = walk_to_top( stmt_list ); |
334 |
|
|
|
335 |
|
|
return the_node; |
336 |
|
|
} |