Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 136... Line 166...
136
#endif
166
#endif
137
 
167
 
138
#include "check_id.h"
168
#include "check_id.h"
139
 
169
 
140
#if is68000
170
#if is68000
141
extern int check_anyway PROTO_S ( ( exp ) ) ;
171
extern int check_anyway(exp);
142
#endif
172
#endif
143
 
173
 
144
/* PROCEDURES */
174
/* PROCEDURES */
145
 
175
 
146
/*********************************************************************
176
/*********************************************************************
147
   make_onearg makes up an exp with the given tag (n), shape (sha)
177
   make_onearg makes up an exp with the given tag (n), shape (sha)
148
   and single argument (a).
178
   and single argument (a).
149
 *********************************************************************/
179
 *********************************************************************/
150
 
180
 
151
exp hc
181
exp
152
    PROTO_N ( (e, t) )
-
 
153
    PROTO_T ( exp e X exp t )
182
hc(exp e, exp t)
154
{
183
{
155
  setlast(t);
184
	setlast(t);
156
  bro(t) = e;
185
	bro(t) = e;
157
  return hold_check(e);
186
	return hold_check(e);
158
}
187
}
159
 
188
 
-
 
189
 
160
static exp make_onearg
190
static exp
161
    PROTO_N ( (n, sha, a) )
-
 
162
    PROTO_T ( unsigned char n X shape sha X exp a )
191
make_onearg(unsigned char n, shape sha, exp a)
163
{
192
{
164
  exp r = getexp (sha, nilexp, 0, a, nilexp, 0, 0, n);
193
	exp r = getexp(sha, nilexp, 0, a, nilexp, 0, 0, n);
165
  return (hc (r, a));
194
	return(hc(r, a));
166
}
195
}
-
 
196
 
167
 
197
 
168
/*********************************************************************
198
/*********************************************************************
169
   make_twoarg makes up an exp with the given tag (n), shape (sha)
199
   make_twoarg makes up an exp with the given tag (n), shape (sha)
170
   and two arguments (a,b) in that order.
200
   and two arguments (a,b) in that order.
171
 *********************************************************************/
201
 *********************************************************************/
172
 
202
 
173
static exp make_twoarg
203
static exp
174
    PROTO_N ( (n, sha, a, b) )
-
 
175
    PROTO_T ( unsigned char n X shape sha X exp a X exp b )
204
make_twoarg(unsigned char n, shape sha, exp a, exp b)
176
{
205
{
177
  exp r = getexp (sha, nilexp, 0, a, nilexp, 0, 0, n);
206
	exp r = getexp(sha, nilexp, 0, a, nilexp, 0, 0, n);
178
  bro (a) = b;
207
	bro(a) = b;
179
  clearlast (a);
208
	clearlast(a);
180
  return (hc (r, b));
209
	return(hc(r, b));
181
}
210
}
-
 
211
 
182
 
212
 
183
/************************************************************************
213
/************************************************************************
184
   used_in delivers 0 if the identifier declared by vardec is unused in
214
   used_in delivers 0 if the identifier declared by vardec is unused in
185
   the exp piece, 1 if it is used for contents operation only, 3 if it is
215
   the exp piece, 1 if it is used for contents operation only, 3 if it is
186
   used otherwise.
216
   used otherwise.
187
 ************************************************************************/
217
 ************************************************************************/
188
 
218
 
189
int  used_in
219
int
190
    PROTO_N ( (vardec, piece) )
-
 
191
    PROTO_T ( exp vardec X exp piece )
220
used_in(exp vardec, exp piece)
192
{
221
{
193
  int  res = 0;
222
	int  res = 0;
194
  exp t = pt (vardec);
223
	exp t = pt(vardec);
195
  exp q;
224
	exp q;
196
  exp upwards = t;
225
	exp upwards = t;
197
  do {				/* test each use of the identifier */
226
	/* test each use of the identifier */
-
 
227
	do {
198
    q = t;
228
		q = t;
199
    while (q != nilexp && q != piece && q != vardec && !parked(q) &&
229
		while (q != nilexp && q != piece && q != vardec &&
200
	(name (q) != ident_tag || !isglob(q))) {
230
		       !parked(q) && (name(q) != ident_tag || !isglob(q))) {
201
      upwards = q;
231
			upwards = q;
202
      q = bro (q);
232
			q = bro(q);
203
    };
233
		}
204
    /* ascend from the use until we reach either vardec or piece */
234
		/* ascend from the use until we reach either vardec or piece */
205
    if (last (upwards) && q == piece) {/* the use was in piece */
235
		if (last (upwards) && q == piece) {
-
 
236
			/* the use was in piece */
206
      res = 1;
237
			res = 1;
207
      if ((last(t) || !last(bro(t)) || name(bro(bro(t))) != 0))  {
238
			if ((last(t) || !last(bro(t)) ||
208
        if (!last(t) ||
-
 
209
          name(bro(t)) != cont_tag)
239
			     name(bro(bro(t))) != 0)) {
210
	res = 3;	/* the use was not contents or in diagnostics*/
240
				/* the use was not contents or in diagnostics*/
-
 
241
				if (!last(t) || name(bro(t)) != cont_tag) {
211
     };
242
					res = 3;
212
    };
243
				}
213
    t = pt (t);
244
			}
214
  }
245
		}
-
 
246
		t = pt(t);
215
  while (t != nilexp && res != 3);
247
	} while (t != nilexp && res != 3);
216
  return (res);
248
	return(res);
217
}
249
}
218
 
-
 
219
 
250
 
220
 
251
 
221
/***********************************************************************
252
/***********************************************************************
222
  simple_const tests whether e is used as a simple constant in whole.
253
  simple_const tests whether e is used as a simple constant in whole.
223
  This is true in the following circumstances only.
254
  This is true in the following circumstances only.
Line 226... Line 257...
226
     external to whole.
257
     external to whole.
227
  3) e is the contents of a variable, and the variable is not used
258
  3) e is the contents of a variable, and the variable is not used
228
     in whole as the destination of an assignment, and the variable
259
     in whole as the destination of an assignment, and the variable
229
     is only used (anywhere) as the destination of assignment or
260
     is only used (anywhere) as the destination of assignment or
230
     argument of contents (ie there is no alias for it).
261
     argument of contents (ie there is no alias for it).
231
 
262
 
232
  no_ass is true iff there are no assignements to things that might
263
  no_ass is true iff there are no assignements to things that might
233
  be aliased during the evaluation of whole. (ware procedure calls!)
264
  be aliased during the evaluation of whole. (ware procedure calls!)
234
 ***********************************************************************/
265
 ***********************************************************************/
235
 
266
 
236
int simple_const
267
int
237
    PROTO_N ( (whole, e, decl, no_ass) )
-
 
238
    PROTO_T ( exp whole X exp e X int decl X int no_ass )
268
simple_const(exp whole, exp e, int decl, int no_ass)
239
{
269
{
240
  if (name (e) == val_tag || name (e) == real_tag || name (e) == null_tag)
270
	if (name(e) == val_tag || name(e) == real_tag || name(e) == null_tag) {
241
    return (1);
271
		return(1);
-
 
272
	}
242
  if (name (e) == name_tag && !isvar (son (e)) &&
273
	if (name(e) == name_tag && !isvar(son(e)) &&
243
      (decl || !internal_to (whole, son (e))))
274
	    (decl || !internal_to(whole, son(e)))) {
244
    return (1);
275
		return(1);
-
 
276
	}
245
  if (name (e) == reff_tag)
277
	if (name(e) == reff_tag) {
246
    e = son (e);
278
		e = son(e);
-
 
279
	}
247
  if (name (e) == cont_tag && name (son (e)) == name_tag &&
280
	if (name(e) == cont_tag && name(son(e)) == name_tag &&
248
      !isparam (son (son (e))) &&
281
	    !isparam(son(son(e))) && isvar(son(son(e)))) {
249
      isvar (son (son (e)))) {
-
 
250
    exp var = son (son (e));
282
		exp var = son(son(e));
251
    int  u = used_in (var, whole);
283
		int  u = used_in(var, whole);
252
    if (u != 3 && (iscaonly(var) || no_ass))
284
		if (u != 3 && (iscaonly(var) || no_ass)) {
253
      return (1);
285
			return(1);
-
 
286
		}
254
    return (0);
287
		return(0);
255
  };
288
	}
256
  return (0);
289
	return(0);
257
}
290
}
-
 
291
 
258
 
292
 
259
/* replace declaration by sequence of
293
/* replace declaration by sequence of definition and body. Done if the
260
   definition and body. Done if the
-
 
261
   identifier is not used. */
294
 * identifier is not used. */
262
static void repbyseq
295
static void
263
    PROTO_N ( (e) )
-
 
264
    PROTO_T ( exp e )
296
repbyseq(exp e)
265
{
297
{
266
  exp def = son (e);
298
	exp def = son(e);
267
  exp body = hold_check(bro (def));
299
	exp body = hold_check(bro(def));
268
  exp seq, s;
300
	exp seq, s;
269
#ifdef NEWDIAGS
301
#ifdef NEWDIAGS
270
  exp t = pt (e);
302
	exp t = pt(e);
271
  while (t != nilexp) {
303
	while (t != nilexp) {
272
    if (isdiaginfo(t))
304
		if (isdiaginfo(t))
273
      setdiscarded(t);
305
			setdiscarded(t);
274
    t = pt(t);
306
		t = pt(t);
-
 
307
	}
-
 
308
#endif
-
 
309
	if (son(def) == nilexp) {
-
 
310
#ifdef NEWDIAGS
-
 
311
		if (diagnose) {
-
 
312
			dg_whole_comp(e, body);
275
  }
313
		}
276
#endif
314
#endif
277
  if (son (def) == nilexp) {
-
 
278
#ifdef NEWDIAGS
-
 
279
    if (diagnose)
-
 
280
      dg_whole_comp (e, body);
-
 
281
#endif
-
 
282
    replace (e, body, e);
315
		replace(e, body, e);
283
    retcell (def);
316
		retcell(def);
284
    return;
317
		return;
285
  };
318
	}
286
  seq = getexp (f_bottom, nilexp, 0, def, nilexp, 0, 0, 0);
319
	seq = getexp(f_bottom, nilexp, 0, def, nilexp, 0, 0, 0);
287
  bro (def) = seq;
320
	bro(def) = seq;
288
  setlast (def);
321
	setlast(def);
289
  s = hold_check(make_twoarg (seq_tag, sh (body), seq, body));
322
	s = hold_check(make_twoarg(seq_tag, sh(body), seq, body));
290
#ifdef NEWDIAGS
323
#ifdef NEWDIAGS
291
  if (diagnose)
324
	if (diagnose) {
292
    dg_whole_comp (e, s);
325
		dg_whole_comp(e, s);
-
 
326
	}
293
#endif
327
#endif
294
  replace (e, s, e);
328
	replace(e, s, e);
295
  return;
329
	return;
296
}
330
}
-
 
331
 
297
 
332
 
