2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 # include "splintMacros.nf"
30 # include "structNames.h"
31 # include "nameChecks.h"
33 static /*@dependent@*/ uentry posRedeclared = uentry_undefined;
34 static /*@only@*/ fileloc posLoc = fileloc_undefined;
35 static int nuentries = 0;
36 static int totuentries = 0;
38 static void checkGlobalsModifies (/*@notnull@*/ uentry p_ue, sRefSet p_sr) ;
39 static void uentry_setDeclDef (uentry p_e, fileloc p_f) /*@modifies p_e@*/ ;
40 static bool uentry_isRefCounted (uentry p_ue) /*@*/ ;
41 static bool uentry_isRefsField (uentry p_ue) /*@*/ ;
42 static bool uentry_isReallySpecified (uentry p_e) /*@*/ ;
43 static void uentry_checkIterArgs (uentry p_ue);
44 static cstring uentry_dumpAux (uentry p_v, bool p_isParam);
46 static void uentry_showWhereLastKind (uentry p_spec) /*@modifies g_warningstream@*/ ;
48 static void uentry_combineModifies (uentry p_ue, /*@owned@*/ sRefSet p_sr)
51 static void uentry_addStateClause (uentry p_ue, /*@only@*/ stateClause p_sc)
55 static void checkAliasState (/*@notnull@*/ uentry p_old,
56 /*@notnull@*/ uentry p_unew,
57 bool p_mustConform, bool p_completeConform)
58 /*@modifies p_old, p_unew@*/ ;
59 static void checkNullState (/*@notnull@*/ uentry p_old,
60 /*@notnull@*/ uentry p_unew,
61 bool p_mustConform, bool p_completeConform)
62 /*@modifies p_old, p_unew@*/ ;
64 static void checkVarConformance (/*@notnull@*/ uentry p_old,
65 /*@notnull@*/ uentry p_unew,
66 bool p_mustConform, bool p_completeConform)
67 /*@modifies p_old, p_unew@*/;
69 static void uentry_setHasMods (uentry p_ue) /*@modifies p_ue@*/;
70 static void uentry_setHasGlobs (uentry p_ue) /*@modifies p_ue@*/;
72 static void uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry p_e);
74 static void uentry_setSpecDef (/*@special@*/ uentry p_e, /*@keep@*/ fileloc p_f)
75 /*@defines p_e->whereSpecified, p_e->whereDeclared, p_e->whereDefined@*/
78 static void returnValueError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_unew);
79 static void nargsError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_unew);
80 static /*@observer@*/ cstring paramStorageName (uentry p_ue) /*@*/ ;
81 static /*@observer@*/ cstring fcnErrName (uentry p_ue) /*@*/ ;
82 static /*@observer@*/ cstring checkedName (chkind p_checked) /*@*/ ;
84 paramTypeError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_oldCurrent,
85 ctype p_oldType, /*@notnull@*/ uentry p_unew,
86 /*@notnull@*/ uentry p_newCurrent,
87 ctype p_newType, int p_paramno) /*@modifies g_warningstream@*/ ;
89 static /*@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);
93 static /*@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) /*@*/ ;
98 static void uentry_convertVarFunction (uentry ue) /*@modifies ue@*/
100 if (uentry_isVariable (ue)
101 && (ctype_isFunction (ctype_realType (uentry_getType (ue)))
102 || ctype_isUnknown (uentry_getType (ue))))
104 uentry_makeVarFunction (ue);
108 static /*@out@*/ /*@notnull@*/ uentry uentry_alloc (void) /*@*/
110 uentry ue = (uentry) dmalloc (sizeof (*ue));
111 ue->warn = warnClause_undefined; /*@i32@*/
118 static cstring uentry_getOptName (uentry p_e) /*@*/ ;
119 static void uentry_updateInto (/*@unique@*/ uentry p_unew, uentry p_old) /*@modifies p_unew, p_old@*/ ;
121 static void uentry_setNullState (/*@notnull@*/ uentry p_ue, nstate p_ns);
122 static void uentry_setAliasKind (/*@notnull@*/ uentry p_ue, alkind p_ak);
123 static /*@only@*/ /*@null@*/ uinfo uinfo_copy (uinfo p_u, ekind p_kind);
124 static void uinfo_free (/*@only@*/ uinfo p_u, ekind p_kind);
125 static void ucinfo_free (/*@only@*/ ucinfo p_u);
126 static void uvinfo_free (/*@only@*/ uvinfo p_u);
130 static /*@only@*/ cstring ancontext_unparse (ancontext an)
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");
146 static int annots[AN_LAST][QU_LAST];
147 static int decls[AN_LAST];
148 static int shdecls[AN_LAST];
149 static int idecls[AN_LAST];
155 for (i = AN_UNKNOWN; i < AN_LAST; i++)
161 for (j = QU_UNKNOWN; j < QU_LAST; j++)
168 static void tallyAnnot (ancontext ac, qual q)
182 for (j = QU_UNKNOWN; j < QU_LAST; j++)
187 for (i = AN_UNKNOWN; i < AN_LAST; i++)
193 printf ("Context: %s (%d declarations, %d sharable, %d indirect)\n",
194 ancontext_unparse (i),
195 decls[i], shdecls[i], idecls[i]);
197 totdecls += decls[i];
198 totshdecls += shdecls[i];
199 totidecls += idecls[i];
201 for (j = QU_UNKNOWN; j < QU_LAST; j++)
203 total[j] += annots[i][j];
204 alltotals += annots[i][j];
207 printf (" Allocation:\n");
211 for (j = QU_UNKNOWN; j < QU_LAST; j++)
213 if (qual_isAliasQual (j) && !qual_isUnique (j))
215 if (annots[i][j] > 0)
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];
224 printf (" Exposure:\n");
228 for (j = QU_UNKNOWN; j < QU_LAST; j++)
230 if (qual_isExQual (j))
232 if (annots[i][j] > 0)
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];
241 printf (" Definition:\n");
243 for (j = QU_UNKNOWN; j < QU_LAST; j++)
245 if (qual_isAllocQual (j))
247 if (annots[i][j] > 0)
249 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
250 100.0 * (double)annots[i][j] / (double)decls[i]);
257 for (j = QU_UNKNOWN; j < QU_LAST; j++)
259 if (qual_isNull (j) || qual_isNotNull (j) || qual_isRelNull (j))
261 if (annots[i][j] > 0)
263 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
264 100.0 * (double)annots[i][j] / (double)decls[i]);
273 for (j = QU_UNKNOWN; j < QU_LAST; j++)
277 for (i = AN_UNKNOWN; i < AN_LAST; i++)
279 if (annots[i][j] > 0)
288 printf ("Annotation: %s\n", qual_unparse (j));
290 for (i = AN_UNKNOWN; i < AN_LAST; i++)
292 if (annots[i][j] > 0)
294 printf ("%25s: %5d\n", ancontext_unparse (i), annots[i][j]);
301 printf ("All Contexts\n");
303 for (j = QU_UNKNOWN; j < QU_LAST; j++)
307 printf ("%10s: %5d (%3.2f%%)\n", qual_unparse (j), total[j],
308 100.0 * (double)total[j] / (double)(totdecls));
313 printf ("Total Annotations: %d (%d decls, %d sharable, %d indirect)\n", alltotals, totdecls, totshdecls, totidecls); }
315 extern void uentry_tallyAnnots (uentry u, ancontext kind)
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;
323 if (kind == AN_UNKNOWN)
331 else if (e == KCONST || e == KENUMCONST)
335 else if (e == KFCN || e == KITER)
337 uentryList params = uentry_getParams (u);
340 uentryList_elements (params, current)
342 if (uentry_isReturned (current))
346 if (!uentry_isElipsisMarker (current))
348 uentry_tallyAnnots (current, AN_FCNPARAM);
350 } end_uentryList_elements;
354 if (ctype_isFunction (u->utype)
356 && ctype_isVisiblySharable (ctype_realType (ctype_getReturnType (u->utype))))
358 recordUnknown = TRUE;
361 else if (e == KDATATYPE || e == KSTRUCTTAG || e == KUNIONTAG || e == KENUMTAG)
363 ctype t = ctype_realType (u->utype);
367 uentryList fields = ctype_getFields (t);
369 uentryList_elements (fields, current)
371 uentry_tallyAnnots (current, AN_SUFIELD);
373 } end_uentryList_elements;
377 if (ctype_isVisiblySharable (u->utype))
379 recordUnknown = TRUE;
387 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
389 recordUnknown = TRUE;
396 if (kind == AN_FCNRETURN)
410 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
415 if (ctype_isRealPointer (ctype_realType (u->utype)))
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;
430 if (uentry_isReturned (u))
432 tallyAnnot (kind, QU_RETURNED);
438 if (ctype_isRefCounted (ctype_realType (u->utype))
439 || (ctype_isFunction (u->utype) &&
440 ctype_isRefCounted (ctype_realType (ctype_getReturnType (u->utype)))))
446 if (kind == AN_FCNPARAM)
448 tallyAnnot (kind, QU_TEMP);
450 else if (recordUnknown)
452 if (kind == AN_FCNRETURN)
455 tallyAnnot (kind, QU_UNKNOWN);
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;
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;
484 case XO_EXPOSED: tallyAnnot (kind, QU_EXPOSED); break;
485 case XO_OBSERVER: tallyAnnot (kind, QU_OBSERVER); break;
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;
499 case NS_ABSNULL: break;
505 static /*@observer@*/ cstring specCode_unparse (specCode s) /*@*/
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>");
519 static specCode specCode_fromInt (int i)
522 llassert (i >= SPC_NONE && i < SPC_LAST);
524 return ((specCode) i);
528 /*@observer@*/ cstring uentry_specOrDefName (uentry u)
530 if (uentry_isDeclared (u))
532 return cstring_makeLiteralTemp ("previously declared");
536 return cstring_makeLiteralTemp ("specified");
540 /*@observer@*/ cstring uentry_specDeclName (uentry u)
542 if (uentry_isDeclared (u))
544 return cstring_makeLiteralTemp ("previous declaration");
548 return cstring_makeLiteralTemp ("specification");
552 static /*@observer@*/ cstring uentry_reDefDecl (uentry old, uentry unew) /*@*/
554 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
556 return cstring_makeLiteralTemp ("redefined");
558 else if (uentry_isCodeDefined (unew))
560 return cstring_makeLiteralTemp ("defined");
562 else if (uentry_isDeclared (old) && uentry_isDeclared (unew))
564 return cstring_makeLiteralTemp ("redeclared");
568 return cstring_makeLiteralTemp ("declared");
572 static constraintList uentry_getFunctionConditions (uentry ue, bool isPost)
574 if (uentry_isValid (ue))
576 functionConstraint constraint;
578 DPRINTF((message ("called uentry_getFcnPostconditions on %s",
579 uentry_unparse (ue) ) ) );
581 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
583 DPRINTF((message ("called uentry_getFunctionConditions on nonfunction %s",
584 uentry_unparse (ue) ) ) );
585 if (!uentry_isFunction (ue) )
587 DPRINTF((message ("called uentry_getFunctionConditions on nonfunction %s",
588 uentry_unparse (ue) ) ));
589 return constraintList_undefined;
593 return constraintList_undefined;
596 if (!uentry_isFunction(ue))
599 DPRINTF((message ("called uentry_getFunctionConditions on non function %s",
600 uentry_unparse (ue) ) ) );
601 return constraintList_undefined;
605 llassert (uentry_isFunction (ue));
609 constraint = ue->info->fcn->postconditions;
613 constraint = ue->info->fcn->preconditions;
616 return functionConstraint_getBufferConstraints (constraint);
619 return constraintList_undefined;
624 /*@only@*/ constraintList uentry_getFcnPreconditions (uentry ue)
626 return uentry_getFunctionConditions (ue, FALSE);
633 constraintList uentry_getFcnPostconditions (uentry ue)
635 return uentry_getFunctionConditions (ue, TRUE);
638 static /*@only@*/ fileloc setLocation (void)
640 fileloc fl = context_getSaveLocation ();
642 if (fileloc_isDefined (fl))
648 return fileloc_copy (g_currentloc);
652 static void uentry_setConstantValue (uentry ue, /*@only@*/ multiVal val)
654 llassert (uentry_isEitherConstant (ue));
655 sRef_setValue (ue->sref, val);
658 /*@notnull@*/ uentry uentry_makeEnumConstant (cstring n, ctype t)
660 fileloc loc = setLocation ();
661 uentry ue = uentry_makeConstant (n, t, loc);
663 ue->ukind = KENUMCONST;
664 uentry_setDefined (ue, loc);
668 /*@notnull@*/ uentry uentry_makeEnumInitializedConstant (cstring n, ctype t, exprNode expr)
670 fileloc loc = setLocation ();
671 uentry ue = uentry_makeConstant (n, t, loc);
672 ctype etype = exprNode_getType (expr);
674 if (!ctype_isRealInt (etype)) {
678 ("Value of enum member is not an integeral type (type %s): %s",
679 ctype_unparse (etype), exprNode_unparse (expr)),
680 exprNode_loc (expr));
683 ue->ukind = KENUMCONST;
684 uentry_setDefined (ue, loc);
688 /*@notnull@*/ uentry uentry_makeSpecEnumConstant (cstring n, ctype t, fileloc loc)
690 uentry ue = uentry_makeConstant (n, t, loc);
692 ue->ukind = KENUMCONST;
696 /*@notnull@*/ uentry uentry_makeVariableLoc (cstring n, ctype t)
698 return uentry_makeVariable (n, t, setLocation (), FALSE);
701 bool uentry_isUnnamedVariable (uentry ue)
703 return uentry_isVariable (ue) && cstring_isUndefined (ue->uname);
706 /*@notnull@*/ /*@only@*/ uentry uentry_makeUnnamedVariable (ctype t)
708 return uentry_makeVariable (cstring_undefined, t, setLocation (), FALSE);
711 /*@notnull@*/ uentry uentry_makeIdDatatype (idDecl id)
713 ctype ct = idDecl_getCtype (id);
714 uentry ue = uentry_makeDatatype (idDecl_observeId (id), ct,
715 MAYBE, MAYBE, setLocation ());
717 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
719 if (!ynm_isOn (ue->info->datatype->abs))
721 if (ctype_isUnknown (ct))
723 ue->info->datatype->mut = MAYBE;
727 ue->info->datatype->mut = ynm_fromBool (ctype_isMutable (ct));
734 void uentry_checkParams (uentry ue)
736 if (uentry_isValid (ue))
738 bool isExt = uentry_isExtern (ue);
740 if (uentry_isRealFunction (ue))
742 uentryList params = uentry_getParams (ue);
745 uentryList_elements (params, current)
749 if (uentry_isValid (current))
751 ctype ct = current->utype;
753 if (ctype_isFixedArray (ct))
755 if (ctype_isArray (ctype_baseArrayPtr (ct))
756 && !ctype_isFixedArray (ctype_baseArrayPtr (ct)))
762 if (uentry_hasName (current))
765 (FLG_FIXEDFORMALARRAY,
766 message ("Function parameter %q declared as "
767 "manifest array (size constant is meaningless)",
768 uentry_getName (current)),
769 uentry_whereDeclared (current));
774 (FLG_FIXEDFORMALARRAY,
775 message ("Unnamed function parameter %d declared as "
776 "manifest array (size constant is meaningless)",
778 uentry_whereDeclared (current));
784 if (ctype_isArray (ct))
786 if (uentry_hasName (current))
790 message ("Function parameter %q declared as "
791 "array (treated as pointer)",
792 uentry_getName (current)),
793 uentry_whereDeclared (current));
799 message ("Unnamed function parameter %d declared as "
800 "array (treated as pointer)",
802 uentry_whereDeclared (current));
807 if (sRef_getNullState (uentry_getSref (current)) == NS_MNOTNULL)
809 if (ctype_isAbstract (ct) &&
810 (isExt || (ctype_isAbstract (ctype_realType (ct))
811 && !context_hasFileAccess (ctype_typeId (ct)))))
816 ("Function %q declared with notnull parameter %q of abstract "
819 uentry_getName (current),
822 ("Since %s is an abstract type, notnull can only be "
823 "used for parameters if the function is static to a "
824 "module where %s is accessible.",
827 uentry_whereDeclared (current));
831 } end_uentryList_elements;
833 if (sRef_getNullState (uentry_getSref (ue)) == NS_MNOTNULL)
835 ctype ct = ue->utype;
837 if (ctype_isAbstract (ct)
838 && (isExt || (ctype_isAbstract (ctype_realType (ct))
839 && !context_hasFileAccess (ctype_typeId (ct)))))
844 ("%s %q declared %s notnull storage of abstract type %s",
845 ekind_capName (uentry_getKind (ue)),
850 ("Since %s is an abstract type, notnull can only be used "
851 "if it is static to a module where %s is accessible.",
854 uentry_whereDeclared (ue));
861 static void reflectImplicitFunctionQualifiers (/*@notnull@*/ uentry ue, bool spec)
863 alkind ak = sRef_getAliasKind (ue->sref);
865 if (alkind_isRefCounted (ak))
867 sRef_setAliasKind (ue->sref, AK_NEWREF, fileloc_undefined);
871 if (alkind_isUnknown (ak))
873 exkind ek = sRef_getExKind (ue->sref);
875 if (exkind_isKnown (ek))
877 DPRINTF (("Setting imp dependent: %s",
878 uentry_unparseFull (ue)));
879 sRef_setAliasKind (ue->sref, AK_IMPDEPENDENT, fileloc_undefined);
883 if (context_getFlag (spec ? FLG_SPECRETIMPONLY : FLG_RETIMPONLY))
885 /* evans 2000-12-22 removed ctype_realType so it will
886 not apply to immutable abstract types. */
888 if (ctype_isVisiblySharable
889 (ctype_realType (ctype_getReturnType (ue->utype))))
891 if (uentryList_hasReturned (uentry_getParams (ue)))
897 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
899 ; /* Immutable objects are not shared. */
903 sRef_setAliasKind (ue->sref, AK_IMPONLY,
905 DPRINTF (("Ret imp only: %s",
906 ctype_unparse (ctype_getReturnType (ue->utype))));
916 static /*@notnull@*/ uentry
917 uentry_makeFunctionAux (cstring n, ctype t,
919 /*@only@*/ globSet globs,
920 /*@only@*/ sRefSet mods,
921 /*@only@*/ warnClause warn,
922 /*@keep@*/ fileloc f, bool priv,
923 /*@unused@*/ bool isForward)
925 uentry e = uentry_alloc ();
928 llassert (warnClause_isUndefined (warn)); /*@i325 remove parameter! */
930 DPRINTF (("Make function: %s", n));
932 if (ctype_isFunction (t))
934 ret = ctype_getReturnType (t);
938 if (ctype_isKnown (t))
940 llbug (message ("not function: %s", ctype_unparse (t)));
947 if (fileloc_isSpec (f) || fileloc_isImport (f))
949 e->whereSpecified = f;
950 e->whereDeclared = fileloc_undefined;
954 e->whereSpecified = fileloc_undefined;
955 e->whereDeclared = f;
958 /* e->shallowCopy = FALSE; */
959 e->uname = cstring_copy (n);
961 e->storageclass = SCNONE;
963 e->sref = sRef_makeResult (ret); /* evans 2001-07-19 - was sRef_makeType */
965 DPRINTF (("Result: %s", sRef_unparseFull (e->sref)));
967 if (ctype_isUA (ret))
969 sRef_setStateFromType (e->sref, ret);
974 e->uses = filelocList_new ();
976 e->hasNameError = FALSE;
980 e->info = (uinfo) dmalloc (sizeof (*e->info));
981 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
983 e->info->fcn->hasMods = sRefSet_isDefined (mods);
984 e->info->fcn->hasGlobs = globSet_isDefined (globs);
986 e->info->fcn->exitCode = XK_UNKNOWN;
987 e->info->fcn->nullPred = qual_createUnknown ();
988 e->info->fcn->specialCode = SPC_NONE;
990 e->info->fcn->access = access;
991 e->info->fcn->globs = globs;
992 e->info->fcn->defparams = uentryList_undefined;
994 sRef_setDefined (e->sref, f);
995 e->whereDefined = fileloc_undefined;
997 e->info->fcn->mods = sRefSet_undefined;
998 e->info->fcn->specclauses = NULL;
1001 e->info->fcn->preconditions = NULL;
1005 e->info->fcn->postconditions = NULL;
1008 checkGlobalsModifies (e, mods);
1009 e->info->fcn->mods = mods;
1014 static void uentry_reflectClauses (uentry ue, functionClauseList clauses)
1016 functionClauseList_elements (clauses, el)
1018 DPRINTF (("Reflect clause: %s on %s",
1019 functionClause_unparse (el), uentry_getName (ue)));
1021 if (functionClause_isNoMods (el))
1023 modifiesClause mel = functionClause_getModifies (el);
1025 if (uentry_hasGlobs (ue))
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));
1037 if (uentry_hasMods (ue))
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));
1048 uentry_setGlobals (ue, globSet_undefined);
1049 uentry_setModifies (ue, sRefSet_undefined);
1051 else if (functionClause_isGlobals (el))
1053 globalsClause glc = functionClause_getGlobals (el);
1055 DPRINTF (("Globals: %s / %s", uentry_unparse (ue),
1056 globalsClause_unparse (glc)));
1058 if (uentry_hasGlobs (ue))
1063 ("Multiple globals clauses for %q: %q",
1064 uentry_getName (ue),
1065 globalsClause_unparse (glc)),
1066 globalsClause_getLoc (glc));
1067 uentry_setGlobals (ue, globalsClause_takeGlobs (glc)); /*@i32@*/
1071 DPRINTF (("Taking globs: %s", globalsClause_unparse (glc)));
1072 uentry_setGlobals (ue, globalsClause_takeGlobs (glc));
1073 DPRINTF (("Taking globs after: %s", globalsClause_unparse (glc)));
1076 else if (functionClause_isModifies (el))
1078 modifiesClause mlc = functionClause_getModifies (el);
1080 DPRINTF (("Has modifies: %s", uentry_unparseFull (ue)));
1082 if (uentry_hasMods (ue))
1090 ("Multiple modifies clauses for %s: %s",
1091 uentry_getName (ue),
1092 modifiesClause_unparse (mlc)),
1093 modifiesClause_getLoc (mlc)))
1095 llhint (message ("Previous modifies clause: ",
1096 sRefSet_unparse (uentry_getMods (ue))));
1102 uentry_combineModifies (ue, modifiesClause_takeMods (mlc)); /*@i32@*/
1106 uentry_setModifies (ue, modifiesClause_takeMods (mlc));
1109 else if (functionClause_isEnsures (el))
1111 functionConstraint cl = functionClause_takeEnsures (el);
1112 DPRINTF (("Setting post: %s / %s",
1113 uentry_unparse (ue), functionConstraint_unparse (cl)));
1114 uentry_setPostconditions (ue, cl);
1116 else if (functionClause_isRequires (el))
1118 functionConstraint cl = functionClause_takeRequires (el);
1119 uentry_setPreconditions (ue, cl);
1121 else if (functionClause_isState (el))
1123 stateClause sc = functionClause_takeState (el);
1125 if (stateClause_isBefore (sc) && stateClause_setsMetaState (sc))
1127 sRefSet rfs = stateClause_getRefs (sc);
1129 sRefSet_elements (rfs, s)
1131 if (sRef_isParam (s))
1134 ** Can't use requires on parameters
1138 (FLG_ANNOTATIONERROR,
1139 message ("Requires clauses for %q concerns parameters %q should be "
1140 "a parameter annotation instead: %q",
1141 uentry_unparse (ue),
1143 stateClause_unparse (sc)),
1144 stateClause_loc (sc));
1146 } end_sRefSet_elements ;
1149 DPRINTF (("State clause: %s", stateClause_unparse (sc)));
1150 uentry_addStateClause (ue, sc);
1152 else if (functionClause_isWarn (el))
1154 warnClause wc = functionClause_takeWarn (el);
1155 uentry_addWarning (ue, wc);
1159 DPRINTF (("Unhandled clause: %s", functionClause_unparse (el)));
1161 } end_functionClauseList_elements ;
1163 DPRINTF (("Checking all: %s", sRef_unparseFull (ue->sref)));
1164 stateClauseList_checkAll (ue);
1167 /*@notnull@*/ uentry uentry_makeIdFunction (idDecl id)
1169 bool leaveFunc = FALSE;
1171 uentry_makeFunction (idDecl_observeId (id), idDecl_getCtype (id),
1172 typeId_invalid, globSet_undefined,
1173 sRefSet_undefined, warnClause_undefined,
1176 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1179 ** This makes parameters names print out correctly.
1180 ** (But we might be a local variable declaration for a function type...)
1183 if (context_inFunctionLike ())
1185 DPRINTF (("Header: %s / %s",
1186 uentry_unparse (context_getHeader ()),
1187 idDecl_unparse (id)));
1191 context_enterFunctionDeclaration (ue);
1195 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1196 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
1197 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1198 reflectImplicitFunctionQualifiers (ue, FALSE);
1199 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1200 uentry_reflectClauses (ue, idDecl_getClauses (id));
1201 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1203 if (!uentry_isStatic (ue)
1204 && cstring_equalLit (ue->uname, "main"))
1206 ctype typ = ue->utype;
1210 llassert (ctype_isFunction (typ));
1212 retval = ctype_getReturnType (typ);
1214 if (!ctype_isInt (retval))
1218 message ("Function main declared to return %s, should return int",
1219 ctype_unparse (retval)),
1220 uentry_whereDeclared (ue));
1223 args = ctype_argsFunction (typ);
1225 if (uentryList_isMissingParams (args)
1226 || uentryList_size (args) == 0)
1232 if (uentryList_size (args) != 2)
1236 message ("Function main declared with %d arg%&, "
1237 "should have 2 (int argc, char *argv[])",
1238 uentryList_size (args)),
1239 uentry_whereLast (ue));
1243 uentry arg = uentryList_getN (args, 0);
1244 ctype ct = uentry_getType (arg);
1246 if (!ctype_isInt (ct))
1250 message ("Parameter 1, %q, of function main declared "
1251 "with type %t, should have type int",
1252 uentry_getName (arg), ct),
1253 uentry_whereDeclared (arg));
1256 arg = uentryList_getN (args, 1);
1257 ct = uentry_getType (arg);
1259 if (ctype_isArrayPtr (ct)
1260 && ctype_isArrayPtr (ctype_baseArrayPtr (ct))
1261 && ctype_isChar (ctype_baseArrayPtr (ctype_baseArrayPtr (ct))))
1269 message ("Parameter 2, %q, of function main declared "
1270 "with type %t, should have type char **",
1271 uentry_getName (arg), ct),
1272 uentry_whereDeclared (arg));
1280 context_exitFunctionDeclaration ();
1286 static void uentry_implicitParamAnnots (/*@notnull@*/ uentry e)
1288 alkind ak = sRef_getAliasKind (e->sref);
1290 if ((alkind_isUnknown (ak) || alkind_isImplicit (ak))
1291 && context_getFlag (FLG_PARAMIMPTEMP))
1293 exkind ek = sRef_getExKind (e->sref);
1295 if (exkind_isKnown (ek))
1297 DPRINTF (("imp dep: %s", uentry_unparseFull (e)));
1298 sRef_setAliasKind (e->sref, AK_IMPDEPENDENT, fileloc_undefined);
1299 sRef_setOrigAliasKind (e->sref, AK_IMPDEPENDENT);
1303 sRef_setAliasKind (e->sref, AK_IMPTEMP, fileloc_undefined);
1304 sRef_setOrigAliasKind (e->sref, AK_IMPTEMP);
1309 static /*@only@*/ /*@notnull@*/ uentry
1310 uentry_makeVariableParamAux (cstring n, ctype t, /*@dependent@*/ sRef s,
1311 /*@only@*/ fileloc loc, sstate defstate) /*@i32 exposed*/
1313 cstring pname = makeParam (n);
1316 DPRINTF (("Sref: %s", sRef_unparseFull (s)));
1317 e = uentry_makeVariableAux (pname, t, loc, s, FALSE, VKPARAM);
1319 cstring_free (pname);
1320 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1321 uentry_implicitParamAnnots (e);
1322 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1324 if (!sRef_isAllocated (e->sref) && !sRef_isPartial (e->sref))
1326 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1327 sRef_setDefState (e->sref, defstate, uentry_whereDeclared (e));
1328 e->info->var->defstate = defstate;
1331 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1336 uentry_setRefCounted (uentry e)
1338 if (uentry_isValid (e))
1340 uentry_setAliasKind (e, AK_REFCOUNTED);
1341 sRef_storeState (e->sref);
1346 uentry_setStatic (uentry c)
1348 if (uentry_isValid (c))
1350 alkind ak = sRef_getAliasKind (c->sref);
1351 c->storageclass = SCSTATIC;
1353 if (uentry_isVariable (c) && !ctype_isFunction (uentry_getType (c)))
1355 if (!alkind_isUnknown (ak)
1356 && !alkind_isStatic (ak))
1358 if (!(ctype_isRealPointer (uentry_getType (c)))
1359 && !(ctype_isAbstract (ctype_realType (uentry_getType (c))))
1360 && !alkind_isRefCounted (ak))
1362 if (alkind_isImplicit (ak)
1363 && alkind_isDependent (ak)
1364 && ctype_isArray (uentry_getType (c)))
1366 ; /* no error for observer arrays */
1372 message ("Static storage %q declared as %s",
1374 alkind_unparse (ak)),
1375 uentry_whereDeclared (c));
1381 if (alkind_isUnknown (ak)
1382 || (alkind_isImplicit (sRef_getAliasKind (c->sref))
1383 && !alkind_isDependent (sRef_getAliasKind (c->sref))))
1385 sRef_setAliasKind (c->sref, AK_STATIC, fileloc_undefined);
1386 sRef_setOrigAliasKind (c->sref, AK_STATIC);
1394 uentry_setExtern (uentry c)
1396 if (uentry_isValid (c))
1397 c->storageclass = SCEXTERN;
1401 uentry_setParamNo (uentry ue, int pno)
1403 llassert (uentry_isAnyParam (ue) && sRef_isParam (ue->sref));
1404 sRef_setParamNo (ue->sref, pno);
1408 void checkGlobalsModifies (/*@notnull@*/ uentry ue, sRefSet sr)
1410 sRefSet_allElements (sr, el)
1412 sRef base = sRef_getRootBase (el);
1414 if (sRef_isFileOrGlobalScope (base) || sRef_isInternalState (base)
1415 || (sRef_isKindSpecial (base) && !sRef_isNothing (base)))
1417 if (!globSet_member (ue->info->fcn->globs, base))
1419 if (uentry_hasGlobs (ue)
1420 || context_getFlag (FLG_WARNMISSINGGLOBALSNOGLOBS))
1423 (FLG_WARNMISSINGGLOBALS,
1425 ("Modifies list for %q uses global %q, "
1426 "not included in globals list.",
1427 uentry_getName (ue),
1428 sRef_unparse (base)),
1429 uentry_whereLast (ue)))
1431 uentry_showWhereSpecified (ue);
1435 ue->info->fcn->globs = globSet_insert (ue->info->fcn->globs,
1437 if (sRef_isFileStatic (base))
1439 context_recordFileGlobals (ue->info->fcn->globs);
1443 } end_sRefSet_allElements;
1447 uentry_makeVariableSrefParam (cstring n, ctype t, /*@only@*/ fileloc loc, /*@exposed@*/ sRef s)
1449 return (uentry_makeVariableParamAux (n, t, s, loc, SS_UNKNOWN));
1453 uentry_fixupSref (uentry ue)
1457 if (uentry_isUndefined (ue) || uentry_isElipsisMarker (ue))
1462 sr = uentry_getSref (ue);
1464 sRef_resetState (sr);
1465 sRef_clearDerived (sr);
1467 llassertprint (uentry_isVariable (ue), ("fixing: %s", uentry_unparseFull (ue)));
1468 llassert (sRef_isValid (sr));
1470 if (uentry_isVariable (ue))
1473 /*@i634 ue->sref = sRef_saveCopyShallow (ue->info->var->origsref); */
1474 sRef_setDefState (sr, ue->info->var->defstate, fileloc_undefined);
1475 sRef_setNullState (sr, ue->info->var->nullstate, fileloc_undefined);
1479 static void uentry_addStateClause (/*@notnull@*/ uentry ue, stateClause sc)
1482 ** Okay to allow multiple clauses of the same kind.
1483 */ /*@i834 is this true?@*/
1485 ue->info->fcn->specclauses =
1486 stateClauseList_add (ue->info->fcn->specclauses, sc);
1488 /* Will call checkAll to check later... */
1491 void uentry_setStateClauseList (uentry ue, stateClauseList clauses)
1493 llassert (uentry_isFunction (ue));
1494 llassert (!stateClauseList_isDefined (ue->info->fcn->specclauses));
1496 DPRINTF (("checked clauses: %s", stateClauseList_unparse (clauses)));
1497 ue->info->fcn->specclauses = clauses;
1498 stateClauseList_checkAll (ue);
1499 DPRINTF (("checked clauses: %s", uentry_unparseFull (ue)));
1503 ** Used for @modifies@ @endmodifies@ syntax.
1505 ** If ue is specified, sr must contain *only*:
1507 ** o file static globals
1508 ** o sRef's derived from modifies spec (i.e., more specific than
1509 ** what was specified)
1511 ** Otherwise, if sr has modifies it must match sr.
1513 ** If it doesn't have modifies, set them to sr.
1517 uentry_checkModifiesContext (void)
1519 if (sRef_modInFunction ())
1523 ("Modifies list not in function context. "
1524 "A modifies list can only appear following the parameter list "
1525 "in a function declaration or header."));
1534 uentry_setModifies (uentry ue, /*@owned@*/ sRefSet sr)
1536 if (!uentry_checkModifiesContext ())
1542 if (uentry_isValid (ue))
1544 if (uentry_isIter (ue))
1546 llassert (sRefSet_isUndefined (ue->info->iter->mods));
1547 ue->info->iter->mods = sr;
1551 uentry_convertVarFunction (ue);
1552 llassertfatal (uentry_isFunction (ue));
1553 llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1555 ue->info->fcn->mods = sr;
1556 ue->info->fcn->hasMods = TRUE;
1558 checkGlobalsModifies (ue, sr);
1561 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1563 ue->info->fcn->hasGlobs = TRUE;
1566 if (sRefSet_hasStatic (ue->info->fcn->mods))
1568 context_recordFileModifies (ue->info->fcn->mods);
1578 uentry_combineModifies (uentry ue, /*@owned@*/ sRefSet sr)
1581 ** Function already has one modifies clause (possibly from
1582 ** a specification).
1585 if (!uentry_checkModifiesContext ())
1590 llassert (uentry_isValid (ue));
1592 if (uentry_isIter (ue))
1594 ue->info->iter->mods = sRefSet_unionFree (ue->info->iter->mods, sr);
1598 llassertfatal (uentry_isFunction (ue));
1599 llassert (ue->info->fcn->hasMods);
1601 checkGlobalsModifies (ue, sr);
1602 ue->info->fcn->mods = sRefSet_unionFree (ue->info->fcn->mods, sr);
1604 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1606 ue->info->fcn->hasGlobs = TRUE;
1610 if (sRefSet_hasStatic (ue->info->fcn->mods))
1612 context_recordFileModifies (ue->info->fcn->mods);
1616 bool uentry_hasWarning (uentry ue)
1618 return (uentry_isValid (ue)
1619 && warnClause_isDefined (ue->warn));
1622 void uentry_addWarning (uentry ue, /*@only@*/ warnClause warn)
1624 llassert (uentry_isValid (ue));
1625 llassert (warnClause_isUndefined (ue->warn));
1630 uentry_setPreconditions (uentry ue, /*@only@*/ functionConstraint preconditions)
1632 if (sRef_modInFunction ())
1635 (message ("Precondition list not in function context. "
1636 "A precondition list can only appear following the parameter list "
1637 "in a function declaration or header."));
1639 /*@-mustfree@*/ return; /*@=mustfree@*/
1642 if (uentry_isValid (ue))
1644 uentry_convertVarFunction (ue);
1645 llassertfatal (uentry_isFunction (ue));
1647 if (functionConstraint_isDefined (ue->info->fcn->preconditions))
1650 I changed this so it didn't appear as a Splint bug
1651 among other things this gets triggered when there is
1652 a function with two requires clauses. Now Splint
1653 prints an error and tries to conjoin the lists.
1656 (message ("Duplicate precondition list"
1657 "Attemping the conjoin the requires clauses"
1661 /* should conjoin constraints? */
1663 ue->info->fcn->preconditions = functionConstraint_conjoin (ue->info->fcn->preconditions, preconditions);
1667 ue->info->fcn->preconditions = preconditions;
1672 llfatalbug ((message("uentry_setPreconditions called with invalid uentry") ));
1681 uentry_setPostconditions (uentry ue, /*@only@*/ functionConstraint postconditions)
1683 if (sRef_modInFunction ())
1686 (message ("Postcondition list not in function context. "
1687 "A postcondition list can only appear following the parameter list "
1688 "in a function declaration or header."));
1690 /*@-mustfree@*/ return; /*@=mustfree@*/
1693 if (uentry_isValid (ue))
1695 uentry_convertVarFunction (ue);
1696 llassertfatal (uentry_isFunction (ue));
1698 if (functionConstraint_isUndefined (ue->info->fcn->postconditions))
1700 ue->info->fcn->postconditions = postconditions;
1704 ue->info->fcn->postconditions = functionConstraint_conjoin (ue->info->fcn->postconditions, postconditions);
1709 llfatalbug ((message("uentry_setPostconditions called with invalid uentry") ));
1714 ** requires: new and old are functions
1718 checkGlobalsConformance (/*@notnull@*/ uentry old,
1719 /*@notnull@*/ uentry unew,
1720 bool mustConform, bool completeConform)
1722 bool hasInternalState = FALSE;
1724 old->info->fcn->hasGlobs |= unew->info->fcn->hasGlobs;
1726 if (globSet_isDefined (unew->info->fcn->globs))
1728 globSet_allElements (unew->info->fcn->globs, el)
1730 if (sRef_isFileStatic (el))
1732 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1734 if (sRef_isInvalid (sr))
1736 bool hasError = FALSE;
1738 if (!hasInternalState
1739 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1740 sRef_makeInternalState ()))
1741 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1742 sRef_makeSpecState ())))
1745 && !uentry_isStatic (old)
1748 message ("Globals list for %q includes internal state, %q, "
1749 "but %s without globals internalState.",
1750 uentry_getName (old),
1752 uentry_specOrDefName (old)),
1753 uentry_whereLast (unew)))
1755 uentry_showWhereSpecified (old);
1759 old->info->fcn->globs = globSet_insert (old->info->fcn->globs,
1760 sRef_makeInternalState ());
1761 hasInternalState = TRUE;
1765 && fileloc_sameFile (uentry_whereDeclared (unew),
1766 uentry_whereDeclared (old)))
1771 message ("Function %q inconsistently %rdeclared (in "
1772 "same file) with file static global %q in "
1774 uentry_getName (unew),
1775 uentry_isDeclared (old),
1777 uentry_whereDeclared (unew)))
1779 uentry_showWhereSpecified (old);
1784 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1785 context_recordFileGlobals (old->info->fcn->globs);
1789 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1791 if (sRef_isInvalid (sr))
1796 message ("Function %q inconsistently %rdeclared with "
1797 "%q in globals list",
1798 uentry_getName (unew),
1799 uentry_isDeclared (old),
1801 uentry_whereDeclared (unew)))
1803 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1804 uentry_showWhereSpecified (old);
1809 if (!bool_equal (sRef_isAllocated (el), sRef_isAllocated (sr)))
1815 ("Function %q global %q inconsistently "
1816 "%rdeclared as %qout global",
1817 uentry_getName (unew),
1819 uentry_isDeclared (old),
1820 cstring_makeLiteral (sRef_isAllocated (el) ? "" : "non-")),
1821 uentry_whereDeclared (unew)))
1823 uentry_showWhereSpecified (old);
1828 } end_globSet_allElements ;
1830 if (completeConform)
1832 globSet_allElements (old->info->fcn->globs, el)
1834 sRef sr = globSet_lookup (unew->info->fcn->globs, el);
1836 if (sRef_isInvalid (sr))
1839 && uentry_isReallySpecified (old)
1842 message ("Function %q specified with %q in globals list, "
1843 "but declared without %q",
1844 uentry_getName (unew),
1847 uentry_whereDeclared (unew)))
1849 uentry_showWhereSpecified (old);
1852 } end_globSet_allElements;
1857 if (completeConform && !globSet_isEmpty (old->info->fcn->globs))
1859 if (uentry_isReallySpecified (old)
1862 message ("%s %q specified with globals list, but "
1863 "declared with no globals",
1864 ekind_capName (unew->ukind),
1865 uentry_getName (unew)),
1866 uentry_whereDeclared (unew)))
1869 (message ("Specification globals: %q",
1870 globSet_unparse (old->info->fcn->globs)),
1871 uentry_whereSpecified (old));
1875 unew->info->fcn->globs = globSet_copyInto (unew->info->fcn->globs,
1876 old->info->fcn->globs);
1881 ** new modifies list must be included by old modifies list.
1883 ** file static state may be added to new, if old has internal.
1887 checkModifiesConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
1888 bool mustConform, bool completeConform)
1891 bool changedMods = FALSE;
1892 bool modInternal = FALSE;
1894 llassert (uentry_isFunction (old) && uentry_isFunction (unew));
1896 old->info->fcn->hasMods |= unew->info->fcn->hasMods;
1897 newMods = unew->info->fcn->mods;
1899 if (sRefSet_isEmpty (newMods))
1901 if (completeConform && !sRefSet_isEmpty (old->info->fcn->mods)
1902 && uentry_isReallySpecified (old))
1906 message ("%s %q specified with modifies clause, "
1907 "but declared with no modifies clause",
1908 ekind_capName (unew->ukind),
1909 uentry_getName (unew)),
1910 uentry_whereDeclared (unew)))
1912 llgenindentmsg (message ("Specification has modifies %q",
1913 sRefSet_unparse (old->info->fcn->mods)),
1914 uentry_whereSpecified (old));
1921 sRefSet_allElements (newMods, current)
1923 if (sRef_isValid (current))
1925 sRef rb = sRef_getRootBase (current);
1927 if (sRef_isFileStatic (rb))
1931 if (!sRefSet_isSameMember (old->info->fcn->mods,
1932 sRef_makeInternalState ())
1933 && !sRefSet_isSameMember (old->info->fcn->mods,
1934 sRef_makeSpecState ()))
1937 && !uentry_isStatic (old)
1941 ("Modifies list for %q includes internal state, "
1942 "but %s without modifies internal.",
1943 uentry_getName (old),
1944 uentry_specOrDefName (old)),
1945 uentry_whereLast (unew)))
1947 uentry_showWhereSpecified (old);
1950 old->info->fcn->mods =
1951 sRefSet_insert (old->info->fcn->mods,
1952 sRef_makeInternalState ());
1957 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1963 if (sRef_canModifyVal (current, old->info->fcn->mods))
1965 int size = sRefSet_size (old->info->fcn->mods);
1967 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1970 if (sRefSet_size (old->info->fcn->mods) != size)
1981 ("Modifies list for %q contains %q, not modifiable "
1983 uentry_getName (old),
1984 sRef_unparse (current),
1985 uentry_specDeclName (old)),
1986 uentry_whereLast (unew)))
1988 uentry_showWhereSpecified (old);
1993 } end_sRefSet_allElements;
1995 if (completeConform && uentry_isReallySpecified (old))
1997 sRefSet_allElements (old->info->fcn->mods, el)
1999 if (sRef_canModify (el, newMods))
2008 ("Specification modifies clause for %q contains %q, "
2009 "not included in declaration modifies clause",
2010 uentry_getName (old),
2012 uentry_whereLast (unew)))
2014 uentry_showWhereSpecified (old);
2017 } end_sRefSet_allElements ;
2021 ** Make sure file static elements will be removed.
2026 context_recordFileModifies (old->info->fcn->mods);
2031 uentry_checkMutableType (uentry ue)
2033 ctype ct = uentry_getType (ue);
2035 if (!ctype_isRealPointer (ct) && !ctype_isRealAbstract (ct))
2037 DPRINTF (("Check mutable: %s", uentry_unparseFull (ue)));
2039 voptgenerror (FLG_MUTREP,
2040 message ("Mutable abstract type %q declared without pointer "
2041 "indirection: %t (violates assignment semantics)",
2042 uentry_getName (ue), ct),
2043 uentry_whereDeclared (ue));
2048 uentry_setMutable (uentry e)
2050 llassert (uentry_isDatatype (e));
2051 e->info->datatype->mut = YES;
2055 uentry_checkIterArgs (uentry ue)
2057 bool hasYield = FALSE;
2060 llassert (uentry_isIter (ue));
2062 args = uentry_getParams (ue);
2064 uentryList_elements (args, el)
2066 sstate ds = uentry_getDefState (el);
2068 if (uentry_isYield (el))
2073 if (sstate_isUnknown (ds))
2075 uentry_setDefState (el, SS_DEFINED);
2081 } end_uentryList_elements;
2085 voptgenerror (FLG_HASYIELD,
2086 message ("Iterator %q declared with no yield parameters",
2087 uentry_getName (ue)),
2088 uentry_whereDeclared (ue));
2093 chkind_fromQual (qual qel)
2095 if (qual_isChecked (qel))
2099 else if (qual_isCheckMod (qel))
2103 else if (qual_isCheckedStrict (qel))
2105 return CH_CHECKEDSTRICT;
2107 else if (qual_isUnchecked (qel))
2109 return CH_UNCHECKED;
2114 /*@notreached@*/ return CH_UNKNOWN;
2119 uentry_reflectOtherQualifier (/*@notnull@*/ uentry ue, qual qel)
2121 if (qual_isKillRef (qel) || qual_isNewRef (qel) || qual_isTempRef (qel))
2123 if (!uentry_isRefCounted (ue))
2126 (FLG_ANNOTATIONERROR,
2127 message ("Reference counting qualifier %s used on non-reference "
2128 "counted storage: %q",
2130 uentry_unparse (ue)),
2131 uentry_whereLast (ue));
2135 alkind ak = alkind_fromQual (qel);
2137 uentry_setAliasKind (ue, ak);
2140 else if (qual_isRefCounted (qel))
2142 ctype ct = ctype_realType (uentry_getType (ue));
2145 if (ctype_isPointer (ct)
2146 && (ctype_isStruct (rt = ctype_realType (ctype_baseArrayPtr (ct)))))
2148 /* check there is a refs field */
2149 uentryList fields = ctype_getFields (rt);
2150 uentry refs = uentry_undefined;
2152 uentryList_elements (fields, field)
2154 if (uentry_isRefsField (field))
2156 if (uentry_isValid (refs))
2159 (FLG_ANNOTATIONERROR,
2160 message ("Reference counted structure type %s has "
2161 "multiple refs fields: %q and %q",
2163 uentry_getName (refs),
2164 uentry_getName (field)),
2165 uentry_whereLast (field));
2170 } end_uentryList_elements;
2172 if (uentry_isInvalid (refs))
2176 message ("Reference counted structure type %s has "
2178 ctype_unparse (ct)),
2180 ("To count reference, the structure must have a field named "
2181 "refs of type int."),
2184 else if (!ctype_isInt (uentry_getType (refs)))
2187 (FLG_ANNOTATIONERROR,
2188 message ("Reference counted structure type %s refs field has "
2189 "type %s (should be int)", ctype_unparse (ct),
2190 ctype_unparse (uentry_getType (refs))),
2191 uentry_whereLast (refs));
2195 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2196 uentry_whereDeclared (ue));
2201 if ((ctype_isPointer (ct)
2202 && ctype_isUnknown (ctype_realType (ctype_baseArrayPtr (ct))))
2203 ||ctype_isAbstract (ct) || ctype_isUnknown (ct))
2205 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2206 uentry_whereDeclared (ue));
2211 (FLG_ANNOTATIONERROR,
2212 message ("Non-pointer to structure type %s declared with "
2213 "refcounted qualifier",
2214 ctype_unparse (ct)),
2215 uentry_whereLast (ue));
2219 else if (qual_isRefs (qel))
2221 if (uentry_isVariable (ue) && !uentry_isParam (ue))
2223 uentry_setAliasKind (ue, AK_REFS);
2228 (FLG_ANNOTATIONERROR,
2229 message ("Refs qualifier used on non-structure field: %q",
2230 uentry_unparse (ue)),
2231 uentry_whereLast (ue));
2234 else if (qual_isAliasQual (qel))
2236 alkind ak = alkind_fromQual (qel);
2238 alkind oldak = uentry_getAliasKind (ue);
2239 ctype ut = uentry_getType (ue);
2241 if (alkind_isImplicit (ak)
2242 && (alkind_isKnown (oldak) && !alkind_isImplicit (oldak)))
2244 /* ignore the implied qualifier */
2248 if (uentry_isEitherConstant (ue))
2251 (FLG_ANNOTATIONERROR,
2252 message ("Alias qualifier %s used on constant: %q",
2253 alkind_unparse (ak), uentry_unparse (ue)),
2254 uentry_whereLast (ue));
2259 if (ctype_isFunction (ut))
2261 ut = ctype_getReturnType (ut);
2264 if (!(ctype_isVisiblySharable (ut)
2265 || ctype_isRealArray (ut)
2266 || ctype_isRealSU (ut)))
2268 if (!qual_isImplied (qel))
2271 (FLG_ANNOTATIONERROR,
2272 message ("Alias qualifier %s used on unsharable storage type %t: %q",
2273 alkind_unparse (ak), ut, uentry_getName (ue)),
2274 uentry_whereLast (ue));
2281 if (uentry_isRefCounted (ue))
2283 if (!(qual_isRefQual (qel) || qual_isOnly (qel)
2284 || qual_isExposed (qel)
2285 || qual_isObserver (qel)))
2287 if (!qual_isImplied (qel))
2290 (FLG_ANNOTATIONERROR,
2292 ("Alias qualifier %s used on reference counted storage: %q",
2293 alkind_unparse (ak),
2294 uentry_unparse (ue)),
2295 uentry_whereLast (ue));
2303 if (qual_isRefQual (qel))
2306 (FLG_ANNOTATIONERROR,
2307 message ("Qualifier %s used on non-reference counted storage: %q",
2308 alkind_unparse (ak), uentry_unparse (ue)),
2309 uentry_whereLast (ue));
2318 uentry_setAliasKind (ue, ak);
2321 else if (qual_isNull (qel))
2323 if (uentry_isConstant (ue))
2327 ctype_isAbstract (ue->utype) ? NS_CONSTNULL : NS_DEFNULL,
2328 uentry_whereDeclared (ue));
2332 uentry_setNullState (ue, NS_POSNULL);
2335 else if (qual_isRelNull (qel))
2337 uentry_setNullState (ue, NS_RELNULL);
2339 else if (qual_isNotNull (qel))
2341 uentry_setNullState (ue, NS_MNOTNULL);
2343 else if (qual_isAbstract (qel)
2344 || qual_isConcrete (qel))
2346 if (!uentry_isDatatype (ue))
2349 (FLG_ANNOTATIONERROR,
2350 message ("Qualifier %s used with non-datatype",
2351 qual_unparse (qel)),
2352 uentry_whereLast (ue));
2356 ue->info->datatype->abs = ynm_fromBool (qual_isAbstract (qel));
2359 else if (qual_isMutable (qel))
2361 if (!uentry_isDatatype (ue))
2364 (FLG_ANNOTATIONERROR,
2365 message ("Qualifier %s used with non-datatype", qual_unparse (qel)),
2366 uentry_whereLast (ue));
2370 if (!ynm_isOn (ue->info->datatype->mut))
2372 uentry_checkMutableType (ue);
2375 ue->info->datatype->mut = YES;
2378 else if (qual_isImmutable (qel))
2380 if (!uentry_isDatatype (ue))
2382 voptgenerror (FLG_ANNOTATIONERROR,
2383 message ("Qualifier %s used with non-datatype",
2384 qual_unparse (qel)),
2385 uentry_whereLast (ue));
2389 ue->info->datatype->mut = NO;
2392 else if (qual_isNullPred (qel))
2394 uentry_convertVarFunction (ue);
2396 if (uentry_isFunction (ue))
2398 ctype typ = uentry_getType (ue);
2399 ctype rtype = ctype_getReturnType (uentry_getType (ue));
2401 if (ctype_isRealBool (rtype))
2403 uentryList pl = ctype_argsFunction (typ);
2405 if (uentryList_size (pl) == 1)
2407 ue->info->fcn->nullPred = qel;
2411 voptgenerror (FLG_ANNOTATIONERROR,
2412 message ("Qualifier %s used with function having %d "
2413 "arguments (should have 1)",
2415 uentryList_size (pl)),
2416 uentry_whereLast (ue));
2421 voptgenerror (FLG_ANNOTATIONERROR,
2422 message ("Qualifier %s used with function returning %s "
2423 "(should return bool)",
2425 ctype_unparse (rtype)),
2426 uentry_whereLast (ue));
2431 voptgenerror (FLG_ANNOTATIONERROR,
2432 message ("Qualifier %s used with non-function",
2433 qual_unparse (qel)),
2434 uentry_whereLast (ue));
2437 else if (qual_isExitQual (qel))
2439 exitkind exk = exitkind_fromQual (qel);
2441 if (uentry_isFunction (ue))
2443 if (exitkind_isKnown (ue->info->fcn->exitCode))
2445 voptgenerror (FLG_ANNOTATIONERROR,
2446 message ("Multiple exit qualifiers used on function %q: %s, %s",
2447 uentry_getName (ue),
2448 exitkind_unparse (ue->info->fcn->exitCode),
2449 exitkind_unparse (exk)),
2450 uentry_whereLast (ue));
2453 ue->info->fcn->exitCode = exk;
2457 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2459 uentry_makeVarFunction (ue);
2460 ue->info->fcn->exitCode = exk;
2464 voptgenerror (FLG_ANNOTATIONERROR,
2465 message ("Exit qualifier %s used with non-function (type %s)",
2467 ctype_unparse (uentry_getType (ue))),
2468 uentry_whereLast (ue));
2472 else if (qual_isMetaState (qel))
2474 annotationInfo ainfo = qual_getAnnotationInfo (qel);
2476 if (annotationInfo_matchesContext (ainfo, ue))
2478 DPRINTF (("Reflecting %s on %s",
2479 annotationInfo_unparse (ainfo),
2480 uentry_unparseFull (ue)));
2482 sRef_reflectAnnotation (ue->sref, ainfo, g_currentloc);
2483 DPRINTF (("==> %s", sRef_unparseFull (ue->sref)));
2484 DPRINTF (("==> %s", uentry_unparseFull (ue)));
2489 (FLG_ANNOTATIONERROR,
2490 message ("Attribute annotation %s used in inconsistent context: %q",
2492 uentry_unparse (ue)),
2493 uentry_whereLast (ue)))
2495 /*@i! annotationInfo_showContextError (ainfo, ue); */
2501 if (qual_isCQual (qel))
2507 llbug (message ("Unhandled qualifier: %s", qual_unparse (qel)));
2513 uentry_reflectQualifiers (uentry ue, qualList q)
2515 llassert (uentry_isValid (ue));
2517 DPRINTF (("Reflect qualifiers: %s / %s",
2518 uentry_unparseFull (ue), qualList_unparse (q)));
2520 qualList_elements (q, qel)
2522 if (qual_isStatic (qel))
2524 uentry_setStatic (ue);
2526 else if (qual_isUnused (qel))
2528 uentry_setUsed (ue, fileloc_undefined);
2529 DPRINTF (("Used: %s", uentry_unparseFull (ue)));
2531 else if (qual_isExternal (qel))
2533 fileloc_free (ue->whereDefined);
2534 ue->whereDefined = fileloc_createExternal ();
2536 else if (qual_isSef (qel))
2538 if (uentry_isVariable (ue))
2540 vkind vk = ue->info->var->kind;
2542 llassert (vk != VKREFPARAM);
2544 if (vk == VKYIELDPARAM)
2547 (FLG_ANNOTATIONERROR,
2548 message ("Qualifier sef cannot be used with %s: %q",
2549 cstring_makeLiteralTemp (vk == VKYIELDPARAM ? "yield" : "returned"),
2550 uentry_unparse (ue)),
2551 uentry_whereLast (ue));
2553 else if (vk == VKRETPARAM)
2555 ue->info->var->kind = VKSEFRETPARAM;
2559 ue->info->var->kind = VKSEFPARAM;
2565 (FLG_ANNOTATIONERROR,
2566 message ("Qualifier sef is meaningful only on parameters: %q",
2567 uentry_unparse (ue)),
2568 uentry_whereLast (ue));
2571 else if (qual_isExtern (qel))
2573 ue->storageclass = SCEXTERN;
2575 else if (qual_isGlobalQual (qel)) /* undef, killed */
2577 DPRINTF (("Reflecting qual: %s / %s",
2578 qual_unparse (qel), uentry_unparse (ue)));
2580 if (uentry_isVariable (ue))
2582 sstate oldstate = ue->info->var->defstate;
2583 sstate defstate = sstate_fromQual (qel);
2586 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
2587 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
2589 defstate = SS_UNDEFKILLED;
2596 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2597 ue->info->var->defstate = defstate;
2602 (FLG_ANNOTATIONERROR,
2603 message ("Qualifier %s used on non-variable: %q",
2604 qual_unparse (qel), uentry_unparse (ue)),
2605 uentry_whereLast (ue));
2608 DPRINTF (("After: %s", uentry_unparseFull (ue)));
2610 /* start modifications */
2611 else if( qual_isBufQualifier(qel) ) {
2612 ctype ct = ctype_realType(uentry_getType(ue));
2613 if( ctype_isArray(ct) || ctype_isPointer(ct) ) {
2615 if( uentry_hasBufStateInfo(ue) ) {
2616 if( qual_isNullTerminated(qel) ) { /* handle Nullterm */
2618 if (uentry_isAnyParam(ue) || uentry_isReturned (ue)) {
2619 /* If formal func param */
2620 uentry_setNullTerminatedState(ue);
2621 uentry_setLen (ue, 1);
2622 uentry_setSize (ue, 1);
2624 sRef_setNullTerminatedState(uentry_getSref(ue));
2625 sRef_setLen (uentry_getSref(ue), 1);
2626 sRef_setSize (uentry_getSref(ue), 1);
2628 uentry_setPossiblyNullTerminatedState(ue);
2630 sRef_setPossiblyNullTerminatedState(uentry_getSref(ue));
2634 /* put other BufState Qualifiers here */
2636 cstring s = uentry_getName(ue);
2637 llfatalbug(message("INTERNAL Error: we have a NULL BufState \
2638 struct for identifier %s\n", s) );
2640 } else if (ctype_isFunction (ct)) { /* We have to handle function */
2642 sRef retSref = uentry_getSref (ue);
2643 ctype retType = sRef_getType (retSref);
2645 if (ctype_isPointer (retType) || ctype_isArray (retType)) {
2646 sRef_setNullTerminatedState (retSref);
2652 message ("Qualifier %s used on non-pointer on \
2653 function return: %q", qual_unparse (qel),
2654 uentry_unparse (ue)));
2661 message ("Qualifier %s used on non-pointer: %q",
2662 qual_unparse (qel), uentry_unparse (ue)));
2664 DPRINTF (("After: %s", uentry_unparseFull (ue)));
2666 else if (qual_isAllocQual (qel)) /* out, partial, reldef, special, etc. */
2668 ctype realType = ctype_realType (ue->utype);
2669 sstate defstate = sstate_fromQual (qel);
2671 if (ctype_isFunction (realType))
2673 realType = ctype_realType (ctype_getReturnType (realType));
2676 if (qual_isRelDef (qel))
2678 ; /* okay anywhere */
2682 if (!ctype_isAP (realType)
2683 && !ctype_isSU (realType)
2684 && !ctype_isUnknown (realType)
2685 && !ctype_isAbstract (ue->utype))
2688 (FLG_ANNOTATIONERROR,
2689 message ("Qualifier %s used on non-pointer or struct: %q",
2690 qual_unparse (qel), uentry_unparse (ue)),
2691 uentry_whereLast (ue));
2695 uentry_setDefState (ue, defstate);
2697 if (sRef_isStateSpecial (ue->sref)
2698 && alkind_isImplicit (sRef_getAliasKind (ue->sref)))
2700 sRef_setAliasKind (ue->sref, AK_ERROR, fileloc_undefined);
2703 else if (qual_isYield (qel))
2705 if (uentry_isVariable (ue))
2707 ue->info->var->kind = VKYIELDPARAM;
2712 (FLG_ANNOTATIONERROR,
2713 message ("Qualifier %s used on non-iterator parameter: %q",
2714 qual_unparse (qel), uentry_unparse (ue)),
2715 uentry_whereLast (ue));
2718 else if (qual_isExQual (qel))
2720 exkind ek = exkind_fromQual (qel);
2721 ctype ut = uentry_getType (ue);
2723 DPRINTF (("Reflect ex qual: %s / %s",
2724 uentry_unparse (ue), exkind_unparse (ek)));
2726 if (ctype_isFunction (ut))
2728 ut = ctype_getReturnType (ut);
2731 if (!(ctype_isVisiblySharable (ut))
2732 && !(ctype_isArray (ut)) /* can apply to arrays also! */
2733 && !(ctype_isStruct (ctype_realType (ut)))) /* applies to structure fields! */
2735 if (!qual_isImplied (qel))
2737 if (ctype_isImmutableAbstract (ut)) {
2739 (FLG_REDUNDANTSHAREQUAL,
2740 message ("Qualifier %s used on unsharable storage type %t: %q",
2741 exkind_unparse (ek), ut, uentry_getName (ue)),
2742 uentry_whereLast (ue));
2745 (FLG_MISPLACEDSHAREQUAL,
2746 message ("Qualifier %s used on unsharable storage type %t: %q",
2747 exkind_unparse (ek), ut, uentry_getName (ue)),
2748 uentry_whereLast (ue));
2754 alkind ak = sRef_getAliasKind (ue->sref);
2756 sRef_setExKind (ue->sref, ek, uentry_whereDeclared (ue));
2757 DPRINTF (("Set exkind: %s", sRef_unparseFull (ue->sref)));
2759 if (alkind_isUnknown (ak) || alkind_isImplicit (ak) || alkind_isStatic (ak))
2761 if (!alkind_isTemp (ak))
2763 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
2764 uentry_setAliasKind (ue, AK_IMPDEPENDENT);
2767 else if (alkind_isDependent (ak) || alkind_isTemp (ak)
2768 || alkind_isOwned (ak))
2776 message ("Exposure qualifier %s used on %s storage (should "
2777 "be dependent): %q",
2779 alkind_unparse (ak),
2780 uentry_unparse (ue)));
2784 else if (qual_isGlobCheck (qel))
2786 if (uentry_isVariable (ue))
2788 chkind ch = chkind_fromQual (qel);
2790 if (ue->info->var->checked != CH_UNKNOWN)
2792 if (ch == ue->info->var->checked)
2794 llerror (FLG_SYNTAX,
2795 message ("Redundant %s qualifier on %q",
2797 uentry_getName (ue)));
2801 llerror (FLG_SYNTAX,
2803 ("Contradictory %s and %s qualifiers on %q",
2805 checkedName (ue->info->var->checked),
2806 uentry_getName (ue)));
2810 ue->info->var->checked = ch;
2816 message ("Qualifier %s used with non-variable",
2817 qual_unparse (qel)));
2820 else if (qual_isReturned (qel))
2822 if (uentry_isVariable (ue))
2824 ue->info->var->kind = VKRETPARAM;
2828 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-variable",
2829 qual_unparse (qel)));
2834 uentry_reflectOtherQualifier (ue, qel);
2837 sRef_storeState (ue->sref);
2838 } end_qualList_elements;
2842 DPRINTF (("Done: %s", sRef_unparseFull (ue->sref)));
2846 uentry_isOnly (uentry ue)
2848 return (!uentry_isUndefined (ue)
2849 && uentry_isVariable (ue)
2850 && alkind_isOnly (sRef_getOrigAliasKind (ue->sref)));
2854 uentry_setAliasKind (/*@notnull@*/ uentry ue, alkind ak)
2856 sRef_setAliasKind (ue->sref, ak, uentry_whereDeclared (ue));
2857 sRef_setOrigAliasKind (ue->sref, ak);
2861 uentry_setNullState (/*@notnull@*/ uentry ue, nstate ns)
2863 if (uentry_isVariable (ue))
2865 ue->info->var->nullstate = ns;
2868 sRef_setNullState (ue->sref, ns, uentry_whereDeclared (ue));
2872 uentry_isUnique (uentry ue)
2874 return (!uentry_isUndefined (ue)
2875 && uentry_isVariable (ue)
2876 && alkind_isUnique (sRef_getOrigAliasKind (ue->sref)));
2880 uentry_isFileStatic (uentry ue)
2882 return (uentry_isStatic (ue)
2883 && (!uentry_isVariable (ue)
2884 || sRef_isFileStatic (uentry_getSref (ue))));
2888 uentry_isExported (uentry ue)
2890 if (uentry_isValid (ue))
2892 if (uentry_isVariable (ue))
2894 return (sRef_isRealGlobal (uentry_getSref (ue)));
2898 return !uentry_isStatic (ue);
2906 uentry_isNonLocal (uentry ue)
2908 return (uentry_isValid (ue) && uentry_isVariable (ue)
2909 && (sRef_isFileOrGlobalScope (ue->sref) || uentry_isStatic (ue)));
2913 uentry_isGlobalVariable (uentry ue)
2915 return (uentry_isValid (ue) && uentry_isVariable (ue)
2916 && sRef_isFileOrGlobalScope (ue->sref));
2920 uentry_isVisibleExternally (uentry ue)
2922 return (uentry_isValid (ue)
2923 && ((uentry_isVariable (ue) && sRef_isRealGlobal (ue->sref))
2924 || (!uentry_isStatic (ue)
2925 && (uentry_isFunction (ue)
2926 || uentry_isIter (ue)
2927 || uentry_isEndIter (ue)
2928 || uentry_isConstant (ue)
2929 || uentry_isDatatype (ue)
2930 || uentry_isAnyTag (ue)))));
2934 uentry_isPrintfLike (uentry ue)
2936 return (uentry_isFunction (ue)
2937 && (ue->info->fcn->specialCode == SPC_PRINTFLIKE));
2941 uentry_isScanfLike (uentry ue)
2943 return (uentry_isFunction (ue)
2944 && (ue->info->fcn->specialCode == SPC_SCANFLIKE));
2948 uentry_isMessageLike (uentry ue)
2950 return (uentry_isFunction (ue)
2951 && (ue->info->fcn->specialCode == SPC_MESSAGELIKE));
2954 static void checkSpecialFunction (/*@notnull@*/ uentry ue)
2956 uentryList args = uentry_getParams (ue);
2958 if (!uentryList_isMissingParams (args))
2960 uentry last = uentry_undefined;
2962 uentryList_elements (args, current)
2964 if (uentry_isElipsisMarker (current))
2966 if (uentry_isUndefined (last))
2970 message ("Function %q is marked %s, but has no format "
2971 "string argument before elipsis",
2972 uentry_getName (ue),
2973 specCode_unparse (ue->info->fcn->specialCode)),
2974 uentry_whereLast (ue));
2975 ue->info->fcn->specialCode = SPC_NONE;
2979 ctype rt = ctype_realType (uentry_getType (last));
2981 if (!ctype_match (rt, ctype_string))
2985 /* wchar_t * is okay too */
2986 if (ctype_isAP (rt))
2988 ctype base = ctype_baseArrayPtr (rt);
2990 if (ctype_isArbitraryIntegral (base))
3000 message ("Function %q is marked %s, but the argument "
3001 "before the elipsis has type %s (should be char *)",
3002 uentry_getName (ue),
3003 specCode_unparse (ue->info->fcn->specialCode),
3004 ctype_unparse (uentry_getType (last))),
3005 uentry_whereLast (ue));
3007 ue->info->fcn->specialCode = SPC_NONE;
3014 } end_uentryList_elements ;
3018 message ("Function %q is marked %s, but has no elipsis parameter",
3019 uentry_getName (ue),
3020 specCode_unparse (ue->info->fcn->specialCode)),
3021 uentry_whereLast (ue));
3023 ue->info->fcn->specialCode = SPC_NONE;
3028 uentry_setPrintfLike (uentry ue)
3030 uentry_convertVarFunction (ue);
3031 llassertfatal (uentry_isFunction (ue));
3032 ue->info->fcn->specialCode = SPC_PRINTFLIKE;
3033 checkSpecialFunction (ue);
3037 uentry_setScanfLike (uentry ue)
3039 uentry_convertVarFunction (ue);
3040 llassertfatal (uentry_isFunction (ue));
3041 ue->info->fcn->specialCode = SPC_SCANFLIKE;
3042 checkSpecialFunction (ue);
3046 uentry_setMessageLike (uentry ue)
3048 uentry_convertVarFunction (ue);
3049 llassertfatal (uentry_isFunction (ue));
3050 ue->info->fcn->specialCode = SPC_MESSAGELIKE;
3051 checkSpecialFunction (ue);
3055 uentry_isSpecialFunction (uentry ue)
3057 return (uentry_isFunction (ue)
3058 && (ue->info->fcn->specialCode != SPC_NONE));
3061 /*@notnull@*/ uentry uentry_makeParam (idDecl t, int i)
3063 ctype ct = idDecl_getCtype (t);
3065 fileloc loc = setLocation ();
3066 sRef pref = sRef_makeParam (i, ct, stateInfo_makeLoc (loc));
3067 uentry ue = uentry_makeVariableSrefParam (idDecl_observeId (t), ct, loc, pref);
3069 DPRINTF (("Make param: %s", uentry_unparseFull (ue)));
3070 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3071 uentry_implicitParamAnnots (ue);
3073 /* Parameter type [][] or [x][] is invalid */
3075 while (ctype_isFixedArray (base)) {
3076 base = ctype_baseArrayPtr (base);
3079 if (ctype_isIncompleteArray (base)) {
3080 base = ctype_baseArrayPtr (base);
3082 if (ctype_isArray (base)) {
3083 if (!uentry_hasName (ue)) {
3084 (void) optgenerror (FLG_INCOMPLETETYPE,
3085 message ("Unnamed function parameter %d is incomplete type (inner array must have bounds): %s",
3087 ctype_unparse (ct)),
3088 uentry_whereLast (ue));
3090 (void) optgenerror (FLG_INCOMPLETETYPE,
3091 message ("Function parameter %q is incomplete type (inner array must have bounds): %s",
3092 uentry_getName (ue),
3093 ctype_unparse (ct)),
3094 uentry_whereLast (ue));
3099 DPRINTF (("Param: %s", uentry_unparseFull (ue)));
3103 /*@only@*/ /*@notnull@*/ uentry uentry_makeIdVariable (idDecl t)
3105 ctype ct = idDecl_getCtype (t);
3107 if (ctype_isFunction (ct))
3109 return (uentry_makeIdFunction (t));
3113 fileloc loc = setLocation ();
3114 uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
3116 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3118 if (!uentry_isExtern (ue))
3120 uentry_setDefined (ue, loc);
3127 /*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t, fileloc loc)
3129 return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), fileloc_copy (loc), SS_DEFINED));
3136 static /*@only@*/ /*@notnull@*/
3137 uentry uentry_makeConstantAux (cstring n, ctype t,
3138 /*@keep@*/ fileloc f, bool priv, bool macro,
3139 /*@only@*/ multiVal m)
3141 uentry e = uentry_alloc ();
3144 e->uname = cstring_copy (n);
3146 e->storageclass = SCNONE;
3148 e->warn = warnClause_undefined; /*@i32 warnings for constants? */
3150 e->sref = sRef_makeConst (t);
3155 e->uses = filelocList_new ();
3156 e->isPrivate = priv;
3157 e->hasNameError = FALSE;
3159 e->info = (uinfo) dmalloc (sizeof (*e->info));
3160 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
3161 e->info->uconst->access = typeIdSet_undefined;
3162 e->info->uconst->macro = macro;
3164 uentry_setSpecDef (e, f);
3166 if (multiVal_isInt (m) && (multiVal_forceInt (m) == 0))
3168 sRef_setDefNull (e->sref, uentry_whereDeclared (e));
3171 uentry_setConstantValue (e, m);
3176 /*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
3178 uentry ue = uentry_makeConstantAux (n, t, f, FALSE, FALSE, multiVal_unknown ());
3182 /*@notnull@*/ uentry uentry_makeConstantValue (cstring n, ctype t, fileloc f, bool priv, multiVal val)
3184 uentry ue = uentry_makeConstantAux (n, t, f, priv, FALSE, val);
3188 /*@notnull@*/ uentry uentry_makeMacroConstant (cstring n, ctype t, fileloc f)
3190 uentry ue = uentry_makeConstantAux (n, t, f, FALSE, TRUE, multiVal_unknown ());
3194 /*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
3196 uentry ue = uentry_makeConstant (idDecl_observeId (t),
3197 idDecl_getCtype (t),
3200 llassert (fileloc_isUndefined (ue->whereDeclared));
3201 ue->whereDeclared = setLocation ();
3202 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3204 DPRINTF (("Constant: %s", uentry_unparseFull (ue)));
3205 DPRINTF (("Value: %s", multiVal_unparse (uentry_getConstantValue (ue))));
3213 void uentry_setDefState (uentry ue, sstate defstate)
3215 if (uentry_isValid (ue))
3217 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
3219 if (uentry_isVariable (ue))
3221 ue->info->var->defstate = defstate; /* evs 2000-05-17: fixed bug, was SS_DEFINED! */
3226 bool uentry_isCheckedUnknown (uentry ue)
3228 return (uentry_isVar (ue)
3229 && (ue->info->var->checked == CH_UNKNOWN));
3232 bool uentry_isCheckMod (uentry ue)
3234 return (uentry_isVar (ue)
3235 && (ue->info->var->checked == CH_CHECKMOD));
3238 bool uentry_isUnchecked (uentry ue)
3240 return (uentry_isVar (ue)
3241 && (ue->info->var->checked == CH_UNCHECKED));
3244 bool uentry_isChecked (uentry ue)
3246 return (uentry_isVar (ue)
3247 && (ue->info->var->checked == CH_CHECKED));
3250 bool uentry_isCheckedModify (uentry ue)
3252 return (uentry_isVar (ue)
3253 && (ue->info->var->checked == CH_CHECKED
3254 || ue->info->var->checked == CH_CHECKMOD
3255 || ue->info->var->checked == CH_CHECKEDSTRICT));
3258 bool uentry_isCheckedStrict (uentry ue)
3260 return (uentry_isVar (ue)
3261 && (ue->info->var->checked == CH_CHECKEDSTRICT));
3264 void uentry_setUnchecked (uentry ue)
3266 llassert (uentry_isVar (ue));
3268 ue->info->var->checked = CH_UNCHECKED;
3271 void uentry_setChecked (uentry ue)
3273 llassert (uentry_isVar (ue));
3275 ue->info->var->checked = CH_CHECKED;
3278 void uentry_setCheckMod (uentry ue)
3280 llassert (uentry_isVar (ue));
3282 ue->info->var->checked = CH_CHECKMOD;
3285 void uentry_setCheckedStrict (uentry ue)
3287 llassert (uentry_isVar (ue));
3289 ue->info->var->checked = CH_CHECKEDSTRICT;
3292 static /*@only@*/ /*@notnull@*/
3293 uentry uentry_makeVariableAux (cstring n, ctype t,
3295 /*@exposed@*/ sRef s,
3296 bool priv, vkind kind)
3298 uentry e = uentry_alloc ();
3301 DPRINTF (("Make variable: %s %s %s", n, ctype_unparse (t), sRef_unparse (s)));
3304 e->uname = cstring_copy (n);
3307 e->storageclass = SCNONE;
3309 e->warn = warnClause_undefined; /*@i32 warnings for variable @*/
3316 e->uses = filelocList_new ();
3317 e->isPrivate = priv;
3318 e->hasNameError = FALSE;
3320 e->info = (uinfo) dmalloc (sizeof (*e->info));
3321 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
3322 e->info->var->kind = kind;
3324 /*@i523 e->info->var->origsref = sRef_saveCopy (e->sref); */
3325 e->info->var->checked = CH_UNKNOWN;
3327 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3328 uentry_setSpecDef (e, f);
3329 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3331 if (ctype_isFunction (rt))
3333 rt = ctype_getReturnType (rt);
3336 if (ctype_isUA (rt))
3338 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3339 sRef_setStateFromType (e->sref, rt);
3342 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3343 e->info->var->defstate = sRef_getDefState (e->sref);
3344 e->info->var->nullstate = sRef_getNullState (e->sref);
3346 /* start modifications */
3347 /* This function sets the uentry for a pointer or array variable declaration,
3348 it allocates memory and sets the fields. We check if the type of the variable
3349 is a pointer or array and allocate a `bbufinfo' struct accordingly */
3351 if (ctype_isArray (t) || ctype_isPointer(t))
3353 /*@i222@*/ e->info->var->bufinfo = dmalloc (sizeof (*e->info->var->bufinfo));
3354 e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
3355 sRef_setNotNullTerminatedState (s);
3359 e->info->var->bufinfo = NULL;
3361 /* end modification */
3367 uentry_isYield (uentry ue)
3369 return (uentry_isVariable (ue)
3370 && (ue->info->var->kind == VKYIELDPARAM
3371 || ue->info->var->kind == VKREFYIELDPARAM));
3375 uentry_isRefsField (uentry ue)
3377 return (uentry_isVariable (ue) && sRef_isRefsField (ue->sref));
3380 /*@only@*/ /*@notnull@*/
3381 uentry uentry_makeVariable (cstring n, ctype t, fileloc f, bool isPriv)
3383 return (uentry_makeVariableAux (n, t, f, sRef_makeType (t), isPriv,
3384 fileloc_isSpec (f) ? VKSPEC : VKNORMAL));
3391 void uentry_makeVarFunction (uentry ue)
3398 llassert (uentry_isValid (ue));
3399 llassert (!sRef_modInFunction ());
3401 ak = sRef_getOrigAliasKind (ue->sref);
3402 ek = sRef_getOrigExKind (ue->sref);
3404 llassert (uentry_isVariable (ue));
3405 oldInfo = ue->info->var;
3407 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
3408 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ctype_realType (ue->utype)));
3411 ** expanded macro is marked used
3414 ue->used = ue->used || (oldInfo->kind == VKEXPMACRO);
3417 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3418 ue->info->fcn->exitCode = XK_UNKNOWN;
3419 ue->info->fcn->nullPred = qual_createUnknown ();
3420 ue->info->fcn->specialCode = SPC_NONE;
3421 ue->info->fcn->access = typeIdSet_undefined;
3422 ue->info->fcn->hasGlobs = FALSE;
3423 ue->info->fcn->globs = globSet_undefined;
3424 ue->info->fcn->hasMods = FALSE;
3425 ue->info->fcn->mods = sRefSet_undefined;
3426 ue->info->fcn->specclauses = NULL;
3427 ue->info->fcn->defparams = uentryList_undefined;
3430 ue->info->fcn->preconditions = functionConstraint_undefined;
3434 ue->info->fcn->postconditions = functionConstraint_undefined;
3437 if (ctype_isFunction (ue->utype))
3439 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3443 ue->sref = sRef_makeType (ctype_unknown);
3446 if (sRef_isRefCounted (ue->sref))
3452 if (alkind_isUnknown (ak))
3454 if (exkind_isKnown (ek))
3456 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3457 ak = AK_IMPDEPENDENT;
3461 if (context_getFlag (FLG_RETIMPONLY))
3463 if (ctype_isFunction (ue->utype)
3464 && ctype_isVisiblySharable
3465 (ctype_realType (ctype_getReturnType (ue->utype))))
3467 if (uentryList_hasReturned (uentry_getParams (ue)))
3473 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3488 loc = ue->whereDeclared;
3490 sRef_setAliasKind (ue->sref, ak, loc);
3491 sRef_setNullState (ue->sref, oldInfo->nullstate, loc);
3492 sRef_setDefState (ue->sref, oldInfo->defstate, loc);
3493 sRef_setExKind (ue->sref, ek, loc);
3495 if (oldInfo->kind == VKEXPMACRO)
3501 fileloc_free (ue->whereDefined);
3502 ue->whereDefined = fileloc_undefined;
3505 uvinfo_free (oldInfo);
3508 void uentry_makeConstantFunction (uentry ue)
3515 llassert (uentry_isValid (ue));
3516 llassert (!sRef_modInFunction ());
3518 ak = sRef_getOrigAliasKind (ue->sref);
3519 ek = sRef_getOrigExKind (ue->sref);
3521 llassert (uentry_isConstant (ue));
3522 oldInfo = ue->info->uconst;
3524 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
3527 ** expanded macro is marked used (until I write a pre-processor)
3531 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3532 ue->info->fcn->exitCode = XK_UNKNOWN;
3533 ue->info->fcn->nullPred = qual_createUnknown ();
3534 ue->info->fcn->specialCode = SPC_NONE;
3535 ue->info->fcn->access = typeIdSet_undefined;
3536 ue->info->fcn->hasGlobs = FALSE;
3537 ue->info->fcn->globs = globSet_undefined;
3538 ue->info->fcn->hasMods = FALSE;
3539 ue->info->fcn->mods = sRefSet_undefined;
3540 ue->info->fcn->specclauses = NULL;
3541 ue->info->fcn->defparams = uentryList_undefined;
3544 ue->info->fcn->preconditions = functionConstraint_undefined;
3548 ue->info->fcn->postconditions = functionConstraint_undefined;
3552 if (ctype_isFunction (ue->utype))
3554 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3558 ue->sref = sRef_makeType (ctype_unknown);
3561 if (sRef_isRefCounted (ue->sref))
3567 if (alkind_isUnknown (ak))
3569 if (exkind_isKnown (ek))
3571 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3572 ak = AK_IMPDEPENDENT;
3576 if (context_getFlag (FLG_RETIMPONLY))
3578 if (ctype_isFunction (ue->utype)
3579 && ctype_isVisiblySharable
3580 (ctype_realType (ctype_getReturnType (ue->utype))))
3582 if (uentryList_hasReturned (uentry_getParams (ue)))
3588 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3603 loc = ue->whereDeclared;
3605 sRef_setAliasKind (ue->sref, ak, loc);
3606 sRef_setExKind (ue->sref, ek, loc);
3608 fileloc_free (ue->whereDefined);
3609 ue->whereDefined = fileloc_undefined;
3610 ucinfo_free (oldInfo);
3614 uentry_setGlobals (uentry ue, /*@only@*/ globSet globs)
3616 llassert (uentry_isValid (ue));
3618 globSet_markImmutable (globs);
3620 if (uentry_isIter (ue))
3622 ue->info->iter->globs = globSet_unionFree (ue->info->iter->globs, globs);
3626 uentry_convertVarFunction (ue);
3627 llassert (uentry_isFunction (ue));
3629 ue->info->fcn->hasGlobs = TRUE;
3630 ue->info->fcn->globs = globSet_unionFree (ue->info->fcn->globs, globs);
3633 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3635 ue->info->fcn->hasMods = TRUE;
3639 void uentry_addAccessType (uentry ue, typeId tid)
3641 if (uentry_isFunction (ue))
3643 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3645 else if (uentry_isEitherConstant (ue))
3647 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3649 else if (uentry_isIter (ue))
3651 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3653 else if (uentry_isEndIter (ue))
3655 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3659 llbug (message ("no access for: %q", uentry_unparse (ue)));
3663 /*@only@*/ /*@notnull@*/ uentry
3664 uentry_makeFunction (cstring n, ctype t,
3666 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
3667 /*@only@*/ warnClause warn,
3670 llassert (warnClause_isUndefined (warn)); /*@i325 remove parameter! */
3671 return (uentry_makeFunctionAux (n, t,
3672 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3673 : typeIdSet_single (access)),
3679 /*@notnull@*/ uentry
3680 uentry_makePrivFunction2 (cstring n, ctype t,
3682 globSet globs, sRefSet mods,
3685 return (uentry_makeFunctionAux (n, t, access, globs, mods, warnClause_undefined,
3690 /*@notnull@*/ uentry
3691 uentry_makeSpecFunction (cstring n, ctype t,
3693 /*@only@*/ globSet globs,
3694 /*@only@*/ sRefSet mods,
3697 uentry ue = uentry_makeFunctionAux (n, t, access,
3698 globs, mods, warnClause_undefined,
3701 uentry_setHasGlobs (ue);
3702 uentry_setHasMods (ue);
3704 reflectImplicitFunctionQualifiers (ue, TRUE);
3708 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3710 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3711 sRef_undefined, FALSE, VKEXPMACRO);
3713 uentry_setDefined (ue, f);
3717 /*@notnull@*/ /*@notnull@*/ uentry
3718 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3720 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3721 typeIdSet_singleOpt (access),
3722 globSet_undefined, sRefSet_undefined,
3723 warnClause_undefined,
3727 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3731 bool uentry_isForward (uentry e)
3733 if (uentry_isValid (e))
3735 ctype ct = uentry_getType (e);
3737 return (ctype_isUnknown (ct)
3738 || (ctype_isFunction (ct)
3739 && ctype_isUnknown (ctype_getReturnType (ct))));
3745 /*@notnull@*/ uentry
3746 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3748 return (uentry_makeFunctionAux (n, ctype_unknown, access,
3749 globSet_undefined, sRefSet_undefined, warnClause_undefined,
3753 /*@notnull@*/ uentry
3754 uentry_makeUnspecFunction (cstring n, ctype t,
3758 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_undefined,
3759 sRefSet_undefined, warnClause_undefined,
3762 reflectImplicitFunctionQualifiers (ue, TRUE);
3770 /* is exported for use by usymtab_interface */
3772 /*@notnull@*/ uentry
3773 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, ynm abstract,
3774 fileloc f, bool priv)
3776 uentry e = uentry_alloc ();
3778 DPRINTF (("Make datatype: %s / %s",
3779 n, ctype_unparse (t)));
3781 /* e->shallowCopy = FALSE; */
3782 e->ukind = KDATATYPE;
3783 e->uname = cstring_copy (n);
3785 e->storageclass = SCNONE;
3786 e->sref = sRef_makeUnknown ();
3790 sRef_setStateFromType (e->sref, t);
3793 uentry_setSpecDef (e, f);
3795 e->warn = warnClause_undefined; /*@i634@*/
3796 e->uses = filelocList_new ();
3797 e->isPrivate = priv;
3798 e->hasNameError = FALSE;
3803 e->info = (uinfo) dmalloc (sizeof (*e->info));
3804 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3805 e->info->datatype->abs = abstract;
3806 e->info->datatype->mut = mut;
3807 e->info->datatype->type = ctype_undefined;
3809 if (uentry_isDeclared (e))
3811 uentry_setDefined (e, f);
3814 if (ynm_isOn (abstract) && !(uentry_isCodeDefined (e)))
3816 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3822 /*@notnull@*/ uentry
3823 uentry_makeDatatype (cstring n, ctype t, ynm mut, ynm abstract, fileloc f)
3825 return (uentry_makeDatatypeAux (n, t, mut, abstract, f, FALSE));
3828 /*@notnull@*/ uentry uentry_makeBoolDatatype (ynm abstract)
3830 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
3831 ctype_bool, NO, abstract,
3832 fileloc_getBuiltin (),
3835 ret->info->datatype->type = ctype_bool;
3843 static /*@only@*/ /*@notnull@*/ uentry
3844 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3845 /*@only@*/ fileloc f)
3847 uentry e = uentry_alloc ();
3850 e->uname = cstring_copy (n);
3852 e->sref = sRef_makeUnknown ();
3853 e->storageclass = SCNONE;
3857 uentry_setSpecDef (e, f);
3859 e->warn = warnClause_undefined; /*@i452@*/
3860 e->uses = filelocList_new ();
3861 e->isPrivate = FALSE;
3862 e->hasNameError = FALSE;
3864 e->info = (uinfo) dmalloc (sizeof (*e->info));
3865 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3866 e->info->iter->access = access;
3867 e->info->iter->mods = sRefSet_undefined;
3868 e->info->iter->globs = globSet_undefined;
3870 uentry_checkIterArgs (e);
3874 /*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3876 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3879 static /*@notnull@*/ uentry
3880 uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3882 uentry e = uentry_alloc ();
3884 /* e->shallowCopy = FALSE; */
3885 e->ukind = KENDITER;
3886 e->storageclass = SCNONE;
3887 e->uname = message ("end_%s", n);
3888 e->utype = ctype_unknown;
3889 e->sref = sRef_makeUnknown ();
3891 uentry_setSpecDef (e, f);
3896 e->uses = filelocList_new ();
3897 e->isPrivate = FALSE;
3898 e->hasNameError = FALSE;
3900 e->info = (uinfo) dmalloc (sizeof (*e->info));
3901 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3903 e->info->enditer->access = access;
3905 e->warn = warnClause_undefined; /*@i452@*/
3909 /*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3911 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3918 static /*@only@*/ /*@notnull@*/ uentry
3919 uentry_makeTagAux (cstring n, ctype t,
3920 /*@only@*/ fileloc fl,
3921 bool priv, ekind kind)
3923 uentry e = uentry_alloc ();
3925 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3927 llbuglit ("uentry_makeTagAux: not a tag type");
3931 /* e->shallowCopy = FALSE; */
3932 e->uname = cstring_copy (n);
3935 e->sref = sRef_makeUnknown ();
3936 e->storageclass = SCNONE;
3938 uentry_setSpecDef (e, fl);
3943 e->uses = filelocList_new ();
3944 e->isPrivate = priv;
3945 e->hasNameError = FALSE;
3947 e->info = (uinfo) dmalloc (sizeof (*e->info));
3948 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3949 e->info->datatype->abs = NO;
3950 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3951 e->info->datatype->type = t;
3952 e->warn = warnClause_undefined; /*@i452@*/
3954 if (uentry_isDeclared (e))
3956 uentry_setDefined (e, fl);
3962 uentry uentry_makeStructTagLoc (cstring n, ctype t)
3964 cstring sname = makeStruct (n);
3965 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3967 cstring_free (sname);
3972 uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3974 cstring sname = makeStruct (n);
3975 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3977 cstring_free (sname);
3982 uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
3984 cstring uname = makeUnion (n);
3985 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
3987 cstring_free (uname);
3992 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
3994 cstring ename = makeEnum (n);
3995 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
3997 cstring_free (ename);
4002 uentry_makeUnionTagLoc (cstring n, ctype t)
4004 cstring uname = makeUnion (n);
4005 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
4007 cstring_free (uname);
4012 uentry_makeEnumTagLoc (cstring n, ctype t)
4014 cstring ename = makeEnum (n);
4015 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
4017 cstring_free (ename);
4022 uentry_isStructTag (uentry ue)
4024 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
4028 uentry_isUnionTag (uentry ue)
4030 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
4034 uentry_isEnumTag (uentry ue)
4036 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
4040 uentry_isAnyTag (uentry ue)
4042 return (uentry_isStructTag (ue)
4043 || uentry_isUnionTag (ue)
4044 || uentry_isEnumTag (ue));
4047 static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
4049 extern void uentry_destroyMod (void)
4050 /*@globals killed emarker@*/ /*@modifies emarker@*/
4052 static bool wasDestroyed = FALSE;
4054 llassert (!wasDestroyed);
4056 if (emarker != NULL)
4058 uentry_reallyFree (emarker);
4061 wasDestroyed = TRUE;
4065 uentry_makeElipsisMarker (void)
4067 if (emarker == NULL)
4069 emarker = uentry_alloc ();
4071 emarker->ukind = KELIPSMARKER;
4072 emarker->uname = cstring_makeLiteral ("...");
4073 emarker->utype = ctype_elipsMarker;
4074 emarker->sref = sRef_undefined;
4075 emarker->storageclass = SCNONE;
4076 emarker->used = FALSE;
4077 emarker->lset = FALSE;
4078 emarker->info = NULL;
4080 uentry_setSpecDef (emarker, fileloc_undefined);
4081 emarker->uses = filelocList_new ();
4082 emarker->isPrivate = FALSE;
4083 emarker->hasNameError = FALSE;
4086 /*@ignore@*/ return (emarker); /*@end@*/
4094 uentry_equiv (uentry p1, uentry p2)
4096 if (uentry_compare (p1, p2) != 0)
4107 uentry_xcomparealpha (uentry *p1, uentry *p2)
4111 if ((res = uentry_compare (*p1, *p2)) == 0) {
4112 if ((*p1 != NULL) && (*p2 != NULL)) {
4113 res = cstring_compare ((*p1)->uname,
4122 uentry_xcompareuses (uentry *p1, uentry *p2)
4127 if (uentry_isValid (u1))
4129 if (uentry_isValid (u2))
4131 return (-1 * int_compare (filelocList_size (u1->uses),
4132 filelocList_size (u2->uses)));
4141 if (uentry_isValid (u2))
4153 uentry_compareStrict (uentry v1, uentry v2)
4155 COMPARERETURN (uentry_compare (v1, v2));
4157 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
4159 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
4160 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
4161 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
4168 uentry_compare (uentry u1, uentry u2)
4170 if (u1 == u2) return 0;
4172 if (uentry_isInvalid (u1)) return -1;
4173 if (uentry_isInvalid (u2)) return 1;
4175 INTCOMPARERETURN (u1->ukind, u2->ukind);
4176 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
4177 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
4178 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
4184 /* bug detected by splint:
4185 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
4190 return (multiVal_compare (uentry_getConstantValue (u1),
4191 uentry_getConstantValue (u2)));
4195 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
4197 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
4198 uentry_accessType (u2)));
4199 return (uentryList_compareParams (uentry_getParams (u1),
4200 uentry_getParams (u2)));
4202 return (typeIdSet_compare (uentry_accessType (u1),
4203 uentry_accessType (u2)));
4206 ** Functions are never equivalent
4209 if (u1 - u2 < 0) /* evans 2001-08-21: was: ((int) u1 < (int) u2), changed to remove gcc warning */
4219 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
4220 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
4221 sRef_getOrigAliasKind (u2->sref)));
4222 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
4223 sRef_getOrigExKind (u2->sref)));
4224 COMPARERETURN (generic_compare (u1->info->var->checked,
4225 u2->info->var->checked));
4226 COMPARERETURN (generic_compare (u1->info->var->defstate,
4227 u2->info->var->defstate));
4228 return (generic_compare (u1->info->var->nullstate,
4229 u2->info->var->nullstate));
4231 COMPARERETURN (ctype_compare (u1->info->datatype->type,
4232 u2->info->datatype->type));
4233 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
4234 u2->info->datatype->mut));
4235 return (ynm_compare (u1->info->datatype->abs, u2->info->datatype->abs));
4244 ** all entries are: <type>[@<info>]*#<name>
4246 ** info depends on kind:
4250 advanceField (char **s)
4252 reader_checkChar (s, '@');
4256 advanceName (char **s)
4258 reader_checkChar (s, '#');
4262 vkind_fromInt (int i)
4264 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
4266 llbuglit ("vkind_fromInt: out of range");
4273 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
4274 typeIdSet access, nstate nullstate,
4275 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
4277 uentry e = uentry_alloc ();
4282 e->sref = sRef_makeConst (ct);
4284 sRef_setNullState (e->sref, nullstate, loc);
4285 e->storageclass = SCNONE;
4287 if (fileloc_isSpec (loc))
4289 e->whereSpecified = loc;
4290 e->whereDeclared = fileloc_undefined;
4294 e->whereSpecified = fileloc_undefined;
4295 e->whereDeclared = loc;
4298 e->whereDefined = fileloc_undefined;
4299 e->uses = filelocList_new ();
4300 e->isPrivate = FALSE;
4301 e->hasNameError = FALSE;
4306 e->warn = warnClause_undefined; /*@i452@*/
4308 e->info = (uinfo) dmalloc (sizeof (*e->info));
4309 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
4310 e->info->uconst->access = access;
4311 e->info->uconst->macro = FALSE; /*@i523! fix this when macro info added to library */
4312 uentry_setConstantValue (e, m);
4313 sRef_storeState (e->sref);
4318 static /*@only@*/ uentry
4319 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
4320 sstate defstate, nstate isnull, alkind aliased,
4321 exkind exp, chkind checked,
4322 /*@only@*/ fileloc loc)
4324 uentry e = uentry_alloc ();
4329 e->storageclass = SCNONE;
4331 e->sref = sRef_makeType (ct);
4332 sRef_setNullState (e->sref, isnull, loc);
4334 e->whereDefined = fileloc_undefined;
4336 if (fileloc_isSpec (loc))
4338 e->whereSpecified = loc;
4339 e->whereDeclared = fileloc_undefined;
4343 e->whereSpecified = fileloc_undefined;
4344 e->whereDeclared = loc;
4347 e->isPrivate = FALSE;
4348 e->hasNameError = FALSE;
4353 e->uses = filelocList_new ();
4354 e->warn = warnClause_undefined; /*@i452@*/
4356 e->info = (uinfo) dmalloc (sizeof (*e->info));
4357 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
4358 e->info->var->kind = kind;
4359 e->info->var->checked = checked;
4360 e->info->var->defstate = defstate;
4362 sRef_setDefState (e->sref, defstate, loc);
4364 e->info->var->nullstate = sRef_getNullState (e->sref);
4366 sRef_setExKind (e->sref, exp, loc);
4367 sRef_setAliasKind (e->sref, aliased, loc);
4369 sRef_storeState (e->sref);
4371 /*DRL ADDED 9-1-2000 */
4372 e->info->var->bufinfo = NULL;
4377 static /*@only@*/ uentry
4378 uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, ynm abstract,
4379 ynm mut, ctype rtype, alkind ak, exkind exp,
4380 sstate defstate, nstate isnull,
4381 /*@only@*/ fileloc loc)
4383 uentry e = uentry_alloc ();
4385 e->ukind = KDATATYPE;
4386 /* e->shallowCopy = FALSE; */
4389 e->storageclass = SCNONE;
4390 e->sref = sRef_makeUnknown ();
4391 DPRINTF (("Merge null 1: %s", sRef_unparseFull (e->sref)));
4394 ** This is only setting null state. (I think?)
4397 if (ctype_isUA (ct))
4399 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
4401 if (uentry_isValid (te))
4403 sRef_setStateFromUentry (e->sref, te);
4407 /* problem for recursive type definitions */
4411 sRef_setAliasKind (e->sref, ak, loc);
4412 sRef_setExKind (e->sref, exp, loc);
4414 sRef_setDefState (e->sref, defstate, loc);
4416 if (ynm_isOn (abstract) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
4418 isnull = NS_ABSNULL;
4421 DPRINTF (("Merge null: %s", sRef_unparseFull (e->sref)));
4422 sRef_mergeNullState (e->sref, isnull);
4424 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
4426 if (fileloc_isSpec (loc))
4428 e->whereSpecified = loc;
4429 e->whereDeclared = fileloc_undefined;
4433 e->whereSpecified = fileloc_undefined;
4434 e->whereDeclared = loc;
4437 e->isPrivate = FALSE;
4438 e->hasNameError = FALSE;
4440 e->warn = warnClause_undefined; /*@i452@*/
4444 e->uses = filelocList_new ();
4446 e->info = (uinfo) dmalloc (sizeof (*e->info));
4447 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4448 e->info->datatype->abs = abstract;
4449 e->info->datatype->mut = mut;
4450 e->info->datatype->type = rtype;
4452 DPRINTF (("About to store: %s", sRef_unparseFull (e->sref)));
4453 sRef_storeState (e->sref);
4454 DPRINTF (("After store: %s", sRef_unparseFull (e->sref)));
4459 static void uentry_setHasGlobs (uentry ue)
4461 llassert (uentry_isFunction (ue));
4463 ue->info->fcn->hasGlobs = TRUE;
4466 static void uentry_setHasMods (uentry ue)
4468 llassert (uentry_isFunction (ue));
4470 ue->info->fcn->hasMods = TRUE;
4473 bool uentry_hasGlobs (uentry ue)
4475 if (uentry_isFunction (ue))
4477 return (ue->info->fcn->hasGlobs);
4483 bool uentry_hasStateClauseList (uentry ue)
4485 return (uentry_isFunction (ue) && stateClauseList_isDefined (ue->info->fcn->specclauses));
4488 bool uentry_hasConditions (uentry ue)
4490 return (uentry_isFunction (ue)
4491 && (functionConstraint_isDefined (ue->info->fcn->preconditions)
4492 || functionConstraint_isDefined (ue->info->fcn->postconditions)));
4495 stateClauseList uentry_getStateClauseList (uentry ue)
4497 if (!uentry_isFunction (ue))
4499 llassert (uentry_isFunction (ue));
4500 return stateClauseList_undefined;
4503 DPRINTF (("Get state clause list: %s", uentry_unparse (ue)));
4504 return ue->info->fcn->specclauses;
4507 bool uentry_hasMods (uentry ue)
4509 if (uentry_isFunction (ue))
4511 return (ue->info->fcn->hasMods);
4518 uentry_makeFunctionBase (/*@only@*/ cstring name, ctype ct,
4520 bool hasGlobs, /*@only@*/ globSet globs,
4521 bool hasMods, /*@only@*/ sRefSet mods,
4522 alkind ak, exkind exp,
4523 sstate defstate, nstate isnull,
4527 /*@only@*/ stateClauseList specclauses,
4528 /*@only@*/ warnClause warnclause,
4529 /*@only@*/ fileloc loc)
4531 uentry e = uentry_alloc ();
4534 /* e->shallowCopy = FALSE; */
4538 e->storageclass = SCNONE;
4540 if (ctype_isFunction (ct))
4542 ret = ctype_getReturnType (ct);
4546 if (ctype_isKnown (ct))
4548 llbug (message ("not function: %s", ctype_unparse (ct)));
4551 ret = ctype_unknown;
4554 e->sref = sRef_makeType (ret);
4556 if (ctype_isUA (ret))
4558 sRef_setStateFromType (e->sref, ret);
4561 sRef_setDefined (e->sref, loc);
4562 sRef_setNullState (e->sref, isnull, loc);
4564 sRef_setAliasKind (e->sref, ak, loc);
4565 sRef_setExKind (e->sref, exp, loc);
4566 sRef_setDefState (e->sref, defstate, loc);
4568 e->whereSpecified = loc;
4569 e->whereDefined = fileloc_undefined;
4571 e->isPrivate = FALSE;
4572 e->hasNameError = FALSE;
4576 e->uses = filelocList_new ();
4577 e->warn = warnclause;
4579 e->info = (uinfo) dmalloc (sizeof (*e->info));
4580 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
4582 e->info->fcn->exitCode = exitCode;
4583 e->info->fcn->specialCode = sCode;
4584 e->info->fcn->nullPred = nullPred;
4585 e->info->fcn->access = access;
4587 e->info->fcn->specclauses = specclauses;
4588 e->info->fcn->hasGlobs = hasGlobs;
4589 e->info->fcn->globs = globs;
4591 e->info->fcn->hasMods = hasMods;
4592 e->info->fcn->mods = mods;
4594 e->info->fcn->defparams = uentryList_undefined;
4595 e->whereDeclared = fileloc_undefined;
4597 sRef_storeState (e->sref);
4600 e->info->fcn->preconditions = NULL;
4604 e->info->fcn->postconditions = NULL;
4610 static /*@only@*/ uentry
4611 uentry_makeTagBase (/*@only@*/ cstring name, ekind tagkind,
4612 ctype ct, ctype rtype, /*@only@*/ fileloc loc)
4614 uentry e = uentry_alloc ();
4616 if (tagkind != KSTRUCTTAG && tagkind != KUNIONTAG && tagkind != KENUMTAG)
4618 llbuglit ("uentry_makeTagBase: not a tag type");
4621 /* e->shallowCopy = FALSE; */
4625 e->sref = sRef_makeUnknown ();
4626 e->storageclass = SCNONE;
4628 if (fileloc_isSpec (loc))
4630 e->whereSpecified = loc;
4631 e->whereDeclared = fileloc_undefined;
4635 e->whereDeclared = loc;
4636 e->whereSpecified = fileloc_undefined;
4639 e->whereDefined = fileloc_undefined;
4641 e->isPrivate = FALSE;
4642 e->hasNameError = FALSE;
4646 e->uses = filelocList_new ();
4647 e->warn = warnClause_undefined; /*@i452@*/
4649 e->info = (uinfo) dmalloc (sizeof (*e->info));
4650 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4651 e->info->datatype->abs = NO;
4652 e->info->datatype->mut = MAYBE;
4653 e->info->datatype->type = rtype;
4655 sRef_storeState (e->sref);
4661 uentry_makeIterBase (/*@only@*/ cstring name, typeIdSet access,
4662 ctype ct, /*@only@*/ fileloc loc)
4664 uentry e = uentry_alloc ();
4666 /* e->shallowCopy = FALSE; */
4670 e->sref = sRef_makeUnknown ();
4671 e->storageclass = SCNONE;
4673 if (fileloc_isSpec (loc))
4675 e->whereSpecified = loc;
4676 e->whereDeclared = fileloc_undefined;
4680 e->whereDeclared = loc;
4681 e->whereSpecified = fileloc_undefined;
4684 e->whereDefined = fileloc_undefined;
4686 e->isPrivate = FALSE;
4687 e->hasNameError = FALSE;
4691 e->uses = filelocList_new ();
4692 e->warn = warnClause_undefined; /*@i452@*/
4694 e->info = (uinfo) dmalloc (sizeof (*e->info));
4695 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
4696 e->info->iter->access = access;
4697 e->info->iter->mods = sRefSet_undefined;
4698 e->info->iter->globs = globSet_undefined;
4700 sRef_storeState (e->sref);
4705 uentry_makeEndIterBase (/*@only@*/ cstring name, typeIdSet access,
4706 /*@only@*/ fileloc loc)
4708 uentry e = uentry_alloc ();
4710 /* e->shallowCopy = FALSE; */
4711 e->ukind = KENDITER;
4712 e->storageclass = SCNONE;
4714 e->utype = ctype_unknown;
4715 e->sref = sRef_makeUnknown ();
4717 if (fileloc_isSpec (loc))
4719 e->whereSpecified = loc;
4720 e->whereDeclared = fileloc_undefined;
4724 e->whereDeclared = loc;
4725 e->whereSpecified = fileloc_undefined;
4728 e->whereDefined = fileloc_undefined;
4730 e->isPrivate = FALSE;
4731 e->hasNameError = FALSE;
4735 e->uses = filelocList_new ();
4736 e->warn = warnClause_undefined; /*@i452@*/
4738 e->info = (uinfo) dmalloc (sizeof (*e->info));
4739 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
4740 e->info->enditer->access = access;
4741 sRef_storeState (e->sref);
4746 void uentry_markFree (/*@unused@*/ /*@owned@*/ uentry u)
4754 uentry_undump (ekind kind, fileloc loc, char **s)
4758 DPRINTF (("Uentry undump: %s", *s));
4762 reader_checkChar (s, '!');
4763 reader_checkChar (s, '.');
4764 ue = uentry_makeElipsisMarker ();
4768 ctype ct = ctype_undump (s);
4782 reader_checkChar (s, '|');
4784 if (reader_optCheckChar (s, '@'))
4786 tkind = vkind_fromInt (reader_getInt (s));
4787 reader_checkChar (s, '|');
4794 if (reader_optCheckChar (s, '$'))
4796 defstate = SS_UNKNOWN;
4797 isnull = NS_UNKNOWN;
4798 aliased = AK_IMPTEMP;
4800 checked = CH_UNKNOWN;
4802 else if (reader_optCheckChar (s, '&'))
4804 defstate = SS_DEFINED;
4805 isnull = NS_UNKNOWN;
4806 aliased = AK_IMPTEMP;
4808 checked = CH_UNKNOWN;
4810 else if (reader_optCheckChar (s, '^'))
4812 defstate = SS_UNKNOWN;
4813 isnull = NS_UNKNOWN;
4814 aliased = AK_IMPTEMP;
4816 checked = CH_UNKNOWN;
4820 defstate = sstate_fromInt (reader_getInt (s));
4821 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4822 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4824 if (reader_optCheckChar (s, '&'))
4827 checked = CH_UNKNOWN;
4831 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4832 advanceField (s); checked = (chkind) (reader_getInt (s));
4837 name = reader_getStringWord (s);
4839 llassert (!cstring_equal (name, GLOBAL_MARKER_NAME));
4841 ue = uentry_makeVariableBase (name, ct, tkind, defstate,
4842 isnull, aliased, exp,
4843 checked, fileloc_copy (loc));
4856 advanceField (s); abstract = ynm_fromCodeChar (reader_loadChar (s));
4857 advanceField (s); mut = ynm_fromCodeChar (reader_loadChar (s));
4858 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4859 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4860 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4861 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4862 advanceField (s); rtype = ctype_undump (s);
4864 name = reader_getStringWord (s);
4865 DPRINTF (("Datatype %s, Exp = %s", name, exkind_unparse (exp)));
4866 ue = uentry_makeDatatypeBase (name, ct, abstract, mut, rtype,
4867 aliased, exp, defstate, isnull,
4868 fileloc_copy (loc));
4885 stateClauseList specclauses = stateClauseList_undefined;
4886 warnClause warnclause = warnClause_undefined;
4888 if (reader_optCheckChar (s, '$'))
4890 defstate = SS_DEFINED;
4891 isnull = NS_UNKNOWN;
4892 exitCode = XK_UNKNOWN;
4894 nullPred = qual_createUnknown ();
4898 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4899 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4900 advanceField (s); exitCode = exitkind_fromInt (reader_getInt (s));
4901 advanceField (s); specc = specCode_fromInt (reader_getInt (s));
4902 advanceField (s); nullPred = qual_undump (s);
4905 if (reader_optCheckChar (s, '$'))
4908 globs = globSet_undefined;
4910 mods = sRefSet_undefined;
4912 else if (reader_optCheckChar (s, '^'))
4915 globs = globSet_undefined;
4917 mods = sRefSet_undefined;
4921 advanceField (s); hasGlobs = bool_fromInt (reader_getInt (s));
4922 advanceField (s); globs = globSet_undump (s);
4923 advanceField (s); hasMods = bool_fromInt (reader_getInt (s));
4924 advanceField (s); mods = sRefSet_undump (s);
4927 if (reader_optCheckChar (s, '$'))
4934 advanceField (s); ak = alkind_fromInt (reader_getInt (s));
4935 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4938 advanceField (s); access = typeIdSet_undump (s);
4941 ** Optional clauses: Start with @<code>:
4944 while (reader_optCheckChar (s, '@'))
4946 if (reader_optCheckChar (s, 'W')) /* Warn clause */
4948 reader_checkChar (s, ':');
4949 warnclause = warnClause_undump (s);
4951 else if (reader_optCheckChar (s, 'S')) /* stateClause List */
4953 reader_checkChar (s, ':');
4954 specclauses = stateClauseList_undump (s);
4962 advanceName (s); name = reader_getStringWord (s);
4964 ue = uentry_makeFunctionBase (name, ct, access,
4967 ak, exp, defstate, isnull,
4968 exitCode, specc, nullPred,
4971 fileloc_copy (loc));
4972 DPRINTF (("Undump: %s", uentry_unparse (ue)));
4979 advanceField (s); access = typeIdSet_undump (s);
4980 advanceName (s); name = reader_getStringWord (s);
4982 ue = uentry_makeIterBase (name, access, ct,
4983 fileloc_copy (loc));
4990 advanceField (s); access = typeIdSet_undump (s);
4991 advanceName (s); name = reader_getStringWord (s);
4993 ue = uentry_makeEndIterBase (name, access, fileloc_copy (loc));
5003 if (reader_optCheckChar (s, '$'))
5005 val = multiVal_undefined;
5006 access = typeIdSet_undefined;
5007 nullstate = NS_UNKNOWN;
5011 advanceField (s); val = multiVal_undump (s);
5012 advanceField (s); access = typeIdSet_undump (s);
5013 advanceField (s); nullstate = nstate_fromInt (reader_getInt (s));
5016 advanceName (s); name = reader_getStringWord (s);
5018 ue = uentry_makeConstantBase (name, ct, access,
5019 nullstate, fileloc_copy (loc), val);
5028 advanceField (s); rtype = ctype_undump (s);
5029 advanceName (s); name = reader_getStringWord (s);
5030 ue = uentry_makeTagBase (name, kind, ct, rtype, fileloc_copy (loc));
5034 llcontbuglit ("uentry_undump: invalid");
5035 ue = uentry_undefined;
5038 llcontbuglit ("uentry_undump: elips marker");
5039 ue = uentry_undefined;
5048 uentry_dump (uentry v)
5050 return (uentry_dumpAux (v, FALSE));
5054 uentry_dumpParam (uentry v)
5056 llassertprint (uentry_isVariable (v) || uentry_isElipsisMarker (v),
5057 ("dump: %s", uentry_unparseFull (v)));
5059 return (uentry_dumpAux (v, TRUE));
5063 uentry_dumpAux (uentry v, bool isParam)
5065 llassert (uentry_isValid (v));
5066 llassert (!uentry_isGlobalMarker (v));
5068 DPRINTF (("Dump uentry: [%p]", v));
5069 DPRINTF (("Dumping entry: %s", uentry_unparseFull (v)));
5074 llcontbuglit ("uentry_dump: invalid entry");
5075 return cstring_undefined;
5077 return (message ("!."));
5081 vkind vk = v->info->var->kind;
5082 sstate dss = sRef_getDefState (v->sref);
5083 nstate nst = sRef_getNullState (v->sref);
5084 alkind alk = sRef_getAliasKind (v->sref);
5085 exkind exk = sRef_getExKind (v->sref);
5086 chkind chk = v->info->var->checked;
5088 DPRINTF (("Dumping var"));
5090 if (dss == SS_UNKNOWN
5091 && nst == NS_UNKNOWN
5092 && alk == AK_IMPTEMP
5093 && exk == XO_UNKNOWN
5094 && chk == CH_UNKNOWN)
5096 sdump = cstring_makeLiteral ("$");
5098 else if (dss == SS_DEFINED
5099 && nst == NS_UNKNOWN
5100 && alk == AK_IMPTEMP
5101 && exk == XO_UNKNOWN
5102 && chk == CH_UNKNOWN)
5104 sdump = cstring_makeLiteral ("&");
5106 else if (dss == SS_UNKNOWN
5107 && nst == NS_UNKNOWN
5108 && alk == AK_UNKNOWN
5109 && exk == XO_UNKNOWN
5110 && chk == CH_UNKNOWN)
5112 sdump = cstring_makeLiteral ("^");
5114 else if (exk == XO_UNKNOWN
5115 && chk == CH_UNKNOWN)
5117 sdump = message ("%d@%d@%d&",
5124 sdump = message ("%d@%d@%d@%d@%d",
5135 return (message ("%q|@%d|%q#%s",
5136 ctype_dump (v->utype),
5139 isParam ? cstring_undefined : v->uname));
5143 return (message ("%q|%q#%s",
5144 ctype_dump (v->utype),
5146 isParam ? cstring_undefined : v->uname));
5152 DPRINTF (("Dumping datatype: %s -> %s type: %s [%d]",
5154 exkind_unparse (sRef_getExKind (v->sref)),
5155 ctype_unparse (v->utype), (int) v->utype));
5158 return (message ("%q@%s@%s@%d@%d@%d@%d@%q#%s",
5159 ctype_dump (v->utype),
5160 ynm_unparseCode (v->info->datatype->abs),
5161 ynm_unparseCode (v->info->datatype->mut),
5162 (int) sRef_getDefState (v->sref),
5163 (int) sRef_getNullState (v->sref),
5164 (int) sRef_getAliasKind (v->sref),
5165 (int) sRef_getExKind (v->sref),
5166 ctype_dump (v->info->datatype->type),
5170 cstring sdump, gdump, adump, xdump;
5171 alkind alk = sRef_getAliasKind (v->sref);
5172 exkind exk = sRef_getExKind (v->sref);
5174 if (sRef_getDefState (v->sref) == SS_DEFINED
5175 && !nstate_isKnown (sRef_getNullState (v->sref))
5176 && !exitkind_isKnown (v->info->fcn->exitCode)
5177 && v->info->fcn->specialCode == SPC_NONE
5178 && qual_isUnknown (v->info->fcn->nullPred))
5180 sdump = cstring_makeLiteral ("$");
5184 sdump = message ("@%d@%d@%d@%d@%x",
5185 (int) sRef_getDefState (v->sref),
5186 (int) sRef_getNullState (v->sref),
5187 (int) v->info->fcn->exitCode,
5188 (int) v->info->fcn->specialCode,
5189 qual_dump (v->info->fcn->nullPred));
5192 if (!uentry_hasGlobs(v) && !uentry_hasMods (v))
5194 gdump = cstring_makeLiteral ("$");
5196 else if (uentry_hasGlobs (v) && globSet_isEmpty (uentry_getGlobs (v))
5197 && uentry_hasMods (v) && sRefSet_isEmpty (uentry_getMods (v)))
5199 gdump = cstring_makeLiteral ("^");
5203 gdump = message ("@%s@%q@%s@%q",
5204 bool_dump (uentry_hasGlobs (v)),
5205 globSet_dump (uentry_getGlobs (v)),
5206 bool_dump (uentry_hasMods (v)),
5207 sRefSet_dump (uentry_getMods (v)));
5210 if (alk == AK_UNKNOWN && exk == XO_UNKNOWN)
5212 adump = cstring_makeLiteral ("$");
5216 adump = message ("@%d@%d", (int) alk, (int) exk);
5219 xdump = cstring_undefined;
5221 if (uentry_hasWarning (v))
5223 xdump = message ("%q@W:%q", xdump, warnClause_dump (v->warn));
5226 if (uentry_hasStateClauseList (v))
5228 xdump = message ("%q@S:%q", xdump, stateClauseList_dump (v->info->fcn->specclauses));
5231 return (message ("%q%q%q%q@%q%q#%s",
5232 ctype_dump (v->utype),
5236 typeIdSet_dump (uentry_accessType (v)),
5241 return (message ("%q@%q#%s",
5242 ctype_dump (v->utype),
5243 typeIdSet_dump (v->info->iter->access),
5246 return (message ("%q@%q#%s",
5247 ctype_dump (v->utype),
5248 typeIdSet_dump (uentry_accessType (v)),
5255 if (multiVal_isUnknown (uentry_getConstantValue (v))
5256 && typeIdSet_isEmpty (uentry_accessType (v))
5257 && (sRef_getNullState (v->sref) == NS_UNKNOWN))
5259 sdump = cstring_makeLiteral ("$");
5263 sdump = message ("@%q@%q@%d",
5264 multiVal_dump (uentry_getConstantValue (v)),
5265 typeIdSet_dump (uentry_accessType (v)),
5266 (int) sRef_getNullState (v->sref));
5269 return (message ("%q%q#%s",
5270 ctype_dump (v->utype),
5277 return (message ("%q@%q#%s",
5278 ctype_dump (v->utype),
5279 ctype_dump (v->info->datatype->type), v->uname));
5286 uentry_unparseAbbrev (uentry v)
5288 if (!uentry_isVariable (v))
5290 llcontbuglit ("uentry_unparseAbbrev: not variable");
5291 return uentry_unparse (v);
5294 return (message ("%s %q", ctype_unparseDeep (v->utype), uentry_getName (v)));
5298 uentry_unparse (uentry v)
5302 if (uentry_isUndefined (v)) return (cstring_makeLiteral ("<undefined>"));
5303 if (uentry_isElipsisMarker (v)) return (cstring_makeLiteral ("..."));
5305 st = uentry_getName (v);
5307 if (cstring_isDefined (st))
5309 return (ctype_unparseDeclaration (v->utype, st));
5314 return (cstring_copy (ctype_unparse (v->utype)));
5319 uentry_unparseFull (uentry v)
5321 if (uentry_isUndefined (v))
5323 return (cstring_makeLiteral ("<undefined>"));
5329 res = message ("[%w] %s %s: %s [spec: %q; decl: %q; def: %q]",
5330 (unsigned long) v, ekind_unparse (v->ukind), v->uname,
5331 ctype_unparse (v->utype),
5332 fileloc_unparse (uentry_whereSpecified (v)),
5333 fileloc_unparse (uentry_whereDeclared (v)),
5334 fileloc_unparse (uentry_whereDefined (v)));
5336 DPRINTF (("uentry: %s", res));
5338 if (uentry_isDatatype (v))
5340 res = message ("%q / type: %s mut: %s abs: %s state: %q",
5343 (ctype_isDefined (v->info->datatype->type)
5344 ? v->info->datatype->type : ctype_unknown),
5345 ynm_unparse (v->info->datatype->mut),
5346 ynm_unparse (v->info->datatype->abs),
5347 sRef_unparseState (v->sref));
5349 else if (uentry_isFunction (v))
5351 res = message ("%q / sref: %q / mods: %q / "
5352 "globs: %q / clauses: %q / pre: %q / post: %q",
5354 sRef_unparseFull (v->sref),
5355 sRefSet_unparse (v->info->fcn->mods),
5356 globSet_unparse (v->info->fcn->globs),
5357 stateClauseList_unparse (v->info->fcn->specclauses),
5358 functionConstraint_unparse (v->info->fcn->preconditions),
5359 functionConstraint_unparse (v->info->fcn->postconditions));
5361 else if (uentry_isIter (v))
5363 res = message ("%q / sref: %q",
5365 sRef_unparseFull (v->sref));
5367 else if (uentry_isVariable (v))
5369 res = message ("%q / sref: %q / kind <%d> isout <%d> null <%d> used <%d>",
5371 sRef_unparseFull (v->sref),
5372 (int) v->info->var->kind,
5373 (int) v->info->var->defstate,
5374 (int) v->info->var->nullstate,
5376 DPRINTF (("sref: [%p]", v->sref));
5377 DPRINTF (("sref: %s", sRef_unparseDebug (v->sref)));
5378 /* DPRINTF (("sref: %s", sRef_unparseDeep (v->sref))); */
5380 else if (uentry_isConstant (v))
5382 res = message ("%q = %q / %q",
5383 res, multiVal_unparse (uentry_getConstantValue (v)),
5384 sRef_unparseFull (v->sref));
5388 res = message ("%q :: %q", res, uentry_unparse (v));
5395 bool uentry_hasAccessType (uentry e)
5397 if (uentry_isValid (e))
5402 return (!typeIdSet_isEmpty (e->info->iter->access));
5404 return (!typeIdSet_isEmpty (e->info->enditer->access));
5406 return (!typeIdSet_isEmpty (e->info->fcn->access));
5409 return (!typeIdSet_isEmpty (e->info->uconst->access));
5418 typeIdSet uentry_accessType (uentry e)
5420 if (uentry_isValid (e))
5425 return (e->info->iter->access);
5427 return (e->info->enditer->access);
5429 return (e->info->fcn->access);
5432 return (e->info->uconst->access);
5438 return typeIdSet_undefined;
5442 uentry_isVariable (uentry e)
5444 return (uentry_isVar (e));
5448 uentry_isSpecified (uentry e)
5450 return (uentry_isValid (e) && !fileloc_isUndefined (e->whereSpecified));
5454 uentry_isReallySpecified (uentry e)
5456 return (uentry_isValid (e)
5457 && fileloc_isRealSpec (e->whereSpecified));
5461 uentry_isVar (uentry e)
5463 return (!uentry_isUndefined (e) && e->ukind == KVAR);
5467 uentry_isFakeTag (uentry e)
5469 return (uentry_isValid (e) && strchr (cstring_toCharsSafe (e->uname), '!') != 0);
5473 uentry_isDatatype (uentry e)
5475 return (!uentry_isUndefined (e) &&
5476 (e->ukind == KDATATYPE || e->ukind == KSTRUCTTAG ||
5477 e->ukind == KUNIONTAG || e->ukind == KENUMTAG));
5481 uentry_setAbstract (uentry e)
5485 llassert (uentry_isDatatype (e)
5486 && (ynm_isMaybe (e->info->datatype->abs)));
5488 oldid = ctype_typeId (e->info->datatype->type);
5489 e->info->datatype->abs = YES;
5490 e->info->datatype->type = ctype_createAbstract (oldid);
5494 uentry_setConcrete (uentry e)
5496 llassert (uentry_isDatatype (e)
5497 && (ynm_isMaybe (e->info->datatype->abs)));
5499 e->info->datatype->abs = NO;
5503 uentry_isAbstractDatatype (uentry e)
5505 return (uentry_isDatatype (e)
5506 && (ynm_isOn (e->info->datatype->abs)));
5510 uentry_isMaybeAbstract (uentry e)
5512 return (uentry_isDatatype (e)
5513 && (ynm_isMaybe (e->info->datatype->abs)));
5517 uentry_isMutableDatatype (uentry e)
5519 bool res = uentry_isDatatype (e)
5520 && (ynm_toBoolRelaxed (e->info->datatype->mut));
5526 uentry_isRefCountedDatatype (uentry e)
5528 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
5532 uentry_isParam (uentry u)
5534 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
5535 || u->info->var->kind == VKYIELDPARAM));
5539 uentry_isExpandedMacro (uentry u)
5541 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
5545 uentry_isSefParam (uentry u)
5547 return (uentry_isVariable (u)
5548 && (u->info->var->kind == VKSEFPARAM
5549 || u->info->var->kind == VKREFSEFPARAM
5550 || u->info->var->kind == VKSEFRETPARAM
5551 || u->info->var->kind == VKREFSEFRETPARAM));
5555 uentry_isRefParam (uentry u)
5557 return (uentry_isVariable (u)
5558 && (u->info->var->kind == VKREFPARAM
5559 || u->info->var->kind == VKREFYIELDPARAM
5560 || u->info->var->kind == VKREFSEFPARAM
5561 || u->info->var->kind == VKREFSEFRETPARAM));
5565 uentry_isAnyParam (uentry u)
5567 return (uentry_isVariable (u)
5568 && ((u->info->var->kind == VKPARAM)
5569 || (u->info->var->kind == VKSEFPARAM)
5570 || (u->info->var->kind == VKYIELDPARAM)
5571 || (u->info->var->kind == VKRETPARAM)
5572 || (u->info->var->kind == VKSEFRETPARAM)));
5576 uentry_getDefState (uentry u)
5578 if (uentry_isValid (u))
5580 return (sRef_getDefState (u->sref));
5584 return (SS_UNKNOWN);
5589 uentry_isOut (uentry u)
5591 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5592 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5596 uentry_isPartial (uentry u)
5598 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5599 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5603 uentry_isStateSpecial (uentry u)
5605 return ((uentry_isVariable (u)
5606 && (u->info->var->defstate == SS_SPECIAL))
5607 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5610 exitkind uentry_getExitCode (uentry ue)
5612 if (uentry_isFunction (ue))
5614 return ue->info->fcn->exitCode;
5622 qual uentry_nullPred (uentry u)
5624 llassert (uentry_isRealFunction (u));
5626 if (uentry_isFunction (u))
5628 return (u->info->fcn->nullPred);
5632 return qual_createUnknown ();
5637 ** Note for variables, this is checking the declared state, not the current state.
5641 uentry_possiblyNull (uentry u)
5643 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5644 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5648 uentry_getAliasKind (uentry u)
5650 if (uentry_isValid (u))
5652 return (sRef_getAliasKind (uentry_getSref (u)));
5661 uentry_getExpKind (uentry u)
5663 if (uentry_isValid (u))
5665 return (sRef_getExKind (uentry_getSref (u)));
5674 uentry_isIter (uentry e)
5676 return (!uentry_isUndefined (e) && e->ukind == KITER);
5680 uentry_isEndIter (uentry e)
5682 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5686 uentry_isRealFunction (uentry e)
5688 return (uentry_isFunction (e) ||
5689 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5693 uentry_hasName (uentry e)
5695 if (uentry_isValid (e))
5697 cstring s = e->uname;
5699 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")
5700 || uentry_isFakeTag (e)));
5709 ** Returns true for fake tags.
5710 ** This is used for dumping the library
5713 bool uentry_hasRealName (uentry e)
5715 return (uentry_isValid (e)
5716 && cstring_isNonEmpty (e->uname)
5717 && !uentry_isGlobalMarker (e));
5721 /*@observer@*/ globSet
5722 uentry_getGlobs (uentry l)
5724 if (uentry_isInvalid (l))
5726 return globSet_undefined;
5729 if (uentry_isFunction (l))
5731 return l->info->fcn->globs;
5733 else if (uentry_isIter (l))
5735 return l->info->iter->globs;
5737 else if (uentry_isEndIter (l))
5739 return globSet_undefined;
5743 if (l->ukind == KVAR)
5745 llcontbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
5747 ekind_unparse (l->ukind)));
5751 llcontbug (message ("Bad call to uentry_getGlobs: %q (%s)",
5753 ekind_unparse (l->ukind)));
5756 return globSet_undefined;
5760 /*@observer@*/ sRefSet
5761 uentry_getMods (uentry l)
5763 llassert (uentry_isValid (l));
5765 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5767 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5768 return sRefSet_undefined;
5771 if (uentry_isFunction (l))
5773 return l->info->fcn->mods;
5775 else if (uentry_isIter (l))
5777 return l->info->iter->mods;
5779 else if (uentry_isEndIter (l))
5781 return sRefSet_undefined;
5790 uentry_getKind (uentry e)
5792 llassert (uentry_isValid (e));
5797 /*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5799 llassert (uentry_isEitherConstant (e));
5800 return (sRef_getValue (e->sref));
5803 /*@observer@*/ uentryList
5804 uentry_getParams (uentry l)
5806 if (uentry_isInvalid (l)) return uentryList_undefined;
5813 ctype ct = l->utype;
5815 if (ctype_isFunction (ct))
5817 return (ctype_argsFunction (ct));
5821 return uentryList_undefined;
5826 ctype ct = l->utype;
5828 llassert (ctype_isFunction (ct));
5829 return (ctype_argsFunction (ct));
5836 /*@observer@*/ cstring
5837 uentry_rawName (uentry e)
5839 if (uentry_isValid (e))
5845 return cstring_undefined;
5850 uentry_getOptName (uentry e)
5852 cstring s = uentry_getName (e);
5854 if (cstring_isDefined (s))
5856 s = cstring_appendChar (s, ' ');
5863 uentry_getName (uentry e)
5865 cstring ret = cstring_undefined;
5867 if (uentry_isValid (e))
5869 if (uentry_isAnyTag (e))
5871 ret = fixTagName (e->uname);
5873 else if (uentry_isAnyParam (e))
5875 ret = cstring_copy (fixParamName (e->uname));
5879 ret = cstring_copy (e->uname);
5886 cstring uentry_observeRealName (uentry e)
5888 cstring ret = cstring_undefined;
5890 if (uentry_isValid (e))
5892 if (uentry_isAnyTag (e))
5894 if (isFakeTag (e->uname))
5896 ret = cstring_undefined;
5900 ret = plainTagName (e->uname);
5903 else if (uentry_isAnyParam (e))
5905 ret = fixParamName (e->uname);
5916 cstring uentry_getRealName (uentry e)
5918 if (uentry_isValid (e))
5920 if (uentry_isAnyTag (e))
5922 return (cstring_undefined);
5929 return cstring_undefined;
5932 ctype uentry_getType (uentry e)
5934 if (uentry_isValid (e))
5940 return ctype_unknown;
5944 fileloc uentry_whereLast (uentry e)
5948 if (uentry_isInvalid (e))
5950 return fileloc_undefined;
5953 loc = e->whereDefined;
5955 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5960 loc = uentry_whereDeclared (e);
5962 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5967 loc = uentry_whereSpecified (e);
5971 fileloc uentry_whereEither (uentry e)
5973 if (uentry_isInvalid (e)) return fileloc_undefined;
5975 if (fileloc_isDefined (e->whereDefined)
5976 && !fileloc_isExternal (e->whereDefined))
5978 return e->whereDefined;
5980 else if (fileloc_isDefined (e->whereDeclared))
5982 return e->whereDeclared;
5986 return e->whereSpecified;
5990 fileloc uentry_whereSpecified (uentry e)
5992 if (uentry_isInvalid (e)) return fileloc_undefined;
5994 return (e->whereSpecified);
5997 fileloc uentry_whereDefined (uentry e)
5999 if (uentry_isInvalid (e)) return fileloc_undefined;
6001 return (e->whereDefined);
6004 fileloc uentry_whereDeclared (uentry e)
6006 if (uentry_isInvalid (e)) return fileloc_undefined;
6008 return (e->whereDeclared);
6011 /*@observer@*/ fileloc
6012 uentry_whereEarliest (uentry e)
6014 if (uentry_isInvalid (e)) return fileloc_undefined;
6016 if (fileloc_isDefined (e->whereSpecified))
6018 return (e->whereSpecified);
6020 else if (fileloc_isDefined (e->whereDeclared))
6022 return (e->whereDeclared);
6026 return e->whereDefined;
6031 uentry_setFunctionDefined (uentry e, fileloc loc)
6033 if (uentry_isValid (e))
6035 llassert (uentry_isFunction (e));
6037 if (fileloc_isUndefined (e->whereDeclared))
6039 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
6042 if (!fileloc_isDefined (e->whereDefined))
6044 e->whereDefined = fileloc_update (e->whereDefined, loc);
6050 uentry_setDeclDef (uentry e, fileloc f)
6052 uentry_setDeclared (e, f);
6054 if (!uentry_isFunction (e)
6055 && !(uentry_isVariable (e) && uentry_isExtern (e)))
6057 uentry_setDefined (e, f);
6062 uentry_setDeclaredForce (uentry e, fileloc f)
6064 llassert (uentry_isValid (e));
6065 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6069 uentry_setDeclaredForceOnly (uentry e, fileloc f)
6071 llassert (uentry_isValid (e));
6072 fileloc_free (e->whereDeclared);
6073 e->whereDeclared = f;
6077 uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
6081 llassert (uentry_isValid (e));
6082 oldloc = e->whereDeclared;
6084 if (fileloc_isDefined (oldloc))
6086 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6088 e->whereDeclared = f;
6089 fileloc_free (oldloc);
6098 e->whereDeclared = f;
6099 fileloc_free (oldloc);
6104 uentry_setDeclared (uentry e, fileloc f)
6108 llassert (uentry_isValid (e));
6109 oldloc = e->whereDeclared;
6111 if (fileloc_isDefined (oldloc))
6113 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6115 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6124 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6129 uentry_clearDefined (uentry e)
6131 if (uentry_isValid (e))
6133 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
6138 uentry_setDefined (uentry e, fileloc f)
6142 llassert (uentry_isValid (e));
6143 oldloc = e->whereDefined;
6145 if (fileloc_isDefined (oldloc))
6147 if (fileloc_isLib (oldloc)
6148 || fileloc_isImport (oldloc)
6149 || fileloc_isBuiltin (oldloc)
6150 || fileloc_isPreproc (oldloc))
6152 e->whereDefined = fileloc_update (e->whereDefined, f);
6156 if (fileloc_equal (oldloc, f) || context_processingMacros ())
6162 if (optgenerror (FLG_REDEF,
6163 message ("%s %q redefined",
6164 ekind_capName (e->ukind),
6165 uentry_getName (e)),
6168 llgenindentmsg (message ("Previous definition of %q",
6169 uentry_getName (e)),
6177 e->whereDefined = fileloc_update (e->whereDefined, f);
6182 uentry_isCodeDefined (uentry e)
6184 llassert (uentry_isValid (e));
6186 return (fileloc_isDefined (e->whereDefined));
6190 uentry_isDeclared (uentry e)
6192 if (uentry_isValid (e))
6194 return (fileloc_isDefined (e->whereDeclared));
6200 sRef uentry_getSref (uentry e)
6202 /* not true, used for functions too (but shouldn't be? */
6203 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
6205 if (uentry_isInvalid (e)) return sRef_undefined;
6210 sRef uentry_getOrigSref (uentry e)
6212 /*@i523*/ /* evans 2001-09-09 - need to fix this
6213 if (uentry_isValid (e))
6215 if (uentry_isVariable (e))
6217 return e->info->var->origsref;
6221 sRef sr = sRef_copy (uentry_getSref (e));
6223 sRef_resetState (sr);
6224 sRef_clearDerived (sr);
6230 return sRef_undefined;
6234 if (uentry_isValid (e))
6236 sRef sr = sRef_copy (uentry_getSref (e));
6238 sRef_resetState (sr);
6239 sRef_clearDerived (sr);
6241 if (uentry_isVariable (e))
6243 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
6244 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
6251 return sRef_undefined;
6256 ** requires: uentry e is not in a hashed symbol table
6260 uentry_setName (uentry e, /*@only@*/ cstring n)
6262 llassert (uentry_isValid (e));
6264 cstring_free (e->uname);
6269 uentry_setType (uentry e, ctype t)
6271 if (uentry_isValid (e))
6274 sRef_setType (e->sref, t);
6279 uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
6282 ctype rettype = ctype_unknown;
6284 llassert (uentry_isValid (ue));
6286 uentry_convertVarFunction (ue);
6287 llassert (uentry_isFunction (ue));
6289 rct = ctype_realType (ue->utype);
6291 if (ctype_isFunction (rct))
6293 rettype = ctype_getReturnType (rct);
6296 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
6300 uentry_setRefParam (uentry e)
6302 if (!uentry_isVar (e))
6304 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6308 if (e->info->var->kind == VKSEFPARAM)
6310 e->info->var->kind = VKREFSEFPARAM;
6312 else if (e->info->var->kind == VKSEFRETPARAM)
6314 e->info->var->kind = VKREFSEFRETPARAM;
6316 else if (e->info->var->kind == VKYIELDPARAM)
6318 e->info->var->kind = VKREFYIELDPARAM;
6322 e->info->var->kind = VKREFPARAM;
6328 uentry_setParam (uentry e)
6330 if (!uentry_isVar (e))
6332 if (uentry_isElipsisMarker (e))
6338 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6345 if (e->info->var->kind == VKYIELDPARAM
6346 || e->info->var->kind == VKSEFPARAM
6347 || e->info->var->kind == VKSEFRETPARAM)
6353 e->info->var->kind = VKPARAM;
6357 e->uname = makeParam (e->uname);
6358 cstring_free (oldname);
6363 uentry_setSref (uentry e, sRef s)
6365 if (uentry_isValid (e))
6367 if (sRef_isValid (e->sref))
6369 sRef_mergeStateQuietReverse (e->sref, s);
6373 e->sref = sRef_saveCopy (s);
6379 uentry_getAbstractType (uentry e)
6381 llassert (uentry_isDatatype (e));
6384 ** This assertion removed.
6385 ** Okay to have undefined type, for system types
6387 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
6388 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
6393 if (ctype_isUndefined (e->info->datatype->type))
6395 return ctype_unknown;
6399 ** Sadly, a kludge...
6402 if (ctype_isUserBool (e->info->datatype->type)) {
6406 return e->info->datatype->type;
6409 ctype uentry_getRealType (uentry e)
6412 typeId uid = USYMIDINVALID;
6414 if (uentry_isInvalid (e))
6416 return ctype_unknown;
6419 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6421 if (uentry_isAnyTag (e))
6426 if (uentry_isAbstractType (e))
6428 ct = uentry_getAbstractType (e);
6430 if (ctype_isManifestBool (ct)) {
6434 llassert (ctype_isUA (ct));
6436 uid = ctype_typeId (ct);
6438 if (!context_hasAccess (uid))
6444 ct = uentry_getType (e);
6446 /* if (ctype_isUserBool (ct)) return ct; */
6448 if (ctype_isManifestBool (ct)) {
6452 if (ctype_isUA (ct))
6454 usymId iid = ctype_typeId (ct);
6456 if (usymId_equal (iid, uid))
6458 llcontbug (message ("uentry_getRealType: recursive type! %s",
6459 ctype_unparse (ct)));
6464 /* evs 2000-07-25: possible infinite recursion ? */
6465 uentry ue2 = usymtab_getTypeEntry (iid);
6469 llcontbug (message ("Bad recursion: %q", uentry_unparseFull (e)));
6470 return ctype_unknown;
6473 return uentry_getRealType (ue2);
6482 ctype uentry_getForceRealType (uentry e)
6485 typeId uid = USYMIDINVALID;
6487 if (uentry_isInvalid (e))
6489 return ctype_unknown;
6492 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6494 if (uentry_isAnyTag (e))
6499 if (uentry_isAbstractType (e))
6501 ct = uentry_getAbstractType (e);
6502 llassert (ctype_isUA (ct));
6504 uid = ctype_typeId (ct);
6505 /* no check for access! */
6508 ct = uentry_getType (e);
6510 /* evs 2000-07-25 */
6511 /* if (ctype_isUserBool (ct)) return ct; */
6513 if (ctype_isManifestBool (ct)) {
6517 if (ctype_isUA (ct))
6519 usymId iid = ctype_typeId (ct);
6521 if (usymId_equal (iid, uid))
6523 llcontbug (message ("uentry_getRealType: recursive type! %s",
6524 ctype_unparse (ct)));
6529 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
6538 uentry uentry_nameCopy (cstring name, uentry e)
6540 uentry enew = uentry_alloc ();
6542 llassert (uentry_isValid (e));
6544 /* enew->shallowCopy = FALSE; */
6545 enew->ukind = e->ukind;
6547 enew->utype = e->utype;
6548 enew->whereSpecified = fileloc_copy (e->whereSpecified);
6549 enew->whereDefined = fileloc_copy (e->whereDefined);
6550 enew->whereDeclared = fileloc_copy (e->whereDeclared);
6551 enew->sref = sRef_copy (e->sref);
6552 enew->used = e->used;
6554 enew->isPrivate = e->isPrivate;
6555 enew->hasNameError = FALSE;
6557 enew->uses = filelocList_new ();
6558 enew->warn = warnClause_undefined;
6560 enew->storageclass = e->storageclass;
6561 enew->info = uinfo_copy (e->info, e->ukind);
6567 uentry_setDatatype (uentry e, usymId uid)
6569 llassert (uentry_isDatatype (e));
6571 if (uentry_isAbstractType (e))
6573 e->info->datatype->type = ctype_createAbstract (uid);
6577 e->info->datatype->type = ctype_createUser (uid);
6582 uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
6583 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
6586 llassert (uentry_isValid (e));
6588 if (fileloc_isSpec (f) || fileloc_isImport (f))
6590 e->whereSpecified = f;
6591 e->whereDeclared = fileloc_undefined;
6592 e->whereDefined = fileloc_undefined;
6596 e->whereSpecified = fileloc_undefined;
6597 e->whereDeclared = f;
6598 e->whereDefined = fileloc_undefined;
6601 llassert (fileloc_storable (f));
6605 ucinfo_free (/*@only@*/ ucinfo u)
6611 uvinfo_free (/*@only@*/ uvinfo u)
6613 /*drl7x added 6/29/01 */
6614 free (u->bufinfo); /* evans - 2001-07-19 fixed this bug */
6619 udinfo_free (/*@only@*/ udinfo u)
6625 ufinfo_free (/*@only@*/ ufinfo u)
6627 globSet_free (u->globs);
6628 sRefSet_free (u->mods);
6629 stateClauseList_free (u->specclauses);
6634 uiinfo_free (/*@only@*/ uiinfo u)
6640 ueinfo_free (/*@only@*/ ueinfo u)
6645 static /*@only@*/ ucinfo
6646 ucinfo_copy (ucinfo u)
6648 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
6649 ret->access = u->access;
6650 ret->macro = u->macro;
6654 static /*@only@*/ uvinfo
6655 uvinfo_copy (uvinfo u)
6657 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
6659 ret->kind = u->kind;
6660 ret->nullstate = u->nullstate;
6661 ret->defstate = u->defstate;
6662 ret->checked = u->checked;
6664 /*@i523 ret->origsref = sRef_copy (u->origsref); */
6666 /* drl added 07-02-001 */
6667 /* copy null terminated information */
6669 if (u->bufinfo != NULL)
6671 ret->bufinfo = (bbufinfo) dmalloc (sizeof( * u->bufinfo ) );
6672 ret->bufinfo->bufstate = u->bufinfo->bufstate;
6673 ret->bufinfo->size = u->bufinfo->size;
6674 ret->bufinfo->len = u->bufinfo->len;
6679 ret->bufinfo = NULL;
6685 static /*@only@*/ udinfo
6686 udinfo_copy (udinfo u)
6688 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6692 ret->type = u->type;
6697 static /*@only@*/ ufinfo
6698 ufinfo_copy (ufinfo u)
6700 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6702 ret->hasGlobs = u->hasGlobs;
6703 ret->hasMods = u->hasMods;
6704 ret->exitCode = u->exitCode;
6705 ret->specialCode = u->specialCode;
6706 ret->nullPred = u->nullPred;
6707 ret->access = u->access;
6708 ret->globs = globSet_newCopy (u->globs);
6709 ret->mods = sRefSet_newCopy (u->mods);
6710 ret->defparams = u->defparams;
6711 ret->specclauses = stateClauseList_copy (u->specclauses);
6713 ret->preconditions = functionConstraint_copy (u->preconditions);
6714 ret->postconditions = functionConstraint_copy (u->postconditions);
6719 static /*@only@*/ uiinfo
6720 uiinfo_copy (uiinfo u)
6722 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6724 ret->access = u->access;
6725 ret->globs = globSet_newCopy (u->globs);
6726 ret->mods = sRefSet_newCopy (u->mods);
6731 static /*@only@*/ ueinfo
6732 ueinfo_copy (ueinfo u)
6734 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6736 ret->access = u->access;
6741 uinfo_free (uinfo u, ekind kind)
6746 case KCONST: ucinfo_free (u->uconst); break;
6747 case KVAR: uvinfo_free (u->var); break;
6751 case KDATATYPE: udinfo_free (u->datatype); break;
6752 case KFCN: ufinfo_free (u->fcn); break;
6753 case KITER: uiinfo_free (u->iter); break;
6754 case KENDITER: ueinfo_free (u->enditer); break;
6755 case KELIPSMARKER: break;
6756 case KINVALID: break;
6762 static /*@only@*/ /*@null@*/ uinfo
6763 uinfo_copy (uinfo u, ekind kind)
6765 if (kind == KELIPSMARKER || kind == KINVALID)
6771 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6776 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6777 case KVAR: ret->var = uvinfo_copy (u->var); break;
6781 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6782 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6783 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6784 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6792 uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6794 filelocList_free (e->uses);
6795 cstring_free (e->uname);
6797 uinfo_free (e->info, e->ukind);
6799 fileloc_free (e->whereSpecified);
6800 fileloc_free (e->whereDefined);
6801 fileloc_free (e->whereDeclared);
6803 warnClause_free (e->warn);
6809 extern void uentry_markOwned (/*@owned@*/ uentry u)
6811 sfreeEventually (u);
6815 uentry_free (/*@only@*/ uentry e)
6817 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6819 uentry_reallyFree (e);
6824 ** For uentry's in the global or file scope
6828 uentry_freeComplete (/*@only@*/ uentry e)
6830 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6832 DPRINTF (("Free complete: %s", sRef_unparseFull (e->sref)));
6833 /*@i@*/ sRef_free (e->sref);
6834 e->sref = sRef_undefined;
6835 uentry_reallyFree (e);
6840 ** requires old->kind != new->kind, old->uname = new->uname
6844 KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6846 llassert (uentry_isValid (old));
6847 llassert (uentry_isValid (unew));
6849 if ((uentry_isEitherConstant (unew) || uentry_isDatatype (unew))
6850 && (fileloc_isPreproc (uentry_whereDeclared (old))
6851 || ctype_isUnknown (old->utype))
6852 && !uentry_isSpecified (old))
6860 if (!uentry_isDeclared (old))
6862 if (uentry_isSpecified (old))
6864 if (uentry_isSpecified (unew))
6866 llbuglit ("Respecification!");
6868 else if (uentry_isDeclared (unew))
6872 message ("%s %q inconsistently declared as %s: %t",
6873 ekind_capName (old->ukind),
6874 uentry_getName (unew),
6875 ekind_unparseLong (unew->ukind),
6877 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6879 uentry_showWhereLastKind (old);
6891 message ("%s %q inconsistently declared as %s: %t",
6892 ekind_capName (old->ukind),
6893 uentry_getName (unew),
6894 ekind_unparseLong (unew->ukind),
6896 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6898 uentry_showWhereLastKind (old);
6904 llassert (uentry_isDeclared (unew));
6906 DPRINTF (("Old: \n\t%s", uentry_unparseFull (old)));
6907 DPRINTF (("New: \n\t%s", uentry_unparseFull (unew)));
6911 message ("%s %q inconsistently redeclared as %s",
6912 ekind_capName (old->ukind),
6913 uentry_getName (unew),
6914 ekind_unparseLong (unew->ukind)),
6915 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6917 uentry_showWhereLastKind (old);
6923 uentry_updateInto (old, unew);
6927 ** def is the definition of spec, modifies spec
6929 ** reports any inconsistencies
6930 ** returns the summary of all available information
6931 ** if spec and def are inconsistent, def is returned
6935 uentry_showWhereLast (uentry spec)
6937 if (uentry_isValid (spec))
6939 if (fileloc_isDefined (spec->whereDefined)
6940 && !fileloc_isLib (spec->whereDefined)
6941 /*!! && !fileloc_isPreproc (spec->whereDefined) */ )
6943 llgenindentmsg (message ("Previous definition of %q: %t",
6944 uentry_getName (spec),
6945 uentry_getType (spec)),
6946 uentry_whereDefined (spec));
6948 else if (uentry_isDeclared (spec))
6950 llgenindentmsg (message ("Previous declaration of %q: %t",
6951 uentry_getName (spec),
6952 uentry_getType (spec)),
6953 uentry_whereDeclared (spec));
6955 else if (uentry_isSpecified (spec))
6957 if (uentry_hasName (spec))
6959 llgenindentmsg (message ("Specification of %q: %t",
6960 uentry_getName (spec),
6961 uentry_getType (spec)),
6962 uentry_whereSpecified (spec));
6966 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
6967 uentry_whereSpecified (spec));
6972 /* nothing to show */
6978 uentry_showWhereLastKind (uentry spec)
6980 if (uentry_isValid (spec))
6982 if (fileloc_isDefined (spec->whereDefined)
6983 && !fileloc_isLib (spec->whereDefined)
6984 /*!! && !fileloc_isPreproc (spec->whereDefined) */ )
6986 llgenindentmsg (message ("Previous definition of %q as %s: %t",
6987 uentry_getName (spec),
6988 ekind_unparseLong (spec->ukind),
6989 uentry_getType (spec)),
6990 uentry_whereDefined (spec));
6992 else if (uentry_isDeclared (spec))
6994 llgenindentmsg (message ("Previous declaration of %q as %s: %t",
6995 uentry_getName (spec),
6996 ekind_unparseLong (spec->ukind),
6997 uentry_getType (spec)),
6998 uentry_whereDeclared (spec));
7000 else if (uentry_isSpecified (spec))
7002 if (uentry_hasName (spec))
7004 llgenindentmsg (message ("Specification of %q as %s: %t",
7005 uentry_getName (spec),
7006 ekind_unparseLong (spec->ukind),
7007 uentry_getType (spec)),
7008 uentry_whereSpecified (spec));
7012 llgenindentmsg (message ("Specification as %s: %t",
7013 ekind_unparseLong (spec->ukind),
7014 uentry_getType (spec)),
7015 uentry_whereSpecified (spec));
7020 /* nothing to show */
7026 uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
7028 fileloc loc = uentry_whereDefined (ce);
7030 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
7032 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
7036 loc = uentry_whereSpecified (ce);
7038 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
7040 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
7045 void uentry_showWhereLastExtra (uentry spec, cstring extra)
7047 if (uentry_isDeclared (spec))
7049 llgenindentmsg (message ("Previous declaration of %q: %q",
7050 uentry_getName (spec), extra),
7051 uentry_whereDeclared (spec));
7053 else if (uentry_isSpecified (spec))
7055 llgenindentmsg (message ("Specification of %q: %q",
7056 uentry_getName (spec), extra),
7057 uentry_whereSpecified (spec));
7061 cstring_free (extra);
7066 uentry_showWhereDeclared (uentry spec)
7068 if (uentry_isDeclared (spec))
7070 if (uentry_hasName (spec))
7072 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7073 uentry_whereDeclared (spec));
7077 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
7080 else if (uentry_isSpecified (spec))
7082 if (uentry_hasName (spec))
7084 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7085 uentry_whereSpecified (spec));
7089 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
7094 /* nothing to show */
7100 uentry_showWhereAny (uentry spec)
7102 if (uentry_isDeclared (spec))
7104 if (uentry_hasName (spec))
7106 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7107 uentry_whereDeclared (spec));
7111 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
7114 else if (uentry_isSpecified (spec))
7116 if (uentry_hasName (spec))
7118 llgenindentmsg (message ("Specification of %q",
7119 uentry_getName (spec)),
7120 uentry_whereSpecified (spec));
7124 llgenindentmsg (cstring_makeLiteral ("Specification"),
7125 uentry_whereSpecified (spec));
7128 else if (fileloc_isDefined (uentry_whereDefined (spec)))
7130 if (uentry_hasName (spec))
7132 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
7133 uentry_whereDefined (spec));
7137 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
7142 /* nothing to show */
7147 uentry_showWhereDefined (uentry spec)
7149 if (uentry_isCodeDefined (spec))
7151 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
7152 uentry_whereDefined (spec));
7157 uentry_showWhereLastPlain (uentry spec)
7159 if (uentry_isDeclared (spec))
7161 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
7162 uentry_whereDeclared (spec));
7164 else if (uentry_isSpecified (spec))
7166 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7167 uentry_whereSpecified (spec));
7175 uentry_showWhereLastVal (uentry spec, cstring val)
7177 if (uentry_isDeclared (spec))
7179 llgenindentmsg (message ("Previous declaration of %q: %s",
7180 uentry_getName (spec), val),
7181 uentry_whereDeclared (spec));
7183 else if (uentry_isSpecified (spec))
7185 llgenindentmsg (message ("Specification of %q: %s",
7186 uentry_getName (spec), val),
7187 uentry_whereSpecified (spec));
7195 uentry_showWhereSpecified (uentry spec)
7197 if (uentry_isSpecified (spec))
7199 if (uentry_hasName (spec))
7201 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7202 uentry_whereSpecified (spec));
7206 llgenindentmsg (cstring_makeLiteral ("Specification"),
7207 uentry_whereSpecified (spec));
7210 else if (uentry_isDeclared (spec))
7212 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7213 uentry_whereDeclared (spec));
7217 /* nothing to show */
7222 uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
7224 if (uentry_isSpecified (spec))
7226 if (uentry_hasName (spec))
7228 llgenindentmsg (message ("Specification of %q: %q",
7229 uentry_getName (spec), s),
7230 uentry_whereSpecified (spec));
7234 llgenindentmsg (message ("Specification: %q", s),
7235 uentry_whereSpecified (spec));
7238 else if (uentry_isDeclared (spec))
7240 llgenindentmsg (message ("Declaration of %q: %q",
7241 uentry_getName (spec), s),
7242 uentry_whereDeclared (spec));
7246 llgenindentmsg (message ("Previous: %q", s),
7247 uentry_whereLast (spec));
7256 checkStructConformance (uentry old, uentry unew)
7259 uentryList fold, fnew;
7262 ** requires: types of old and new are structs or unions
7265 llassert (uentry_isValid (old));
7266 llassert (uentry_isValid (unew));
7268 oldr = ctype_realType (old->utype);
7269 fold = ctype_getFields (oldr);
7271 newr = ctype_realType (unew->utype);
7272 fnew = ctype_getFields (newr);
7274 if (!uentryList_matchFields (fold, fnew))
7276 if (fileloc_equal (uentry_whereLast (old),
7277 uentry_whereLast (unew)))
7285 message ("%q %q %rdeclared with fields { %q }, %s "
7286 "with fields { %q }",
7287 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
7288 uentry_getName (old),
7289 uentry_isDeclared (old),
7290 uentryList_unparseAbbrev (fnew),
7291 uentry_specOrDefName (old),
7292 uentryList_unparseAbbrev (fold)),
7293 uentry_whereDeclared (unew)))
7295 uentry_showWhereLastPlain (old);
7296 uentryList_showFieldDifference (fold, fnew);
7300 old->utype = unew->utype;
7305 checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7308 ** requires old and new are enums
7311 ctype rold = ctype_realType (old->utype);
7312 ctype rnew = ctype_realType (unew->utype);
7313 enumNameList eold = ctype_elist (rold);
7314 enumNameList enew = ctype_elist (rnew);
7316 if (!enumNameList_match (eold, enew))
7320 message ("Enum %q declared with members { %q } but "
7321 "%s with members { %q }",
7322 uentry_getName (old),
7323 enumNameList_unparse (enew),
7324 uentry_specOrDefName (old),
7325 enumNameList_unparse (eold)),
7326 uentry_whereDeclared (unew)))
7328 uentry_showWhereSpecified (old);
7329 old->utype = unew->utype;
7335 ** either oldCurrent or newCurrent may be undefined!
7339 paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
7340 uentry unew, uentry newCurrent, ctype newType,
7343 bool hasError = FALSE;
7345 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
7347 if (uentry_hasName (newCurrent))
7349 hasError = optgenerror
7351 message ("Parameter %d, %q, of function %q has inconsistent type: "
7352 "declared %t, %s %t",
7353 paramno + 1, uentry_getName (newCurrent),
7354 uentry_getName (unew),
7355 newType, uentry_specOrDefName (old), oldType),
7356 uentry_whereDeclared (newCurrent));
7360 hasError = optgenerror
7362 message ("Parameter %d of function %q has inconsistent type: "
7363 "declared %t, %s %t",
7364 paramno + 1, uentry_getName (unew),
7365 newType, uentry_specOrDefName (old), oldType),
7366 uentry_whereDeclared (newCurrent));
7368 DPRINTF (("type: %s / %s",
7369 ctype_unparse (newType),
7370 ctype_unparse (ctype_realType (newType))));
7375 if (uentry_isDeclared (unew))
7377 hasError = optgenerror
7379 message ("Parameter %d of function %s has inconsistent type: "
7380 "declared %t, %s %t",
7381 paramno + 1, unew->uname,
7382 newType, uentry_specOrDefName (old), oldType),
7383 uentry_whereDeclared (unew));
7387 hasError = optgenerror
7389 message ("Parameter %d of function %s has inconsistent type: "
7390 "declared %t, %s %t",
7391 paramno + 1, unew->uname,
7392 newType, uentry_specOrDefName (old), oldType),
7393 uentry_whereDeclared (unew));
7399 DPRINTF (("Here: %s / %s",
7400 uentry_unparseFull (oldCurrent),
7401 uentry_unparseFull (newCurrent)));
7403 if (!uentry_isUndefined (oldCurrent))
7405 if (!uentry_isUndefined (newCurrent)
7406 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
7408 uentry_showWhereLast (oldCurrent);
7412 uentry_showWhereLastPlain (old);
7415 uentry_setType (oldCurrent, newType);
7419 uentry_showWhereLastPlain (old);
7425 nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7429 message ("Function %s %rdeclared with %d arg%&, %s with %d",
7431 uentry_isDeclared (old),
7432 uentryList_size (uentry_getParams (unew)),
7433 uentry_specOrDefName (old),
7434 uentryList_size (uentry_getParams (old))),
7435 uentry_whereDeclared (unew)))
7437 uentry_showWhereLastPlain (old);
7442 returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7446 message ("Function %s inconsistently %rdeclared to return %t",
7448 uentry_isDeclared (old),
7449 ctype_getReturnType (unew->utype)),
7450 uentry_whereDeclared (unew)))
7452 uentry_showWhereLastVal (old, ctype_unparse (ctype_getReturnType (old->utype)));
7456 static cstring paramStorageName (uentry ue)
7458 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
7461 static cstring fcnErrName (uentry ue)
7463 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
7466 extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
7468 if (uentry_isVar (ue))
7470 return (checkedName (ue->info->var->checked));
7474 return (cstring_makeLiteralTemp ("<checked invalid>"));
7478 static cstring checkedName (chkind checked)
7482 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
7483 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
7484 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
7485 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
7486 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
7492 void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
7497 if (uentry_isVar (unew))
7499 llassert (uentry_isVar (old));
7501 oldState = old->info->var->nullstate;
7502 newState = unew->info->var->nullstate;
7506 oldState = sRef_getNullState (old->sref);
7507 newState = sRef_getNullState (unew->sref);
7510 if (oldState == NS_ABSNULL)
7512 if (uentry_isVar (old))
7514 old->info->var->nullstate = newState;
7517 sRef_mergeNullState (old->sref, newState);
7519 else if (newState == NS_UNKNOWN)
7521 if (completeConform && newState != oldState
7522 && uentry_isReallySpecified (old))
7526 message ("%s %q specified as %s, but declared without %s qualifier",
7527 ekind_capName (unew->ukind),
7528 uentry_getName (unew),
7529 nstate_unparse (oldState),
7530 nstate_unparse (oldState)),
7531 uentry_whereDeclared (unew)))
7533 uentry_showWhereSpecified (old);
7537 if (uentry_isVar (unew))
7539 unew->info->var->nullstate = oldState;
7542 sRef_mergeNullState (unew->sref, oldState);
7544 else if (newState == NS_POSNULL)
7546 if (oldState == NS_MNOTNULL
7547 && (ctype_isUA (unew->utype)
7548 || (uentry_isFunction (unew)
7549 && ctype_isUA (ctype_getReturnType (unew->utype)))))
7551 if (uentry_isVar (unew))
7553 unew->info->var->nullstate = oldState;
7556 sRef_mergeNullState (unew->sref, oldState);
7560 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
7561 || oldState == NS_UNKNOWN)
7568 ("%s %q inconsistently %rdeclared %s possibly null storage, "
7570 uentry_ekindName (unew),
7571 uentry_getName (unew),
7572 uentry_isDeclared (old),
7574 uentry_specOrDefName (old),
7575 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
7576 uentry_whereDeclared (unew)))
7578 uentry_showWhereSpecified (old);
7583 if (uentry_isVar (old))
7585 old->info->var->nullstate = newState;
7588 sRef_mergeNullState (old->sref, newState);
7591 else if (newState == NS_MNOTNULL)
7593 if (oldState != NS_MNOTNULL)
7599 message ("%s %q inconsistently %rdeclared %s notnull storage, "
7600 "%s without notnull qualifier",
7601 uentry_ekindName (unew),
7602 uentry_getName (unew),
7603 uentry_isDeclared (old),
7605 uentry_specOrDefName (old)),
7606 uentry_whereDeclared (unew)))
7608 uentry_showWhereSpecified (old);
7612 if (uentry_isVar (old))
7614 old->info->var->nullstate = newState;
7617 sRef_mergeNullState (old->sref, newState);
7622 if (uentry_isVar (unew))
7624 unew->info->var->nullstate = oldState;
7627 sRef_mergeNullState (unew->sref, oldState);
7632 void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7633 bool mustConform, bool completeConform)
7639 if (uentry_isVar (old) && uentry_isVar (unew))
7641 oldState = old->info->var->defstate;
7642 newState = unew->info->var->defstate;
7647 oldState = sRef_getDefState (old->sref);
7648 newState = sRef_getDefState (unew->sref);
7651 if (newState != oldState
7652 && newState != SS_UNKNOWN
7653 && newState != SS_DEFINED)
7659 message ("%s %q inconsistently %rdeclared %s %s %s, "
7661 uentry_ekindName (unew),
7662 uentry_getName (unew),
7663 uentry_isDeclared (old),
7665 sstate_unparse (newState),
7666 paramStorageName (unew),
7667 uentry_specOrDefName (old),
7669 sstate_unparse (oldState),
7670 paramStorageName (unew)),
7671 uentry_whereDeclared (unew)))
7673 uentry_showWhereSpecified (old);
7677 if (vars) old->info->var->defstate = newState;
7678 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
7683 && (newState != oldState) && (oldState != SS_DEFINED)
7684 && uentry_isReallySpecified (old))
7688 message ("%s %q specified as %s, but declared without %s qualifier",
7689 ekind_capName (unew->ukind),
7690 uentry_getName (unew),
7691 sstate_unparse (oldState),
7692 sstate_unparse (oldState)),
7693 uentry_whereDeclared (unew)))
7695 uentry_showWhereSpecified (old);
7699 if (vars) unew->info->var->defstate = oldState;
7700 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
7705 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7706 bool mustConform, bool completeConform)
7711 oldKind = sRef_getAliasKind (old->sref);
7712 newKind = sRef_getAliasKind (unew->sref);
7714 if (alkind_isImplicit (newKind)
7715 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
7717 if (completeConform && !alkind_equal (newKind, oldKind)
7718 && uentry_isReallySpecified (old))
7722 message ("%s %q specified as %s, but declared without "
7723 "explicit alias qualifier",
7724 ekind_capName (unew->ukind),
7725 uentry_getName (unew),
7726 alkind_unparse (oldKind)),
7727 uentry_whereDeclared (unew)))
7729 uentry_showWhereSpecified (old);
7734 ** This really shouldn't be necessary, but it is!
7735 ** Function params (?) use new here.
7738 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7742 if (alkind_isKnown (newKind))
7744 if (!alkind_equal (oldKind, newKind))
7746 if (alkind_isKnown (oldKind))
7751 message ("%s %q inconsistently %rdeclared %s %s storage, "
7753 uentry_ekindName (unew),
7754 uentry_getName (unew),
7755 uentry_isDeclared (old),
7757 alkind_unparse (newKind),
7758 uentry_specOrDefName (old),
7759 alkind_unparse (oldKind)),
7760 uentry_whereDeclared (unew)))
7762 uentry_showWhereSpecified (old);
7764 DPRINTF (("Old: %s", sRef_unparseFull (old->sref)));
7765 DPRINTF (("New: %s", sRef_unparseFull (unew->sref)));
7766 sRef_setAliasKind (old->sref, AK_ERROR,
7767 uentry_whereDeclared (unew));
7771 sRef_setAliasKind (old->sref, newKind,
7772 uentry_whereDeclared (unew));
7777 if (!(alkind_isImplicit (newKind)))
7780 !uentry_isFunction (unew) &&
7783 message ("%s %q inconsistently %rdeclared %s %s storage, "
7784 "implicitly %s as temp storage",
7785 uentry_ekindName (unew),
7786 uentry_getName (unew),
7787 uentry_isDeclared (old),
7789 alkind_unparse (newKind),
7790 uentry_specOrDefName (old)),
7791 uentry_whereDeclared (unew)))
7793 uentry_showWhereSpecified (old);
7797 sRef_setAliasKind (old->sref, newKind,
7798 uentry_whereDeclared (unew));
7800 else /* newKind is temp or refcounted */
7807 else /* newKind unknown */
7814 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7815 bool mustConform, bool completeConform)
7820 oldKind = sRef_getExKind (old->sref);
7821 newKind = sRef_getExKind (unew->sref);
7823 if (exkind_isKnown (newKind))
7825 if (oldKind != newKind)
7827 if (exkind_isKnown (oldKind))
7832 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7833 uentry_ekindName (unew),
7834 uentry_getName (unew),
7835 uentry_isDeclared (old),
7837 exkind_unparse (newKind),
7838 uentry_specOrDefName (old),
7839 exkind_unparse (oldKind)),
7840 uentry_whereDeclared (unew)))
7842 uentry_showWhereSpecified (old);
7845 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7852 message ("%s %q inconsistently %rdeclared %s %s, "
7853 "implicitly %s without exposure qualifier",
7854 uentry_ekindName (unew),
7855 uentry_getName (unew),
7856 uentry_isDeclared (old),
7858 exkind_unparse (newKind),
7859 uentry_specOrDefName (old)),
7860 uentry_whereDeclared (unew)))
7862 uentry_showWhereSpecified (old);
7865 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7871 if (completeConform && exkind_isKnown (oldKind)
7872 && uentry_isReallySpecified (old))
7876 message ("%s %q specified as %s, but declared without "
7877 "exposure qualifier",
7878 ekind_capName (unew->ukind),
7879 uentry_getName (unew),
7880 exkind_unparse (oldKind)),
7881 uentry_whereDeclared (unew)))
7883 uentry_showWhereSpecified (old);
7887 /* yes, this is necessary! (if its a param) */
7888 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7893 checkMetaState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7894 bool mustConform, /*@unused@*/ bool completeConform)
7896 valueTable newvals = sRef_getValueTable (unew->sref);
7898 if (valueTable_isDefined (newvals))
7900 DPRINTF (("Check meta state: %s -> %s",
7901 uentry_unparseFull (old),
7902 uentry_unparseFull (unew)));
7904 DPRINTF (("Check meta state refs: %s -> %s",
7905 sRef_unparseFull (old->sref),
7906 sRef_unparseFull (unew->sref)));
7908 DPRINTF (("Value table: %s", valueTable_unparse (newvals)));
7911 ** Copy the new values into the old ref
7914 valueTable_elements (newvals, key, newval)
7916 metaStateInfo msinfo = context_lookupMetaStateInfo (key);
7917 stateValue oldval = sRef_getMetaStateValue (old->sref, key);
7919 llassert (metaStateInfo_isDefined (msinfo));
7921 if (stateValue_isUndefined (oldval))
7923 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7927 if (stateValue_isError (oldval))
7929 if (!stateValue_isError (newval))
7931 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7935 ; /* No change necessary. */
7940 if (stateValue_getValue (newval) != stateValue_getValue (oldval))
7942 if (fileloc_isXHFile (uentry_whereDeclared (unew)))
7948 if (!stateValue_isError (newval)
7949 && !stateValue_isImplicit (newval))
7951 if (uentry_hasName (unew)
7952 || !sRef_isParam (uentry_getSref (unew)))
7957 message ("%s %q inconsistently %rdeclared %s %q, %s as %q",
7958 uentry_ekindName (unew),
7959 uentry_getName (unew),
7960 uentry_isDeclared (old),
7962 stateValue_unparseValue (newval, msinfo),
7963 uentry_specOrDefName (old),
7964 stateValue_unparseValue (oldval, msinfo)),
7965 uentry_whereDeclared (unew)))
7967 uentry_showWhereSpecified (old);
7975 message ("%s %d inconsistently %rdeclared %s %q, %s as %q",
7976 uentry_ekindName (unew),
7977 sRef_getParam (uentry_getSref (unew)),
7978 uentry_isDeclared (old),
7980 stateValue_unparseValue (newval, msinfo),
7981 uentry_specOrDefName (old),
7982 stateValue_unparseValue (oldval, msinfo)),
7983 uentry_whereDeclared (unew)))
7985 uentry_showWhereSpecified (old);
7991 DPRINTF (("Updating!"));
7992 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7996 DPRINTF (("Values match"));
8000 } end_valueTable_elements ;
8005 uentry_checkStateConformance (/*@notnull@*/ uentry old,
8006 /*@notnull@*/ uentry unew,
8007 bool mustConform, bool completeConform)
8009 checkDefState (old, unew, mustConform, completeConform);
8010 checkNullState (old, unew, mustConform, completeConform);
8011 checkAliasState (old, unew, mustConform, completeConform);
8012 checkExpState (old, unew, mustConform, completeConform);
8013 checkMetaState (old, unew, mustConform, completeConform);
8015 sRef_storeState (old->sref);
8016 sRef_storeState (unew->sref);
8020 checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
8022 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
8027 llassert (uentry_isVar (old));
8028 llassert (uentry_isVar (unew));
8030 if (cstring_isEmpty (old->uname))
8032 cstring_free (old->uname);
8033 old->uname = cstring_copy (unew->uname);
8036 if (unew->info->var->kind == VKRETPARAM
8037 || unew->info->var->kind == VKSEFRETPARAM)
8039 if (old->info->var->kind != VKRETPARAM
8040 && old->info->var->kind != VKSEFRETPARAM)
8044 message ("Parameter %q inconsistently %rdeclared as "
8045 "returned parameter",
8046 uentry_getName (unew),
8047 uentry_isDeclared (old)),
8048 uentry_whereDeclared (unew)))
8050 uentry_showWhereSpecified (old);
8051 old->info->var->kind = unew->info->var->kind;
8057 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
8059 if (old->info->var->kind != VKSEFPARAM
8060 && old->info->var->kind != VKSEFRETPARAM)
8064 message ("Parameter %qinconsistently %rdeclared as "
8066 uentry_getOptName (unew),
8067 uentry_isDeclared (old)),
8068 uentry_whereDeclared (unew)))
8070 uentry_showWhereSpecified (old);
8071 old->info->var->kind = unew->info->var->kind;
8076 if (old->info->var->kind == VKSPEC)
8078 old->info->var->kind = unew->info->var->kind;
8082 unew->info->var->kind = old->info->var->kind;
8085 if (unew->info->var->checked != CH_UNKNOWN
8086 && unew->info->var->checked != old->info->var->checked)
8088 if (old->info->var->checked == CH_UNKNOWN
8089 && !fileloc_isUser (uentry_whereLast (old)))
8097 message ("Variable %q inconsistently %rdeclared as "
8098 "%s parameter (was %s)",
8099 uentry_getName (unew),
8100 uentry_isDeclared (old),
8101 checkedName (unew->info->var->checked),
8102 checkedName (old->info->var->checked)),
8103 uentry_whereDeclared (unew)))
8105 uentry_showWhereSpecified (old);
8109 old->info->var->checked = unew->info->var->checked;
8114 && (old->info->var->checked != CH_UNKNOWN)
8115 && uentry_isReallySpecified (old))
8119 message ("%s %q specified as %s, but declared without %s qualifier",
8120 ekind_capName (unew->ukind),
8121 uentry_getName (unew),
8122 checkedName (old->info->var->checked),
8123 checkedName (old->info->var->checked)),
8124 uentry_whereDeclared (unew)))
8126 uentry_showWhereSpecified (old);
8130 unew->info->var->checked = old->info->var->checked;
8133 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8136 void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
8138 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
8143 llassert (uentry_isVar (u1));
8144 llassert (uentry_isVar (u2));
8146 if (u1->info->var->kind != u2->info->var->kind) {
8147 if (u1->info->var->kind == VKSEFRETPARAM) {
8148 if (u2->info->var->kind == VKRETPARAM) {
8151 message ("Function types are inconsistent. Parameter %d is "
8152 "sef parameter, but non-sef parameter in "
8153 "assigned function: %s",
8154 paramno, exprNode_unparse (e)),
8156 } else if (u2->info->var->kind == VKSEFPARAM) {
8159 message ("Function types are inconsistent. Parameter %d is "
8160 "returns parameter, but non-returns parameter in "
8161 "assigned function: %s",
8162 paramno, exprNode_unparse (e)),
8167 message ("Function types are inconsistent. Parameter %d is "
8168 "sef returns parameter, but non-sef returns parameter in "
8169 "assigned function: %s",
8170 paramno, exprNode_unparse (e)),
8173 } else if (u1->info->var->kind == VKRETPARAM) {
8176 message ("Function types are inconsistent. Parameter %d is "
8177 "returns parameter, but non-returns parameter in "
8178 "assigned function: %s",
8179 paramno, exprNode_unparse (e)),
8181 } else if (u1->info->var->kind == VKSEFPARAM) {
8184 message ("Function types are inconsistent. Parameter %d is "
8185 "sef parameter, but non-sef parameter in "
8186 "assigned function: %s",
8187 paramno, exprNode_unparse (e)),
8190 if (u2->info->var->kind == VKSEFRETPARAM) {
8193 message ("Function types are inconsistent. Parameter %d is "
8194 "normal parameter, but sef returns parameter in "
8195 "assigned function: %s",
8196 paramno, exprNode_unparse (e)),
8198 } else if (u2->info->var->kind == VKSEFPARAM) {
8201 message ("Function types are inconsistent. Parameter %d is "
8202 "normal parameter, but sef parameter in "
8203 "assigned function: %s",
8204 paramno, exprNode_unparse (e)),
8206 } else if (u2->info->var->kind == VKRETPARAM) {
8209 message ("Function types are inconsistent. Parameter %d is "
8210 "normal parameter, but returns parameter in "
8211 "assigned function: %s",
8212 paramno, exprNode_unparse (e)),
8220 if (u1->info->var->defstate != u2->info->var->defstate)
8224 message ("Function types are inconsistent. Parameter %d is "
8225 "%s, but %s in assigned function: %s",
8227 sstate_unparse (u1->info->var->defstate),
8228 sstate_unparse (u2->info->var->defstate),
8229 exprNode_unparse (e)),
8233 if (u1->info->var->nullstate != u2->info->var->nullstate)
8237 message ("Function types are inconsistent. Parameter %d is "
8238 "%s, but %s in assigned function: %s",
8240 nstate_unparse (u1->info->var->nullstate),
8241 nstate_unparse (u2->info->var->nullstate),
8242 exprNode_unparse (e)),
8246 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
8250 message ("Function types are inconsistent. Parameter %d is "
8251 "%s, but %s in assigned function: %s",
8253 alkind_unparse (sRef_getAliasKind (u1->sref)),
8254 alkind_unparse (sRef_getAliasKind (u2->sref)),
8255 exprNode_unparse (e)),
8259 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
8263 message ("Function types are inconsistent. Parameter %d is "
8264 "%s, but %s in assigned function: %s",
8266 exkind_unparse (sRef_getExKind (u1->sref)),
8267 exkind_unparse (sRef_getExKind (u2->sref)),
8268 exprNode_unparse (e)),
8274 checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8275 /*@notnull@*/ uentry unew,
8276 bool mustConform, /*@unused@*/ bool completeConform)
8278 uentryList oldParams = uentry_getParams (old);
8279 uentryList newParams = uentry_getParams (unew);
8280 ctype newType = unew->utype;
8281 ctype oldType = ctype_realType (old->utype);
8282 ctype oldRetType = ctype_unknown;
8283 ctype newRetType = ctype_unknown;
8285 DPRINTF (("Function conform: %s ==> %s",
8286 uentry_unparseFull (old),
8287 uentry_unparseFull (unew)));
8289 if (uentry_isForward (old))
8291 mustConform = FALSE;
8292 uentry_updateInto (old, unew);
8297 ** check return values
8300 if (ctype_isKnown (oldType))
8302 llassert (ctype_isFunction (oldType));
8303 oldRetType = ctype_getReturnType (oldType);
8306 if (ctype_isKnown (newType))
8308 llassert (ctype_isFunction (newType));
8309 newRetType = ctype_getReturnType (newType);
8312 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
8313 && !ctype_matchDef (newRetType, oldRetType))
8315 if (mustConform) returnValueError (old, unew);
8319 if (ctype_isConj (newRetType))
8321 if (ctype_isConj (oldRetType))
8323 if (!ctype_sameAltTypes (newRetType, oldRetType))
8327 message ("Function %q inconsistently %rdeclared to "
8328 "return alternate types %s "
8329 "(types match, but alternates are not identical, "
8330 "so checking may not be correct)",
8331 uentry_getName (unew),
8332 uentry_isDeclared (old),
8333 ctype_unparse (newRetType)),
8334 uentry_whereDeclared (unew)))
8336 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
8342 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
8347 DPRINTF (("Before state: %s",
8348 uentry_unparseFull (old)));
8349 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8350 DPRINTF (("After state: %s",
8351 uentry_unparseFull (old)));
8353 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
8355 if (exitkind_isKnown (unew->info->fcn->exitCode))
8359 message ("Function %q inconsistently %rdeclared using %s",
8360 uentry_getName (unew),
8361 uentry_isDeclared (old),
8362 exitkind_unparse (unew->info->fcn->exitCode)),
8363 uentry_whereDeclared (unew)))
8365 uentry_showWhereSpecified (old);
8370 unew->info->fcn->exitCode = old->info->fcn->exitCode;
8374 if (!qual_isUnknown (unew->info->fcn->nullPred))
8376 if (!qual_match (old->info->fcn->nullPred, unew->info->fcn->nullPred))
8380 message ("Function %q inconsistently %rdeclared using %s",
8381 uentry_getName (unew),
8382 uentry_isDeclared (old),
8383 qual_unparse (unew->info->fcn->nullPred)),
8384 uentry_whereDeclared (unew)))
8386 uentry_showWhereSpecified (old);
8392 unew->info->fcn->nullPred = old->info->fcn->nullPred;
8395 if (unew->info->fcn->specialCode != SPC_NONE)
8397 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
8401 message ("Function %q inconsistently %rdeclared using %s",
8402 uentry_getName (unew),
8403 uentry_isDeclared (old),
8404 specCode_unparse (unew->info->fcn->specialCode)),
8405 uentry_whereDeclared (unew)))
8407 uentry_showWhereSpecified (old);
8413 unew->info->fcn->specialCode = old->info->fcn->specialCode;
8420 if (!uentryList_sameObject (oldParams, newParams)
8421 && (!uentryList_isMissingParams (oldParams)))
8423 if (!uentryList_isMissingParams (newParams))
8426 int nparams = uentryList_size (oldParams);
8427 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
8429 if (nparams != uentryList_size (newParams))
8431 nargsError (old, unew);
8434 if (uentryList_size (newParams) < nparams)
8436 nparams = uentryList_size (newParams);
8439 while (paramno < nparams)
8441 uentry oldCurrent = uentryList_getN (oldParams, paramno);
8442 uentry newCurrent = uentryList_getN (newParams, paramno);
8443 ctype oldCurrentType = uentry_getType (oldCurrent);
8444 ctype newCurrentType = uentry_getType (newCurrent);
8446 llassert (uentry_isValid (oldCurrent)
8447 && uentry_isValid (newCurrent));
8449 if (!uentry_isElipsisMarker (oldCurrent)
8450 && !uentry_isElipsisMarker (newCurrent))
8452 checkVarConformance (oldCurrent, newCurrent,
8453 mustConform, completeConform);
8458 if (uentry_hasName (oldCurrent)
8459 && uentry_hasName (newCurrent))
8461 cstring oldname = uentry_getName (oldCurrent);
8462 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
8464 cstring nname = uentry_getName (newCurrent);
8467 if (cstring_isDefined (pfx)
8468 && cstring_equalPrefix (oldname, pfx))
8470 oname = cstring_suffix (oldname, cstring_length (pfx));
8475 /*@-branchstate@*/ } /*@=branchstate@*/
8477 if (cstring_isDefined (pfx)
8478 && cstring_equalPrefix (nname, pfx))
8480 nnamefix = cstring_suffix (nname, cstring_length (pfx));
8485 /*@-branchstate@*/ } /*@=branchstate@*/
8487 if (!cstring_equal (oname, nnamefix))
8490 (FLG_DECLPARAMMATCH,
8491 message ("Definition parameter name %s does not match "
8492 "name of corresponding parameter in "
8495 uentry_whereLast (newCurrent)))
8497 uentry_showWhereLastPlain (oldCurrent);
8501 cstring_free (oldname);
8502 cstring_free (nname);
8506 if (!ctype_match (oldCurrentType, newCurrentType))
8508 paramTypeError (old, oldCurrent, oldCurrentType,
8509 unew, newCurrent, newCurrentType, paramno);
8513 if (ctype_isMissingParamsMarker (newCurrentType)
8514 || ctype_isElips (newCurrentType)
8515 || ctype_isMissingParamsMarker (oldCurrentType)
8516 || ctype_isElips (oldCurrentType))
8522 if (ctype_isConj (newCurrentType))
8524 if (ctype_isConj (oldCurrentType))
8526 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
8530 message ("Parameter %q inconsistently %rdeclared with "
8531 "alternate types %s "
8532 "(types match, but alternates are not identical, "
8533 "so checking may not be correct)",
8534 uentry_getName (newCurrent),
8535 uentry_isDeclared (oldCurrent),
8536 ctype_unparse (newCurrentType)),
8537 uentry_whereDeclared (unew)))
8539 uentry_showWhereLastVal (oldCurrent,
8540 ctype_unparse (oldCurrentType));
8548 message ("Parameter %q inconsistently %rdeclared with "
8549 "alternate types %s",
8550 uentry_getName (newCurrent),
8551 uentry_isDeclared (oldCurrent),
8552 ctype_unparse (newCurrentType)),
8553 uentry_whereDeclared (unew)))
8555 uentry_showWhereLastVal (oldCurrent,
8556 ctype_unparse (oldCurrentType));
8563 if (ctype_isConj (oldCurrentType))
8565 uentry_setType (newCurrent, oldCurrentType);
8573 ** Forgot this! detected by splint:
8574 ** uentry.c:1257,15: Suspected infinite loop
8580 if (!uentryList_isMissingParams (newParams))
8582 if (ctype_isConj (oldRetType))
8584 old->utype = ctype_makeFunction (oldRetType,
8585 uentryList_copy (newParams));
8589 old->utype = unew->utype;
8593 checkGlobalsConformance (old, unew, mustConform, completeConform);
8594 checkModifiesConformance (old, unew, mustConform, completeConform);
8596 DPRINTF (("Before list: %s",
8597 uentry_unparseFull (old)));
8599 if (stateClauseList_isDefined (unew->info->fcn->specclauses))
8601 if (!stateClauseList_isDefined (old->info->fcn->specclauses))
8606 message ("Function %q redeclared using special clauses (can only "
8607 "be used in first declaration)",
8608 uentry_getName (unew)),
8609 uentry_whereDeclared (unew)))
8611 uentry_showWhereLast (old);
8615 /*@i23 need checking @*/
8617 old->info->fcn->specclauses = unew->info->fcn->specclauses;
8621 /*@i43 should be able to append? @*/
8623 stateClauseList_checkEqual (old, unew);
8624 stateClauseList_free (unew->info->fcn->specclauses);
8625 unew->info->fcn->specclauses = stateClauseList_undefined;
8629 /*@=branchstate@*/ /*@i23 shouldn't need this@*/
8631 if (fileloc_isUndefined (old->whereDeclared))
8633 old->whereDeclared = fileloc_copy (unew->whereDeclared);
8635 else if (fileloc_isUndefined (unew->whereDeclared))
8637 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8646 uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
8650 llassert (uentry_isValid (ue));
8651 llassert (uentry_isEitherConstant (ue));
8653 DPRINTF (("Constant value: %s / %s", uentry_unparse (ue), multiVal_unparse (m)));
8654 uval = uentry_getConstantValue (ue);
8656 if (multiVal_isDefined (uval))
8658 if (multiVal_isDefined (m))
8660 if (!multiVal_equiv (uval, m))
8664 message ("%s %q defined with inconsistent value: %q",
8665 ekind_capName (ue->ukind),
8666 uentry_getName (ue),
8667 multiVal_unparse (m)),
8670 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
8678 uentry_setConstantValue (ue, m);
8683 bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
8686 bool typeError = FALSE;
8688 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
8690 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
8694 DPRINTF (("Check struct conformance: %s / %s",
8695 uentry_unparseFull (old),
8696 uentry_unparseFull (unew)));
8697 checkStructConformance (old, unew);
8702 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8704 llbug (message ("struct tags: bad types: %t / %t",
8705 old->utype, unew->utype));
8709 else if (uentry_isEnumTag (old))
8711 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
8713 if (mustConform) checkEnumConformance (old, unew);
8717 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8719 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
8720 ctype_unparse (unew->utype)));
8724 else if (!ctype_match (old->utype, unew->utype))
8726 DPRINTF (("Type mismatch: %s / %s",
8727 ctype_unparse (old->utype),
8728 ctype_unparse (unew->utype)));
8730 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
8732 ctype realt = ctype_realType (unew->utype);
8734 if (ctype_isRealInt (realt) || ctype_isChar (realt))
8736 unew->utype = ctype_bool;
8742 typeError = optgenerror
8744 message ("%q defined as %s", uentry_getName (old),
8745 ctype_unparse (realt)),
8746 uentry_whereDeclared (unew));
8754 ctype oldr = ctype_realType (old->utype);
8755 ctype newr = ctype_realType (unew->utype);
8757 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
8759 checkStructConformance (old, unew);
8761 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
8763 checkStructConformance (old, unew);
8765 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
8767 checkEnumConformance (old, unew);
8769 else if (uentry_isConstant (old)
8770 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
8772 /* okay...for now! (should check the type is reset later... */
8776 DPRINTF (("YABA!"));
8779 message ("%s %q %rdeclared with inconsistent type: %t",
8780 ekind_capName (unew->ukind),
8781 uentry_getName (unew),
8782 uentry_isDeclared (old),
8784 uentry_whereDeclared (unew)))
8786 uentry_showWhereLast (old);
8802 uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
8803 /*@notnull@*/ uentry unew,
8804 bool mustConform, bool completeConform)
8806 if (ctype_isDefined (unew->info->datatype->type))
8809 ** bool is hard coded here, since it is built into LCL.
8810 ** For now, we're stuck with LCL's types.
8813 if (ctype_isDirectBool (old->utype) &&
8814 cstring_equalLit (unew->uname, "bool"))
8816 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
8817 evs 2000-07-25: removed
8819 unew->utype = ctype_bool;
8822 if (ctype_isUnknown (old->info->datatype->type))
8824 old->info->datatype->type = unew->info->datatype->type;
8828 DPRINTF (("Old: %s / New: %s",
8829 uentry_unparseFull (old),
8830 uentry_unparseFull (unew)));
8831 DPRINTF (("Types: %s / %s",
8832 ctype_unparse (old->info->datatype->type),
8833 ctype_unparse (unew->info->datatype->type)));
8835 if (ctype_matchDef (old->info->datatype->type,
8836 unew->info->datatype->type))
8845 ("Type %q %s with inconsistent type: %t",
8846 uentry_getName (unew),
8847 uentry_reDefDecl (old, unew),
8848 unew->info->datatype->type),
8849 uentry_whereDeclared (unew)))
8851 uentry_showWhereLastExtra
8852 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
8855 old->info->datatype->type = unew->info->datatype->type;
8860 if (unew->info->datatype->abs != MAYBE)
8862 if (ynm_isOff (old->info->datatype->abs)
8863 && ynm_isOn (unew->info->datatype->abs))
8865 if (!ctype_isDirectBool (old->utype))
8870 ("Datatype %q inconsistently %rdeclared as abstract type",
8871 uentry_getName (unew),
8872 uentry_isDeclared (old)),
8873 uentry_whereDeclared (unew)))
8875 uentry_showWhereLastPlain (old);
8879 else if (ynm_isOn (old->info->datatype->abs)
8880 && ynm_isOff (unew->info->datatype->abs))
8882 if (!ctype_isDirectBool (old->utype))
8887 ("Datatype %q inconsistently %rdeclared as concrete type",
8888 uentry_getName (unew),
8889 uentry_isDeclared (old)),
8890 uentry_whereDeclared (unew)))
8892 uentry_showWhereLastPlain (old);
8903 if (ynm_isOn (old->info->datatype->abs))
8905 old->sref = unew->sref;
8906 unew->info->datatype->mut = old->info->datatype->mut;
8909 && uentry_isReallySpecified (old))
8914 ("Datatype %q specified as abstract, "
8915 "but abstract annotation not used in declaration",
8916 uentry_getName (unew)),
8917 uentry_whereDeclared (unew)))
8919 uentry_showWhereLastPlain (old);
8925 unew->info->datatype->abs = old->info->datatype->abs;
8927 if (ynm_isMaybe (unew->info->datatype->mut))
8929 if (completeConform && ynm_isOff (old->info->datatype->mut)
8930 && uentry_isReallySpecified (old))
8935 ("Datatype %q specified as immutable, "
8936 "but immutable annotation not used in declaration",
8937 uentry_getName (unew)),
8938 uentry_whereDeclared (unew)))
8940 uentry_showWhereLastPlain (old);
8944 unew->info->datatype->mut = old->info->datatype->mut;
8946 else if (ynm_isMaybe (old->info->datatype->mut))
8948 old->info->datatype->mut = unew->info->datatype->mut;
8952 if (ynm_isOn (old->info->datatype->abs))
8954 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
8958 message ("Datatype %q inconsistently %rdeclared as immutable",
8959 uentry_getName (unew),
8960 uentry_isDeclared (old)),
8961 uentry_whereDeclared (unew)))
8963 uentry_showWhereLastPlain (old);
8968 if (ynm_isOff (old->info->datatype->mut)
8969 && ynm_isOn (unew->info->datatype->mut))
8973 message ("Datatype %q inconsistently %rdeclared as mutable",
8974 uentry_getName (unew),
8975 uentry_isDeclared (old)),
8976 uentry_whereDeclared (unew)))
8978 uentry_showWhereLastPlain (old);
8983 old->info->datatype->mut = unew->info->datatype->mut;
8986 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8990 uentry_checkConstantConformance (/*@notnull@*/ uentry old,
8991 /*@notnull@*/ uentry unew,
8993 /*@unused@*/ bool completeConform)
8995 multiVal oldval = uentry_getConstantValue (old);
8996 multiVal newval = uentry_getConstantValue (unew);
8998 if (multiVal_isDefined (oldval))
9000 if (multiVal_isDefined (newval))
9002 if (!multiVal_equiv (oldval, newval))
9007 message ("%s %q %rdeclared with inconsistent value: %q",
9008 ekind_capName (unew->ukind),
9009 uentry_getName (unew),
9010 uentry_isDeclared (old),
9011 multiVal_unparse (newval)),
9012 uentry_whereDeclared (unew)))
9014 uentry_showWhereLastExtra (old, multiVal_unparse (oldval));
9018 uentry_setConstantValue (unew, multiVal_copy (oldval));
9027 uentry_setConstantValue (old, multiVal_copy (newval));
9032 uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
9033 /*@notnull@*/ uentry unew, bool mustConform,
9034 bool completeConform)
9036 bool typeError = FALSE;
9037 bool fcnConformance = FALSE;
9039 if (!ekind_equal (unew->ukind, old->ukind))
9042 ** okay, only if one is a function and the other is
9043 ** a variable of type function.
9046 if (unew->ukind == KENUMCONST
9047 && old->ukind == KCONST)
9049 old->ukind = KENUMCONST;
9053 if (unew->ukind == KFCN
9054 && old->ukind == KCONST
9055 && ctype_isUnknown (old->utype))
9058 ** When a function is defined with an unparam macro
9061 uentry_updateInto (old, unew);
9065 if (uentry_isExpandedMacro (old)
9066 && uentry_isEitherConstant (unew))
9068 uentry_updateInto (old, unew);
9072 if (uentry_isEndIter (unew))
9074 if (ctype_isUnknown (old->utype))
9076 if (!uentry_isSpecified (old)
9077 && uentry_isCodeDefined (unew))
9079 if (!fileloc_withinLines (uentry_whereDefined (old),
9080 uentry_whereDeclared (unew), 2))
9081 { /* bogus! will give errors if there is too much whitespace */
9085 ("Iterator finalized name %q does not match name in "
9086 "previous iter declaration (should be end_%q). This iter "
9087 "is declared at %q",
9088 uentry_getName (unew),
9089 uentry_getName (old),
9090 fileloc_unparse (uentry_whereDefined (old))),
9091 uentry_whereDeclared (old));
9095 uentry_updateInto (old, unew);
9100 KindConformanceError (old, unew, mustConform);
9104 if (uentry_isFunction (unew))
9106 if (uentry_isVariable (old))
9108 if (!ctype_isUnknown (old->utype))
9110 if (ctype_isFunction (old->utype))
9112 uentry_makeVarFunction (old);
9113 checkFunctionConformance (old, unew, mustConform,
9115 fcnConformance = TRUE;
9119 KindConformanceError (old, unew, mustConform);
9124 if (uentry_isExpandedMacro (old))
9126 if (fileloc_isUndefined (unew->whereDefined))
9128 unew->whereDefined = fileloc_update (unew->whereDefined,
9132 uentry_updateInto (old, unew);
9133 old->used = unew->used = TRUE;
9138 /* undeclared identifier */
9139 old->utype = unew->utype;
9140 uentry_makeVarFunction (old);
9141 checkFunctionConformance (old, unew, FALSE, FALSE);
9142 fcnConformance = TRUE;
9148 KindConformanceError (old, unew, mustConform);
9151 else if (uentry_isFunction (old) && uentry_isVariable (unew))
9153 if (!ctype_isUnknown (unew->utype))
9155 if (ctype_isFunction (unew->utype))
9157 uentry_makeVarFunction (unew);
9158 checkFunctionConformance (old, unew, mustConform, completeConform);
9159 fcnConformance = TRUE;
9163 KindConformanceError (old, unew, mustConform);
9168 KindConformanceError (old, unew, mustConform);
9173 KindConformanceError (old, unew, mustConform);
9179 ** check parameter lists for functions
9180 ** (before type errors, to get better messages
9183 if (uentry_isFunction (old))
9185 checkFunctionConformance (old, unew, mustConform, completeConform);
9186 fcnConformance = TRUE;
9190 if (!ctype_isUndefined (old->utype))
9192 typeError = checkTypeConformance (old, unew, mustConform);
9199 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
9201 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
9204 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
9206 DPRINTF (("Check datatype: %s / %s",
9207 uentry_unparseFull (old),
9208 uentry_unparseFull (unew)));
9210 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
9213 if (uentry_isVariable (old) && uentry_isVariable (unew))
9216 !ctype_matchDef (old->utype, unew->utype))
9221 ("Variable %q %s with inconsistent type (arrays and pointers are "
9222 "not identical in variable declarations): %t",
9223 uentry_getName (unew),
9224 uentry_reDefDecl (old, unew),
9226 uentry_whereDeclared (unew)))
9228 uentry_showWhereLast (old);
9231 ** Avoid repeated errors.
9234 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
9236 old->whereDefined = fileloc_update (old->whereDefined,
9244 checkVarConformance (old, unew, mustConform, completeConform);
9249 /* old->utype = unew->utype; */
9253 if (ctype_isConj (old->utype))
9255 if (ctype_isConj (unew->utype))
9257 if (!ctype_sameAltTypes (old->utype, unew->utype))
9261 message ("%s %q inconsistently %rdeclared with "
9262 "alternate types %s "
9263 "(types match, but alternates are not identical, "
9264 "so checking may not be correct)",
9265 ekind_capName (uentry_getKind (old)),
9266 uentry_getName (unew),
9267 uentry_isDeclared (old),
9268 ctype_unparse (unew->utype)),
9269 uentry_whereDeclared (unew)))
9271 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
9275 old->utype = unew->utype;
9282 if (ctype_isUnknown (old->utype))
9284 old->utype = unew->utype;
9289 if (unew->ukind == old->ukind)
9292 unew->info = uinfo_copy (old->info, old->ukind);
9295 sRef_storeState (old->sref);
9296 sRef_storeState (unew->sref);
9299 static void uentry_mergeConstraints (uentry spec, uentry def)
9301 if (uentry_isFunction (def))
9303 DPRINTF (("Here: %s / %s",
9304 uentry_unparseFull (spec),
9305 uentry_unparseFull (def)));
9306 /* evans 2001-07-21 */
9307 llassert (uentry_isFunction (spec));
9309 if (functionConstraint_isDefined (def->info->fcn->preconditions))
9311 if (fileloc_isXHFile (uentry_whereLast (def)))
9313 llassert (uentry_isFunction (spec));
9314 spec->info->fcn->preconditions = functionConstraint_conjoin (spec->info->fcn->preconditions,
9315 def->info->fcn->preconditions);
9317 else if (fileloc_equal (uentry_whereLast (spec), uentry_whereLast (def)))
9323 /* Check if the constraints are identical */
9328 ("Preconditions for %q redeclared. Dropping previous precondition: %q",
9329 uentry_getName (spec),
9330 functionConstraint_unparse (spec->info->fcn->preconditions)),
9331 uentry_whereLast (def)))
9333 uentry_showWhereSpecified (spec);
9336 functionConstraint_free (spec->info->fcn->preconditions);
9337 spec->info->fcn->preconditions = def->info->fcn->preconditions;
9340 def->info->fcn->preconditions = functionConstraint_undefined;
9343 if (functionConstraint_isDefined (def->info->fcn->postconditions))
9345 if (fileloc_isXHFile (uentry_whereLast (def)))
9347 llassert (uentry_isFunction (spec));
9348 DPRINTF (("Post: %s /++/ %s",
9349 functionConstraint_unparse (spec->info->fcn->postconditions),
9350 functionConstraint_unparse (def->info->fcn->postconditions)));
9351 spec->info->fcn->postconditions = functionConstraint_conjoin (spec->info->fcn->postconditions,
9352 def->info->fcn->postconditions);
9353 def->info->fcn->postconditions = functionConstraint_undefined;
9354 DPRINTF (("Conjoined post: %s", functionConstraint_unparse (spec->info->fcn->postconditions)));
9361 ("Postconditions for %q redeclared. Dropping previous postcondition: %q",
9362 uentry_getName (spec),
9363 functionConstraint_unparse (spec->info->fcn->postconditions)),
9364 uentry_whereLast (def)))
9366 uentry_showWhereSpecified (spec);
9369 functionConstraint_free (spec->info->fcn->postconditions);
9370 spec->info->fcn->postconditions = def->info->fcn->postconditions;
9371 def->info->fcn->postconditions = functionConstraint_undefined;
9378 ** modifies spec to reflect def, reports any inconsistencies
9382 uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
9384 llassert (uentry_isValid (spec));
9385 llassert (uentry_isValid (def));
9386 llassert (cstring_equal (spec->uname, def->uname));
9388 if (uentry_isFunction (def))
9390 if (uentry_isConstant (spec))
9392 llassert (ctype_isUnknown (spec->utype) || ctype_isFunction (spec->utype));
9393 uentry_makeConstantFunction (spec);
9397 uentry_convertVarFunction (spec);
9400 llassert (uentry_isFunction (spec));
9403 DPRINTF (("Merge entries: %s / %s",
9404 uentry_unparseFull (spec),
9405 uentry_unparseFull (def)));
9407 uentry_mergeConstraints (spec, def);
9409 uentry_checkConformance (spec, def, TRUE,
9410 context_getFlag (FLG_NEEDSPEC));
9412 DPRINTF (("Merge entries after conform: %s / %s",
9413 uentry_unparseFull (spec),
9414 uentry_unparseFull (def)));
9416 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
9419 ** okay, declarations conform. Propagate extra information.
9422 uentry_setDefined (spec, uentry_whereDefined (def));
9423 uentry_setDeclared (spec, uentry_whereDeclared (def));
9425 if (uentry_isStatic (def))
9429 message ("%s %q specified, but declared as static",
9430 ekind_capName (def->ukind),
9431 uentry_getName (def)),
9432 uentry_whereDeclared (def)))
9434 uentry_showWhereSpecified (spec);
9439 spec->storageclass = def->storageclass;
9442 sRef_storeState (spec->sref);
9444 spec->used = def->used || spec->used;
9445 spec->hasNameError |= def->hasNameError;
9449 if (!spec->hasNameError)
9451 uentry_checkName (spec);
9460 ** Can't generate function redeclaration errors when the
9461 ** entries are merged, since we don't yet know if its the
9462 ** definition of the function.
9466 uentry_clearDecl (void)
9468 posRedeclared = uentry_undefined;
9469 fileloc_free (posLoc);
9470 posLoc = fileloc_undefined;
9474 uentry_checkDecl (void)
9476 if (uentry_isValid (posRedeclared) && !fileloc_isXHFile (posLoc))
9478 llassert (fileloc_isDefined (posLoc));
9480 if (uentry_isCodeDefined (posRedeclared))
9482 if (optgenerror (FLG_REDECL,
9483 message ("%s %q declared after definition",
9484 ekind_capName (posRedeclared->ukind),
9485 uentry_getName (posRedeclared)),
9488 llgenindentmsg (message ("Definition of %q",
9489 uentry_getName (posRedeclared)),
9490 posRedeclared->whereDeclared);
9495 if (optgenerror (FLG_REDECL,
9496 message ("%s %q declared more than once",
9497 ekind_capName (posRedeclared->ukind),
9498 uentry_getName (posRedeclared)),
9501 llgenindentmsg (message ("Previous declaration of %q",
9502 uentry_getName (posRedeclared)),
9503 posRedeclared->whereDeclared);
9508 fileloc_free (posLoc);
9509 posLoc = fileloc_undefined;
9510 posRedeclared = uentry_undefined;
9514 ** Redefinition of old as unew.
9515 ** modifies old to reflect unew, reports any inconsistencies
9519 uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
9521 fileloc olddef = uentry_whereDeclared (old);
9522 fileloc unewdef = uentry_whereDeclared (unew);
9526 DPRINTF (("uentry merge: %s / %s",
9527 uentry_unparseFull (old),
9528 uentry_unparseFull (unew)));
9531 fileloc_isUndefined (olddef)
9532 && fileloc_isDefined (uentry_whereDefined (old))
9533 && !uentry_isExpandedMacro (old);
9535 if (!context_getFlag (FLG_INCONDEFSLIB)
9536 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9538 mustConform = FALSE;
9545 llassert (uentry_isValid (old));
9546 llassert (uentry_isValid (unew));
9547 llassert (cstring_equal (old->uname, unew->uname));
9549 if (uentry_isFunction (unew) && !uentry_isFunction (old))
9551 if (uentry_isConstant (old))
9553 llassert (ctype_isUnknown (old->utype) || ctype_isFunction (old->utype));
9554 uentry_makeConstantFunction (old);
9558 uentry_convertVarFunction (old);
9561 llassert (uentry_isFunction (old));
9564 DPRINTF (("uentry merge: %s / %s",
9565 uentry_unparseFull (old),
9566 uentry_unparseFull (unew)));
9568 if (uentry_isExtern (unew))
9570 uentry_setUsed (old, unewdef);
9574 ** should check old one was extern!
9577 if (uentry_isStatic (old))
9579 if (!(uentry_isStatic (unew)))
9583 message ("%s %q shadows static declaration",
9584 ekind_capName (unew->ukind),
9585 uentry_getName (unew)),
9588 uentry_showWhereLast (old);
9593 uentry_setDeclDef (old, unewdef);
9596 else if (uentry_isStatic (unew))
9598 uentry_setDeclDef (old, unewdef);
9600 else if (uentry_isExtern (old))
9602 uentry_setDeclared (old, unewdef);
9606 if (!uentry_isExtern (unew)
9607 && !uentry_isForward (old)
9608 && !fileloc_equal (olddef, unewdef)
9609 && !fileloc_isUndefined (olddef)
9610 && !fileloc_isUndefined (unewdef)
9611 && !fileloc_isBuiltin (olddef)
9612 && !fileloc_isBuiltin (unewdef)
9613 && !uentry_isYield (old)
9614 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9616 if (uentry_isVariable (old) || uentry_isVariable (unew))
9618 ; /* will report redeclaration error later */
9622 if (fileloc_isDefined (uentry_whereDefined (old)))
9626 message ("%s %q defined more than once",
9627 ekind_capName (unew->ukind),
9628 uentry_getName (unew)),
9629 uentry_whereLast (unew)))
9632 (message ("Previous definition of %q",
9633 uentry_getName (old)),
9634 uentry_whereLast (old));
9637 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
9639 uentry_updateInto (old, unew);
9640 old->sref = sRef_saveCopy (old->sref);
9648 if (fileloc_isLib (olddef)
9649 || fileloc_isUndefined (olddef)
9650 || fileloc_isImport (olddef))
9652 if (uentry_isExtern (unew))
9654 if (uentry_isExtern (old)
9655 || (fileloc_isDefined (uentry_whereDeclared (old))
9656 && (!fileloc_equal (uentry_whereDeclared (old),
9657 uentry_whereDefined (old)))))
9661 message ("%s %q declared more than once",
9662 ekind_capName (unew->ukind),
9663 uentry_getName (unew)),
9664 unew->whereDeclared))
9667 (message ("Previous declaration of %q",
9668 uentry_getName (old)),
9669 old->whereDeclared);
9673 uentry_setExtern (old);
9677 uentry_setDeclared (old, unewdef); /* evans 2001-07-23 was setDefined */
9683 DPRINTF (("uentry merge: %s / %s",
9684 uentry_unparseFull (old),
9685 uentry_unparseFull (unew)));
9687 uentry_mergeConstraints (old, unew);
9688 DPRINTF (("uentry merge: %s / %s",
9689 uentry_unparseFull (old),
9690 uentry_unparseFull (unew)));
9692 uentry_checkConformance (old, unew, mustConform, FALSE);
9693 DPRINTF (("uentry merge: %s / %s",
9694 uentry_unparseFull (old),
9695 uentry_unparseFull (unew)));
9697 old->used = old->used || unew->used;
9698 old->uses = filelocList_append (old->uses, unew->uses);
9699 unew->uses = filelocList_undefined;
9701 sRef_storeState (old->sref);
9702 sRef_storeState (unew->sref);
9706 old->whereDefined = fileloc_update (old->whereDefined,
9710 DPRINTF (("here: %s", uentry_unparseFull (old)));
9713 ** No redeclaration errors for functions here, since we
9714 ** don't know if this is the definition of the function.
9717 if (fileloc_isUser (old->whereDeclared)
9718 && fileloc_isUser (unew->whereDeclared)
9719 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
9720 && !fileloc_isDefined (unew->whereDefined))
9722 if (uentry_isFunction (old))
9724 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
9725 posLoc = fileloc_update (posLoc, unew->whereDeclared);
9729 if (optgenerror (FLG_REDECL,
9730 message ("%s %q declared more than once",
9731 ekind_capName (unew->ukind),
9732 uentry_getName (unew)),
9733 unew->whereDeclared))
9735 llgenindentmsg (message ("Previous declaration of %q",
9736 uentry_getName (old)),
9737 old->whereDeclared);
9742 if (fileloc_isUndefined (old->whereDefined))
9744 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
9748 if (!context_processingMacros ()
9749 && fileloc_isUser (old->whereDefined)
9750 && fileloc_isUser (unew->whereDefined)
9751 && !fileloc_equal (old->whereDefined, unew->whereDefined))
9753 if (uentry_isVariable (unew) || uentry_isFunction (unew))
9755 if (uentry_isVariable (unew)
9756 && uentry_isExtern (unew))
9758 if (optgenerror (FLG_REDECL,
9759 message ("%s %q declared after definition",
9760 ekind_capName (unew->ukind),
9761 uentry_getName (unew)),
9762 unew->whereDeclared))
9764 llgenindentmsg (message ("Definition of %q",
9765 uentry_getName (old)),
9771 if (optgenerror (FLG_REDEF,
9772 message ("%s %q redefined",
9773 ekind_capName (unew->ukind),
9774 uentry_getName (unew)),
9775 unew->whereDefined))
9777 llgenindentmsg (message ("Previous definition of %q",
9778 uentry_getName (old)),
9786 if (uentry_isExternal (unew))
9788 old->whereDefined = fileloc_createExternal ();
9791 if (unew->hasNameError)
9793 old->hasNameError = TRUE;
9798 if (!old->hasNameError)
9800 uentry_checkName (old);
9803 DPRINTF (("After: %s", uentry_unparseFull (old)));
9804 llassert (!ctype_isUndefined (old->utype));
9808 uentry_copyState (uentry res, uentry other)
9810 llassert (uentry_isValid (res));
9811 llassert (uentry_isValid (other));
9813 res->used = other->used;
9815 res->info->var->kind = other->info->var->kind;
9816 res->info->var->defstate = other->info->var->defstate;
9817 res->info->var->nullstate = other->info->var->nullstate;
9818 res->info->var->checked = other->info->var->checked;
9820 sRef_copyState (res->sref, other->sref);
9824 uentry_sameKind (uentry u1, uentry u2)
9826 if (uentry_isValid (u1) && uentry_isValid (u2))
9828 if (uentry_isVar (u1) && uentry_isVar (u2))
9830 ctype c1 = u1->utype;
9831 ctype c2 = u2->utype;
9833 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
9836 ** both functions, or both not functions
9839 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
9843 return ((u1->ukind == u2->ukind));
9850 static void uentry_updateInto (/*@unique@*/ uentry unew, uentry old)
9853 llassert (uentry_isValid (unew));
9854 llassert (uentry_isValid (old));
9856 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9857 okind = unew->ukind;
9858 unew->ukind = old->ukind;
9859 llassert (cstring_equal (unew->uname, old->uname));
9860 unew->utype = old->utype;
9862 if (fileloc_isDefined (unew->whereSpecified)
9863 && !fileloc_isDefined (old->whereSpecified))
9865 ; /* Keep the old value */
9869 fileloc_free (unew->whereSpecified); /*@i523 why no error without this? */
9870 unew->whereSpecified = fileloc_copy (old->whereSpecified);
9873 if (fileloc_isDefined (unew->whereDefined)
9874 && !fileloc_isDefined (old->whereDefined))
9876 ; /* Keep the old value */
9880 fileloc_free (unew->whereDefined); /*@i523 why no error without this? */
9881 unew->whereDefined = fileloc_copy (old->whereDefined);
9884 if (fileloc_isDefined (unew->whereDeclared)
9885 && !fileloc_isDefined (old->whereDeclared))
9887 ; /* Keep the old value */
9891 fileloc_free (unew->whereDeclared); /*@i523 why no error without this? */
9892 unew->whereDeclared = fileloc_copy (old->whereDeclared);
9895 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9897 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
9898 unew->used = old->used;
9900 unew->isPrivate = old->isPrivate;
9901 unew->hasNameError = old->hasNameError;
9902 unew->uses = filelocList_append (unew->uses, old->uses);
9903 old->uses = filelocList_undefined;
9905 unew->storageclass = old->storageclass;
9906 uinfo_free (unew->info, okind);
9907 unew->info = uinfo_copy (old->info, old->ukind);
9911 uentry_copyAux (uentry e, bool saveCopy)
9914 if (uentry_isValid (e))
9916 uentry enew = uentry_alloc ();
9917 DPRINTF (("copy: %s", uentry_unparseFull (e)));
9918 enew->ukind = e->ukind;
9919 enew->uname = cstring_copy (e->uname);
9920 enew->utype = e->utype;
9922 enew->whereSpecified = fileloc_copy (e->whereSpecified);
9923 enew->whereDefined = fileloc_copy (e->whereDefined);
9924 enew->whereDeclared = fileloc_copy (e->whereDeclared);
9928 enew->sref = sRef_saveCopy (e->sref); /* Memory leak! */
9932 enew->sref = sRef_copy (e->sref);
9935 enew->used = e->used;
9937 enew->isPrivate = e->isPrivate;
9938 enew->hasNameError = e->hasNameError;
9939 enew->uses = filelocList_undefined;
9941 enew->storageclass = e->storageclass;
9942 enew->info = uinfo_copy (e->info, e->ukind);
9943 enew->warn = warnClause_copy (e->warn);
9945 DPRINTF (("Here we are..."));
9946 DPRINTF (("original: %s", uentry_unparseFull (e)));
9947 DPRINTF (("copy: %s", uentry_unparse (enew)));
9948 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
9953 return uentry_undefined;
9958 uentry_copy (uentry e)
9960 return uentry_copyAux (e, TRUE);
9964 uentry_copyNoSave (uentry e)
9966 return uentry_copyAux (e, FALSE);
9970 uentry_setState (uentry res, uentry other)
9972 llassert (uentry_isValid (res));
9973 llassert (uentry_isValid (other));
9975 llassert (res->ukind == other->ukind);
9976 llassert (res->ukind == KVAR);
9978 res->sref = sRef_saveCopy (other->sref);
9979 res->used = other->used;
9980 filelocList_free (res->uses);
9981 res->uses = other->uses;
9982 other->uses = filelocList_undefined;
9983 res->lset = other->lset;
9987 uentry_mergeUses (uentry res, uentry other)
9989 llassert (uentry_isValid (res));
9990 llassert (uentry_isValid (other));
9992 res->used = other->used || res->used;
9993 res->lset = other->lset || res->lset;
9994 res->uses = filelocList_append (res->uses, other->uses);
9995 other->uses = filelocList_undefined;
10000 ** This is a really ugly routine.
10002 ** gack...fix this one day.
10007 ** >> res is the false branch, other is the true branch (or continuation)
10009 ** >> res is the true branch, other is the false branch (or continutation)
10016 ** References not effected by res are propagated from other.
10020 branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10021 bool flip, clause cl, fileloc loc)
10025 message ("%s %q is %s %s, but %s %s.",
10026 ekind_capName (res->ukind), uentry_getName (res),
10027 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
10028 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
10031 if (sRef_isDead (res->sref))
10033 sRef_showStateInfo (res->sref);
10034 sRef_showStateInfo (other->sref);
10036 else if (sRef_isKept (res->sref))
10038 sRef_showAliasInfo (res->sref);
10039 sRef_showAliasInfo (other->sref);
10041 else /* dependent */
10043 sRef_showAliasInfo (res->sref);
10044 sRef_showAliasInfo (other->sref);
10047 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
10051 static bool uentry_incompatibleMemoryStates (sRef rs, sRef os)
10053 alkind rk = sRef_getAliasKind (rs);
10054 alkind ok = sRef_getAliasKind (os);
10056 if (alkind_isError (rk) || alkind_isError (ok))
10062 return ((sRef_isDead (rs)
10063 || (alkind_isKept (rk) && !alkind_isKept (ok))
10064 || (alkind_isDependent (rk)
10065 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
10066 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
10071 branchStateAltError (/*@notnull@*/ uentry res,
10072 /*@notnull@*/ uentry other, bool flip,
10073 clause cl, fileloc loc)
10077 message ("%s %q is %s %s, but %s %s.",
10078 ekind_capName (res->ukind), uentry_getName (res),
10079 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
10080 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
10083 if (sRef_isDead (other->sref))
10085 sRef_showStateInfo (other->sref);
10089 sRef_showAliasInfo (other->sref);
10092 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
10093 sRef_setDefinedComplete (res->sref, fileloc_undefined);
10095 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
10096 sRef_setDefinedComplete (other->sref, fileloc_undefined);
10101 ** A reference is relevant for certain checks, only if it
10102 ** is not definitely null on this path (but not declared
10103 ** to always be null.)
10106 static bool uentry_relevantReference (sRef sr, bool flip)
10108 if (sRef_isKept (sr) || sRef_isDependent (sr))
10116 return !sRef_definitelyNullContext (sr);
10120 return !sRef_definitelyNullAltContext (sr);
10126 uentry_mergeAliasStates (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10127 fileloc loc, bool mustReturn, bool flip, bool opt,
10130 sRef rs = res->sref;
10131 sRef os = other->sref;
10133 DPRINTF (("Merge alias states: %s / %s",
10134 uentry_unparseFull (res),
10135 uentry_unparseFull (other)));
10137 if (sRef_isValid (rs))
10141 if (uentry_incompatibleMemoryStates (rs, os))
10143 DPRINTF (("Incompatible: \n\t%s / \n\t%s",
10144 sRef_unparseFull (rs), sRef_unparseFull (os)));
10146 if (sRef_isThroughArrayFetch (rs)
10147 && !context_getFlag (FLG_STRICTBRANCHSTATE))
10149 if (sRef_isKept (rs) || sRef_isKept (os))
10151 sRef_maybeKill (rs, loc);
10153 else if (sRef_isPossiblyDead (os))
10155 sRef_maybeKill (rs, loc);
10164 if (uentry_relevantReference (os, flip))
10166 if (sRef_isLocalParamVar (rs)
10167 && (sRef_isLocalState (os)
10168 || sRef_isDependent (os)))
10170 if (sRef_isDependent (rs))
10172 sRef_setDependent (os, loc);
10176 sRef_setDefState (rs, SS_UNUSEABLE, loc);
10181 branchStateError (res, other, flip, cl, loc);
10186 if (sRef_isKept (rs))
10188 DPRINTF (("Setting kept: %s", sRef_unparseFull (os)));
10189 sRef_setKept (os, loc);
10194 if (uentry_incompatibleMemoryStates (os, rs))
10196 if (uentry_relevantReference (rs, !flip))
10198 if (sRef_isLocalParamVar (rs)
10199 && (sRef_isDependent (rs)
10200 || sRef_isLocalState (rs)))
10202 if (sRef_isDependent (os))
10204 sRef_setDependent (rs, loc);
10208 sRef_setDefState (rs, SS_UNUSEABLE, loc);
10213 if (sRef_isParam (os))
10216 ** If the local variable associated
10217 ** with the param has the correct state,
10219 ** (e.g., free (s); s = new(); ...
10222 uentry uvar = usymtab_lookupSafe (other->uname);
10224 if (uentry_isValid (uvar)
10225 && ((sRef_isDead (os)
10226 && sRef_isOnly (uvar->sref))
10227 || (sRef_isDependent (os)
10228 && sRef_isOwned (uvar->sref))))
10234 branchStateAltError (res, other,
10240 DPRINTF (("Here: %s / %s",
10241 uentry_unparseFull (res),
10242 uentry_unparseFull (other)));
10244 branchStateAltError (res, other,
10251 if (sRef_isKept (os))
10253 sRef_setKept (rs, loc);
10259 DPRINTF (("Merge opt..."));
10260 sRef_mergeOptState (rs, os, cl, loc);
10261 DPRINTF (("Done!"));
10265 DPRINTF (("Merging states: \n\t%s / \n\t%s", sRef_unparseFull (rs), sRef_unparseFull (os)));
10266 sRef_mergeState (rs, os, cl, loc);
10267 DPRINTF (("After merging : \n\t%s / \n\t%s", sRef_unparseFull (rs), sRef_unparseFull (os)));
10272 if (sRef_isModified (os))
10274 sRef_setModified (rs);
10279 DPRINTF (("After merge: %s", sRef_unparseFull (res->sref)));
10283 uentry_mergeValueStates (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10284 fileloc loc, bool mustReturn, /*@unused@*/ bool flip)
10286 valueTable rvalues;
10287 valueTable ovalues;
10289 DPRINTF (("Merge values: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
10297 rvalues = sRef_getValueTable (res->sref);
10298 ovalues = sRef_getValueTable (other->sref);
10300 if (valueTable_isUndefined (ovalues))
10302 DPRINTF (("No value table: %s", sRef_unparseFull (other->sref)));
10305 else if (valueTable_isUndefined (rvalues))
10308 ** Copy values from other
10312 DPRINTF (("Has value table: %s", sRef_unparseFull (other->sref)));
10313 DPRINTF (("No value table: %s", sRef_unparseFull (res->sref)));
10318 valueTable_elements (ovalues, fkey, fval) {
10320 metaStateInfo minfo;
10321 stateCombinationTable sctable;
10325 tval = valueTable_lookup (rvalues, fkey);
10327 DPRINTF (("Merge value: %s / %s X %s", fkey,
10328 stateValue_unparse (fval), stateValue_unparse (tval)));
10330 minfo = context_lookupMetaStateInfo (fkey);
10331 llassert (stateValue_isDefined (tval));
10333 if (metaStateInfo_isUndefined (minfo) || !stateValue_isDefined (tval))
10335 DPRINTF (("Cannot find meta state for: %s", fkey));
10340 llassert (metaStateInfo_isDefined (minfo));
10342 if (stateValue_isError (fval)
10343 || sRef_definitelyNullContext (res->sref))
10345 sRef_setMetaStateValueComplete (res->sref,
10346 fkey, stateValue_getValue (fval),
10347 stateValue_getLoc (fval));
10348 DPRINTF (("Setting res: %s", sRef_unparseFull (res->sref)));
10350 else if (stateValue_isError (tval)
10351 || sRef_definitelyNullAltContext (other->sref))
10353 DPRINTF (("Other branch is definitely null!"));
10355 else if (sRef_isStateUndefined (res->sref)
10356 || sRef_isDead (res->sref))
10358 ; /* Combination state doesn't matter if it is undefined or dead */
10362 DPRINTF (("Check: %s / %s / %s / %s", fkey,
10363 metaStateInfo_unparse (minfo),
10364 stateValue_unparse (fval),
10365 stateValue_unparse (tval)));
10367 DPRINTF (("state values: %d / %d",
10368 stateValue_getValue (fval), stateValue_getValue (tval)));
10370 sctable = metaStateInfo_getMergeTable (minfo);
10372 DPRINTF (("Merge table: %s",
10373 stateCombinationTable_unparse (sctable)));
10375 msg = cstring_undefined;
10377 nval = stateCombinationTable_lookup (sctable,
10378 stateValue_getValue (fval),
10379 stateValue_getValue (tval),
10382 DPRINTF (("nval: %d / %d / %d", nval,
10383 stateValue_getValue (fval), stateValue_getValue (tval)));
10385 if (nval == stateValue_error)
10387 /*@i32 print extra info for assignments@*/
10389 if (uentry_isGlobalMarker (res))
10394 ("Control branches merge with incompatible global states (%s and %s)%q",
10395 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10396 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10397 cstring_isDefined (msg)
10398 ? message (": %s", msg) : cstring_undefined),
10401 sRef_showMetaStateInfo (res->sref, fkey);
10402 sRef_showMetaStateInfo (other->sref, fkey);
10410 ("Control branches merge with incompatible states for %q (%s and %s)%q",
10411 uentry_getName (res),
10412 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10413 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10414 cstring_isDefined (msg)
10415 ? message (": %s", msg) : cstring_undefined),
10418 sRef_showMetaStateInfo (res->sref, fkey);
10419 sRef_showMetaStateInfo (other->sref, fkey);
10420 DPRINTF (("Res: %s", sRef_unparseFull (res->sref)));
10421 DPRINTF (("Other: %s", sRef_unparseFull (other->sref)));
10422 DPRINTF (("Null: %s / %s",
10423 bool_unparse (usymtab_isDefinitelyNull (res->sref)),
10424 bool_unparse (usymtab_isDefinitelyNull (other->sref))));
10430 if (nval == stateValue_getValue (fval)
10431 && nval != stateValue_getValue (tval))
10433 loc = stateValue_getLoc (fval);
10435 else if (nval == stateValue_getValue (tval)
10436 && nval != stateValue_getValue (fval))
10438 loc = stateValue_getLoc (tval);
10445 if (stateValue_getValue (sRef_getMetaStateValue (res->sref, fkey)) == nval
10446 && nval == stateValue_getValue (fval)
10447 && nval == stateValue_getValue (tval))
10453 sRef_setMetaStateValueComplete (res->sref, fkey, nval, loc);
10457 } end_valueTable_elements ;
10463 uentry_mergeSetStates (/*@notnull@*/ uentry res,
10464 /*@notnull@*/ uentry other, /*@unused@*/ fileloc loc,
10465 bool flip, clause cl)
10467 if (cl == DOWHILECLAUSE)
10469 res->used = other->used || res->used;
10470 res->lset = other->lset || res->lset;
10471 res->uses = filelocList_append (res->uses, other->uses);
10472 other->uses = filelocList_undefined;
10476 if (sRef_isMacroParamRef (res->sref)
10477 && !uentry_isSefParam (other)
10478 && !uentry_isSefParam (res))
10480 bool hasError = FALSE;
10482 if (bool_equal (res->used, other->used))
10484 res->used = other->used;
10488 if (other->used && !flip)
10493 message ("Macro parameter %q used in true clause, "
10494 "but not in false clause",
10495 uentry_getName (res)),
10496 uentry_whereDeclared (res));
10503 message ("Macro parameter %q used in false clause, "
10504 "but not in true clause",
10505 uentry_getName (res)),
10506 uentry_whereDeclared (res));
10512 /* make it sef now, prevent more errors */
10513 res->info->var->kind = VKREFSEFPARAM;
10519 res->used = other->used || res->used;
10520 res->lset = other->lset || res->lset;
10521 res->uses = filelocList_append (res->uses, other->uses);
10522 other->uses = filelocList_undefined;
10528 uentry_mergeState (uentry res, uentry other, fileloc loc,
10529 bool mustReturn, bool flip, bool opt,
10532 llassert (uentry_isValid (res));
10533 llassert (uentry_isValid (other));
10535 llassert (res->ukind == other->ukind);
10536 llassert (res->ukind == KVAR);
10538 DPRINTF (("Merge state: %s / %s", uentry_unparseFull (res),
10539 uentry_unparseFull (other)));
10541 uentry_mergeAliasStates (res, other, loc, mustReturn, flip, opt, cl);
10542 uentry_mergeValueStates (res, other, loc, mustReturn, flip);
10543 uentry_mergeSetStates (res, other, loc, flip, cl);
10545 DPRINTF (("Merge ==> %s", uentry_unparseFull (res)));
10548 void uentry_setUsed (uentry e, fileloc loc)
10550 static bool firstTime = TRUE;
10551 static bool showUses = FALSE;
10552 static bool exportLocal = FALSE;
10554 DPRINTF (("Used: %s / %s", uentry_unparse (e), fileloc_unparse (loc)));
10558 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
10560 showUses = context_getFlag (FLG_SHOWUSES);
10561 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
10566 if (uentry_isValid (e))
10570 if (warnClause_isDefined (e->warn))
10572 flagSpec flg = warnClause_getFlag (e->warn);
10575 if (warnClause_hasMessage (e->warn))
10577 msg = cstring_copy (warnClause_getMessage (e->warn));
10581 msg = message ("Use of possibly dangerous %s",
10582 uentry_ekindNameLC (e));
10586 message ("%q: %q", msg, uentry_getName (e)),
10590 if (sRef_isMacroParamRef (e->sref))
10592 if (uentry_isYield (e) || uentry_isSefParam (e))
10598 if (context_inConditional ())
10602 message ("Macro parameter %q used in conditionally "
10603 "executed code (may or may not be "
10604 "evaluated exactly once)",
10605 uentry_getName (e)),
10608 e->info->var->kind = VKREFSEFPARAM;
10617 message ("Macro parameter %q used more than once",
10618 uentry_getName (e)),
10619 uentry_whereDeclared (e)))
10621 e->info->var->kind = VKREFSEFPARAM;
10628 if ((dp = uentry_directParamNo (e)) >= 0)
10630 uentry_setUsed (usymtab_getParam (dp), loc);
10635 if (!sRef_isLocalVar (e->sref))
10639 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
10645 if (context_inMacro ())
10647 e->uses = filelocList_addUndefined (e->uses);
10651 e->uses = filelocList_addDifferentFile
10653 uentry_whereDeclared (e),
10662 bool uentry_isReturned (uentry u)
10664 return (uentry_isValid (u) && uentry_isVar (u)
10665 && (u->info->var->kind == VKRETPARAM
10666 || u->info->var->kind == VKSEFRETPARAM));
10671 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args)
10673 llassert (uentry_isRealFunction (u));
10675 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
10677 stateClauseList clauses = uentry_getStateClauseList (u);
10678 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10680 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
10681 sRef_setAllocated (res, g_currentloc);
10683 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10684 stateClauseList_unparse (clauses)));
10687 ** This should be in exprNode_reflectEnsuresClause
10690 stateClauseList_postElements (clauses, cl)
10692 if (!stateClause_isGlobal (cl))
10694 sRefSet refs = stateClause_getRefs (cl);
10695 sRefMod modf = stateClause_getEffectFunction (cl);
10697 sRefSet_elements (refs, el)
10699 sRef base = sRef_getRootBase (el);
10701 if (sRef_isResult (base))
10705 sRef sr = sRef_fixBase (el, res);
10706 modf (sr, g_currentloc);
10713 } end_sRefSet_elements ;
10715 } end_stateClauseList_postElements ;
10723 sRefSet prefs = sRefSet_new ();
10724 sRef res = sRef_undefined;
10725 sRef tcref = sRef_undefined;
10726 sRef tref = sRef_undefined;
10729 params = uentry_getParams (u);
10732 ** Setting up aliases has to happen *after* setting null state!
10735 uentryList_elements (params, current)
10737 if (uentry_isReturned (current))
10739 if (exprNodeList_size (args) >= paramno)
10741 exprNode ecur = exprNodeList_nth (args, paramno);
10742 tref = exprNode_getSref (ecur);
10744 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10746 if (sRef_isValid (tref))
10748 tcref = sRef_copy (tref);
10750 if (sRef_isDead (tcref))
10752 sRef_setDefined (tcref, g_currentloc);
10753 sRef_setOnly (tcref, g_currentloc);
10756 if (sRef_isRefCounted (tcref))
10758 /* could be a new ref now (but only if its returned) */
10759 sRef_setAliasKindComplete (tcref, AK_ERROR, g_currentloc);
10762 sRef_makeSafe (tcref);
10763 prefs = sRefSet_insert (prefs, tcref);
10769 } end_uentryList_elements ;
10771 if (sRefSet_size (prefs) > 0)
10773 nstate n = sRef_getNullState (u->sref);
10775 if (sRefSet_size (prefs) == 1)
10777 sRef rref = sRefSet_choose (prefs);
10779 res = sRef_makeType (sRef_getType (rref));
10780 sRef_copyState (res, tref);
10784 /* should this ever happen? */ /*@i534 evans 2001-05-27 */
10785 res = sRefSet_mergeIntoOne (prefs);
10788 if (nstate_isKnown (n))
10790 sRef_setNullState (res, n, g_currentloc);
10791 DPRINTF (("Setting null: %s", sRef_unparseFull (res)));
10796 if (ctype_isFunction (u->utype))
10798 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10799 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10803 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10804 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
10807 if (sRef_isRefCounted (res))
10809 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10813 if (sRef_getNullState (res) == NS_ABSNULL)
10815 ctype ct = ctype_realType (u->utype);
10817 if (ctype_isAbstract (ct))
10819 sRef_setNotNull (res, g_currentloc);
10823 if (ctype_isUser (ct))
10825 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
10829 sRef_setNotNull (res, g_currentloc);
10834 if (sRef_isRefCounted (res))
10836 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10838 else if (sRef_isKillRef (res))
10840 sRef_setAliasKind (res, AK_REFCOUNTED, g_currentloc);
10847 ak = sRef_getAliasKind (res);
10849 if (alkind_isImplicit (ak))
10851 sRef_setAliasKind (res, alkind_fixImplicit (ak), g_currentloc);
10855 DPRINTF (("Aliasing: %s / %s", sRef_unparseFull (res), sRef_unparseFull (tref)));
10856 usymtab_addReallyForceMustAlias (tref, res); /* evans 2001-05-27 */
10858 /* evans 2002-03-03 - need to be symettric explicitly, since its not a local now */
10859 usymtab_addReallyForceMustAlias (res, tref);
10862 sRefSet_free (prefs);
10864 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
10870 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args, fileloc loc)
10872 llassert (uentry_isRealFunction (u));
10874 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
10876 stateClauseList clauses = uentry_getStateClauseList (u);
10877 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10879 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
10880 sRef_setAllocated (res, loc);
10882 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10883 stateClauseList_unparse (clauses)));
10886 ** This should be in exprNode_reflectEnsuresClause
10889 stateClauseList_postElements (clauses, cl)
10891 if (!stateClause_isGlobal (cl))
10893 sRefSet refs = stateClause_getRefs (cl);
10894 sRefMod modf = stateClause_getEffectFunction (cl);
10896 sRefSet_elements (refs, el)
10898 sRef base = sRef_getRootBase (el);
10900 if (sRef_isResult (base))
10904 sRef sr = sRef_fixBase (el, res);
10912 } end_sRefSet_elements ;
10914 } end_stateClauseList_postElements ;
10922 sRefSet prefs = sRefSet_new ();
10923 sRef res = sRef_undefined;
10926 params = uentry_getParams (u);
10928 uentryList_elements (params, current)
10930 if (uentry_isReturned (current))
10932 if (exprNodeList_size (args) >= paramno)
10934 exprNode ecur = exprNodeList_nth (args, paramno);
10935 sRef tref = exprNode_getSref (ecur);
10937 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10939 if (sRef_isValid (tref))
10941 sRef tcref = sRef_copy (tref);
10943 usymtab_addForceMustAlias (tcref, tref); /* evans 2001-05-27 */
10945 if (sRef_isNew (tcref))
10947 /* tcref->kind = SK_OBJECT; */ /*!! Not new anymore */
10950 if (sRef_isDead (tcref))
10952 sRef_setDefined (tcref, loc);
10953 sRef_setOnly (tcref, loc);
10956 if (sRef_isRefCounted (tcref))
10958 /* could be a new ref now (but only if its returned) */
10959 sRef_setAliasKindComplete (tcref, AK_ERROR, loc);
10962 sRef_makeSafe (tcref);
10963 DPRINTF (("Returns tcref / %s", sRef_unparseFull (tcref)));
10964 prefs = sRefSet_insert (prefs, tcref);
10970 } end_uentryList_elements ;
10972 if (sRefSet_size (prefs) > 0)
10974 nstate n = sRef_getNullState (u->sref);
10976 if (sRefSet_size (prefs) == 1)
10978 res = sRefSet_choose (prefs);
10982 /* should this ever happen? */ /*@i534 evans 2001-05-27 */
10983 res = sRefSet_mergeIntoOne (prefs);
10986 if (nstate_isKnown (n))
10988 sRef_setNullState (res, n, loc);
10993 if (ctype_isFunction (u->utype))
10995 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10996 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
11000 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
11003 if (sRef_isRefCounted (res))
11005 sRef_setAliasKind (res, AK_NEWREF, loc);
11010 if (sRef_getNullState (res) == NS_ABSNULL)
11012 ctype ct = ctype_realType (u->utype);
11014 if (ctype_isAbstract (ct))
11016 sRef_setNotNull (res, loc);
11020 if (ctype_isUser (ct))
11022 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
11026 sRef_setNotNull (res, loc);
11031 if (sRef_isRefCounted (res))
11033 sRef_setAliasKind (res, AK_NEWREF, loc);
11035 else if (sRef_isKillRef (res))
11037 sRef_setAliasKind (res, AK_REFCOUNTED, loc);
11044 ak = sRef_getAliasKind (res);
11046 if (alkind_isImplicit (ak))
11048 sRef_setAliasKind (res,
11049 alkind_fixImplicit (ak),
11053 sRefSet_free (prefs);
11056 if (sRef_isOnly (res))
11058 sRef_setFresh (res, loc);
11062 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
11067 static bool uentry_isRefCounted (uentry ue)
11069 ctype ct = uentry_getType (ue);
11071 if (ctype_isFunction (ct))
11073 return (ctype_isRefCounted (ctype_getReturnType (ct)));
11077 return (ctype_isRefCounted (ct));
11082 ** old was declared yield in the specification.
11083 ** new is declared in the iter implementation.
11086 void uentry_checkYieldParam (uentry old, uentry unew)
11090 llassert (uentry_isVariable (old));
11091 llassert (uentry_isVariable (unew));
11093 unew->info->var->kind = VKYIELDPARAM;
11094 (void) checkTypeConformance (old, unew, TRUE);
11095 checkVarConformance (old, unew, TRUE, FALSE);
11097 /* get rid of param marker */
11099 name = uentry_getName (unew);
11100 cstring_free (unew->uname);
11101 unew->uname = name;
11102 unew->info->var->kind = VKREFYIELDPARAM;
11104 uentry_setUsed (old, fileloc_undefined);
11105 uentry_setUsed (unew, fileloc_undefined);
11108 /*@observer@*/ cstring
11109 uentry_ekindName (uentry ue)
11111 if (uentry_isValid (ue))
11116 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
11118 return cstring_makeLiteralTemp ("Datatype");
11120 return cstring_makeLiteralTemp ("Enum member");
11122 return cstring_makeLiteralTemp ("Constant");
11124 if (uentry_isParam (ue))
11126 return cstring_makeLiteralTemp ("Parameter");
11128 else if (uentry_isExpandedMacro (ue))
11130 return cstring_makeLiteralTemp ("Expanded macro");
11134 return cstring_makeLiteralTemp ("Variable");
11137 return cstring_makeLiteralTemp ("Function");
11139 return cstring_makeLiteralTemp ("Iterator");
11141 return cstring_makeLiteralTemp ("Iterator finalizer");
11143 return cstring_makeLiteralTemp ("Struct tag");
11145 return cstring_makeLiteralTemp ("Union tag");
11147 return cstring_makeLiteralTemp ("Enum tag");
11149 return cstring_makeLiteralTemp ("Optional parameters");
11154 return cstring_makeLiteralTemp ("<Undefined>");
11160 /*@observer@*/ cstring
11161 uentry_ekindNameLC (uentry ue)
11163 if (uentry_isValid (ue))
11168 return cstring_makeLiteralTemp ("<error: invalid uentry>");
11170 return cstring_makeLiteralTemp ("datatype");
11172 return cstring_makeLiteralTemp ("enum member");
11174 return cstring_makeLiteralTemp ("constant");
11176 if (uentry_isParam (ue))
11178 return cstring_makeLiteralTemp ("parameter");
11180 else if (uentry_isExpandedMacro (ue))
11182 return cstring_makeLiteralTemp ("expanded macro");
11186 return cstring_makeLiteralTemp ("variable");
11189 return cstring_makeLiteralTemp ("function");
11191 return cstring_makeLiteralTemp ("iterator");
11193 return cstring_makeLiteralTemp ("iterator finalizer");
11195 return cstring_makeLiteralTemp ("struct tag");
11197 return cstring_makeLiteralTemp ("union tag");
11199 return cstring_makeLiteralTemp ("enum tag");
11201 return cstring_makeLiteralTemp ("optional parameters");
11206 return cstring_makeLiteralTemp ("<Undefined>");
11212 void uentry_setHasNameError (uentry ue)
11214 llassert (uentry_isValid (ue));
11216 ue->hasNameError = TRUE;
11219 void uentry_checkName (uentry ue)
11221 DPRINTF (("Checking name: %s / %s / %s", uentry_unparse (ue),
11222 uentry_observeRealName (ue),
11223 bool_unparse (uentry_isVisibleExternally (ue))));
11225 if (uentry_isValid (ue)
11226 && !context_inXHFile ()
11227 && uentry_hasName (ue)
11228 && !uentry_isElipsisMarker (ue)
11229 && context_getFlag (FLG_NAMECHECKS)
11230 && !ue->hasNameError
11231 && !uentry_isEndIter (ue)
11232 && !fileloc_isBuiltin (uentry_whereLast (ue))
11233 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
11235 DPRINTF (("Here..."));
11237 if (uentry_isPriv (ue))
11239 ; /* any checks here? */
11241 else if (fileloc_isExternal (uentry_whereDefined (ue)))
11243 ; /* no errors for externals */
11249 if (uentry_isExpandedMacro (ue))
11255 if (uentry_isExpandedMacro (ue))
11259 else if (uentry_isVariable (ue))
11261 sRef sr = uentry_getSref (ue);
11263 if (sRef_isValid (sr))
11265 scope = sRef_getScope (sr);
11272 else if (uentry_isFunction (ue)
11273 || uentry_isIter (ue)
11274 || uentry_isEndIter (ue)
11275 || uentry_isConstant (ue))
11277 scope = uentry_isStatic (ue) ? fileScope : globScope;
11279 else /* datatypes, etc. must be global */
11284 usymtab_checkDistinctName (ue, scope);
11287 if (context_getFlag (FLG_CPPNAMES))
11292 if (scope == globScope)
11294 checkExternalName (ue);
11296 else if (scope == fileScope)
11298 checkFileScopeName (ue);
11302 checkLocalName (ue);
11306 checkAnsiName (ue);
11311 /*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@only@*/ fileloc loc)
11317 ** Can't but unrecognized ids in macros in global scope, because srefs will break!
11320 if (!context_inMacro ())
11322 sRef_setGlobalScopeSafe ();
11325 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
11326 uentry_setUsed (ue, loc);
11328 tloc = fileloc_createExternal ();
11329 uentry_setDefined (ue, tloc);
11330 fileloc_free (tloc);
11331 uentry_setHasNameError (ue);
11333 if (context_getFlag (FLG_REPEATUNRECOG) || (context_inOldSytleScope() ) )
11335 uentry_markOwned (ue);
11339 ue = usymtab_supReturnFileEntry (ue);
11342 if (!context_inMacro ())
11344 sRef_clearGlobalScopeSafe ();
11350 uentry uentry_makeGlobalMarker ()
11355 llassert (sRef_inGlobalScope ());
11357 ue = uentry_makeVariableAux
11358 (GLOBAL_MARKER_NAME, ctype_unknown, fileloc_undefined,
11359 sRef_makeGlobalMarker (),
11362 tloc = fileloc_createExternal ();
11363 uentry_setUsed (ue, tloc);
11364 uentry_setDefined (ue, tloc);
11365 fileloc_free (tloc);
11366 uentry_setHasNameError (ue);
11372 bool uentry_isGlobalMarker (uentry ue)
11374 return (uentry_isValid (ue)
11375 && (cstring_equal (uentry_rawName (ue), GLOBAL_MARKER_NAME)));
11378 /* new start modifications */
11380 /* start modifications */
11382 requires: p_e is defined, is a ptr/array variable
11384 effects: sets the state of the variable
11388 void uentry_setPossiblyNullTerminatedState (uentry p_e)
11390 llassert (uentry_isValid (p_e));
11392 if (p_e->info != NULL)
11394 if (p_e->info->var != NULL)
11396 llassert (p_e->info->var->bufinfo != NULL);
11397 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
11398 sRef_setPossiblyNullTerminatedState (p_e->sref);
11404 requires: p_e is defined, is a ptr/array variable
11406 effects: sets the size of the buffer
11409 void uentry_setNullTerminatedState (uentry p_e) {
11410 llassert (uentry_isValid (p_e));
11412 if (p_e->info != NULL)
11414 if (p_e->info->var != NULL)
11416 llassert (p_e->info->var->bufinfo != NULL);
11417 p_e->info->var->bufinfo->bufstate = BB_NULLTERMINATED;
11418 sRef_setNullTerminatedState (p_e->sref);
11424 requires: p_e is defined, is a ptr/array variable
11426 effects: sets the size of the buffer
11429 void uentry_setSize (uentry p_e, int size)
11431 if (uentry_isValid (p_e))
11433 if (p_e->info != NULL)
11435 if (p_e->info->var != NULL)
11437 llassert (p_e->info->var->bufinfo != NULL);
11438 p_e->info->var->bufinfo->size = size;
11439 sRef_setSize (p_e->sref, size);
11446 requires: p_e is defined, is a ptr/array variable
11448 effects: sets the length of the buffer
11451 void uentry_setLen (uentry p_e, int len)
11453 if (uentry_isValid (p_e))
11455 if (p_e->info != NULL
11456 && p_e->info->var != NULL)
11458 llassert (p_e->info->var->bufinfo != NULL);
11459 p_e->info->var->bufinfo->len = len;
11460 sRef_setLen (p_e->sref, len);
11467 bool uentry_hasMetaStateEnsures (uentry e)
11469 if (uentry_isValid (e) && uentry_isFunction (e))
11471 return functionConstraint_hasMetaStateConstraint (e->info->fcn->postconditions);
11479 metaStateConstraintList uentry_getMetaStateEnsures (uentry e)
11481 llassert (uentry_isValid (e) && uentry_isFunction (e));
11482 return functionConstraint_getMetaStateConstraints (e->info->fcn->postconditions);
11485 # ifdef DEBUGSPLINT
11488 ** For debugging only
11491 void uentry_checkValid (uentry ue)
11493 if (uentry_isValid (ue))
11495 sRef_checkCompletelyReasonable (ue->sref);