18 MarkDef(nd, flags, on)
19 register struct node *nd;
22 while( nd && nd->nd_class != Def ) {
23 if( (nd->nd_class == Arrsel) ||
24 (nd->nd_class == LinkDef) )
26 else if( nd->nd_class == Arrow )
30 if( nd && (nd->nd_class == Def) ) {
31 if( (flags & D_SET) && on &&
32 BlockScope != nd->nd_def->df_scope )
33 nd->nd_def->df_flags |= D_SETINHIGH;
36 if( (flags & D_SET) &&
37 (nd->nd_def->df_flags & D_WITH) )
39 "variable \"%s\" already referenced in with",
40 nd->nd_def->df_idf->id_text);
42 nd->nd_def->df_flags |= flags;
45 nd->nd_def->df_flags &= ~flags;
49 AssertStat(expp, line)
50 register struct node *expp;
55 if( !ChkExpression(expp) )
58 if( expp->nd_type != bool_type ) {
59 node_error(expp, "type of assertion should be boolean");
63 if( !options['a'] && !err_occurred ) {
65 CodeExpr(expp, &dsr, NO_LABEL);
71 AssignStat(left, right)
72 register struct node *left, *right;
74 register struct type *ltp, *rtp;
78 retval = ChkExpression(right);
80 retval &= ChkLhs(left);
85 MarkDef(left, (unsigned short)D_SET, 1);
89 if( ltp == int_type && rtp == long_type ) {
90 right = MkNode(IntReduc, NULLNODE, right, &dot);
91 right->nd_type = int_type;
93 else if( ltp == long_type && rtp == int_type ) {
94 right = MkNode(IntCoerc, NULLNODE, right, &dot);
95 right->nd_type = long_type;
98 if( !TstAssCompat(ltp, rtp) ) {
99 node_error(left, "type incompatibility in assignment");
103 if( left->nd_class == Def &&
104 (left->nd_def->df_flags & D_INLOOP) ) {
105 node_error(left, "assignment to a control variable");
109 if( rtp == emptyset_type )
110 right->nd_type = ltp;
112 if( !err_occurred ) {
114 CodeExpr(right, &dsr, NO_LABEL);
116 if( rtp->tp_fund & (T_ARRAY | T_RECORD) )
119 CodeValue(&dsr, rtp);
121 if( ltp == real_type && BaseType(rtp) == int_type )
122 Int2Real(rtp->tp_size);
124 RangeCheck(ltp, rtp);
126 CodeMove(&dsr, left, rtp);
134 register struct node *nd;
136 if( !ChkCall(nd) ) return;
139 node_error(nd, "procedure call expected");
145 register struct node *nd;
147 register struct def *df;
150 retvar = ChkVariable(nd);
151 retvar &= ChkExpression(nd->nd_left);
152 MarkUsed(nd->nd_left);
153 retvar &= ChkExpression(nd->nd_right);
154 MarkUsed(nd->nd_right);
155 if( !retvar ) return;
157 assert(nd->nd_class == Def);
161 if( df->df_scope != BlockScope ) {
162 node_error(nd, "for loop: control variable must be local");
166 assert(df->df_kind == D_VARIABLE);
168 if( df->df_scope != GlobalScope && df->var_off >= 0 ) {
170 "for loop: control variable can't be a parameter");
171 MarkDef(nd,(unsigned short)(D_LOOPVAR | D_SET | D_USED), 1);
175 if( !(df->df_type->tp_fund & T_ORDINAL) ) {
176 node_error(nd, "for loop: control variable must be ordinal");
177 MarkDef(nd,(unsigned short)(D_LOOPVAR | D_SET | D_USED), 1);
181 if( !TstCompat(df->df_type, nd->nd_left->nd_type) )
183 "for loop: initial value incompatible with control variable");
185 if( !TstCompat(df->df_type, nd->nd_right->nd_type) )
187 "for loop: final value incompatible with control variable");
189 if( df->df_type == long_type )
190 node_error(nd, "for loop: control variable can not be a long");
192 if( df->df_flags & D_INLOOP )
193 node_error(nd, "for loop: control variable already used");
195 if( df->df_flags & D_SETINHIGH )
197 "for loop: control variable already set in block");
199 MarkDef(nd,(unsigned short) (D_LOOPVAR | D_INLOOP | D_SET | D_USED), 1);
205 register struct node *nd;
207 register struct def *df;
211 if( (df->df_scope != BlockScope) ||
212 (df->df_scope != GlobalScope && df->var_off >= 0) ||
213 !(df->df_type->tp_fund & T_ORDINAL)
217 MarkDef(nd,(unsigned short) (D_INLOOP | D_SET), 0);
221 CodeInitFor(nd, priority)
222 register struct node *nd;
224 /* Push final-value, the value may only be evaluated
225 once, so generate a temporary for it, when not a constant.
231 if( nd->nd_class != Value ) {
232 tmp = NewInt(priority);
242 CodeFor(nd, stepsize, l1, l2)
246 /* Test if loop has to be done */
247 if( stepsize == 1 ) /* TO */
252 /* Label at begin of the body */
255 RangeCheck(nd->nd_type, nd->nd_left->nd_type);
259 CodeEndFor(nd, stepsize, l1, l2, tmp2)
264 /* Test if loop has to be done once more */
270 CodePExpr(nd->nd_right);
273 /* Increment/decrement the control-variable */
274 if( stepsize == 1 ) /* TO */
288 struct withdesig *wds;
290 struct scopelist *scl;
292 if( nd->nd_type->tp_fund != T_RECORD ) {
293 node_error(nd, "record variable expected");
297 MarkDef(nd, (unsigned short)(D_USED | D_SET | D_WITH), 1);
299 if( (nd->nd_class == Arrow) &&
300 (nd->nd_right->nd_type->tp_fund & T_FILE) ) {
301 nd->nd_right->nd_def->df_flags |= D_WITH;
305 scl = new_scopelist();
306 scl->sc_scope = nd->nd_type->rec_scope;
310 if( err_occurred ) return;
316 wds = new_withdesig();
317 wds->w_next = WithDesigs;
319 wds->w_scope = scl->sc_scope;
321 /* create a desig structure for the temporary */
322 ds.dsg_kind = DSG_FIXED;
323 ds.dsg_offset = NewPtr(1);
326 /* need some pointertype to store pointer */
327 CodeStore(&ds, nil_type);
329 /* record is indirectly available */
330 ds.dsg_kind = DSG_PFIXED;
334 EndWith(saved_scl, nd)
335 struct scopelist *saved_scl;
338 /* restore scope, and release structures */
339 struct scopelist *scl;
340 struct withdesig *wds;
343 while( CurrVis != saved_scl ) {
345 /* release scopelist */
347 CurrVis = CurrVis->next;
350 if( WithDesigs == 0 )
351 continue; /* we didn't generate any code */
353 /* release temporary */
354 FreePtr(WithDesigs->w_desig.dsg_offset);
356 /* release withdesig */
358 WithDesigs = WithDesigs->w_next;
362 for( nd1 = nd; nd1 != NULLNODE; nd1 = nd1->nd_right ) {
363 MarkDef(nd1->nd_left, (unsigned short)(D_WITH), 0);