298
/************************************************************************
333
/************************************************************************
299
   propagate looks right and upwards from plc through the tree, looking
334
   propagate looks right and upwards from plc through the tree, looking
300
   for contents operations applied to the variable defined by vardec.
335
   for contents operations applied to the variable defined by vardec.
301
   The assumption is that plc made an assignment to the variable defined
336
   The assumption is that plc made an assignment to the variable defined
Line 306... Line 341...
306
   The scan terminates if ende is reached or when it is no longer safe
341
   The scan terminates if ende is reached or when it is no longer safe
307
   to propagate the value forward. 1 is delivered if ende was reached
342
   to propagate the value forward. 1 is delivered if ende was reached
308
   while propagation was still safe, 0 otherwise.
343
   while propagation was still safe, 0 otherwise.
309
 ************************************************************************/
344
 ************************************************************************/
310
 
345
 
311
static int propagate
346
static int
312
    PROTO_N ( (vardec, ende, plc, bfirst) )
-
 
313
    PROTO_T ( exp vardec X exp ende X exp plc X int bfirst )
347
propagate(exp vardec, exp ende, exp plc, int bfirst)
314
{
348
{
315
  exp p = plc;			/* starting place */
349
	exp p = plc;		/* starting place */
316
  int good = 1;		/* good is set to 0 when we find a place
350
	int good = 1;		/* good is set to 0 when we find a place
317
				   where we must stop */
351
				   where we must stop */
318
  int bb = bfirst;		/* if bb is 1, avoid the first up */
352
	int bb = bfirst;	/* if bb is 1, avoid the first up */
319
 
-
 
320
 
-
 
321
/* up ascends the tree */
-
 
322
up: if (bb)
-
 
323
    bb = 0;
-
 
324
  else {
-
 
325
    if (p == ende) {		/* finished */
-
 
326
      goto ex;
-
 
327
    }
-
 
328
    else {
-
 
329
      if (!last (p)) {
-
 
330
	p = bro (p);
-
 
331
	if (name (p) == labst_tag) {/* can't go further */
-
 
332
	  good = 0;
-
 
333
	  goto ex;
-
 
334
	};
-
 
335
      }
-
 
336
      else {
-
 
337
	if (name (bro (p)) == proc_tag ||
-
 
338
             name (bro (p)) == labst_tag ||
-
 
339
	     name (bro (p)) == condassign_tag) {
-
 
340
	  /* can't go further */
-
 
341
	  good = 0;
-
 
342
	  goto ex;
-
 
343
	}
-
 
344
	else {
-
 
345
          p = bro(p);
-
 
346
          if ((name (p) == ass_tag || name (p) == assvol_tag) &&
-
 
347
		name (son (p)) == name_tag && son (son (p)) == vardec) {
-
 
348
            good = 0;
-
 
349
            goto ex;
-
 
350
          };
-
 
351
	  goto up;
-
 
352
	};
-
 
353
      }
-
 
354
    };
-
 
355
  };
-
 
356
 
-
 
357
/* rep processes an exp */
-
 
358
rep: if (name (p) == ass_tag || name (p) == assvol_tag) {
-
 
359
    if (name (son (p)) == name_tag && son (son (p)) == vardec) {
-
 
360
      /* just process the value */
-
 
361
      p = bro(son(p));
-
 
362
      goto rep;
-
 
363
    }
-
 
364
    else {			/* assignment to something else */
-
 
365
      p = son (p);
-
 
366
      goto rep;
-
 
367
    };
-
 
368
  };
-
 
369
 
353
 
370
  if (name (p) == cont_tag) {
-
 
371
    if (name (son (p)) == name_tag && son (son (p)) == vardec) {
-
 
372
      set_propagate(p);		/* mark it */
-
 
373
      goto up;
-
 
374
    }
-
 
375
    else {
-
 
376
      p = son (p);
-
 
377
      goto rep;
-
 
378
    };
-
 
379
  };
-
 
380
 
-
 
381
  if (name (p) == name_tag || name(p) == env_offset_tag)
-
 
382
    goto up;
-
 
383
 
-
 
384
  if (name (p) == apply_tag || name(p) == apply_general_tag) {
-
 
385
    if (isglob(vardec)) {/* vardec is global */
-
 
386
      good = 0;
-
 
387
      goto ex;
-
 
388
    }
-
 
389
    else {			/* not aliased so OK */
-
 
390
      p = son (p);
-
 
391
      goto rep;
-
 
392
    };
-
 
393
  };
-
 
394
 
-
 
395
  if (name (p) == rep_tag) {
-
 
396
      good = 0;
-
 
397
      goto ex;
-
 
398
  };
-
 
399
 
-
 
400
  if (name (p) == cond_tag) {
-
 
401
    if (propagate (vardec, son (p), son (p), 1)) {
-
 
402
      good = propagate (vardec, bro(son(bro (son (p)))),
-
 
403
			 bro(son(bro (son (p)))), 1);
-
 
404
      /* if we can propagate right through the first of the cond we can go
-
 
405
         into the alt. This condition is stronger than needed. */
-
 
406
      if (good)
-
 
407
	goto up;
-
 
408
      else
-
 
409
	goto ex;
-
 
410
    }
-
 
411
    else {
-
 
412
      good = 0;
-
 
413
      goto ex;
-
 
414
    };
-
 
415
  };
-
 
416
 
-
 
417
  if (name (p) == solve_tag) {
-
 
418
    IGNORE propagate (vardec, son (p), son (p), 1);
-
 
419
    /* give up after trying the first element */
-
 
420
    good = 0;
-
 
421
    goto ex;
-
 
422
  };
-
 
423
 
354
 
-
 
355
	/* up ascends the tree */
-
 
356
up:	if (bb) {
-
 
357
		bb = 0;
-
 
358
	} else {
-
 
359
		if (p == ende) {		/* finished */
-
 
360
			goto ex;
-
 
361
		} else {
-
 
362
			if (!last(p)) {
-
 
363
				p = bro(p);
-
 
364
				if (name(p) == labst_tag) {
-
 
365
					/* can't go further */
-
 
366
					good = 0;
-
 
367
					goto ex;
-
 
368
				}
-
 
369
			} else {
-
 
370
				if (name(bro(p)) == proc_tag ||
-
 
371
				    name(bro(p)) == labst_tag ||
-
 
372
				    name(bro(p)) == condassign_tag) {
-
 
373
					/* can't go further */
-
 
374
					good = 0;
-
 
375
					goto ex;
-
 
376
				} else {
-
 
377
					p = bro(p);
-
 
378
					if ((name(p) == ass_tag ||
-
 
379
					     name(p) == assvol_tag) &&
-
 
380
					    name(son(p)) == name_tag &&
-
 
381
					    son(son(p)) == vardec) {
-
 
382
						good = 0;
-
 
383
						goto ex;
-
 
384
					}
-
 
385
					goto up;
-
 
386
				}
-
 
387
			}
-
 
388
		}
-
 
389
	}
-
 
390
 
-
 
391
	/* rep processes an exp */
-
 
392
rep:	if (name(p) == ass_tag || name(p) == assvol_tag) {
-
 
393
		if (name(son(p)) == name_tag && son(son(p)) == vardec) {
-
 
394
			/* just process the value */
-
 
395
			p = bro(son(p));
-
 
396
			goto rep;
-
 
397
		} else {
-
 
398
			/* assignment to something else */
-
 
399
			p = son(p);
-
 
400
			goto rep;
-
 
401
		}
-
 
402
	}
-
 
403
 
-
 
404
	if (name(p) == cont_tag) {
-
 
405
		if (name(son(p)) == name_tag && son(son(p)) == vardec) {
-
 
406
			set_propagate(p);		/* mark it */
-
 
407
			goto up;
-
 
408
		} else {
-
 
409
			p = son(p);
-
 
410
			goto rep;
-
 
411
		}
-
 
412
	}
-
 
413
 
-
 
414
	if (name(p) == name_tag || name(p) == env_offset_tag) {
-
 
415
		goto up;
-
 
416
	}
-
 
417
 
-
 
418
	if (name(p) == apply_tag || name(p) == apply_general_tag) {
-
 
419
		if (isglob(vardec)) {
-
 
420
			/* vardec is global */
-
 
421
			good = 0;
-
 
422
			goto ex;
-
 
423
		} else {
-
 
424
			/* not aliased so OK */
-
 
425
			p = son(p);
-
 
426
			goto rep;
-
 
427
		}
-
 
428
	}
-
 
429
 
-
 
430
	if (name(p) == rep_tag) {
-
 
431
		good = 0;
-
 
432
		goto ex;
-
 
433
	}
-
 
434
 
-
 
435
	if (name(p) == cond_tag) {
-
 
436
		if (propagate(vardec, son(p), son(p), 1)) {
-
 
437
			good = propagate(vardec, bro(son(bro(son(p)))),
-
 
438
					 bro(son(bro(son(p)))), 1);
-
 
439
			/* if we can propagate right through the first of the
-
 
440
			 * cond we can go into the alt. This condition is
-
 
441
			 * stronger than needed. */
-
 
442
			if (good) {
-
 
443
				goto up;
-
 
444
			} else {
-
 
445
				goto ex;
-
 
446
			}
-
 
447
		} else {
-
 
448
			good = 0;
-
 
449
			goto ex;
-
 
450
		}
-
 
451
	}
-
 
452
 
-
 
453
	if (name(p) == solve_tag) {
-
 
454
		IGNORE propagate(vardec, son(p), son(p), 1);
-
 
455
		/* give up after trying the first element */
-
 
456
		good = 0;
-
 
457
		goto ex;
-
 
458
	}
-
 
459
 
424
  if (name (p) == case_tag) {
460
	if (name(p) == case_tag) {
425
    if (propagate (vardec, son (p), son (p), 1))
461
		if (propagate(vardec, son(p), son(p), 1)) {
426
      goto up;
462
			goto up;
-
 
463
		}
427
    good = 0;
464
		good = 0;
428
    goto ex;
465
		goto ex;
-
 
466
	}
-
 
467
 
-
 
468
	if (son(p) == nilexp) {
-
 
469
		goto up;
429
  };
470
	}
-
 
471
 
-
 
472
	p = son(p);
-
 
473
	goto rep;
430
 
474
 
431
  if (son (p) == nilexp)
-
 
432
    goto up;
-
 
433
 
475
 
434
  p = son (p);
476
ex:	return(good);
435
  goto rep;
477
}
436
 
478
 
437
 
-
 
438
ex: return (good);
-
 
439
}
-
 
440
 
479
 
441
/*******************************************************************
480
/*******************************************************************
442
   change_cont looks at all the cont uses of the variable defined by
481
   change_cont looks at all the cont uses of the variable defined by
443
   vardec. If they have been marked by propagate or if force is 1,
482
   vardec. If they have been marked by propagate or if force is 1,
444
   the cont(var) is replaced by val.
483
   the cont(var) is replaced by val.
445
 *******************************************************************/
484
 *******************************************************************/
446
 
485
 
447
static exp change_shape
486
static exp
448
    PROTO_N ( (e, sha) )
-
 
449
    PROTO_T ( exp e X shape sha )
487
change_shape(exp e, shape sha)
450
{
488
{
451
  if (name (e) == val_tag)
489
	if (name(e) == val_tag) {
452
    no (e) = dochvar (no (e), sha);
490
		no(e) = dochvar(no(e), sha);
-
 
491
	}
453
  sh (e) = sha;
492
	sh(e) = sha;
454
  return (e);
493
	return(e);
455
}
494
}
-
 
