]> andersk Git - splint.git/blame - src/uentry.c
Fixed problem with russian characters.
[splint.git] / src / uentry.c
CommitLineData
616915dd 1/*
11db3170 2** Splint - annotation-assisted static program checker
c59f5181 3** Copyright (C) 1994-2003 University of Virginia,
616915dd 4** Massachusetts Institute of Technology
5**
6** This program is free software; you can redistribute it and/or modify it
7** under the terms of the GNU General Public License as published by the
8** Free Software Foundation; either version 2 of the License, or (at your
9** option) any later version.
10**
11** This program is distributed in the hope that it will be useful, but
12** WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14** General Public License for more details.
15**
16** The GNU General Public License is available from http://www.gnu.org/ or
17** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18** MA 02111-1307, USA.
19**
155af98d 20** For information on splint: info@splint.org
21** To report a bug: splint-bug@splint.org
11db3170 22** For more information: http://www.splint.org
616915dd 23*/
24/*
25** uentry.c
26*/
27
1b8ae690 28# include "splintMacros.nf"
616915dd 29# include "basic.h"
30# include "structNames.h"
31# include "nameChecks.h"
32
616915dd 33static /*@dependent@*/ uentry posRedeclared = uentry_undefined;
34static /*@only@*/ fileloc posLoc = fileloc_undefined;
35static int nuentries = 0;
36static int totuentries = 0;
37
38static void checkGlobalsModifies (/*@notnull@*/ uentry p_ue, sRefSet p_sr) ;
39static void uentry_setDeclDef (uentry p_e, fileloc p_f) /*@modifies p_e@*/ ;
40static bool uentry_isRefCounted (uentry p_ue) /*@*/ ;
41static bool uentry_isRefsField (uentry p_ue) /*@*/ ;
42static bool uentry_isReallySpecified (uentry p_e) /*@*/ ;
43static void uentry_checkIterArgs (uentry p_ue);
44static cstring uentry_dumpAux (uentry p_v, bool p_isParam);
45
80489f0a 46static void uentry_showWhereLastKind (uentry p_spec) /*@modifies g_warningstream@*/ ;
f2b6724f 47
28bf4b0b 48static void uentry_combineModifies (uentry p_ue, /*@owned@*/ sRefSet p_sr)
49 /*@modifies p_ue@*/ ;
50
51static void uentry_addStateClause (uentry p_ue, /*@only@*/ stateClause p_sc)
52 /*@modifies p_ue@*/ ;
53
616915dd 54/*@access ekind@*/
55static void checkAliasState (/*@notnull@*/ uentry p_old,
56 /*@notnull@*/ uentry p_unew,
57 bool p_mustConform, bool p_completeConform)
58 /*@modifies p_old, p_unew@*/ ;
59static void checkNullState (/*@notnull@*/ uentry p_old,
60 /*@notnull@*/ uentry p_unew,
61 bool p_mustConform, bool p_completeConform)
62 /*@modifies p_old, p_unew@*/ ;
63
64static void checkVarConformance (/*@notnull@*/ uentry p_old,
65 /*@notnull@*/ uentry p_unew,
66 bool p_mustConform, bool p_completeConform)
67 /*@modifies p_old, p_unew@*/;
68
616915dd 69static void uentry_setHasMods (uentry p_ue) /*@modifies p_ue@*/;
70static void uentry_setHasGlobs (uentry p_ue) /*@modifies p_ue@*/;
616915dd 71
72static void uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry p_e);
73
74static void uentry_setSpecDef (/*@special@*/ uentry p_e, /*@keep@*/ fileloc p_f)
75 /*@defines p_e->whereSpecified, p_e->whereDeclared, p_e->whereDefined@*/
76 /*@modifies p_e@*/;
77
78static void returnValueError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_unew);
79static void nargsError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_unew);
80static /*@observer@*/ cstring paramStorageName (uentry p_ue) /*@*/ ;
81static /*@observer@*/ cstring fcnErrName (uentry p_ue) /*@*/ ;
82static /*@observer@*/ cstring checkedName (chkind p_checked) /*@*/ ;
83static void
84 paramTypeError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_oldCurrent,
85 ctype p_oldType, /*@notnull@*/ uentry p_unew,
86 /*@notnull@*/ uentry p_newCurrent,
80489f0a 87 ctype p_newType, int p_paramno) /*@modifies g_warningstream@*/ ;
616915dd 88
89static /*@only@*/ /*@notnull@*/ uentry
90 uentry_makeVariableAux (cstring p_n, ctype p_t, /*@keep@*/ fileloc p_f,
91 /*@exposed@*/ sRef p_s, bool p_priv, vkind p_kind);
92
3e3ec469 93static /*@only@*/ /*@notnull@*/ uentry
94 uentry_makeConstantAux (cstring p_n, ctype p_t,
95 /*@keep@*/ fileloc p_f, bool p_priv, bool p_macro,
96 /*@only@*/ multiVal p_m) /*@*/ ;
5e211f69 97
efd360a3 98static void uentry_convertVarFunction (uentry ue) /*@modifies ue@*/
99{
100 if (uentry_isVariable (ue)
101 && (ctype_isFunction (ctype_realType (uentry_getType (ue)))
102 || ctype_isUnknown (uentry_getType (ue))))
103 {
104 uentry_makeVarFunction (ue);
105 }
106}
107
616915dd 108static /*@out@*/ /*@notnull@*/ uentry uentry_alloc (void) /*@*/
109{
110 uentry ue = (uentry) dmalloc (sizeof (*ue));
b73d1009 111 ue->warn = warnClause_undefined;
616915dd 112 nuentries++;
113 totuentries++;
114
115 return ue;
116}
117
118static cstring uentry_getOptName (uentry p_e) /*@*/ ;
efd360a3 119static void uentry_updateInto (/*@unique@*/ uentry p_unew, uentry p_old) /*@modifies p_unew, p_old@*/ ;
120
616915dd 121static void uentry_setNullState (/*@notnull@*/ uentry p_ue, nstate p_ns);
122static void uentry_setAliasKind (/*@notnull@*/ uentry p_ue, alkind p_ak);
123static /*@only@*/ /*@null@*/ uinfo uinfo_copy (uinfo p_u, ekind p_kind);
124static void uinfo_free (/*@only@*/ uinfo p_u, ekind p_kind);
b072092f 125static void ucinfo_free (/*@only@*/ ucinfo p_u);
616915dd 126static void uvinfo_free (/*@only@*/ uvinfo p_u);
127
128# ifdef DOANNOTS
129
130static /*@only@*/ cstring ancontext_unparse (ancontext an)
131{
132 switch (an)
133 {
134 case AN_UNKNOWN: return cstring_makeLiteral ("unknown");
135 case AN_FCNRETURN: return cstring_makeLiteral ("return value");
136 case AN_FCNPARAM: return cstring_makeLiteral ("function param");
137 case AN_SUFIELD: return cstring_makeLiteral ("su field");
138 case AN_TDEFN: return cstring_makeLiteral ("type definition");
139 case AN_GSVAR: return cstring_makeLiteral ("global/static var");
140 case AN_CONST: return cstring_makeLiteral ("constant");
141 BADDEFAULT;
142 }
143 BADEXIT;
144}
145
146static int annots[AN_LAST][QU_LAST];
147static int decls[AN_LAST];
148static int shdecls[AN_LAST];
149static int idecls[AN_LAST];
150
151void initAnnots ()
152{
153 int i, j;
154
155 for (i = AN_UNKNOWN; i < AN_LAST; i++)
156 {
157 decls[i] = 0;
158 shdecls[i] = 0;
159 idecls[i] = 0;
160
161 for (j = QU_UNKNOWN; j < QU_LAST; j++)
162 {
163 annots[i][j] = 0;
164 }
165 }
166}
167
168static void tallyAnnot (ancontext ac, qual q)
169{
170 (annots[ac][q])++;
171}
172
173void printAnnots ()
174{
175 int total[QU_LAST];
176 int alltotals = 0;
177 int totdecls = 0;
178 int totshdecls = 0;
179 int totidecls = 0;
180 int i, j;
181
182 for (j = QU_UNKNOWN; j < QU_LAST; j++)
183 {
184 total[j] = 0;
185 }
186
187 for (i = AN_UNKNOWN; i < AN_LAST; i++)
188 {
189 int tmptot;
190
191 if (decls[i] > 0)
192 {
193 printf ("Context: %s (%d declarations, %d sharable, %d indirect)\n",
194 ancontext_unparse (i),
195 decls[i], shdecls[i], idecls[i]);
196
197 totdecls += decls[i];
198 totshdecls += shdecls[i];
199 totidecls += idecls[i];
200
201 for (j = QU_UNKNOWN; j < QU_LAST; j++)
202 {
203 total[j] += annots[i][j];
204 alltotals += annots[i][j];
205 }
206
207 printf (" Allocation:\n");
208
209 tmptot = 0;
210
211 for (j = QU_UNKNOWN; j < QU_LAST; j++)
212 {
213 if (qual_isAliasQual (j) && !qual_isUnique (j))
214 {
215 if (annots[i][j] > 0)
216 {
217 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
218 100.0 * (double)annots[i][j] / (double)decls[i]);
219 tmptot += annots[i][j];
220 }
221 }
222 }
223
224 printf (" Exposure:\n");
225
226 tmptot = 0;
227
228 for (j = QU_UNKNOWN; j < QU_LAST; j++)
229 {
230 if (qual_isExQual (j))
231 {
232 if (annots[i][j] > 0)
233 {
234 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
235 100.0 * (double)annots[i][j] / (double)decls[i]);
236 tmptot += annots[i][j];
237 }
238 }
239 }
240
241 printf (" Definition:\n");
242
243 for (j = QU_UNKNOWN; j < QU_LAST; j++)
244 {
245 if (qual_isAllocQual (j))
246 {
247 if (annots[i][j] > 0)
248 {
249 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
250 100.0 * (double)annots[i][j] / (double)decls[i]);
251 }
252 }
253 }
254
255 printf (" Null:\n");
256
257 for (j = QU_UNKNOWN; j < QU_LAST; j++)
258 {
259 if (qual_isNull (j) || qual_isNotNull (j) || qual_isRelNull (j))
260 {
261 if (annots[i][j] > 0)
262 {
263 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
264 100.0 * (double)annots[i][j] / (double)decls[i]);
265 }
266 }
267 }
268
269 printf ("\n");
270 }
271 }
272
273 for (j = QU_UNKNOWN; j < QU_LAST; j++)
274 {
275 bool hasone = FALSE;
276
277 for (i = AN_UNKNOWN; i < AN_LAST; i++)
278 {
279 if (annots[i][j] > 0)
280 {
281 hasone = TRUE;
282 break;
283 }
284 }
285
286 if (hasone)
287 {
288 printf ("Annotation: %s\n", qual_unparse (j));
289
290 for (i = AN_UNKNOWN; i < AN_LAST; i++)
291 {
292 if (annots[i][j] > 0)
293 {
294 printf ("%25s: %5d\n", ancontext_unparse (i), annots[i][j]);
295 }
296 }
297 printf ("\n");
298 }
299 }
300
301 printf ("All Contexts\n");
302
303 for (j = QU_UNKNOWN; j < QU_LAST; j++)
304 {
305 if (total[j] > 0)
306 {
307 printf ("%10s: %5d (%3.2f%%)\n", qual_unparse (j), total[j],
308 100.0 * (double)total[j] / (double)(totdecls));
309 }
310 }
311 printf ("\n");
312
4ab867d6 313 printf ("Total Annotations: %d (%d decls, %d sharable, %d indirect)\n", alltotals, totdecls, totshdecls, totidecls); }
616915dd 314
315extern void uentry_tallyAnnots (uentry u, ancontext kind)
316{
317 alkind ak = sRef_getAliasKind (u->sref);
318 exkind ek = sRef_getExKind (u->sref);
319 nstate ns = sRef_getNullState (u->sref);
320 sstate ss = sRef_getDefState (u->sref);
321 bool recordUnknown = FALSE;
616915dd 322
323 if (kind == AN_UNKNOWN)
324 {
325 ekind e = u->ukind;
326
327 if (e == KENDITER)
328 {
329 return;
330 }
331 else if (e == KCONST || e == KENUMCONST)
332 {
333 kind = AN_CONST;
334 }
335 else if (e == KFCN || e == KITER)
336 {
337 uentryList params = uentry_getParams (u);
338 bool hasRet = FALSE;
339
340 uentryList_elements (params, current)
341 {
342 if (uentry_isReturned (current))
343 {
344 hasRet = TRUE;
345 }
346 if (!uentry_isElipsisMarker (current))
347 {
348 uentry_tallyAnnots (current, AN_FCNPARAM);
349 }
350 } end_uentryList_elements;
351
352 kind = AN_FCNRETURN;
353
354 if (ctype_isFunction (u->utype)
355 && !hasRet
28bf4b0b 356 && ctype_isVisiblySharable (ctype_realType (ctype_getReturnType (u->utype))))
616915dd 357 {
358 recordUnknown = TRUE;
359 }
360 }
361 else if (e == KDATATYPE || e == KSTRUCTTAG || e == KUNIONTAG || e == KENUMTAG)
362 {
363 ctype t = ctype_realType (u->utype);
364
365 if (ctype_isSU (t))
366 {
367 uentryList fields = ctype_getFields (t);
368
369 uentryList_elements (fields, current)
370 {
371 uentry_tallyAnnots (current, AN_SUFIELD);
372 }
373 } end_uentryList_elements;
374
375 kind = AN_TDEFN;
376
377 if (ctype_isVisiblySharable (u->utype))
378 {
379 recordUnknown = TRUE;
380 }
381 }
382 else
383 {
384 kind = AN_GSVAR;
385
386
387 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
388 {
389 recordUnknown = TRUE;
390 }
391 }
392 }
393
394 decls[kind]++;
395
396 if (kind == AN_FCNRETURN)
397 {
398 if (recordUnknown)
399 {
400 shdecls[kind]++;
401 idecls[kind]++;
402 }
403 else
404 {
405 ;
406 }
407 }
408 else
409 {
410 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
411 {
412 shdecls[kind]++;
413 }
414
415 if (ctype_isRealPointer (ctype_realType (u->utype)))
416 {
417 idecls[kind]++;
418 }
419 }
420
616915dd 421 switch (ss)
422 {
423 case SS_ALLOCATED: tallyAnnot (kind, QU_OUT); break;
424 case SS_PARTIAL: tallyAnnot (kind, QU_PARTIAL); break;
425 case SS_RELDEF: tallyAnnot (kind, QU_RELDEF); break;
426 case SS_SPECIAL: tallyAnnot (kind, QU_SPECIAL); break;
427 default: break;
428 }
429
430 if (uentry_isReturned (u))
431 {
432 tallyAnnot (kind, QU_RETURNED);
433 }
434
435 switch (ak)
436 {
437 case AK_UNKNOWN:
438 if (ctype_isRefCounted (ctype_realType (u->utype))
439 || (ctype_isFunction (u->utype) &&
28bf4b0b 440 ctype_isRefCounted (ctype_realType (ctype_getReturnType (u->utype)))))
616915dd 441 {
442 ;
443 }
444 else
445 {
446 if (kind == AN_FCNPARAM)
447 {
448 tallyAnnot (kind, QU_TEMP);
449 }
450 else if (recordUnknown)
451 {
452 if (kind == AN_FCNRETURN)
453 {
454 }
455 tallyAnnot (kind, QU_UNKNOWN);
456 }
457 }
458 break;
459 case AK_ONLY: tallyAnnot (kind, QU_ONLY); break;
460 case AK_IMPONLY: tallyAnnot (kind, QU_ONLY); break;
461 case AK_KEEP: tallyAnnot (kind, QU_KEEP); break;
462 case AK_KEPT: tallyAnnot (kind, QU_KEPT); break;
463 case AK_IMPTEMP:
464 case AK_TEMP: tallyAnnot (kind, QU_TEMP); break;
465 case AK_SHARED: tallyAnnot (kind, QU_SHARED); break;
466 case AK_UNIQUE: tallyAnnot (kind, QU_UNIQUE); break;
467 case AK_RETURNED: tallyAnnot (kind, QU_RETURNED); break;
468 case AK_REFCOUNTED: tallyAnnot (kind, QU_UNKNOWN); break;
469 case AK_REFS: tallyAnnot (kind, QU_REFS); break;
470 case AK_KILLREF: tallyAnnot (kind, QU_KILLREF); break;
471 case AK_NEWREF: tallyAnnot (kind, QU_NEWREF); break;
472 case AK_OWNED: tallyAnnot (kind, QU_OWNED); break;
473 case AK_IMPDEPENDENT:
474 case AK_DEPENDENT: tallyAnnot (kind, QU_DEPENDENT); break;
475 case AK_ERROR:
476 case AK_FRESH:
477 case AK_STACK:
478 case AK_LOCAL:
479 break;
480 }
481
482 switch (ek)
483 {
484 case XO_EXPOSED: tallyAnnot (kind, QU_EXPOSED); break;
485 case XO_OBSERVER: tallyAnnot (kind, QU_OBSERVER); break;
486 default: break;
487 }
488
489 switch (ns)
490 {
491 case NS_ERROR: break;
492 case NS_UNKNOWN: break;
493 case NS_NOTNULL: break;
494 case NS_MNOTNULL: tallyAnnot (kind, QU_NOTNULL); break;
495 case NS_RELNULL: tallyAnnot (kind, QU_RELNULL); break;
496 case NS_CONSTNULL: tallyAnnot (kind, QU_NULL); break;
497 case NS_POSNULL: tallyAnnot (kind, QU_NULL); break;
498 case NS_DEFNULL:
499 case NS_ABSNULL: break;
500 }
501}
502
503# endif
504
505static /*@observer@*/ cstring specCode_unparse (specCode s) /*@*/
506{
507 switch (s)
508 {
509 case SPC_NONE: return cstring_makeLiteralTemp ("normal");
510 case SPC_PRINTFLIKE: return cstring_makeLiteralTemp ("printflike");
511 case SPC_SCANFLIKE: return cstring_makeLiteralTemp ("scanflike");
512 case SPC_MESSAGELIKE: return cstring_makeLiteralTemp ("messagelike");
513 case SPC_LAST: return cstring_makeLiteralTemp ("<error>");
514 }
515
516 BADEXIT;
517}
518
519static specCode specCode_fromInt (int i)
520{
521 /*@+enumint@*/
522 llassert (i >= SPC_NONE && i < SPC_LAST);
523
524 return ((specCode) i);
525 /*@=enumint@*/
526}
527
528/*@observer@*/ cstring uentry_specOrDefName (uentry u)
529{
530 if (uentry_isDeclared (u))
531 {
532 return cstring_makeLiteralTemp ("previously declared");
533 }
534 else
535 {
536 return cstring_makeLiteralTemp ("specified");
537 }
538}
539
540/*@observer@*/ cstring uentry_specDeclName (uentry u)
541{
542 if (uentry_isDeclared (u))
543 {
544 return cstring_makeLiteralTemp ("previous declaration");
545 }
546 else
547 {
548 return cstring_makeLiteralTemp ("specification");
549 }
550}
551
552static /*@observer@*/ cstring uentry_reDefDecl (uentry old, uentry unew) /*@*/
553{
554 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
555 {
556 return cstring_makeLiteralTemp ("redefined");
557 }
558 else if (uentry_isCodeDefined (unew))
559 {
560 return cstring_makeLiteralTemp ("defined");
561 }
562 else if (uentry_isDeclared (old) && uentry_isDeclared (unew))
563 {
564 return cstring_makeLiteralTemp ("redeclared");
565 }
566 else
567 {
568 return cstring_makeLiteralTemp ("declared");
569 }
570}
571
ccf0a4a8 572static constraintList uentry_getFunctionConditions (uentry ue, bool isPost)
616915dd 573{
574 if (uentry_isValid (ue))
575 {
ccf0a4a8 576 functionConstraint constraint;
616915dd 577
bb7c2085 578 DPRINTF((message ("called uentry_getFcnPostconditions on %s",
ccf0a4a8 579 uentry_unparse (ue) ) ) );
580
581 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
616915dd 582 {
bb7c2085 583 DPRINTF((message ("called uentry_getFunctionConditions on nonfunction %s",
ccf0a4a8 584 uentry_unparse (ue) ) ) );
585 if (!uentry_isFunction (ue) )
616915dd 586 {
ccf0a4a8 587 DPRINTF((message ("called uentry_getFunctionConditions on nonfunction %s",
588 uentry_unparse (ue) ) ));
589 return constraintList_undefined;
28bf4b0b 590 }
ccf0a4a8 591
592
593 return constraintList_undefined;
594 }
595
596 if (!uentry_isFunction(ue))
597 {
598
bb7c2085 599 DPRINTF((message ("called uentry_getFunctionConditions on non function %s",
ccf0a4a8 600 uentry_unparse (ue) ) ) );
601 return constraintList_undefined;
602
603 }
3814599d 604
ccf0a4a8 605 llassert (uentry_isFunction (ue));
3814599d 606
ccf0a4a8 607 if (isPost)
608 {
609 constraint = ue->info->fcn->postconditions;
616915dd 610 }
ccf0a4a8 611 else
612 {
613 constraint = ue->info->fcn->preconditions;
614 }
615
616 return functionConstraint_getBufferConstraints (constraint);
616915dd 617 }
618
619 return constraintList_undefined;
620
621}
622
ccf0a4a8 623/*drl7x*/
624/*@only@*/ constraintList uentry_getFcnPreconditions (uentry ue)
625{
626 return uentry_getFunctionConditions (ue, FALSE);
627}
628
629/*drl
630 12/28/2000
631*/
632
633constraintList uentry_getFcnPostconditions (uentry ue)
634{
635 return uentry_getFunctionConditions (ue, TRUE);
636}
616915dd 637
638static /*@only@*/ fileloc setLocation (void)
639{
640 fileloc fl = context_getSaveLocation ();
641
642 if (fileloc_isDefined (fl))
643 {
644 return fl;
645 }
646 else
647 {
648 return fileloc_copy (g_currentloc);
649 }
650}
651
b9904f57 652static void uentry_setConstantValue (uentry ue, /*@only@*/ multiVal val)
653{
654 llassert (uentry_isEitherConstant (ue));
655 sRef_setValue (ue->sref, val);
656}
657
616915dd 658/*@notnull@*/ uentry uentry_makeEnumConstant (cstring n, ctype t)
659{
660 fileloc loc = setLocation ();
661 uentry ue = uentry_makeConstant (n, t, loc);
662
663 ue->ukind = KENUMCONST;
664 uentry_setDefined (ue, loc);
665 return ue;
666}
667
668/*@notnull@*/ uentry uentry_makeEnumInitializedConstant (cstring n, ctype t, exprNode expr)
669{
670 fileloc loc = setLocation ();
671 uentry ue = uentry_makeConstant (n, t, loc);
672 ctype etype = exprNode_getType (expr);
673
674 if (!ctype_isRealInt (etype)) {
675 voptgenerror
676 (FLG_ENUMMEMBERS,
677 message
678 ("Value of enum member is not an integeral type (type %s): %s",
679 ctype_unparse (etype), exprNode_unparse (expr)),
680 exprNode_loc (expr));
681 }
682
683 ue->ukind = KENUMCONST;
684 uentry_setDefined (ue, loc);
685 return ue;
686}
687
616915dd 688/*@notnull@*/ uentry uentry_makeSpecEnumConstant (cstring n, ctype t, fileloc loc)
689{
690 uentry ue = uentry_makeConstant (n, t, loc);
691
692 ue->ukind = KENUMCONST;
693 return ue;
694}
616915dd 695
696/*@notnull@*/ uentry uentry_makeVariableLoc (cstring n, ctype t)
697{
698 return uentry_makeVariable (n, t, setLocation (), FALSE);
699}
700
288cbc5c 701bool uentry_isUnnamedVariable (uentry ue)
702{
703 return uentry_isVariable (ue) && cstring_isUndefined (ue->uname);
704}
705
616915dd 706/*@notnull@*/ /*@only@*/ uentry uentry_makeUnnamedVariable (ctype t)
707{
708 return uentry_makeVariable (cstring_undefined, t, setLocation (), FALSE);
709}
616915dd 710
711/*@notnull@*/ uentry uentry_makeIdDatatype (idDecl id)
712{
713 ctype ct = idDecl_getCtype (id);
714 uentry ue = uentry_makeDatatype (idDecl_observeId (id), ct,
e5081f8c 715 MAYBE, qual_createUnknown (),
716 setLocation ());
616915dd 717
718 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
719
e5081f8c 720 if (!qual_isEitherAbstract (ue->info->datatype->abs))
616915dd 721 {
722 if (ctype_isUnknown (ct))
723 {
724 ue->info->datatype->mut = MAYBE;
725 }
726 else
727 {
728 ue->info->datatype->mut = ynm_fromBool (ctype_isMutable (ct));
729 }
730 }
731
732 return ue;
733}
734
735void uentry_checkParams (uentry ue)
736{
737 if (uentry_isValid (ue))
738 {
739 bool isExt = uentry_isExtern (ue);
740
741 if (uentry_isRealFunction (ue))
742 {
743 uentryList params = uentry_getParams (ue);
b87215ab 744 int paramno = 0;
616915dd 745
746 uentryList_elements (params, current)
747 {
b87215ab 748 paramno++;
749
616915dd 750 if (uentry_isValid (current))
751 {
752 ctype ct = current->utype;
753
754 if (ctype_isFixedArray (ct))
755 {
756 if (ctype_isArray (ctype_baseArrayPtr (ct))
757 && !ctype_isFixedArray (ctype_baseArrayPtr (ct)))
758 {
759 ;
760 }
761 else
762 {
b87215ab 763 if (uentry_hasName (current))
764 {
765 voptgenerror
766 (FLG_FIXEDFORMALARRAY,
767 message ("Function parameter %q declared as "
768 "manifest array (size constant is meaningless)",
769 uentry_getName (current)),
770 uentry_whereDeclared (current));
771 }
772 else
773 {
774 voptgenerror
775 (FLG_FIXEDFORMALARRAY,
776 message ("Unnamed function parameter %d declared as "
777 "manifest array (size constant is meaningless)",
778 paramno),
779 uentry_whereDeclared (current));
780 }
616915dd 781 }
782 }
783 else
784 {
785 if (ctype_isArray (ct))
786 {
b87215ab 787 if (uentry_hasName (current))
788 {
789 voptgenerror
790 (FLG_FORMALARRAY,
791 message ("Function parameter %q declared as "
792 "array (treated as pointer)",
793 uentry_getName (current)),
794 uentry_whereDeclared (current));
795 }
796 else
797 {
798 voptgenerror
799 (FLG_FORMALARRAY,
800 message ("Unnamed function parameter %d declared as "
801 "array (treated as pointer)",
802 paramno),
803 uentry_whereDeclared (current));
804 }
616915dd 805 }
806 }
807
808 if (sRef_getNullState (uentry_getSref (current)) == NS_MNOTNULL)
809 {
810 if (ctype_isAbstract (ct) &&
811 (isExt || (ctype_isAbstract (ctype_realType (ct))
812 && !context_hasFileAccess (ctype_typeId (ct)))))
813 {
814 vgenhinterror
815 (FLG_INCONDEFS,
816 message
817 ("Function %q declared with notnull parameter %q of abstract "
818 "type %s",
819 uentry_getName (ue),
820 uentry_getName (current),
821 ctype_unparse (ct)),
822 message
823 ("Since %s is an abstract type, notnull can only be "
824 "used for parameters if the function is static to a "
825 "module where %s is accessible.",
826 ctype_unparse (ct),
827 ctype_unparse (ct)),
828 uentry_whereDeclared (current));
829 }
830 }
831 }
832 } end_uentryList_elements;
833
834 if (sRef_getNullState (uentry_getSref (ue)) == NS_MNOTNULL)
835 {
836 ctype ct = ue->utype;
837
838 if (ctype_isAbstract (ct)
839 && (isExt || (ctype_isAbstract (ctype_realType (ct))
840 && !context_hasFileAccess (ctype_typeId (ct)))))
841 {
842 vgenhinterror
843 (FLG_INCONDEFS,
844 message
845 ("%s %q declared %s notnull storage of abstract type %s",
846 ekind_capName (uentry_getKind (ue)),
847 uentry_getName (ue),
848 fcnErrName (ue),
849 ctype_unparse (ct)),
850 message
851 ("Since %s is an abstract type, notnull can only be used "
852 "if it is static to a module where %s is accessible.",
853 ctype_unparse (ct),
854 ctype_unparse (ct)),
855 uentry_whereDeclared (ue));
856 }
857 }
858 }
859 }
860}
861
862static void reflectImplicitFunctionQualifiers (/*@notnull@*/ uentry ue, bool spec)
863{
864 alkind ak = sRef_getAliasKind (ue->sref);
865
866 if (alkind_isRefCounted (ak))
867 {
868 sRef_setAliasKind (ue->sref, AK_NEWREF, fileloc_undefined);
869 }
870 else
871 {
872 if (alkind_isUnknown (ak))
873 {
874 exkind ek = sRef_getExKind (ue->sref);
875
876 if (exkind_isKnown (ek))
877 {
28bf4b0b 878 DPRINTF (("Setting imp dependent: %s",
879 uentry_unparseFull (ue)));
616915dd 880 sRef_setAliasKind (ue->sref, AK_IMPDEPENDENT, fileloc_undefined);
881 }
882 else
883 {
884 if (context_getFlag (spec ? FLG_SPECRETIMPONLY : FLG_RETIMPONLY))
885 {
28bf4b0b 886 /* evans 2000-12-22 removed ctype_realType so it will
887 not apply to immutable abstract types. */
888
616915dd 889 if (ctype_isVisiblySharable
28bf4b0b 890 (ctype_realType (ctype_getReturnType (ue->utype))))
616915dd 891 {
892 if (uentryList_hasReturned (uentry_getParams (ue)))
893 {
894 ;
895 }
28bf4b0b 896 else
616915dd 897 {
b73d1009 898 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype))
899 || ctype_isNumAbstract (ctype_getReturnType (ue->utype)))
28bf4b0b 900 {
901 ; /* Immutable objects are not shared. */
902 }
903 else
904 {
905 sRef_setAliasKind (ue->sref, AK_IMPONLY,
906 fileloc_undefined);
907 DPRINTF (("Ret imp only: %s",
908 ctype_unparse (ctype_getReturnType (ue->utype))));
909 }
910 }
616915dd 911 }
912 }
913 }
914 }
915 }
916}
917
918static /*@notnull@*/ uentry
919uentry_makeFunctionAux (cstring n, ctype t,
920 typeIdSet access,
921 /*@only@*/ globSet globs,
28bf4b0b 922 /*@only@*/ sRefSet mods,
923 /*@only@*/ warnClause warn,
616915dd 924 /*@keep@*/ fileloc f, bool priv,
925 /*@unused@*/ bool isForward)
926{
927 uentry e = uentry_alloc ();
928 ctype ret;
929
b73d1009 930 llassert (warnClause_isUndefined (warn));
ccf0a4a8 931
616915dd 932 if (ctype_isFunction (t))
933 {
28bf4b0b 934 ret = ctype_getReturnType (t);
616915dd 935 }
936 else
937 {
938 if (ctype_isKnown (t))
939 {
940 llbug (message ("not function: %s", ctype_unparse (t)));
941 }
942 ret = ctype_unknown;
943 }
944
945 e->ukind = KFCN;
946
947 if (fileloc_isSpec (f) || fileloc_isImport (f))
948 {
949 e->whereSpecified = f;
950 e->whereDeclared = fileloc_undefined;
951 }
952 else
953 {
954 e->whereSpecified = fileloc_undefined;
955 e->whereDeclared = f;
956 }
957
958 /* e->shallowCopy = FALSE; */
959 e->uname = cstring_copy (n);
960 e->utype = t;
961 e->storageclass = SCNONE;
962
b072092f 963 e->sref = sRef_makeResult (ret); /* evans 2001-07-19 - was sRef_makeType */
964
965 DPRINTF (("Result: %s", sRef_unparseFull (e->sref)));
616915dd 966
967 if (ctype_isUA (ret))
968 {
969 sRef_setStateFromType (e->sref, ret);
970 }
971
972 e->used = FALSE;
973 e->lset = FALSE;
974 e->uses = filelocList_new ();
975 e->isPrivate = priv;
976 e->hasNameError = FALSE;
977
28bf4b0b 978 e->warn = warn;
979
616915dd 980 e->info = (uinfo) dmalloc (sizeof (*e->info));
981 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
982
983 e->info->fcn->hasMods = sRefSet_isDefined (mods);
984 e->info->fcn->hasGlobs = globSet_isDefined (globs);
985
986 e->info->fcn->exitCode = XK_UNKNOWN;
28bf4b0b 987 e->info->fcn->nullPred = qual_createUnknown ();
616915dd 988 e->info->fcn->specialCode = SPC_NONE;
989
990 e->info->fcn->access = access;
991 e->info->fcn->globs = globs;
992 e->info->fcn->defparams = uentryList_undefined;
993
994 sRef_setDefined (e->sref, f);
995 e->whereDefined = fileloc_undefined;
996
997 e->info->fcn->mods = sRefSet_undefined;
998 e->info->fcn->specclauses = NULL;
999
1000 /*drl 11 29 2000*/
1001 e->info->fcn->preconditions = NULL;
1002 /*end drl*/
1003
1004 /*drl 12 28 2000*/
1005 e->info->fcn->postconditions = NULL;
1006 /*end drl*/
1007
1008 checkGlobalsModifies (e, mods);
1009 e->info->fcn->mods = mods;
1010
1011 return (e);
1012}
1013
28bf4b0b 1014static void uentry_reflectClauses (uentry ue, functionClauseList clauses)
1015{
1016 functionClauseList_elements (clauses, el)
1017 {
1018 DPRINTF (("Reflect clause: %s on %s",
1019 functionClause_unparse (el), uentry_getName (ue)));
1020
1021 if (functionClause_isNoMods (el))
1022 {
1023 modifiesClause mel = functionClause_getModifies (el);
1024
1025 if (uentry_hasGlobs (ue))
1026 {
1027 voptgenerror
1028 (FLG_SYNTAX,
1029 message
1030 ("No globals and modifies inconsistent to globals clause for %q: %q",
1031 uentry_getName (ue),
1032 globSet_unparse (uentry_getGlobs (ue))),
1033 modifiesClause_getLoc (mel));
1034
1035 }
1036
1037 if (uentry_hasMods (ue))
1038 {
1039 voptgenerror
1040 (FLG_SYNTAX,
1041 message
1042 ("No globals and modifies inconsistent to modifies clause for %q: %q",
1043 uentry_getName (ue),
1044 sRefSet_unparse (uentry_getMods (ue))),
1045 modifiesClause_getLoc (mel));
1046 }
1047
1048 uentry_setGlobals (ue, globSet_undefined);
1049 uentry_setModifies (ue, sRefSet_undefined);
1050 }
1051 else if (functionClause_isGlobals (el))
1052 {
1053 globalsClause glc = functionClause_getGlobals (el);
1054
1055 DPRINTF (("Globals: %s / %s", uentry_unparse (ue),
1056 globalsClause_unparse (glc)));
1057
1058 if (uentry_hasGlobs (ue))
1059 {
928377c6 1060 vgenhinterror
28bf4b0b 1061 (FLG_SYNTAX,
1062 message
1063 ("Multiple globals clauses for %q: %q",
1064 uentry_getName (ue),
1065 globalsClause_unparse (glc)),
928377c6 1066 cstring_makeLiteral ("Only one globals clause may be used. The second globals clause is ignored."),
28bf4b0b 1067 globalsClause_getLoc (glc));
928377c6 1068
1069 /*
1070 uentry_setGlobals (ue, globalsClause_takeGlobs (glc));
1071 */
28bf4b0b 1072 }
1073 else
1074 {
bb7c2085 1075 DPRINTF (("Taking globs: %s", globalsClause_unparse (glc)));
28bf4b0b 1076 uentry_setGlobals (ue, globalsClause_takeGlobs (glc));
bb7c2085 1077 DPRINTF (("Taking globs after: %s", globalsClause_unparse (glc)));
28bf4b0b 1078 }
1079 }
1080 else if (functionClause_isModifies (el))
1081 {
1082 modifiesClause mlc = functionClause_getModifies (el);
1083
1084 DPRINTF (("Has modifies: %s", uentry_unparseFull (ue)));
1085
1086 if (uentry_hasMods (ue))
1087 {
1088 /*
1089 ** Not an error:
1090
1091 if (optgenerror
1092 (FLG_SYNTAX,
1093 message
1094 ("Multiple modifies clauses for %s: %s",
1095 uentry_getName (ue),
1096 modifiesClause_unparse (mlc)),
1097 modifiesClause_getLoc (mlc)))
1098 {
1099 llhint (message ("Previous modifies clause: ",
1100 sRefSet_unparse (uentry_getMods (ue))));
1101 }
1102
1103 **
1104 */
1105
b73d1009 1106 uentry_combineModifies (ue, modifiesClause_takeMods (mlc));
28bf4b0b 1107 }
1108 else
1109 {
1110 uentry_setModifies (ue, modifiesClause_takeMods (mlc));
1111 }
1112 }
d9a28762 1113 else if (functionClause_isEnsures (el))
1114 {
3814599d 1115 functionConstraint cl = functionClause_takeEnsures (el);
ba45e1e4 1116 DPRINTF (("Setting post: %s / %s",
1117 uentry_unparse (ue), functionConstraint_unparse (cl)));
d9a28762 1118 uentry_setPostconditions (ue, cl);
1119 }
1120 else if (functionClause_isRequires (el))
1121 {
3814599d 1122 functionConstraint cl = functionClause_takeRequires (el);
d9a28762 1123 uentry_setPreconditions (ue, cl);
1124 }
28bf4b0b 1125 else if (functionClause_isState (el))
1126 {
1127 stateClause sc = functionClause_takeState (el);
ccf0a4a8 1128
1129 if (stateClause_isBefore (sc) && stateClause_setsMetaState (sc))
1130 {
1131 sRefSet rfs = stateClause_getRefs (sc);
1132
1133 sRefSet_elements (rfs, s)
1134 {
1135 if (sRef_isParam (s))
1136 {
1137 /*
1138 ** Can't use requires on parameters
1139 */
1140
1141 voptgenerror
1142 (FLG_ANNOTATIONERROR,
1143 message ("Requires clauses for %q concerns parameters %q should be "
1144 "a parameter annotation instead: %q",
1145 uentry_unparse (ue),
1146 sRef_unparse (s),
1147 stateClause_unparse (sc)),
1148 stateClause_loc (sc));
1149 }
1150 } end_sRefSet_elements ;
1151 }
1152
1153 DPRINTF (("State clause: %s", stateClause_unparse (sc)));
28bf4b0b 1154 uentry_addStateClause (ue, sc);
1155 }
1156 else if (functionClause_isWarn (el))
1157 {
1158 warnClause wc = functionClause_takeWarn (el);
1159 uentry_addWarning (ue, wc);
1160 }
1161 else
1162 {
1163 DPRINTF (("Unhandled clause: %s", functionClause_unparse (el)));
1164 }
1165 } end_functionClauseList_elements ;
1166
ccf0a4a8 1167 DPRINTF (("Checking all: %s", sRef_unparseFull (ue->sref)));
28bf4b0b 1168 stateClauseList_checkAll (ue);
1169}
1170
616915dd 1171/*@notnull@*/ uentry uentry_makeIdFunction (idDecl id)
1172{
28bf4b0b 1173 bool leaveFunc = FALSE;
616915dd 1174 uentry ue =
1175 uentry_makeFunction (idDecl_observeId (id), idDecl_getCtype (id),
1176 typeId_invalid, globSet_undefined,
28bf4b0b 1177 sRefSet_undefined, warnClause_undefined,
616915dd 1178 setLocation ());
28bf4b0b 1179
ccf0a4a8 1180 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1181
28bf4b0b 1182 /*
1183 ** This makes parameters names print out correctly.
1184 ** (But we might be a local variable declaration for a function type...)
1185 */
1186
1187 if (context_inFunctionLike ())
1188 {
1189 DPRINTF (("Header: %s / %s",
1190 uentry_unparse (context_getHeader ()),
1191 idDecl_unparse (id)));
1192 }
1193 else
1194 {
1195 context_enterFunctionDeclaration (ue);
1196 leaveFunc = TRUE;
1197 }
1198
ccf0a4a8 1199 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
616915dd 1200 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
ccf0a4a8 1201 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
616915dd 1202 reflectImplicitFunctionQualifiers (ue, FALSE);
ccf0a4a8 1203 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
28bf4b0b 1204 uentry_reflectClauses (ue, idDecl_getClauses (id));
ccf0a4a8 1205 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
28bf4b0b 1206
616915dd 1207 if (!uentry_isStatic (ue)
1208 && cstring_equalLit (ue->uname, "main"))
1209 {
1210 ctype typ = ue->utype;
1211 ctype retval;
1212 uentryList args;
1213
1214 llassert (ctype_isFunction (typ));
1215
28bf4b0b 1216 retval = ctype_getReturnType (typ);
616915dd 1217
1218 if (!ctype_isInt (retval))
1219 {
1220 voptgenerror
1221 (FLG_MAINTYPE,
1222 message ("Function main declared to return %s, should return int",
1223 ctype_unparse (retval)),
1224 uentry_whereDeclared (ue));
1225 }
1226
1227 args = ctype_argsFunction (typ);
1228
1229 if (uentryList_isMissingParams (args)
1230 || uentryList_size (args) == 0)
1231 {
1232 ;
1233 }
1234 else
1235 {
1236 if (uentryList_size (args) != 2)
1237 {
1238 voptgenerror
1239 (FLG_MAINTYPE,
28bf4b0b 1240 message ("Function main declared with %d arg%&, "
616915dd 1241 "should have 2 (int argc, char *argv[])",
1242 uentryList_size (args)),
1243 uentry_whereLast (ue));
1244 }
1245 else
1246 {
1247 uentry arg = uentryList_getN (args, 0);
1248 ctype ct = uentry_getType (arg);
1249
1250 if (!ctype_isInt (ct))
1251 {
1252 voptgenerror
1253 (FLG_MAINTYPE,
1254 message ("Parameter 1, %q, of function main declared "
1255 "with type %t, should have type int",
1256 uentry_getName (arg), ct),
1257 uentry_whereDeclared (arg));
1258 }
1259
1260 arg = uentryList_getN (args, 1);
1261 ct = uentry_getType (arg);
1262
1263 if (ctype_isArrayPtr (ct)
1264 && ctype_isArrayPtr (ctype_baseArrayPtr (ct))
1265 && ctype_isChar (ctype_baseArrayPtr (ctype_baseArrayPtr (ct))))
1266 {
1267 ;
1268 }
1269 else
1270 {
1271 voptgenerror
1272 (FLG_MAINTYPE,
1273 message ("Parameter 2, %q, of function main declared "
1274 "with type %t, should have type char **",
1275 uentry_getName (arg), ct),
1276 uentry_whereDeclared (arg));
1277 }
1278 }
1279 }
1280 }
1281
28bf4b0b 1282 if (leaveFunc)
1283 {
1284 context_exitFunctionDeclaration ();
1285 }
1286
616915dd 1287 return ue;
1288}
1289
1290static void uentry_implicitParamAnnots (/*@notnull@*/ uentry e)
1291{
1292 alkind ak = sRef_getAliasKind (e->sref);
1293
1294 if ((alkind_isUnknown (ak) || alkind_isImplicit (ak))
1295 && context_getFlag (FLG_PARAMIMPTEMP))
1296 {
1297 exkind ek = sRef_getExKind (e->sref);
1298
1299 if (exkind_isKnown (ek))
1300 {
28bf4b0b 1301 DPRINTF (("imp dep: %s", uentry_unparseFull (e)));
616915dd 1302 sRef_setAliasKind (e->sref, AK_IMPDEPENDENT, fileloc_undefined);
1303 sRef_setOrigAliasKind (e->sref, AK_IMPDEPENDENT);
1304 }
1305 else
1306 {
1307 sRef_setAliasKind (e->sref, AK_IMPTEMP, fileloc_undefined);
1308 sRef_setOrigAliasKind (e->sref, AK_IMPTEMP);
1309 }
1310 }
1311}
1312
1313static /*@only@*/ /*@notnull@*/ uentry
6970c11b 1314uentry_makeVariableParamAux (cstring n, ctype t, /*@dependent@*/ sRef s,
b73d1009 1315 /*@only@*/ fileloc loc, sstate defstate)
616915dd 1316{
1317 cstring pname = makeParam (n);
28bf4b0b 1318 uentry e;
1319
1320 DPRINTF (("Sref: %s", sRef_unparseFull (s)));
6970c11b 1321 e = uentry_makeVariableAux (pname, t, loc, s, FALSE, VKPARAM);
616915dd 1322
1323 cstring_free (pname);
28bf4b0b 1324 DPRINTF (("Param: %s", uentry_unparseFull (e)));
616915dd 1325 uentry_implicitParamAnnots (e);
28bf4b0b 1326 DPRINTF (("Param: %s", uentry_unparseFull (e)));
616915dd 1327
1328 if (!sRef_isAllocated (e->sref) && !sRef_isPartial (e->sref))
1329 {
28bf4b0b 1330 DPRINTF (("Param: %s", uentry_unparseFull (e)));
616915dd 1331 sRef_setDefState (e->sref, defstate, uentry_whereDeclared (e));
1332 e->info->var->defstate = defstate;
1333 }
1334
28bf4b0b 1335 DPRINTF (("Param: %s", uentry_unparseFull (e)));
616915dd 1336 return (e);
1337}
1338
616915dd 1339void
1340uentry_setRefCounted (uentry e)
1341{
1342 if (uentry_isValid (e))
1343 {
1344 uentry_setAliasKind (e, AK_REFCOUNTED);
1345 sRef_storeState (e->sref);
1346 }
1347}
616915dd 1348
1349void
1350uentry_setStatic (uentry c)
1351{
1352 if (uentry_isValid (c))
1353 {
1354 alkind ak = sRef_getAliasKind (c->sref);
1355 c->storageclass = SCSTATIC;
1356
1357 if (uentry_isVariable (c) && !ctype_isFunction (uentry_getType (c)))
1358 {
1359 if (!alkind_isUnknown (ak)
1360 && !alkind_isStatic (ak))
1361 {
1362 if (!(ctype_isRealPointer (uentry_getType (c)))
1363 && !(ctype_isAbstract (ctype_realType (uentry_getType (c))))
1364 && !alkind_isRefCounted (ak))
1365 {
1366 if (alkind_isImplicit (ak)
1367 && alkind_isDependent (ak)
1368 && ctype_isArray (uentry_getType (c)))
1369 {
1370 ; /* no error for observer arrays */
1371 }
1372 else
1373 {
1374 voptgenerror
1375 (FLG_INCONDEFS,
1376 message ("Static storage %q declared as %s",
1377 uentry_getName (c),
1378 alkind_unparse (ak)),
1379 uentry_whereDeclared (c));
1380 }
1381 }
1382 }
1383 else
1384 {
1385 if (alkind_isUnknown (ak)
1386 || (alkind_isImplicit (sRef_getAliasKind (c->sref))
1387 && !alkind_isDependent (sRef_getAliasKind (c->sref))))
1388 {
1389 sRef_setAliasKind (c->sref, AK_STATIC, fileloc_undefined);
1390 sRef_setOrigAliasKind (c->sref, AK_STATIC);
1391 }
1392 }
1393 }
1394 }
1395}
1396
1397void
1398uentry_setExtern (uentry c)
1399{
1400 if (uentry_isValid (c))
1401 c->storageclass = SCEXTERN;
1402}
1403
1404void
1405uentry_setParamNo (uentry ue, int pno)
1406{
1407 llassert (uentry_isAnyParam (ue) && sRef_isParam (ue->sref));
1408 sRef_setParamNo (ue->sref, pno);
1409}
1410
1411static
1412void checkGlobalsModifies (/*@notnull@*/ uentry ue, sRefSet sr)
1413{
1414 sRefSet_allElements (sr, el)
1415 {
1416 sRef base = sRef_getRootBase (el);
1417
28bf4b0b 1418 if (sRef_isFileOrGlobalScope (base) || sRef_isInternalState (base)
616915dd 1419 || (sRef_isKindSpecial (base) && !sRef_isNothing (base)))
1420 {
1421 if (!globSet_member (ue->info->fcn->globs, base))
1422 {
1423 if (uentry_hasGlobs (ue)
1424 || context_getFlag (FLG_WARNMISSINGGLOBALSNOGLOBS))
1425 {
1426 if (optgenerror
1427 (FLG_WARNMISSINGGLOBALS,
1428 message
1429 ("Modifies list for %q uses global %q, "
1430 "not included in globals list.",
1431 uentry_getName (ue),
1432 sRef_unparse (base)),
1433 uentry_whereLast (ue)))
1434 {
1435 uentry_showWhereSpecified (ue);
1436 }
1437 }
1438
1439 ue->info->fcn->globs = globSet_insert (ue->info->fcn->globs,
1440 base);
1441 if (sRef_isFileStatic (base))
1442 {
1443 context_recordFileGlobals (ue->info->fcn->globs);
1444 }
1445 }
1446 }
1447 } end_sRefSet_allElements;
1448}
1449
1450uentry
6970c11b 1451uentry_makeVariableSrefParam (cstring n, ctype t, /*@only@*/ fileloc loc, /*@exposed@*/ sRef s)
616915dd 1452{
6970c11b 1453 return (uentry_makeVariableParamAux (n, t, s, loc, SS_UNKNOWN));
616915dd 1454}
1455
1456void
1457uentry_fixupSref (uentry ue)
1458{
1459 sRef sr;
1460
1461 if (uentry_isUndefined (ue) || uentry_isElipsisMarker (ue))
1462 {
1463 return;
1464 }
1465
1466 sr = uentry_getSref (ue);
1467
1468 sRef_resetState (sr);
1469 sRef_clearDerived (sr);
1470
1471 llassertprint (uentry_isVariable (ue), ("fixing: %s", uentry_unparseFull (ue)));
1472 llassert (sRef_isValid (sr));
1473
1474 if (uentry_isVariable (ue))
1475 {
b73d1009 1476 /* removed this: no need to copy? ue->sref = sRef_saveCopyShallow (ue->info->var->origsref); */
616915dd 1477 sRef_setDefState (sr, ue->info->var->defstate, fileloc_undefined);
1478 sRef_setNullState (sr, ue->info->var->nullstate, fileloc_undefined);
1479 }
1480}
1481
abd7f895 1482static void uentry_addStateClause (/*@notnull@*/ uentry ue, stateClause sc)
28bf4b0b 1483{
1484 /*
1485 ** Okay to allow multiple clauses of the same kind.
b73d1009 1486 */
28bf4b0b 1487
1488 ue->info->fcn->specclauses =
1489 stateClauseList_add (ue->info->fcn->specclauses, sc);
1490
1491 /* Will call checkAll to check later... */
1492}
1493
1494void uentry_setStateClauseList (uentry ue, stateClauseList clauses)
616915dd 1495{
1496 llassert (uentry_isFunction (ue));
28bf4b0b 1497 llassert (!stateClauseList_isDefined (ue->info->fcn->specclauses));
616915dd 1498
28bf4b0b 1499 DPRINTF (("checked clauses: %s", stateClauseList_unparse (clauses)));
616915dd 1500 ue->info->fcn->specclauses = clauses;
28bf4b0b 1501 stateClauseList_checkAll (ue);
1502 DPRINTF (("checked clauses: %s", uentry_unparseFull (ue)));
616915dd 1503}
1504
1505/*
1506** Used for @modifies@ @endmodifies@ syntax.
1507**
1508** If ue is specified, sr must contain *only*:
1509**
1510** o file static globals
1511** o sRef's derived from modifies spec (i.e., more specific than
1512** what was specified)
1513**
1514** Otherwise, if sr has modifies it must match sr.
1515**
1516** If it doesn't have modifies, set them to sr.
1517*/
1518
28bf4b0b 1519static bool
1520uentry_checkModifiesContext (void)
616915dd 1521{
1522 if (sRef_modInFunction ())
1523 {
1524 llparseerror
28bf4b0b 1525 (message
1526 ("Modifies list not in function context. "
1527 "A modifies list can only appear following the parameter list "
1528 "in a function declaration or header."));
1529
1530 return FALSE;
616915dd 1531 }
28bf4b0b 1532
1533 return TRUE;
1534}
616915dd 1535
28bf4b0b 1536void
1537uentry_setModifies (uentry ue, /*@owned@*/ sRefSet sr)
1538{
1539 if (!uentry_checkModifiesContext ())
616915dd 1540 {
28bf4b0b 1541 sRefSet_free (sr);
1542 return;
616915dd 1543 }
1544
1545 if (uentry_isValid (ue))
1546 {
1547 if (uentry_isIter (ue))
1548 {
1549 llassert (sRefSet_isUndefined (ue->info->iter->mods));
1550 ue->info->iter->mods = sr;
1551 }
1552 else
1553 {
efd360a3 1554 uentry_convertVarFunction (ue);
616915dd 1555 llassertfatal (uentry_isFunction (ue));
1556 llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1557
1558 ue->info->fcn->mods = sr;
1559 ue->info->fcn->hasMods = TRUE;
1560
1561 checkGlobalsModifies (ue, sr);
1562 }
1563
1564 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1565 {
1566 ue->info->fcn->hasGlobs = TRUE;
1567 }
28bf4b0b 1568
1569 if (sRefSet_hasStatic (ue->info->fcn->mods))
1570 {
1571 context_recordFileModifies (ue->info->fcn->mods);
1572 }
616915dd 1573 }
1574 else
1575 {
1576 sRefSet_free (sr);
1577 }
1578}
1579
28bf4b0b 1580static void
1581uentry_combineModifies (uentry ue, /*@owned@*/ sRefSet sr)
1582{
1583 /*
1584 ** Function already has one modifies clause (possibly from
1585 ** a specification).
1586 */
1587
1588 if (!uentry_checkModifiesContext ())
1589 {
1590 BADBRANCH;
1591 }
1592
1593 llassert (uentry_isValid (ue));
1594
1595 if (uentry_isIter (ue))
1596 {
1597 ue->info->iter->mods = sRefSet_unionFree (ue->info->iter->mods, sr);
1598 }
1599 else
1600 {
1601 llassertfatal (uentry_isFunction (ue));
1602 llassert (ue->info->fcn->hasMods);
1603
1604 checkGlobalsModifies (ue, sr);
1605 ue->info->fcn->mods = sRefSet_unionFree (ue->info->fcn->mods, sr);
1606
1607 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1608 {
1609 ue->info->fcn->hasGlobs = TRUE;
1610 }
1611 }
1612
1613 if (sRefSet_hasStatic (ue->info->fcn->mods))
1614 {
1615 context_recordFileModifies (ue->info->fcn->mods);
1616 }
1617}
1618
1619bool uentry_hasWarning (uentry ue)
1620{
1621 return (uentry_isValid (ue)
1622 && warnClause_isDefined (ue->warn));
1623}
1624
1625void uentry_addWarning (uentry ue, /*@only@*/ warnClause warn)
1626{
abd7f895 1627 llassert (uentry_isValid (ue));
28bf4b0b 1628 llassert (warnClause_isUndefined (ue->warn));
1629 ue->warn = warn;
1630}
1631
616915dd 1632void
3814599d 1633uentry_setPreconditions (uentry ue, /*@only@*/ functionConstraint preconditions)
616915dd 1634{
1635 if (sRef_modInFunction ())
1636 {
1637 llparseerror
1638 (message ("Precondition list not in function context. "
1639 "A precondition list can only appear following the parameter list "
1640 "in a function declaration or header."));
1641
1642 /*@-mustfree@*/ return; /*@=mustfree@*/
1643 }
1644
1645 if (uentry_isValid (ue))
1646 {
efd360a3 1647 uentry_convertVarFunction (ue);
1648 llassertfatal (uentry_isFunction (ue));
3814599d 1649
efd360a3 1650 if (functionConstraint_isDefined (ue->info->fcn->preconditions))
1651 {
312c9815 1652 /*drl oops this date is wronge...*/
77d37419 1653 /* drl 11-29-2002
11db3170 1654 I changed this so it didn't appear as a Splint bug
9db43751 1655 among other things this gets triggered when there is
11db3170 1656 a function with two requires clauses. Now Splint
9db43751 1657 prints an error and tries to conjoin the lists.
1658 */
1659 llparseerror
1660 (message ("Duplicate precondition list"
1661 "Attemping the conjoin the requires clauses"
1662 ));
1663
1664
1665 /* should conjoin constraints? */
efd360a3 1666 /*@notreached@*/
1667 ue->info->fcn->preconditions = functionConstraint_conjoin (ue->info->fcn->preconditions, preconditions);
1668 }
1669 else
1670 {
1671 ue->info->fcn->preconditions = preconditions;
1672 }
616915dd 1673 }
1674 else
1675 {
bb7c2085 1676 llfatalbug ((message("uentry_setPreconditions called with invalid uentry") ));
616915dd 1677 }
1678}
1679
1680/*
1681 drl
1682 added 12/28/2000
1683*/
1684void
3814599d 1685uentry_setPostconditions (uentry ue, /*@only@*/ functionConstraint postconditions)
616915dd 1686{
1687 if (sRef_modInFunction ())
1688 {
1689 llparseerror
1690 (message ("Postcondition list not in function context. "
1691 "A postcondition list can only appear following the parameter list "
1692 "in a function declaration or header."));
3814599d 1693
616915dd 1694 /*@-mustfree@*/ return; /*@=mustfree@*/
1695 }
1696
1697 if (uentry_isValid (ue))
1698 {
efd360a3 1699 uentry_convertVarFunction (ue);
1700 llassertfatal (uentry_isFunction (ue));
1701
1702 if (functionConstraint_isUndefined (ue->info->fcn->postconditions))
1703 {
1704 ue->info->fcn->postconditions = postconditions;
1705 }
1706 else
1707 {
efd360a3 1708 ue->info->fcn->postconditions = functionConstraint_conjoin (ue->info->fcn->postconditions, postconditions);
1709 }
616915dd 1710 }
1711 else
1712 {
bb7c2085 1713 llfatalbug ((message("uentry_setPostconditions called with invalid uentry") ));
616915dd 1714 }
1715}
1716
1717/*
1718** requires: new and old are functions
1719*/
1720
1721static void
1722checkGlobalsConformance (/*@notnull@*/ uentry old,
1723 /*@notnull@*/ uentry unew,
1724 bool mustConform, bool completeConform)
1725{
1726 bool hasInternalState = FALSE;
1727
1728 old->info->fcn->hasGlobs |= unew->info->fcn->hasGlobs;
1729
1730 if (globSet_isDefined (unew->info->fcn->globs))
1731 {
1732 globSet_allElements (unew->info->fcn->globs, el)
1733 {
1734 if (sRef_isFileStatic (el))
1735 {
1736 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1737
1738 if (sRef_isInvalid (sr))
1739 {
1740 bool hasError = FALSE;
1741
1742 if (!hasInternalState
1743 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1744 sRef_makeInternalState ()))
1745 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1746 sRef_makeSpecState ())))
1747 {
1748 if (mustConform
1749 && !uentry_isStatic (old)
1750 && optgenerror
1751 (FLG_INCONDEFS,
1752 message ("Globals list for %q includes internal state, %q, "
1753 "but %s without globals internalState.",
1754 uentry_getName (old),
1755 sRef_unparse (el),
1756 uentry_specOrDefName (old)),
1757 uentry_whereLast (unew)))
1758 {
1759 uentry_showWhereSpecified (old);
1760 hasError = TRUE;
1761 }
1762
1763 old->info->fcn->globs = globSet_insert (old->info->fcn->globs,
1764 sRef_makeInternalState ());
1765 hasInternalState = TRUE;
1766 }
1767
1768 if (!hasError
1769 && fileloc_sameFile (uentry_whereDeclared (unew),
1770 uentry_whereDeclared (old)))
1771 {
1772 if (mustConform
1773 && optgenerror
1774 (FLG_INCONDEFS,
1775 message ("Function %q inconsistently %rdeclared (in "
1776 "same file) with file static global %q in "
1777 "globals list",
1778 uentry_getName (unew),
1779 uentry_isDeclared (old),
1780 sRef_unparse (el)),
1781 uentry_whereDeclared (unew)))
1782 {
1783 uentry_showWhereSpecified (old);
1784 }
1785 }
1786 }
1787
1788 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1789 context_recordFileGlobals (old->info->fcn->globs);
1790 }
1791 else
1792 {
1793 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1794
1795 if (sRef_isInvalid (sr))
1796 {
1797 if (mustConform
1798 && optgenerror
1799 (FLG_INCONDEFS,
1800 message ("Function %q inconsistently %rdeclared with "
1801 "%q in globals list",
1802 uentry_getName (unew),
1803 uentry_isDeclared (old),
1804 sRef_unparse (el)),
1805 uentry_whereDeclared (unew)))
1806 {
1807 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1808 uentry_showWhereSpecified (old);
1809 }
1810 }
1811 else
1812 {
1813 if (!bool_equal (sRef_isAllocated (el), sRef_isAllocated (sr)))
1814 {
1815 if (mustConform
1816 && optgenerror
1817 (FLG_INCONDEFS,
1818 message
1819 ("Function %q global %q inconsistently "
1820 "%rdeclared as %qout global",
1821 uentry_getName (unew),
1822 sRef_unparse (el),
1823 uentry_isDeclared (old),
1824 cstring_makeLiteral (sRef_isAllocated (el) ? "" : "non-")),
1825 uentry_whereDeclared (unew)))
1826 {
1827 uentry_showWhereSpecified (old);
1828 }
1829 }
1830 }
1831 }
1832 } end_globSet_allElements ;
1833
1834 if (completeConform)
1835 {
1836 globSet_allElements (old->info->fcn->globs, el)
1837 {
1838 sRef sr = globSet_lookup (unew->info->fcn->globs, el);
1839
1840 if (sRef_isInvalid (sr))
1841 {
1842 if (mustConform
1843 && uentry_isReallySpecified (old)
1844 && optgenerror
1845 (FLG_NEEDSPEC,
1846 message ("Function %q specified with %q in globals list, "
1847 "but declared without %q",
1848 uentry_getName (unew),
1849 sRef_unparse (el),
1850 sRef_unparse (el)),
1851 uentry_whereDeclared (unew)))
1852 {
1853 uentry_showWhereSpecified (old);
1854 }
1855 }
1856 } end_globSet_allElements;
1857 }
1858 }
1859 else
1860 {
1861 if (completeConform && !globSet_isEmpty (old->info->fcn->globs))
1862 {
1863 if (uentry_isReallySpecified (old)
1864 && optgenerror
1865 (FLG_NEEDSPEC,
1866 message ("%s %q specified with globals list, but "
1867 "declared with no globals",
1868 ekind_capName (unew->ukind),
1869 uentry_getName (unew)),
1870 uentry_whereDeclared (unew)))
1871 {
1872 llgenindentmsg
1873 (message ("Specification globals: %q",
1874 globSet_unparse (old->info->fcn->globs)),
1875 uentry_whereSpecified (old));
1876 }
1877 }
1878
28bf4b0b 1879 unew->info->fcn->globs = globSet_copyInto (unew->info->fcn->globs,
1880 old->info->fcn->globs);
616915dd 1881 }
1882}
1883
1884/*
1885** new modifies list must be included by old modifies list.
1886**
1887** file static state may be added to new, if old has internal.
1888*/
1889
1890static void
1891checkModifiesConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
1892 bool mustConform, bool completeConform)
1893{
1894 sRefSet newMods;
1895 bool changedMods = FALSE;
1896 bool modInternal = FALSE;
1897
1898 llassert (uentry_isFunction (old) && uentry_isFunction (unew));
1899
1900 old->info->fcn->hasMods |= unew->info->fcn->hasMods;
1901 newMods = unew->info->fcn->mods;
1902
1903 if (sRefSet_isEmpty (newMods))
1904 {
1905 if (completeConform && !sRefSet_isEmpty (old->info->fcn->mods)
1906 && uentry_isReallySpecified (old))
1907 {
1908 if (optgenerror
1909 (FLG_NEEDSPEC,
1910 message ("%s %q specified with modifies clause, "
1911 "but declared with no modifies clause",
1912 ekind_capName (unew->ukind),
1913 uentry_getName (unew)),
1914 uentry_whereDeclared (unew)))
1915 {
1916 llgenindentmsg (message ("Specification has modifies %q",
1917 sRefSet_unparse (old->info->fcn->mods)),
1918 uentry_whereSpecified (old));
1919 }
1920 }
1921
1922 return;
1923 }
1924
1925 sRefSet_allElements (newMods, current)
1926 {
1927 if (sRef_isValid (current))
1928 {
1929 sRef rb = sRef_getRootBase (current);
1930
1931 if (sRef_isFileStatic (rb))
1932 {
1933 if (!modInternal)
1934 {
1935 if (!sRefSet_isSameMember (old->info->fcn->mods,
1936 sRef_makeInternalState ())
1937 && !sRefSet_isSameMember (old->info->fcn->mods,
1938 sRef_makeSpecState ()))
1939 {
1940 if (mustConform
1941 && !uentry_isStatic (old)
1942 && optgenerror
1943 (FLG_INCONDEFS,
1944 message
1945 ("Modifies list for %q includes internal state, "
1946 "but %s without modifies internal.",
1947 uentry_getName (old),
1948 uentry_specOrDefName (old)),
1949 uentry_whereLast (unew)))
1950 {
1951 uentry_showWhereSpecified (old);
1952 }
1953
1954 old->info->fcn->mods =
1955 sRefSet_insert (old->info->fcn->mods,
1956 sRef_makeInternalState ());
1957 modInternal = TRUE;
1958 }
1959 }
1960
1961 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1962 current);
1963 changedMods = TRUE;
1964 }
1965 else
1966 {
1967 if (sRef_canModifyVal (current, old->info->fcn->mods))
1968 {
1969 int size = sRefSet_size (old->info->fcn->mods);
1970
1971 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1972 current);
1973
1974 if (sRefSet_size (old->info->fcn->mods) != size)
1975 {
1976 changedMods = TRUE;
1977 }
1978 }
1979 else
1980 {
1981 if (mustConform
1982 && optgenerror
1983 (FLG_INCONDEFS,
1984 message
1985 ("Modifies list for %q contains %q, not modifiable "
1986 "according to %s",
1987 uentry_getName (old),
1988 sRef_unparse (current),
1989 uentry_specDeclName (old)),
1990 uentry_whereLast (unew)))
1991 {
1992 uentry_showWhereSpecified (old);
1993 }
1994 }
1995 }
1996 }
1997 } end_sRefSet_allElements;
1998
1999 if (completeConform && uentry_isReallySpecified (old))
2000 {
2001 sRefSet_allElements (old->info->fcn->mods, el)
2002 {
2003 if (sRef_canModify (el, newMods))
2004 {
2005 ; /* okay */
2006 }
2007 else
2008 {
2009 if (optgenerror
2010 (FLG_NEEDSPEC,
2011 message
2012 ("Specification modifies clause for %q contains %q, "
2013 "not included in declaration modifies clause",
2014 uentry_getName (old),
2015 sRef_unparse (el)),
2016 uentry_whereLast (unew)))
2017 {
2018 uentry_showWhereSpecified (old);
2019 }
2020 }
2021 } end_sRefSet_allElements ;
2022 }
2023
2024 /*
2025 ** Make sure file static elements will be removed.
2026 */
2027
2028 if (changedMods)
2029 {
2030 context_recordFileModifies (old->info->fcn->mods);
2031 }
2032}
2033
2034static void
2035 uentry_checkMutableType (uentry ue)
2036{
2037 ctype ct = uentry_getType (ue);
2038
2039 if (!ctype_isRealPointer (ct) && !ctype_isRealAbstract (ct))
2040 {
28bf4b0b 2041 DPRINTF (("Check mutable: %s", uentry_unparseFull (ue)));
2042
616915dd 2043 voptgenerror (FLG_MUTREP,
2044 message ("Mutable abstract type %q declared without pointer "
2045 "indirection: %t (violates assignment semantics)",
2046 uentry_getName (ue), ct),
2047 uentry_whereDeclared (ue));
2048 }
2049}
2050
2051void
2052uentry_setMutable (uentry e)
2053{
2054 llassert (uentry_isDatatype (e));
2055 e->info->datatype->mut = YES;
2056}
2057
2058static void
2059uentry_checkIterArgs (uentry ue)
2060{
2061 bool hasYield = FALSE;
2062 uentryList args;
2063
2064 llassert (uentry_isIter (ue));
2065
2066 args = uentry_getParams (ue);
2067
2068 uentryList_elements (args, el)
2069 {
2070 sstate ds = uentry_getDefState (el);
2071
2072 if (uentry_isYield (el))
2073 {
2074 hasYield = TRUE;
2075 }
2076
2077 if (sstate_isUnknown (ds))
2078 {
2079 uentry_setDefState (el, SS_DEFINED);
2080 }
2081 else
2082 {
2083 ;
2084 }
2085 } end_uentryList_elements;
2086
2087 if (!hasYield)
2088 {
2089 voptgenerror (FLG_HASYIELD,
2090 message ("Iterator %q declared with no yield parameters",
2091 uentry_getName (ue)),
2092 uentry_whereDeclared (ue));
2093 }
2094}
2095
2096static chkind
2097chkind_fromQual (qual qel)
2098{
2099 if (qual_isChecked (qel))
2100 {
2101 return CH_CHECKED;
2102 }
2103 else if (qual_isCheckMod (qel))
2104 {
2105 return CH_CHECKMOD;
2106 }
2107 else if (qual_isCheckedStrict (qel))
2108 {
2109 return CH_CHECKEDSTRICT;
2110 }
2111 else if (qual_isUnchecked (qel))
2112 {
2113 return CH_UNCHECKED;
2114 }
2115 else
2116 {
2117 BADEXIT;
2118 /*@notreached@*/ return CH_UNKNOWN;
2119 }
2120}
2121
2122static void
2123uentry_reflectOtherQualifier (/*@notnull@*/ uentry ue, qual qel)
2124{
2125 if (qual_isKillRef (qel) || qual_isNewRef (qel) || qual_isTempRef (qel))
2126 {
2127 if (!uentry_isRefCounted (ue))
2128 {
28bf4b0b 2129 voptgenerror
2130 (FLG_ANNOTATIONERROR,
616915dd 2131 message ("Reference counting qualifier %s used on non-reference "
2132 "counted storage: %q",
2133 qual_unparse (qel),
28bf4b0b 2134 uentry_unparse (ue)),
2135 uentry_whereLast (ue));
616915dd 2136 }
2137 else
2138 {
2139 alkind ak = alkind_fromQual (qel);
2140
2141 uentry_setAliasKind (ue, ak);
2142 }
2143 }
2144 else if (qual_isRefCounted (qel))
2145 {
2146 ctype ct = ctype_realType (uentry_getType (ue));
2147 ctype rt;
2148
2149 if (ctype_isPointer (ct)
2150 && (ctype_isStruct (rt = ctype_realType (ctype_baseArrayPtr (ct)))))
2151 {
2152 /* check there is a refs field */
2153 uentryList fields = ctype_getFields (rt);
2154 uentry refs = uentry_undefined;
2155
2156 uentryList_elements (fields, field)
2157 {
2158 if (uentry_isRefsField (field))
2159 {
2160 if (uentry_isValid (refs))
2161 {
28bf4b0b 2162 voptgenerror
2163 (FLG_ANNOTATIONERROR,
616915dd 2164 message ("Reference counted structure type %s has "
2165 "multiple refs fields: %q and %q",
2166 ctype_unparse (ct),
2167 uentry_getName (refs),
28bf4b0b 2168 uentry_getName (field)),
2169 uentry_whereLast (field));
616915dd 2170 }
2171
2172 refs = field;
2173 }
2174 } end_uentryList_elements;
2175
2176 if (uentry_isInvalid (refs))
2177 {
2178 vgenhinterror
2179 (FLG_SYNTAX,
2180 message ("Reference counted structure type %s has "
2181 "no refs field",
2182 ctype_unparse (ct)),
2183 cstring_makeLiteral
2184 ("To count reference, the structure must have a field named "
2185 "refs of type int."),
2186 g_currentloc);
2187 }
2188 else if (!ctype_isInt (uentry_getType (refs)))
2189 {
28bf4b0b 2190 voptgenerror
2191 (FLG_ANNOTATIONERROR,
616915dd 2192 message ("Reference counted structure type %s refs field has "
2193 "type %s (should be int)", ctype_unparse (ct),
28bf4b0b 2194 ctype_unparse (uentry_getType (refs))),
2195 uentry_whereLast (refs));
616915dd 2196 }
2197 else
2198 {
2199 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2200 uentry_whereDeclared (ue));
2201 }
2202 }
2203 else
2204 {
2205 if ((ctype_isPointer (ct)
2206 && ctype_isUnknown (ctype_realType (ctype_baseArrayPtr (ct))))
2207 ||ctype_isAbstract (ct) || ctype_isUnknown (ct))
2208 {
2209 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2210 uentry_whereDeclared (ue));
2211 }
2212 else
2213 {
28bf4b0b 2214 voptgenerror
2215 (FLG_ANNOTATIONERROR,
616915dd 2216 message ("Non-pointer to structure type %s declared with "
2217 "refcounted qualifier",
28bf4b0b 2218 ctype_unparse (ct)),
2219 uentry_whereLast (ue));
616915dd 2220 }
2221 }
2222 }
2223 else if (qual_isRefs (qel))
2224 {
2225 if (uentry_isVariable (ue) && !uentry_isParam (ue))
2226 {
2227 uentry_setAliasKind (ue, AK_REFS);
2228 }
2229 else
2230 {
28bf4b0b 2231 voptgenerror
2232 (FLG_ANNOTATIONERROR,
616915dd 2233 message ("Refs qualifier used on non-structure field: %q",
28bf4b0b 2234 uentry_unparse (ue)),
2235 uentry_whereLast (ue));
616915dd 2236 }
2237 }
2238 else if (qual_isAliasQual (qel))
2239 {
2240 alkind ak = alkind_fromQual (qel);
2241 bool okay = TRUE;
2242 alkind oldak = uentry_getAliasKind (ue);
2243 ctype ut = uentry_getType (ue);
2244
2245 if (alkind_isImplicit (ak)
2246 && (alkind_isKnown (oldak) && !alkind_isImplicit (oldak)))
2247 {
2248 /* ignore the implied qualifier */
2249 okay = FALSE;
2250 }
2251
2252 if (uentry_isEitherConstant (ue))
2253 {
28bf4b0b 2254 voptgenerror
2255 (FLG_ANNOTATIONERROR,
616915dd 2256 message ("Alias qualifier %s used on constant: %q",
28bf4b0b 2257 alkind_unparse (ak), uentry_unparse (ue)),
2258 uentry_whereLast (ue));
2259
616915dd 2260 okay = FALSE;
2261 }
2262
2263 if (ctype_isFunction (ut))
2264 {
28bf4b0b 2265 ut = ctype_getReturnType (ut);
616915dd 2266 }
2267
2268 if (!(ctype_isVisiblySharable (ut)
2269 || ctype_isRealArray (ut)
2270 || ctype_isRealSU (ut)))
2271 {
2272 if (!qual_isImplied (qel))
2273 {
28bf4b0b 2274 voptgenerror
2275 (FLG_ANNOTATIONERROR,
616915dd 2276 message ("Alias qualifier %s used on unsharable storage type %t: %q",
28bf4b0b 2277 alkind_unparse (ak), ut, uentry_getName (ue)),
2278 uentry_whereLast (ue));
616915dd 2279 }
2280
2281 okay = FALSE;
2282 }
2283 else
2284 {
2285 if (uentry_isRefCounted (ue))
2286 {
2287 if (!(qual_isRefQual (qel) || qual_isOnly (qel)
2288 || qual_isExposed (qel)
2289 || qual_isObserver (qel)))
2290 {
2291 if (!qual_isImplied (qel))
2292 {
28bf4b0b 2293 voptgenerror
2294 (FLG_ANNOTATIONERROR,
616915dd 2295 message
2296 ("Alias qualifier %s used on reference counted storage: %q",
2297 alkind_unparse (ak),
28bf4b0b 2298 uentry_unparse (ue)),
2299 uentry_whereLast (ue));
616915dd 2300 }
2301
2302 okay = FALSE;
2303 }
2304 }
2305 else
2306 {
2307 if (qual_isRefQual (qel))
2308 {
28bf4b0b 2309 voptgenerror
2310 (FLG_ANNOTATIONERROR,
616915dd 2311 message ("Qualifier %s used on non-reference counted storage: %q",
28bf4b0b 2312 alkind_unparse (ak), uentry_unparse (ue)),
2313 uentry_whereLast (ue));
616915dd 2314
2315 okay = FALSE;
2316 }
2317 }
2318 }
2319
2320 if (okay)
2321 {
2322 uentry_setAliasKind (ue, ak);
2323 }
2324 }
2325 else if (qual_isNull (qel))
2326 {
2327 if (uentry_isConstant (ue))
2328 {
2329 sRef_setNullState
2330 (ue->sref,
2331 ctype_isAbstract (ue->utype) ? NS_CONSTNULL : NS_DEFNULL,
2332 uentry_whereDeclared (ue));
2333 }
2334 else
2335 {
2336 uentry_setNullState (ue, NS_POSNULL);
2337 }
2338 }
2339 else if (qual_isRelNull (qel))
2340 {
2341 uentry_setNullState (ue, NS_RELNULL);
2342 }
2343 else if (qual_isNotNull (qel))
2344 {
2345 uentry_setNullState (ue, NS_MNOTNULL);
2346 }
2347 else if (qual_isAbstract (qel)
e5081f8c 2348 || qual_isNumAbstract (qel)
616915dd 2349 || qual_isConcrete (qel))
2350 {
2351 if (!uentry_isDatatype (ue))
2352 {
28bf4b0b 2353 voptgenerror
2354 (FLG_ANNOTATIONERROR,
616915dd 2355 message ("Qualifier %s used with non-datatype",
28bf4b0b 2356 qual_unparse (qel)),
2357 uentry_whereLast (ue));
616915dd 2358 }
2359 else
2360 {
e5081f8c 2361 ue->info->datatype->abs = qel;
2362 DPRINTF (("Setting abstract %s: %s",
2363 uentry_unparse (ue), qual_unparse (qel)));
616915dd 2364 }
2365 }
2366 else if (qual_isMutable (qel))
2367 {
2368 if (!uentry_isDatatype (ue))
2369 {
28bf4b0b 2370 voptgenerror
2371 (FLG_ANNOTATIONERROR,
2372 message ("Qualifier %s used with non-datatype", qual_unparse (qel)),
2373 uentry_whereLast (ue));
616915dd 2374 }
2375 else
2376 {
2377 if (!ynm_isOn (ue->info->datatype->mut))
2378 {
2379 uentry_checkMutableType (ue);
2380 }
2381
2382 ue->info->datatype->mut = YES;
2383 }
2384 }
2385 else if (qual_isImmutable (qel))
2386 {
2387 if (!uentry_isDatatype (ue))
2388 {
28bf4b0b 2389 voptgenerror (FLG_ANNOTATIONERROR,
2390 message ("Qualifier %s used with non-datatype",
2391 qual_unparse (qel)),
2392 uentry_whereLast (ue));
616915dd 2393 }
2394 else
2395 {
2396 ue->info->datatype->mut = NO;
2397 }
2398 }
2399 else if (qual_isNullPred (qel))
2400 {
efd360a3 2401 uentry_convertVarFunction (ue);
2402
616915dd 2403 if (uentry_isFunction (ue))
2404 {
2405 ctype typ = uentry_getType (ue);
28bf4b0b 2406 ctype rtype = ctype_getReturnType (uentry_getType (ue));
616915dd 2407
2408 if (ctype_isRealBool (rtype))
2409 {
2410 uentryList pl = ctype_argsFunction (typ);
2411
2412 if (uentryList_size (pl) == 1)
2413 {
2414 ue->info->fcn->nullPred = qel;
2415 }
2416 else
2417 {
28bf4b0b 2418 voptgenerror (FLG_ANNOTATIONERROR,
2419 message ("Qualifier %s used with function having %d "
2420 "arguments (should have 1)",
2421 qual_unparse (qel),
2422 uentryList_size (pl)),
2423 uentry_whereLast (ue));
616915dd 2424 }
2425 }
2426 else
2427 {
28bf4b0b 2428 voptgenerror (FLG_ANNOTATIONERROR,
2429 message ("Qualifier %s used with function returning %s "
2430 "(should return bool)",
2431 qual_unparse (qel),
2432 ctype_unparse (rtype)),
2433 uentry_whereLast (ue));
616915dd 2434 }
2435 }
2436 else
2437 {
28bf4b0b 2438 voptgenerror (FLG_ANNOTATIONERROR,
2439 message ("Qualifier %s used with non-function",
2440 qual_unparse (qel)),
2441 uentry_whereLast (ue));
616915dd 2442 }
2443 }
2444 else if (qual_isExitQual (qel))
2445 {
2446 exitkind exk = exitkind_fromQual (qel);
2447
2448 if (uentry_isFunction (ue))
2449 {
2450 if (exitkind_isKnown (ue->info->fcn->exitCode))
2451 {
28bf4b0b 2452 voptgenerror (FLG_ANNOTATIONERROR,
2453 message ("Multiple exit qualifiers used on function %q: %s, %s",
2454 uentry_getName (ue),
2455 exitkind_unparse (ue->info->fcn->exitCode),
2456 exitkind_unparse (exk)),
2457 uentry_whereLast (ue));
616915dd 2458 }
2459
2460 ue->info->fcn->exitCode = exk;
2461 }
2462 else
2463 {
2464 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2465 {
2466 uentry_makeVarFunction (ue);
2467 ue->info->fcn->exitCode = exk;
2468 }
2469 else
2470 {
28bf4b0b 2471 voptgenerror (FLG_ANNOTATIONERROR,
2472 message ("Exit qualifier %s used with non-function (type %s)",
2473 qual_unparse (qel),
2474 ctype_unparse (uentry_getType (ue))),
2475 uentry_whereLast (ue));
2476 }
2477 }
2478 }
2479 else if (qual_isMetaState (qel))
2480 {
2481 annotationInfo ainfo = qual_getAnnotationInfo (qel);
2482
2483 if (annotationInfo_matchesContext (ainfo, ue))
2484 {
2485 DPRINTF (("Reflecting %s on %s",
2486 annotationInfo_unparse (ainfo),
2487 uentry_unparseFull (ue)));
2488
2489 sRef_reflectAnnotation (ue->sref, ainfo, g_currentloc);
2490 DPRINTF (("==> %s", sRef_unparseFull (ue->sref)));
2491 DPRINTF (("==> %s", uentry_unparseFull (ue)));
2492 }
2493 else
2494 {
2495 if (optgenerror
2496 (FLG_ANNOTATIONERROR,
0bf5022d 2497 message ("Attribute annotation %s used in inconsistent context: %q",
28bf4b0b 2498 qual_unparse (qel),
2499 uentry_unparse (ue)),
2500 uentry_whereLast (ue)))
2501 {
517a2db3 2502 /* annotationInfo_showContextError (ainfo, ue); */
616915dd 2503 }
2504 }
2505 }
2506 else
2507 {
2508 if (qual_isCQual (qel))
2509 {
2510 ; /* okay */
2511 }
2512 else
2513 {
28bf4b0b 2514 llbug (message ("Unhandled qualifier: %s", qual_unparse (qel)));
616915dd 2515 }
2516 }
2517}
2518
2519void
2520uentry_reflectQualifiers (uentry ue, qualList q)
2521{
2522 llassert (uentry_isValid (ue));
2523
ccf0a4a8 2524 DPRINTF (("Reflect qualifiers: %s / %s",
2525 uentry_unparseFull (ue), qualList_unparse (q)));
2526
616915dd 2527 qualList_elements (q, qel)
2528 {
2529 if (qual_isStatic (qel))
2530 {
2531 uentry_setStatic (ue);
2532 }
2533 else if (qual_isUnused (qel))
2534 {
2535 uentry_setUsed (ue, fileloc_undefined);
37ae0b5e 2536 DPRINTF (("Used: %s", uentry_unparseFull (ue)));
616915dd 2537 }
2538 else if (qual_isExternal (qel))
2539 {
2540 fileloc_free (ue->whereDefined);
2541 ue->whereDefined = fileloc_createExternal ();
2542 }
2543 else if (qual_isSef (qel))
2544 {
2545 if (uentry_isVariable (ue))
2546 {
2547 vkind vk = ue->info->var->kind;
2548
2549 llassert (vk != VKREFPARAM);
2550
2551 if (vk == VKYIELDPARAM)
2552 {
28bf4b0b 2553 voptgenerror
2554 (FLG_ANNOTATIONERROR,
616915dd 2555 message ("Qualifier sef cannot be used with %s: %q",
2556 cstring_makeLiteralTemp (vk == VKYIELDPARAM ? "yield" : "returned"),
28bf4b0b 2557 uentry_unparse (ue)),
2558 uentry_whereLast (ue));
616915dd 2559 }
2560 else if (vk == VKRETPARAM)
2561 {
2562 ue->info->var->kind = VKSEFRETPARAM;
2563 }
2564 else
2565 {
2566 ue->info->var->kind = VKSEFPARAM;
2567 }
2568 }
2569 else
2570 {
28bf4b0b 2571 voptgenerror
2572 (FLG_ANNOTATIONERROR,
616915dd 2573 message ("Qualifier sef is meaningful only on parameters: %q",
28bf4b0b 2574 uentry_unparse (ue)),
2575 uentry_whereLast (ue));
616915dd 2576 }
2577 }
2578 else if (qual_isExtern (qel))
2579 {
2580 ue->storageclass = SCEXTERN;
2581 }
2582 else if (qual_isGlobalQual (qel)) /* undef, killed */
2583 {
28bf4b0b 2584 DPRINTF (("Reflecting qual: %s / %s",
2585 qual_unparse (qel), uentry_unparse (ue)));
2586
616915dd 2587 if (uentry_isVariable (ue))
2588 {
2589 sstate oldstate = ue->info->var->defstate;
2590 sstate defstate = sstate_fromQual (qel);
2591
2592
2593 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
2594 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
2595 {
2596 defstate = SS_UNDEFKILLED;
2597 }
2598 else
2599 {
2600 ; /* any errors? */
2601 }
2602
2603 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2604 ue->info->var->defstate = defstate;
2605 }
2606 else
2607 {
28bf4b0b 2608 voptgenerror
2609 (FLG_ANNOTATIONERROR,
616915dd 2610 message ("Qualifier %s used on non-variable: %q",
28bf4b0b 2611 qual_unparse (qel), uentry_unparse (ue)),
2612 uentry_whereLast (ue));
616915dd 2613 }
28bf4b0b 2614
2615 DPRINTF (("After: %s", uentry_unparseFull (ue)));
616915dd 2616 }
2617 /* start modifications */
616915dd 2618 else if( qual_isBufQualifier(qel) ) {
2619 ctype ct = ctype_realType(uentry_getType(ue));
616915dd 2620 if( ctype_isArray(ct) || ctype_isPointer(ct) ) {
2621
2622 if( uentry_hasBufStateInfo(ue) ) {
616915dd 2623 if( qual_isNullTerminated(qel) ) { /* handle Nullterm */
2624
2625 if (uentry_isAnyParam(ue) || uentry_isReturned (ue)) {
2626 /* If formal func param */
2627 uentry_setNullTerminatedState(ue);
2628 uentry_setLen (ue, 1);
2629 uentry_setSize (ue, 1);
2630
2631 sRef_setNullTerminatedState(uentry_getSref(ue));
2632 sRef_setLen (uentry_getSref(ue), 1);
2633 sRef_setSize (uentry_getSref(ue), 1);
2634 } else {
2635 uentry_setPossiblyNullTerminatedState(ue);
2636
2637 sRef_setPossiblyNullTerminatedState(uentry_getSref(ue));
2638 }
2639
2640 }
2641 /* put other BufState Qualifiers here */
2642 } else {
2643 cstring s = uentry_getName(ue);
2644 llfatalbug(message("INTERNAL Error: we have a NULL BufState \
2645 struct for identifier %s\n", s) );
2646 }
2647 } else if (ctype_isFunction (ct)) { /* We have to handle function */
2648
2649 sRef retSref = uentry_getSref (ue);
2650 ctype retType = sRef_getType (retSref);
2651
2652 if (ctype_isPointer (retType) || ctype_isArray (retType)) {
2653 sRef_setNullTerminatedState (retSref);
2654
2655 } else {
2656
2657 llerror
2658 (FLG_SYNTAX,
2659 message ("Qualifier %s used on non-pointer on \
2660 function return: %q", qual_unparse (qel),
2661 uentry_unparse (ue)));
2662 }
2663 }
2664
2665 else {
2666 llerror
2667 (FLG_SYNTAX,
2668 message ("Qualifier %s used on non-pointer: %q",
2669 qual_unparse (qel), uentry_unparse (ue)));
2670 }
28bf4b0b 2671 DPRINTF (("After: %s", uentry_unparseFull (ue)));
616915dd 2672 }/* end else if */
2673 else if (qual_isAllocQual (qel)) /* out, partial, reldef, special, etc. */
2674 {
2675 ctype realType = ctype_realType (ue->utype);
2676 sstate defstate = sstate_fromQual (qel);
2677
2678 if (ctype_isFunction (realType))
2679 {
28bf4b0b 2680 realType = ctype_realType (ctype_getReturnType (realType));
616915dd 2681 }
2682
2683 if (qual_isRelDef (qel))
2684 {
2685 ; /* okay anywhere */
2686 }
2687 else
2688 {
2689 if (!ctype_isAP (realType)
2690 && !ctype_isSU (realType)
2691 && !ctype_isUnknown (realType)
2692 && !ctype_isAbstract (ue->utype))
2693 {
28bf4b0b 2694 voptgenerror
2695 (FLG_ANNOTATIONERROR,
616915dd 2696 message ("Qualifier %s used on non-pointer or struct: %q",
28bf4b0b 2697 qual_unparse (qel), uentry_unparse (ue)),
2698 uentry_whereLast (ue));
616915dd 2699 }
2700 }
2701
2702 uentry_setDefState (ue, defstate);
2703
2704 if (sRef_isStateSpecial (ue->sref)
2705 && alkind_isImplicit (sRef_getAliasKind (ue->sref)))
2706 {
2707 sRef_setAliasKind (ue->sref, AK_ERROR, fileloc_undefined);
2708 }
2709 }
2710 else if (qual_isYield (qel))
2711 {
2712 if (uentry_isVariable (ue))
2713 {
2714 ue->info->var->kind = VKYIELDPARAM;
2715 }
2716 else
2717 {
28bf4b0b 2718 voptgenerror
2719 (FLG_ANNOTATIONERROR,
616915dd 2720 message ("Qualifier %s used on non-iterator parameter: %q",
28bf4b0b 2721 qual_unparse (qel), uentry_unparse (ue)),
2722 uentry_whereLast (ue));
616915dd 2723 }
2724 }
2725 else if (qual_isExQual (qel))
2726 {
2727 exkind ek = exkind_fromQual (qel);
2728 ctype ut = uentry_getType (ue);
2729
28bf4b0b 2730 DPRINTF (("Reflect ex qual: %s / %s",
2731 uentry_unparse (ue), exkind_unparse (ek)));
2732
616915dd 2733 if (ctype_isFunction (ut))
2734 {
28bf4b0b 2735 ut = ctype_getReturnType (ut);
616915dd 2736 }
2737
2738 if (!(ctype_isVisiblySharable (ut))
2739 && !(ctype_isArray (ut)) /* can apply to arrays also! */
2740 && !(ctype_isStruct (ctype_realType (ut)))) /* applies to structure fields! */
2741 {
2742 if (!qual_isImplied (qel))
2743 {
28bf4b0b 2744 if (ctype_isImmutableAbstract (ut)) {
2745 voptgenerror
2746 (FLG_REDUNDANTSHAREQUAL,
2747 message ("Qualifier %s used on unsharable storage type %t: %q",
2748 exkind_unparse (ek), ut, uentry_getName (ue)),
2749 uentry_whereLast (ue));
2750 } else {
2751 voptgenerror
2752 (FLG_MISPLACEDSHAREQUAL,
2753 message ("Qualifier %s used on unsharable storage type %t: %q",
2754 exkind_unparse (ek), ut, uentry_getName (ue)),
2755 uentry_whereLast (ue));
2756 }
616915dd 2757 }
2758 }
2759 else
2760 {
2761 alkind ak = sRef_getAliasKind (ue->sref);
2762
2763 sRef_setExKind (ue->sref, ek, uentry_whereDeclared (ue));
28bf4b0b 2764 DPRINTF (("Set exkind: %s", sRef_unparseFull (ue->sref)));
616915dd 2765
2766 if (alkind_isUnknown (ak) || alkind_isImplicit (ak) || alkind_isStatic (ak))
2767 {
2768 if (!alkind_isTemp (ak))
2769 {
28bf4b0b 2770 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
616915dd 2771 uentry_setAliasKind (ue, AK_IMPDEPENDENT);
2772 }
2773 }
2774 else if (alkind_isDependent (ak) || alkind_isTemp (ak)
2775 || alkind_isOwned (ak))
2776 {
2777 ; /* okay */
2778 }
2779 else
2780 {
2781 llerror
2782 (FLG_SYNTAX,
2783 message ("Exposure qualifier %s used on %s storage (should "
2784 "be dependent): %q",
2785 qual_unparse (qel),
2786 alkind_unparse (ak),
2787 uentry_unparse (ue)));
2788 }
2789 }
2790 }
2791 else if (qual_isGlobCheck (qel))
2792 {
2793 if (uentry_isVariable (ue))
2794 {
2795 chkind ch = chkind_fromQual (qel);
2796
2797 if (ue->info->var->checked != CH_UNKNOWN)
2798 {
2799 if (ch == ue->info->var->checked)
2800 {
2801 llerror (FLG_SYNTAX,
2802 message ("Redundant %s qualifier on %q",
2803 qual_unparse (qel),
2804 uentry_getName (ue)));
2805 }
2806 else
2807 {
2808 llerror (FLG_SYNTAX,
2809 message
2810 ("Contradictory %s and %s qualifiers on %q",
2811 qual_unparse (qel),
2812 checkedName (ue->info->var->checked),
2813 uentry_getName (ue)));
2814 }
2815 }
2816
2817 ue->info->var->checked = ch;
2818 }
2819 else
2820 {
2821 llerror
2822 (FLG_SYNTAX,
2823 message ("Qualifier %s used with non-variable",
2824 qual_unparse (qel)));
2825 }
2826 }
2827 else if (qual_isReturned (qel))
2828 {
2829 if (uentry_isVariable (ue))
2830 {
2831 ue->info->var->kind = VKRETPARAM;
2832 }
2833 else
2834 {
2835 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-variable",
2836 qual_unparse (qel)));
2837 }
2838 }
2839 else
2840 {
2841 uentry_reflectOtherQualifier (ue, qel);
2842 }
2843
2844 sRef_storeState (ue->sref);
2845 } end_qualList_elements;
2846
2847 qualList_clear (q);
ccf0a4a8 2848
2849 DPRINTF (("Done: %s", sRef_unparseFull (ue->sref)));
616915dd 2850}
2851
2852bool
2853uentry_isOnly (uentry ue)
2854{
2855 return (!uentry_isUndefined (ue)
2856 && uentry_isVariable (ue)
2857 && alkind_isOnly (sRef_getOrigAliasKind (ue->sref)));
2858}
2859
2860static void
2861uentry_setAliasKind (/*@notnull@*/ uentry ue, alkind ak)
2862{
2863 sRef_setAliasKind (ue->sref, ak, uentry_whereDeclared (ue));
2864 sRef_setOrigAliasKind (ue->sref, ak);
2865}
2866
2867static void
2868uentry_setNullState (/*@notnull@*/ uentry ue, nstate ns)
2869{
2870 if (uentry_isVariable (ue))
2871 {
2872 ue->info->var->nullstate = ns;
2873 }
2874
2875 sRef_setNullState (ue->sref, ns, uentry_whereDeclared (ue));
2876}
2877
2878bool
2879uentry_isUnique (uentry ue)
2880{
2881 return (!uentry_isUndefined (ue)
2882 && uentry_isVariable (ue)
2883 && alkind_isUnique (sRef_getOrigAliasKind (ue->sref)));
2884}
2885
2886bool
2887uentry_isFileStatic (uentry ue)
2888{
2889 return (uentry_isStatic (ue)
2890 && (!uentry_isVariable (ue)
2891 || sRef_isFileStatic (uentry_getSref (ue))));
2892}
2893
2894bool
2895uentry_isExported (uentry ue)
2896{
2897 if (uentry_isValid (ue))
2898 {
2899 if (uentry_isVariable (ue))
2900 {
2901 return (sRef_isRealGlobal (uentry_getSref (ue)));
2902 }
2903 else
2904 {
2905 return !uentry_isStatic (ue);
2906 }
2907 }
2908
2909 return FALSE;
2910}
2911
2912bool
2913uentry_isNonLocal (uentry ue)
2914{
2915 return (uentry_isValid (ue) && uentry_isVariable (ue)
28bf4b0b 2916 && (sRef_isFileOrGlobalScope (ue->sref) || uentry_isStatic (ue)));
2917}
2918
2919bool
2920uentry_isGlobalVariable (uentry ue)
2921{
2922 return (uentry_isValid (ue) && uentry_isVariable (ue)
2923 && sRef_isFileOrGlobalScope (ue->sref));
616915dd 2924}
2925
2926bool
28bf4b0b 2927uentry_isVisibleExternally (uentry ue)
616915dd 2928{
28bf4b0b 2929 return (uentry_isValid (ue)
2930 && ((uentry_isVariable (ue) && sRef_isRealGlobal (ue->sref))
2931 || (!uentry_isStatic (ue)
2932 && (uentry_isFunction (ue)
2933 || uentry_isIter (ue)
2934 || uentry_isEndIter (ue)
2935 || uentry_isConstant (ue)
2936 || uentry_isDatatype (ue)
2937 || uentry_isAnyTag (ue)))));
616915dd 2938}
2939
2940bool
2941uentry_isPrintfLike (uentry ue)
2942{
2943 return (uentry_isFunction (ue)
2944 && (ue->info->fcn->specialCode == SPC_PRINTFLIKE));
2945}
2946
2947bool
2948uentry_isScanfLike (uentry ue)
2949{
2950 return (uentry_isFunction (ue)
2951 && (ue->info->fcn->specialCode == SPC_SCANFLIKE));
2952}
2953
2954bool
2955uentry_isMessageLike (uentry ue)
2956{
2957 return (uentry_isFunction (ue)
2958 && (ue->info->fcn->specialCode == SPC_MESSAGELIKE));
2959}
2960
2961static void checkSpecialFunction (/*@notnull@*/ uentry ue)
2962{
2963 uentryList args = uentry_getParams (ue);
2964
2965 if (!uentryList_isMissingParams (args))
2966 {
2967 uentry last = uentry_undefined;
2968
2969 uentryList_elements (args, current)
2970 {
2971 if (uentry_isElipsisMarker (current))
2972 {
2973 if (uentry_isUndefined (last))
2974 {
2975 voptgenerror
2976 (FLG_SYNTAX,
2977 message ("Function %q is marked %s, but has no format "
2978 "string argument before elipsis",
2979 uentry_getName (ue),
2980 specCode_unparse (ue->info->fcn->specialCode)),
2981 uentry_whereLast (ue));
2982 ue->info->fcn->specialCode = SPC_NONE;
2983 }
2984 else
2985 {
2986 ctype rt = ctype_realType (uentry_getType (last));
2987
2988 if (!ctype_match (rt, ctype_string))
2989 {
2990 bool okay = FALSE;
2991
2992 /* wchar_t * is okay too */
2993 if (ctype_isAP (rt))
2994 {
2995 ctype base = ctype_baseArrayPtr (rt);
2996
2997 if (ctype_isArbitraryIntegral (base))
2998 {
2999 okay = TRUE;
3000 }
3001 }
3002
3003 if (!okay)
3004 {
3005 voptgenerror
3006 (FLG_SYNTAX,
3007 message ("Function %q is marked %s, but the argument "
3008 "before the elipsis has type %s (should be char *)",
3009 uentry_getName (ue),
3010 specCode_unparse (ue->info->fcn->specialCode),
3011 ctype_unparse (uentry_getType (last))),
3012 uentry_whereLast (ue));
3013
3014 ue->info->fcn->specialCode = SPC_NONE;
3015 }
3016 }
3017 }
3018 return;
3019 }
3020 last = current;
3021 } end_uentryList_elements ;
3022
3023 voptgenerror
3024 (FLG_SYNTAX,
3025 message ("Function %q is marked %s, but has no elipsis parameter",
3026 uentry_getName (ue),
3027 specCode_unparse (ue->info->fcn->specialCode)),
3028 uentry_whereLast (ue));
3029
3030 ue->info->fcn->specialCode = SPC_NONE;
3031 }
3032}
3033
3034void
3035uentry_setPrintfLike (uentry ue)
3036{
efd360a3 3037 uentry_convertVarFunction (ue);
616915dd 3038 llassertfatal (uentry_isFunction (ue));
3039 ue->info->fcn->specialCode = SPC_PRINTFLIKE;
3040 checkSpecialFunction (ue);
3041}
3042
3043void
3044uentry_setScanfLike (uentry ue)
3045{
efd360a3 3046 uentry_convertVarFunction (ue);
616915dd 3047 llassertfatal (uentry_isFunction (ue));
3048 ue->info->fcn->specialCode = SPC_SCANFLIKE;
3049 checkSpecialFunction (ue);
3050}
3051
3052void
3053uentry_setMessageLike (uentry ue)
3054{
efd360a3 3055 uentry_convertVarFunction (ue);
616915dd 3056 llassertfatal (uentry_isFunction (ue));
3057 ue->info->fcn->specialCode = SPC_MESSAGELIKE;
3058 checkSpecialFunction (ue);
3059}
3060
3061bool
3062uentry_isSpecialFunction (uentry ue)
3063{
3064 return (uentry_isFunction (ue)
3065 && (ue->info->fcn->specialCode != SPC_NONE));
3066}
3067
3068/*@notnull@*/ uentry uentry_makeParam (idDecl t, int i)
3069{
3070 ctype ct = idDecl_getCtype (t);
3071 ctype base = ct;
6970c11b 3072 fileloc loc = setLocation ();
16c024b5 3073 sRef pref = sRef_makeParam (i, ct, stateInfo_makeLoc (loc, SA_CREATED));
6970c11b 3074 uentry ue = uentry_makeVariableSrefParam (idDecl_observeId (t), ct, loc, pref);
616915dd 3075
6970c11b 3076 DPRINTF (("Make param: %s", uentry_unparseFull (ue)));
c09ebffe 3077 DPRINTF (("Base: %s [%d]", ctype_unparse (base), ctype_isFixedArray (base)));
616915dd 3078 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3079 uentry_implicitParamAnnots (ue);
3080
c09ebffe 3081 /* Parameter type [][] or [x][] is invalid, but [][x] is okay */
616915dd 3082
c09ebffe 3083 while (ctype_isFixedArray (base))
3084 {
3085 base = ctype_baseArrayPtr (base);
3086 }
616915dd 3087
c09ebffe 3088 DPRINTF (("Base: %s", ctype_unparse (base)));
3089
3090 if (ctype_isIncompleteArray (base))
3091 {
3092 base = ctype_baseArrayPtr (base);
3093 DPRINTF (("Base: %s", ctype_unparse (base)));
3094 if (ctype_isArray (base))
3095 {
3096 if (!uentry_hasName (ue))
3097 {
3098 voptgenerror
3099 (FLG_INCOMPLETETYPE,
3100 message ("Unnamed function parameter %d is incomplete type (inner array must have bounds): %s",
3101 i + 1,
3102 ctype_unparse (ct)),
3103 uentry_whereLast (ue));
3104 }
3105 else
3106 {
3107 voptgenerror
3108 (FLG_INCOMPLETETYPE,
3109 message ("Function parameter %q is incomplete type (inner array must have bounds): %s",
3110 uentry_getName (ue),
3111 ctype_unparse (ct)),
3112 uentry_whereLast (ue));
3113 }
3114 }
616915dd 3115 }
c09ebffe 3116
28bf4b0b 3117 DPRINTF (("Param: %s", uentry_unparseFull (ue)));
616915dd 3118 return ue;
3119}
3120
3121/*@only@*/ /*@notnull@*/ uentry uentry_makeIdVariable (idDecl t)
3122{
3123 ctype ct = idDecl_getCtype (t);
3124
3125 if (ctype_isFunction (ct))
3126 {
3127 return (uentry_makeIdFunction (t));
3128 }
3129 else
3130 {
3131 fileloc loc = setLocation ();
3132 uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
37ae0b5e 3133
616915dd 3134 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3135
3136 if (!uentry_isExtern (ue))
3137 {
3138 uentry_setDefined (ue, loc);
3139 }
3140
3141 return ue;
3142 }
3143}
3144
6970c11b 3145/*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t, fileloc loc)
616915dd 3146{
6970c11b 3147 return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), fileloc_copy (loc), SS_DEFINED));
616915dd 3148}
616915dd 3149
3150/*
3151** constants
3152*/
3153
5e211f69 3154static /*@only@*/ /*@notnull@*/
616915dd 3155uentry uentry_makeConstantAux (cstring n, ctype t,
5e211f69 3156 /*@keep@*/ fileloc f, bool priv, bool macro,
616915dd 3157 /*@only@*/ multiVal m)
3158{
3159 uentry e = uentry_alloc ();
3160
3161 e->ukind = KCONST;
3162 e->uname = cstring_copy (n);
3163 e->utype = t;
3164 e->storageclass = SCNONE;
3165
b73d1009 3166 e->warn = warnClause_undefined; /* Don't support warnings for constants */
28bf4b0b 3167
616915dd 3168 e->sref = sRef_makeConst (t);
3169
3170 e->lset = FALSE;
3171 e->used = FALSE;
3172
3173 e->uses = filelocList_new ();
3174 e->isPrivate = priv;
3175 e->hasNameError = FALSE;
3176
3177 e->info = (uinfo) dmalloc (sizeof (*e->info));
3178 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
616915dd 3179 e->info->uconst->access = typeIdSet_undefined;
5e211f69 3180 e->info->uconst->macro = macro;
616915dd 3181
3182 uentry_setSpecDef (e, f);
3183
3184 if (multiVal_isInt (m) && (multiVal_forceInt (m) == 0))
3185 {
3186 sRef_setDefNull (e->sref, uentry_whereDeclared (e));
3187 }
3188
b9904f57 3189 uentry_setConstantValue (e, m);
3190
616915dd 3191 return (e);
3192}
3193
3194/*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
3195{
02b84d4b 3196 uentry ue = uentry_makeConstantAux (n, t, f, FALSE, FALSE, multiVal_unknown ());
3197 return ue;
5e211f69 3198}
3199
3e3ec469 3200/*@notnull@*/ uentry uentry_makeConstantValue (cstring n, ctype t, fileloc f, bool priv, multiVal val)
5e211f69 3201{
02b84d4b 3202 uentry ue = uentry_makeConstantAux (n, t, f, priv, FALSE, val);
3203 return ue;
5e211f69 3204}
3205
3206/*@notnull@*/ uentry uentry_makeMacroConstant (cstring n, ctype t, fileloc f)
3207{
02b84d4b 3208 uentry ue = uentry_makeConstantAux (n, t, f, FALSE, TRUE, multiVal_unknown ());
3209 return ue;
616915dd 3210}
3211
3212/*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
3213{
3214 uentry ue = uentry_makeConstant (idDecl_observeId (t),
3215 idDecl_getCtype (t),
3216 fileloc_undefined);
3217
3218 llassert (fileloc_isUndefined (ue->whereDeclared));
3219 ue->whereDeclared = setLocation ();
616915dd 3220 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3221
b9904f57 3222 DPRINTF (("Constant: %s", uentry_unparseFull (ue)));
7534721d 3223 DPRINTF (("Value: %s", multiVal_unparse (uentry_getConstantValue (ue))));
616915dd 3224 return ue;
3225}
3226
3227/*
3228** variables
3229*/
3230
3231void uentry_setDefState (uentry ue, sstate defstate)
3232{
3233 if (uentry_isValid (ue))
3234 {
3235 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
3236
3237 if (uentry_isVariable (ue))
3238 {
3239 ue->info->var->defstate = defstate; /* evs 2000-05-17: fixed bug, was SS_DEFINED! */
3240 }
3241 }
3242}
3243
3244bool uentry_isCheckedUnknown (uentry ue)
3245{
3246 return (uentry_isVar (ue)
3247 && (ue->info->var->checked == CH_UNKNOWN));
3248}
3249
3250bool uentry_isCheckMod (uentry ue)
3251{
3252 return (uentry_isVar (ue)
3253 && (ue->info->var->checked == CH_CHECKMOD));
3254}
3255
3256bool uentry_isUnchecked (uentry ue)
3257{
3258 return (uentry_isVar (ue)
3259 && (ue->info->var->checked == CH_UNCHECKED));
3260}
3261
3262bool uentry_isChecked (uentry ue)
3263{
3264 return (uentry_isVar (ue)
3265 && (ue->info->var->checked == CH_CHECKED));
3266}
3267
3268bool uentry_isCheckedModify (uentry ue)
3269{
3270 return (uentry_isVar (ue)
3271 && (ue->info->var->checked == CH_CHECKED
3272 || ue->info->var->checked == CH_CHECKMOD
3273 || ue->info->var->checked == CH_CHECKEDSTRICT));
3274}
3275
3276bool uentry_isCheckedStrict (uentry ue)
3277{
3278 return (uentry_isVar (ue)
3279 && (ue->info->var->checked == CH_CHECKEDSTRICT));
3280}
3281
3282void uentry_setUnchecked (uentry ue)
3283{
3284 llassert (uentry_isVar (ue));
3285
3286 ue->info->var->checked = CH_UNCHECKED;
3287}
3288
3289void uentry_setChecked (uentry ue)
3290{
3291 llassert (uentry_isVar (ue));
3292
3293 ue->info->var->checked = CH_CHECKED;
3294}
3295
3296void uentry_setCheckMod (uentry ue)
3297{
3298 llassert (uentry_isVar (ue));
3299
3300 ue->info->var->checked = CH_CHECKMOD;
3301}
3302
3303void uentry_setCheckedStrict (uentry ue)
3304{
3305 llassert (uentry_isVar (ue));
3306
3307 ue->info->var->checked = CH_CHECKEDSTRICT;
3308}
3309
3310static /*@only@*/ /*@notnull@*/
abd7f895 3311uentry uentry_makeVariableAux (cstring n, ctype t,
3312 fileloc f,
3313 /*@exposed@*/ sRef s,
3314 bool priv, vkind kind)
616915dd 3315{
3316 uentry e = uentry_alloc ();
3317 ctype rt = t;
abd7f895 3318
616915dd 3319 DPRINTF (("Make variable: %s %s %s", n, ctype_unparse (t), sRef_unparse (s)));
3320
3321 e->ukind = KVAR;
3322 e->uname = cstring_copy (n);
3323 e->utype = t;
3324
3325 e->storageclass = SCNONE;
3326
b73d1009 3327 e->warn = warnClause_undefined; /* Don't support warnings for variables yet @*/
28bf4b0b 3328
616915dd 3329 e->sref = s;
3330
3331 e->used = FALSE;
3332 e->lset = FALSE;
3333
3334 e->uses = filelocList_new ();
3335 e->isPrivate = priv;
3336 e->hasNameError = FALSE;
3337
3338 e->info = (uinfo) dmalloc (sizeof (*e->info));
3339 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
3340 e->info->var->kind = kind;
3341
b73d1009 3342 /* removed: e->info->var->origsref = sRef_saveCopy (e->sref); */
616915dd 3343 e->info->var->checked = CH_UNKNOWN;
3344
28bf4b0b 3345 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
616915dd 3346 uentry_setSpecDef (e, f);
28bf4b0b 3347 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
616915dd 3348
3349 if (ctype_isFunction (rt))
3350 {
28bf4b0b 3351 rt = ctype_getReturnType (rt);
616915dd 3352 }
3353
3354 if (ctype_isUA (rt))
3355 {
28bf4b0b 3356 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
616915dd 3357 sRef_setStateFromType (e->sref, rt);
3358 }
3359
28bf4b0b 3360 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
616915dd 3361 e->info->var->defstate = sRef_getDefState (e->sref);
3362 e->info->var->nullstate = sRef_getNullState (e->sref);
3363
6970c11b 3364 /* start modifications */
3365 /* This function sets the uentry for a pointer or array variable declaration,
3366 it allocates memory and sets the fields. We check if the type of the variable
3367 is a pointer or array and allocate a `bbufinfo' struct accordingly */
3368
abd7f895 3369 if (ctype_isArray (t) || ctype_isPointer(t))
3370 {
b73d1009 3371 e->info->var->bufinfo = dmalloc (sizeof (*e->info->var->bufinfo));
abd7f895 3372 e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
3373 sRef_setNotNullTerminatedState (s);
3374 }
3375 else
3376 {
3377 e->info->var->bufinfo = NULL;
3378 }/* end else */
3379 /* end modification */
616915dd 3380
3381 return (e);
3382}
3383
3384bool
3385uentry_isYield (uentry ue)
3386{
3387 return (uentry_isVariable (ue)
3388 && (ue->info->var->kind == VKYIELDPARAM
3389 || ue->info->var->kind == VKREFYIELDPARAM));
3390}
3391
3392static bool
3393uentry_isRefsField (uentry ue)
3394{
3395 return (uentry_isVariable (ue) && sRef_isRefsField (ue->sref));
3396}
3397
3398/*@only@*/ /*@notnull@*/
3399uentry uentry_makeVariable (cstring n, ctype t, fileloc f, bool isPriv)
3400{
3401 return (uentry_makeVariableAux (n, t, f, sRef_makeType (t), isPriv,
3402 fileloc_isSpec (f) ? VKSPEC : VKNORMAL));
3403}
3404
3405/*
3406** functions
3407*/
3408
3409void uentry_makeVarFunction (uentry ue)
3410{
3411 alkind ak;
3412 exkind ek;
3413 uvinfo oldInfo;
3414 fileloc loc;
3415
3416 llassert (uentry_isValid (ue));
3417 llassert (!sRef_modInFunction ());
3418
3419 ak = sRef_getOrigAliasKind (ue->sref);
3420 ek = sRef_getOrigExKind (ue->sref);
3421
b072092f 3422 llassert (uentry_isVariable (ue));
616915dd 3423 oldInfo = ue->info->var;
3424
ac35a6ab 3425 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
3426 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ctype_realType (ue->utype)));
616915dd 3427
3428 /*
ac35a6ab 3429 ** expanded macro is marked used
616915dd 3430 */
3431
efd360a3 3432 ue->used = ue->used || (oldInfo->kind == VKEXPMACRO);
616915dd 3433
3434 ue->ukind = KFCN;
3435 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3436 ue->info->fcn->exitCode = XK_UNKNOWN;
28bf4b0b 3437 ue->info->fcn->nullPred = qual_createUnknown ();
616915dd 3438 ue->info->fcn->specialCode = SPC_NONE;
3439 ue->info->fcn->access = typeIdSet_undefined;
3440 ue->info->fcn->hasGlobs = FALSE;
3441 ue->info->fcn->globs = globSet_undefined;
3442 ue->info->fcn->hasMods = FALSE;
3443 ue->info->fcn->mods = sRefSet_undefined;
3444 ue->info->fcn->specclauses = NULL;
3445 ue->info->fcn->defparams = uentryList_undefined;
3446
3447 /*drl*/
3814599d 3448 ue->info->fcn->preconditions = functionConstraint_undefined;
616915dd 3449 /*end */
3450
3451 /*drl 12/28/2000*/
efd360a3 3452 ue->info->fcn->postconditions = functionConstraint_undefined;
616915dd 3453 /*end */
616915dd 3454
3455 if (ctype_isFunction (ue->utype))
3456 {
28bf4b0b 3457 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
616915dd 3458 }
3459 else
3460 {
3461 ue->sref = sRef_makeType (ctype_unknown);
3462 }
3463
3464 if (sRef_isRefCounted (ue->sref))
3465 {
3466 ak = AK_NEWREF;
3467 }
3468 else
3469 {
3470 if (alkind_isUnknown (ak))
3471 {
3472 if (exkind_isKnown (ek))
3473 {
28bf4b0b 3474 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
616915dd 3475 ak = AK_IMPDEPENDENT;
3476 }
3477 else
3478 {
3479 if (context_getFlag (FLG_RETIMPONLY))
3480 {
3481 if (ctype_isFunction (ue->utype)
3482 && ctype_isVisiblySharable
28bf4b0b 3483 (ctype_realType (ctype_getReturnType (ue->utype))))
616915dd 3484 {
3485 if (uentryList_hasReturned (uentry_getParams (ue)))
3486 {
3487 ;
3488 }
3489 else
3490 {
28bf4b0b 3491 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3492 {
3493 ;
3494 }
3495 else
3496 {
3497 ak = AK_IMPONLY;
3498 }
3499 }
616915dd 3500 }
3501 }
3502 }
3503 }
3504 }
3505
3506 loc = ue->whereDeclared;
3507
3508 sRef_setAliasKind (ue->sref, ak, loc);
3509 sRef_setNullState (ue->sref, oldInfo->nullstate, loc);
3510 sRef_setDefState (ue->sref, oldInfo->defstate, loc);
3511 sRef_setExKind (ue->sref, ek, loc);
3512
3513 if (oldInfo->kind == VKEXPMACRO)
3514 {
efd360a3 3515 ;
616915dd 3516 }
3517 else
3518 {
3519 fileloc_free (ue->whereDefined);
3520 ue->whereDefined = fileloc_undefined;
3521 }
3522
3523 uvinfo_free (oldInfo);
3524}
3525
b072092f 3526void uentry_makeConstantFunction (uentry ue)
3527{
3528 alkind ak;
3529 exkind ek;
3530 ucinfo oldInfo;
3531 fileloc loc;
3532
3533 llassert (uentry_isValid (ue));
3534 llassert (!sRef_modInFunction ());
3535
3536 ak = sRef_getOrigAliasKind (ue->sref);
3537 ek = sRef_getOrigExKind (ue->sref);
3538
3539 llassert (uentry_isConstant (ue));
3540 oldInfo = ue->info->uconst;
3541
3542 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
3543
3544 /*
3545 ** expanded macro is marked used (until I write a pre-processor)
3546 */
3547
3548 ue->ukind = KFCN;
3549 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3550 ue->info->fcn->exitCode = XK_UNKNOWN;
3551 ue->info->fcn->nullPred = qual_createUnknown ();
3552 ue->info->fcn->specialCode = SPC_NONE;
3553 ue->info->fcn->access = typeIdSet_undefined;
3554 ue->info->fcn->hasGlobs = FALSE;
3555 ue->info->fcn->globs = globSet_undefined;
3556 ue->info->fcn->hasMods = FALSE;
3557 ue->info->fcn->mods = sRefSet_undefined;
3558 ue->info->fcn->specclauses = NULL;
3559 ue->info->fcn->defparams = uentryList_undefined;
3560
3561 /*drl*/
3562 ue->info->fcn->preconditions = functionConstraint_undefined;
3563 /*end */
3564
3565 /*drl 12/28/2000*/
3566 ue->info->fcn->postconditions = functionConstraint_undefined;
3567 /*end */
3568
3569
3570 if (ctype_isFunction (ue->utype))
3571 {
3572 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3573 }
3574 else
3575 {
3576 ue->sref = sRef_makeType (ctype_unknown);
3577 }
3578
3579 if (sRef_isRefCounted (ue->sref))
3580 {
3581 ak = AK_NEWREF;
3582 }
3583 else
3584 {
3585 if (alkind_isUnknown (ak))
3586 {
3587 if (exkind_isKnown (ek))
3588 {
3589 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3590 ak = AK_IMPDEPENDENT;
3591 }
3592 else
3593 {
3594 if (context_getFlag (FLG_RETIMPONLY))
3595 {
3596 if (ctype_isFunction (ue->utype)
3597 && ctype_isVisiblySharable
3598 (ctype_realType (ctype_getReturnType (ue->utype))))
3599 {
3600 if (uentryList_hasReturned (uentry_getParams (ue)))
3601 {
3602 ;
3603 }
3604 else
3605 {
3606 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3607 {
3608 ;
3609 }
3610 else
3611 {
3612 ak = AK_IMPONLY;
3613 }
3614 }
3615 }
3616 }
3617 }
3618 }
3619 }
3620
3621 loc = ue->whereDeclared;
3622
3623 sRef_setAliasKind (ue->sref, ak, loc);
3624 sRef_setExKind (ue->sref, ek, loc);
3625
3626 fileloc_free (ue->whereDefined);
3627 ue->whereDefined = fileloc_undefined;
3628 ucinfo_free (oldInfo);
3629}
3630
616915dd 3631void
b87215ab 3632uentry_setGlobals (uentry ue, /*@only@*/ globSet globs)
616915dd 3633{
3634 llassert (uentry_isValid (ue));
3635
b87215ab 3636 globSet_markImmutable (globs);
3637
616915dd 3638 if (uentry_isIter (ue))
3639 {
b87215ab 3640 ue->info->iter->globs = globSet_unionFree (ue->info->iter->globs, globs);
616915dd 3641 }
3642 else
3643 {
efd360a3 3644 uentry_convertVarFunction (ue);
616915dd 3645 llassert (uentry_isFunction (ue));
616915dd 3646
b87215ab 3647 ue->info->fcn->hasGlobs = TRUE;
3648 ue->info->fcn->globs = globSet_unionFree (ue->info->fcn->globs, globs);
616915dd 3649 }
3650
3651 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3652 {
3653 ue->info->fcn->hasMods = TRUE;
3654 }
3655}
3656
3657void uentry_addAccessType (uentry ue, typeId tid)
3658{
3659 if (uentry_isFunction (ue))
3660 {
3661 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3662 }
3663 else if (uentry_isEitherConstant (ue))
3664 {
3665 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3666 }
3667 else if (uentry_isIter (ue))
3668 {
3669 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3670 }
3671 else if (uentry_isEndIter (ue))
3672 {
3673 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3674 }
3675 else
3676 {
3677 llbug (message ("no access for: %q", uentry_unparse (ue)));
3678 }
3679}
3680
3681/*@only@*/ /*@notnull@*/ uentry
3682 uentry_makeFunction (cstring n, ctype t,
3683 typeId access,
3684 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
28bf4b0b 3685 /*@only@*/ warnClause warn,
616915dd 3686 fileloc f)
3687{
b73d1009 3688 llassert (warnClause_isUndefined (warn));
616915dd 3689 return (uentry_makeFunctionAux (n, t,
3690 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3691 : typeIdSet_single (access)),
28bf4b0b 3692 globs, mods, warn,
3693 f,
616915dd 3694 FALSE, FALSE));
3695}
3696
616915dd 3697/*@notnull@*/ uentry
3698 uentry_makePrivFunction2 (cstring n, ctype t,
3699 typeIdSet access,
3700 globSet globs, sRefSet mods,
3701 fileloc f)
3702{
28bf4b0b 3703 return (uentry_makeFunctionAux (n, t, access, globs, mods, warnClause_undefined,
3704 f, TRUE, FALSE));
616915dd 3705}
3706
3707
3708/*@notnull@*/ uentry
3709 uentry_makeSpecFunction (cstring n, ctype t,
3710 typeIdSet access,
3711 /*@only@*/ globSet globs,
3712 /*@only@*/ sRefSet mods,
3713 fileloc f)
3714{
3715 uentry ue = uentry_makeFunctionAux (n, t, access,
28bf4b0b 3716 globs, mods, warnClause_undefined,
3717 f, FALSE, FALSE);
616915dd 3718
3719 uentry_setHasGlobs (ue);
3720 uentry_setHasMods (ue);
3721
3722 reflectImplicitFunctionQualifiers (ue, TRUE);
3723 return (ue);
3724}
616915dd 3725
3726uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3727{
3728 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3729 sRef_undefined, FALSE, VKEXPMACRO);
3730
3731 uentry_setDefined (ue, f);
3732 return ue;
3733}
3734
3735/*@notnull@*/ /*@notnull@*/ uentry
3736 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3737{
3738 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3739 typeIdSet_singleOpt (access),
3740 globSet_undefined, sRefSet_undefined,
28bf4b0b 3741 warnClause_undefined,
616915dd 3742 fileloc_undefined,
3743 FALSE, TRUE);
3744
3745 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3746 return ue;
3747}
3748
3749bool uentry_isForward (uentry e)
3750{
3751 if (uentry_isValid (e))
3752 {
3753 ctype ct = uentry_getType (e);
3754
3755 return (ctype_isUnknown (ct)
3756 || (ctype_isFunction (ct)
28bf4b0b 3757 && ctype_isUnknown (ctype_getReturnType (ct))));
616915dd 3758 }
3759
3760 return FALSE;
3761}
3762
616915dd 3763/*@notnull@*/ uentry
3764uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3765{
3766 return (uentry_makeFunctionAux (n, ctype_unknown, access,
28bf4b0b 3767 globSet_undefined, sRefSet_undefined, warnClause_undefined,
3768 f,FALSE, TRUE));
616915dd 3769}
3770
3771/*@notnull@*/ uentry
3772uentry_makeUnspecFunction (cstring n, ctype t,
3773 typeIdSet access,
3774 fileloc f)
3775{
28bf4b0b 3776 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_undefined,
3777 sRefSet_undefined, warnClause_undefined,
3778 f, FALSE, TRUE);
616915dd 3779
3780 reflectImplicitFunctionQualifiers (ue, TRUE);
3781 return ue;
3782}
616915dd 3783
3784/*
3785** datatypes
3786*/
3787
3788/* is exported for use by usymtab_interface */
3789
3790/*@notnull@*/ uentry
e5081f8c 3791 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, qual abstract,
616915dd 3792 fileloc f, bool priv)
3793{
3794 uentry e = uentry_alloc ();
3795
3796 DPRINTF (("Make datatype: %s / %s",
3797 n, ctype_unparse (t)));
3798
3799 /* e->shallowCopy = FALSE; */
3800 e->ukind = KDATATYPE;
3801 e->uname = cstring_copy (n);
3802 e->utype = t;
3803 e->storageclass = SCNONE;
3804 e->sref = sRef_makeUnknown ();
3805
3806 if (ctype_isUA (t))
3807 {
3808 sRef_setStateFromType (e->sref, t);
3809 }
3810
3811 uentry_setSpecDef (e, f);
3812
b73d1009 3813 e->warn = warnClause_undefined;
616915dd 3814 e->uses = filelocList_new ();
3815 e->isPrivate = priv;
3816 e->hasNameError = FALSE;
3817
3818 e->used = FALSE;
3819 e->lset = FALSE;
3820
3821 e->info = (uinfo) dmalloc (sizeof (*e->info));
3822 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
28bf4b0b 3823 e->info->datatype->abs = abstract;
616915dd 3824 e->info->datatype->mut = mut;
3825 e->info->datatype->type = ctype_undefined;
3826
3827 if (uentry_isDeclared (e))
3828 {
3829 uentry_setDefined (e, f);
3830 }
3831
e5081f8c 3832 if (qual_isAbstract (abstract) && !(uentry_isCodeDefined (e)))
616915dd 3833 {
3834 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3835 }
3836
3837 return (e);
3838}
3839
3840/*@notnull@*/ uentry
e5081f8c 3841 uentry_makeDatatype (cstring n, ctype t, ynm mut, qual abstract, fileloc f)
616915dd 3842{
28bf4b0b 3843 return (uentry_makeDatatypeAux (n, t, mut, abstract, f, FALSE));
616915dd 3844}
3845
e5081f8c 3846/*@notnull@*/ uentry uentry_makeBoolDatatype (qual abstract)
616915dd 3847{
3848 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
28bf4b0b 3849 ctype_bool, NO, abstract,
616915dd 3850 fileloc_getBuiltin (),
3851 FALSE);
3852
3853 ret->info->datatype->type = ctype_bool;
3854 return ret;
3855}
3856
3857/*
3858** iters
3859*/
3860
3861static /*@only@*/ /*@notnull@*/ uentry
3862 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3863 /*@only@*/ fileloc f)
3864{
3865 uentry e = uentry_alloc ();
3866
3867 e->ukind = KITER;
3868 e->uname = cstring_copy (n);
3869 e->utype = ct;
3870 e->sref = sRef_makeUnknown ();
3871 e->storageclass = SCNONE;
3872 e->used = FALSE;
3873 e->lset = FALSE;
3874
3875 uentry_setSpecDef (e, f);
3876
b73d1009 3877 e->warn = warnClause_undefined;
616915dd 3878 e->uses = filelocList_new ();
3879 e->isPrivate = FALSE;
3880 e->hasNameError = FALSE;
3881
3882 e->info = (uinfo) dmalloc (sizeof (*e->info));
3883 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3884 e->info->iter->access = access;
3885 e->info->iter->mods = sRefSet_undefined;
3886 e->info->iter->globs = globSet_undefined;
3887
3888 uentry_checkIterArgs (e);
3889 return (e);
3890}
3891
3892/*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3893{
3894 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3895}
3896
3897static /*@notnull@*/ uentry
3898uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3899{
3900 uentry e = uentry_alloc ();
3901
3902 /* e->shallowCopy = FALSE; */
3903 e->ukind = KENDITER;
3904 e->storageclass = SCNONE;
3905 e->uname = message ("end_%s", n);
3906 e->utype = ctype_unknown;
3907 e->sref = sRef_makeUnknown ();
3908
3909 uentry_setSpecDef (e, f);
3910
3911 e->used = FALSE;
3912 e->lset = FALSE;
3913
3914 e->uses = filelocList_new ();
3915 e->isPrivate = FALSE;
3916 e->hasNameError = FALSE;
3917
3918 e->info = (uinfo) dmalloc (sizeof (*e->info));
3919 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3920
3921 e->info->enditer->access = access;
b73d1009 3922 e->warn = warnClause_undefined;
616915dd 3923
3924 return (e);
3925}
3926
3927/*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3928{
3929 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3930}
3931
3932/*
3933** tags
3934*/
3935
3936static /*@only@*/ /*@notnull@*/ uentry
3937 uentry_makeTagAux (cstring n, ctype t,
3938 /*@only@*/ fileloc fl,
3939 bool priv, ekind kind)
3940{
3941 uentry e = uentry_alloc ();
3942
3943 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3944 {
3945 llbuglit ("uentry_makeTagAux: not a tag type");
3946 }
3947
3948 e->ukind = kind;
3949 /* e->shallowCopy = FALSE; */
3950 e->uname = cstring_copy (n);
3951
3952 e->utype = t;
3953 e->sref = sRef_makeUnknown ();
3954 e->storageclass = SCNONE;
3955
3956 uentry_setSpecDef (e, fl);
3957
3958 e->used = FALSE;
3959 e->lset = FALSE;
3960
3961 e->uses = filelocList_new ();
3962 e->isPrivate = priv;
3963 e->hasNameError = FALSE;
3964
3965 e->info = (uinfo) dmalloc (sizeof (*e->info));
3966 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
e5081f8c 3967 e->info->datatype->abs = qual_createUnknown ();
616915dd 3968 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3969 e->info->datatype->type = t;
b73d1009 3970 e->warn = warnClause_undefined;
616915dd 3971
3972 if (uentry_isDeclared (e))
3973 {
3974 uentry_setDefined (e, fl);
3975 }
3976
3977 return (e);
3978}
3979
3980uentry uentry_makeStructTagLoc (cstring n, ctype t)
3981{
3982 cstring sname = makeStruct (n);
3983 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3984
3985 cstring_free (sname);
3986 return (ret);
3987}
3988
3989/*@only@*/ uentry
3990uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3991{
3992 cstring sname = makeStruct (n);
3993 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3994
3995 cstring_free (sname);
3996 return ret;
3997}
3998
3999/*@only@*/ uentry
4000uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
4001{
4002 cstring uname = makeUnion (n);
4003 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
4004
4005 cstring_free (uname);
4006 return (ret);
4007}
4008
616915dd 4009uentry
4010uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
4011{
4012 cstring ename = makeEnum (n);
4013 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
4014
4015 cstring_free (ename);
4016 return ret;
4017}
616915dd 4018
4019uentry
4020uentry_makeUnionTagLoc (cstring n, ctype t)
4021{
4022 cstring uname = makeUnion (n);
4023 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
4024
4025 cstring_free (uname);
4026 return ret;
4027}
4028
4029uentry
4030uentry_makeEnumTagLoc (cstring n, ctype t)
4031{
4032 cstring ename = makeEnum (n);
4033 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
4034
4035 cstring_free (ename);
4036 return ret;
4037}
4038
4039bool
4040uentry_isStructTag (uentry ue)
4041{
4042 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
4043}
4044
4045bool
4046uentry_isUnionTag (uentry ue)
4047{
4048 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
4049}
4050
4051bool
4052uentry_isEnumTag (uentry ue)
4053{
4054 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
4055}
4056
4057bool
4058uentry_isAnyTag (uentry ue)
4059{
4060 return (uentry_isStructTag (ue)
4061 || uentry_isUnionTag (ue)
4062 || uentry_isEnumTag (ue));
4063}
4064
4065static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
4066
4067extern void uentry_destroyMod (void)
4068 /*@globals killed emarker@*/ /*@modifies emarker@*/
4069{
4070 static bool wasDestroyed = FALSE;
4071
4072 llassert (!wasDestroyed);
4073
4074 if (emarker != NULL)
4075 {
4076 uentry_reallyFree (emarker);
4077 }
4078
4079 wasDestroyed = TRUE;
4080}
4081
4082uentry
4083uentry_makeElipsisMarker (void)
4084{
4085 if (emarker == NULL)
4086 {
4087 emarker = uentry_alloc ();
4088
4089 emarker->ukind = KELIPSMARKER;
4090 emarker->uname = cstring_makeLiteral ("...");
4091 emarker->utype = ctype_elipsMarker;
4092 emarker->sref = sRef_undefined;
4093 emarker->storageclass = SCNONE;
4094 emarker->used = FALSE;
4095 emarker->lset = FALSE;
4096 emarker->info = NULL;
4097
4098 uentry_setSpecDef (emarker, fileloc_undefined);
4099 emarker->uses = filelocList_new ();
4100 emarker->isPrivate = FALSE;
4101 emarker->hasNameError = FALSE;
4102 }
4103
4104 /*@ignore@*/ return (emarker); /*@end@*/
4105}
4106
4107/*
4108** comparisons
4109*/
4110
4111bool
4112uentry_equiv (uentry p1, uentry p2)
4113{
4114 if (uentry_compare (p1, p2) != 0)
4115 {
4116 return FALSE;
4117 }
4118 else
4119 {
4120 return TRUE;
4121 }
4122}
4123
4124int
4125uentry_xcomparealpha (uentry *p1, uentry *p2)
4126{
4127 int res;
4128
4129 if ((res = uentry_compare (*p1, *p2)) == 0) {
4130 if ((*p1 != NULL) && (*p2 != NULL)) {
4131 res = cstring_compare ((*p1)->uname,
4132 (*p2)->uname);
4133 }
4134 }
4135
4136 return res;
4137}
4138
4139int
4140uentry_xcompareuses (uentry *p1, uentry *p2)
4141{
4142 uentry u1 = *p1;
4143 uentry u2 = *p2;
4144
4145 if (uentry_isValid (u1))
4146 {
4147 if (uentry_isValid (u2))
4148 {
4149 return (-1 * int_compare (filelocList_size (u1->uses),
4150 filelocList_size (u2->uses)));
4151 }
4152 else
4153 {
4154 return 1;
4155 }
4156 }
4157 else
4158 {
4159 if (uentry_isValid (u2))
4160 {
4161 return -1;
4162 }
4163 else
4164 {
4165 return 0;
4166 }
4167 }
4168}
4169
4170int
4171uentry_compareStrict (uentry v1, uentry v2)
4172{
4173 COMPARERETURN (uentry_compare (v1, v2));
4174
4175 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
4176 {
4177 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
4178 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
4179 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
4180 }
4181
4182 return 0;
4183}
4184
4185int
4186uentry_compare (uentry u1, uentry u2)
4187{
4188 if (u1 == u2) return 0;
4189
4190 if (uentry_isInvalid (u1)) return -1;
4191 if (uentry_isInvalid (u2)) return 1;
4192
4193 INTCOMPARERETURN (u1->ukind, u2->ukind);
4194 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
4195 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
616915dd 4196 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
4197
4198 switch (u1->ukind)
4199 {
4200 case KINVALID:
4201 case KELIPSMARKER:
1b8ae690 4202 /* bug detected by splint:
616915dd 4203 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
4204 */
4205 return 0;
4206 case KENUMCONST:
4207 case KCONST:
b9904f57 4208 return (multiVal_compare (uentry_getConstantValue (u1),
4209 uentry_getConstantValue (u2)));
616915dd 4210 case KSTRUCTTAG:
4211 case KUNIONTAG:
4212 case KENUMTAG:
4213 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
4214 case KITER:
4215 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
4216 uentry_accessType (u2)));
4217 return (uentryList_compareParams (uentry_getParams (u1),
4218 uentry_getParams (u2)));
4219 case KENDITER:
4220 return (typeIdSet_compare (uentry_accessType (u1),
4221 uentry_accessType (u2)));
4222 case KFCN:
28bf4b0b 4223 /*
4224 ** Functions are never equivalent
4225 */
4226
b7e84605 4227 if (u1 - u2 < 0) /* evans 2001-08-21: was: ((int) u1 < (int) u2), changed to remove gcc warning */
28bf4b0b 4228 {
4229 return -1;
4230 }
4231 else
4232 {
4233 return 1;
4234 }
4235 case KVAR:
4236
4237 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
4238 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
4239 sRef_getOrigAliasKind (u2->sref)));
4240 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
4241 sRef_getOrigExKind (u2->sref)));
616915dd 4242 COMPARERETURN (generic_compare (u1->info->var->checked,
4243 u2->info->var->checked));
4244 COMPARERETURN (generic_compare (u1->info->var->defstate,
4245 u2->info->var->defstate));
4246 return (generic_compare (u1->info->var->nullstate,
4247 u2->info->var->nullstate));
4248 case KDATATYPE:
4249 COMPARERETURN (ctype_compare (u1->info->datatype->type,
4250 u2->info->datatype->type));
4251 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
4252 u2->info->datatype->mut));
e5081f8c 4253 return (generic_compare (u1->info->datatype->abs, u2->info->datatype->abs));
616915dd 4254 }
4255
4256 BADEXIT;
4257}
4258
4259/*
4260** library format:
4261**
4262** all entries are: <type>[@<info>]*#<name>
4263**
4264** info depends on kind:
4265*/
4266
4267static void
4268advanceField (char **s)
4269{
28bf4b0b 4270 reader_checkChar (s, '@');
616915dd 4271}
4272
4273static void
4274advanceName (char **s)
4275{
28bf4b0b 4276 reader_checkChar (s, '#');
616915dd 4277}
4278
4279static vkind
4280vkind_fromInt (int i)
4281{
4282 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
4283 {
4284 llbuglit ("vkind_fromInt: out of range");
4285 }
4286
4287 return (vkind)i;
4288}
4289
4290static uentry
4291 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
4292 typeIdSet access, nstate nullstate,
4293 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
4294{
4295 uentry e = uentry_alloc ();
4296
4297 e->ukind = KCONST;
4298 e->uname = name;
4299 e->utype = ct;
4300 e->sref = sRef_makeConst (ct);
4301
4302 sRef_setNullState (e->sref, nullstate, loc);
4303 e->storageclass = SCNONE;
4304
4305 if (fileloc_isSpec (loc))
4306 {
4307 e->whereSpecified = loc;
4308 e->whereDeclared = fileloc_undefined;
4309 }
4310 else
4311 {
4312 e->whereSpecified = fileloc_undefined;
4313 e->whereDeclared = loc;
4314 }
4315
4316 e->whereDefined = fileloc_undefined;
4317 e->uses = filelocList_new ();
4318 e->isPrivate = FALSE;
4319 e->hasNameError = FALSE;
4320
4321 e->used = FALSE;
4322 e->lset = FALSE;
4323
b73d1009 4324 e->warn = warnClause_undefined;
28bf4b0b 4325
616915dd 4326 e->info = (uinfo) dmalloc (sizeof (*e->info));
4327 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
616915dd 4328 e->info->uconst->access = access;
b73d1009 4329 e->info->uconst->macro = FALSE; /* fix this when macro info added to library */
b9904f57 4330 uentry_setConstantValue (e, m);
616915dd 4331 sRef_storeState (e->sref);
4332
4333 return (e);
4334}
4335
4336static /*@only@*/ uentry
4337 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
4338 sstate defstate, nstate isnull, alkind aliased,
4339 exkind exp, chkind checked,
4340 /*@only@*/ fileloc loc)
4341{
4342 uentry e = uentry_alloc ();
4343
4344 e->ukind = KVAR;
4345 e->uname = name;
4346 e->utype = ct;
4347 e->storageclass = SCNONE;
4348
4349 e->sref = sRef_makeType (ct);
4350 sRef_setNullState (e->sref, isnull, loc);
4351
4352 e->whereDefined = fileloc_undefined;
4353
4354 if (fileloc_isSpec (loc))
4355 {
4356 e->whereSpecified = loc;
4357 e->whereDeclared = fileloc_undefined;
4358 }
4359 else
4360 {
4361 e->whereSpecified = fileloc_undefined;
4362 e->whereDeclared = loc;
4363 }
4364
4365 e->isPrivate = FALSE;
4366 e->hasNameError = FALSE;
4367
4368 e->used = FALSE;
4369 e->lset = FALSE;
4370
4371 e->uses = filelocList_new ();
b73d1009 4372 e->warn = warnClause_undefined;
616915dd 4373
4374 e->info = (uinfo) dmalloc (sizeof (*e->info));
4375 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
4376 e->info->var->kind = kind;
4377 e->info->var->checked = checked;
4378 e->info->var->defstate = defstate;
4379
4380 sRef_setDefState (e->sref, defstate, loc);
4381
4382 e->info->var->nullstate = sRef_getNullState (e->sref);
4383
4384 sRef_setExKind (e->sref, exp, loc);
4385 sRef_setAliasKind (e->sref, aliased, loc);
4386
4387 sRef_storeState (e->sref);
4388
4389 /*DRL ADDED 9-1-2000 */
4390 e->info->var->bufinfo = NULL;
4391
4392 return (e);
4393}
4394
4395static /*@only@*/ uentry
e5081f8c 4396uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, qual abstract,
616915dd 4397 ynm mut, ctype rtype, alkind ak, exkind exp,
4398 sstate defstate, nstate isnull,
4399 /*@only@*/ fileloc loc)
4400{
4401 uentry e = uentry_alloc ();
4402
4403 e->ukind = KDATATYPE;
4404 /* e->shallowCopy = FALSE; */
4405 e->uname = name;
4406 e->utype = ct;
4407 e->storageclass = SCNONE;
4408 e->sref = sRef_makeUnknown ();
28bf4b0b 4409 DPRINTF (("Merge null 1: %s", sRef_unparseFull (e->sref)));
616915dd 4410
4411 /*
4412 ** This is only setting null state. (I think?)
4413 */
4414
4415 if (ctype_isUA (ct))
4416 {
4417 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
4418
4419 if (uentry_isValid (te))
4420 {
4421 sRef_setStateFromUentry (e->sref, te);
4422 }
4423 else
4424 {
4425 /* problem for recursive type definitions */
4426 }
4427 }
4428
4429 sRef_setAliasKind (e->sref, ak, loc);
4430 sRef_setExKind (e->sref, exp, loc);
4431
4432 sRef_setDefState (e->sref, defstate, loc);
4433
e5081f8c 4434 if (qual_isEitherAbstract (abstract) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
616915dd 4435 {
4436 isnull = NS_ABSNULL;
4437 }
4438
28bf4b0b 4439 DPRINTF (("Merge null: %s", sRef_unparseFull (e->sref)));
616915dd 4440 sRef_mergeNullState (e->sref, isnull);
4441
4442 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
4443
4444 if (fileloc_isSpec (loc))
4445 {
4446 e->whereSpecified = loc;
4447 e->whereDeclared = fileloc_undefined;
4448 }
4449 else
4450 {
4451 e->whereSpecified = fileloc_undefined;
4452 e->whereDeclared = loc;
4453 }
4454
4455 e->isPrivate = FALSE;
4456 e->hasNameError = FALSE;
b73d1009 4457 e->warn = warnClause_undefined;
616915dd 4458 e->used = FALSE;
4459 e->lset = FALSE;
4460 e->uses = filelocList_new ();
4461
4462 e->info = (uinfo) dmalloc (sizeof (*e->info));
4463 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
28bf4b0b 4464 e->info->datatype->abs = abstract;
616915dd 4465 e->info->datatype->mut = mut;
4466 e->info->datatype->type = rtype;
28bf4b0b 4467
4468 DPRINTF (("About to store: %s", sRef_unparseFull (e->sref)));
616915dd 4469 sRef_storeState (e->sref);
28bf4b0b 4470 DPRINTF (("After store: %s", sRef_unparseFull (e->sref)));
616915dd 4471
4472 return (e);
4473}
4474
616915dd 4475static void uentry_setHasGlobs (uentry ue)
4476{
4477 llassert (uentry_isFunction (ue));
4478
4479 ue->info->fcn->hasGlobs = TRUE;
4480}
4481
4482static void uentry_setHasMods (uentry ue)
4483{
4484 llassert (uentry_isFunction (ue));
4485
4486 ue->info->fcn->hasMods = TRUE;
4487}
616915dd 4488
4489bool uentry_hasGlobs (uentry ue)
4490{
4491 if (uentry_isFunction (ue))
4492 {
4493 return (ue->info->fcn->hasGlobs);
4494 }
4495
4496 return FALSE;
4497}
4498
28bf4b0b 4499bool uentry_hasStateClauseList (uentry ue)
616915dd 4500{
28bf4b0b 4501 return (uentry_isFunction (ue) && stateClauseList_isDefined (ue->info->fcn->specclauses));
616915dd 4502}
4503
ccf0a4a8 4504bool uentry_hasConditions (uentry ue)
4505{
4506 return (uentry_isFunction (ue)
4507 && (functionConstraint_isDefined (ue->info->fcn->preconditions)
4508 || functionConstraint_isDefined (ue->info->fcn->postconditions)));
4509}
4510
28bf4b0b 4511stateClauseList uentry_getStateClauseList (uentry ue)
616915dd 4512{
28bf4b0b 4513 if (!uentry_isFunction (ue))
4514 {
4515 llassert (uentry_isFunction (ue));
4516 return stateClauseList_undefined;
4517 }
4518
4519 DPRINTF (("Get state clause list: %s", uentry_unparse (ue)));
616915dd 4520 return ue->info->fcn->specclauses;
4521}
4522
4523bool uentry_hasMods (uentry ue)
4524{
4525 if (uentry_isFunction (ue))
4526 {
4527 return (ue->info->fcn->hasMods);
4528 }
4529
4530 return FALSE;
4531}
4532
4533static uentry
4534 uentry_makeFunctionBase (/*@only@*/ cstring name, ctype ct,
4535 typeIdSet access,
4536 bool hasGlobs, /*@only@*/ globSet globs,
4537 bool hasMods, /*@only@*/ sRefSet mods,
4538 alkind ak, exkind exp,
4539 sstate defstate, nstate isnull,
4540 exitkind exitCode,
4541 specCode sCode,
4542 qual nullPred,
28bf4b0b 4543 /*@only@*/ stateClauseList specclauses,
4544 /*@only@*/ warnClause warnclause,
616915dd 4545 /*@only@*/ fileloc loc)
4546{
4547 uentry e = uentry_alloc ();
4548 ctype ret;
4549
4550 /* e->shallowCopy = FALSE; */
4551 e->ukind = KFCN;
4552 e->uname = name;
4553 e->utype = ct;
4554 e->storageclass = SCNONE;
4555
4556 if (ctype_isFunction (ct))
4557 {
28bf4b0b 4558 ret = ctype_getReturnType (ct);
616915dd 4559 }
4560 else
4561 {
4562 if (ctype_isKnown (ct))
4563 {
4564 llbug (message ("not function: %s", ctype_unparse (ct)));
4565 }
4566
4567 ret = ctype_unknown;
4568 }
4569
4570 e->sref = sRef_makeType (ret);
4571
4572 if (ctype_isUA (ret))
4573 {
4574 sRef_setStateFromType (e->sref, ret);
4575 }
4576
4577 sRef_setDefined (e->sref, loc);
4578 sRef_setNullState (e->sref, isnull, loc);
4579
4580 sRef_setAliasKind (e->sref, ak, loc);
4581 sRef_setExKind (e->sref, exp, loc);
4582 sRef_setDefState (e->sref, defstate, loc);
4583
4584 e->whereSpecified = loc;
4585 e->whereDefined = fileloc_undefined;
4586
4587 e->isPrivate = FALSE;
4588 e->hasNameError = FALSE;
4589
4590 e->used = FALSE;
4591 e->lset = FALSE;
4592 e->uses = filelocList_new ();
28bf4b0b 4593 e->warn = warnclause;
616915dd 4594
4595 e->info = (uinfo) dmalloc (sizeof (*e->info));
4596 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
4597
4598 e->info->fcn->exitCode = exitCode;
4599 e->info->fcn->specialCode = sCode;
4600 e->info->fcn->nullPred = nullPred;
4601 e->info->fcn->access = access;
4602
4603 e->info->fcn->specclauses = specclauses;
4604 e->info->fcn->hasGlobs = hasGlobs;
4605 e->info->fcn->globs = globs;
4606
4607 e->info->fcn->hasMods = hasMods;
4608 e->info->fcn->mods = mods;
4609
4610 e->info->fcn->defparams = uentryList_undefined;
4611 e->whereDeclared = fileloc_undefined;
4612
4613 sRef_storeState (e->sref);
4614
4615 /*drl 111 30 2000*/
4616 e->info->fcn->preconditions = NULL;
4617 /* end drl */
4618
4619 /*drl 12 28 2000*/
4620 e->info->fcn->postconditions = NULL;
4621 /* end drl */
4622
4623 return (e);
4624}
4625
4626static /*@only@*/ uentry
4627 uentry_makeTagBase (/*@only@*/ cstring name, ekind tagkind,
4628 ctype ct, ctype rtype, /*@only@*/ fileloc loc)
4629{
4630 uentry e = uentry_alloc ();
4631
4632 if (tagkind != KSTRUCTTAG && tagkind != KUNIONTAG && tagkind != KENUMTAG)
4633 {
4634 llbuglit ("uentry_makeTagBase: not a tag type");
4635 }
4636
4637 /* e->shallowCopy = FALSE; */
4638 e->ukind = tagkind;
4639 e->uname = name;
4640 e->utype = ct;
4641 e->sref = sRef_makeUnknown ();
4642 e->storageclass = SCNONE;
4643
4644 if (fileloc_isSpec (loc))
4645 {
4646 e->whereSpecified = loc;
4647 e->whereDeclared = fileloc_undefined;
4648 }
4649 else
4650 {
4651 e->whereDeclared = loc;
4652 e->whereSpecified = fileloc_undefined;
4653 }
4654
4655 e->whereDefined = fileloc_undefined;
4656
4657 e->isPrivate = FALSE;
4658 e->hasNameError = FALSE;
4659
4660 e->used = FALSE;
4661 e->lset = FALSE;
4662 e->uses = filelocList_new ();
b73d1009 4663 e->warn = warnClause_undefined;
616915dd 4664
4665 e->info = (uinfo) dmalloc (sizeof (*e->info));
4666 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
e5081f8c 4667 e->info->datatype->abs = qual_createUnknown ();
616915dd 4668 e->info->datatype->mut = MAYBE;
4669 e->info->datatype->type = rtype;
4670
4671 sRef_storeState (e->sref);
4672
4673 return (e);
4674}
4675
4676static uentry
4677 uentry_makeIterBase (/*@only@*/ cstring name, typeIdSet access,
4678 ctype ct, /*@only@*/ fileloc loc)
4679{
4680 uentry e = uentry_alloc ();
4681
4682 /* e->shallowCopy = FALSE; */
4683 e->ukind = KITER;
4684 e->uname = name;
4685 e->utype = ct;
4686 e->sref = sRef_makeUnknown ();
4687 e->storageclass = SCNONE;
4688
4689 if (fileloc_isSpec (loc))
4690 {
4691 e->whereSpecified = loc;
4692 e->whereDeclared = fileloc_undefined;
4693 }
4694 else
4695 {
4696 e->whereDeclared = loc;
4697 e->whereSpecified = fileloc_undefined;
4698 }
4699
4700 e->whereDefined = fileloc_undefined;
4701
4702 e->isPrivate = FALSE;
4703 e->hasNameError = FALSE;
4704
4705 e->used = FALSE;
4706 e->lset = FALSE;
4707 e->uses = filelocList_new ();
b73d1009 4708 e->warn = warnClause_undefined;
616915dd 4709
4710 e->info = (uinfo) dmalloc (sizeof (*e->info));
4711 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
4712 e->info->iter->access = access;
4713 e->info->iter->mods = sRefSet_undefined;
4714 e->info->iter->globs = globSet_undefined;
4715
4716 sRef_storeState (e->sref);
4717 return (e);
4718}
4719
4720static uentry
4721 uentry_makeEndIterBase (/*@only@*/ cstring name, typeIdSet access,
4722 /*@only@*/ fileloc loc)
4723{
4724 uentry e = uentry_alloc ();
4725
4726 /* e->shallowCopy = FALSE; */
4727 e->ukind = KENDITER;
4728 e->storageclass = SCNONE;
4729 e->uname = name;
4730 e->utype = ctype_unknown;
4731 e->sref = sRef_makeUnknown ();
4732
4733 if (fileloc_isSpec (loc))
4734 {
4735 e->whereSpecified = loc;
4736 e->whereDeclared = fileloc_undefined;
4737 }
4738 else
4739 {
4740 e->whereDeclared = loc;
4741 e->whereSpecified = fileloc_undefined;
4742 }
4743
4744 e->whereDefined = fileloc_undefined;
4745
4746 e->isPrivate = FALSE;
4747 e->hasNameError = FALSE;
4748
4749 e->used = FALSE;
4750 e->lset = FALSE;
4751 e->uses = filelocList_new ();
b73d1009 4752 e->warn = warnClause_undefined;
616915dd 4753
4754 e->info = (uinfo) dmalloc (sizeof (*e->info));
4755 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
4756 e->info->enditer->access = access;
4757 sRef_storeState (e->sref);
4758
4759 return (e);
4760}
4761
4762void uentry_markFree (/*@unused@*/ /*@owned@*/ uentry u)
4763{
4764 /* should save u */
4765/*@-mustfree@*/
4766}
4767/*@=mustfree@*/
4768
4769/*@only@*/ uentry
4770uentry_undump (ekind kind, fileloc loc, char **s)
4771{
4772 uentry ue;
4773
28bf4b0b 4774 DPRINTF (("Uentry undump: %s", *s));
4775
616915dd 4776 if (**s == '!')
4777 {
28bf4b0b 4778 reader_checkChar (s, '!');
4779 reader_checkChar (s, '.');
616915dd 4780 ue = uentry_makeElipsisMarker ();
4781 }
4782 else
4783 {
4784 ctype ct = ctype_undump (s);
4785 cstring name;
4786
4787 switch (kind)
4788 {
4789 case KVAR:
4790 {
4791 vkind tkind;
4792 sstate defstate;
4793 nstate isnull;
4794 alkind aliased;
4795 exkind exp;
4796 chkind checked;
4797
28bf4b0b 4798 reader_checkChar (s, '|');
616915dd 4799
28bf4b0b 4800 if (reader_optCheckChar (s, '@'))
616915dd 4801 {
28bf4b0b 4802 tkind = vkind_fromInt (reader_getInt (s));
4803 reader_checkChar (s, '|');
616915dd 4804 }
4805 else
4806 {
4807 tkind = VKPARAM;
4808 }
4809
28bf4b0b 4810 if (reader_optCheckChar (s, '$'))
616915dd 4811 {
4812 defstate = SS_UNKNOWN;
4813 isnull = NS_UNKNOWN;
4814 aliased = AK_IMPTEMP;
4815 exp = XO_UNKNOWN;
4816 checked = CH_UNKNOWN;
4817 }
28bf4b0b 4818 else if (reader_optCheckChar (s, '&'))
616915dd 4819 {
4820 defstate = SS_DEFINED;
4821 isnull = NS_UNKNOWN;
4822 aliased = AK_IMPTEMP;
4823 exp = XO_UNKNOWN;
4824 checked = CH_UNKNOWN;
4825 }
28bf4b0b 4826 else if (reader_optCheckChar (s, '^'))
616915dd 4827 {
4828 defstate = SS_UNKNOWN;
4829 isnull = NS_UNKNOWN;
4830 aliased = AK_IMPTEMP;
4831 exp = XO_UNKNOWN;
4832 checked = CH_UNKNOWN;
4833 }
4834 else
4835 {
28bf4b0b 4836 defstate = sstate_fromInt (reader_getInt (s));
4837 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4838 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
616915dd 4839
28bf4b0b 4840 if (reader_optCheckChar (s, '&'))
616915dd 4841 {
4842 exp = XO_UNKNOWN;
4843 checked = CH_UNKNOWN;
4844 }
4845 else
4846 {
28bf4b0b 4847 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4848 advanceField (s); checked = (chkind) (reader_getInt (s));
616915dd 4849 }
4850 }
4851
4852 advanceName (s);
28bf4b0b 4853 name = reader_getStringWord (s);
616915dd 4854
28bf4b0b 4855 llassert (!cstring_equal (name, GLOBAL_MARKER_NAME));
4856
616915dd 4857 ue = uentry_makeVariableBase (name, ct, tkind, defstate,
4858 isnull, aliased, exp,
4859 checked, fileloc_copy (loc));
4860 }
4861 break;
4862 case KDATATYPE:
4863 {
e5081f8c 4864 qual abstract;
616915dd 4865 ynm mut;
4866 ctype rtype;
4867 sstate defstate;
4868 nstate isnull;
4869 alkind aliased;
4870 exkind exp;
4871
e5081f8c 4872 advanceField (s); abstract = qual_abstractFromCodeChar (reader_loadChar (s));
28bf4b0b 4873 advanceField (s); mut = ynm_fromCodeChar (reader_loadChar (s));
4874 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4875 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4876 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4877 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
616915dd 4878 advanceField (s); rtype = ctype_undump (s);
4879 advanceName (s);
28bf4b0b 4880 name = reader_getStringWord (s);
4881 DPRINTF (("Datatype %s, Exp = %s", name, exkind_unparse (exp)));
4882 ue = uentry_makeDatatypeBase (name, ct, abstract, mut, rtype,
616915dd 4883 aliased, exp, defstate, isnull,
4884 fileloc_copy (loc));
4885 }
4886 break;
4887 case KFCN:
4888 {
4889 alkind ak;
4890 exkind exp;
4891 sstate defstate;
4892 nstate isnull;
4893 exitkind exitCode;
4894 specCode specc;
4895 qual nullPred;
4896 typeIdSet access;
4897 bool hasGlobs;
4898 globSet globs;
4899 bool hasMods;
4900 sRefSet mods;
28bf4b0b 4901 stateClauseList specclauses = stateClauseList_undefined;
4902 warnClause warnclause = warnClause_undefined;
616915dd 4903
28bf4b0b 4904 if (reader_optCheckChar (s, '$'))
616915dd 4905 {
4906 defstate = SS_DEFINED;
4907 isnull = NS_UNKNOWN;
4908 exitCode = XK_UNKNOWN;
4909 specc = SPC_NONE;
28bf4b0b 4910 nullPred = qual_createUnknown ();
616915dd 4911 }
4912 else
4913 {
28bf4b0b 4914 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4915 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4916 advanceField (s); exitCode = exitkind_fromInt (reader_getInt (s));
4917 advanceField (s); specc = specCode_fromInt (reader_getInt (s));
4918 advanceField (s); nullPred = qual_undump (s);
616915dd 4919 }
4920
28bf4b0b 4921 if (reader_optCheckChar (s, '$'))
616915dd 4922 {
4923 hasGlobs = FALSE;
4924 globs = globSet_undefined;
4925 hasMods = FALSE;
4926 mods = sRefSet_undefined;
4927 }
28bf4b0b 4928 else if (reader_optCheckChar (s, '^'))
616915dd 4929 {
4930 hasGlobs = TRUE;
4931 globs = globSet_undefined;
4932 hasMods = TRUE;
4933 mods = sRefSet_undefined;
4934 }
4935 else
4936 {
28bf4b0b 4937 advanceField (s); hasGlobs = bool_fromInt (reader_getInt (s));
616915dd 4938 advanceField (s); globs = globSet_undump (s);
28bf4b0b 4939 advanceField (s); hasMods = bool_fromInt (reader_getInt (s));
616915dd 4940 advanceField (s); mods = sRefSet_undump (s);
4941 }
4942
28bf4b0b 4943 if (reader_optCheckChar (s, '$'))
616915dd 4944 {
4945 ak = AK_UNKNOWN;
4946 exp = XO_UNKNOWN;
4947 }
4948 else
4949 {
28bf4b0b 4950 advanceField (s); ak = alkind_fromInt (reader_getInt (s));
4951 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
616915dd 4952 }
4953
4954 advanceField (s); access = typeIdSet_undump (s);
4955
28bf4b0b 4956 /*
4957 ** Optional clauses: Start with @<code>:
4958 */
4959
4960 while (reader_optCheckChar (s, '@'))
616915dd 4961 {
28bf4b0b 4962 if (reader_optCheckChar (s, 'W')) /* Warn clause */
4963 {
4964 reader_checkChar (s, ':');
4965 warnclause = warnClause_undump (s);
4966 }
4967 else if (reader_optCheckChar (s, 'S')) /* stateClause List */
4968 {
4969 reader_checkChar (s, ':');
4970 specclauses = stateClauseList_undump (s);
4971 }
4972 else
4973 {
4974 BADBRANCH;
4975 }
616915dd 4976 }
4977
28bf4b0b 4978 advanceName (s); name = reader_getStringWord (s);
616915dd 4979
4980 ue = uentry_makeFunctionBase (name, ct, access,
4981 hasGlobs, globs,
4982 hasMods, mods,
4983 ak, exp, defstate, isnull,
4984 exitCode, specc, nullPred,
4985 specclauses,
28bf4b0b 4986 warnclause,
616915dd 4987 fileloc_copy (loc));
4988 DPRINTF (("Undump: %s", uentry_unparse (ue)));
4989 }
4990 break;
4991 case KITER:
4992 {
4993 typeIdSet access;
4994
4995 advanceField (s); access = typeIdSet_undump (s);
28bf4b0b 4996 advanceName (s); name = reader_getStringWord (s);
616915dd 4997
4998 ue = uentry_makeIterBase (name, access, ct,
4999 fileloc_copy (loc));
5000 }
5001 break;
5002 case KENDITER:
5003 {
5004 typeIdSet access;
5005
5006 advanceField (s); access = typeIdSet_undump (s);
28bf4b0b 5007 advanceName (s); name = reader_getStringWord (s);
616915dd 5008
5009 ue = uentry_makeEndIterBase (name, access, fileloc_copy (loc));
5010 }
5011 break;
5012 case KENUMCONST:
5013 case KCONST:
5014 {
5015 typeIdSet access;
5016 multiVal val;
5017 nstate nullstate;
5018
28bf4b0b 5019 if (reader_optCheckChar (s, '$'))
616915dd 5020 {
5021 val = multiVal_undefined;
5022 access = typeIdSet_undefined;
5023 nullstate = NS_UNKNOWN;
5024 }
5025 else
5026 {
5027 advanceField (s); val = multiVal_undump (s);
5028 advanceField (s); access = typeIdSet_undump (s);
28bf4b0b 5029 advanceField (s); nullstate = nstate_fromInt (reader_getInt (s));
616915dd 5030 }
5031
28bf4b0b 5032 advanceName (s); name = reader_getStringWord (s);
616915dd 5033
5034 ue = uentry_makeConstantBase (name, ct, access,
5035 nullstate, fileloc_copy (loc), val);
5036 break;
5037 }
5038 case KSTRUCTTAG:
5039 case KUNIONTAG:
5040 case KENUMTAG:
5041 {
5042 ctype rtype;
5043
5044 advanceField (s); rtype = ctype_undump (s);
28bf4b0b 5045 advanceName (s); name = reader_getStringWord (s);
616915dd 5046 ue = uentry_makeTagBase (name, kind, ct, rtype, fileloc_copy (loc));
5047 }
5048 break;
5049 case KINVALID:
5050 llcontbuglit ("uentry_undump: invalid");
5051 ue = uentry_undefined;
5052 break;
5053 case KELIPSMARKER:
5054 llcontbuglit ("uentry_undump: elips marker");
5055 ue = uentry_undefined;
5056 break;
5057 }
5058 }
5059
5060 return (ue);
5061}
5062
5063cstring
5064uentry_dump (uentry v)
5065{
5066 return (uentry_dumpAux (v, FALSE));
5067}
5068
5069cstring
5070uentry_dumpParam (uentry v)
5071{
5072 llassertprint (uentry_isVariable (v) || uentry_isElipsisMarker (v),
5073 ("dump: %s", uentry_unparseFull (v)));
5074
5075 return (uentry_dumpAux (v, TRUE));
5076}
5077
5078static cstring
5079uentry_dumpAux (uentry v, bool isParam)
5080{
5081 llassert (uentry_isValid (v));
28bf4b0b 5082 llassert (!uentry_isGlobalMarker (v));
616915dd 5083
28bf4b0b 5084 DPRINTF (("Dump uentry: [%p]", v));
616915dd 5085 DPRINTF (("Dumping entry: %s", uentry_unparseFull (v)));
28bf4b0b 5086
616915dd 5087 switch (v->ukind)
5088 {
5089 case KINVALID:
5090 llcontbuglit ("uentry_dump: invalid entry");
5091 return cstring_undefined;
5092 case KELIPSMARKER:
5093 return (message ("!."));
5094 case KVAR:
5095 {
5096 cstring sdump;
5097 vkind vk = v->info->var->kind;
5098 sstate dss = sRef_getDefState (v->sref);
5099 nstate nst = sRef_getNullState (v->sref);
5100 alkind alk = sRef_getAliasKind (v->sref);
5101 exkind exk = sRef_getExKind (v->sref);
5102 chkind chk = v->info->var->checked;
5103
5104 DPRINTF (("Dumping var"));
5105
5106 if (dss == SS_UNKNOWN
5107 && nst == NS_UNKNOWN
5108 && alk == AK_IMPTEMP
5109 && exk == XO_UNKNOWN
5110 && chk == CH_UNKNOWN)
5111 {
5112 sdump = cstring_makeLiteral ("$");
5113 }
5114 else if (dss == SS_DEFINED
5115 && nst == NS_UNKNOWN
5116 && alk == AK_IMPTEMP
5117 && exk == XO_UNKNOWN
5118 && chk == CH_UNKNOWN)
5119 {
5120 sdump = cstring_makeLiteral ("&");
5121 }
5122 else if (dss == SS_UNKNOWN
5123 && nst == NS_UNKNOWN
5124 && alk == AK_UNKNOWN
5125 && exk == XO_UNKNOWN
5126 && chk == CH_UNKNOWN)
5127 {
5128 sdump = cstring_makeLiteral ("^");
5129 }
5130 else if (exk == XO_UNKNOWN
5131 && chk == CH_UNKNOWN)
5132 {
5133 sdump = message ("%d@%d@%d&",
5134 (int) dss,
5135 (int) nst,
5136 (int) alk);
5137 }
5138 else
5139 {
5140 sdump = message ("%d@%d@%d@%d@%d",
e5081f8c 5141 (int) dss,
616915dd 5142 (int) nst,
5143 (int) alk,
5144 (int) exk,
5145 (int) chk);
5146 }
5147
5148
5149 if (vk != VKPARAM)
5150 {
5151 return (message ("%q|@%d|%q#%s",
5152 ctype_dump (v->utype),
5153 (int) vk,
5154 sdump,
5155 isParam ? cstring_undefined : v->uname));
5156 }
5157 else
5158 {
5159 return (message ("%q|%q#%s",
5160 ctype_dump (v->utype),
5161 sdump,
5162 isParam ? cstring_undefined : v->uname));
5163 }
5164
5165 }
5166 case KDATATYPE:
28bf4b0b 5167 /*
5168 DPRINTF (("Dumping datatype: %s -> %s type: %s [%d]",
5169 uentry_unparse (v),
5170 exkind_unparse (sRef_getExKind (v->sref)),
5171 ctype_unparse (v->utype), (int) v->utype));
5172 */
5173
e5081f8c 5174 return (message ("%q@%c@%s@%d@%d@%d@%d@%q#%s",
616915dd 5175 ctype_dump (v->utype),
e5081f8c 5176 qual_abstractCode (v->info->datatype->abs),
616915dd 5177 ynm_unparseCode (v->info->datatype->mut),
5178 (int) sRef_getDefState (v->sref),
5179 (int) sRef_getNullState (v->sref),
5180 (int) sRef_getAliasKind (v->sref),
5181 (int) sRef_getExKind (v->sref),
5182 ctype_dump (v->info->datatype->type),
5183 v->uname));
5184 case KFCN:
5185 {
28bf4b0b 5186 cstring sdump, gdump, adump, xdump;
616915dd 5187 alkind alk = sRef_getAliasKind (v->sref);
5188 exkind exk = sRef_getExKind (v->sref);
5189
5190 if (sRef_getDefState (v->sref) == SS_DEFINED
5191 && !nstate_isKnown (sRef_getNullState (v->sref))
5192 && !exitkind_isKnown (v->info->fcn->exitCode)
5193 && v->info->fcn->specialCode == SPC_NONE
28bf4b0b 5194 && qual_isUnknown (v->info->fcn->nullPred))
616915dd 5195 {
5196 sdump = cstring_makeLiteral ("$");
5197 }
5198 else
5199 {
28bf4b0b 5200 sdump = message ("@%d@%d@%d@%d@%x",
616915dd 5201 (int) sRef_getDefState (v->sref),
5202 (int) sRef_getNullState (v->sref),
5203 (int) v->info->fcn->exitCode,
5204 (int) v->info->fcn->specialCode,
28bf4b0b 5205 qual_dump (v->info->fcn->nullPred));
616915dd 5206 }
5207
5208 if (!uentry_hasGlobs(v) && !uentry_hasMods (v))
5209 {
5210 gdump = cstring_makeLiteral ("$");
5211 }
5212 else if (uentry_hasGlobs (v) && globSet_isEmpty (uentry_getGlobs (v))
5213 && uentry_hasMods (v) && sRefSet_isEmpty (uentry_getMods (v)))
5214 {
5215 gdump = cstring_makeLiteral ("^");
5216 }
5217 else
5218 {
5219 gdump = message ("@%s@%q@%s@%q",
5220 bool_dump (uentry_hasGlobs (v)),
5221 globSet_dump (uentry_getGlobs (v)),
5222 bool_dump (uentry_hasMods (v)),
5223 sRefSet_dump (uentry_getMods (v)));
5224 }
5225
5226 if (alk == AK_UNKNOWN && exk == XO_UNKNOWN)
5227 {
5228 adump = cstring_makeLiteral ("$");
5229 }
5230 else
5231 {
5232 adump = message ("@%d@%d", (int) alk, (int) exk);
5233 }
5234
28bf4b0b 5235 xdump = cstring_undefined;
5236
5237 if (uentry_hasWarning (v))
616915dd 5238 {
28bf4b0b 5239 xdump = message ("%q@W:%q", xdump, warnClause_dump (v->warn));
616915dd 5240 }
28bf4b0b 5241
5242 if (uentry_hasStateClauseList (v))
616915dd 5243 {
28bf4b0b 5244 xdump = message ("%q@S:%q", xdump, stateClauseList_dump (v->info->fcn->specclauses));
616915dd 5245 }
28bf4b0b 5246
5247 return (message ("%q%q%q%q@%q%q#%s",
5248 ctype_dump (v->utype),
5249 sdump,
5250 gdump,
5251 adump,
5252 typeIdSet_dump (uentry_accessType (v)),
5253 xdump,
5254 v->uname));
616915dd 5255 }
5256 case KITER:
5257 return (message ("%q@%q#%s",
5258 ctype_dump (v->utype),
5259 typeIdSet_dump (v->info->iter->access),
5260 v->uname));
5261 case KENDITER:
5262 return (message ("%q@%q#%s",
5263 ctype_dump (v->utype),
5264 typeIdSet_dump (uentry_accessType (v)),
5265 v->uname));
5266 case KENUMCONST:
5267 case KCONST:
5268 {
5269 cstring sdump;
5270
b9904f57 5271 if (multiVal_isUnknown (uentry_getConstantValue (v))
616915dd 5272 && typeIdSet_isEmpty (uentry_accessType (v))
5273 && (sRef_getNullState (v->sref) == NS_UNKNOWN))
5274 {
5275 sdump = cstring_makeLiteral ("$");
5276 }
5277 else
5278 {
5279 sdump = message ("@%q@%q@%d",
b9904f57 5280 multiVal_dump (uentry_getConstantValue (v)),
616915dd 5281 typeIdSet_dump (uentry_accessType (v)),
5282 (int) sRef_getNullState (v->sref));
5283 }
5284
5285 return (message ("%q%q#%s",
5286 ctype_dump (v->utype),
5287 sdump,
5288 v->uname));
5289 }
5290 case KSTRUCTTAG:
5291 case KUNIONTAG:
5292 case KENUMTAG:
5293 return (message ("%q@%q#%s",
5294 ctype_dump (v->utype),
5295 ctype_dump (v->info->datatype->type), v->uname));
5296 }
5297
5298 BADEXIT;
5299}
5300
5301/*@only@*/ cstring
5302uentry_unparseAbbrev (uentry v)
5303{
5304 if (!uentry_isVariable (v))
5305 {
5306 llcontbuglit ("uentry_unparseAbbrev: not variable");
5307 return uentry_unparse (v);
5308 }
5309
5310 return (message ("%s %q", ctype_unparseDeep (v->utype), uentry_getName (v)));
5311}
5312
5313/*@only@*/ cstring
5314uentry_unparse (uentry v)
5315{
5316 cstring st;
5317
5318 if (uentry_isUndefined (v)) return (cstring_makeLiteral ("<undefined>"));
5319 if (uentry_isElipsisMarker (v)) return (cstring_makeLiteral ("..."));
5320
5321 st = uentry_getName (v);
5322
5323 if (cstring_isDefined (st))
5324 {
5325 return (ctype_unparseDeclaration (v->utype, st));
5326 }
5327 else
5328 {
5329 cstring_free (st);
5330 return (cstring_copy (ctype_unparse (v->utype)));
5331 }
5332}
5333
5334/*@only@*/ cstring
5335uentry_unparseFull (uentry v)
5336{
5337 if (uentry_isUndefined (v))
5338 {
5339 return (cstring_makeLiteral ("<undefined>"));
5340 }
616915dd 5341 else
5342 {
28bf4b0b 5343 cstring res;
5344
e5081f8c 5345 res = message ("[%p] %s %s: %s [spec: %q; decl: %q; def: %q]",
5346 v, ekind_unparse (v->ukind), v->uname,
28bf4b0b 5347 ctype_unparse (v->utype),
5348 fileloc_unparse (uentry_whereSpecified (v)),
5349 fileloc_unparse (uentry_whereDeclared (v)),
5350 fileloc_unparse (uentry_whereDefined (v)));
5351
5352 DPRINTF (("uentry: %s", res));
5353
5354 if (uentry_isDatatype (v))
5355 {
5356 res = message ("%q / type: %s mut: %s abs: %s state: %q",
5357 res,
5358 ctype_unparse
5359 (ctype_isDefined (v->info->datatype->type)
5360 ? v->info->datatype->type : ctype_unknown),
5361 ynm_unparse (v->info->datatype->mut),
e5081f8c 5362 qual_unparse (v->info->datatype->abs),
28bf4b0b 5363 sRef_unparseState (v->sref));
5364 }
5365 else if (uentry_isFunction (v))
5366 {
5367 res = message ("%q / sref: %q / mods: %q / "
ba45e1e4 5368 "globs: %q / clauses: %q / pre: %q / post: %q",
28bf4b0b 5369 res,
5370 sRef_unparseFull (v->sref),
5371 sRefSet_unparse (v->info->fcn->mods),
5372 globSet_unparse (v->info->fcn->globs),
ba45e1e4 5373 stateClauseList_unparse (v->info->fcn->specclauses),
5374 functionConstraint_unparse (v->info->fcn->preconditions),
5375 functionConstraint_unparse (v->info->fcn->postconditions));
28bf4b0b 5376 }
5377 else if (uentry_isIter (v))
5378 {
5379 res = message ("%q / sref: %q",
5380 res,
5381 sRef_unparseFull (v->sref));
5382 }
5383 else if (uentry_isVariable (v))
5384 {
5385 res = message ("%q / sref: %q / kind <%d> isout <%d> null <%d> used <%d>",
5386 res,
5387 sRef_unparseFull (v->sref),
5388 (int) v->info->var->kind,
5389 (int) v->info->var->defstate,
5390 (int) v->info->var->nullstate,
5391 (int) v->used);
5392 DPRINTF (("sref: [%p]", v->sref));
5393 DPRINTF (("sref: %s", sRef_unparseDebug (v->sref)));
5394 /* DPRINTF (("sref: %s", sRef_unparseDeep (v->sref))); */
5395 }
b9904f57 5396 else if (uentry_isConstant (v))
5397 {
02b84d4b 5398 res = message ("%q = %q / %q",
5399 res, multiVal_unparse (uentry_getConstantValue (v)),
5400 sRef_unparseFull (v->sref));
b9904f57 5401 }
28bf4b0b 5402 else
5403 {
5404 res = message ("%q :: %q", res, uentry_unparse (v));
5405 }
5406
5407 return res;
616915dd 5408 }
5409}
5410
5411bool uentry_hasAccessType (uentry e)
5412{
5413 if (uentry_isValid (e))
5414 {
5415 switch (e->ukind)
5416 {
5417 case KITER:
5418 return (!typeIdSet_isEmpty (e->info->iter->access));
5419 case KENDITER:
5420 return (!typeIdSet_isEmpty (e->info->enditer->access));
5421 case KFCN:
5422 return (!typeIdSet_isEmpty (e->info->fcn->access));
5423 case KENUMCONST:
5424 case KCONST:
5425 return (!typeIdSet_isEmpty (e->info->uconst->access));
5426 default:
5427 return FALSE;
5428 }
5429 }
5430
5431 return FALSE;
5432}
5433
5434typeIdSet uentry_accessType (uentry e)
5435{
5436 if (uentry_isValid (e))
5437 {
5438 switch (e->ukind)
5439 {
5440 case KITER:
5441 return (e->info->iter->access);
5442 case KENDITER:
5443 return (e->info->enditer->access);
5444 case KFCN:
5445 return (e->info->fcn->access);
5446 case KENUMCONST:
5447 case KCONST:
5448 return (e->info->uconst->access);
5449 default:
5450 break;
5451 }
5452 }
5453
5454 return typeIdSet_undefined;
5455}
5456
5457bool
5458uentry_isVariable (uentry e)
5459{
5460 return (uentry_isVar (e));
5461}
5462
5463bool
5464uentry_isSpecified (uentry e)
5465{
5466 return (uentry_isValid (e) && !fileloc_isUndefined (e->whereSpecified));
5467}
5468
5469static bool
5470uentry_isReallySpecified (uentry e)
5471{
5472 return (uentry_isValid (e)
5473 && fileloc_isRealSpec (e->whereSpecified));
5474}
5475
5476bool
5477uentry_isVar (uentry e)
5478{
5479 return (!uentry_isUndefined (e) && e->ukind == KVAR);
5480}
5481
5482bool
5483uentry_isFakeTag (uentry e)
5484{
5485 return (uentry_isValid (e) && strchr (cstring_toCharsSafe (e->uname), '!') != 0);
5486}
5487
5488bool
5489uentry_isDatatype (uentry e)
5490{
5491 return (!uentry_isUndefined (e) &&
5492 (e->ukind == KDATATYPE || e->ukind == KSTRUCTTAG ||
5493 e->ukind == KUNIONTAG || e->ukind == KENUMTAG));
5494}
5495
5496void
5497uentry_setAbstract (uentry e)
5498{
5499 typeId oldid;
5500
5501 llassert (uentry_isDatatype (e)
e5081f8c 5502 && (qual_isUnknown (e->info->datatype->abs)));
616915dd 5503
5504 oldid = ctype_typeId (e->info->datatype->type);
e5081f8c 5505 e->info->datatype->abs = qual_createAbstract ();
616915dd 5506 e->info->datatype->type = ctype_createAbstract (oldid);
5507}
5508
5509void
5510uentry_setConcrete (uentry e)
5511{
5512 llassert (uentry_isDatatype (e)
e5081f8c 5513 && (qual_isUnknown (e->info->datatype->abs)
5514 || qual_isConcrete (e->info->datatype->abs)));
616915dd 5515
e5081f8c 5516 e->info->datatype->abs = qual_createConcrete ();
616915dd 5517}
5518
5519bool
5520uentry_isAbstractDatatype (uentry e)
5521{
5522 return (uentry_isDatatype (e)
e5081f8c 5523 && (qual_isEitherAbstract (e->info->datatype->abs)));
616915dd 5524}
5525
5526bool
5527uentry_isMaybeAbstract (uentry e)
5528{
5529 return (uentry_isDatatype (e)
e5081f8c 5530 && (!qual_isConcrete (e->info->datatype->abs)));
616915dd 5531}
5532
5533bool
5534uentry_isMutableDatatype (uentry e)
5535{
b73d1009 5536 if (uentry_isDatatype (e))
5537 {
5538 if (ctype_isNumAbstract (e->info->datatype->type))
5539 {
5540 return FALSE;
5541 }
5542 else
5543 {
5544 return ynm_toBoolRelaxed (e->info->datatype->mut);
5545 }
5546 }
5547
5548 return FALSE;
616915dd 5549}
5550
5551bool
5552uentry_isRefCountedDatatype (uentry e)
5553{
5554 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
5555}
5556
5557bool
5558uentry_isParam (uentry u)
5559{
5560 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
5561 || u->info->var->kind == VKYIELDPARAM));
5562}
5563
5564bool
5565uentry_isExpandedMacro (uentry u)
5566{
5567 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
5568}
5569
5570bool
5571uentry_isSefParam (uentry u)
5572{
5573 return (uentry_isVariable (u)
5574 && (u->info->var->kind == VKSEFPARAM
5575 || u->info->var->kind == VKREFSEFPARAM
5576 || u->info->var->kind == VKSEFRETPARAM
5577 || u->info->var->kind == VKREFSEFRETPARAM));
5578}
5579
5580bool
5581uentry_isRefParam (uentry u)
5582{
5583 return (uentry_isVariable (u)
5584 && (u->info->var->kind == VKREFPARAM
5585 || u->info->var->kind == VKREFYIELDPARAM
5586 || u->info->var->kind == VKREFSEFPARAM
5587 || u->info->var->kind == VKREFSEFRETPARAM));
5588}
5589
5590bool
5591uentry_isAnyParam (uentry u)
5592{
5593 return (uentry_isVariable (u)
5594 && ((u->info->var->kind == VKPARAM)
5595 || (u->info->var->kind == VKSEFPARAM)
5596 || (u->info->var->kind == VKYIELDPARAM)
5597 || (u->info->var->kind == VKRETPARAM)
5598 || (u->info->var->kind == VKSEFRETPARAM)));
5599}
5600
5601sstate
5602uentry_getDefState (uentry u)
5603{
5604 if (uentry_isValid (u))
5605 {
5606 return (sRef_getDefState (u->sref));
5607 }
5608 else
5609 {
5610 return (SS_UNKNOWN);
5611 }
5612}
5613
5614bool
5615uentry_isOut (uentry u)
5616{
5617 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5618 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5619}
5620
5621bool
5622uentry_isPartial (uentry u)
5623{
5624 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5625 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5626}
5627
5628bool
5629uentry_isStateSpecial (uentry u)
5630{
5631 return ((uentry_isVariable (u)
5632 && (u->info->var->defstate == SS_SPECIAL))
5633 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5634}
5635
5636exitkind uentry_getExitCode (uentry ue)
5637{
5638 if (uentry_isFunction (ue))
5639 {
5640 return ue->info->fcn->exitCode;
5641 }
5642 else
5643 {
5644 return XK_UNKNOWN;
5645 }
5646}
5647
28bf4b0b 5648qual uentry_nullPred (uentry u)
616915dd 5649{
5650 llassert (uentry_isRealFunction (u));
5651
5652 if (uentry_isFunction (u))
5653 {
5654 return (u->info->fcn->nullPred);
5655 }
5656 else
5657 {
28bf4b0b 5658 return qual_createUnknown ();
616915dd 5659 }
5660}
5661
28bf4b0b 5662/*
5663** Note for variables, this is checking the declared state, not the current state.
5664*/
5665
616915dd 5666bool
5667uentry_possiblyNull (uentry u)
5668{
5669 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5670 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5671}
5672
5673alkind
5674uentry_getAliasKind (uentry u)
5675{
5676 if (uentry_isValid (u))
5677 {
5678 return (sRef_getAliasKind (uentry_getSref (u)));
5679 }
5680 else
5681 {
5682 return AK_UNKNOWN;
5683 }
5684}
5685
5686exkind
5687uentry_getExpKind (uentry u)
5688{
5689 if (uentry_isValid (u))
5690 {
5691 return (sRef_getExKind (uentry_getSref (u)));
5692 }
5693 else
5694 {
5695 return XO_UNKNOWN;
5696 }
5697}
5698
5699bool
5700uentry_isIter (uentry e)
5701{
5702 return (!uentry_isUndefined (e) && e->ukind == KITER);
5703}
5704
5705bool
5706uentry_isEndIter (uentry e)
5707{
5708 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5709}
5710
5711bool
5712uentry_isRealFunction (uentry e)
5713{
5714 return (uentry_isFunction (e) ||
5715 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5716}
5717
5718bool
5719uentry_hasName (uentry e)
5720{
5721 if (uentry_isValid (e))
5722 {
5723 cstring s = e->uname;
5724
28bf4b0b 5725 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")
5726 || uentry_isFakeTag (e)));
616915dd 5727 }
5728 else
5729 {
5730 return FALSE;
5731 }
5732}
5733
28bf4b0b 5734/*
5735** Returns true for fake tags.
5736** This is used for dumping the library
5737*/
5738
616915dd 5739bool uentry_hasRealName (uentry e)
5740{
28bf4b0b 5741 return (uentry_isValid (e)
5742 && cstring_isNonEmpty (e->uname)
5743 && !uentry_isGlobalMarker (e));
616915dd 5744}
5745
5746
5747/*@observer@*/ globSet
5748uentry_getGlobs (uentry l)
5749{
5750 if (uentry_isInvalid (l))
5751 {
5752 return globSet_undefined;
5753 }
5754
6fcd0b1e 5755 if (uentry_isFunction (l))
5756 {
5757 return l->info->fcn->globs;
5758 }
5759 else if (uentry_isIter (l))
616915dd 5760 {
6fcd0b1e 5761 return l->info->iter->globs;
5762 }
5763 else if (uentry_isEndIter (l))
5764 {
5765 return globSet_undefined;
5766 }
5767 else
5768 {
5769 if (l->ukind == KVAR)
616915dd 5770 {
6fcd0b1e 5771 llcontbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
616915dd 5772 uentry_unparse (l),
5773 ekind_unparse (l->ukind)));
6fcd0b1e 5774 }
5775 else
5776 {
5777 llcontbug (message ("Bad call to uentry_getGlobs: %q (%s)",
616915dd 5778 uentry_unparse (l),
5779 ekind_unparse (l->ukind)));
616915dd 5780 }
6fcd0b1e 5781
616915dd 5782 return globSet_undefined;
5783 }
616915dd 5784}
5785
51bc6ecc 5786# ifdef WIN32
5787/* Make Microsoft VC++ happy */
5788# pragma warning (disable : 4715)
5789# endif
5790
616915dd 5791/*@observer@*/ sRefSet
5792uentry_getMods (uentry l)
5793{
5794 llassert (uentry_isValid (l));
5795
5796 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5797 {
5798 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5799 return sRefSet_undefined;
5800 }
5801
6fcd0b1e 5802 if (uentry_isFunction (l))
5803 {
5804 return l->info->fcn->mods;
5805 }
5806 else if (uentry_isIter (l))
5807 {
5808 return l->info->iter->mods;
5809 }
5810 else if (uentry_isEndIter (l))
5811 {
5812 return sRefSet_undefined;
5813 }
5814 else
5815 {
5816 BADBRANCH;
5817 }
616915dd 5818}
5819
5820ekind
5821uentry_getKind (uentry e)
5822{
5823 llassert (uentry_isValid (e));
616915dd 5824 return (e->ukind);
5825}
5826
5827/*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5828{
b9904f57 5829 llassert (uentry_isEitherConstant (e));
5830 return (sRef_getValue (e->sref));
616915dd 5831}
5832
5833/*@observer@*/ uentryList
5834uentry_getParams (uentry l)
5835{
5836 if (uentry_isInvalid (l)) return uentryList_undefined;
5837
5838 switch (l->ukind)
5839 {
5840 case KFCN:
5841 case KITER:
5842 {
5843 ctype ct = l->utype;
5844
5845 if (ctype_isFunction (ct))
5846 {
5847 return (ctype_argsFunction (ct));
5848 }
5849 else
5850 {
5851 return uentryList_undefined;
5852 }
5853 }
5854 case KVAR:
5855 {
5856 ctype ct = l->utype;
5857
39888ce3 5858 /*drl 12/10/2002 changed to fix bug involving multiple redefines of library functions in macros. Bug was reported by Malcolm Parsons
5859
5860 Old code was simplly llassert (ctype_isFunction (ct) );
5861 */
5862
5863 llassert (ctype_isFunction (ct) || context_inMacro() );
5864
616915dd 5865 return (ctype_argsFunction (ct));
5866 }
5867 BADDEFAULT;
5868 }
5869 BADEXIT;
5870}
5871
5872/*@observer@*/ cstring
5873uentry_rawName (uentry e)
5874{
5875 if (uentry_isValid (e))
5876 {
5877 return (e->uname);
5878 }
5879 else
5880 {
5881 return cstring_undefined;
5882 }
5883}
5884
5885static cstring
5886uentry_getOptName (uentry e)
5887{
5888 cstring s = uentry_getName (e);
5889
5890 if (cstring_isDefined (s))
5891 {
5892 s = cstring_appendChar (s, ' ');
5893 }
5894
5895 return s;
5896}
5897
5898/*@only@*/ cstring
5899uentry_getName (uentry e)
5900{
5901 cstring ret = cstring_undefined;
5902
5903 if (uentry_isValid (e))
5904 {
616915dd 5905 if (uentry_isAnyTag (e))
5906 {
28bf4b0b 5907 ret = fixTagName (e->uname);
616915dd 5908 }
5909 else if (uentry_isAnyParam (e))
5910 {
5911 ret = cstring_copy (fixParamName (e->uname));
5912 }
5913 else
5914 {
5915 ret = cstring_copy (e->uname);
5916 }
5917 }
5918
5919 return ret;
5920}
5921
28bf4b0b 5922cstring uentry_observeRealName (uentry e)
5923{
5924 cstring ret = cstring_undefined;
5925
5926 if (uentry_isValid (e))
5927 {
5928 if (uentry_isAnyTag (e))
5929 {
5930 if (isFakeTag (e->uname))
5931 {
5932 ret = cstring_undefined;
5933 }
5934 else
5935 {
5936 ret = plainTagName (e->uname);
5937 }
5938 }
5939 else if (uentry_isAnyParam (e))
5940 {
5941 ret = fixParamName (e->uname);
5942 }
5943 else
5944 {
5945 ret = e->uname;
5946 }
5947 }
5948
5949 return ret;
5950}
5951
616915dd 5952cstring uentry_getRealName (uentry e)
5953{
5954 if (uentry_isValid (e))
5955 {
5956 if (uentry_isAnyTag (e))
5957 {
5958 return (cstring_undefined);
5959 }
5960 else
5961 {
5962 return (e->uname);
5963 }
5964 }
5965 return cstring_undefined;
5966}
5967
5968ctype uentry_getType (uentry e)
5969{
5970 if (uentry_isValid (e))
5971 {
5972 return e->utype;
5973 }
5974 else
5975 {
5976 return ctype_unknown;
5977 }
5978}
5979
5980fileloc uentry_whereLast (uentry e)
5981{
5982 fileloc loc;
5983
5984 if (uentry_isInvalid (e))
5985 {
5986 return fileloc_undefined;
5987 }
5988
5989 loc = e->whereDefined;
5990
5991 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5992 {
5993 return loc;
5994 }
5995
5996 loc = uentry_whereDeclared (e);
5997
5998 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5999 {
6000 return loc;
6001 }
6002
6003 loc = uentry_whereSpecified (e);
6004 return loc;
6005}
6006
6007fileloc uentry_whereEither (uentry e)
6008{
6009 if (uentry_isInvalid (e)) return fileloc_undefined;
6010
6011 if (fileloc_isDefined (e->whereDefined)
6012 && !fileloc_isExternal (e->whereDefined))
6013 {
6014 return e->whereDefined;
6015 }
6016 else if (fileloc_isDefined (e->whereDeclared))
6017 {
6018 return e->whereDeclared;
6019 }
6020 else
6021 {
6022 return e->whereSpecified;
6023 }
6024}
6025
6026fileloc uentry_whereSpecified (uentry e)
6027{
6028 if (uentry_isInvalid (e)) return fileloc_undefined;
6029
6030 return (e->whereSpecified);
6031}
6032
6033fileloc uentry_whereDefined (uentry e)
6034{
6035 if (uentry_isInvalid (e)) return fileloc_undefined;
6036
6037 return (e->whereDefined);
6038}
6039
6040fileloc uentry_whereDeclared (uentry e)
6041{
6042 if (uentry_isInvalid (e)) return fileloc_undefined;
6043
6044 return (e->whereDeclared);
6045}
6046
6047/*@observer@*/ fileloc
6048uentry_whereEarliest (uentry e)
6049{
6050 if (uentry_isInvalid (e)) return fileloc_undefined;
6051
6052 if (fileloc_isDefined (e->whereSpecified))
6053 {
6054 return (e->whereSpecified);
6055 }
6056 else if (fileloc_isDefined (e->whereDeclared))
6057 {
6058 return (e->whereDeclared);
6059 }
6060 else
6061 {
6062 return e->whereDefined;
6063 }
6064}
6065
6066void
6067uentry_setFunctionDefined (uentry e, fileloc loc)
6068{
6069 if (uentry_isValid (e))
6070 {
6071 llassert (uentry_isFunction (e));
6072
6073 if (fileloc_isUndefined (e->whereDeclared))
6074 {
6075 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
6076 }
6077
6078 if (!fileloc_isDefined (e->whereDefined))
6079 {
6080 e->whereDefined = fileloc_update (e->whereDefined, loc);
6081 }
6082 }
6083}
6084
6085void
6086uentry_setDeclDef (uentry e, fileloc f)
6087{
6088 uentry_setDeclared (e, f);
6089
6090 if (!uentry_isFunction (e)
6091 && !(uentry_isVariable (e) && uentry_isExtern (e)))
6092 {
6093 uentry_setDefined (e, f);
6094 }
6095}
6096
6097void
6098uentry_setDeclaredForce (uentry e, fileloc f)
6099{
6100 llassert (uentry_isValid (e));
6101 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6102}
6103
6104void
6105uentry_setDeclaredForceOnly (uentry e, fileloc f)
6106{
6107 llassert (uentry_isValid (e));
6108 fileloc_free (e->whereDeclared);
6109 e->whereDeclared = f;
6110}
6111
6112void
6113uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
6114{
6115 fileloc oldloc;
6116
6117 llassert (uentry_isValid (e));
6118 oldloc = e->whereDeclared;
6119
6120 if (fileloc_isDefined (oldloc))
6121 {
6122 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6123 {
6124 e->whereDeclared = f;
6125 fileloc_free (oldloc);
6126 }
6127 else
6128 {
6129 fileloc_free (f);
6130 }
6131 }
6132 else
6133 {
6134 e->whereDeclared = f;
6135 fileloc_free (oldloc);
6136 }
6137}
6138
6139void
6140uentry_setDeclared (uentry e, fileloc f)
6141{
6142 fileloc oldloc;
6143
6144 llassert (uentry_isValid (e));
6145 oldloc = e->whereDeclared;
6146
6147 if (fileloc_isDefined (oldloc))
6148 {
6149 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6150 {
6151 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6152 }
6153 else
6154 {
6155 ;
6156 }
6157 }
6158 else
6159 {
6160 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6161 }
6162}
6163
6164void
6165uentry_clearDefined (uentry e)
6166{
6167 if (uentry_isValid (e))
6168 {
6169 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
6170 }
6171}
6172
6173void
6174uentry_setDefined (uentry e, fileloc f)
6175{
6176 fileloc oldloc;
6177
6178 llassert (uentry_isValid (e));
6179 oldloc = e->whereDefined;
6180
6181 if (fileloc_isDefined (oldloc))
6182 {
6183 if (fileloc_isLib (oldloc)
6184 || fileloc_isImport (oldloc)
6185 || fileloc_isBuiltin (oldloc)
6186 || fileloc_isPreproc (oldloc))
6187 {
6188 e->whereDefined = fileloc_update (e->whereDefined, f);
6189 }
6190 else
6191 {
6192 if (fileloc_equal (oldloc, f) || context_processingMacros ())
6193 {
6194 ; /* okay */
6195 }
6196 else
6197 {
6198 if (optgenerror (FLG_REDEF,
6199 message ("%s %q redefined",
6200 ekind_capName (e->ukind),
6201 uentry_getName (e)),
6202 f))
6203 {
6204 llgenindentmsg (message ("Previous definition of %q",
6205 uentry_getName (e)),
6206 e->whereDefined);
6207 }
6208 }
6209 }
6210 }
6211 else
6212 {
6213 e->whereDefined = fileloc_update (e->whereDefined, f);
6214 }
6215}
6216
6217bool
6218uentry_isCodeDefined (uentry e)
6219{
efd360a3 6220 llassert (uentry_isValid (e));
6221
6222 return (fileloc_isDefined (e->whereDefined));
616915dd 6223}
6224
6225bool
6226uentry_isDeclared (uentry e)
6227{
6228 if (uentry_isValid (e))
6229 {
6230 return (fileloc_isDefined (e->whereDeclared));
6231 }
6232
6233 return FALSE;
6234}
6235
6236sRef uentry_getSref (uentry e)
6237{
6238 /* not true, used for functions too (but shouldn't be? */
6239 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
6240
6241 if (uentry_isInvalid (e)) return sRef_undefined;
6242
6243 return (e->sref);
6244}
6245
6246sRef uentry_getOrigSref (uentry e)
6247{
b73d1009 6248 /* evans 2003-04-12 - removed for now */
6249 /* evans 2001-09-09 - need to fix this
b7e84605 6250 if (uentry_isValid (e))
6251 {
6252 if (uentry_isVariable (e))
6253 {
6254 return e->info->var->origsref;
6255 }
6256 else
6257 {
6258 sRef sr = sRef_copy (uentry_getSref (e));
6259
6260 sRef_resetState (sr);
6261 sRef_clearDerived (sr);
6262 return (sr);
6263 }
6264 }
6265 else
6266 {
6267 return sRef_undefined;
6268 }
6269 */
6270
616915dd 6271 if (uentry_isValid (e))
6272 {
6273 sRef sr = sRef_copy (uentry_getSref (e));
6274
6275 sRef_resetState (sr);
6276 sRef_clearDerived (sr);
6277
6278 if (uentry_isVariable (e))
6279 {
6280 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
6281 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
6282 }
6283
6284 return (sr);
6285 }
6286 else
6287 {
6288 return sRef_undefined;
6289 }
6290}
6291
6292/*
6293** requires: uentry e is not in a hashed symbol table
6294*/
6295
6296void
6297uentry_setName (uentry e, /*@only@*/ cstring n)
6298{
6299 llassert (uentry_isValid (e));
6300
6301 cstring_free (e->uname);
6302 e->uname = n;
6303}
6304
6305void
6306uentry_setType (uentry e, ctype t)
6307{
6308 if (uentry_isValid (e))
6309 {
6310 e->utype = t;
6311 sRef_setType (e->sref, t);
6312 }
6313}
6314
6315void
6316uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
6317{
6318 ctype rct;
6319 ctype rettype = ctype_unknown;
6320
6321 llassert (uentry_isValid (ue));
6322
efd360a3 6323 uentry_convertVarFunction (ue);
616915dd 6324 llassert (uentry_isFunction (ue));
6325
efd360a3 6326 rct = ctype_realType (ue->utype);
6327
616915dd 6328 if (ctype_isFunction (rct))
6329 {
28bf4b0b 6330 rettype = ctype_getReturnType (rct);
616915dd 6331 }
6332
6333 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
6334}
6335
6336void
6337uentry_setRefParam (uentry e)
6338{
616915dd 6339 if (!uentry_isVar (e))
6340 {
6341 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6342 }
6343 else
6344 {
6345 if (e->info->var->kind == VKSEFPARAM)
6346 {
6347 e->info->var->kind = VKREFSEFPARAM;
6348 }
6349 else if (e->info->var->kind == VKSEFRETPARAM)
6350 {
6351 e->info->var->kind = VKREFSEFRETPARAM;
6352 }
6353 else if (e->info->var->kind == VKYIELDPARAM)
6354 {
6355 e->info->var->kind = VKREFYIELDPARAM;
6356 }
6357 else
6358 {
6359 e->info->var->kind = VKREFPARAM;
6360 }
6361 }
6362}
6363
6364void
6365uentry_setParam (uentry e)
6366{
6367 if (!uentry_isVar (e))
6368 {
6369 if (uentry_isElipsisMarker (e))
6370 {
6371
6372 }
6373 else
6374 {
6375 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6376 }
6377 }
6378 else
6379 {
6380 cstring oldname;
6381
6382 if (e->info->var->kind == VKYIELDPARAM
6383 || e->info->var->kind == VKSEFPARAM
6384 || e->info->var->kind == VKSEFRETPARAM)
6385 {
6386 ;
6387 }
6388 else
6389 {
6390 e->info->var->kind = VKPARAM;
6391 }
6392
6393 oldname = e->uname;
6394 e->uname = makeParam (e->uname);
6395 cstring_free (oldname);
6396 }
6397}
6398
6399void
6400uentry_setSref (uentry e, sRef s)
6401{
6402 if (uentry_isValid (e))
6403 {
6404 if (sRef_isValid (e->sref))
6405 {
6406 sRef_mergeStateQuietReverse (e->sref, s);
6407 }
6408 else
6409 {
6410 e->sref = sRef_saveCopy (s);
6411 }
6412 }
6413}
6414
6415ctype
6416uentry_getAbstractType (uentry e)
6417{
6418 llassert (uentry_isDatatype (e));
6419
6420 /*
6421 ** This assertion removed.
6422 ** Okay to have undefined type, for system types
6423
6424 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
6425 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
6426 e->utype);
6427
6428 */
6429
6430 if (ctype_isUndefined (e->info->datatype->type))
6431 {
6432 return ctype_unknown;
6433 }
6434
6435 /*
6436 ** Sadly, a kludge...
6437 */
6438
6439 if (ctype_isUserBool (e->info->datatype->type)) {
6440 return ctype_bool;
6441 }
6442
6443 return e->info->datatype->type;
6444}
6445
6446ctype uentry_getRealType (uentry e)
6447{
6448 ctype ct;
b73d1009 6449 typeId uid = typeId_invalid;
616915dd 6450
6451 if (uentry_isInvalid (e))
6452 {
6453 return ctype_unknown;
6454 }
aec3dcdb 6455
6456 if (!uentry_isDatatype (e))
6457 {
6458 /* This shouldn't happen, except when types are redeclared in strange ways */
6459 return ctype_unknown;
6460 }
616915dd 6461
6462 if (uentry_isAnyTag (e))
6463 {
6464 return (e->utype);
6465 }
6466
6467 if (uentry_isAbstractType (e))
6468 {
6469 ct = uentry_getAbstractType (e);
6470
6471 if (ctype_isManifestBool (ct)) {
6472 return ct;
6473 }
6474
6475 llassert (ctype_isUA (ct));
6476
6477 uid = ctype_typeId (ct);
6478
6479 if (!context_hasAccess (uid))
6480 {
6481 return (ct);
6482 }
6483 }
6484
6485 ct = uentry_getType (e);
6486
6487 /* if (ctype_isUserBool (ct)) return ct; */
6488
6489 if (ctype_isManifestBool (ct)) {
6490 return ctype_bool;
6491 }
6492
6493 if (ctype_isUA (ct))
6494 {
b73d1009 6495 typeId iid = ctype_typeId (ct);
616915dd 6496
b73d1009 6497 if (typeId_equal (iid, uid))
616915dd 6498 {
6499 llcontbug (message ("uentry_getRealType: recursive type! %s",
6500 ctype_unparse (ct)));
6501 return ct;
6502 }
6503 else
6504 {
6505 /* evs 2000-07-25: possible infinite recursion ? */
6506 uentry ue2 = usymtab_getTypeEntry (iid);
28bf4b0b 6507
6508 if (ue2 == e)
6509 {
6510 llcontbug (message ("Bad recursion: %q", uentry_unparseFull (e)));
6511 return ctype_unknown;
6512 }
616915dd 6513
6514 return uentry_getRealType (ue2);
6515 }
6516 }
6517 else
6518 {
6519 return ct;
6520 }
6521}
6522
6523ctype uentry_getForceRealType (uentry e)
6524{
6525 ctype ct;
b73d1009 6526 typeId uid = typeId_invalid;
616915dd 6527
6528 if (uentry_isInvalid (e))
6529 {
6530 return ctype_unknown;
6531 }
6532
6533 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6534
6535 if (uentry_isAnyTag (e))
6536 {
6537 return (e->utype);
6538 }
6539
6540 if (uentry_isAbstractType (e))
6541 {
6542 ct = uentry_getAbstractType (e);
6543 llassert (ctype_isUA (ct));
6544
6545 uid = ctype_typeId (ct);
6546 /* no check for access! */
6547 }
6548
6549 ct = uentry_getType (e);
6550
6551 /* evs 2000-07-25 */
6552 /* if (ctype_isUserBool (ct)) return ct; */
6553
6554 if (ctype_isManifestBool (ct)) {
6555 return ctype_bool;
6556 }
6557
6558 if (ctype_isUA (ct))
6559 {
b73d1009 6560 typeId iid = ctype_typeId (ct);
616915dd 6561
b73d1009 6562 if (typeId_equal (iid, uid))
616915dd 6563 {
6564 llcontbug (message ("uentry_getRealType: recursive type! %s",
6565 ctype_unparse (ct)));
6566 return ct;
6567 }
6568 else
6569 {
6570 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
6571 }
6572 }
6573 else
6574 {
6575 return ct;
6576 }
6577}
6578
6579uentry uentry_nameCopy (cstring name, uentry e)
6580{
6581 uentry enew = uentry_alloc ();
6582
6583 llassert (uentry_isValid (e));
6584
6585 /* enew->shallowCopy = FALSE; */
6586 enew->ukind = e->ukind;
6587 enew->uname = name;
6588 enew->utype = e->utype;
6589 enew->whereSpecified = fileloc_copy (e->whereSpecified);
6590 enew->whereDefined = fileloc_copy (e->whereDefined);
6591 enew->whereDeclared = fileloc_copy (e->whereDeclared);
6592 enew->sref = sRef_copy (e->sref);
6593 enew->used = e->used;
6594 enew->lset = FALSE;
6595 enew->isPrivate = e->isPrivate;
6596 enew->hasNameError = FALSE;
6597
6598 enew->uses = filelocList_new ();
28bf4b0b 6599 enew->warn = warnClause_undefined;
616915dd 6600
6601 enew->storageclass = e->storageclass;
6602 enew->info = uinfo_copy (e->info, e->ukind);
6603
6604 return enew;
6605}
6606
6607void
b73d1009 6608uentry_setDatatype (uentry e, typeId uid)
616915dd 6609{
6610 llassert (uentry_isDatatype (e));
6611
6612 if (uentry_isAbstractType (e))
6613 {
e5081f8c 6614 if (qual_isNumAbstract (e->info->datatype->abs))
6615 {
6616 e->info->datatype->type = ctype_createNumAbstract (uid);
6617 }
6618 else
6619 {
6620 llassert (qual_isAbstract (e->info->datatype->abs));
6621 e->info->datatype->type = ctype_createAbstract (uid);
6622 }
616915dd 6623 }
6624 else
6625 {
6626 e->info->datatype->type = ctype_createUser (uid);
6627 }
6628}
6629
6630static void
6631uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
6632 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
6633 /*@modifies e@*/
6634{
6635 llassert (uentry_isValid (e));
6636
6637 if (fileloc_isSpec (f) || fileloc_isImport (f))
6638 {
6639 e->whereSpecified = f;
6640 e->whereDeclared = fileloc_undefined;
6641 e->whereDefined = fileloc_undefined;
6642 }
6643 else
6644 {
6645 e->whereSpecified = fileloc_undefined;
6646 e->whereDeclared = f;
6647 e->whereDefined = fileloc_undefined;
6648 }
7ebcc5bb 6649
6650 llassert (fileloc_storable (f));
616915dd 6651}
6652
6653static void
6654ucinfo_free (/*@only@*/ ucinfo u)
6655{
616915dd 6656 sfree (u);
6657}
6658
6659static void
6660uvinfo_free (/*@only@*/ uvinfo u)
6661{
28bf4b0b 6662 /*drl7x added 6/29/01 */
b072092f 6663 free (u->bufinfo); /* evans - 2001-07-19 fixed this bug */
616915dd 6664 sfree (u);
6665}
6666
6667static void
6668udinfo_free (/*@only@*/ udinfo u)
6669{
6670 sfree (u);
6671}
6672
6673static void
6674ufinfo_free (/*@only@*/ ufinfo u)
6675{
6676 globSet_free (u->globs);
6677 sRefSet_free (u->mods);
28bf4b0b 6678 stateClauseList_free (u->specclauses);
616915dd 6679 sfree (u);
6680}
6681
6682static void
6683uiinfo_free (/*@only@*/ uiinfo u)
6684{
6685 sfree (u);
6686}
6687
6688static void
6689ueinfo_free (/*@only@*/ ueinfo u)
6690{
6691 sfree (u);
6692}
6693
6694static /*@only@*/ ucinfo
6695ucinfo_copy (ucinfo u)
6696{
6697 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
616915dd 6698 ret->access = u->access;
3e3ec469 6699 ret->macro = u->macro;
616915dd 6700 return ret;
6701}
6702
6703static /*@only@*/ uvinfo
6704uvinfo_copy (uvinfo u)
6705{
6706 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
6707
6708 ret->kind = u->kind;
6709 ret->nullstate = u->nullstate;
6710 ret->defstate = u->defstate;
6711 ret->checked = u->checked;
28bf4b0b 6712
b7e84605 6713
28bf4b0b 6714 /* drl added 07-02-001 */
6715 /* copy null terminated information */
6716
6717 if (u->bufinfo != NULL)
6718 {
6719 ret->bufinfo = (bbufinfo) dmalloc (sizeof( * u->bufinfo ) );
6720 ret->bufinfo->bufstate = u->bufinfo->bufstate;
6721 ret->bufinfo->size = u->bufinfo->size;
6722 ret->bufinfo->len = u->bufinfo->len;
6723 return ret;
6724 }
6725 else
6726 {
6727 ret->bufinfo = NULL;
6728 return ret;
6729 }
6730
616915dd 6731}
6732
6733static /*@only@*/ udinfo
6734udinfo_copy (udinfo u)
6735{
6736 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6737
6738 ret->abs = u->abs;
6739 ret->mut = u->mut;
6740 ret->type = u->type;
6741
6742 return ret;
6743}
6744
6745static /*@only@*/ ufinfo
6746ufinfo_copy (ufinfo u)
6747{
6748 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6749
6750 ret->hasGlobs = u->hasGlobs;
6751 ret->hasMods = u->hasMods;
6752 ret->exitCode = u->exitCode;
6753 ret->specialCode = u->specialCode;
6754 ret->nullPred = u->nullPred;
6755 ret->access = u->access;
6756 ret->globs = globSet_newCopy (u->globs);
6757 ret->mods = sRefSet_newCopy (u->mods);
6758 ret->defparams = u->defparams;
28bf4b0b 6759 ret->specclauses = stateClauseList_copy (u->specclauses);
616915dd 6760
3814599d 6761 ret->preconditions = functionConstraint_copy (u->preconditions);
6762 ret->postconditions = functionConstraint_copy (u->postconditions);
616915dd 6763
6764 return ret;
6765}
6766
6767static /*@only@*/ uiinfo
6768uiinfo_copy (uiinfo u)
6769{
6770 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6771
6772 ret->access = u->access;
6773 ret->globs = globSet_newCopy (u->globs);
6774 ret->mods = sRefSet_newCopy (u->mods);
6775
6776 return (ret);
6777}
6778
6779static /*@only@*/ ueinfo
6780ueinfo_copy (ueinfo u)
6781{
6782 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6783
6784 ret->access = u->access;
6785 return ret;
6786}
6787
6788static void
6789uinfo_free (uinfo u, ekind kind)
6790{
6791 switch (kind)
6792 {
6793 case KENUMCONST:
6794 case KCONST: ucinfo_free (u->uconst); break;
6795 case KVAR: uvinfo_free (u->var); break;
6796 case KSTRUCTTAG:
6797 case KUNIONTAG:
6798 case KENUMTAG:
6799 case KDATATYPE: udinfo_free (u->datatype); break;
6800 case KFCN: ufinfo_free (u->fcn); break;
6801 case KITER: uiinfo_free (u->iter); break;
6802 case KENDITER: ueinfo_free (u->enditer); break;
6803 case KELIPSMARKER: break;
6804 case KINVALID: break;
6805 }
6806
6807 sfree (u);
6808}
6809
6810static /*@only@*/ /*@null@*/ uinfo
6811uinfo_copy (uinfo u, ekind kind)
6812{
6813 if (kind == KELIPSMARKER || kind == KINVALID)
6814 {
6815 return NULL;
6816 }
6817 else
6818 {
6819 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6820
6821 switch (kind)
6822 {
6823 case KENUMCONST:
6824 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6825 case KVAR: ret->var = uvinfo_copy (u->var); break;
6826 case KSTRUCTTAG:
6827 case KUNIONTAG:
6828 case KENUMTAG:
6829 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6830 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6831 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6832 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6833 BADDEFAULT;
6834 }
6835 return ret;
6836 }
6837}
6838
6839static void
6840uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6841{
6842 filelocList_free (e->uses);
6843 cstring_free (e->uname);
6844
6845 uinfo_free (e->info, e->ukind);
6846
6847 fileloc_free (e->whereSpecified);
6848 fileloc_free (e->whereDefined);
6849 fileloc_free (e->whereDeclared);
6850
28bf4b0b 6851 warnClause_free (e->warn);
6852
616915dd 6853 nuentries--;
6854 sfree (e);
6fcd0b1e 6855}
616915dd 6856
6857extern void uentry_markOwned (/*@owned@*/ uentry u)
6858{
6859 sfreeEventually (u);
6860}
6861
6862void
6863uentry_free (/*@only@*/ uentry e)
6864{
6865 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6866 {
6867 uentry_reallyFree (e);
6868 }
6869}
6870
6871/*
6872** For uentry's in the global or file scope
6873*/
6874
6875void
6876uentry_freeComplete (/*@only@*/ uentry e)
6877{
6878 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6879 {
28bf4b0b 6880 DPRINTF (("Free complete: %s", sRef_unparseFull (e->sref)));
616915dd 6881 /*@i@*/ sRef_free (e->sref);
6882 e->sref = sRef_undefined;
6883 uentry_reallyFree (e);
6884 }
6885}
6886
6887/*
6888** requires old->kind != new->kind, old->uname = new->uname
6889*/
6890
6891static void
6892KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6893{
6894 llassert (uentry_isValid (old));
6895 llassert (uentry_isValid (unew));
6896
ce7034f0 6897 if ((uentry_isEitherConstant (unew) || uentry_isDatatype (unew))
616915dd 6898 && (fileloc_isPreproc (uentry_whereDeclared (old))
6899 || ctype_isUnknown (old->utype))
6900 && !uentry_isSpecified (old))
6901 {
6902 ; /* no error */
6903 }
6904 else
6905 {
6906 if (mustConform)
6907 {
6908 if (!uentry_isDeclared (old))
6909 {
6910 if (uentry_isSpecified (old))
6911 {
6912 if (uentry_isSpecified (unew))
6913 {
6914 llbuglit ("Respecification!");
6915 }
6916 else if (uentry_isDeclared (unew))
6917 {
6918 if (optgenerror
6919 (FLG_INCONDEFS,
6920 message ("%s %q inconsistently declared as %s: %t",
6921 ekind_capName (old->ukind),
6922 uentry_getName (unew),
6923 ekind_unparseLong (unew->ukind),
6924 unew->utype),
f2b6724f 6925 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
616915dd 6926 {
f2b6724f 6927 uentry_showWhereLastKind (old);
616915dd 6928 }
6929 }
6930 else
6931 {
6932 BADEXIT;
6933 }
6934 }
6935 else
6936 {
6937 if (optgenerror
6938 (FLG_INCONDEFS,
6939 message ("%s %q inconsistently declared as %s: %t",
6940 ekind_capName (old->ukind),
6941 uentry_getName (unew),
6942 ekind_unparseLong (unew->ukind),
6943 unew->utype),
f2b6724f 6944 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
616915dd 6945 {
f2b6724f 6946 uentry_showWhereLastKind (old);
616915dd 6947 }
6948 }
6949 }
6950 else
6951 {
6952 llassert (uentry_isDeclared (unew));
6953
f2b6724f 6954 DPRINTF (("Old: \n\t%s", uentry_unparseFull (old)));
6955 DPRINTF (("New: \n\t%s", uentry_unparseFull (unew)));
6956
616915dd 6957 if (optgenerror
6958 (FLG_INCONDEFS,
6959 message ("%s %q inconsistently redeclared as %s",
6960 ekind_capName (old->ukind),
6961 uentry_getName (unew),
6962 ekind_unparseLong (unew->ukind)),
f2b6724f 6963 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
616915dd 6964 {
f2b6724f 6965 uentry_showWhereLastKind (old);
616915dd 6966 }
6967 }
6968 }
6969 }
6970
efd360a3 6971 uentry_updateInto (old, unew);
616915dd 6972}
6973
6974/*
6975** def is the definition of spec, modifies spec
6976**
6977** reports any inconsistencies
6978** returns the summary of all available information
6979** if spec and def are inconsistent, def is returned
6980*/
6981
6982void
6983uentry_showWhereLast (uentry spec)
6984{
6985 if (uentry_isValid (spec))
6986 {
6987 if (fileloc_isDefined (spec->whereDefined)
6988 && !fileloc_isLib (spec->whereDefined)
f2b6724f 6989 /*!! && !fileloc_isPreproc (spec->whereDefined) */ )
616915dd 6990 {
6991 llgenindentmsg (message ("Previous definition of %q: %t",
6992 uentry_getName (spec),
6993 uentry_getType (spec)),
6994 uentry_whereDefined (spec));
6995 }
6996 else if (uentry_isDeclared (spec))
6997 {
6998 llgenindentmsg (message ("Previous declaration of %q: %t",
6999 uentry_getName (spec),
7000 uentry_getType (spec)),
7001 uentry_whereDeclared (spec));
7002 }
7003 else if (uentry_isSpecified (spec))
7004 {
7005 if (uentry_hasName (spec))
7006 {
7007 llgenindentmsg (message ("Specification of %q: %t",
7008 uentry_getName (spec),
7009 uentry_getType (spec)),
7010 uentry_whereSpecified (spec));
7011 }
7012 else
7013 {
7014 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
7015 uentry_whereSpecified (spec));
7016 }
7017 }
7018 else
7019 {
7020 /* nothing to show */
7021 }
7022 }
7023}
7024
f2b6724f 7025static void
7026uentry_showWhereLastKind (uentry spec)
7027{
7028 if (uentry_isValid (spec))
7029 {
7030 if (fileloc_isDefined (spec->whereDefined)
7031 && !fileloc_isLib (spec->whereDefined)
7032 /*!! && !fileloc_isPreproc (spec->whereDefined) */ )
7033 {
7034 llgenindentmsg (message ("Previous definition of %q as %s: %t",
7035 uentry_getName (spec),
7036 ekind_unparseLong (spec->ukind),
7037 uentry_getType (spec)),
7038 uentry_whereDefined (spec));
7039 }
7040 else if (uentry_isDeclared (spec))
7041 {
7042 llgenindentmsg (message ("Previous declaration of %q as %s: %t",
7043 uentry_getName (spec),
7044 ekind_unparseLong (spec->ukind),
7045 uentry_getType (spec)),
7046 uentry_whereDeclared (spec));
7047 }
7048 else if (uentry_isSpecified (spec))
7049 {
7050 if (uentry_hasName (spec))
7051 {
7052 llgenindentmsg (message ("Specification of %q as %s: %t",
7053 uentry_getName (spec),
7054 ekind_unparseLong (spec->ukind),
7055 uentry_getType (spec)),
7056 uentry_whereSpecified (spec));
7057 }
7058 else
7059 {
7060 llgenindentmsg (message ("Specification as %s: %t",
7061 ekind_unparseLong (spec->ukind),
7062 uentry_getType (spec)),
7063 uentry_whereSpecified (spec));
7064 }
7065 }
7066 else
7067 {
7068 /* nothing to show */
7069 }
7070 }
7071}
7072
616915dd 7073void
7074uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
7075{
7076 fileloc loc = uentry_whereDefined (ce);
7077
7078 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
7079 {
7080 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
7081 loc);
7082 }
7083
7084 loc = uentry_whereSpecified (ce);
7085
7086 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
7087 {
7088 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
7089 loc);
7090 }
7091}
7092
7093void uentry_showWhereLastExtra (uentry spec, cstring extra)
7094{
7095 if (uentry_isDeclared (spec))
7096 {
7097 llgenindentmsg (message ("Previous declaration of %q: %q",
7098 uentry_getName (spec), extra),
7099 uentry_whereDeclared (spec));
7100 }
7101 else if (uentry_isSpecified (spec))
7102 {
7103 llgenindentmsg (message ("Specification of %q: %q",
7104 uentry_getName (spec), extra),
7105 uentry_whereSpecified (spec));
7106 }
7107 else
7108 {
7109 cstring_free (extra);
7110 }
7111}
7112
7113void
7114uentry_showWhereDeclared (uentry spec)
7115{
7116 if (uentry_isDeclared (spec))
7117 {
7118 if (uentry_hasName (spec))
7119 {
7120 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7121 uentry_whereDeclared (spec));
7122 }
7123 else
7124 {
7125 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
7126 }
7127 }
7128 else if (uentry_isSpecified (spec))
7129 {
7130 if (uentry_hasName (spec))
7131 {
7132 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7133 uentry_whereSpecified (spec));
7134 }
7135 else
7136 {
7137 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
7138 }
7139 }
7140 else
7141 {
7142 /* nothing to show */
7143 }
7144
7145}
7146
7147void
7148uentry_showWhereAny (uentry spec)
7149{
7150 if (uentry_isDeclared (spec))
7151 {
7152 if (uentry_hasName (spec))
7153 {
7154 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7155 uentry_whereDeclared (spec));
7156 }
7157 else
7158 {
7159 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
7160 }
7161 }
7162 else if (uentry_isSpecified (spec))
7163 {
7164 if (uentry_hasName (spec))
7165 {
7166 llgenindentmsg (message ("Specification of %q",
7167 uentry_getName (spec)),
7168 uentry_whereSpecified (spec));
7169 }
7170 else
7171 {
7172 llgenindentmsg (cstring_makeLiteral ("Specification"),
7173 uentry_whereSpecified (spec));
7174 }
7175 }
7176 else if (fileloc_isDefined (uentry_whereDefined (spec)))
7177 {
7178 if (uentry_hasName (spec))
7179 {
7180 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
7181 uentry_whereDefined (spec));
7182 }
7183 else
7184 {
7185 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
7186 }
7187 }
7188 else
7189 {
7190 /* nothing to show */
7191 }
7192}
7193
7194void
7195uentry_showWhereDefined (uentry spec)
7196{
7197 if (uentry_isCodeDefined (spec))
7198 {
7199 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
7200 uentry_whereDefined (spec));
7201 }
7202}
7203
7204void
7205uentry_showWhereLastPlain (uentry spec)
7206{
7207 if (uentry_isDeclared (spec))
7208 {
7209 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
7210 uentry_whereDeclared (spec));
7211 }
7212 else if (uentry_isSpecified (spec))
7213 {
7214 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7215 uentry_whereSpecified (spec));
7216 }
7217 else
7218 {
7219 }
7220}
7221
7222static void
7223uentry_showWhereLastVal (uentry spec, cstring val)
7224{
7225 if (uentry_isDeclared (spec))
7226 {
7227 llgenindentmsg (message ("Previous declaration of %q: %s",
7228 uentry_getName (spec), val),
7229 uentry_whereDeclared (spec));
7230 }
7231 else if (uentry_isSpecified (spec))
7232 {
7233 llgenindentmsg (message ("Specification of %q: %s",
7234 uentry_getName (spec), val),
7235 uentry_whereSpecified (spec));
7236 }
7237 else
7238 {
7239 }
7240}
7241
7242void
7243uentry_showWhereSpecified (uentry spec)
7244{
7245 if (uentry_isSpecified (spec))
7246 {
7247 if (uentry_hasName (spec))
7248 {
7249 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7250 uentry_whereSpecified (spec));
7251 }
7252 else
7253 {
7254 llgenindentmsg (cstring_makeLiteral ("Specification"),
7255 uentry_whereSpecified (spec));
7256 }
7257 }
7258 else if (uentry_isDeclared (spec))
7259 {
7260 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7261 uentry_whereDeclared (spec));
7262 }
7263 else
7264 {
7265 /* nothing to show */
7266 }
7267}
7268
7269void
7270uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
7271{
7272 if (uentry_isSpecified (spec))
7273 {
7274 if (uentry_hasName (spec))
7275 {
7276 llgenindentmsg (message ("Specification of %q: %q",
7277 uentry_getName (spec), s),
7278 uentry_whereSpecified (spec));
7279 }
7280 else
7281 {
7282 llgenindentmsg (message ("Specification: %q", s),
7283 uentry_whereSpecified (spec));
7284 }
7285 }
7286 else if (uentry_isDeclared (spec))
7287 {
7288 llgenindentmsg (message ("Declaration of %q: %q",
7289 uentry_getName (spec), s),
7290 uentry_whereDeclared (spec));
7291 }
7292 else
7293 {
7294 llgenindentmsg (message ("Previous: %q", s),
7295 uentry_whereLast (spec));
7296 }
7297}
7298
7299/*
7300**
7301*/
7302
7303static void
7304checkStructConformance (uentry old, uentry unew)
7305{
7306 ctype oldr, newr;
7307 uentryList fold, fnew;
7308
7309 /*
7310 ** requires: types of old and new are structs or unions
7311 */
7312
7313 llassert (uentry_isValid (old));
7314 llassert (uentry_isValid (unew));
7315
7316 oldr = ctype_realType (old->utype);
7317 fold = ctype_getFields (oldr);
7318
7319 newr = ctype_realType (unew->utype);
7320 fnew = ctype_getFields (newr);
7321
7322 if (!uentryList_matchFields (fold, fnew))
7323 {
7324 if (fileloc_equal (uentry_whereLast (old),
7325 uentry_whereLast (unew)))
7326 {
7327 ; /* cheat! */
7328 }
7329 else
7330 {
7331 if (optgenerror
7332 (FLG_MATCHFIELDS,
7333 message ("%q %q %rdeclared with fields { %q }, %s "
7334 "with fields { %q }",
7335 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
7336 uentry_getName (old),
7337 uentry_isDeclared (old),
7338 uentryList_unparseAbbrev (fnew),
7339 uentry_specOrDefName (old),
7340 uentryList_unparseAbbrev (fold)),
7341 uentry_whereDeclared (unew)))
7342 {
7343 uentry_showWhereLastPlain (old);
7344 uentryList_showFieldDifference (fold, fnew);
7345 }
7346 }
7347
7348 old->utype = unew->utype;
7349 }
7350}
7351
7352static void
7353checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7354{
7355 /*
7356 ** requires old and new are enums
7357 */
7358
7359 ctype rold = ctype_realType (old->utype);
7360 ctype rnew = ctype_realType (unew->utype);
7361 enumNameList eold = ctype_elist (rold);
7362 enumNameList enew = ctype_elist (rnew);
7363
7364 if (!enumNameList_match (eold, enew))
7365 {
7366 if (optgenerror
7367 (FLG_MATCHFIELDS,
7368 message ("Enum %q declared with members { %q } but "
140c27a8 7369 "%s with members { %q }",
616915dd 7370 uentry_getName (old),
7371 enumNameList_unparse (enew),
140c27a8 7372 uentry_specOrDefName (old),
616915dd 7373 enumNameList_unparse (eold)),
7374 uentry_whereDeclared (unew)))
7375 {
7376 uentry_showWhereSpecified (old);
7377 old->utype = unew->utype;
7378 }
7379 }
7380}
7381
7382/*
7383** either oldCurrent or newCurrent may be undefined!
7384*/
7385
7386static void
7387paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
7388 uentry unew, uentry newCurrent, ctype newType,
7389 int paramno)
7390{
7391 bool hasError = FALSE;
7392
7393 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
7394 {
7395 if (uentry_hasName (newCurrent))
7396 {
7397 hasError = optgenerror
7398 (FLG_TYPE,
7399 message ("Parameter %d, %q, of function %q has inconsistent type: "
7400 "declared %t, %s %t",
7401 paramno + 1, uentry_getName (newCurrent),
7402 uentry_getName (unew),
7403 newType, uentry_specOrDefName (old), oldType),
7404 uentry_whereDeclared (newCurrent));
7405 }
7406 else
7407 {
7408 hasError = optgenerror
7409 (FLG_TYPE,
7410 message ("Parameter %d of function %q has inconsistent type: "
7411 "declared %t, %s %t",
7412 paramno + 1, uentry_getName (unew),
7413 newType, uentry_specOrDefName (old), oldType),
7414 uentry_whereDeclared (newCurrent));
7415
7416 DPRINTF (("type: %s / %s",
7417 ctype_unparse (newType),
7418 ctype_unparse (ctype_realType (newType))));
7419 }
7420 }
7421 else
7422 {
7423 if (uentry_isDeclared (unew))
7424 {
7425 hasError = optgenerror
7426 (FLG_TYPE,
7427 message ("Parameter %d of function %s has inconsistent type: "
7428 "declared %t, %s %t",
7429 paramno + 1, unew->uname,
7430 newType, uentry_specOrDefName (old), oldType),
7431 uentry_whereDeclared (unew));
7432 }
7433 else
7434 {
7435 hasError = optgenerror
7436 (FLG_TYPE,
7437 message ("Parameter %d of function %s has inconsistent type: "
7438 "declared %t, %s %t",
7439 paramno + 1, unew->uname,
7440 newType, uentry_specOrDefName (old), oldType),
7441 uentry_whereDeclared (unew));
7442 }
7443 }
7444
7445 if (hasError)
7446 {
6970c11b 7447 DPRINTF (("Here: %s / %s",
7448 uentry_unparseFull (oldCurrent),
7449 uentry_unparseFull (newCurrent)));
7450
616915dd 7451 if (!uentry_isUndefined (oldCurrent))
7452 {
7453 if (!uentry_isUndefined (newCurrent)
7454 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
7455 {
7456 uentry_showWhereLast (oldCurrent);
7457 }
7458 else
7459 {
7460 uentry_showWhereLastPlain (old);
7461 }
7462
7463 uentry_setType (oldCurrent, newType);
7464 }
7465 else
7466 {
7467 uentry_showWhereLastPlain (old);
7468 }
7469 }
7470}
7471
7472static void
7473nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7474{
7475 if (optgenerror
7476 (FLG_TYPE,
28bf4b0b 7477 message ("Function %s %rdeclared with %d arg%&, %s with %d",
616915dd 7478 unew->uname,
7479 uentry_isDeclared (old),
7480 uentryList_size (uentry_getParams (unew)),
7481 uentry_specOrDefName (old),
7482 uentryList_size (uentry_getParams (old))),
7483 uentry_whereDeclared (unew)))
7484 {
7485 uentry_showWhereLastPlain (old);
7486 }
7487}
7488
7489static void
7490returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7491{
7492 if (optgenerror
7493 (FLG_INCONDEFS,
7494 message ("Function %s inconsistently %rdeclared to return %t",
7495 unew->uname,
7496 uentry_isDeclared (old),
28bf4b0b 7497 ctype_getReturnType (unew->utype)),
616915dd 7498 uentry_whereDeclared (unew)))
7499 {
28bf4b0b 7500 uentry_showWhereLastVal (old, ctype_unparse (ctype_getReturnType (old->utype)));
616915dd 7501 }
7502}
7503
7504static cstring paramStorageName (uentry ue)
7505{
7506 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
7507}
7508
7509static cstring fcnErrName (uentry ue)
7510{
7511 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
7512}
7513
7514extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
7515{
7516 if (uentry_isVar (ue))
7517 {
7518 return (checkedName (ue->info->var->checked));
7519 }
7520 else
7521 {
7522 return (cstring_makeLiteralTemp ("<checked invalid>"));
7523 }
7524}
7525
7526static cstring checkedName (chkind checked)
7527{
7528 switch (checked)
7529 {
7530 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
7531 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
7532 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
7533 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
7534 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
7535 }
7536 BADEXIT;
7537}
7538
7539static
7540void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
7541{
7542 nstate oldState;
7543 nstate newState;
7544
7545 if (uentry_isVar (unew))
7546 {
7547 llassert (uentry_isVar (old));
7548
7549 oldState = old->info->var->nullstate;
7550 newState = unew->info->var->nullstate;
7551 }
7552 else
7553 {
7554 oldState = sRef_getNullState (old->sref);
7555 newState = sRef_getNullState (unew->sref);
7556 }
7557
7558 if (oldState == NS_ABSNULL)
7559 {
7560 if (uentry_isVar (old))
7561 {
7562 old->info->var->nullstate = newState;
7563 }
7564
7565 sRef_mergeNullState (old->sref, newState);
7566 }
7567 else if (newState == NS_UNKNOWN)
7568 {
7569 if (completeConform && newState != oldState
7570 && uentry_isReallySpecified (old))
7571 {
7572 if (optgenerror
7573 (FLG_NEEDSPEC,
7574 message ("%s %q specified as %s, but declared without %s qualifier",
7575 ekind_capName (unew->ukind),
7576 uentry_getName (unew),
7577 nstate_unparse (oldState),
7578 nstate_unparse (oldState)),
7579 uentry_whereDeclared (unew)))
7580 {
7581 uentry_showWhereSpecified (old);
7582 }
7583 }
7584
7585 if (uentry_isVar (unew))
7586 {
7587 unew->info->var->nullstate = oldState;
7588 }
7589
7590 sRef_mergeNullState (unew->sref, oldState);
7591 }
7592 else if (newState == NS_POSNULL)
7593 {
7594 if (oldState == NS_MNOTNULL
7595 && (ctype_isUA (unew->utype)
7596 || (uentry_isFunction (unew)
28bf4b0b 7597 && ctype_isUA (ctype_getReturnType (unew->utype)))))
616915dd 7598 {
7599 if (uentry_isVar (unew))
7600 {
7601 unew->info->var->nullstate = oldState;
7602 }
7603
7604 sRef_mergeNullState (unew->sref, oldState);
7605 }
7606 else
7607 {
7608 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
7609 || oldState == NS_UNKNOWN)
7610 {
7611 if (mustConform)
7612 {
7613 if (optgenerror
7614 (FLG_INCONDEFS,
7615 message
7616 ("%s %q inconsistently %rdeclared %s possibly null storage, "
7617 "%s %q qualifier",
7618 uentry_ekindName (unew),
7619 uentry_getName (unew),
7620 uentry_isDeclared (old),
7621 fcnErrName (unew),
7622 uentry_specOrDefName (old),
7623 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
7624 uentry_whereDeclared (unew)))
7625 {
7626 uentry_showWhereSpecified (old);
7627 }
7628 }
7629 }
7630
7631 if (uentry_isVar (old))
7632 {
7633 old->info->var->nullstate = newState;
7634 }
7635
7636 sRef_mergeNullState (old->sref, newState);
7637 }
7638 }
7639 else if (newState == NS_MNOTNULL)
7640 {
7641 if (oldState != NS_MNOTNULL)
7642 {
7643 if (mustConform)
7644 {
7645 if (optgenerror
7646 (FLG_INCONDEFS,
7647 message ("%s %q inconsistently %rdeclared %s notnull storage, "
7648 "%s without notnull qualifier",
7649 uentry_ekindName (unew),
7650 uentry_getName (unew),
7651 uentry_isDeclared (old),
7652 fcnErrName (unew),
7653 uentry_specOrDefName (old)),
7654 uentry_whereDeclared (unew)))
7655 {
7656 uentry_showWhereSpecified (old);
7657 }
7658 }
7659
7660 if (uentry_isVar (old))
7661 {
7662 old->info->var->nullstate = newState;
7663 }
7664
7665 sRef_mergeNullState (old->sref, newState);
7666 }
7667 }
7668 else
7669 {
7670 if (uentry_isVar (unew))
7671 {
7672 unew->info->var->nullstate = oldState;
7673 }
7674
7675 sRef_mergeNullState (unew->sref, oldState);
7676 }
7677}
7678
7679static
7680void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7681 bool mustConform, bool completeConform)
7682{
7683 sstate oldState;
7684 sstate newState;
7685 bool vars = FALSE;
7686
7687 if (uentry_isVar (old) && uentry_isVar (unew))
7688 {
7689 oldState = old->info->var->defstate;
7690 newState = unew->info->var->defstate;
7691 vars = TRUE;
7692 }
7693 else
7694 {
7695 oldState = sRef_getDefState (old->sref);
7696 newState = sRef_getDefState (unew->sref);
7697 }
7698
28bf4b0b 7699 if (newState != oldState
7700 && newState != SS_UNKNOWN
7701 && newState != SS_DEFINED)
616915dd 7702 {
7703 if (mustConform)
7704 {
7705 if (optgenerror
7706 (FLG_INCONDEFS,
7707 message ("%s %q inconsistently %rdeclared %s %s %s, "
7708 "%s %s %s %s",
7709 uentry_ekindName (unew),
7710 uentry_getName (unew),
7711 uentry_isDeclared (old),
7712 fcnErrName (unew),
7713 sstate_unparse (newState),
7714 paramStorageName (unew),
7715 uentry_specOrDefName (old),
7716 fcnErrName (unew),
7717 sstate_unparse (oldState),
7718 paramStorageName (unew)),
7719 uentry_whereDeclared (unew)))
7720 {
7721 uentry_showWhereSpecified (old);
7722 }
7723 }
28bf4b0b 7724
616915dd 7725 if (vars) old->info->var->defstate = newState;
7726 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
7727 }
7728 else
7729 {
7730 if (completeConform
7731 && (newState != oldState) && (oldState != SS_DEFINED)
7732 && uentry_isReallySpecified (old))
7733 {
7734 if (optgenerror
7735 (FLG_NEEDSPEC,
7736 message ("%s %q specified as %s, but declared without %s qualifier",
7737 ekind_capName (unew->ukind),
7738 uentry_getName (unew),
7739 sstate_unparse (oldState),
7740 sstate_unparse (oldState)),
7741 uentry_whereDeclared (unew)))
7742 {
7743 uentry_showWhereSpecified (old);
7744 }
7745 }
28bf4b0b 7746
616915dd 7747 if (vars) unew->info->var->defstate = oldState;
7748 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
7749 }
7750}
7751
7752static void
7753 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7754 bool mustConform, bool completeConform)
7755{
7756 alkind newKind;
7757 alkind oldKind;
7758
7759 oldKind = sRef_getAliasKind (old->sref);
7760 newKind = sRef_getAliasKind (unew->sref);
7761
7762 if (alkind_isImplicit (newKind)
7763 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
7764 {
7765 if (completeConform && !alkind_equal (newKind, oldKind)
7766 && uentry_isReallySpecified (old))
7767 {
7768 if (optgenerror
7769 (FLG_NEEDSPEC,
7770 message ("%s %q specified as %s, but declared without "
7771 "explicit alias qualifier",
7772 ekind_capName (unew->ukind),
7773 uentry_getName (unew),
7774 alkind_unparse (oldKind)),
7775 uentry_whereDeclared (unew)))
7776 {
7777 uentry_showWhereSpecified (old);
7778 }
7779 }
7780
7781 /*
7782 ** This really shouldn't be necessary, but it is!
7783 ** Function params (?) use new here.
7784 */
7785
7786 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7787 return;
7788 }
7789
7790 if (alkind_isKnown (newKind))
7791 {
7792 if (!alkind_equal (oldKind, newKind))
7793 {
7794 if (alkind_isKnown (oldKind))
7795 {
7796 if (mustConform &&
7797 optgenerror
7798 (FLG_INCONDEFS,
7799 message ("%s %q inconsistently %rdeclared %s %s storage, "
7800 "%s as %s storage",
7801 uentry_ekindName (unew),
7802 uentry_getName (unew),
7803 uentry_isDeclared (old),
7804 fcnErrName (unew),
7805 alkind_unparse (newKind),
7806 uentry_specOrDefName (old),
7807 alkind_unparse (oldKind)),
7808 uentry_whereDeclared (unew)))
7809 {
7810 uentry_showWhereSpecified (old);
7811
28bf4b0b 7812 DPRINTF (("Old: %s", sRef_unparseFull (old->sref)));
7813 DPRINTF (("New: %s", sRef_unparseFull (unew->sref)));
616915dd 7814 sRef_setAliasKind (old->sref, AK_ERROR,
7815 uentry_whereDeclared (unew));
7816 }
7817 else
7818 {
7819 sRef_setAliasKind (old->sref, newKind,
7820 uentry_whereDeclared (unew));
7821 }
7822 }
7823 else
7824 {
7825 if (!(alkind_isImplicit (newKind)))
7826 {
7827 if (mustConform &&
7828 !uentry_isFunction (unew) &&
7829 optgenerror
7830 (FLG_INCONDEFS,
7831 message ("%s %q inconsistently %rdeclared %s %s storage, "
7832 "implicitly %s as temp storage",
7833 uentry_ekindName (unew),
7834 uentry_getName (unew),
7835 uentry_isDeclared (old),
7836 fcnErrName (unew),
7837 alkind_unparse (newKind),
7838 uentry_specOrDefName (old)),
7839 uentry_whereDeclared (unew)))
7840 {
7841 uentry_showWhereSpecified (old);
7842 oldKind = AK_ERROR;
7843 }
7844
7845 sRef_setAliasKind (old->sref, newKind,
7846 uentry_whereDeclared (unew));
7847 }
7848 else /* newKind is temp or refcounted */
7849 {
7850 ;
7851 }
7852 }
7853 }
7854 }
7855 else /* newKind unknown */
7856 {
7857 ;
7858 }
7859}
7860
7861static void
7862 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7863 bool mustConform, bool completeConform)
7864{
7865 exkind newKind;
7866 exkind oldKind;
7867
7868 oldKind = sRef_getExKind (old->sref);
7869 newKind = sRef_getExKind (unew->sref);
7870
7871 if (exkind_isKnown (newKind))
7872 {
7873 if (oldKind != newKind)
7874 {
7875 if (exkind_isKnown (oldKind))
7876 {
7877 if (mustConform &&
7878 optgenerror
7879 (FLG_INCONDEFS,
7880 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7881 uentry_ekindName (unew),
7882 uentry_getName (unew),
7883 uentry_isDeclared (old),
7884 fcnErrName (unew),
7885 exkind_unparse (newKind),
7886 uentry_specOrDefName (old),
7887 exkind_unparse (oldKind)),
7888 uentry_whereDeclared (unew)))
7889 {
7890 uentry_showWhereSpecified (old);
7891 }
7892
7893 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7894 }
7895 else
7896 {
7897 if (mustConform &&
7898 optgenerror
7899 (FLG_INCONDEFS,
7900 message ("%s %q inconsistently %rdeclared %s %s, "
7901 "implicitly %s without exposure qualifier",
7902 uentry_ekindName (unew),
7903 uentry_getName (unew),
7904 uentry_isDeclared (old),
7905 fcnErrName (unew),
7906 exkind_unparse (newKind),
7907 uentry_specOrDefName (old)),
7908 uentry_whereDeclared (unew)))
7909 {
7910 uentry_showWhereSpecified (old);
7911 }
7912
7913 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7914 }
7915 }
7916 }
7917 else
7918 {
7919 if (completeConform && exkind_isKnown (oldKind)
7920 && uentry_isReallySpecified (old))
7921 {
7922 if (optgenerror
7923 (FLG_NEEDSPEC,
7924 message ("%s %q specified as %s, but declared without "
7925 "exposure qualifier",
7926 ekind_capName (unew->ukind),
7927 uentry_getName (unew),
7928 exkind_unparse (oldKind)),
7929 uentry_whereDeclared (unew)))
7930 {
7931 uentry_showWhereSpecified (old);
7932 }
7933 }
7934
7935 /* yes, this is necessary! (if its a param) */
7936 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7937 }
7938}
7939
28bf4b0b 7940static void
7941checkMetaState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7942 bool mustConform, /*@unused@*/ bool completeConform)
7943{
7944 valueTable newvals = sRef_getValueTable (unew->sref);
7945
7946 if (valueTable_isDefined (newvals))
7947 {
7948 DPRINTF (("Check meta state: %s -> %s",
7949 uentry_unparseFull (old),
7950 uentry_unparseFull (unew)));
7951
7952 DPRINTF (("Check meta state refs: %s -> %s",
7953 sRef_unparseFull (old->sref),
7954 sRef_unparseFull (unew->sref)));
7955
7956 DPRINTF (("Value table: %s", valueTable_unparse (newvals)));
7957
7958 /*
7959 ** Copy the new values into the old ref
7960 */
7961
7962 valueTable_elements (newvals, key, newval)
7963 {
7964 metaStateInfo msinfo = context_lookupMetaStateInfo (key);
7965 stateValue oldval = sRef_getMetaStateValue (old->sref, key);
7966
7967 llassert (metaStateInfo_isDefined (msinfo));
7968
7969 if (stateValue_isUndefined (oldval))
7970 {
7971 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7972 }
7973 else
7974 {
7975 if (stateValue_isError (oldval))
7976 {
7977 if (!stateValue_isError (newval))
7978 {
7979 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7980 }
7981 else
7982 {
7983 ; /* No change necessary. */
7984 }
7985 }
7986 else
7987 {
7988 if (stateValue_getValue (newval) != stateValue_getValue (oldval))
7989 {
7990 if (fileloc_isXHFile (uentry_whereDeclared (unew)))
7991 {
7992 ;
7993 }
7994 else
7995 {
ccf0a4a8 7996 if (!stateValue_isError (newval)
7997 && !stateValue_isImplicit (newval))
28bf4b0b 7998 {
ccf0a4a8 7999 if (uentry_hasName (unew)
8000 || !sRef_isParam (uentry_getSref (unew)))
8001 {
8002 if (mustConform
8003 && optgenerror
8004 (FLG_INCONDEFS,
8005 message ("%s %q inconsistently %rdeclared %s %q, %s as %q",
8006 uentry_ekindName (unew),
8007 uentry_getName (unew),
8008 uentry_isDeclared (old),
8009 fcnErrName (unew),
8010 stateValue_unparseValue (newval, msinfo),
8011 uentry_specOrDefName (old),
8012 stateValue_unparseValue (oldval, msinfo)),
8013 uentry_whereDeclared (unew)))
8014 {
8015 uentry_showWhereSpecified (old);
8016 }
8017 }
8018 else
abb1cb43 8019 {
ccf0a4a8 8020 if (mustConform
8021 && optgenerror
8022 (FLG_INCONDEFS,
8023 message ("%s %d inconsistently %rdeclared %s %q, %s as %q",
8024 uentry_ekindName (unew),
8025 sRef_getParam (uentry_getSref (unew)),
8026 uentry_isDeclared (old),
8027 fcnErrName (unew),
8028 stateValue_unparseValue (newval, msinfo),
8029 uentry_specOrDefName (old),
8030 stateValue_unparseValue (oldval, msinfo)),
8031 uentry_whereDeclared (unew)))
8032 {
8033 uentry_showWhereSpecified (old);
8034 }
abb1cb43 8035 }
28bf4b0b 8036 }
8037 }
8038
8039 DPRINTF (("Updating!"));
8040 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
8041 }
8042 else
8043 {
8044 DPRINTF (("Values match"));
8045 }
8046 }
8047 }
8048 } end_valueTable_elements ;
8049 }
8050}
8051
616915dd 8052static void
8053uentry_checkStateConformance (/*@notnull@*/ uentry old,
8054 /*@notnull@*/ uentry unew,
8055 bool mustConform, bool completeConform)
8056{
8057 checkDefState (old, unew, mustConform, completeConform);
8058 checkNullState (old, unew, mustConform, completeConform);
8059 checkAliasState (old, unew, mustConform, completeConform);
8060 checkExpState (old, unew, mustConform, completeConform);
28bf4b0b 8061 checkMetaState (old, unew, mustConform, completeConform);
616915dd 8062
8063 sRef_storeState (old->sref);
8064 sRef_storeState (unew->sref);
8065}
8066
8067static void
8068checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
8069{
8070 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
8071 {
8072 return;
8073 }
8074
8075 llassert (uentry_isVar (old));
8076 llassert (uentry_isVar (unew));
8077
8078 if (cstring_isEmpty (old->uname))
8079 {
8080 cstring_free (old->uname);
8081 old->uname = cstring_copy (unew->uname);
8082 }
8083
8084 if (unew->info->var->kind == VKRETPARAM
8085 || unew->info->var->kind == VKSEFRETPARAM)
8086 {
8087 if (old->info->var->kind != VKRETPARAM
8088 && old->info->var->kind != VKSEFRETPARAM)
8089 {
8090 if (optgenerror
8091 (FLG_INCONDEFS,
8092 message ("Parameter %q inconsistently %rdeclared as "
8093 "returned parameter",
8094 uentry_getName (unew),
8095 uentry_isDeclared (old)),
8096 uentry_whereDeclared (unew)))
8097 {
8098 uentry_showWhereSpecified (old);
8099 old->info->var->kind = unew->info->var->kind;
8100 }
8101 }
8102 }
8103
8104
8105 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
8106 {
8107 if (old->info->var->kind != VKSEFPARAM
8108 && old->info->var->kind != VKSEFRETPARAM)
8109 {
8110 if (optgenerror
8111 (FLG_INCONDEFS,
8112 message ("Parameter %qinconsistently %rdeclared as "
8113 "sef parameter",
8114 uentry_getOptName (unew),
8115 uentry_isDeclared (old)),
8116 uentry_whereDeclared (unew)))
8117 {
8118 uentry_showWhereSpecified (old);
8119 old->info->var->kind = unew->info->var->kind;
8120 }
8121 }
8122 }
8123
8124 if (old->info->var->kind == VKSPEC)
8125 {
8126 old->info->var->kind = unew->info->var->kind;
8127 }
8128 else
8129 {
8130 unew->info->var->kind = old->info->var->kind;
8131 }
8132
8133 if (unew->info->var->checked != CH_UNKNOWN
8134 && unew->info->var->checked != old->info->var->checked)
8135 {
8136 if (old->info->var->checked == CH_UNKNOWN
8137 && !fileloc_isUser (uentry_whereLast (old)))
8138 {
8139 ; /* no error */
8140 }
8141 else
8142 {
8143 if (optgenerror
8144 (FLG_INCONDEFS,
8145 message ("Variable %q inconsistently %rdeclared as "
8146 "%s parameter (was %s)",
8147 uentry_getName (unew),
8148 uentry_isDeclared (old),
8149 checkedName (unew->info->var->checked),
8150 checkedName (old->info->var->checked)),
8151 uentry_whereDeclared (unew)))
8152 {
8153 uentry_showWhereSpecified (old);
8154 }
8155 }
8156
8157 old->info->var->checked = unew->info->var->checked;
8158 }
8159 else
8160 {
8161 if (completeConform
8162 && (old->info->var->checked != CH_UNKNOWN)
8163 && uentry_isReallySpecified (old))
8164 {
8165 if (optgenerror
8166 (FLG_NEEDSPEC,
8167 message ("%s %q specified as %s, but declared without %s qualifier",
8168 ekind_capName (unew->ukind),
8169 uentry_getName (unew),
8170 checkedName (old->info->var->checked),
8171 checkedName (old->info->var->checked)),
8172 uentry_whereDeclared (unew)))
8173 {
8174 uentry_showWhereSpecified (old);
8175 }
8176 }
8177
8178 unew->info->var->checked = old->info->var->checked;
8179 }
8180
8181 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8182}
8183
8184void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
8185{
8186 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
8187 {
8188 return;
8189 }
8190
8191 llassert (uentry_isVar (u1));
8192 llassert (uentry_isVar (u2));
8193
8194 if (u1->info->var->kind != u2->info->var->kind) {
8195 if (u1->info->var->kind == VKSEFRETPARAM) {
8196 if (u2->info->var->kind == VKRETPARAM) {
8197 voptgenerror
8198 (FLG_TYPE,
8199 message ("Function types are inconsistent. Parameter %d is "
8200 "sef parameter, but non-sef parameter in "
8201 "assigned function: %s",
8202 paramno, exprNode_unparse (e)),
8203 exprNode_loc (e));
8204 } else if (u2->info->var->kind == VKSEFPARAM) {
8205 voptgenerror
8206 (FLG_TYPE,
8207 message ("Function types are inconsistent. Parameter %d is "
8208 "returns parameter, but non-returns parameter in "
8209 "assigned function: %s",
8210 paramno, exprNode_unparse (e)),
8211 exprNode_loc (e));
8212 } else {
8213 voptgenerror
8214 (FLG_TYPE,
8215 message ("Function types are inconsistent. Parameter %d is "
8216 "sef returns parameter, but non-sef returns parameter in "
8217 "assigned function: %s",
8218 paramno, exprNode_unparse (e)),
8219 exprNode_loc (e));
8220 }
8221 } else if (u1->info->var->kind == VKRETPARAM) {
8222 voptgenerror
8223 (FLG_TYPE,
8224 message ("Function types are inconsistent. Parameter %d is "
8225 "returns parameter, but non-returns parameter in "
8226 "assigned function: %s",
8227 paramno, exprNode_unparse (e)),
8228 exprNode_loc (e));
8229 } else if (u1->info->var->kind == VKSEFPARAM) {
8230 voptgenerror
8231 (FLG_TYPE,
8232 message ("Function types are inconsistent. Parameter %d is "
8233 "sef parameter, but non-sef parameter in "
8234 "assigned function: %s",
8235 paramno, exprNode_unparse (e)),
8236 exprNode_loc (e));
8237 } else {
8238 if (u2->info->var->kind == VKSEFRETPARAM) {
8239 voptgenerror
8240 (FLG_TYPE,
8241 message ("Function types are inconsistent. Parameter %d is "
8242 "normal parameter, but sef returns parameter in "
8243 "assigned function: %s",
8244 paramno, exprNode_unparse (e)),
8245 exprNode_loc (e));
8246 } else if (u2->info->var->kind == VKSEFPARAM) {
8247 voptgenerror
8248 (FLG_TYPE,
8249 message ("Function types are inconsistent. Parameter %d is "
8250 "normal parameter, but sef parameter in "
8251 "assigned function: %s",
8252 paramno, exprNode_unparse (e)),
8253 exprNode_loc (e));
8254 } else if (u2->info->var->kind == VKRETPARAM) {
8255 voptgenerror
8256 (FLG_TYPE,
8257 message ("Function types are inconsistent. Parameter %d is "
8258 "normal parameter, but returns parameter in "
8259 "assigned function: %s",
8260 paramno, exprNode_unparse (e)),
8261 exprNode_loc (e));
8262 } else {
8263 BADBRANCH;
8264 }
8265 }
8266 }
8267
8268 if (u1->info->var->defstate != u2->info->var->defstate)
8269 {
8270 voptgenerror
8271 (FLG_TYPE,
8272 message ("Function types are inconsistent. Parameter %d is "
8273 "%s, but %s in assigned function: %s",
8274 paramno,
8275 sstate_unparse (u1->info->var->defstate),
8276 sstate_unparse (u2->info->var->defstate),
8277 exprNode_unparse (e)),
8278 exprNode_loc (e));
8279 }
8280
8281 if (u1->info->var->nullstate != u2->info->var->nullstate)
8282 {
8283 voptgenerror
8284 (FLG_TYPE,
8285 message ("Function types are inconsistent. Parameter %d is "
8286 "%s, but %s in assigned function: %s",
8287 paramno,
8288 nstate_unparse (u1->info->var->nullstate),
8289 nstate_unparse (u2->info->var->nullstate),
8290 exprNode_unparse (e)),
8291 exprNode_loc (e));
8292 }
8293
8294 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
8295 {
8296 voptgenerror
8297 (FLG_TYPE,
8298 message ("Function types are inconsistent. Parameter %d is "
8299 "%s, but %s in assigned function: %s",
8300 paramno,
8301 alkind_unparse (sRef_getAliasKind (u1->sref)),
8302 alkind_unparse (sRef_getAliasKind (u2->sref)),
8303 exprNode_unparse (e)),
8304 exprNode_loc (e));
8305 }
8306
8307 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
8308 {
8309 voptgenerror
8310 (FLG_TYPE,
8311 message ("Function types are inconsistent. Parameter %d is "
8312 "%s, but %s in assigned function: %s",
8313 paramno,
8314 exkind_unparse (sRef_getExKind (u1->sref)),
8315 exkind_unparse (sRef_getExKind (u2->sref)),
8316 exprNode_unparse (e)),
8317 exprNode_loc (e));
8318 }
8319}
8320
aec3dcdb 8321static void uentry_convertIntoFunction (/*@notnull@*/ uentry old)
8322{
8323 /*
8324 ** Convert old into a function
8325 */
8326
8327 old->ukind = KFCN;
8328 old->utype = ctype_unknown;
8329 old->info->fcn = (ufinfo) dmalloc (sizeof (*old->info->fcn));
8330 old->info->fcn->hasMods = FALSE;
8331 old->info->fcn->hasGlobs = FALSE;
8332 old->info->fcn->exitCode = XK_UNKNOWN;
8333 old->info->fcn->nullPred = qual_createUnknown ();
8334 old->info->fcn->specialCode = SPC_NONE;
8335 old->info->fcn->access = typeIdSet_undefined;
8336 old->info->fcn->globs = globSet_undefined;
8337 old->info->fcn->defparams = uentryList_undefined;
8338 old->info->fcn->mods = sRefSet_undefined;
8339 old->info->fcn->specclauses = NULL;
8340 old->info->fcn->preconditions = NULL;
8341 old->info->fcn->postconditions = NULL;
8342}
8343
616915dd 8344static void
8345checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8346 /*@notnull@*/ uentry unew,
8347 bool mustConform, /*@unused@*/ bool completeConform)
8348{
8349 uentryList oldParams = uentry_getParams (old);
8350 uentryList newParams = uentry_getParams (unew);
8351 ctype newType = unew->utype;
ac35a6ab 8352 ctype oldType = ctype_realType (old->utype);
616915dd 8353 ctype oldRetType = ctype_unknown;
8354 ctype newRetType = ctype_unknown;
8355
28bf4b0b 8356 DPRINTF (("Function conform: %s ==> %s",
8357 uentry_unparseFull (old),
8358 uentry_unparseFull (unew)));
8359
616915dd 8360 if (uentry_isForward (old))
8361 {
8362 mustConform = FALSE;
efd360a3 8363 uentry_updateInto (old, unew);
616915dd 8364 return;
8365 }
8366
8367 /*
8368 ** check return values
8369 */
8370
8371 if (ctype_isKnown (oldType))
8372 {
aec3dcdb 8373 if (ctype_isFunction (oldType))
8374 {
8375 oldRetType = ctype_getReturnType (oldType);
8376 }
8377 else
8378 {
8379 if (optgenerror
8380 (FLG_INCONDEFS,
8381 message ("%s %q declared as function, but previously declared as %s",
8382 ekind_capName (unew->ukind),
8383 uentry_getName (unew),
8384 ekind_unparseLong (old->ukind)),
8385 uentry_whereDeclared (unew)))
8386 {
8387 uentry_showWhereLast (old);
8388 }
8389
8390 uentry_convertIntoFunction (old);
8391 return;
8392 }
616915dd 8393 }
8394
8395 if (ctype_isKnown (newType))
8396 {
8397 llassert (ctype_isFunction (newType));
28bf4b0b 8398 newRetType = ctype_getReturnType (newType);
616915dd 8399 }
8400
8401 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
8402 && !ctype_matchDef (newRetType, oldRetType))
8403 {
8404 if (mustConform) returnValueError (old, unew);
8405 }
8406 else
8407 {
8408 if (ctype_isConj (newRetType))
8409 {
8410 if (ctype_isConj (oldRetType))
8411 {
8412 if (!ctype_sameAltTypes (newRetType, oldRetType))
8413 {
8414 if (optgenerror
8415 (FLG_INCONDEFS,
8416 message ("Function %q inconsistently %rdeclared to "
8417 "return alternate types %s "
8418 "(types match, but alternates are not identical, "
8419 "so checking may not be correct)",
8420 uentry_getName (unew),
8421 uentry_isDeclared (old),
8422 ctype_unparse (newRetType)),
8423 uentry_whereDeclared (unew)))
8424 {
8425 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
8426 }
8427 }
8428 }
8429 else
8430 {
8431 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
8432 }
8433 }
8434 }
8435
28bf4b0b 8436 DPRINTF (("Before state: %s",
8437 uentry_unparseFull (old)));
616915dd 8438 uentry_checkStateConformance (old, unew, mustConform, completeConform);
28bf4b0b 8439 DPRINTF (("After state: %s",
8440 uentry_unparseFull (old)));
616915dd 8441
8442 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
8443 {
8444 if (exitkind_isKnown (unew->info->fcn->exitCode))
8445 {
8446 if (optgenerror
8447 (FLG_INCONDEFS,
8448 message ("Function %q inconsistently %rdeclared using %s",
8449 uentry_getName (unew),
8450 uentry_isDeclared (old),
8451 exitkind_unparse (unew->info->fcn->exitCode)),
8452 uentry_whereDeclared (unew)))
8453 {
8454 uentry_showWhereSpecified (old);
8455 }
8456 }
8457 else
8458 {
8459 unew->info->fcn->exitCode = old->info->fcn->exitCode;
8460 }
8461 }
8462
8463 if (!qual_isUnknown (unew->info->fcn->nullPred))
8464 {
28bf4b0b 8465 if (!qual_match (old->info->fcn->nullPred, unew->info->fcn->nullPred))
616915dd 8466 {
8467 if (optgenerror
8468 (FLG_INCONDEFS,
8469 message ("Function %q inconsistently %rdeclared using %s",
8470 uentry_getName (unew),
8471 uentry_isDeclared (old),
8472 qual_unparse (unew->info->fcn->nullPred)),
8473 uentry_whereDeclared (unew)))
8474 {
8475 uentry_showWhereSpecified (old);
8476 }
8477 }
8478 }
8479 else
8480 {
8481 unew->info->fcn->nullPred = old->info->fcn->nullPred;
8482 }
8483
8484 if (unew->info->fcn->specialCode != SPC_NONE)
8485 {
8486 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
8487 {
8488 if (optgenerror
8489 (FLG_INCONDEFS,
8490 message ("Function %q inconsistently %rdeclared using %s",
8491 uentry_getName (unew),
8492 uentry_isDeclared (old),
8493 specCode_unparse (unew->info->fcn->specialCode)),
8494 uentry_whereDeclared (unew)))
8495 {
8496 uentry_showWhereSpecified (old);
8497 }
8498 }
8499 }
8500 else
8501 {
8502 unew->info->fcn->specialCode = old->info->fcn->specialCode;
8503 }
8504
8505 /*
8506 ** check parameters
8507 */
8508
8509 if (!uentryList_sameObject (oldParams, newParams)
8510 && (!uentryList_isMissingParams (oldParams)))
8511 {
8512 if (!uentryList_isMissingParams (newParams))
8513 {
8514 int paramno = 0;
8515 int nparams = uentryList_size (oldParams);
8516 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
8517
8518 if (nparams != uentryList_size (newParams))
8519 {
8520 nargsError (old, unew);
8521 }
8522
8523 if (uentryList_size (newParams) < nparams)
8524 {
8525 nparams = uentryList_size (newParams);
8526 }
8527
8528 while (paramno < nparams)
8529 {
8530 uentry oldCurrent = uentryList_getN (oldParams, paramno);
8531 uentry newCurrent = uentryList_getN (newParams, paramno);
8532 ctype oldCurrentType = uentry_getType (oldCurrent);
8533 ctype newCurrentType = uentry_getType (newCurrent);
8534
8535 llassert (uentry_isValid (oldCurrent)
8536 && uentry_isValid (newCurrent));
8537
8538 if (!uentry_isElipsisMarker (oldCurrent)
8539 && !uentry_isElipsisMarker (newCurrent))
8540 {
8541 checkVarConformance (oldCurrent, newCurrent,
8542 mustConform, completeConform);
8543 }
8544
8545 if (checknames)
8546 {
8547 if (uentry_hasName (oldCurrent)
8548 && uentry_hasName (newCurrent))
8549 {
8550 cstring oldname = uentry_getName (oldCurrent);
8551 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
8552 cstring oname;
8553 cstring nname = uentry_getName (newCurrent);
8554 cstring nnamefix;
8555
8556 if (cstring_isDefined (pfx)
68de3f33 8557 && cstring_equalPrefix (oldname, pfx))
616915dd 8558 {
8559 oname = cstring_suffix (oldname, cstring_length (pfx));
8560 }
8561 else
8562 {
8563 oname = oldname;
8564 /*@-branchstate@*/ } /*@=branchstate@*/
8565
8566 if (cstring_isDefined (pfx)
68de3f33 8567 && cstring_equalPrefix (nname, pfx))
616915dd 8568 {
8569 nnamefix = cstring_suffix (nname, cstring_length (pfx));
8570 }
8571 else
8572 {
8573 nnamefix = nname;
8574 /*@-branchstate@*/ } /*@=branchstate@*/
8575
8576 if (!cstring_equal (oname, nnamefix))
8577 {
8578 if (optgenerror
8579 (FLG_DECLPARAMMATCH,
8580 message ("Definition parameter name %s does not match "
8581 "name of corresponding parameter in "
8582 "declaration: %s",
8583 nnamefix, oname),
8584 uentry_whereLast (newCurrent)))
8585 {
8586 uentry_showWhereLastPlain (oldCurrent);
8587 }
8588 }
8589
8590 cstring_free (oldname);
8591 cstring_free (nname);
8592 }
8593 }
8594
8595 if (!ctype_match (oldCurrentType, newCurrentType))
8596 {
8597 paramTypeError (old, oldCurrent, oldCurrentType,
8598 unew, newCurrent, newCurrentType, paramno);
8599 }
8600 else
8601 {
8602 if (ctype_isMissingParamsMarker (newCurrentType)
8603 || ctype_isElips (newCurrentType)
8604 || ctype_isMissingParamsMarker (oldCurrentType)
8605 || ctype_isElips (oldCurrentType))
8606 {
8607 ;
8608 }
8609 else
8610 {
8611 if (ctype_isConj (newCurrentType))
8612 {
8613 if (ctype_isConj (oldCurrentType))
8614 {
8615 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
8616 {
8617 if (optgenerror
8618 (FLG_INCONDEFS,
8619 message ("Parameter %q inconsistently %rdeclared with "
8620 "alternate types %s "
8621 "(types match, but alternates are not identical, "
8622 "so checking may not be correct)",
8623 uentry_getName (newCurrent),
8624 uentry_isDeclared (oldCurrent),
8625 ctype_unparse (newCurrentType)),
8626 uentry_whereDeclared (unew)))
8627 {
8628 uentry_showWhereLastVal (oldCurrent,
8629 ctype_unparse (oldCurrentType));
8630 }
8631 }
8632 }
8633 else
8634 {
8635 if (optgenerror
8636 (FLG_INCONDEFS,
8637 message ("Parameter %q inconsistently %rdeclared with "
8638 "alternate types %s",
8639 uentry_getName (newCurrent),
8640 uentry_isDeclared (oldCurrent),
8641 ctype_unparse (newCurrentType)),
8642 uentry_whereDeclared (unew)))
8643 {
8644 uentry_showWhereLastVal (oldCurrent,
8645 ctype_unparse (oldCurrentType));
8646
8647 }
8648 }
8649 }
8650 else
8651 {
8652 if (ctype_isConj (oldCurrentType))
8653 {
8654 uentry_setType (newCurrent, oldCurrentType);
8655 }
8656 }
8657 }
8658 }
8659
8660 paramno++;
8661 /*
1b8ae690 8662 ** Forgot this! detected by splint:
616915dd 8663 ** uentry.c:1257,15: Suspected infinite loop
8664 */
8665 }
8666 }
8667 }
8668
8669 if (!uentryList_isMissingParams (newParams))
8670 {
8671 if (ctype_isConj (oldRetType))
8672 {
8673 old->utype = ctype_makeFunction (oldRetType,
8674 uentryList_copy (newParams));
8675 }
8676 else
8677 {
8678 old->utype = unew->utype;
8679 }
8680 }
8681
8682 checkGlobalsConformance (old, unew, mustConform, completeConform);
8683 checkModifiesConformance (old, unew, mustConform, completeConform);
8684
28bf4b0b 8685 DPRINTF (("Before list: %s",
8686 uentry_unparseFull (old)));
8687
8688 if (stateClauseList_isDefined (unew->info->fcn->specclauses))
616915dd 8689 {
28bf4b0b 8690 if (!stateClauseList_isDefined (old->info->fcn->specclauses))
616915dd 8691 {
28bf4b0b 8692 /*
616915dd 8693 if (optgenerror
8694 (FLG_INCONDEFS,
8695 message ("Function %q redeclared using special clauses (can only "
8696 "be used in first declaration)",
8697 uentry_getName (unew)),
8698 uentry_whereDeclared (unew)))
8699 {
8700 uentry_showWhereLast (old);
8701 }
28bf4b0b 8702 */
8703
b73d1009 8704 /* need to add some checking @*/
28bf4b0b 8705 old->info->fcn->specclauses = unew->info->fcn->specclauses;
616915dd 8706 }
8707 else
8708 {
b73d1009 8709 /* should be able to append? */
28bf4b0b 8710
8711 stateClauseList_checkEqual (old, unew);
8712 stateClauseList_free (unew->info->fcn->specclauses);
8713 unew->info->fcn->specclauses = stateClauseList_undefined;
8714 /*@-branchstate@*/
616915dd 8715 }
8716 }
b73d1009 8717 /*@=branchstate@*/ /* shouldn't need this */
616915dd 8718
8719 if (fileloc_isUndefined (old->whereDeclared))
8720 {
8721 old->whereDeclared = fileloc_copy (unew->whereDeclared);
8722 }
8723 else if (fileloc_isUndefined (unew->whereDeclared))
8724 {
8725 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8726 }
8727 else
8728 {
8729 /* no change */
8730 }
b73d1009 8731 /*@-compmempass@*/
8732} /*@=compmempass@*/ /* I think this is a spurious warning */
616915dd 8733
8734void
8735uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
8736{
8737 multiVal uval;
8738
8739 llassert (uentry_isValid (ue));
8740 llassert (uentry_isEitherConstant (ue));
8741
b9904f57 8742 DPRINTF (("Constant value: %s / %s", uentry_unparse (ue), multiVal_unparse (m)));
8743 uval = uentry_getConstantValue (ue);
616915dd 8744
8745 if (multiVal_isDefined (uval))
8746 {
8747 if (multiVal_isDefined (m))
8748 {
8749 if (!multiVal_equiv (uval, m))
8750 {
8751 if (optgenerror
8752 (FLG_INCONDEFS,
8753 message ("%s %q defined with inconsistent value: %q",
8754 ekind_capName (ue->ukind),
8755 uentry_getName (ue),
8756 multiVal_unparse (m)),
8757 g_currentloc))
8758 {
8759 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
8760 }
8761 }
8762 }
8763 multiVal_free (m);
8764 }
8765 else
8766 {
b9904f57 8767 uentry_setConstantValue (ue, m);
616915dd 8768 }
8769}
8770
8771static
8772bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
8773 bool mustConform)
8774{
8775 bool typeError = FALSE;
8776
8777 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
8778 {
8779 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
8780 {
8781 if (mustConform)
8782 {
28bf4b0b 8783 DPRINTF (("Check struct conformance: %s / %s",
8784 uentry_unparseFull (old),
8785 uentry_unparseFull (unew)));
616915dd 8786 checkStructConformance (old, unew);
8787 }
8788 }
8789 else
8790 {
8791 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8792 {
8793 llbug (message ("struct tags: bad types: %t / %t",
8794 old->utype, unew->utype));
8795 }
8796 }
8797 }
8798 else if (uentry_isEnumTag (old))
8799 {
8800 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
8801 {
8802 if (mustConform) checkEnumConformance (old, unew);
8803 }
8804 else
8805 {
8806 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8807 {
8808 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
8809 ctype_unparse (unew->utype)));
8810 }
8811 }
8812 }
8813 else if (!ctype_match (old->utype, unew->utype))
8814 {
28bf4b0b 8815 DPRINTF (("Type mismatch: %s / %s",
8816 ctype_unparse (old->utype),
8817 ctype_unparse (unew->utype)));
8818
616915dd 8819 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
8820 {
8821 ctype realt = ctype_realType (unew->utype);
8822
8823 if (ctype_isRealInt (realt) || ctype_isChar (realt))
8824 {
8825 unew->utype = ctype_bool;
8826 }
8827 else
8828 {
8829 if (mustConform)
8830 {
8831 typeError = optgenerror
8832 (FLG_INCONDEFS,
8833 message ("%q defined as %s", uentry_getName (old),
8834 ctype_unparse (realt)),
8835 uentry_whereDeclared (unew));
8836 }
8837 }
8838 }
8839 else
8840 {
8841 if (mustConform)
8842 {
8843 ctype oldr = ctype_realType (old->utype);
8844 ctype newr = ctype_realType (unew->utype);
8845
8846 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
8847 {
8848 checkStructConformance (old, unew);
8849 }
8850 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
8851 {
8852 checkStructConformance (old, unew);
8853 }
8854 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
8855 {
8856 checkEnumConformance (old, unew);
8857 }
8858 else if (uentry_isConstant (old)
8859 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
8860 {
8861 /* okay...for now! (should check the type is reset later... */
8862 }
8863 else
8864 {
8865 DPRINTF (("YABA!"));
8866 if (optgenerror
8867 (FLG_INCONDEFS,
8868 message ("%s %q %rdeclared with inconsistent type: %t",
8869 ekind_capName (unew->ukind),
8870 uentry_getName (unew),
8871 uentry_isDeclared (old),
8872 unew->utype),
8873 uentry_whereDeclared (unew)))
8874 {
8875 uentry_showWhereLast (old);
8876 typeError = TRUE;
8877 }
8878 }
8879 }
8880 }
8881 }
8882 else
8883 {
8884 /* no error */
8885 }
8886
8887 return typeError;
8888}
8889
8890static void
8891uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
8892 /*@notnull@*/ uentry unew,
8893 bool mustConform, bool completeConform)
8894{
8895 if (ctype_isDefined (unew->info->datatype->type))
8896 {
8897 /*
8898 ** bool is hard coded here, since it is built into LCL.
8899 ** For now, we're stuck with LCL's types.
8900 */
8901
8902 if (ctype_isDirectBool (old->utype) &&
8903 cstring_equalLit (unew->uname, "bool"))
8904 {
8905 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
8906 evs 2000-07-25: removed
8907 */
8908 unew->utype = ctype_bool;
8909 }
8910
8911 if (ctype_isUnknown (old->info->datatype->type))
8912 {
8913 old->info->datatype->type = unew->info->datatype->type;
8914 }
8915 else
8916 {
8917 DPRINTF (("Old: %s / New: %s",
8918 uentry_unparseFull (old),
8919 uentry_unparseFull (unew)));
8920 DPRINTF (("Types: %s / %s",
8921 ctype_unparse (old->info->datatype->type),
8922 ctype_unparse (unew->info->datatype->type)));
8923
8924 if (ctype_matchDef (old->info->datatype->type,
8925 unew->info->datatype->type))
8926 {
8927 ;
8928 }
8929 else
8930 {
8931 if (optgenerror
8932 (FLG_INCONDEFS,
8933 message
8934 ("Type %q %s with inconsistent type: %t",
8935 uentry_getName (unew),
8936 uentry_reDefDecl (old, unew),
8937 unew->info->datatype->type),
8938 uentry_whereDeclared (unew)))
8939 {
8940 uentry_showWhereLastExtra
8941 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
8942 }
8943
8944 old->info->datatype->type = unew->info->datatype->type;
8945 }
8946 }
8947 }
8948
e5081f8c 8949 if (!qual_isUnknown (unew->info->datatype->abs))
616915dd 8950 {
e5081f8c 8951 if (qual_isConcrete (old->info->datatype->abs)
8952 && qual_isEitherAbstract (unew->info->datatype->abs))
616915dd 8953 {
8954 if (!ctype_isDirectBool (old->utype))
8955 {
8956 if (optgenerror
8957 (FLG_INCONDEFS,
8958 message
8959 ("Datatype %q inconsistently %rdeclared as abstract type",
8960 uentry_getName (unew),
8961 uentry_isDeclared (old)),
8962 uentry_whereDeclared (unew)))
8963 {
8964 uentry_showWhereLastPlain (old);
8965 }
8966 }
8967 }
e5081f8c 8968 else if (qual_isEitherAbstract (old->info->datatype->abs)
8969 && qual_isConcrete (unew->info->datatype->abs))
616915dd 8970 {
8971 if (!ctype_isDirectBool (old->utype))
8972 {
8973 if (optgenerror
8974 (FLG_INCONDEFS,
8975 message
8976 ("Datatype %q inconsistently %rdeclared as concrete type",
8977 uentry_getName (unew),
8978 uentry_isDeclared (old)),
8979 uentry_whereDeclared (unew)))
8980 {
8981 uentry_showWhereLastPlain (old);
8982 }
8983 }
8984 }
8985 else
8986 {
8987 ;
8988 }
8989 }
8990 else
8991 {
e5081f8c 8992 if (qual_isEitherAbstract (old->info->datatype->abs))
616915dd 8993 {
8994 old->sref = unew->sref;
8995 unew->info->datatype->mut = old->info->datatype->mut;
8996
8997 if (completeConform
8998 && uentry_isReallySpecified (old))
8999 {
9000 if (optgenerror
9001 (FLG_NEEDSPEC,
9002 message
9003 ("Datatype %q specified as abstract, "
9004 "but abstract annotation not used in declaration",
9005 uentry_getName (unew)),
9006 uentry_whereDeclared (unew)))
9007 {
9008 uentry_showWhereLastPlain (old);
9009 }
9010 }
9011 }
9012 }
9013
9014 unew->info->datatype->abs = old->info->datatype->abs;
9015
9016 if (ynm_isMaybe (unew->info->datatype->mut))
9017 {
9018 if (completeConform && ynm_isOff (old->info->datatype->mut)
9019 && uentry_isReallySpecified (old))
9020 {
9021 if (optgenerror
9022 (FLG_NEEDSPEC,
9023 message
9024 ("Datatype %q specified as immutable, "
9025 "but immutable annotation not used in declaration",
9026 uentry_getName (unew)),
9027 uentry_whereDeclared (unew)))
9028 {
9029 uentry_showWhereLastPlain (old);
9030 }
9031 }
9032
9033 unew->info->datatype->mut = old->info->datatype->mut;
9034 }
9035 else if (ynm_isMaybe (old->info->datatype->mut))
9036 {
9037 old->info->datatype->mut = unew->info->datatype->mut;
9038 }
9039 else
9040 {
e5081f8c 9041 if (qual_isEitherAbstract (old->info->datatype->abs))
616915dd 9042 {
9043 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
9044 {
9045 if (optgenerror
9046 (FLG_INCONDEFS,
9047 message ("Datatype %q inconsistently %rdeclared as immutable",
9048 uentry_getName (unew),
9049 uentry_isDeclared (old)),
9050 uentry_whereDeclared (unew)))
9051 {
9052 uentry_showWhereLastPlain (old);
9053 }
9054 }
9055 else
9056 {
9057 if (ynm_isOff (old->info->datatype->mut)
9058 && ynm_isOn (unew->info->datatype->mut))
9059 {
9060 if (optgenerror
9061 (FLG_INCONDEFS,
9062 message ("Datatype %q inconsistently %rdeclared as mutable",
9063 uentry_getName (unew),
9064 uentry_isDeclared (old)),
9065 uentry_whereDeclared (unew)))
9066 {
9067 uentry_showWhereLastPlain (old);
9068 }
9069 }
9070 }
9071 }
9072 old->info->datatype->mut = unew->info->datatype->mut;
9073 }
9074
9075 uentry_checkStateConformance (old, unew, mustConform, completeConform);
9076}
9077
9078static void
9079uentry_checkConstantConformance (/*@notnull@*/ uentry old,
9080 /*@notnull@*/ uentry unew,
9081 bool mustConform,
9082 /*@unused@*/ bool completeConform)
9083{
b9904f57 9084 multiVal oldval = uentry_getConstantValue (old);
9085 multiVal newval = uentry_getConstantValue (unew);
616915dd 9086
b9904f57 9087 if (multiVal_isDefined (oldval))
616915dd 9088 {
b9904f57 9089 if (multiVal_isDefined (newval))
616915dd 9090 {
b9904f57 9091 if (!multiVal_equiv (oldval, newval))
616915dd 9092 {
9093 if (mustConform
9094 && optgenerror
9095 (FLG_INCONDEFS,
9096 message ("%s %q %rdeclared with inconsistent value: %q",
9097 ekind_capName (unew->ukind),
9098 uentry_getName (unew),
9099 uentry_isDeclared (old),
b9904f57 9100 multiVal_unparse (newval)),
616915dd 9101 uentry_whereDeclared (unew)))
9102 {
b9904f57 9103 uentry_showWhereLastExtra (old, multiVal_unparse (oldval));
616915dd 9104 }
9105 }
9106
b9904f57 9107 uentry_setConstantValue (unew, multiVal_copy (oldval));
616915dd 9108 }
9109 else
9110 {
9111 ;
9112 }
9113 }
9114 else
9115 {
b9904f57 9116 uentry_setConstantValue (old, multiVal_copy (newval));
616915dd 9117 }
9118}
9119
9120static void
9121uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
9122 /*@notnull@*/ uentry unew, bool mustConform,
9123 bool completeConform)
9124{
9125 bool typeError = FALSE;
9126 bool fcnConformance = FALSE;
9127
9128 if (!ekind_equal (unew->ukind, old->ukind))
9129 {
9130 /*
9131 ** okay, only if one is a function and the other is
9132 ** a variable of type function.
9133 */
9134
9135 if (unew->ukind == KENUMCONST
9136 && old->ukind == KCONST)
9137 {
9138 old->ukind = KENUMCONST;
9139 goto nokinderror;
9140 }
9141
9142 if (unew->ukind == KFCN
9143 && old->ukind == KCONST
9144 && ctype_isUnknown (old->utype))
9145 {
9146 /*
9147 ** When a function is defined with an unparam macro
9148 */
9149
efd360a3 9150 uentry_updateInto (old, unew);
616915dd 9151 return;
9152 }
9153
9154 if (uentry_isExpandedMacro (old)
9155 && uentry_isEitherConstant (unew))
9156 {
efd360a3 9157 uentry_updateInto (old, unew);
616915dd 9158 return;
9159 }
9160
9161 if (uentry_isEndIter (unew))
9162 {
9163 if (ctype_isUnknown (old->utype))
9164 {
9165 if (!uentry_isSpecified (old)
9166 && uentry_isCodeDefined (unew))
9167 {
9168 if (!fileloc_withinLines (uentry_whereDefined (old),
9169 uentry_whereDeclared (unew), 2))
9170 { /* bogus! will give errors if there is too much whitespace */
9171 voptgenerror
9172 (FLG_SYNTAX,
9173 message
9174 ("Iterator finalized name %q does not match name in "
9175 "previous iter declaration (should be end_%q). This iter "
9176 "is declared at %q",
9177 uentry_getName (unew),
9178 uentry_getName (old),
9179 fileloc_unparse (uentry_whereDefined (old))),
9180 uentry_whereDeclared (old));
9181 }
9182 }
9183
efd360a3 9184 uentry_updateInto (old, unew);
616915dd 9185 return;
9186 }
9187 else
9188 {
9189 KindConformanceError (old, unew, mustConform);
9190 }
9191 }
9192
9193 if (uentry_isFunction (unew))
9194 {
9195 if (uentry_isVariable (old))
9196 {
9197 if (!ctype_isUnknown (old->utype))
9198 {
9199 if (ctype_isFunction (old->utype))
9200 {
9201 uentry_makeVarFunction (old);
9202 checkFunctionConformance (old, unew, mustConform,
9203 completeConform);
9204 fcnConformance = TRUE;
9205 }
9206 else
9207 {
9208 KindConformanceError (old, unew, mustConform);
9209 }
9210 }
9211 else
9212 {
9213 if (uentry_isExpandedMacro (old))
9214 {
9215 if (fileloc_isUndefined (unew->whereDefined))
9216 {
9217 unew->whereDefined = fileloc_update (unew->whereDefined,
9218 old->whereDefined);
9219 }
9220
efd360a3 9221 uentry_updateInto (old, unew);
616915dd 9222 old->used = unew->used = TRUE;
9223 return;
9224 }
9225 else
9226 {
9227 /* undeclared identifier */
9228 old->utype = unew->utype;
9229 uentry_makeVarFunction (old);
9230 checkFunctionConformance (old, unew, FALSE, FALSE);
9231 fcnConformance = TRUE;
9232 }
9233 }
9234 }
9235 else
9236 {
9237 KindConformanceError (old, unew, mustConform);
9238 }
9239 }
9240 else if (uentry_isFunction (old) && uentry_isVariable (unew))
9241 {
9242 if (!ctype_isUnknown (unew->utype))
9243 {
9244 if (ctype_isFunction (unew->utype))
9245 {
9246 uentry_makeVarFunction (unew);
9247 checkFunctionConformance (old, unew, mustConform, completeConform);
9248 fcnConformance = TRUE;
9249 }
9250 else
9251 {
9252 KindConformanceError (old, unew, mustConform);
9253 }
9254 }
9255 else
9256 {
9257 KindConformanceError (old, unew, mustConform);
9258 }
9259 }
9260 else
9261 {
9262 KindConformanceError (old, unew, mustConform);
9263 }
9264 }
9265 else
9266 {
9267 /*
9268 ** check parameter lists for functions
9269 ** (before type errors, to get better messages
9270 */
9271
9272 if (uentry_isFunction (old))
9273 {
9274 checkFunctionConformance (old, unew, mustConform, completeConform);
9275 fcnConformance = TRUE;
9276 }
9277 else
9278 {
9279 if (!ctype_isUndefined (old->utype))
9280 {
9281 typeError = checkTypeConformance (old, unew, mustConform);
9282 }
9283 }
9284 }
9285
9286 nokinderror:
9287
9288 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
9289 {
9290 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
9291 }
9292
9293 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
9294 {
9295 DPRINTF (("Check datatype: %s / %s",
9296 uentry_unparseFull (old),
9297 uentry_unparseFull (unew)));
9298
9299 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
9300 }
9301
9302 if (uentry_isVariable (old) && uentry_isVariable (unew))
9303 {
9304 if (!typeError &&
9305 !ctype_matchDef (old->utype, unew->utype))
9306 {
9307 if (optgenerror
9308 (FLG_INCONDEFS,
9309 message
9310 ("Variable %q %s with inconsistent type (arrays and pointers are "
9311 "not identical in variable declarations): %t",
9312 uentry_getName (unew),
9313 uentry_reDefDecl (old, unew),
9314 unew->utype),
9315 uentry_whereDeclared (unew)))
9316 {
9317 uentry_showWhereLast (old);
9318
9319 /*
9320 ** Avoid repeated errors.
9321 */
9322
9323 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
9324 {
9325 old->whereDefined = fileloc_update (old->whereDefined,
9326 fileloc_undefined);
9327 }
9328
9329 typeError = TRUE;
9330 }
9331 }
9332
9333 checkVarConformance (old, unew, mustConform, completeConform);
9334 }
9335
9336 if (fcnConformance)
9337 {
9338 /* old->utype = unew->utype; */
9339 }
9340 else
9341 {
9342 if (ctype_isConj (old->utype))
9343 {
9344 if (ctype_isConj (unew->utype))
9345 {
9346 if (!ctype_sameAltTypes (old->utype, unew->utype))
9347 {
9348 if (optgenerror
9349 (FLG_INCONDEFS,
9350 message ("%s %q inconsistently %rdeclared with "
9351 "alternate types %s "
9352 "(types match, but alternates are not identical, "
9353 "so checking may not be correct)",
9354 ekind_capName (uentry_getKind (old)),
9355 uentry_getName (unew),
9356 uentry_isDeclared (old),
9357 ctype_unparse (unew->utype)),
9358 uentry_whereDeclared (unew)))
9359 {
9360 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
9361 }
9362 else
9363 {
9364 old->utype = unew->utype;
9365 }
9366 }
9367 }
9368 }
9369 else
9370 {
9371 if (ctype_isUnknown (old->utype))
9372 {
9373 old->utype = unew->utype;
9374 }
9375 }
9376 }
9377
9378 if (unew->ukind == old->ukind)
9379 {
9380 sfree (unew->info);
9381 unew->info = uinfo_copy (old->info, old->ukind);
9382 }
9383
9384 sRef_storeState (old->sref);
9385 sRef_storeState (unew->sref);
9386}
9387
ba45e1e4 9388static void uentry_mergeConstraints (uentry spec, uentry def)
9389{
9390 if (uentry_isFunction (def))
9391 {
9392 DPRINTF (("Here: %s / %s",
9393 uentry_unparseFull (spec),
9394 uentry_unparseFull (def)));
efd360a3 9395 /* evans 2001-07-21 */
9396 llassert (uentry_isFunction (spec));
ba45e1e4 9397
9398 if (functionConstraint_isDefined (def->info->fcn->preconditions))
9399 {
9400 if (fileloc_isXHFile (uentry_whereLast (def)))
9401 {
9402 llassert (uentry_isFunction (spec));
9403 spec->info->fcn->preconditions = functionConstraint_conjoin (spec->info->fcn->preconditions,
9404 def->info->fcn->preconditions);
ba45e1e4 9405 }
ccf0a4a8 9406 else if (fileloc_equal (uentry_whereLast (spec), uentry_whereLast (def)))
9407 {
9408 ;
9409 }
ba45e1e4 9410 else
9411 {
ccf0a4a8 9412 /* Check if the constraints are identical */
9413
3120b462 9414 if (optgenerror
9415 (FLG_INCONDEFS,
9416 message
9417 ("Preconditions for %q redeclared. Dropping previous precondition: %q",
9418 uentry_getName (spec),
9419 functionConstraint_unparse (spec->info->fcn->preconditions)),
9420 uentry_whereLast (def)))
9421 {
9422 uentry_showWhereSpecified (spec);
9423 }
9424
9425 functionConstraint_free (spec->info->fcn->preconditions);
9426 spec->info->fcn->preconditions = def->info->fcn->preconditions;
ba45e1e4 9427 }
3120b462 9428
9429 def->info->fcn->preconditions = functionConstraint_undefined;
ba45e1e4 9430 }
9431
ba45e1e4 9432 if (functionConstraint_isDefined (def->info->fcn->postconditions))
9433 {
9434 if (fileloc_isXHFile (uentry_whereLast (def)))
9435 {
9436 llassert (uentry_isFunction (spec));
9437 DPRINTF (("Post: %s /++/ %s",
9438 functionConstraint_unparse (spec->info->fcn->postconditions),
9439 functionConstraint_unparse (def->info->fcn->postconditions)));
9440 spec->info->fcn->postconditions = functionConstraint_conjoin (spec->info->fcn->postconditions,
9441 def->info->fcn->postconditions);
9442 def->info->fcn->postconditions = functionConstraint_undefined;
9443 DPRINTF (("Conjoined post: %s", functionConstraint_unparse (spec->info->fcn->postconditions)));
9444 }
9445 else
9446 {
3120b462 9447 if (optgenerror
9448 (FLG_INCONDEFS,
9449 message
9450 ("Postconditions for %q redeclared. Dropping previous postcondition: %q",
9451 uentry_getName (spec),
9452 functionConstraint_unparse (spec->info->fcn->postconditions)),
9453 uentry_whereLast (def)))
9454 {
9455 uentry_showWhereSpecified (spec);
9456 }
9457
9458 functionConstraint_free (spec->info->fcn->postconditions);
9459 spec->info->fcn->postconditions = def->info->fcn->postconditions;
9460 def->info->fcn->postconditions = functionConstraint_undefined;
ba45e1e4 9461 }
9462 }
9463 }
9464}
9465
616915dd 9466/*
9467** modifies spec to reflect def, reports any inconsistencies
9468*/
9469
9470void
9471uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
9472{
9473 llassert (uentry_isValid (spec));
9474 llassert (uentry_isValid (def));
9475 llassert (cstring_equal (spec->uname, def->uname));
efd360a3 9476
9477 if (uentry_isFunction (def))
9478 {
9479 if (uentry_isConstant (spec))
9480 {
9481 llassert (ctype_isUnknown (spec->utype) || ctype_isFunction (spec->utype));
9482 uentry_makeConstantFunction (spec);
9483 }
9484 else
9485 {
9486 uentry_convertVarFunction (spec);
9487 }
9488
9489 llassert (uentry_isFunction (spec));
9490 }
28bf4b0b 9491
9492 DPRINTF (("Merge entries: %s / %s",
9493 uentry_unparseFull (spec),
9494 uentry_unparseFull (def)));
616915dd 9495
ba45e1e4 9496 uentry_mergeConstraints (spec, def);
9497
616915dd 9498 uentry_checkConformance (spec, def, TRUE,
9499 context_getFlag (FLG_NEEDSPEC));
9500
28bf4b0b 9501 DPRINTF (("Merge entries after conform: %s / %s",
9502 uentry_unparseFull (spec),
9503 uentry_unparseFull (def)));
9504
616915dd 9505 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
9506
9507 /*
9508 ** okay, declarations conform. Propagate extra information.
9509 */
9510
9511 uentry_setDefined (spec, uentry_whereDefined (def));
9512 uentry_setDeclared (spec, uentry_whereDeclared (def));
9513
9514 if (uentry_isStatic (def))
9515 {
9516 if (optgenerror
9517 (FLG_INCONDEFS,
9518 message ("%s %q specified, but declared as static",
9519 ekind_capName (def->ukind),
9520 uentry_getName (def)),
9521 uentry_whereDeclared (def)))
9522 {
9523 uentry_showWhereSpecified (spec);
9524 }
9525 }
9526 else
9527 {
9528 spec->storageclass = def->storageclass;
9529 }
9530
9531 sRef_storeState (spec->sref);
9532
9533 spec->used = def->used || spec->used;
9534 spec->hasNameError |= def->hasNameError;
9535
9536 uentry_free (def);
9537
9538 if (!spec->hasNameError)
9539 {
9540 uentry_checkName (spec);
9541 }
9542 else
9543 {
9544 ;
9545 }
9546}
9547
9548/*
9549** Can't generate function redeclaration errors when the
9550** entries are merged, since we don't yet know if its the
9551** definition of the function.
9552*/
9553
9554void
9555uentry_clearDecl (void)
9556{
9557 posRedeclared = uentry_undefined;
9558 fileloc_free (posLoc);
9559 posLoc = fileloc_undefined;
9560}
9561
9562void
9563uentry_checkDecl (void)
9564{
f0171cff 9565 if (uentry_isValid (posRedeclared) && !fileloc_isXHFile (posLoc))
616915dd 9566 {
9567 llassert (fileloc_isDefined (posLoc));
9568
9569 if (uentry_isCodeDefined (posRedeclared))
9570 {
9571 if (optgenerror (FLG_REDECL,
9572 message ("%s %q declared after definition",
9573 ekind_capName (posRedeclared->ukind),
9574 uentry_getName (posRedeclared)),
9575 posLoc))
9576 {
9577 llgenindentmsg (message ("Definition of %q",
9578 uentry_getName (posRedeclared)),
9579 posRedeclared->whereDeclared);
9580 }
9581 }
9582 else
9583 {
9584 if (optgenerror (FLG_REDECL,
9585 message ("%s %q declared more than once",
9586 ekind_capName (posRedeclared->ukind),
9587 uentry_getName (posRedeclared)),
9588 posLoc))
9589 {
9590 llgenindentmsg (message ("Previous declaration of %q",
9591 uentry_getName (posRedeclared)),
9592 posRedeclared->whereDeclared);
9593 }
9594 }
9595 }
9596
9597 fileloc_free (posLoc);
9598 posLoc = fileloc_undefined;
9599 posRedeclared = uentry_undefined;
9600}
9601
9602/*
9603** Redefinition of old as unew.
9604** modifies old to reflect unew, reports any inconsistencies
9605*/
9606
9607void
9608uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
9609{
d89a0c94 9610 fileloc olddef = uentry_whereDeclared (old);
616915dd 9611 fileloc unewdef = uentry_whereDeclared (unew);
9612 bool mustConform;
9613 bool wasForward;
28bf4b0b 9614
9615 DPRINTF (("uentry merge: %s / %s",
9616 uentry_unparseFull (old),
9617 uentry_unparseFull (unew)));
616915dd 9618
616915dd 9619 wasForward =
9620 fileloc_isUndefined (olddef)
efd360a3 9621 && fileloc_isDefined (uentry_whereDefined (old))
9622 && !uentry_isExpandedMacro (old);
616915dd 9623
9624 if (!context_getFlag (FLG_INCONDEFSLIB)
9625 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9626 {
9627 mustConform = FALSE;
9628 }
9629 else
9630 {
9631 mustConform = TRUE;
9632 }
9633
9634 llassert (uentry_isValid (old));
9635 llassert (uentry_isValid (unew));
9636 llassert (cstring_equal (old->uname, unew->uname));
9637
efd360a3 9638 if (uentry_isFunction (unew) && !uentry_isFunction (old))
9639 {
9640 if (uentry_isConstant (old))
9641 {
9642 llassert (ctype_isUnknown (old->utype) || ctype_isFunction (old->utype));
9643 uentry_makeConstantFunction (old);
9644 }
9645 else
9646 {
9647 uentry_convertVarFunction (old);
9648 }
9649
aec3dcdb 9650 if (!uentry_isFunction (old))
9651 {
9652 if (optgenerror
9653 (FLG_INCONDEFS,
9654 message ("%s %q declared as function, but previously declared as %s",
9655 ekind_capName (unew->ukind),
9656 uentry_getName (unew),
9657 ekind_unparseLong (old->ukind)),
9658 uentry_whereDeclared (unew)))
9659 {
9660 uentry_showWhereLast (old);
9661 }
9662
9663 uentry_convertIntoFunction (old);
9664 return;
9665 }
efd360a3 9666 }
9667
9668 DPRINTF (("uentry merge: %s / %s",
9669 uentry_unparseFull (old),
9670 uentry_unparseFull (unew)));
9671
9672 if (uentry_isExtern (unew))
9673 {
9674 uentry_setUsed (old, unewdef);
9675 }
9676
616915dd 9677 /*
9678 ** should check old one was extern!
9679 */
9680
9681 if (uentry_isStatic (old))
9682 {
9683 if (!(uentry_isStatic (unew)))
9684 {
9685 if (optgenerror
9686 (FLG_SHADOW,
9687 message ("%s %q shadows static declaration",
9688 ekind_capName (unew->ukind),
9689 uentry_getName (unew)),
9690 unewdef))
9691 {
9692 uentry_showWhereLast (old);
9693 }
9694 }
9695 else
9696 {
9697 uentry_setDeclDef (old, unewdef);
9698 }
9699 }
9700 else if (uentry_isStatic (unew))
9701 {
9702 uentry_setDeclDef (old, unewdef);
9703 }
9704 else if (uentry_isExtern (old))
9705 {
9706 uentry_setDeclared (old, unewdef);
9707 }
9708 else
9709 {
d89a0c94 9710 if (!uentry_isExtern (unew)
9711 && !uentry_isForward (old)
616915dd 9712 && !fileloc_equal (olddef, unewdef)
9713 && !fileloc_isUndefined (olddef)
9714 && !fileloc_isUndefined (unewdef)
9715 && !fileloc_isBuiltin (olddef)
9716 && !fileloc_isBuiltin (unewdef)
9717 && !uentry_isYield (old)
9718 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9719 {
9720 if (uentry_isVariable (old) || uentry_isVariable (unew))
9721 {
9722 ; /* will report redeclaration error later */
9723 }
9724 else
9725 {
9726 if (fileloc_isDefined (uentry_whereDefined (old)))
9727 {
9728 if (optgenerror
9729 (FLG_REDEF,
9730 message ("%s %q defined more than once",
9731 ekind_capName (unew->ukind),
9732 uentry_getName (unew)),
9733 uentry_whereLast (unew)))
9734 {
9735 llgenindentmsg
9736 (message ("Previous definition of %q",
9737 uentry_getName (old)),
9738 uentry_whereLast (old));
9739 }
9740 /*
9741 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
9742 {
efd360a3 9743 uentry_updateInto (old, unew);
616915dd 9744 old->sref = sRef_saveCopy (old->sref);
9745 }
9746 */
9747 }
9748 }
9749 }
9750 else
9751 {
9752 if (fileloc_isLib (olddef)
9753 || fileloc_isUndefined (olddef)
9754 || fileloc_isImport (olddef))
9755 {
9756 if (uentry_isExtern (unew))
9757 {
9758 if (uentry_isExtern (old)
9759 || (fileloc_isDefined (uentry_whereDeclared (old))
9760 && (!fileloc_equal (uentry_whereDeclared (old),
9761 uentry_whereDefined (old)))))
9762 {
9763 if (optgenerror
9764 (FLG_REDECL,
9765 message ("%s %q declared more than once",
9766 ekind_capName (unew->ukind),
9767 uentry_getName (unew)),
9768 unew->whereDeclared))
9769 {
9770 llgenindentmsg
9771 (message ("Previous declaration of %q",
9772 uentry_getName (old)),
9773 old->whereDeclared);
9774 }
9775 }
9776
9777 uentry_setExtern (old);
9778 }
9779 else
9780 {
d89a0c94 9781 uentry_setDeclared (old, unewdef); /* evans 2001-07-23 was setDefined */
616915dd 9782 }
9783 }
9784 }
9785 }
9786
efd360a3 9787 DPRINTF (("uentry merge: %s / %s",
9788 uentry_unparseFull (old),
9789 uentry_unparseFull (unew)));
ba45e1e4 9790
efd360a3 9791 uentry_mergeConstraints (old, unew);
d89a0c94 9792 DPRINTF (("uentry merge: %s / %s",
9793 uentry_unparseFull (old),
9794 uentry_unparseFull (unew)));
9795
616915dd 9796 uentry_checkConformance (old, unew, mustConform, FALSE);
d89a0c94 9797 DPRINTF (("uentry merge: %s / %s",
9798 uentry_unparseFull (old),
9799 uentry_unparseFull (unew)));
616915dd 9800
9801 old->used = old->used || unew->used;
9802 old->uses = filelocList_append (old->uses, unew->uses);
9803 unew->uses = filelocList_undefined;
9804
9805 sRef_storeState (old->sref);
9806 sRef_storeState (unew->sref);
9807
9808 if (wasForward)
9809 {
9810 old->whereDefined = fileloc_update (old->whereDefined,
9811 fileloc_undefined);
9812 }
9813
d89a0c94 9814 DPRINTF (("here: %s", uentry_unparseFull (old)));
9815
616915dd 9816 /*
9817 ** No redeclaration errors for functions here, since we
9818 ** don't know if this is the definition of the function.
9819 */
9820
9821 if (fileloc_isUser (old->whereDeclared)
9822 && fileloc_isUser (unew->whereDeclared)
9823 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
9824 && !fileloc_isDefined (unew->whereDefined))
9825 {
9826 if (uentry_isFunction (old))
9827 {
9828 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
9829 posLoc = fileloc_update (posLoc, unew->whereDeclared);
9830 }
9831 else
9832 {
9833 if (optgenerror (FLG_REDECL,
9834 message ("%s %q declared more than once",
9835 ekind_capName (unew->ukind),
9836 uentry_getName (unew)),
9837 unew->whereDeclared))
9838 {
9839 llgenindentmsg (message ("Previous declaration of %q",
9840 uentry_getName (old)),
9841 old->whereDeclared);
9842 }
9843 }
9844 }
9845
9846 if (fileloc_isUndefined (old->whereDefined))
9847 {
9848 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
9849 }
9850 else
9851 {
9852 if (!context_processingMacros ()
9853 && fileloc_isUser (old->whereDefined)
9854 && fileloc_isUser (unew->whereDefined)
9855 && !fileloc_equal (old->whereDefined, unew->whereDefined))
9856 {
9857 if (uentry_isVariable (unew) || uentry_isFunction (unew))
9858 {
9859 if (uentry_isVariable (unew)
9860 && uentry_isExtern (unew))
9861 {
9862 if (optgenerror (FLG_REDECL,
9863 message ("%s %q declared after definition",
9864 ekind_capName (unew->ukind),
9865 uentry_getName (unew)),
9866 unew->whereDeclared))
9867 {
9868 llgenindentmsg (message ("Definition of %q",
9869 uentry_getName (old)),
9870 old->whereDefined);
9871 }
9872 }
9873 else
9874 {
9875 if (optgenerror (FLG_REDEF,
9876 message ("%s %q redefined",
9877 ekind_capName (unew->ukind),
9878 uentry_getName (unew)),
9879 unew->whereDefined))
9880 {
9881 llgenindentmsg (message ("Previous definition of %q",
9882 uentry_getName (old)),
9883 old->whereDefined);
9884 }
9885 }
9886 }
9887 }
9888 }
9889
9890 if (uentry_isExternal (unew))
9891 {
9892 old->whereDefined = fileloc_createExternal ();
9893 }
9894
9895 if (unew->hasNameError)
9896 {
9897 old->hasNameError = TRUE;
9898 }
9899
9900 uentry_free (unew);
9901
9902 if (!old->hasNameError)
9903 {
9904 uentry_checkName (old);
9905 }
9906
d89a0c94 9907 DPRINTF (("After: %s", uentry_unparseFull (old)));
616915dd 9908 llassert (!ctype_isUndefined (old->utype));
9909}
9910
9911void
9912uentry_copyState (uentry res, uentry other)
9913{
9914 llassert (uentry_isValid (res));
9915 llassert (uentry_isValid (other));
9916
9917 res->used = other->used;
9918
9919 res->info->var->kind = other->info->var->kind;
9920 res->info->var->defstate = other->info->var->defstate;
9921 res->info->var->nullstate = other->info->var->nullstate;
9922 res->info->var->checked = other->info->var->checked;
9923
9924 sRef_copyState (res->sref, other->sref);
9925}
9926
9927bool
9928uentry_sameKind (uentry u1, uentry u2)
9929{
9930 if (uentry_isValid (u1) && uentry_isValid (u2))
9931 {
9932 if (uentry_isVar (u1) && uentry_isVar (u2))
9933 {
9934 ctype c1 = u1->utype;
9935 ctype c2 = u2->utype;
9936
9937 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
9938
9939 /*
9940 ** both functions, or both not functions
9941 */
9942
9943 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
9944 }
9945 else
9946 {
9947 return ((u1->ukind == u2->ukind));
9948 }
9949 }
9950
9951 return FALSE;
9952}
9953
efd360a3 9954static void uentry_updateInto (/*@unique@*/ uentry unew, uentry old)
616915dd 9955{
abd7f895 9956 ekind okind;
616915dd 9957 llassert (uentry_isValid (unew));
9958 llassert (uentry_isValid (old));
9959
d89a0c94 9960 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
abd7f895 9961 okind = unew->ukind;
616915dd 9962 unew->ukind = old->ukind;
efd360a3 9963 llassert (cstring_equal (unew->uname, old->uname));
616915dd 9964 unew->utype = old->utype;
9965
efd360a3 9966 if (fileloc_isDefined (unew->whereSpecified)
9967 && !fileloc_isDefined (old->whereSpecified))
9968 {
9969 ; /* Keep the old value */
9970 }
9971 else
9972 {
b73d1009 9973 fileloc_free (unew->whereSpecified);
efd360a3 9974 unew->whereSpecified = fileloc_copy (old->whereSpecified);
9975 }
9976
9977 if (fileloc_isDefined (unew->whereDefined)
9978 && !fileloc_isDefined (old->whereDefined))
9979 {
9980 ; /* Keep the old value */
9981 }
9982 else
9983 {
b73d1009 9984 fileloc_free (unew->whereDefined);
efd360a3 9985 unew->whereDefined = fileloc_copy (old->whereDefined);
9986 }
9987
9988 if (fileloc_isDefined (unew->whereDeclared)
9989 && !fileloc_isDefined (old->whereDeclared))
9990 {
9991 ; /* Keep the old value */
9992 }
9993 else
9994 {
b73d1009 9995 fileloc_free (unew->whereDeclared);
efd360a3 9996 unew->whereDeclared = fileloc_copy (old->whereDeclared);
9997 }
616915dd 9998
d89a0c94 9999 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
10000
616915dd 10001 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
10002 unew->used = old->used;
10003 unew->lset = FALSE;
10004 unew->isPrivate = old->isPrivate;
10005 unew->hasNameError = old->hasNameError;
efd360a3 10006 unew->uses = filelocList_append (unew->uses, old->uses);
10007 old->uses = filelocList_undefined;
616915dd 10008
10009 unew->storageclass = old->storageclass;
efd360a3 10010 uinfo_free (unew->info, okind);
616915dd 10011 unew->info = uinfo_copy (old->info, old->ukind);
10012}
10013
6fcd0b1e 10014static uentry
10015uentry_copyAux (uentry e, bool saveCopy)
616915dd 10016{
6fcd0b1e 10017
616915dd 10018 if (uentry_isValid (e))
10019 {
10020 uentry enew = uentry_alloc ();
10021 DPRINTF (("copy: %s", uentry_unparseFull (e)));
efd360a3 10022 enew->ukind = e->ukind;
10023 enew->uname = cstring_copy (e->uname);
10024 enew->utype = e->utype;
10025
10026 enew->whereSpecified = fileloc_copy (e->whereSpecified);
10027 enew->whereDefined = fileloc_copy (e->whereDefined);
10028 enew->whereDeclared = fileloc_copy (e->whereDeclared);
10029
6fcd0b1e 10030 if (saveCopy)
10031 {
10032 enew->sref = sRef_saveCopy (e->sref); /* Memory leak! */
10033 }
10034 else
10035 {
10036 enew->sref = sRef_copy (e->sref);
10037 }
10038
efd360a3 10039 enew->used = e->used;
10040 enew->lset = FALSE;
10041 enew->isPrivate = e->isPrivate;
10042 enew->hasNameError = e->hasNameError;
10043 enew->uses = filelocList_undefined;
10044
10045 enew->storageclass = e->storageclass;
10046 enew->info = uinfo_copy (e->info, e->ukind);
10047 enew->warn = warnClause_copy (e->warn);
10048
616915dd 10049 DPRINTF (("Here we are..."));
10050 DPRINTF (("original: %s", uentry_unparseFull (e)));
10051 DPRINTF (("copy: %s", uentry_unparse (enew)));
10052 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
10053 return enew;
10054 }
10055 else
10056 {
10057 return uentry_undefined;
10058 }
10059}
10060
6fcd0b1e 10061uentry
10062uentry_copy (uentry e)
10063{
10064 return uentry_copyAux (e, TRUE);
10065}
10066
10067uentry
10068uentry_copyNoSave (uentry e)
10069{
10070 return uentry_copyAux (e, FALSE);
10071}
10072
616915dd 10073void
10074uentry_setState (uentry res, uentry other)
10075{
10076 llassert (uentry_isValid (res));
10077 llassert (uentry_isValid (other));
10078
10079 llassert (res->ukind == other->ukind);
10080 llassert (res->ukind == KVAR);
10081
10082 res->sref = sRef_saveCopy (other->sref);
10083 res->used = other->used;
10084 filelocList_free (res->uses);
10085 res->uses = other->uses;
10086 other->uses = filelocList_undefined;
10087 res->lset = other->lset;
10088}
10089
10090void
10091uentry_mergeUses (uentry res, uentry other)
10092{
10093 llassert (uentry_isValid (res));
10094 llassert (uentry_isValid (other));
10095
10096 res->used = other->used || res->used;
10097 res->lset = other->lset || res->lset;
10098 res->uses = filelocList_append (res->uses, other->uses);
10099 other->uses = filelocList_undefined;
10100}
10101
10102
10103/*
10104** This is a really ugly routine.
10105**
10106** gack...fix this one day.
10107*/
10108
10109/*
10110** flip == TRUE
10111** >> res is the false branch, other is the true branch (or continuation)
10112** flip == FALSE
10113** >> res is the true branch, other is the false branch (or continutation)
10114**
10115** opt == TRUE if,
10116**
10117** <other>
10118** if <res> ;
10119**
10120** References not effected by res are propagated from other.
10121*/
10122
10123static void
b87215ab 10124branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10125 bool flip, clause cl, fileloc loc)
616915dd 10126{
10127 if (optgenerror
10128 (FLG_BRANCHSTATE,
10129 message ("%s %q is %s %s, but %s %s.",
10130 ekind_capName (res->ukind), uentry_getName (res),
10131 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
10132 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
10133 loc))
10134 {
16c024b5 10135 DPRINTF (("Here: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
10136
616915dd 10137 if (sRef_isDead (res->sref))
10138 {
16c024b5 10139 if (sRef_hasStateInfoLoc (res->sref)) {
10140 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10141 sRef_showStateInfo (res->sref);
10142 }
10143
10144 if (sRef_hasStateInfoLoc (other->sref)) {
10145 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10146 sRef_showStateInfo (other->sref);
10147 }
616915dd 10148 }
10149 else if (sRef_isKept (res->sref))
10150 {
16c024b5 10151 if (sRef_hasAliasInfoLoc (res->sref)) {
10152 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10153 sRef_showAliasInfo (res->sref);
10154 }
10155
10156 if (sRef_hasAliasInfoLoc (other->sref)) {
10157 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10158 sRef_showAliasInfo (other->sref);
10159 }
616915dd 10160 }
10161 else /* dependent */
10162 {
16c024b5 10163 if (sRef_hasAliasInfoLoc (res->sref)) {
10164 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10165 sRef_showAliasInfo (res->sref);
10166 }
10167
10168 if (sRef_hasAliasInfoLoc (other->sref)) {
10169 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10170 sRef_showAliasInfo (other->sref);
10171 }
616915dd 10172 }
10173
10174 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
10175 }
10176}
10177
60868d40 10178static bool uentry_incompatibleMemoryStates (sRef rs, sRef os)
616915dd 10179{
10180 alkind rk = sRef_getAliasKind (rs);
10181 alkind ok = sRef_getAliasKind (os);
10182
10183 if (alkind_isError (rk) || alkind_isError (ok))
10184 {
10185 return FALSE;
10186 }
10187 else
10188 {
10189 return ((sRef_isDead (rs)
10190 || (alkind_isKept (rk) && !alkind_isKept (ok))
10191 || (alkind_isDependent (rk)
10192 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
10193 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
10194 }
10195}
10196
10197static void
10198 branchStateAltError (/*@notnull@*/ uentry res,
10199 /*@notnull@*/ uentry other, bool flip,
10200 clause cl, fileloc loc)
10201{
10202 if (optgenerror
10203 (FLG_BRANCHSTATE,
10204 message ("%s %q is %s %s, but %s %s.",
10205 ekind_capName (res->ukind), uentry_getName (res),
10206 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
10207 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
10208 loc))
10209 {
10210 if (sRef_isDead (other->sref))
10211 {
16c024b5 10212 if (sRef_hasStateInfoLoc (other->sref)) {
10213 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10214 sRef_showStateInfo (other->sref);
10215 }
10216
10217 if (sRef_hasStateInfoLoc (res->sref)) {
10218 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10219 sRef_showStateInfo (res->sref);
10220 }
616915dd 10221 }
10222 else /* kept */
10223 {
16c024b5 10224 if (sRef_hasAliasInfoLoc (other->sref)) {
10225 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10226 sRef_showAliasInfo (other->sref);
10227 }
10228
10229 if (sRef_hasAliasInfoLoc (res->sref)) {
10230 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10231 sRef_showAliasInfo (res->sref);
10232 }
616915dd 10233 }
10234
10235 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
10236 sRef_setDefinedComplete (res->sref, fileloc_undefined);
10237
10238 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
10239 sRef_setDefinedComplete (other->sref, fileloc_undefined);
10240 }
10241}
10242
28bf4b0b 10243/*
10244** A reference is relevant for certain checks, only if it
10245** is not definitely null on this path (but not declared
10246** to always be null.)
10247*/
10248
10249static bool uentry_relevantReference (sRef sr, bool flip)
616915dd 10250{
28bf4b0b 10251 if (sRef_isKept (sr) || sRef_isDependent (sr))
10252 {
10253 return FALSE;
10254 }
10255 else
10256 {
10257 if (flip)
10258 {
10259 return !sRef_definitelyNullContext (sr);
10260 }
10261 else
10262 {
10263 return !sRef_definitelyNullAltContext (sr);
10264 }
10265 }
616915dd 10266}
616915dd 10267
28bf4b0b 10268static void
abd7f895 10269uentry_mergeAliasStates (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10270 fileloc loc, bool mustReturn, bool flip, bool opt,
28bf4b0b 10271 clause cl)
10272{
60868d40 10273 sRef rs = res->sref;
10274 sRef os = other->sref;
10275
28bf4b0b 10276 DPRINTF (("Merge alias states: %s / %s",
10277 uentry_unparseFull (res),
10278 uentry_unparseFull (other)));
616915dd 10279
60868d40 10280 if (sRef_isValid (rs))
616915dd 10281 {
10282 if (!mustReturn)
10283 {
60868d40 10284 if (uentry_incompatibleMemoryStates (rs, os))
616915dd 10285 {
60868d40 10286 DPRINTF (("Incompatible: \n\t%s / \n\t%s",
10287 sRef_unparseFull (rs), sRef_unparseFull (os)));
28bf4b0b 10288
60868d40 10289 if (sRef_isThroughArrayFetch (rs)
616915dd 10290 && !context_getFlag (FLG_STRICTBRANCHSTATE))
10291 {
60868d40 10292 if (sRef_isKept (rs) || sRef_isKept (os))
616915dd 10293 {
60868d40 10294 sRef_maybeKill (rs, loc);
616915dd 10295 }
60868d40 10296 else if (sRef_isPossiblyDead (os))
616915dd 10297 {
60868d40 10298 sRef_maybeKill (rs, loc);
616915dd 10299 }
10300 else
10301 {
10302 ;
10303 }
10304 }
10305 else
10306 {
60868d40 10307 if (uentry_relevantReference (os, flip))
616915dd 10308 {
60868d40 10309 if (sRef_isLocalParamVar (rs)
10310 && (sRef_isLocalState (os)
10311 || sRef_isDependent (os)))
616915dd 10312 {
60868d40 10313 if (sRef_isDependent (rs))
616915dd 10314 {
60868d40 10315 sRef_setDependent (os, loc);
616915dd 10316 }
10317 else
10318 {
60868d40 10319 sRef_setDefState (rs, SS_UNUSEABLE, loc);
616915dd 10320 }
10321 }
10322 else
10323 {
16c024b5 10324 branchStateError (res, other, !flip, cl, loc); /* evans 2002-12-15: changed flip to !flip */
616915dd 10325 }
10326 }
10327 }
10328
60868d40 10329 if (sRef_isKept (rs))
616915dd 10330 {
60868d40 10331 DPRINTF (("Setting kept: %s", sRef_unparseFull (os)));
10332 sRef_setKept (os, loc);
616915dd 10333 }
10334 }
10335 else
10336 {
60868d40 10337 if (uentry_incompatibleMemoryStates (os, rs))
616915dd 10338 {
60868d40 10339 if (uentry_relevantReference (rs, !flip))
616915dd 10340 {
60868d40 10341 if (sRef_isLocalParamVar (rs)
10342 && (sRef_isDependent (rs)
10343 || sRef_isLocalState (rs)))
616915dd 10344 {
60868d40 10345 if (sRef_isDependent (os))
616915dd 10346 {
60868d40 10347 sRef_setDependent (rs, loc);
616915dd 10348 }
10349 else
10350 {
60868d40 10351 sRef_setDefState (rs, SS_UNUSEABLE, loc);
616915dd 10352 }
10353 }
10354 else
10355 {
60868d40 10356 if (sRef_isParam (os))
616915dd 10357 {
10358 /*
10359 ** If the local variable associated
10360 ** with the param has the correct state,
10361 ** its okay.
10362 ** (e.g., free (s); s = new(); ...
10363 */
28bf4b0b 10364
616915dd 10365 uentry uvar = usymtab_lookupSafe (other->uname);
28bf4b0b 10366
616915dd 10367 if (uentry_isValid (uvar)
60868d40 10368 && ((sRef_isDead (os)
616915dd 10369 && sRef_isOnly (uvar->sref))
60868d40 10370 || (sRef_isDependent (os)
616915dd 10371 && sRef_isOwned (uvar->sref))))
10372 {
10373 /* no error */
10374 }
10375 else
10376 {
10377 branchStateAltError (res, other,
10378 flip, cl, loc);
10379 }
10380 }
10381 else
10382 {
28bf4b0b 10383 DPRINTF (("Here: %s / %s",
10384 uentry_unparseFull (res),
10385 uentry_unparseFull (other)));
10386
616915dd 10387 branchStateAltError (res, other,
10388 flip, cl, loc);
10389 }
10390 }
10391 }
10392 }
28bf4b0b 10393
60868d40 10394 if (sRef_isKept (os))
616915dd 10395 {
60868d40 10396 sRef_setKept (rs, loc);
616915dd 10397 }
10398 }
10399
10400 if (opt)
10401 {
10402 DPRINTF (("Merge opt..."));
60868d40 10403 sRef_mergeOptState (rs, os, cl, loc);
616915dd 10404 DPRINTF (("Done!"));
10405 }
10406 else
10407 {
60868d40 10408 DPRINTF (("Merging states: \n\t%s / \n\t%s", sRef_unparseFull (rs), sRef_unparseFull (os)));
10409 sRef_mergeState (rs, os, cl, loc);
10410 DPRINTF (("After merging : \n\t%s / \n\t%s", sRef_unparseFull (rs), sRef_unparseFull (os)));
616915dd 10411 }
10412 }
10413 else
10414 {
60868d40 10415 if (sRef_isModified (os))
616915dd 10416 {
60868d40 10417 sRef_setModified (rs);
616915dd 10418 }
10419 }
28bf4b0b 10420 }
60868d40 10421
10422 DPRINTF (("After merge: %s", sRef_unparseFull (res->sref)));
28bf4b0b 10423}
616915dd 10424
28bf4b0b 10425static void
abd7f895 10426uentry_mergeValueStates (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10427 fileloc loc, bool mustReturn, /*@unused@*/ bool flip)
28bf4b0b 10428{
10429 valueTable rvalues;
10430 valueTable ovalues;
10431
10432 DPRINTF (("Merge values: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
10433
b7e84605 10434 if (mustReturn)
10435 {
10436 return;
10437 }
10438 /* flip? */
10439
28bf4b0b 10440 rvalues = sRef_getValueTable (res->sref);
10441 ovalues = sRef_getValueTable (other->sref);
10442
10443 if (valueTable_isUndefined (ovalues))
10444 {
10445 DPRINTF (("No value table: %s", sRef_unparseFull (other->sref)));
10446 ;
10447 }
10448 else if (valueTable_isUndefined (rvalues))
10449 {
10450 /*
10451 ** Copy values from other
10452 */
10453
517a2db3 10454 /* ??? */
28bf4b0b 10455 }
10456 else
10457 {
10458 valueTable_elements (ovalues, fkey, fval) {
10459 stateValue tval;
10460 metaStateInfo minfo;
10461 stateCombinationTable sctable;
10462 cstring msg;
10463 int nval;
10464
10465 tval = valueTable_lookup (rvalues, fkey);
10466
10467 DPRINTF (("Merge value: %s / %s X %s", fkey,
10468 stateValue_unparse (fval), stateValue_unparse (tval)));
10469
10470 minfo = context_lookupMetaStateInfo (fkey);
10471 llassert (stateValue_isDefined (tval));
10472
10473 if (metaStateInfo_isUndefined (minfo) || !stateValue_isDefined (tval))
10474 {
10475 DPRINTF (("Cannot find meta state for: %s", fkey));
10476 BADBRANCH;
10477 }
10478 else
10479 {
10480 llassert (metaStateInfo_isDefined (minfo));
10481
10482 if (stateValue_isError (fval)
10483 || sRef_definitelyNullContext (res->sref))
10484 {
10485 sRef_setMetaStateValueComplete (res->sref,
10486 fkey, stateValue_getValue (fval),
b7e84605 10487 stateValue_getLoc (fval));
28bf4b0b 10488 DPRINTF (("Setting res: %s", sRef_unparseFull (res->sref)));
10489 }
10490 else if (stateValue_isError (tval)
10491 || sRef_definitelyNullAltContext (other->sref))
10492 {
10493 DPRINTF (("Other branch is definitely null!"));
10494 }
b7e84605 10495 else if (sRef_isStateUndefined (res->sref)
10496 || sRef_isDead (res->sref))
10497 {
10498 ; /* Combination state doesn't matter if it is undefined or dead */
10499 }
28bf4b0b 10500 else
10501 {
10502 DPRINTF (("Check: %s / %s / %s / %s", fkey,
10503 metaStateInfo_unparse (minfo),
10504 stateValue_unparse (fval),
10505 stateValue_unparse (tval)));
10506
10507 DPRINTF (("state values: %d / %d",
10508 stateValue_getValue (fval), stateValue_getValue (tval)));
10509
10510 sctable = metaStateInfo_getMergeTable (minfo);
10511
10512 DPRINTF (("Merge table: %s",
10513 stateCombinationTable_unparse (sctable)));
10514
10515 msg = cstring_undefined;
10516
10517 nval = stateCombinationTable_lookup (sctable,
10518 stateValue_getValue (fval),
10519 stateValue_getValue (tval),
10520 &msg);
10521
10522 DPRINTF (("nval: %d / %d / %d", nval,
10523 stateValue_getValue (fval), stateValue_getValue (tval)));
10524
b7e84605 10525 if (nval == stateValue_error)
28bf4b0b 10526 {
28bf4b0b 10527 if (uentry_isGlobalMarker (res))
10528 {
10529 if (optgenerror
10530 (FLG_STATEMERGE,
10531 message
b7e84605 10532 ("Control branches merge with incompatible global states (%s and %s)%q",
28bf4b0b 10533 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10534 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
b7e84605 10535 cstring_isDefined (msg)
10536 ? message (": %s", msg) : cstring_undefined),
28bf4b0b 10537 loc))
10538 {
10539 sRef_showMetaStateInfo (res->sref, fkey);
10540 sRef_showMetaStateInfo (other->sref, fkey);
10541 }
10542 }
10543 else
10544 {
10545 if (optgenerror
10546 (FLG_STATEMERGE,
10547 message
b7e84605 10548 ("Control branches merge with incompatible states for %q (%s and %s)%q",
28bf4b0b 10549 uentry_getName (res),
10550 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10551 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
b7e84605 10552 cstring_isDefined (msg)
10553 ? message (": %s", msg) : cstring_undefined),
28bf4b0b 10554 loc))
10555 {
10556 sRef_showMetaStateInfo (res->sref, fkey);
10557 sRef_showMetaStateInfo (other->sref, fkey);
10558 DPRINTF (("Res: %s", sRef_unparseFull (res->sref)));
10559 DPRINTF (("Other: %s", sRef_unparseFull (other->sref)));
10560 DPRINTF (("Null: %s / %s",
10561 bool_unparse (usymtab_isDefinitelyNull (res->sref)),
10562 bool_unparse (usymtab_isDefinitelyNull (other->sref))));
10563
10564 }
10565 }
10566 }
10567
10568 if (nval == stateValue_getValue (fval)
10569 && nval != stateValue_getValue (tval))
10570 {
10571 loc = stateValue_getLoc (fval);
10572 }
10573 else if (nval == stateValue_getValue (tval)
10574 && nval != stateValue_getValue (fval))
10575 {
10576 loc = stateValue_getLoc (tval);
10577 }
10578 else
10579 {
10580 ;
10581 }
10582
10583 if (stateValue_getValue (sRef_getMetaStateValue (res->sref, fkey)) == nval
10584 && nval == stateValue_getValue (fval)
10585 && nval == stateValue_getValue (tval))
10586 {
10587 ;
10588 }
10589 else
10590 {
10591 sRef_setMetaStateValueComplete (res->sref, fkey, nval, loc);
10592 }
10593 }
10594 }
10595 } end_valueTable_elements ;
10596 }
10597}
10598
10599
10600static void
abd7f895 10601uentry_mergeSetStates (/*@notnull@*/ uentry res,
10602 /*@notnull@*/ uentry other, /*@unused@*/ fileloc loc,
28bf4b0b 10603 bool flip, clause cl)
10604{
10605 if (cl == DOWHILECLAUSE)
10606 {
10607 res->used = other->used || res->used;
10608 res->lset = other->lset || res->lset;
10609 res->uses = filelocList_append (res->uses, other->uses);
10610 other->uses = filelocList_undefined;
10611 }
10612 else
10613 {
10614 if (sRef_isMacroParamRef (res->sref)
10615 && !uentry_isSefParam (other)
10616 && !uentry_isSefParam (res))
616915dd 10617 {
28bf4b0b 10618 bool hasError = FALSE;
10619
10620 if (bool_equal (res->used, other->used))
616915dd 10621 {
28bf4b0b 10622 res->used = other->used;
10623 }
10624 else
10625 {
10626 if (other->used && !flip)
616915dd 10627 {
28bf4b0b 10628 hasError =
10629 optgenerror
10630 (FLG_MACROPARAMS,
10631 message ("Macro parameter %q used in true clause, "
10632 "but not in false clause",
10633 uentry_getName (res)),
10634 uentry_whereDeclared (res));
616915dd 10635 }
10636 else
28bf4b0b 10637 {
10638 hasError =
10639 optgenerror
10640 (FLG_MACROPARAMS,
10641 message ("Macro parameter %q used in false clause, "
10642 "but not in true clause",
10643 uentry_getName (res)),
10644 uentry_whereDeclared (res));
10645 }
10646 res->used = TRUE;
10647
10648 if (hasError)
616915dd 10649 {
28bf4b0b 10650 /* make it sef now, prevent more errors */
10651 res->info->var->kind = VKREFSEFPARAM;
616915dd 10652 }
10653 }
28bf4b0b 10654 }
10655 else
10656 {
10657 res->used = other->used || res->used;
10658 res->lset = other->lset || res->lset;
10659 res->uses = filelocList_append (res->uses, other->uses);
10660 other->uses = filelocList_undefined;
616915dd 10661 }
10662 }
10663}
10664
28bf4b0b 10665void
10666uentry_mergeState (uentry res, uentry other, fileloc loc,
10667 bool mustReturn, bool flip, bool opt,
10668 clause cl)
10669{
10670 llassert (uentry_isValid (res));
10671 llassert (uentry_isValid (other));
10672
10673 llassert (res->ukind == other->ukind);
10674 llassert (res->ukind == KVAR);
10675
10676 DPRINTF (("Merge state: %s / %s", uentry_unparseFull (res),
10677 uentry_unparseFull (other)));
10678
10679 uentry_mergeAliasStates (res, other, loc, mustReturn, flip, opt, cl);
b7e84605 10680 uentry_mergeValueStates (res, other, loc, mustReturn, flip);
28bf4b0b 10681 uentry_mergeSetStates (res, other, loc, flip, cl);
3e3ec469 10682
10683 DPRINTF (("Merge ==> %s", uentry_unparseFull (res)));
28bf4b0b 10684}
10685
616915dd 10686void uentry_setUsed (uentry e, fileloc loc)
10687{
10688 static bool firstTime = TRUE;
10689 static bool showUses = FALSE;
10690 static bool exportLocal = FALSE;
10691
28bf4b0b 10692 DPRINTF (("Used: %s / %s", uentry_unparse (e), fileloc_unparse (loc)));
10693
616915dd 10694 if (firstTime)
10695 {
10696 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
10697
10698 showUses = context_getFlag (FLG_SHOWUSES);
10699 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
10700
10701 firstTime = FALSE;
10702 }
10703
10704 if (uentry_isValid (e))
10705 {
28bf4b0b 10706 if (warnClause_isDefined (e->warn))
10707 {
10708 flagSpec flg = warnClause_getFlag (e->warn);
10709 cstring msg;
10710
10711 if (warnClause_hasMessage (e->warn))
10712 {
10713 msg = cstring_copy (warnClause_getMessage (e->warn));
10714 }
10715 else
10716 {
10717 msg = message ("Use of possibly dangerous %s",
10718 uentry_ekindNameLC (e));
10719 }
10720
10721 vfsgenerror (flg,
10722 message ("%q: %q", msg, uentry_getName (e)),
10723 loc);
10724 }
10725
616915dd 10726 if (sRef_isMacroParamRef (e->sref))
10727 {
10728 if (uentry_isYield (e) || uentry_isSefParam (e))
10729 {
10730 ;
10731 }
10732 else
10733 {
10734 if (context_inConditional ())
10735 {
10736 if (optgenerror
10737 (FLG_MACROPARAMS,
10738 message ("Macro parameter %q used in conditionally "
10739 "executed code (may or may not be "
10740 "evaluated exactly once)",
10741 uentry_getName (e)),
10742 loc))
10743 {
10744 e->info->var->kind = VKREFSEFPARAM;
10745 }
10746 }
10747 else
10748 {
10749 if ((e)->used)
10750 {
10751 if (optgenerror
10752 (FLG_MACROPARAMS,
10753 message ("Macro parameter %q used more than once",
10754 uentry_getName (e)),
10755 uentry_whereDeclared (e)))
10756 {
10757 e->info->var->kind = VKREFSEFPARAM;
10758 }
10759 }
10760 }
10761 }
10762 }
10763
b73d1009 10764 if (usymId_isValid (usymtab_directParamNo (e)))
616915dd 10765 {
b73d1009 10766 uentry_setUsed (usymtab_getParam (usymId_toInt (usymtab_directParamNo (e))), loc);
616915dd 10767 }
10768
10769 e->used = TRUE;
28bf4b0b 10770
616915dd 10771 if (!sRef_isLocalVar (e->sref))
10772 {
10773 if (showUses)
10774 {
10775 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
10776 }
10777 else
10778 {
10779 if (exportLocal)
10780 {
10781 if (context_inMacro ())
10782 {
10783 e->uses = filelocList_addUndefined (e->uses);
10784 }
10785 else
10786 {
10787 e->uses = filelocList_addDifferentFile
10788 (e->uses,
10789 uentry_whereDeclared (e),
10790 loc);
10791 }
10792 }
10793 }
10794 }
10795 }
10796}
10797
10798bool uentry_isReturned (uentry u)
10799{
10800 return (uentry_isValid (u) && uentry_isVar (u)
10801 && (u->info->var->kind == VKRETPARAM
10802 || u->info->var->kind == VKSEFRETPARAM));
10803}
10804
6fcd0b1e 10805/*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args, fileloc loc)
616915dd 10806{
10807 llassert (uentry_isRealFunction (u));
10808
28bf4b0b 10809 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
616915dd 10810 {
28bf4b0b 10811 stateClauseList clauses = uentry_getStateClauseList (u);
10812 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
616915dd 10813
28bf4b0b 10814 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
6fcd0b1e 10815 sRef_setAllocated (res, loc);
616915dd 10816
28bf4b0b 10817 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10818 stateClauseList_unparse (clauses)));
616915dd 10819
ccf0a4a8 10820 /*
10821 ** This should be in exprNode_reflectEnsuresClause
10822 */
10823
28bf4b0b 10824 stateClauseList_postElements (clauses, cl)
10825 {
10826 if (!stateClause_isGlobal (cl))
616915dd 10827 {
28bf4b0b 10828 sRefSet refs = stateClause_getRefs (cl);
10829 sRefMod modf = stateClause_getEffectFunction (cl);
10830
10831 sRefSet_elements (refs, el)
616915dd 10832 {
28bf4b0b 10833 sRef base = sRef_getRootBase (el);
10834
10835 if (sRef_isResult (base))
616915dd 10836 {
28bf4b0b 10837 if (modf != NULL)
10838 {
10839 sRef sr = sRef_fixBase (el, res);
6fcd0b1e 10840 modf (sr, loc);
28bf4b0b 10841 }
616915dd 10842 }
28bf4b0b 10843 else
10844 {
10845 ;
10846 }
10847 } end_sRefSet_elements ;
10848 }
10849 } end_stateClauseList_postElements ;
ccf0a4a8 10850
616915dd 10851 return res;
10852 }
10853 else
10854 {
10855 uentryList params;
10856 alkind ak;
10857 sRefSet prefs = sRefSet_new ();
10858 sRef res = sRef_undefined;
10859 int paramno = 0;
10860
10861 params = uentry_getParams (u);
10862
10863 uentryList_elements (params, current)
10864 {
10865 if (uentry_isReturned (current))
10866 {
10867 if (exprNodeList_size (args) >= paramno)
10868 {
10869 exprNode ecur = exprNodeList_nth (args, paramno);
10870 sRef tref = exprNode_getSref (ecur);
10871
28bf4b0b 10872 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10873
616915dd 10874 if (sRef_isValid (tref))
10875 {
10876 sRef tcref = sRef_copy (tref);
10877
28bf4b0b 10878 usymtab_addForceMustAlias (tcref, tref); /* evans 2001-05-27 */
10879
6fcd0b1e 10880 if (sRef_isNew (tcref))
10881 {
10882 /* tcref->kind = SK_OBJECT; */ /*!! Not new anymore */
10883 }
10884
616915dd 10885 if (sRef_isDead (tcref))
10886 {
6fcd0b1e 10887 sRef_setDefined (tcref, loc);
10888 sRef_setOnly (tcref, loc);
616915dd 10889 }
10890
10891 if (sRef_isRefCounted (tcref))
10892 {
10893 /* could be a new ref now (but only if its returned) */
6fcd0b1e 10894 sRef_setAliasKindComplete (tcref, AK_ERROR, loc);
616915dd 10895 }
10896
10897 sRef_makeSafe (tcref);
6fcd0b1e 10898 DPRINTF (("Returns tcref / %s", sRef_unparseFull (tcref)));
616915dd 10899 prefs = sRefSet_insert (prefs, tcref);
10900 }
10901 }
10902 }
10903
10904 paramno++;
10905 } end_uentryList_elements ;
10906
10907 if (sRefSet_size (prefs) > 0)
10908 {
10909 nstate n = sRef_getNullState (u->sref);
10910
10911 if (sRefSet_size (prefs) == 1)
10912 {
10913 res = sRefSet_choose (prefs);
10914 }
10915 else
10916 {
b73d1009 10917 /* should this ever happen? */
616915dd 10918 res = sRefSet_mergeIntoOne (prefs);
10919 }
10920
10921 if (nstate_isKnown (n))
10922 {
6fcd0b1e 10923 sRef_setNullState (res, n, loc);
616915dd 10924 }
10925 }
10926 else
10927 {
10928 if (ctype_isFunction (u->utype))
10929 {
28bf4b0b 10930 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10931 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
616915dd 10932 }
10933 else
10934 {
10935 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
10936 }
10937
10938 if (sRef_isRefCounted (res))
10939 {
6fcd0b1e 10940 sRef_setAliasKind (res, AK_NEWREF, loc);
616915dd 10941 }
10942 }
10943
28bf4b0b 10944
616915dd 10945 if (sRef_getNullState (res) == NS_ABSNULL)
10946 {
10947 ctype ct = ctype_realType (u->utype);
10948
10949 if (ctype_isAbstract (ct))
10950 {
6fcd0b1e 10951 sRef_setNotNull (res, loc);
616915dd 10952 }
10953 else
10954 {
10955 if (ctype_isUser (ct))
10956 {
10957 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
10958 }
10959 else
10960 {
6fcd0b1e 10961 sRef_setNotNull (res, loc);
616915dd 10962 }
10963 }
10964 }
10965
10966 if (sRef_isRefCounted (res))
10967 {
6fcd0b1e 10968 sRef_setAliasKind (res, AK_NEWREF, loc);
616915dd 10969 }
10970 else if (sRef_isKillRef (res))
10971 {
6fcd0b1e 10972 sRef_setAliasKind (res, AK_REFCOUNTED, loc);
616915dd 10973 }
10974 else
10975 {
10976 ;
10977 }
10978
10979 ak = sRef_getAliasKind (res);
10980
10981 if (alkind_isImplicit (ak))
10982 {
10983 sRef_setAliasKind (res,
10984 alkind_fixImplicit (ak),
6fcd0b1e 10985 loc);
616915dd 10986 }
10987
10988 sRefSet_free (prefs);
6fcd0b1e 10989
10990 /*
10991 if (sRef_isOnly (res))
10992 {
10993 sRef_setFresh (res, loc);
10994 }
10995 */
10996
28bf4b0b 10997 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
616915dd 10998 return res;
10999 }
11000}
11001
11002static bool uentry_isRefCounted (uentry ue)
11003{
11004 ctype ct = uentry_getType (ue);
11005
11006 if (ctype_isFunction (ct))
11007 {
28bf4b0b 11008 return (ctype_isRefCounted (ctype_getReturnType (ct)));
616915dd 11009 }
11010 else
11011 {
11012 return (ctype_isRefCounted (ct));
11013 }
11014}
11015
11016/*
11017** old was declared yield in the specification.
11018** new is declared in the iter implementation.
11019*/
11020
11021void uentry_checkYieldParam (uentry old, uentry unew)
11022{
11023 cstring name;
11024
11025 llassert (uentry_isVariable (old));
11026 llassert (uentry_isVariable (unew));
11027
11028 unew->info->var->kind = VKYIELDPARAM;
11029 (void) checkTypeConformance (old, unew, TRUE);
11030 checkVarConformance (old, unew, TRUE, FALSE);
11031
11032 /* get rid of param marker */
11033
11034 name = uentry_getName (unew);
11035 cstring_free (unew->uname);
11036 unew->uname = name;
11037 unew->info->var->kind = VKREFYIELDPARAM;
11038
11039 uentry_setUsed (old, fileloc_undefined);
11040 uentry_setUsed (unew, fileloc_undefined);
11041}
11042
11043/*@observer@*/ cstring
11044uentry_ekindName (uentry ue)
11045{
11046 if (uentry_isValid (ue))
11047 {
11048 switch (ue->ukind)
11049 {
11050 case KINVALID:
11051 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
11052 case KDATATYPE:
11053 return cstring_makeLiteralTemp ("Datatype");
11054 case KENUMCONST:
11055 return cstring_makeLiteralTemp ("Enum member");
11056 case KCONST:
11057 return cstring_makeLiteralTemp ("Constant");
11058 case KVAR:
11059 if (uentry_isParam (ue))
11060 {
11061 return cstring_makeLiteralTemp ("Parameter");
11062 }
11063 else if (uentry_isExpandedMacro (ue))
11064 {
11065 return cstring_makeLiteralTemp ("Expanded macro");
11066 }
11067 else
11068 {
11069 return cstring_makeLiteralTemp ("Variable");
11070 }
11071 case KFCN:
11072 return cstring_makeLiteralTemp ("Function");
11073 case KITER:
11074 return cstring_makeLiteralTemp ("Iterator");
11075 case KENDITER:
11076 return cstring_makeLiteralTemp ("Iterator finalizer");
11077 case KSTRUCTTAG:
11078 return cstring_makeLiteralTemp ("Struct tag");
11079 case KUNIONTAG:
11080 return cstring_makeLiteralTemp ("Union tag");
11081 case KENUMTAG:
11082 return cstring_makeLiteralTemp ("Enum tag");
11083 case KELIPSMARKER:
11084 return cstring_makeLiteralTemp ("Optional parameters");
11085 }
11086 }
11087 else
11088 {
11089 return cstring_makeLiteralTemp ("<Undefined>");
11090 }
11091
11092 BADEXIT;
11093}
11094
28bf4b0b 11095/*@observer@*/ cstring
11096uentry_ekindNameLC (uentry ue)
11097{
11098 if (uentry_isValid (ue))
11099 {
11100 switch (ue->ukind)
11101 {
11102 case KINVALID:
11103 return cstring_makeLiteralTemp ("<error: invalid uentry>");
11104 case KDATATYPE:
11105 return cstring_makeLiteralTemp ("datatype");
11106 case KENUMCONST:
11107 return cstring_makeLiteralTemp ("enum member");
11108 case KCONST:
11109 return cstring_makeLiteralTemp ("constant");
11110 case KVAR:
11111 if (uentry_isParam (ue))
11112 {
11113 return cstring_makeLiteralTemp ("parameter");
11114 }
11115 else if (uentry_isExpandedMacro (ue))
11116 {
11117 return cstring_makeLiteralTemp ("expanded macro");
11118 }
11119 else
11120 {
11121 return cstring_makeLiteralTemp ("variable");
11122 }
11123 case KFCN:
11124 return cstring_makeLiteralTemp ("function");
11125 case KITER:
11126 return cstring_makeLiteralTemp ("iterator");
11127 case KENDITER:
11128 return cstring_makeLiteralTemp ("iterator finalizer");
11129 case KSTRUCTTAG:
11130 return cstring_makeLiteralTemp ("struct tag");
11131 case KUNIONTAG:
11132 return cstring_makeLiteralTemp ("union tag");
11133 case KENUMTAG:
11134 return cstring_makeLiteralTemp ("enum tag");
11135 case KELIPSMARKER:
11136 return cstring_makeLiteralTemp ("optional parameters");
11137 }
11138 }
11139 else
11140 {
11141 return cstring_makeLiteralTemp ("<Undefined>");
11142 }
11143
11144 BADEXIT;
11145}
11146
616915dd 11147void uentry_setHasNameError (uentry ue)
11148{
11149 llassert (uentry_isValid (ue));
11150
11151 ue->hasNameError = TRUE;
11152}
11153
11154void uentry_checkName (uentry ue)
11155{
28bf4b0b 11156 DPRINTF (("Checking name: %s / %s / %s", uentry_unparse (ue),
11157 uentry_observeRealName (ue),
11158 bool_unparse (uentry_isVisibleExternally (ue))));
11159
616915dd 11160 if (uentry_isValid (ue)
28bf4b0b 11161 && !context_inXHFile ()
11162 && uentry_hasName (ue)
616915dd 11163 && !uentry_isElipsisMarker (ue)
11164 && context_getFlag (FLG_NAMECHECKS)
11165 && !ue->hasNameError
11166 && !uentry_isEndIter (ue)
11167 && !fileloc_isBuiltin (uentry_whereLast (ue))
11168 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
28bf4b0b 11169 {
11170 DPRINTF (("Here..."));
11171
616915dd 11172 if (uentry_isPriv (ue))
11173 {
11174 ; /* any checks here? */
11175 }
11176 else if (fileloc_isExternal (uentry_whereDefined (ue)))
11177 {
11178 ; /* no errors for externals */
11179 }
11180 else
11181 {
11182 int scope;
11183
11184 if (uentry_isExpandedMacro (ue))
11185 {
11186 scope = globScope;
11187 }
11188 else
11189 {
11190 if (uentry_isExpandedMacro (ue))
11191 {
11192 scope = fileScope;
11193 }
11194 else if (uentry_isVariable (ue))
11195 {
11196 sRef sr = uentry_getSref (ue);
11197
11198 if (sRef_isValid (sr))
11199 {
11200 scope = sRef_getScope (sr);
11201 }
11202 else
11203 {
11204 scope = fileScope;
11205 }
11206 }
11207 else if (uentry_isFunction (ue)
11208 || uentry_isIter (ue)
11209 || uentry_isEndIter (ue)
11210 || uentry_isConstant (ue))
11211 {
11212 scope = uentry_isStatic (ue) ? fileScope : globScope;
11213 }
11214 else /* datatypes, etc. must be global */
11215 {
11216 scope = globScope;
11217 }
11218
11219 usymtab_checkDistinctName (ue, scope);
11220 }
28bf4b0b 11221
616915dd 11222 if (context_getFlag (FLG_CPPNAMES))
11223 {
28bf4b0b 11224 checkCppName (ue);
616915dd 11225 }
11226
11227 if (scope == globScope)
11228 {
28bf4b0b 11229 checkExternalName (ue);
616915dd 11230 }
28bf4b0b 11231 else if (scope == fileScope)
11232 {
11233 checkFileScopeName (ue);
11234 }
11235 else
616915dd 11236 {
11237 checkLocalName (ue);
616915dd 11238 }
11239
616915dd 11240 checkPrefix (ue);
28bf4b0b 11241 checkAnsiName (ue);
616915dd 11242 }
11243 }
11244}
11245
7ebcc5bb 11246/*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@only@*/ fileloc loc)
616915dd 11247{
11248 uentry ue;
11249 fileloc tloc;
11250
11251 /*
7ebcc5bb 11252 ** Can't but unrecognized ids in macros in global scope, because srefs will break!
11253 */
11254
616915dd 11255 if (!context_inMacro ())
11256 {
11257 sRef_setGlobalScopeSafe ();
11258 }
11259
11260 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
11261 uentry_setUsed (ue, loc);
11262
11263 tloc = fileloc_createExternal ();
11264 uentry_setDefined (ue, tloc);
11265 fileloc_free (tloc);
11266 uentry_setHasNameError (ue);
11267
c3be2604 11268 if (context_getFlag (FLG_REPEATUNRECOG) || (context_inOldStyleScope()))
616915dd 11269 {
11270 uentry_markOwned (ue);
11271 }
11272 else
11273 {
11274 ue = usymtab_supReturnFileEntry (ue);
11275 }
11276
11277 if (!context_inMacro ())
11278 {
11279 sRef_clearGlobalScopeSafe ();
11280 }
11281
11282 return ue;
11283}
11284
28bf4b0b 11285uentry uentry_makeGlobalMarker ()
11286{
11287 uentry ue;
11288 fileloc tloc;
11289
11290 llassert (sRef_inGlobalScope ());
11291
11292 ue = uentry_makeVariableAux
11293 (GLOBAL_MARKER_NAME, ctype_unknown, fileloc_undefined,
11294 sRef_makeGlobalMarker (),
11295 FALSE, VKNORMAL);
11296
11297 tloc = fileloc_createExternal ();
11298 uentry_setUsed (ue, tloc);
11299 uentry_setDefined (ue, tloc);
11300 fileloc_free (tloc);
11301 uentry_setHasNameError (ue);
11302
11303 return ue;
11304}
11305
11306
11307bool uentry_isGlobalMarker (uentry ue)
11308{
11309 return (uentry_isValid (ue)
11310 && (cstring_equal (uentry_rawName (ue), GLOBAL_MARKER_NAME)));
11311}
11312
616915dd 11313/* new start modifications */
28bf4b0b 11314
616915dd 11315/* start modifications */
11316/*
11317requires: p_e is defined, is a ptr/array variable
11318modifies: p_e
11319effects: sets the state of the variable
11320*/
11321
28bf4b0b 11322
abd7f895 11323void uentry_setPossiblyNullTerminatedState (uentry p_e)
11324{
11325 llassert (uentry_isValid (p_e));
616915dd 11326
abd7f895 11327 if (p_e->info != NULL)
11328 {
11329 if (p_e->info->var != NULL)
11330 {
11331 llassert (p_e->info->var->bufinfo != NULL);
11332 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
11333 sRef_setPossiblyNullTerminatedState (p_e->sref);
11334 }
11335 }
616915dd 11336}
11337
11338/*
11339requires: p_e is defined, is a ptr/array variable
11340modifies: p_e
11341effects: sets the size of the buffer
11342*/
11343
11344void uentry_setNullTerminatedState (uentry p_e) {
abd7f895 11345 llassert (uentry_isValid (p_e));
616915dd 11346
abd7f895 11347 if (p_e->info != NULL)
11348 {
11349 if (p_e->info->var != NULL)
11350 {
11351 llassert (p_e->info->var->bufinfo != NULL);
11352 p_e->info->var->bufinfo->bufstate = BB_NULLTERMINATED;
11353 sRef_setNullTerminatedState (p_e->sref);
11354 }
11355 }
616915dd 11356}
11357
616915dd 11358/*
11359requires: p_e is defined, is a ptr/array variable
11360modifies: p_e
11361effects: sets the size of the buffer
11362*/
11363
abd7f895 11364void uentry_setSize (uentry p_e, int size)
11365{
11366 if (uentry_isValid (p_e))
11367 {
11368 if (p_e->info != NULL)
11369 {
11370 if (p_e->info->var != NULL)
11371 {
11372 llassert (p_e->info->var->bufinfo != NULL);
11373 p_e->info->var->bufinfo->size = size;
11374 sRef_setSize (p_e->sref, size);
11375 }
11376 }
b7b694d6 11377 }
616915dd 11378}
11379
616915dd 11380/*
11381requires: p_e is defined, is a ptr/array variable
11382modifies: p_e
11383effects: sets the length of the buffer
11384*/
11385
abd7f895 11386void uentry_setLen (uentry p_e, int len)
11387{
11388 if (uentry_isValid (p_e))
11389 {
11390 if (p_e->info != NULL
11391 && p_e->info->var != NULL)
11392 {
11393 llassert (p_e->info->var->bufinfo != NULL);
11394 p_e->info->var->bufinfo->len = len;
11395 sRef_setLen (p_e->sref, len);
11396 }
b7b694d6 11397 }
616915dd 11398}
b7b694d6 11399
616915dd 11400/*@=type*/
ba45e1e4 11401
11402bool uentry_hasMetaStateEnsures (uentry e)
11403{
11404 if (uentry_isValid (e) && uentry_isFunction (e))
11405 {
11406 return functionConstraint_hasMetaStateConstraint (e->info->fcn->postconditions);
11407 }
11408 else
11409 {
11410 return FALSE;
11411 }
11412}
11413
ccf0a4a8 11414metaStateConstraintList uentry_getMetaStateEnsures (uentry e)
ba45e1e4 11415{
ccf0a4a8 11416 llassert (uentry_isValid (e) && uentry_isFunction (e));
11417 return functionConstraint_getMetaStateConstraints (e->info->fcn->postconditions);
ba45e1e4 11418}
6483a926 11419
b73d1009 11420
11421bool uentry_hasBufStateInfo (uentry ue)
11422{
11423 llassert (uentry_isValid (ue));
11424 return (ue->info->var->bufinfo != NULL);
11425}
11426
11427bool uentry_isNullTerminated (uentry ue)
11428{
11429 llassert (uentry_hasBufStateInfo (ue));
11430 llassert (ue->info->var->bufinfo != NULL);
11431 return ue->info->var->bufinfo->bufstate == BB_NULLTERMINATED;
11432}
11433
11434bool uentry_isPossiblyNullTerminated (uentry ue)
11435{
11436 llassert (uentry_hasBufStateInfo (ue));
11437 llassert (ue->info->var->bufinfo != NULL);
11438 return (ue->info->var->bufinfo->bufstate == BB_POSSIBLYNULLTERMINATED);
11439}
11440
11441bool uentry_isNotNullTerminated (uentry ue)
11442{
11443 llassert (uentry_hasBufStateInfo (ue));
11444 llassert (ue->info->var->bufinfo != NULL);
11445 return (ue->info->var->bufinfo->bufstate == BB_NOTNULLTERMINATED);
11446}
11447
6483a926 11448# ifdef DEBUGSPLINT
11449
11450/*
11451** For debugging only
11452*/
11453
11454void uentry_checkValid (uentry ue)
11455{
11456 if (uentry_isValid (ue))
11457 {
02b84d4b 11458 sRef_checkCompletelyReasonable (ue->sref);
6483a926 11459 }
11460}
11461
11462# endif
This page took 2.269374 seconds and 5 git commands to generate.