495
 
456
 
496
 
457
static int change_cont
497
static int
458
    PROTO_N ( (vardec, val, force) )
-
 
459
    PROTO_T ( exp vardec X exp val X int force )
498
change_cont(exp vardec, exp val, int force)
460
{
499
{
461
  exp t;
500
	exp t;
462
  exp bh = hold (bro (son (vardec)));
501
	exp bh = hold(bro(son(vardec)));
463
  int ch = 0;
502
	int ch = 0;
464
  int go = 1;
503
	int go = 1;
465
  int defsize = shape_size(sh(son(vardec)));
504
	int defsize = shape_size(sh(son(vardec)));
466
  while (go) {
505
	while (go) {
467
    t = pt (vardec);
506
		t = pt(vardec);
468
    go = 0;
507
		go = 0;
469
    while (!go && t != nilexp) {
508
		while (!go && t != nilexp) {
470
      if (last (t) && name (bro (t)) == cont_tag &&
509
			if (last(t) && name(bro(t)) == cont_tag &&
471
#ifdef NEWDIAGS
510
#ifdef NEWDIAGS
472
	  !isdiaginfo(t) &&
511
			    !isdiaginfo(t) &&
473
#endif
512
#endif
474
	  (to_propagate (bro (t)) || force)) {
513
			    (to_propagate(bro(t)) || force)) {
475
        if (defsize == shape_size(sh(bro(t)))) {
514
				if (defsize == shape_size(sh(bro(t)))) {
476
	   exp p = bro (t);
515
					exp p = bro(t);
477
	   exp c = change_shape (copy (val), sh (p));
516
					exp c = change_shape(copy(val), sh(p));
478
	   kill_exp (t, son(bh));
517
					kill_exp(t, son(bh));
479
	   replace (p, c, son(bh));
518
					replace(p, c, son(bh));
480
	   retcell (p);
519
					retcell(p);
481
	   t = pt (vardec);
520
					t = pt(vardec);
482
	   ch = 1;
521
					ch = 1;
483
	   go = 1;
522
					go = 1;
484
        }
-
 
485
        else
523
				} else {
486
          clear_propagate(bro(t));
524
					clear_propagate(bro(t));
487
      }
525
				}
488
      else
526
			} else {
489
	t = pt (t);
527
				t = pt(t);
490
    };
528
			}
491
  };
529
		}
-
 
530
	}
492
  bro (son (vardec)) = son (bh);
531
	bro(son(vardec)) = son(bh);
493
  setlast (bro (son (vardec)));
532
	setlast(bro(son(vardec)));
494
  bro (bro (son (vardec))) = vardec;
533
	bro(bro(son(vardec))) = vardec;
495
  retcell (bh);
534
	retcell(bh);
496
  return (ch);
535
	return(ch);
497
}
536
}
-
 
537
 
498
 
538
 
499
/*********************************************************************
539
/*********************************************************************
500
   checks identity and variable declarations.
540
   checks identity and variable declarations.
501
 *********************************************************************/
541
 *********************************************************************/
502
 
542
 
503
 
543
int
504
int check_id
-
 
505
    PROTO_N ( (e, scope) )
-
 
506
    PROTO_T ( exp e X exp scope )
544
check_id(exp e, exp scope)
507
{
545
{
508
  int is_var = isvar (e);
546
  int is_var = isvar(e);
509
  int is_vis = (all_variables_visible || isvis (e));
547
  int is_vis = (all_variables_visible || isvis(e));
510
  exp def = son (e);
548
  exp def = son(e);
511
  exp body = bro (def);
549
  exp body = bro(def);
512
  int looping;
550
  int looping;
513
  exp t1;
551
  exp t1;
514
 
552
 
515
  if ( no (e) == 0 )
553
  if (no(e) == 0) {
516
  {
-
 
517
    if (!isvis(e) && !isenvoff(e) && !isglob (e) && !isparam(e)) {
554
    if (!isvis(e) && !isenvoff(e) && !isglob(e) && !isparam(e)) {
518
		/* the variable is not used */
555
      /* the variable is not used */
519
      repbyseq (e);
556
      repbyseq(e);
520
      return (1);
557
      return(1);
-
 
558
    } else {
-
 
559
      if (isparam(e)) {
-
 
560
	setcaonly(e);
-
 
561
      }
-
 
562
      return 0;
521
    }
563
    }
522
    else
-
 
523
     {
-
 
524
       if (isparam(e))
-
 
525
         setcaonly(e);
-
 
526
       return 0;
-
 
527
     };
-
 
528
  };
564
  }
529
 
565
 
530
 
566
 
531
#if load_ptr_pars
567
#if load_ptr_pars
532
  if (!is_vis && is_var && isparam(e) && no(e) > 1 &&
568
  if (!is_vis && is_var && isparam(e) && no(e) > 1 && name(sh(def)) == ptrhd
533
	name(sh(def)) == ptrhd
-
 
534
#if is68000
569
#if is68000
535
	&& check_anyway(e)
570
      && check_anyway(e)
536
#endif
571
#endif
537
	) {
572
     ) {
538
    int ch_load = 1;
573
    int ch_load = 1;
539
    int sz = shape_size(sh(def));
574
    int sz = shape_size(sh(def));
540
    t1 = pt (e);
575
    t1 = pt(e);
541
    looping = 1;
576
    looping = 1;
542
    do {
577
    do {
543
#ifdef NEWDIAGS
578
#ifdef NEWDIAGS
544
      if (!isdiaginfo(t1)) {
579
      if (!isdiaginfo(t1)) {
545
#endif
580
#endif
546
 
581
 
547
	if (!last (t1) && last (bro (t1)) &&
-
 
548
	    name (bro (bro (t1))) == ass_tag &&
582
	if (!last(t1) && last(bro(t1)) && name(bro(bro(t1))) == ass_tag &&
549
	    shape_size(sh(bro(t1))) == sz) {
583
	    shape_size(sh(bro(t1))) == sz) {
550
	  ;
584
	  ;
-
 
585
	} else if (!last(t1) || name(bro(t1)) != cont_tag ||
-
 
586
		   shape_size(sh(bro(t1))) != sz) {
-
 
587
	  ch_load = 0;
551
	}
588
	}
552
	else
-
 
553
	if (!last (t1) || name (bro (t1)) != cont_tag ||
-
 
554
	     shape_size(sh(bro(t1))) != sz)
-
 
555
	    ch_load = 0;
-
 
556
 
589
 
557
#ifdef NEWDIAGS
590
#ifdef NEWDIAGS
558
      };
591
      }
559
#endif
592
#endif
560
	if (pt (t1) == nilexp)
593
      if (pt(t1) == nilexp) {
561
	  looping = 0;
594
	looping = 0;
562
	else
595
      } else {
563
	  t1 = pt (t1);
596
	t1 = pt(t1);
564
    }
597
      }
565
    while (looping && ch_load);
598
    } while (looping && ch_load);
566
 
599
 
567
    if (ch_load) {
600
    if (ch_load) {
568
      exp old_pt_list = pt(e);
601
      exp old_pt_list = pt(e);
569
      int old_uses = no(e);
602
      int old_uses = no(e);
570
      exp new_var;
603
      exp new_var;
571
      exp new_n;
604
      exp new_n;
572
      exp real_body;
605
      exp real_body;
573
 
606
 
574
      t1 = e;
607
      t1 = e;
575
      while (name(bro(son(t1))) == ident_tag && isparam(bro(son(t1))))
608
      while (name(bro(son(t1))) == ident_tag && isparam(bro(son(t1)))) {
576
        t1 = bro(son(t1));
609
	t1 = bro(son(t1));
-
 
610
      }
577
      real_body = bro(son(t1));
611
      real_body = bro(son(t1));
578
 
612
 
579
      new_n = getexp(sh(def), real_body, 0, e, nilexp, 0,
613
      new_n = getexp(sh(def), real_body, 0, e, nilexp, 0, 0, name_tag);
580
			 0, name_tag);
-
 
581
      new_var = getexp(sh(e), nilexp, 0, new_n, old_pt_list,
614
      new_var = getexp(sh(e), nilexp, 0, new_n, old_pt_list, 1, old_uses,
582
                          1, old_uses, ident_tag);
615
		       ident_tag);
583
      setloadparam(new_n);
616
      setloadparam(new_n);
584
      setfather(new_var, real_body);
617
      setfather(new_var, real_body);
585
      pt(e) = new_n;
618
      pt(e) = new_n;
586
      no(e) = 1;
619
      no(e) = 1;
587
      clearvar(e);
620
      clearvar(e);
588
      while (old_pt_list != nilexp)
621
      while (old_pt_list != nilexp) {
589
       {
-
 
590
         son(old_pt_list) = new_var;
622
	son(old_pt_list) = new_var;
591
         old_pt_list = pt(old_pt_list);
623
	old_pt_list = pt(old_pt_list);
592
       };
624
      }
593
      new_var = hold_check(new_var);
625
      new_var = hold_check(new_var);
594
 
626
 
595
      bro(son(t1)) = new_var;
627
      bro(son(t1)) = new_var;
596
      setfather(t1, new_var);
628
      setfather(t1, new_var);
597
      return 1;
629
      return 1;
598
    };
630
    }
599
  };
631
  }
600
#endif
632
#endif
601
 
633
 
602
  if (!is_vis && !is_var &&
634
  if (!is_vis && !is_var &&
603
#if load_ptr_pars
635
#if load_ptr_pars
604
	(name(def) != name_tag || !isloadparam(def)) &&
636
      (name(def) != name_tag || !isloadparam(def)) &&
605
#endif
637
#endif
606
      (name (def) == val_tag ||
638
      (name(def) == val_tag ||
607
#if load_ptr_pars
639
#if load_ptr_pars
608
	(name (def) == name_tag &&
640
       (name(def) == name_tag &&
609
             (!isparam(son(def)) || name(sh(def)) == ptrhd))
641
	(!isparam(son(def)) || name(sh(def)) == ptrhd))
610
#else
642
#else
611
         name (def) == name_tag
643
       name(def) == name_tag
612
#endif
644
#endif
613
          ||
645
       ||
614
#if is80x86
646
#if is80x86
615
	(name(def) == name_tag && isparam(son(def)) && !isvar(son(def)) &&
647
       (name(def) == name_tag && isparam(son(def)) && !isvar(son(def)) &&
616
		shape_size(sh(def)) < shape_size(sh(son(son(def)))) &&
648
	shape_size(sh(def)) < shape_size(sh(son(son(def)))) &&
617
		name(sh(def)) <= ulonghd) ||
649
	name(sh(def)) <= ulonghd) ||
618
#endif
650
#endif
619
 
651
 
620
	( /* substitute the definitions of identity declarations into
652
       /* substitute the definitions of identity declarations into body
621
             body if it seems cheaper to do so */
653
	* if it seems cheaper to do so */
622
	  name (def) == reff_tag && name (son (def)) == cont_tag &&
654
       (name(def) == reff_tag && name(son(def)) == cont_tag &&
623
	  name (son (son (def))) == name_tag &&
655
	name(son(son(def))) == name_tag && isvar(son(son(son(def)))) &&
624
	  isvar (son (son (son (def)))) &&
-
 
625
	  !isglob (son (son (son (def)))) &&
656
	!isglob(son(son(son(def)))) &&
626
	  used_in(son (son (son (def))), body) != 3
657
	used_in(son(son(son(def))), body) != 3) ||
627
	) ||
-
 
628
	(
-
 
629
	  name (def) == reff_tag && name (son (def)) == name_tag &&
658
       (name(def) == reff_tag && name(son(def)) == name_tag &&
630
	  isvar (son (son (def))) &&
-
 
631
	  !isglob (son (son (def))) &&
659
	isvar(son(son(def))) && !isglob(son(son(def))) &&
632
	  used_in(son (son (def)), body) != 3
660
	used_in(son(son(def)), body) != 3) || name(def) == null_tag ||
633
	) ||
-
 
634
	name (def) == null_tag ||
-
 
635
	name (def) == real_tag)) {
661
       name(def) == real_tag)) {
636
/*     identifying a constant or named value */
662
	 /* identifying a constant or named value */
637
      {
-
 
638
#if !substitute_params
663
#if !substitute_params
639
      int   do_anyway = 0;
664
    int do_anyway = 0;
640
#else
665
#else
641
      int   do_anyway = 1;
666
    int do_anyway = 1;
642
#endif
667
#endif
643
      if (do_anyway || name (def) != name_tag ||
668
    if (do_anyway || name(def) != name_tag || !isparam(son(def)) ||
644
	  !isparam (son (def)) ||
669
	isvar(son(def))) {
-
 
670
      exp bh = hold(body);
-
 
671
#ifdef NEWDIAGS
-
 
672
      dg_info dgh = dgf(def);
-
 
673
      /* don't copy line info to all uses */
-
 
674
      dgf(def) = nildiag;
-
 
675
#endif
-
 
676
      while (pt(e) != nilexp) {
-
 
677
	exp mem = pt(e);
-
 
678
	exp cp;
-
 
679
	pt(e) = pt(mem);
-
 
680
	cp = copy(def);
-
 
681
#ifdef NEWDIAGS
645
	  isvar (son (def))) {
682
	if (isdiaginfo(mem)) {
-
 
683
	  IGNORE diaginfo_exp(cp);
-
 
684
	} else {
-
 
685
	  --no(e);
-
 
686
	}
-
 
687
#else
-
 
688
	--no(e);
-
 
689
#endif
-
 
690
	if (name(cp) == name_tag) {
-
 
691
	  no(cp) += no(mem);
-
 
692
	}
-
 
693
	if (sh(cp) != sh(mem)) {
-
 
694
	  if (name(sh(cp)) <= u64hd) {
-
 
695
	    cp = hold_check(me_u3(sh(mem), cp, chvar_tag));
-
 
696
	  } else {
646
	exp bh = hold (body);
697
	    sh(cp) = sh(mem);
-
 
698
	  }
-
 
699
	}
647
#ifdef NEWDIAGS
700
#ifdef NEWDIAGS
648
	dg_info dgh = dgf(def);
701
	if (diagnose) {
649
	dgf(def) = nildiag;	/* don't copy line info to all uses */
702
	  dg_whole_comp(mem, cp);
-
 
703
	}
650
#endif
704
#endif
651
	while (pt (e) != nilexp) {
-
 
652
	  exp mem = pt (e);
705
	replace(mem, cp, body);
653
	  exp cp;
706
      }
654
	  pt (e) = pt (mem);
-
 
655
	  cp = copy (def);
-
 
656
#ifdef NEWDIAGS
707
#ifdef NEWDIAGS
657
	  if (isdiaginfo(mem))
-
 
658
	    IGNORE diaginfo_exp (cp);
-
 
659
	  else
-
 
660
	    --no (e);
-
 
661
#else
-
 
662
	  --no (e);
-
 
663
#endif
-
 
664
	  if (name (cp) == name_tag)
-
 
665
	    no (cp) += no (mem);
-
 
666
	  if (sh(cp) != sh(mem)) {
-
 
667
	    if (name(sh(cp)) <= u64hd)
-
 
668
	      cp = hold_check(me_u3(sh(mem), cp, chvar_tag));
-
 
669
	    else
-
 
670
	      sh (cp) = sh (mem);
-
 
671
	  };
-
 
672
#ifdef NEWDIAGS
-
 
673
	  if (diagnose)
-
 
674
	    dg_whole_comp (mem, cp);
-
 
675
#endif
-
 
676
	  replace (mem, cp, body);
-
 
677
	};
-
 
678
#ifdef NEWDIAGS
-
 
679
	dgf(def) = dgh;
708
      dgf(def) = dgh;
680
#endif
709
#endif
681
	bro (def) = son (bh);
710
      bro(def) = son(bh);
682
	bro (bro (def)) = e;
711
      bro(bro(def)) = e;
683
	setlast (bro (def));
712
      setlast(bro(def));
684
	retcell (bh);
713
      retcell(bh);
685
	IGNORE check (e, scope);
714
      IGNORE check(e, scope);
686
	return (1);
715
      return(1);
687
      };
-
 
688
    };
716
    }
689
  };
717
  }
690
 
-
 
691
  if (!is_vis && !is_var &&
-
 
692
         name(def) == reff_tag && al1(sh(def)) == 1
-
 
693
 
718
 
-
 
719
  if (!is_vis && !is_var && name(def) == reff_tag && al1(sh(def)) == 1) {
694
     )  {  /* also substitute identity definitions which are references
720
    /* also substitute identity definitions which are references
695
              to bitfields. */
721
       to bitfields. */
696
    exp t = pt(e);
722
    exp t = pt(e);
697
    int n = no(def);
723
    int n = no(def);
698
    shape sha = sh(def);
724
    shape sha = sh(def);
699
    shape shb = sh(son(def));
725
    shape shb = sh(son(def));
700
    exp q, k;
726
    exp q, k;
701
 
727
 
702
#ifdef NEWDIAGS
728
#ifdef NEWDIAGS
703
    if (diagnose)
729
    if (diagnose) {
704
      dg_whole_comp (def, son(def));
730
      dg_whole_comp(def, son(def));
-
 
731
    }
705
#endif
732
#endif
706
    replace(def, son(def), son(def));
733
    replace(def, son(def), son(def));
707
 
734
 
708
    while (1)
735
    while (1) {
709
     {
-
 
710
       k = pt(t);
736
      k = pt(t);
711
       q = getexp(sha, nilexp, 0, copy(t), nilexp, 0, n, reff_tag);
737
      q = getexp(sha, nilexp, 0, copy(t), nilexp, 0, n, reff_tag);
712
       sh(son(q)) = shb;
738
      sh(son(q)) = shb;
713
       q = hc(q, son(q));
739
      q = hc(q, son(q));
714
       replace(t, q, q);
740
      replace(t, q, q);
715
       kill_exp(t, t);
741
      kill_exp(t, t);
716
       if (k == nilexp)
742
      if (k == nilexp) {
717
         return 1;
743
	return 1;
-
 
744
      }
718
       t = k;
745
      t = k;
719
     };
746
    }
720
  };
747
  }
721
 
-
 
722
 
748
 
723
  if (!is_vis && !is_var && name (def) == string_tag) {
749
  if (!is_vis && !is_var && name(def) == string_tag) {
724
         /* and substitute strings */
750
    /* and substitute strings */
725
    exp t = pt (e);
751
    exp t = pt(e);
726
    int all_chars = 1;
752
    int all_chars = 1;
727
    while (1) {
753
    while (1) {
728
      if (name (sh (t)) > ucharhd) {
754
      if (name(sh(t)) > ucharhd) {
729
	all_chars = 0;
755
	all_chars = 0;
730
	break;
756
	break;
731
      };
757
      }
-
 
758
      if (last (t)) {
732
      if (last (t))	/* Surely this is wrong ??? */
759
	/* Surely this is wrong ??? */
733
	break;
760
	break;
-
 
761
      }
734
      t = pt (t);
762
      t = pt(t);
735
    };
763
    }
736
    if (all_chars) {
764
    if (all_chars) {
737
      char *str = nostr(def);
765
      char *str = nostr(def);
738
 
766
 
739
      t = pt (e);
767
      t = pt(e);
740
      while (1) {
768
      while (1) {
741
	int l = (int)last (t);	/* Surely this is wrong ??? */
769
	/* Surely this is wrong ??? */
-
 
770
	int l = (int)last (t);
-
 
771
 
742
	exp n = bro (t);
772
	exp n = bro(t);
743
	int  v = str[no (t) / 8];
773
	int  v = str[no(t) / 8];
744
	exp c;
774
	exp c;
745
        if (name (sh (t)) == ucharhd)
775
	if (name(sh(t)) == ucharhd) {
746
	  v = v & 0xff;
776
	  v = v & 0xff;
-
 
777
	}
747
        c = getexp (sh (t), nilexp, 0, nilexp, nilexp, 0, v, val_tag);
778
	c = getexp(sh(t), nilexp, 0, nilexp, nilexp, 0,
-
 
779
		   v, val_tag);
748
	replace (t, c, c);
780
	replace(t, c, c);
749
	kill_exp (t, t);
781
	kill_exp(t, t);
750
	if (l)
782
	if (l) {
751
	  break;
783
	  break;
-
 
784
	}
752
	t = n;
785
	t = n;
753
      };
786
      }
754
      if (no (e) == 0) {
787
      if (no(e) == 0) {
755
	replace (e, bro (son (e)), scope);
788
	replace(e, bro(son(e)), scope);
756
	return (1);
789
	return(1);
757
      };
790
      }
758
      return (0);
791
      return(0);
759
    };
792
    }
760
  };
793
  }
761
 
794
 
762
 
-
 
763
  if (!is_vis && !is_var &&
795
  if (!is_vis && !is_var && name(body) == seq_tag &&
764
      name (body) == seq_tag && name (son (son (body))) == ass_tag &&
796
      name(son(son(body))) == ass_tag && name(bro(son(body))) == name_tag) {
765
      name (bro (son (body))) == name_tag) {
-
 
766
    exp tb = bro (son (son (son (body))));
797
    exp tb = bro(son(son(son(body))));
767
    if (name (tb) == name_tag && son (tb) == e &&
798
    if (name(tb) == name_tag && son(tb) == e &&
768
	son (bro (son (body))) == e &&
799
	son(bro(son(body))) == e && last(son(son(body))) &&
769
	last (son (son (body))) &&
-
 
770
	sh (tb) == sh (def) && sh (tb) == sh (bro (son (body)))) {
800
	sh(tb) == sh(def) && sh(tb) == sh(bro(son(body)))) {
771
      /*  e=id(def, seq(ass(tz, n(e)), n(e)) -> seq(ass(tz, def),
801
      /*  e=id(def, seq(ass(tz, n(e)), n(e)) -> seq(ass(tz,
772
         cont(tz)) */
802
       *  def), cont(tz)) */
773
      exp ass = son (son (body));
803
      exp ass = son(son(body));
774
      exp tz = son (ass);
804
      exp tz = son(ass);
775
      exp r, s, c;
805
      exp r, s, c;
776
      exp cz = copy (tz);
806
      exp cz = copy(tz);
777
      bro (tz) = def;
807
      bro(tz) = def;
778
      ass = hc (ass, def);
808
      ass = hc(ass, def);
779
      r = getexp (f_top, nilexp, 0, ass, nilexp, 0, 0, 0);
809
      r = getexp(f_top, nilexp, 0, ass, nilexp, 0, 0, 0);
780
      setlast (ass);
810
      setlast(ass);
781
      bro (ass) = r;
811
      bro(ass) = r;
782
      s = getexp (sh (body), nilexp, 0, r, nilexp, 0, 0, seq_tag);
812
      s = getexp(sh(body), nilexp, 0, r, nilexp, 0, 0, seq_tag);
783
      c = getexp (sh (body), s, 1, cz, nilexp, 0, 0, cont_tag);
813
      c = getexp(sh(body), s, 1, cz, nilexp, 0, 0, cont_tag);
784
      setbro (r, hc (c, cz));
814
      setbro(r, hc(c, cz));
785
      replace (e, hc (s, bro (son (s))), e);
815
      replace(e, hc(s, bro(son(s))), e);
786
      return (1);
816
      return(1);
787
    };
817
    }
788
  };
818
  }
789
 
819
 
790
    /* look to see if we can replace variable definitions by identities.
820
  /* look to see if we can replace variable definitions by identities.
791
       This can be done if there are only contents operations and no
821
     This can be done if there are only contents operations and no
792
       aliasing */
822
     aliasing */
-
 
823
  if (!is_vis && is_var) {
793
  if (!is_vis && is_var) {	/* variable declaration */
824
    /* variable declaration */
794
    int all_c = 1;		/* every use is a contents operation */
825
    int all_c = 1;	/* every use is a contents operation */
795
    int all_a = 1;		/* every use is an assignment operation */
826
    int all_a = 1;	/* every use is an assignment operation */
796
    int not_aliased = 1;
827
    int not_aliased = 1;
797
    int ca = 0;		/* there is an assignment of a constant */
828
    int ca = 0;		/* there is an assignment of a constant */
798
    int vardecass = 0;		/* there is an assignment of a variable
829
    int vardecass = 0;	/* there is an assignment of a variable
799
				   (not its contents) (lhvalue in C
830
			   (not its contents) (lhvalue in C
800
				   terms). */
831
			   terms). */
801
    exp assd_val;		/* the assigned value */
832
    exp assd_val;	/* the assigned value */
802
    int conversion = 0;
833
    int conversion = 0;
803
    int biggest_assigned_const = 0;
834
    int biggest_assigned_const = 0;
804
    exp tc = pt (e);
835
    exp tc = pt(e);
805
    int defsize = shape_size(sh(def));
836
    int defsize = shape_size(sh(def));
-
 
837
    do {
806
    do {			/* scan the uses of the variable */
838
      /* scan the uses of the variable */
807
      if (last(tc) && (name(bro(tc)) == hold_tag || name(bro(tc))==hold2_tag)){
839
      if (last(tc) && (name(bro(tc)) == hold_tag ||
-
 
840
		       name(bro(tc)) == hold2_tag)) {
808
#ifdef NEWDIAGS
841
#ifdef NEWDIAGS
809
        if (diag_visible) {
842
	if (diag_visible) {
810
#else
843
#else
811
        if (diagnose) {
844
	if (diagnose) {
812
#endif
845
#endif
813
		setvis(e);
846
	  setvis(e);
814
		return 0;
847
	  return 0;
815
	}
848
	}
816
      }
-
 
817
      else  {
849
      } else {
818
      if (last (tc) && name (bro (tc)) == cont_tag && no(tc) == 0 &&
850
	if (last(tc) && name(bro(tc)) == cont_tag && no(tc) == 0 &&
819
#ifdef NEWDIAGS
851
#ifdef NEWDIAGS
820
	   !isdiaginfo(tc) &&
852
	    !isdiaginfo(tc) &&
821
#endif
853
#endif
822
           (name(sh(bro(tc)))<shrealhd || name(sh(bro(tc)))>doublehd ||
854
	    (name(sh(bro(tc))) <shrealhd || name(sh(bro(tc))) >doublehd ||
823
            (name(sh(def)) >= shrealhd && name(sh(def)) <= doublehd) )) {
855
	     (name(sh(def)) >= shrealhd && name(sh(def)) <= doublehd))) {
824
	int qq = shape_size(sh(bro (tc)));
856
	  int qq = shape_size(sh(bro(tc)));
825
	all_a = 0;		/* contents op so not all assignments */
857
	  /* contents op so not all
-
 
858
	   * assignments */
-
 
859
	  all_a = 0;
-
 
860
 
826
	if (name(father(bro(tc))) != test_tag)
861
	  if (name(father(bro(tc))) != test_tag) {
827
	  conversion = -1;
862
	    conversion = -1;
828
	if ((defsize != qq) &&
863
	  }
829
	    (name(sh(def)) < shrealhd))
864
	  if ((defsize != qq) && (name(sh(def)) < shrealhd)) {
830
         {
-
 
831
#if is80x86
865
#if is80x86
832
	  if (!isparam(e) || no(e) != 1) {
866
	    if (!isparam(e) || no(e) != 1) {
833
	   if (no(tc) == 0 && defsize <= 32) {
867
	      if (no(tc) == 0 && defsize <= 32) {
834
	    if (qq == 8)
868
		if (qq == 8) {
835
	      setbyteuse(e);
869
		  setbyteuse(e);
-
 
870
		}
-
 
871
	      } else {
-
 
872
		all_c = 0;
-
 
873
		not_aliased = 0;
-
 
874
	      }
836
	   }
875
	    }
837
	   else {
876
#else
838
            all_c = 0;
877
	    all_c = 0;
839
	    not_aliased = 0;
878
	    not_aliased = 0;
-
 
879
#endif
840
	   }
880
	  }
-
 
881
	} else {
-
 
882
	  if (!last(tc) && last(bro(tc)) && no(tc) == 0 &&
-
 
883
#ifdef NEWDIAGS
-
 
884
	      !isdiaginfo(tc) &&
-
 
885
#endif
-
 
886
	      name(bro(bro(tc))) == ass_tag) {
-
 
887
	    /* assignment op */
-
 
888
	    all_c = 0;		/* not all contents */
-
 
889
	    assd_val = bro(tc);
-
 
890
 
-
 
891
	    if (name(assd_val) == val_tag) {
-
 
892
	      if (no(assd_val) < 0) {
-
 
893
		conversion = -1;
-
 
894
	      }
-
 
895
	      if (no(assd_val) > biggest_assigned_const) {
-
 
896
		biggest_assigned_const = no(assd_val);
-
 
897
	      }
-
 
898
	    } else if (name(assd_val) == chvar_tag &&
-
 
899
		       name(sh(son(assd_val))) <= uwordhd &&
-
 
900
		       is_signed(sh(son(assd_val)))) {
-
 
901
	      int sz1 = shape_size(sh(son(assd_val)));
-
 
902
	      if (conversion == 0) {
-
 
903
		conversion = sz1;
-
 
904
	      } else if (conversion != sz1) {
-
 
905
		conversion = -1;
-
 
906
	      }
-
 
907
	    } else {
-
 
908
	      conversion = -1;
841
	  }
909
	    }
-
 
910
 
-
 
911
	    if (defsize != shape_size(sh(assd_val))) {
-
 
912
#if is80x86
-
 
913
	      if (no(tc) == 0 && defsize <= 32) {
-
 
914
		if (shape_size(sh(bro(tc))) == 8) {
-
 
915
		  setbyteuse(e);
-
 
916
		}
-
 
917
	      } else {
-
 
918
		all_a = 0;
-
 
919
		not_aliased = 0;
-
 
920
	      }
842
#else
921
#else
843
          all_c = 0;
922
	      all_a = 0;
844
	  not_aliased = 0;
923
	      not_aliased = 0;
-
 
924
#endif
-
 
925
	    }
-
 
926
	    if (name(assd_val) == val_tag || name(assd_val) == real_tag ||
-
 
927
		name(assd_val) == null_tag ||
-
 
928
		(name(assd_val) == name_tag && isglob(son(assd_val)))) {
-
 
929
	      ca = 1;		/* assigning a constant */
-
 
930
	    } else {
-
 
931
	      if (name(assd_val) == ident_tag && isvar(assd_val)) {
-
 
932
		vardecass = 1;
-
 
933
	      }
-
 
934
	    }
-
 
935
	  } else
-
 
936
#ifdef NEWDIAGS
-
 
937
		  if (!isdiaginfo(tc))
845
#endif
938
#endif
-
 
939
		  {
-
 
940
		    if (isreallyass(tc)) {
-
 
941
		      all_c = 0;
-
 
942
		      all_a = 0; /* so that we dont remove the proc call */
-
 
943
		    } else {
-
 
944
		      /* something else */
-
 
945
		      exp dad = father(tc);
-
 
946
		      all_c = 0;
-
 
947
		      all_a = 0;
-
 
948
		      if (!((name(dad) == addptr_tag ||
-
 
949
			     name(dad) == subptr_tag) &&
-
 
950
			    ((!last(dad) && last(bro(dad)) &&
-
 
951
			      name(bro(bro(dad))) == ass_tag) ||
-
 
952
			     (last(dad) && name(bro(dad)) == cont_tag))) ||
-
 
953
			  (name(sh(def)) == realhd &&
-
 
954
			   name(sh(bro(dad))) != realhd) ||
-
 
955
			  (name(sh(def)) == doublehd &&
-
 
956
			   name(sh(bro(dad))) != doublehd)) {
-
 
957
			/* not an assignment to element of array */
-
 
958
			not_aliased = 0;
-
 
959
		      } else {
-
 
960
			setvis(e);
-
 
961
			uses_loc_address = 1;
846
         };
962
		      }
-
 
963
		    }
-
 
964
		  }
-
 
965
	}
-
 
966
	}
-
 
967
	tc = pt(tc);
-
 
968
      } while (tc != nilexp);
-
 
969
 
-
 
970
      if (not_aliased || iscaonly(e)) {
-
 
971
	/* set no alias flag if nothing but cont and ass */
-
 
972
	setcaonly (e);
-
 
973
      } else {
-
 
974
	/* set visible flag if there is an alias */
-
 
975
	setvis (e);
-
 
976
	uses_loc_address = 1;
847
      }
977
      }
-
 
978
 
848
      else {
979
      if (all_c) {
-
 
980
	/* if only cont operations replace by an identity declaration and
-
 
981
	 * change the uses accordingly */
-
 
982
	exp bh = hold(body);
-
 
983
	int i, j;
-
 
984
	setid(e);
-
 
985
	tc = e;
-
 
986
	do {
-
 
987
	  tc = pt(tc);
849
	if (!last (tc) && last (bro (tc)) && no(tc) == 0 &&
988
	  if (name(bro(tc)) == cont_tag) {
-
 
989
	    sh(tc) = sh(bro(tc));
850
#ifdef NEWDIAGS
990
#ifdef NEWDIAGS
851
	    !isdiaginfo(tc) &&
991
	    if (diagnose) {
-
 
992
	      dg_whole_comp(bro(tc), tc);
-
 
993
	    }
852
#endif
994
#endif
853
	    name (bro (bro (tc))) == ass_tag) {/* assignment op */
995
	    replace(bro(tc), tc, tc);
854
	  all_c = 0;		/* not all contents */
996
	  }
855
	  assd_val = bro (tc);
997
	} while (pt(tc) != nilexp);
856
 
998
 
857
	  if (name(assd_val) == val_tag) {
999
	if (no(e) < 100) {
858
	    if (no(assd_val) < 0 )
1000
	  for (i = 0; i < no(e); ++i) {
859
	      conversion = -1;
1001
	    tc = e;
860
	    if (no(assd_val) > biggest_assigned_const)
1002
	    for (j = 0; tc != nilexp && j <= i; ++j) {
-
 
1003
	      tc = pt(tc);
-
 
1004
#ifdef NEWDIAGS
861
	      biggest_assigned_const = no(assd_val);
1005
	      while (tc != nilexp && isdiaginfo(tc))
-
 
1006
		tc = pt(tc);
-
 
1007
#endif
-
 
1008
	    }
-
 
1009
	    altered(tc, son(bh));
862
	  }
1010
	  }
863
	  else
1011
	}
864
	  if (name(assd_val) == chvar_tag &&
-
 
865
		name(sh(son(assd_val))) <= uwordhd &&
-
 
-
 
1012
 
866
		is_signed(sh(son(assd_val)))) {
1013
	bro(def) = son(bh);
867
	    int sz1 = shape_size(sh(son(assd_val)));
-
 
868
	    if (conversion == 0)
1014
	bro(bro(def)) = e;
869
	      conversion = sz1;
1015
	setlast(bro(def));
870
	    else
1016
	retcell(bh);
871
	    if (conversion != sz1)
1017
	IGNORE check(e, scope);
872
	      conversion = -1;
1018
	return(1);
873
	  }
1019
      }
874
	  else
-
 
875
	    conversion = -1;
-
 
876
 
1020
 
-
 
1021
#if is80x86 || ishppa
-
 
1022
      /* look for places where we can avoid sign extending */
877
	  if (defsize != shape_size(sh(assd_val)))
1023
      if (not_aliased && name(sh(def)) == slonghd &&
-
 
1024
	  conversion == 16 && /* not 8 because of 80x86 regs */
-
 
1025
	  (biggest_assigned_const & ((conversion == 8) ? (int)0xffffff80 :
-
 
1026
				     (int)0xffff8000)) == 0 &&
-
 
1027
	  name(def) == clear_tag) {
-
 
1028
	exp temp = pt(e);
-
 
1029
	shape ish = (conversion == 8) ? scharsh : swordsh;
-
 
1030
	setse_opt(e);
-
 
1031
	while (temp != nilexp) {
-
 
1032
	  exp next = pt(temp);
-
 
1033
	  if (last(temp)) {
-
 
1034
	    if ((last(bro(temp)) || name(bro(bro(temp))) != val_tag) &&
-
 
1035
		name(bro(temp)) != hold_tag) {
-
 
1036
	      exp x = me_u3(slongsh, copy(bro(temp)), chvar_tag);
-
 
1037
	      sh(son(x)) = ish;
-
 
1038
	      replace(bro(temp), x, x);
-
 
1039
	      IGNORE check(father(x), father(x));
-
 
1040
	      kill_exp(bro(temp), bro(temp));
878
           {
1041
	    }
879
#if is80x86
1042
	  } else {
880
	    if (no(tc) == 0 && defsize <= 32) {
1043
	    if (name(bro(temp)) == val_tag) {
881
	      if (shape_size(sh(bro(tc))) == 8)
1044
	      sh(bro(temp)) = ish;
882
		setbyteuse(e);
1045
	    } else {
-
 
1046
	      bro(son(bro(temp))) = bro(bro(temp));
-
 
1047
	      bro(temp) = son(bro(temp));
-
 
1048
#if ishppa
-
 
1049
	      sh(bro(temp)) = (conversion == 8) ? ucharsh : uwordsh;
-
 
1050
#endif
883
	    }
1051
	    }
884
	    else {
-
 
885
              all_a = 0;
-
 
886
	      not_aliased = 0;
-
 
887
	    };
-
 
888
#else
-
 
889
            all_a = 0;
-
 
890
	    not_aliased = 0;
-
 
891
#endif
-
 
892
           };
-
 
893
	  if (name (assd_val) == val_tag || name (assd_val) == real_tag ||
-
 
894
	      name (assd_val) == null_tag ||
-
 
895
	      (name (assd_val) == name_tag &&
-
 
896
		isglob (son (assd_val))))
-
 
897
	    ca = 1;		/* assigning a constant */
-
 
898
	  else {
-
 
899
	    if (name (assd_val) == ident_tag &&
-
 
900
		isvar (assd_val))
-
 
901
	      vardecass = 1;
-
 
902
	  };
-
 
903
	}
-
 
904
	else
-
 
905
#ifdef NEWDIAGS
-
 
906
	if (!isdiaginfo(tc))
-
 
907
#endif
-
 
908
	{
-
 
909
	  if (isreallyass(tc)) {
-
 
910
	    all_c = 0;
-
 
911
	    all_a = 0; /* so that we dont remove the proc call */
-
 
912
	  }
1052
	  }
913
	  else {			/* something else */
-
 
914
	  exp dad = father (tc);
-
 
915
	  all_c = 0;
-
 
916
	  all_a = 0;
1053
	  temp = next;
917
	  if (!((name (dad) == addptr_tag || name (dad) == subptr_tag) &&
-
 
918
		((!last (dad) && last (bro (dad)) &&
-
 
919
		    name (bro (bro (dad))) == ass_tag) ||
-
 
920
		  (last (dad) && name (bro (dad)) == cont_tag))) ||
-
 
921
	      (name (sh (def)) == realhd &&
-
 
922
		name (sh (bro (dad))) != realhd) ||
-
 
923
	      (name (sh (def)) == doublehd &&
-
 
924
		name (sh (bro (dad))) != doublehd))
-
 
925
	    /* not an assignment to element of array */
-
 
926
	    not_aliased = 0;
-
 
927
          else
-
 
928
            {
-
 
929
              setvis (e);
-
 
930
              uses_loc_address = 1;
-
 
931
            };
-
 
932
	  };
-
 
933
	}
1054
	}
934
       };
-
 
935
      };
-
 
936
      tc = pt (tc);
-
 
937
    }
-
 
938
    while (tc != nilexp);
-
 
939
    if (not_aliased || iscaonly(e))
-
 
940
      setcaonly (e);		/* set no alias flag if nothing but cont
-
 
941
				   and ass */
-
 
942
    else
-
 
943
     {
-
 
944
      setvis (e);		/* set visible flag if there is an alias
-
 
945
				*/
-
 
946
      uses_loc_address = 1;
-
 
947
     };
-
 
948
 
-
 
949
    if (all_c) {		/* if only cont operations replace by an
-
 
950
				   identity declaration and change the
-
 
951
				   uses accordingly */
-
 
952
      exp bh = hold (body);
-
 
953
      int  i,
-
 
954
            j;
-
 
955
      setid(e);
-
 
956
      tc = e;
-
 
957
      do {
-
 
958
	tc = pt (tc);
-
 
959
        if (name(bro(tc)) == cont_tag)  {
-
 
960
	  sh (tc) = sh (bro (tc));
-
 
961
#ifdef NEWDIAGS
-
 
962
	  if (diagnose)
-
 
963
	    dg_whole_comp (bro(tc), tc);
-
 
964
#endif
-
 
965
	  replace (bro (tc), tc, tc);
1055
	replace(def, me_shint(slongsh, 0), def);
966
        };
-
 
967
      }
1056
      }
968
      while (pt (tc) != nilexp);
-
 
969
 
-
 
970
      if (no(e) < 100) {
-
 
971
        for (i = 0; i < no (e); ++i) {
-
 
972
	  tc = e;
-
 
973
	  for (j = 0; tc != nilexp && j <= i; ++j) {
-
 
974
	    tc = pt (tc);
-
 
975
#ifdef NEWDIAGS
-
 
976
	    while (tc != nilexp && isdiaginfo(tc))
-
 
977
	      tc = pt (tc);
-
 
978
#endif
1057
#endif
979
	  }
-
 
980
	  altered (tc, son (bh));
-
 
981
        };
-
 
982
      };
-
 
983
 
-
 
984
      bro (def) = son (bh);
-
 
985
      bro (bro (def)) = e;
-
 
986
      setlast (bro (def));
-
 
987
      retcell (bh);
-
 
988
      IGNORE check (e, scope);
-
 
989
      return (1);
-
 
990
    };
-
 
991
 
1058
 
992
#if is80x86 || ishppa
1059
      if (not_aliased && no(e) < 1000 &&
993
	/* look for places where we can avoid sign extending */
1060
	  (name(sh(def)) < shrealhd || name(sh(def)) > doublehd) &&
994
    if (not_aliased && name(sh(def)) == slonghd &&
1061
	  (ca || vardecass || name(def) == val_tag ||
995
	  conversion == 16 && /* not 8 because of 80x86 regs */
1062
	   name(son(e)) == real_tag || name(def) == null_tag)) {
-
 
1063
	/* propagate constant assignment forward from the place where they
-
 
1064
	   occur */
996
	  (biggest_assigned_const &
1065
	int  no_ass;
-
 
1066
	int chv;
997
	    ((conversion == 8) ? (int)0xffffff80 : (int)0xffff8000)) == 0 &&
1067
	if (name(def) == val_tag || name(son(e)) == real_tag ||
998
	name(def) == clear_tag) {
1068
	    name(def) == null_tag
999
      exp temp = pt(e);
1069
	    /*
1000
      shape ish = (conversion == 8) ? scharsh : swordsh;
-
 
1001
      setse_opt(e);
1070
	       ||
1002
      while (temp != nilexp) {
1071
	       (name(def) == name_tag &&
1003
	exp next = pt(temp);
1072
	       isglob (son(def)))
1004
	if (last(temp)) {
1073
	     */
1005
	  if ((last(bro(temp)) || name(bro(bro(temp))) != val_tag) &&
-
 
1006
		name(bro(temp)) != hold_tag) {
1074
	   ) {
1007
	    exp x = me_u3(slongsh, copy(bro(temp)), chvar_tag);
-
 
1008
	    sh(son(x)) = ish;
1075
	  do {
1009
	    replace(bro(temp), x, x);
1076
	    body = bro(def);
1010
	    IGNORE check(father(x), father(x));
1077
	    IGNORE propagate(e, e, body, 1);
1011
	    kill_exp(bro(temp), bro(temp));
1078
	  } while (change_cont(e, def, 0));
1012
	  };
-
 
1013
	}
1079
	}
1014
	else {
-
 
1015
	  if (name(bro(temp)) == val_tag)
-
 
1016
	    sh(bro(temp)) = ish;
-
 
1017
	  else {
-
 
1018
	    bro(son(bro(temp))) = bro(bro(temp));
-
 
1019
	    bro(temp) = son(bro(temp));
-
 
1020
#if ishppa
-
 
1021
	    sh(bro(temp)) = (conversion == 8) ? ucharsh : uwordsh;
-
 
1022
#endif
-
 
1023
	  };
-
 
1024
	};
-
 
1025
	temp = next;
1080
	body = bro(def);
1026
      };
-
 
1027
      replace(def, me_shint(slongsh, 0), def);
-
 
1028
    };
-
 
1029
#endif
-
 
1030
 
1081
 
1031
    if (not_aliased && no(e) < 1000 &&
-
 
1032
         (name(sh(def)) < shrealhd || name(sh(def)) > doublehd) &&
-
 
1033
         (ca || vardecass || name (def) == val_tag ||
-
 
1034
           name (son (e)) == real_tag || name (def) == null_tag)) {
-
 
1035
      /* propagate constant assignment forward from the place where they
-
 
1036
         occur */
-
 
1037
      int  no_ass;
-
 
1038
      int chv;
-
 
1039
      if (name (def) == val_tag || name (son (e)) == real_tag ||
-
 
1040
	  name (def) == null_tag
-
 
1041
/*
-
 
1042
		 ||
-
 
1043
	  (name (def) == name_tag &&
-
 
1044
	    isglob (son (def)))
-
 
1045
*/
-
 
1046
	  ) {
-
 
1047
	do {
1082
	do {
1048
	  body = bro (def);
-
 
1049
	  IGNORE propagate (e, e, body, 1);
-
 
1050
	}
-
 
1051
	while (change_cont (e, def, 0));
-
 
1052
      };
-
 
1053
      body = bro (def);
-
 
1054
 
-
 
1055
      do {
-
 
1056
	chv = 0;
1083
	  chv = 0;
1057
	no_ass = 0;
1084
	  no_ass = 0;
1058
	tc = pt (e);
1085
	  tc = pt(e);
1059
	while (!chv && tc != nilexp) {
1086
	  while (!chv && tc != nilexp) {
1060
	  if (!last (tc) &&
1087
	    if (!last(tc) &&
1061
#ifdef NEWDIAGS
1088
#ifdef NEWDIAGS
1062
	      !isdiaginfo(tc) &&
1089
		!isdiaginfo(tc) &&
1063
#endif
1090
#endif
1064
	      sh (bro (tc)) == sh (son (son (tc))) &&
1091
		sh(bro(tc)) == sh(son(son(tc))) && last(bro(tc)) &&
1065
	      last (bro (tc)) &&
-
 
1066
	      name (bro (bro (tc))) == ass_tag) {
1092
		name(bro(bro(tc))) == ass_tag) {
1067
	    exp var = bro (tc);
1093
	      exp var = bro(tc);
1068
	    exp va, df, bd;
1094
	      exp va, df, bd;
1069
	    if (eq_shape (sh (bro (tc)), sh (son (e))) &&
1095
	      if (eq_shape(sh(bro(tc)), sh(son(e))) &&
1070
		(name (bro (tc)) == val_tag ||
-
 
1071
		  name (bro (tc)) == real_tag ||
1096
		  (name(bro(tc)) == val_tag || name(bro(tc)) == real_tag ||
1072
		  name (bro (tc)) == null_tag
1097
		   name(bro(tc)) == null_tag
1073
/*
1098
		   /*
1074
		 ||
1099
		      ||
1075
		  (name (bro (tc)) == name_tag &&
1100
		      (name(bro(tc)) == name_tag &&
1076
		    isglob (son (bro (tc))))
1101
		      isglob (son(bro(tc))))
1077
*/
1102
		    */
1078
		 )) {
1103
		  )) {
1079
	      IGNORE propagate (e, e, bro (bro (tc)), 0);
1104
		IGNORE propagate(e, e, bro(bro(tc)), 0);
1080
	      chv = change_cont (e, bro (tc), 0);
1105
		chv = change_cont(e, bro(tc), 0);
1081
	      body = bro (def);
1106
		body = bro(def);
1082
	      ++no_ass;
1107
		++no_ass;
-
 
1108
	      } else {
-
 
1109
		va = son(tc);
-
 
1110
		df = son(var);
1083
 
1111
 
-
 
1112
		if (df != nilexp && (bd = bro(df)) != nilexp &&
-
 
1113
		    !isinlined(e) && !isglob(va) && isvar(va) &&
-
 
1114
		    name(bd) == seq_tag && name(bro(son(bd))) == cont_tag &&
-
 
1115
		    name(son(bro(son(bd)))) == name_tag &&
-
 
1116
		    son(son(bro(son(bd)))) == var &&
-
 
1117
		    isvar(var) && used_in(va, bd) == 0) {
-
 
1118
		  exp a = son(bro(var));
-
 
1119
		  exp prev_uses, ass, seq_hold, s;
-
 
1120
		  kill_exp(bro(son(bd)), body);
-
 
1121
		  prev_uses = pt(va);
-
 
1122
		  tc = var;
-
 
1123
		  pt(va) = pt(var);
1084
	    }
1124
		  do {
-
 
1125
		    son(pt(tc)) = va;
1085
	    else {
1126
		    ++no(va);
1086
	      va = son (tc);
1127
		    tc = pt(tc);
-
 
1128
		  } while (pt(tc) != nilexp);
1087
	      df = son (var);
1129
		  pt(tc) = prev_uses;
1088
 
1130
 
1089
	      if (df != nilexp && (bd = bro(df)) != nilexp &&
-
 
1090
		  !isinlined(e) &&
-
 
1091
		  !isglob(va) && isvar(va) &&
-
 
1092
		  name (bd) == seq_tag &&
1131
		  if (name(df) == clear_tag) {
1093
		  name (bro (son (bd))) == cont_tag &&
-
 
1094
		  name (son (bro (son (bd)))) == name_tag &&
1132
		    ass = getexp(f_top, nilexp, 0, nilexp, nilexp, 0, 0,
1095
		  son (son (bro (son (bd)))) == var &&
-
 
1096
		  isvar (var) &&
1133
				 top_tag);
1097
		  used_in (va, bd) == 0) {
-
 
1098
		exp a = son (bro (var));
1134
		  } else {
1099
		exp prev_uses, ass, seq_hold, s;
1135
		    ass = getexp(f_top, nilexp, 0, a, nilexp, 0, 0, ass_tag);
1100
		kill_exp (bro (son (bd)), body);
1136
		    bro(a) = df;
1101
		prev_uses = pt (va);
1137
		    bro(df) = ass;
1102
		tc = var;
-
 
1103
		pt (va) = pt (var);
1138
		    setlast(df);
1104
		do {
1139
		  }
1105
		  son (pt (tc)) = va;
1140
		  seq_hold = make_onearg(0, f_bottom, ass);
-
 
1141
		  s = make_twoarg(seq_tag, f_top, seq_hold, son(son(bd)));
1106
		  ++no (va);
1142
		  replace(bro(var), s, body);
1107
		  tc = pt (tc);
1143
		  chv = 1;
1108
		}
1144
		}
-
 
1145
	      }
-
 
1146
	    }
1109
		while (pt (tc) != nilexp);
1147
	    tc = pt(tc);
-
 
1148
	  }
1110
		pt (tc) = prev_uses;
1149
	} while (chv);
1111
 
1150
 
1112
		if (name (df) == clear_tag)
1151
#ifdef NEWDIAGS
1113
		  ass = getexp (f_top, nilexp, 0, nilexp, nilexp,
1152
	if (no(e) == no_ass && !isparam(e)) {
1114
		      0, 0, top_tag);
1153
	  int diagonly = 1;
1115
		else {
1154
	  tc = pt(e);
1116
		  ass = getexp (f_top, nilexp, 0, a, nilexp,
1155
	  while (tc != nilexp) {
-
 
1156
	    if (!isdiaginfo(tc)) {
1117
		      0, 0, ass_tag);
1157
	      if (diagnose) {
-
 
1158
		dg_rem_ass(bro(bro(tc)));
1118
		  bro (a) = df;
1159
	      }
-
 
1160
	      replace(bro(bro(tc)), bro(tc), bro(def));
1119
		  bro (df) = ass;
1161
	      diagonly = 0;
-
 
1162
	    }
1120
		  setlast (df);
1163
	    tc = pt(tc);
1121
		};
1164
	  }
1122
		seq_hold = make_onearg (0, f_bottom, ass);
-
 
1123
		s = make_twoarg (seq_tag, f_top, seq_hold,
1165
	  if (!diagonly) {
1124
                                  son (son (bd)));
-
 
1125
		replace (bro (var), s, body);
1166
	    repbyseq(e);
1126
		chv = 1;
1167
	  }
-
 
1168
	}
-
 
1169
#else
-
 
1170
	if (no(e) == no_ass && pt(e) != nilexp && !isparam(e)) {
1127
	      };
1171
	  tc = pt(e);
-
 
1172
	  while (replace(bro(bro(tc)), bro(tc), bro(def)), pt(tc) != nilexp) {
1128
	    };
1173
	    tc = pt(tc);
1129
	  };
1174
	  }
1130
	  tc = pt (tc);
1175
	  repbyseq(e);
1131
	};
1176
	}
-
 
1177
#endif
-
 
1178
	return(1);
1132
      } while (chv) ;
1179
      }
1133
 
1180
 
-
 
1181
      if (!isparam(e) && name(def) == clear_tag && name(body) == seq_tag &&
1134
#ifdef NEWDIAGS
1182
	  name(son(son(body))) == ass_tag &&
1135
      if (no (e) == no_ass && !isparam(e)) {
1183
	  name(son(son(son(body)))) == name_tag &&
1136
	int diagonly = 1;
1184
	  son(son(son(son(body)))) == e &&
-
 
1185
	  eq_shape(sh(def), sh(bro(son(son(son(body))))))) {
-
 
1186
	/* definition is clear and first assignment is to this variable */
-
 
1187
	exp val = bro(son(son(son(body))));/* assigned value */
1137
	tc = pt (e);
1188
	if (!used_in(e, val)) {
-
 
1189
	  son(e) = val;		/* put it in as initialisation */
1138
	while (tc != nilexp) {
1190
	  clearlast(val);
1139
	  if (!isdiaginfo(tc)) {
1191
	  bro(val) = body;
1140
	    if (diagnose)
1192
	  /* kill the use of var */
-
 
1193
	  kill_exp(son(son(son(body))), son(son(son(body))));
1141
	      dg_rem_ass (bro(bro(tc)));
1194
	  /* replace assignment by void */
1142
	    replace (bro (bro (tc)), bro (tc), bro(def));
1195
	  replace(son(son(body)), getexp(f_top, nilexp, 0, nilexp, nilexp, 0,
-
 
1196
					 0, top_tag), body);
1143
	    diagonly = 0;
1197
	  return(1);
1144
	  }
1198
	}
1145
	  tc = pt (tc);
1199
      }
1146
	};
1200
 
1147
	if (!diagonly)
1201
#ifdef NEWDIAGS
1148
	  repbyseq (e);
1202
      if (all_a && !isparam(e) && !diag_visible) {
1149
      };
-
 
1150
#else
1203
#else
1151
      if (no (e) == no_ass && pt (e) != nilexp && !isparam(e)) {
1204
      if (all_a && !isparam(e) && !diagnose) {
1152
	tc = pt (e);
-
 
1153
	while (replace (bro (bro (tc)), bro (tc), bro(def)),
-
 
1154
	    pt (tc) != nilexp)
-
 
1155
	  tc = pt (tc);
-
 
1156
	repbyseq (e);
-
 
1157
      };
-
 
1158
#endif
1205
#endif
-
 
1206
	/* if only assignments replace them by evaluating the value assigned
-
 
1207
	 * and discarding it. replace the declaration by a sequence of
1159
      return (1);
1208
	 * definition and body */
1160
    };
1209
	tc = pt(e);
1161
 
1210
 
1162
    if (!isparam(e) && name (def) == clear_tag &&
-
 
1163
        name (body) == seq_tag &&
1211
	while (1) {
1164
	name (son (son (body))) == ass_tag &&
1212
	  if (!last(tc) && name(bro(bro(tc))) == ass_tag) {
1165
	name (son (son (son (body)))) == name_tag &&
-
 
1166
	son (son (son (son (body)))) == e &&
1213
#ifdef NEWDIAGS
1167
	eq_shape (sh (def), sh (bro (son (son (son (body))))))) {
-
 
1168
      /* definition is clear and first assignment is to this variable */
-
 
1169
      exp val = bro (son (son (son (body))));/* assigned value */
-
 
1170
      if (!used_in(e, val)) {
1214
	    if (diagnose) {
1171
        son (e) = val;		/* put it in as initialisation */
-
 
1172
        clearlast (val);
1215
	      dg_rem_ass(bro(bro(tc)));
1173
        bro (val) = body;
1216
	    }
1174
        /* kill the use of var */
1217
#endif
1175
        kill_exp (son (son (son (body))), son (son (son (body))));
1218
	    replace(bro(bro(tc)), bro(tc), body);
-
 
1219
	  }
1176
        replace (son (son (body)),
1220
	  tc = pt(tc);
1177
	    getexp (f_top, nilexp, 0, nilexp, nilexp, 0, 0, top_tag),
-
 
1178
	    body);		/* replace assignment by void */
1221
	  if (tc == nilexp) {
1179
        return (1);
1222
	    break;
1180
      };
1223
	  }
1181
    };
1224
	}
1182
 
1225
 
1183
#ifdef NEWDIAGS
-
 
1184
    if (all_a && !isparam(e) && !diag_visible) {
-
 
1185
#else
-
 
1186
    if (all_a && !isparam(e) && !diagnose) {
-
 
1187
#endif
-
 
1188
				/* if only assignments replace them by
-
 
1189
				   evaluating the value assigned and
-
 
1190
				   discarding it. replace the declaration
-
 
1191
				   by a sequence of definition and body */
-
 
1192
      tc = pt (e);
1226
	repbyseq(e);
1193
 
-
 
1194
      while (1)
-
 
1195
       {
-
 
1196
         if (!last(tc) && name(bro(bro(tc))) == ass_tag) {
-
 
1197
#ifdef NEWDIAGS
-
 
1198
	   if (diagnose)
-
 
1199
	     dg_rem_ass (bro(bro(tc)));
-
 
1200
#endif
1227
	return(1);
1201
           replace (bro (bro (tc)), bro (tc), body);
-
 
1202
	 }
-
 
1203
         tc = pt(tc);
-
 
1204
         if (tc == nilexp)
-
 
1205
           break;
-
 
1206
       };
1228
      }
1207
 
1229
 
1208
      repbyseq (e);
-
 
1209
      return (1);
-
 
1210
    };
1230
      }
1211
 
1231
 
1212
 
-
 
1213
  };
-
 
1214
 
-
 
1215
  if (!is_var && !is_vis && no(e) == 1 && !isparam(e) &&
1232
      if (!is_var && !is_vis && no(e) == 1 && !isparam(e) &&
1216
	name(body) == ident_tag && name(son(body)) == name_tag &&
1233
	  name(body) == ident_tag && name(son(body)) == name_tag &&
1217
	son(son(body)) == e &&
-
 
1218
	shape_size(def) == shape_size(son(body))) {
1234
	  son(son(body)) == e && shape_size(def) == shape_size(son(body))) {
1219
#ifdef NEWDIAGS
1235
#ifdef NEWDIAGS
1220
    if (diagnose) {
1236
	if (diagnose) {
1221
      exp t = pt(e);
1237
	  exp t = pt(e);
1222
      while (t) {
1238
	  while (t) {
1223
	if (isdiaginfo(t))
1239
	    if (isdiaginfo(t)) {
1224
	  setdiscarded(t);
1240
	      setdiscarded(t);
-
 
1241
	    }
1225
	t = pt(t);
1242
	    t = pt(t);
1226
      }
1243
	  }
-
 
1244
	}
-
 
1245
#endif
-
 
1246
	replace(son(body), def, def);
-
 
1247
#ifdef NEWDIAGS
-
 
1248
	if (diagnose) {
-
 
1249
	  dg_whole_comp(e, body);
1227
    }
1250
	}
1228
#endif
1251
#endif
1229
    replace(son(body), def, def);
-
 
1230
#ifdef NEWDIAGS
-
 
1231
    if (diagnose)
-
 
1232
      dg_whole_comp (e, body);
-
 
1233
#endif
-
 
1234
    replace(e, body, scope);
1252
	replace(e, body, scope);
1235
    return 1;
1253
	return 1;
1236
  };
1254
      }
1237
 
1255
 
1238
  if (!is_var && !is_vis && name(def) == compound_tag) {
1256
      if (!is_var && !is_vis && name(def) == compound_tag) {
1239
	exp c = son(def);
1257
	exp c = son(def);
1240
	int nuses = no(e);
1258
	int nuses = no(e);
1241
	int changed = 0;
1259
	int changed = 0;
1242
	for(; ; ) {
1260
	for (;;) {
1243
	   int n = name(bro(c));
1261
	  int n = name(bro(c));
1244
	   if (n == val_tag || n == real_tag || n == name_tag ||
1262
	  if (n == val_tag || n == real_tag || n == name_tag || n == null_tag) {
1245
			 n == null_tag){
-
 
1246
	   	exp u = pt(e);
1263
	    exp u = pt(e);
1247
		for(; nuses !=0 && u!=nilexp; ) {
1264
	    for (; nuses !=0 && u !=nilexp;) {
1248
		    exp nextu = pt(u);
1265
	      exp nextu = pt(u);
1249
#ifdef NEWDIAGS
1266
#ifdef NEWDIAGS
1250
		    if (!isdiaginfo(u) && no(u)==no(c) && eq_shape(sh(u), sh(bro(c))) ) {
1267
	      if (!isdiaginfo(u) && no(u) ==no(c) &&
-
 
1268
		  eq_shape(sh(u), sh(bro(c)))) {
1251
#else
1269
#else
1252
		    if (no(u)==no(c) && eq_shape(sh(u), sh(bro(c))) ) {
1270
	      if (no(u) ==no(c) && eq_shape(sh(u), sh(bro(c)))) {
1253
#endif
1271
#endif
1254
			replace(u, copy(bro(c)), bro(def));
1272
		replace(u, copy(bro(c)), bro(def));
1255
			nextu = pt(u); /* it could have changed */
1273
		nextu = pt(u); /* it could have changed */
1256
			kill_exp(u, bro(def));
1274
		kill_exp(u, bro(def));
1257
			nuses--;
1275
		nuses--;
1258
			changed = 1;
1276
		changed = 1;
1259
		    }
1277
	      }
1260
		    u = nextu;
1278
	      u = nextu;
1261
		}
-
 
1262
	    }
1279
	    }
-
 
1280
	  }
1263
	    if (nuses ==0 || last(bro(c))) break;
1281
	  if (nuses ==0 || last(bro(c))) {
-
 
1282
	    break;
-
 
1283
	  }
1264
	    c = bro(bro(c));
1284
	  c = bro(bro(c));
1265
	}
1285
	}
1266
	if ((no(e)==0 || pt(e) == nilexp) && !isenvoff(e) ) {
1286
	if ((no(e) ==0 || pt(e) == nilexp) && !isenvoff(e)) {
1267
		repbyseq(e);
1287
	  repbyseq(e);
1268
		return 1;
1288
	  return 1;
1269
	}
1289
	}
1270
	return changed;
1290
	return changed;
1271
  }
1291
      }
1272
  if (!is_var && !is_vis && name(def) == nof_tag) {
1292
      if (!is_var && !is_vis && name(def) == nof_tag) {
1273
	exp c = son(def);
1293
	exp c = son(def);
1274
	int changed = 0;
1294
	int changed = 0;
1275
	int nuses = no(e);
1295
	int nuses = no(e);
1276
	int sz = rounder(shape_size(sh(c)), shape_align(sh(c)));
1296
	int sz = rounder(shape_size(sh(c)), shape_align(sh(c)));
1277
	int nd = 0;
1297
	int nd = 0;
1278
	for(;; ) {
1298
	for (;;) {
1279
	   int n = name(c);
1299
	  int n = name(c);
1280
	   if (n == val_tag || n == real_tag || n == name_tag || n == null_tag){
1300
	  if (n == val_tag || n == real_tag || n == name_tag || n == null_tag) {
1281
	   	exp u = pt(e);
1301
	    exp u = pt(e);
1282
		for(; nuses!=0 && u!=nilexp; ) {
1302
	    for (; nuses !=0 && u !=nilexp;) {
1283
		    exp nextu = pt(u);
1303
	      exp nextu = pt(u);
1284
#ifdef NEWDIAGS
1304
#ifdef NEWDIAGS
1285
		    if (!isdiaginfo(u) && no(u)==nd && eq_shape(sh(u), sh(c))) {
1305
	      if (!isdiaginfo(u) && no(u) ==nd && eq_shape(sh(u), sh(c))) {
1286
#else
1306
#else
1287
		    if (no(u)==nd && eq_shape(sh(u), sh(c))) {
1307
	      if (no(u) ==nd && eq_shape(sh(u), sh(c))) {
1288
#endif
1308
#endif
1289
			replace(u, copy(c), bro(def));
1309
		replace(u, copy(c), bro(def));
1290
			nextu = pt(u); /* it could have changed */
1310
		nextu = pt(u); /* it could have changed */
1291
			kill_exp(u, bro(def));
1311
		kill_exp(u, bro(def));
1292
			nuses--;
1312
		nuses--;
1293
			changed = 1;
1313
		changed = 1;
1294
		    }
1314
	      }
1295
		    u = nextu;
1315
	      u = nextu;
1296
		}
-
 
1297
	    }
1316
	    }
-
 
1317
	  }
1298
    	    if (nuses==0 || last(c)) break;
1318
	  if (nuses==0 || last(c)) {
-
 
1319
	    break;
-
 
1320
	  }
1299
	    c = bro(c);
1321
	  c = bro(c);
1300
	    nd+=sz;
1322
	  nd+=sz;
-
 
1323
	}
-
 
1324
	if ((no(e) ==0 || pt(e) == nilexp) && !isenvoff(e)) {
-
 
1325
	  repbyseq(e);
-
 
1326
	  return 1;
1301
	}
1327
	}
1302
	if ((no(e)==0 || pt(e) == nilexp) && !isenvoff(e) ) {
-
 
1303
		repbyseq(e);
-
 
1304
		return 1;
-
 
1305
	}
-
 
1306
	return changed;
1328
      return changed;
1307
  }
1329
      }
1308
 
1330
 
1309
  return (0);
1331
  return(0);
1310
}
1332
}