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 cstring_makeLiteral ("Only one globals clause may be used. The second globals clause is ignored."),
1067 globalsClause_getLoc (glc));
1070 uentry_setGlobals (ue, globalsClause_takeGlobs (glc));
1075 DPRINTF (("Taking globs: %s", globalsClause_unparse (glc)));
1076 uentry_setGlobals (ue, globalsClause_takeGlobs (glc));
1077 DPRINTF (("Taking globs after: %s", globalsClause_unparse (glc)));
1080 else if (functionClause_isModifies (el))
1082 modifiesClause mlc = functionClause_getModifies (el);
1084 DPRINTF (("Has modifies: %s", uentry_unparseFull (ue)));
1086 if (uentry_hasMods (ue))
1094 ("Multiple modifies clauses for %s: %s",
1095 uentry_getName (ue),
1096 modifiesClause_unparse (mlc)),
1097 modifiesClause_getLoc (mlc)))
1099 llhint (message ("Previous modifies clause: ",
1100 sRefSet_unparse (uentry_getMods (ue))));
1106 uentry_combineModifies (ue, modifiesClause_takeMods (mlc)); /*@i32@*/
1110 uentry_setModifies (ue, modifiesClause_takeMods (mlc));
1113 else if (functionClause_isEnsures (el))
1115 functionConstraint cl = functionClause_takeEnsures (el);
1116 DPRINTF (("Setting post: %s / %s",
1117 uentry_unparse (ue), functionConstraint_unparse (cl)));
1118 uentry_setPostconditions (ue, cl);
1120 else if (functionClause_isRequires (el))
1122 functionConstraint cl = functionClause_takeRequires (el);
1123 uentry_setPreconditions (ue, cl);
1125 else if (functionClause_isState (el))
1127 stateClause sc = functionClause_takeState (el);
1129 if (stateClause_isBefore (sc) && stateClause_setsMetaState (sc))
1131 sRefSet rfs = stateClause_getRefs (sc);
1133 sRefSet_elements (rfs, s)
1135 if (sRef_isParam (s))
1138 ** Can't use requires on parameters
1142 (FLG_ANNOTATIONERROR,
1143 message ("Requires clauses for %q concerns parameters %q should be "
1144 "a parameter annotation instead: %q",
1145 uentry_unparse (ue),
1147 stateClause_unparse (sc)),
1148 stateClause_loc (sc));
1150 } end_sRefSet_elements ;
1153 DPRINTF (("State clause: %s", stateClause_unparse (sc)));
1154 uentry_addStateClause (ue, sc);
1156 else if (functionClause_isWarn (el))
1158 warnClause wc = functionClause_takeWarn (el);
1159 uentry_addWarning (ue, wc);
1163 DPRINTF (("Unhandled clause: %s", functionClause_unparse (el)));
1165 } end_functionClauseList_elements ;
1167 DPRINTF (("Checking all: %s", sRef_unparseFull (ue->sref)));
1168 stateClauseList_checkAll (ue);
1171 /*@notnull@*/ uentry uentry_makeIdFunction (idDecl id)
1173 bool leaveFunc = FALSE;
1175 uentry_makeFunction (idDecl_observeId (id), idDecl_getCtype (id),
1176 typeId_invalid, globSet_undefined,
1177 sRefSet_undefined, warnClause_undefined,
1180 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1183 ** This makes parameters names print out correctly.
1184 ** (But we might be a local variable declaration for a function type...)
1187 if (context_inFunctionLike ())
1189 DPRINTF (("Header: %s / %s",
1190 uentry_unparse (context_getHeader ()),
1191 idDecl_unparse (id)));
1195 context_enterFunctionDeclaration (ue);
1199 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1200 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
1201 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1202 reflectImplicitFunctionQualifiers (ue, FALSE);
1203 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1204 uentry_reflectClauses (ue, idDecl_getClauses (id));
1205 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1207 if (!uentry_isStatic (ue)
1208 && cstring_equalLit (ue->uname, "main"))
1210 ctype typ = ue->utype;
1214 llassert (ctype_isFunction (typ));
1216 retval = ctype_getReturnType (typ);
1218 if (!ctype_isInt (retval))
1222 message ("Function main declared to return %s, should return int",
1223 ctype_unparse (retval)),
1224 uentry_whereDeclared (ue));
1227 args = ctype_argsFunction (typ);
1229 if (uentryList_isMissingParams (args)
1230 || uentryList_size (args) == 0)
1236 if (uentryList_size (args) != 2)
1240 message ("Function main declared with %d arg%&, "
1241 "should have 2 (int argc, char *argv[])",
1242 uentryList_size (args)),
1243 uentry_whereLast (ue));
1247 uentry arg = uentryList_getN (args, 0);
1248 ctype ct = uentry_getType (arg);
1250 if (!ctype_isInt (ct))
1254 message ("Parameter 1, %q, of function main declared "
1255 "with type %t, should have type int",
1256 uentry_getName (arg), ct),
1257 uentry_whereDeclared (arg));
1260 arg = uentryList_getN (args, 1);
1261 ct = uentry_getType (arg);
1263 if (ctype_isArrayPtr (ct)
1264 && ctype_isArrayPtr (ctype_baseArrayPtr (ct))
1265 && ctype_isChar (ctype_baseArrayPtr (ctype_baseArrayPtr (ct))))
1273 message ("Parameter 2, %q, of function main declared "
1274 "with type %t, should have type char **",
1275 uentry_getName (arg), ct),
1276 uentry_whereDeclared (arg));
1284 context_exitFunctionDeclaration ();
1290 static void uentry_implicitParamAnnots (/*@notnull@*/ uentry e)
1292 alkind ak = sRef_getAliasKind (e->sref);
1294 if ((alkind_isUnknown (ak) || alkind_isImplicit (ak))
1295 && context_getFlag (FLG_PARAMIMPTEMP))
1297 exkind ek = sRef_getExKind (e->sref);
1299 if (exkind_isKnown (ek))
1301 DPRINTF (("imp dep: %s", uentry_unparseFull (e)));
1302 sRef_setAliasKind (e->sref, AK_IMPDEPENDENT, fileloc_undefined);
1303 sRef_setOrigAliasKind (e->sref, AK_IMPDEPENDENT);
1307 sRef_setAliasKind (e->sref, AK_IMPTEMP, fileloc_undefined);
1308 sRef_setOrigAliasKind (e->sref, AK_IMPTEMP);
1313 static /*@only@*/ /*@notnull@*/ uentry
1314 uentry_makeVariableParamAux (cstring n, ctype t, /*@dependent@*/ sRef s,
1315 /*@only@*/ fileloc loc, sstate defstate) /*@i32 exposed*/
1317 cstring pname = makeParam (n);
1320 DPRINTF (("Sref: %s", sRef_unparseFull (s)));
1321 e = uentry_makeVariableAux (pname, t, loc, s, FALSE, VKPARAM);
1323 cstring_free (pname);
1324 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1325 uentry_implicitParamAnnots (e);
1326 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1328 if (!sRef_isAllocated (e->sref) && !sRef_isPartial (e->sref))
1330 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1331 sRef_setDefState (e->sref, defstate, uentry_whereDeclared (e));
1332 e->info->var->defstate = defstate;
1335 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1340 uentry_setRefCounted (uentry e)
1342 if (uentry_isValid (e))
1344 uentry_setAliasKind (e, AK_REFCOUNTED);
1345 sRef_storeState (e->sref);
1350 uentry_setStatic (uentry c)
1352 if (uentry_isValid (c))
1354 alkind ak = sRef_getAliasKind (c->sref);
1355 c->storageclass = SCSTATIC;
1357 if (uentry_isVariable (c) && !ctype_isFunction (uentry_getType (c)))
1359 if (!alkind_isUnknown (ak)
1360 && !alkind_isStatic (ak))
1362 if (!(ctype_isRealPointer (uentry_getType (c)))
1363 && !(ctype_isAbstract (ctype_realType (uentry_getType (c))))
1364 && !alkind_isRefCounted (ak))
1366 if (alkind_isImplicit (ak)
1367 && alkind_isDependent (ak)
1368 && ctype_isArray (uentry_getType (c)))
1370 ; /* no error for observer arrays */
1376 message ("Static storage %q declared as %s",
1378 alkind_unparse (ak)),
1379 uentry_whereDeclared (c));
1385 if (alkind_isUnknown (ak)
1386 || (alkind_isImplicit (sRef_getAliasKind (c->sref))
1387 && !alkind_isDependent (sRef_getAliasKind (c->sref))))
1389 sRef_setAliasKind (c->sref, AK_STATIC, fileloc_undefined);
1390 sRef_setOrigAliasKind (c->sref, AK_STATIC);
1398 uentry_setExtern (uentry c)
1400 if (uentry_isValid (c))
1401 c->storageclass = SCEXTERN;
1405 uentry_setParamNo (uentry ue, int pno)
1407 llassert (uentry_isAnyParam (ue) && sRef_isParam (ue->sref));
1408 sRef_setParamNo (ue->sref, pno);
1412 void checkGlobalsModifies (/*@notnull@*/ uentry ue, sRefSet sr)
1414 sRefSet_allElements (sr, el)
1416 sRef base = sRef_getRootBase (el);
1418 if (sRef_isFileOrGlobalScope (base) || sRef_isInternalState (base)
1419 || (sRef_isKindSpecial (base) && !sRef_isNothing (base)))
1421 if (!globSet_member (ue->info->fcn->globs, base))
1423 if (uentry_hasGlobs (ue)
1424 || context_getFlag (FLG_WARNMISSINGGLOBALSNOGLOBS))
1427 (FLG_WARNMISSINGGLOBALS,
1429 ("Modifies list for %q uses global %q, "
1430 "not included in globals list.",
1431 uentry_getName (ue),
1432 sRef_unparse (base)),
1433 uentry_whereLast (ue)))
1435 uentry_showWhereSpecified (ue);
1439 ue->info->fcn->globs = globSet_insert (ue->info->fcn->globs,
1441 if (sRef_isFileStatic (base))
1443 context_recordFileGlobals (ue->info->fcn->globs);
1447 } end_sRefSet_allElements;
1451 uentry_makeVariableSrefParam (cstring n, ctype t, /*@only@*/ fileloc loc, /*@exposed@*/ sRef s)
1453 return (uentry_makeVariableParamAux (n, t, s, loc, SS_UNKNOWN));
1457 uentry_fixupSref (uentry ue)
1461 if (uentry_isUndefined (ue) || uentry_isElipsisMarker (ue))
1466 sr = uentry_getSref (ue);
1468 sRef_resetState (sr);
1469 sRef_clearDerived (sr);
1471 llassertprint (uentry_isVariable (ue), ("fixing: %s", uentry_unparseFull (ue)));
1472 llassert (sRef_isValid (sr));
1474 if (uentry_isVariable (ue))
1477 /*@i634 ue->sref = sRef_saveCopyShallow (ue->info->var->origsref); */
1478 sRef_setDefState (sr, ue->info->var->defstate, fileloc_undefined);
1479 sRef_setNullState (sr, ue->info->var->nullstate, fileloc_undefined);
1483 static void uentry_addStateClause (/*@notnull@*/ uentry ue, stateClause sc)
1486 ** Okay to allow multiple clauses of the same kind.
1487 */ /*@i834 is this true?@*/
1489 ue->info->fcn->specclauses =
1490 stateClauseList_add (ue->info->fcn->specclauses, sc);
1492 /* Will call checkAll to check later... */
1495 void uentry_setStateClauseList (uentry ue, stateClauseList clauses)
1497 llassert (uentry_isFunction (ue));
1498 llassert (!stateClauseList_isDefined (ue->info->fcn->specclauses));
1500 DPRINTF (("checked clauses: %s", stateClauseList_unparse (clauses)));
1501 ue->info->fcn->specclauses = clauses;
1502 stateClauseList_checkAll (ue);
1503 DPRINTF (("checked clauses: %s", uentry_unparseFull (ue)));
1507 ** Used for @modifies@ @endmodifies@ syntax.
1509 ** If ue is specified, sr must contain *only*:
1511 ** o file static globals
1512 ** o sRef's derived from modifies spec (i.e., more specific than
1513 ** what was specified)
1515 ** Otherwise, if sr has modifies it must match sr.
1517 ** If it doesn't have modifies, set them to sr.
1521 uentry_checkModifiesContext (void)
1523 if (sRef_modInFunction ())
1527 ("Modifies list not in function context. "
1528 "A modifies list can only appear following the parameter list "
1529 "in a function declaration or header."));
1538 uentry_setModifies (uentry ue, /*@owned@*/ sRefSet sr)
1540 if (!uentry_checkModifiesContext ())
1546 if (uentry_isValid (ue))
1548 if (uentry_isIter (ue))
1550 llassert (sRefSet_isUndefined (ue->info->iter->mods));
1551 ue->info->iter->mods = sr;
1555 uentry_convertVarFunction (ue);
1556 llassertfatal (uentry_isFunction (ue));
1557 llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1559 ue->info->fcn->mods = sr;
1560 ue->info->fcn->hasMods = TRUE;
1562 checkGlobalsModifies (ue, sr);
1565 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1567 ue->info->fcn->hasGlobs = TRUE;
1570 if (sRefSet_hasStatic (ue->info->fcn->mods))
1572 context_recordFileModifies (ue->info->fcn->mods);
1582 uentry_combineModifies (uentry ue, /*@owned@*/ sRefSet sr)
1585 ** Function already has one modifies clause (possibly from
1586 ** a specification).
1589 if (!uentry_checkModifiesContext ())
1594 llassert (uentry_isValid (ue));
1596 if (uentry_isIter (ue))
1598 ue->info->iter->mods = sRefSet_unionFree (ue->info->iter->mods, sr);
1602 llassertfatal (uentry_isFunction (ue));
1603 llassert (ue->info->fcn->hasMods);
1605 checkGlobalsModifies (ue, sr);
1606 ue->info->fcn->mods = sRefSet_unionFree (ue->info->fcn->mods, sr);
1608 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1610 ue->info->fcn->hasGlobs = TRUE;
1614 if (sRefSet_hasStatic (ue->info->fcn->mods))
1616 context_recordFileModifies (ue->info->fcn->mods);
1620 bool uentry_hasWarning (uentry ue)
1622 return (uentry_isValid (ue)
1623 && warnClause_isDefined (ue->warn));
1626 void uentry_addWarning (uentry ue, /*@only@*/ warnClause warn)
1628 llassert (uentry_isValid (ue));
1629 llassert (warnClause_isUndefined (ue->warn));
1634 uentry_setPreconditions (uentry ue, /*@only@*/ functionConstraint preconditions)
1636 if (sRef_modInFunction ())
1639 (message ("Precondition list not in function context. "
1640 "A precondition list can only appear following the parameter list "
1641 "in a function declaration or header."));
1643 /*@-mustfree@*/ return; /*@=mustfree@*/
1646 if (uentry_isValid (ue))
1648 uentry_convertVarFunction (ue);
1649 llassertfatal (uentry_isFunction (ue));
1651 if (functionConstraint_isDefined (ue->info->fcn->preconditions))
1653 /*drl oops this date is wronge...*/
1655 I changed this so it didn't appear as a Splint bug
1656 among other things this gets triggered when there is
1657 a function with two requires clauses. Now Splint
1658 prints an error and tries to conjoin the lists.
1661 (message ("Duplicate precondition list"
1662 "Attemping the conjoin the requires clauses"
1666 /* should conjoin constraints? */
1668 ue->info->fcn->preconditions = functionConstraint_conjoin (ue->info->fcn->preconditions, preconditions);
1672 ue->info->fcn->preconditions = preconditions;
1677 llfatalbug ((message("uentry_setPreconditions called with invalid uentry") ));
1686 uentry_setPostconditions (uentry ue, /*@only@*/ functionConstraint postconditions)
1688 if (sRef_modInFunction ())
1691 (message ("Postcondition list not in function context. "
1692 "A postcondition list can only appear following the parameter list "
1693 "in a function declaration or header."));
1695 /*@-mustfree@*/ return; /*@=mustfree@*/
1698 if (uentry_isValid (ue))
1700 uentry_convertVarFunction (ue);
1701 llassertfatal (uentry_isFunction (ue));
1703 if (functionConstraint_isUndefined (ue->info->fcn->postconditions))
1705 ue->info->fcn->postconditions = postconditions;
1709 ue->info->fcn->postconditions = functionConstraint_conjoin (ue->info->fcn->postconditions, postconditions);
1714 llfatalbug ((message("uentry_setPostconditions called with invalid uentry") ));
1719 ** requires: new and old are functions
1723 checkGlobalsConformance (/*@notnull@*/ uentry old,
1724 /*@notnull@*/ uentry unew,
1725 bool mustConform, bool completeConform)
1727 bool hasInternalState = FALSE;
1729 old->info->fcn->hasGlobs |= unew->info->fcn->hasGlobs;
1731 if (globSet_isDefined (unew->info->fcn->globs))
1733 globSet_allElements (unew->info->fcn->globs, el)
1735 if (sRef_isFileStatic (el))
1737 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1739 if (sRef_isInvalid (sr))
1741 bool hasError = FALSE;
1743 if (!hasInternalState
1744 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1745 sRef_makeInternalState ()))
1746 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1747 sRef_makeSpecState ())))
1750 && !uentry_isStatic (old)
1753 message ("Globals list for %q includes internal state, %q, "
1754 "but %s without globals internalState.",
1755 uentry_getName (old),
1757 uentry_specOrDefName (old)),
1758 uentry_whereLast (unew)))
1760 uentry_showWhereSpecified (old);
1764 old->info->fcn->globs = globSet_insert (old->info->fcn->globs,
1765 sRef_makeInternalState ());
1766 hasInternalState = TRUE;
1770 && fileloc_sameFile (uentry_whereDeclared (unew),
1771 uentry_whereDeclared (old)))
1776 message ("Function %q inconsistently %rdeclared (in "
1777 "same file) with file static global %q in "
1779 uentry_getName (unew),
1780 uentry_isDeclared (old),
1782 uentry_whereDeclared (unew)))
1784 uentry_showWhereSpecified (old);
1789 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1790 context_recordFileGlobals (old->info->fcn->globs);
1794 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1796 if (sRef_isInvalid (sr))
1801 message ("Function %q inconsistently %rdeclared with "
1802 "%q in globals list",
1803 uentry_getName (unew),
1804 uentry_isDeclared (old),
1806 uentry_whereDeclared (unew)))
1808 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1809 uentry_showWhereSpecified (old);
1814 if (!bool_equal (sRef_isAllocated (el), sRef_isAllocated (sr)))
1820 ("Function %q global %q inconsistently "
1821 "%rdeclared as %qout global",
1822 uentry_getName (unew),
1824 uentry_isDeclared (old),
1825 cstring_makeLiteral (sRef_isAllocated (el) ? "" : "non-")),
1826 uentry_whereDeclared (unew)))
1828 uentry_showWhereSpecified (old);
1833 } end_globSet_allElements ;
1835 if (completeConform)
1837 globSet_allElements (old->info->fcn->globs, el)
1839 sRef sr = globSet_lookup (unew->info->fcn->globs, el);
1841 if (sRef_isInvalid (sr))
1844 && uentry_isReallySpecified (old)
1847 message ("Function %q specified with %q in globals list, "
1848 "but declared without %q",
1849 uentry_getName (unew),
1852 uentry_whereDeclared (unew)))
1854 uentry_showWhereSpecified (old);
1857 } end_globSet_allElements;
1862 if (completeConform && !globSet_isEmpty (old->info->fcn->globs))
1864 if (uentry_isReallySpecified (old)
1867 message ("%s %q specified with globals list, but "
1868 "declared with no globals",
1869 ekind_capName (unew->ukind),
1870 uentry_getName (unew)),
1871 uentry_whereDeclared (unew)))
1874 (message ("Specification globals: %q",
1875 globSet_unparse (old->info->fcn->globs)),
1876 uentry_whereSpecified (old));
1880 unew->info->fcn->globs = globSet_copyInto (unew->info->fcn->globs,
1881 old->info->fcn->globs);
1886 ** new modifies list must be included by old modifies list.
1888 ** file static state may be added to new, if old has internal.
1892 checkModifiesConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
1893 bool mustConform, bool completeConform)
1896 bool changedMods = FALSE;
1897 bool modInternal = FALSE;
1899 llassert (uentry_isFunction (old) && uentry_isFunction (unew));
1901 old->info->fcn->hasMods |= unew->info->fcn->hasMods;
1902 newMods = unew->info->fcn->mods;
1904 if (sRefSet_isEmpty (newMods))
1906 if (completeConform && !sRefSet_isEmpty (old->info->fcn->mods)
1907 && uentry_isReallySpecified (old))
1911 message ("%s %q specified with modifies clause, "
1912 "but declared with no modifies clause",
1913 ekind_capName (unew->ukind),
1914 uentry_getName (unew)),
1915 uentry_whereDeclared (unew)))
1917 llgenindentmsg (message ("Specification has modifies %q",
1918 sRefSet_unparse (old->info->fcn->mods)),
1919 uentry_whereSpecified (old));
1926 sRefSet_allElements (newMods, current)
1928 if (sRef_isValid (current))
1930 sRef rb = sRef_getRootBase (current);
1932 if (sRef_isFileStatic (rb))
1936 if (!sRefSet_isSameMember (old->info->fcn->mods,
1937 sRef_makeInternalState ())
1938 && !sRefSet_isSameMember (old->info->fcn->mods,
1939 sRef_makeSpecState ()))
1942 && !uentry_isStatic (old)
1946 ("Modifies list for %q includes internal state, "
1947 "but %s without modifies internal.",
1948 uentry_getName (old),
1949 uentry_specOrDefName (old)),
1950 uentry_whereLast (unew)))
1952 uentry_showWhereSpecified (old);
1955 old->info->fcn->mods =
1956 sRefSet_insert (old->info->fcn->mods,
1957 sRef_makeInternalState ());
1962 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1968 if (sRef_canModifyVal (current, old->info->fcn->mods))
1970 int size = sRefSet_size (old->info->fcn->mods);
1972 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1975 if (sRefSet_size (old->info->fcn->mods) != size)
1986 ("Modifies list for %q contains %q, not modifiable "
1988 uentry_getName (old),
1989 sRef_unparse (current),
1990 uentry_specDeclName (old)),
1991 uentry_whereLast (unew)))
1993 uentry_showWhereSpecified (old);
1998 } end_sRefSet_allElements;
2000 if (completeConform && uentry_isReallySpecified (old))
2002 sRefSet_allElements (old->info->fcn->mods, el)
2004 if (sRef_canModify (el, newMods))
2013 ("Specification modifies clause for %q contains %q, "
2014 "not included in declaration modifies clause",
2015 uentry_getName (old),
2017 uentry_whereLast (unew)))
2019 uentry_showWhereSpecified (old);
2022 } end_sRefSet_allElements ;
2026 ** Make sure file static elements will be removed.
2031 context_recordFileModifies (old->info->fcn->mods);
2036 uentry_checkMutableType (uentry ue)
2038 ctype ct = uentry_getType (ue);
2040 if (!ctype_isRealPointer (ct) && !ctype_isRealAbstract (ct))
2042 DPRINTF (("Check mutable: %s", uentry_unparseFull (ue)));
2044 voptgenerror (FLG_MUTREP,
2045 message ("Mutable abstract type %q declared without pointer "
2046 "indirection: %t (violates assignment semantics)",
2047 uentry_getName (ue), ct),
2048 uentry_whereDeclared (ue));
2053 uentry_setMutable (uentry e)
2055 llassert (uentry_isDatatype (e));
2056 e->info->datatype->mut = YES;
2060 uentry_checkIterArgs (uentry ue)
2062 bool hasYield = FALSE;
2065 llassert (uentry_isIter (ue));
2067 args = uentry_getParams (ue);
2069 uentryList_elements (args, el)
2071 sstate ds = uentry_getDefState (el);
2073 if (uentry_isYield (el))
2078 if (sstate_isUnknown (ds))
2080 uentry_setDefState (el, SS_DEFINED);
2086 } end_uentryList_elements;
2090 voptgenerror (FLG_HASYIELD,
2091 message ("Iterator %q declared with no yield parameters",
2092 uentry_getName (ue)),
2093 uentry_whereDeclared (ue));
2098 chkind_fromQual (qual qel)
2100 if (qual_isChecked (qel))
2104 else if (qual_isCheckMod (qel))
2108 else if (qual_isCheckedStrict (qel))
2110 return CH_CHECKEDSTRICT;
2112 else if (qual_isUnchecked (qel))
2114 return CH_UNCHECKED;
2119 /*@notreached@*/ return CH_UNKNOWN;
2124 uentry_reflectOtherQualifier (/*@notnull@*/ uentry ue, qual qel)
2126 if (qual_isKillRef (qel) || qual_isNewRef (qel) || qual_isTempRef (qel))
2128 if (!uentry_isRefCounted (ue))
2131 (FLG_ANNOTATIONERROR,
2132 message ("Reference counting qualifier %s used on non-reference "
2133 "counted storage: %q",
2135 uentry_unparse (ue)),
2136 uentry_whereLast (ue));
2140 alkind ak = alkind_fromQual (qel);
2142 uentry_setAliasKind (ue, ak);
2145 else if (qual_isRefCounted (qel))
2147 ctype ct = ctype_realType (uentry_getType (ue));
2150 if (ctype_isPointer (ct)
2151 && (ctype_isStruct (rt = ctype_realType (ctype_baseArrayPtr (ct)))))
2153 /* check there is a refs field */
2154 uentryList fields = ctype_getFields (rt);
2155 uentry refs = uentry_undefined;
2157 uentryList_elements (fields, field)
2159 if (uentry_isRefsField (field))
2161 if (uentry_isValid (refs))
2164 (FLG_ANNOTATIONERROR,
2165 message ("Reference counted structure type %s has "
2166 "multiple refs fields: %q and %q",
2168 uentry_getName (refs),
2169 uentry_getName (field)),
2170 uentry_whereLast (field));
2175 } end_uentryList_elements;
2177 if (uentry_isInvalid (refs))
2181 message ("Reference counted structure type %s has "
2183 ctype_unparse (ct)),
2185 ("To count reference, the structure must have a field named "
2186 "refs of type int."),
2189 else if (!ctype_isInt (uentry_getType (refs)))
2192 (FLG_ANNOTATIONERROR,
2193 message ("Reference counted structure type %s refs field has "
2194 "type %s (should be int)", ctype_unparse (ct),
2195 ctype_unparse (uentry_getType (refs))),
2196 uentry_whereLast (refs));
2200 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2201 uentry_whereDeclared (ue));
2206 if ((ctype_isPointer (ct)
2207 && ctype_isUnknown (ctype_realType (ctype_baseArrayPtr (ct))))
2208 ||ctype_isAbstract (ct) || ctype_isUnknown (ct))
2210 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2211 uentry_whereDeclared (ue));
2216 (FLG_ANNOTATIONERROR,
2217 message ("Non-pointer to structure type %s declared with "
2218 "refcounted qualifier",
2219 ctype_unparse (ct)),
2220 uentry_whereLast (ue));
2224 else if (qual_isRefs (qel))
2226 if (uentry_isVariable (ue) && !uentry_isParam (ue))
2228 uentry_setAliasKind (ue, AK_REFS);
2233 (FLG_ANNOTATIONERROR,
2234 message ("Refs qualifier used on non-structure field: %q",
2235 uentry_unparse (ue)),
2236 uentry_whereLast (ue));
2239 else if (qual_isAliasQual (qel))
2241 alkind ak = alkind_fromQual (qel);
2243 alkind oldak = uentry_getAliasKind (ue);
2244 ctype ut = uentry_getType (ue);
2246 if (alkind_isImplicit (ak)
2247 && (alkind_isKnown (oldak) && !alkind_isImplicit (oldak)))
2249 /* ignore the implied qualifier */
2253 if (uentry_isEitherConstant (ue))
2256 (FLG_ANNOTATIONERROR,
2257 message ("Alias qualifier %s used on constant: %q",
2258 alkind_unparse (ak), uentry_unparse (ue)),
2259 uentry_whereLast (ue));
2264 if (ctype_isFunction (ut))
2266 ut = ctype_getReturnType (ut);
2269 if (!(ctype_isVisiblySharable (ut)
2270 || ctype_isRealArray (ut)
2271 || ctype_isRealSU (ut)))
2273 if (!qual_isImplied (qel))
2276 (FLG_ANNOTATIONERROR,
2277 message ("Alias qualifier %s used on unsharable storage type %t: %q",
2278 alkind_unparse (ak), ut, uentry_getName (ue)),
2279 uentry_whereLast (ue));
2286 if (uentry_isRefCounted (ue))
2288 if (!(qual_isRefQual (qel) || qual_isOnly (qel)
2289 || qual_isExposed (qel)
2290 || qual_isObserver (qel)))
2292 if (!qual_isImplied (qel))
2295 (FLG_ANNOTATIONERROR,
2297 ("Alias qualifier %s used on reference counted storage: %q",
2298 alkind_unparse (ak),
2299 uentry_unparse (ue)),
2300 uentry_whereLast (ue));
2308 if (qual_isRefQual (qel))
2311 (FLG_ANNOTATIONERROR,
2312 message ("Qualifier %s used on non-reference counted storage: %q",
2313 alkind_unparse (ak), uentry_unparse (ue)),
2314 uentry_whereLast (ue));
2323 uentry_setAliasKind (ue, ak);
2326 else if (qual_isNull (qel))
2328 if (uentry_isConstant (ue))
2332 ctype_isAbstract (ue->utype) ? NS_CONSTNULL : NS_DEFNULL,
2333 uentry_whereDeclared (ue));
2337 uentry_setNullState (ue, NS_POSNULL);
2340 else if (qual_isRelNull (qel))
2342 uentry_setNullState (ue, NS_RELNULL);
2344 else if (qual_isNotNull (qel))
2346 uentry_setNullState (ue, NS_MNOTNULL);
2348 else if (qual_isAbstract (qel)
2349 || qual_isConcrete (qel))
2351 if (!uentry_isDatatype (ue))
2354 (FLG_ANNOTATIONERROR,
2355 message ("Qualifier %s used with non-datatype",
2356 qual_unparse (qel)),
2357 uentry_whereLast (ue));
2361 ue->info->datatype->abs = ynm_fromBool (qual_isAbstract (qel));
2364 else if (qual_isMutable (qel))
2366 if (!uentry_isDatatype (ue))
2369 (FLG_ANNOTATIONERROR,
2370 message ("Qualifier %s used with non-datatype", qual_unparse (qel)),
2371 uentry_whereLast (ue));
2375 if (!ynm_isOn (ue->info->datatype->mut))
2377 uentry_checkMutableType (ue);
2380 ue->info->datatype->mut = YES;
2383 else if (qual_isImmutable (qel))
2385 if (!uentry_isDatatype (ue))
2387 voptgenerror (FLG_ANNOTATIONERROR,
2388 message ("Qualifier %s used with non-datatype",
2389 qual_unparse (qel)),
2390 uentry_whereLast (ue));
2394 ue->info->datatype->mut = NO;
2397 else if (qual_isNullPred (qel))
2399 uentry_convertVarFunction (ue);
2401 if (uentry_isFunction (ue))
2403 ctype typ = uentry_getType (ue);
2404 ctype rtype = ctype_getReturnType (uentry_getType (ue));
2406 if (ctype_isRealBool (rtype))
2408 uentryList pl = ctype_argsFunction (typ);
2410 if (uentryList_size (pl) == 1)
2412 ue->info->fcn->nullPred = qel;
2416 voptgenerror (FLG_ANNOTATIONERROR,
2417 message ("Qualifier %s used with function having %d "
2418 "arguments (should have 1)",
2420 uentryList_size (pl)),
2421 uentry_whereLast (ue));
2426 voptgenerror (FLG_ANNOTATIONERROR,
2427 message ("Qualifier %s used with function returning %s "
2428 "(should return bool)",
2430 ctype_unparse (rtype)),
2431 uentry_whereLast (ue));
2436 voptgenerror (FLG_ANNOTATIONERROR,
2437 message ("Qualifier %s used with non-function",
2438 qual_unparse (qel)),
2439 uentry_whereLast (ue));
2442 else if (qual_isExitQual (qel))
2444 exitkind exk = exitkind_fromQual (qel);
2446 if (uentry_isFunction (ue))
2448 if (exitkind_isKnown (ue->info->fcn->exitCode))
2450 voptgenerror (FLG_ANNOTATIONERROR,
2451 message ("Multiple exit qualifiers used on function %q: %s, %s",
2452 uentry_getName (ue),
2453 exitkind_unparse (ue->info->fcn->exitCode),
2454 exitkind_unparse (exk)),
2455 uentry_whereLast (ue));
2458 ue->info->fcn->exitCode = exk;
2462 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2464 uentry_makeVarFunction (ue);
2465 ue->info->fcn->exitCode = exk;
2469 voptgenerror (FLG_ANNOTATIONERROR,
2470 message ("Exit qualifier %s used with non-function (type %s)",
2472 ctype_unparse (uentry_getType (ue))),
2473 uentry_whereLast (ue));
2477 else if (qual_isMetaState (qel))
2479 annotationInfo ainfo = qual_getAnnotationInfo (qel);
2481 if (annotationInfo_matchesContext (ainfo, ue))
2483 DPRINTF (("Reflecting %s on %s",
2484 annotationInfo_unparse (ainfo),
2485 uentry_unparseFull (ue)));
2487 sRef_reflectAnnotation (ue->sref, ainfo, g_currentloc);
2488 DPRINTF (("==> %s", sRef_unparseFull (ue->sref)));
2489 DPRINTF (("==> %s", uentry_unparseFull (ue)));
2494 (FLG_ANNOTATIONERROR,
2495 message ("Attribute annotation %s used in inconsistent context: %q",
2497 uentry_unparse (ue)),
2498 uentry_whereLast (ue)))
2500 /*@i! annotationInfo_showContextError (ainfo, ue); */
2506 if (qual_isCQual (qel))
2512 llbug (message ("Unhandled qualifier: %s", qual_unparse (qel)));
2518 uentry_reflectQualifiers (uentry ue, qualList q)
2520 llassert (uentry_isValid (ue));
2522 DPRINTF (("Reflect qualifiers: %s / %s",
2523 uentry_unparseFull (ue), qualList_unparse (q)));
2525 qualList_elements (q, qel)
2527 if (qual_isStatic (qel))
2529 uentry_setStatic (ue);
2531 else if (qual_isUnused (qel))
2533 uentry_setUsed (ue, fileloc_undefined);
2534 DPRINTF (("Used: %s", uentry_unparseFull (ue)));
2536 else if (qual_isExternal (qel))
2538 fileloc_free (ue->whereDefined);
2539 ue->whereDefined = fileloc_createExternal ();
2541 else if (qual_isSef (qel))
2543 if (uentry_isVariable (ue))
2545 vkind vk = ue->info->var->kind;
2547 llassert (vk != VKREFPARAM);
2549 if (vk == VKYIELDPARAM)
2552 (FLG_ANNOTATIONERROR,
2553 message ("Qualifier sef cannot be used with %s: %q",
2554 cstring_makeLiteralTemp (vk == VKYIELDPARAM ? "yield" : "returned"),
2555 uentry_unparse (ue)),
2556 uentry_whereLast (ue));
2558 else if (vk == VKRETPARAM)
2560 ue->info->var->kind = VKSEFRETPARAM;
2564 ue->info->var->kind = VKSEFPARAM;
2570 (FLG_ANNOTATIONERROR,
2571 message ("Qualifier sef is meaningful only on parameters: %q",
2572 uentry_unparse (ue)),
2573 uentry_whereLast (ue));
2576 else if (qual_isExtern (qel))
2578 ue->storageclass = SCEXTERN;
2580 else if (qual_isGlobalQual (qel)) /* undef, killed */
2582 DPRINTF (("Reflecting qual: %s / %s",
2583 qual_unparse (qel), uentry_unparse (ue)));
2585 if (uentry_isVariable (ue))
2587 sstate oldstate = ue->info->var->defstate;
2588 sstate defstate = sstate_fromQual (qel);
2591 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
2592 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
2594 defstate = SS_UNDEFKILLED;
2601 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2602 ue->info->var->defstate = defstate;
2607 (FLG_ANNOTATIONERROR,
2608 message ("Qualifier %s used on non-variable: %q",
2609 qual_unparse (qel), uentry_unparse (ue)),
2610 uentry_whereLast (ue));
2613 DPRINTF (("After: %s", uentry_unparseFull (ue)));
2615 /* start modifications */
2616 else if( qual_isBufQualifier(qel) ) {
2617 ctype ct = ctype_realType(uentry_getType(ue));
2618 if( ctype_isArray(ct) || ctype_isPointer(ct) ) {
2620 if( uentry_hasBufStateInfo(ue) ) {
2621 if( qual_isNullTerminated(qel) ) { /* handle Nullterm */
2623 if (uentry_isAnyParam(ue) || uentry_isReturned (ue)) {
2624 /* If formal func param */
2625 uentry_setNullTerminatedState(ue);
2626 uentry_setLen (ue, 1);
2627 uentry_setSize (ue, 1);
2629 sRef_setNullTerminatedState(uentry_getSref(ue));
2630 sRef_setLen (uentry_getSref(ue), 1);
2631 sRef_setSize (uentry_getSref(ue), 1);
2633 uentry_setPossiblyNullTerminatedState(ue);
2635 sRef_setPossiblyNullTerminatedState(uentry_getSref(ue));
2639 /* put other BufState Qualifiers here */
2641 cstring s = uentry_getName(ue);
2642 llfatalbug(message("INTERNAL Error: we have a NULL BufState \
2643 struct for identifier %s\n", s) );
2645 } else if (ctype_isFunction (ct)) { /* We have to handle function */
2647 sRef retSref = uentry_getSref (ue);
2648 ctype retType = sRef_getType (retSref);
2650 if (ctype_isPointer (retType) || ctype_isArray (retType)) {
2651 sRef_setNullTerminatedState (retSref);
2657 message ("Qualifier %s used on non-pointer on \
2658 function return: %q", qual_unparse (qel),
2659 uentry_unparse (ue)));
2666 message ("Qualifier %s used on non-pointer: %q",
2667 qual_unparse (qel), uentry_unparse (ue)));
2669 DPRINTF (("After: %s", uentry_unparseFull (ue)));
2671 else if (qual_isAllocQual (qel)) /* out, partial, reldef, special, etc. */
2673 ctype realType = ctype_realType (ue->utype);
2674 sstate defstate = sstate_fromQual (qel);
2676 if (ctype_isFunction (realType))
2678 realType = ctype_realType (ctype_getReturnType (realType));
2681 if (qual_isRelDef (qel))
2683 ; /* okay anywhere */
2687 if (!ctype_isAP (realType)
2688 && !ctype_isSU (realType)
2689 && !ctype_isUnknown (realType)
2690 && !ctype_isAbstract (ue->utype))
2693 (FLG_ANNOTATIONERROR,
2694 message ("Qualifier %s used on non-pointer or struct: %q",
2695 qual_unparse (qel), uentry_unparse (ue)),
2696 uentry_whereLast (ue));
2700 uentry_setDefState (ue, defstate);
2702 if (sRef_isStateSpecial (ue->sref)
2703 && alkind_isImplicit (sRef_getAliasKind (ue->sref)))
2705 sRef_setAliasKind (ue->sref, AK_ERROR, fileloc_undefined);
2708 else if (qual_isYield (qel))
2710 if (uentry_isVariable (ue))
2712 ue->info->var->kind = VKYIELDPARAM;
2717 (FLG_ANNOTATIONERROR,
2718 message ("Qualifier %s used on non-iterator parameter: %q",
2719 qual_unparse (qel), uentry_unparse (ue)),
2720 uentry_whereLast (ue));
2723 else if (qual_isExQual (qel))
2725 exkind ek = exkind_fromQual (qel);
2726 ctype ut = uentry_getType (ue);
2728 DPRINTF (("Reflect ex qual: %s / %s",
2729 uentry_unparse (ue), exkind_unparse (ek)));
2731 if (ctype_isFunction (ut))
2733 ut = ctype_getReturnType (ut);
2736 if (!(ctype_isVisiblySharable (ut))
2737 && !(ctype_isArray (ut)) /* can apply to arrays also! */
2738 && !(ctype_isStruct (ctype_realType (ut)))) /* applies to structure fields! */
2740 if (!qual_isImplied (qel))
2742 if (ctype_isImmutableAbstract (ut)) {
2744 (FLG_REDUNDANTSHAREQUAL,
2745 message ("Qualifier %s used on unsharable storage type %t: %q",
2746 exkind_unparse (ek), ut, uentry_getName (ue)),
2747 uentry_whereLast (ue));
2750 (FLG_MISPLACEDSHAREQUAL,
2751 message ("Qualifier %s used on unsharable storage type %t: %q",
2752 exkind_unparse (ek), ut, uentry_getName (ue)),
2753 uentry_whereLast (ue));
2759 alkind ak = sRef_getAliasKind (ue->sref);
2761 sRef_setExKind (ue->sref, ek, uentry_whereDeclared (ue));
2762 DPRINTF (("Set exkind: %s", sRef_unparseFull (ue->sref)));
2764 if (alkind_isUnknown (ak) || alkind_isImplicit (ak) || alkind_isStatic (ak))
2766 if (!alkind_isTemp (ak))
2768 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
2769 uentry_setAliasKind (ue, AK_IMPDEPENDENT);
2772 else if (alkind_isDependent (ak) || alkind_isTemp (ak)
2773 || alkind_isOwned (ak))
2781 message ("Exposure qualifier %s used on %s storage (should "
2782 "be dependent): %q",
2784 alkind_unparse (ak),
2785 uentry_unparse (ue)));
2789 else if (qual_isGlobCheck (qel))
2791 if (uentry_isVariable (ue))
2793 chkind ch = chkind_fromQual (qel);
2795 if (ue->info->var->checked != CH_UNKNOWN)
2797 if (ch == ue->info->var->checked)
2799 llerror (FLG_SYNTAX,
2800 message ("Redundant %s qualifier on %q",
2802 uentry_getName (ue)));
2806 llerror (FLG_SYNTAX,
2808 ("Contradictory %s and %s qualifiers on %q",
2810 checkedName (ue->info->var->checked),
2811 uentry_getName (ue)));
2815 ue->info->var->checked = ch;
2821 message ("Qualifier %s used with non-variable",
2822 qual_unparse (qel)));
2825 else if (qual_isReturned (qel))
2827 if (uentry_isVariable (ue))
2829 ue->info->var->kind = VKRETPARAM;
2833 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-variable",
2834 qual_unparse (qel)));
2839 uentry_reflectOtherQualifier (ue, qel);
2842 sRef_storeState (ue->sref);
2843 } end_qualList_elements;
2847 DPRINTF (("Done: %s", sRef_unparseFull (ue->sref)));
2851 uentry_isOnly (uentry ue)
2853 return (!uentry_isUndefined (ue)
2854 && uentry_isVariable (ue)
2855 && alkind_isOnly (sRef_getOrigAliasKind (ue->sref)));
2859 uentry_setAliasKind (/*@notnull@*/ uentry ue, alkind ak)
2861 sRef_setAliasKind (ue->sref, ak, uentry_whereDeclared (ue));
2862 sRef_setOrigAliasKind (ue->sref, ak);
2866 uentry_setNullState (/*@notnull@*/ uentry ue, nstate ns)
2868 if (uentry_isVariable (ue))
2870 ue->info->var->nullstate = ns;
2873 sRef_setNullState (ue->sref, ns, uentry_whereDeclared (ue));
2877 uentry_isUnique (uentry ue)
2879 return (!uentry_isUndefined (ue)
2880 && uentry_isVariable (ue)
2881 && alkind_isUnique (sRef_getOrigAliasKind (ue->sref)));
2885 uentry_isFileStatic (uentry ue)
2887 return (uentry_isStatic (ue)
2888 && (!uentry_isVariable (ue)
2889 || sRef_isFileStatic (uentry_getSref (ue))));
2893 uentry_isExported (uentry ue)
2895 if (uentry_isValid (ue))
2897 if (uentry_isVariable (ue))
2899 return (sRef_isRealGlobal (uentry_getSref (ue)));
2903 return !uentry_isStatic (ue);
2911 uentry_isNonLocal (uentry ue)
2913 return (uentry_isValid (ue) && uentry_isVariable (ue)
2914 && (sRef_isFileOrGlobalScope (ue->sref) || uentry_isStatic (ue)));
2918 uentry_isGlobalVariable (uentry ue)
2920 return (uentry_isValid (ue) && uentry_isVariable (ue)
2921 && sRef_isFileOrGlobalScope (ue->sref));
2925 uentry_isVisibleExternally (uentry ue)
2927 return (uentry_isValid (ue)
2928 && ((uentry_isVariable (ue) && sRef_isRealGlobal (ue->sref))
2929 || (!uentry_isStatic (ue)
2930 && (uentry_isFunction (ue)
2931 || uentry_isIter (ue)
2932 || uentry_isEndIter (ue)
2933 || uentry_isConstant (ue)
2934 || uentry_isDatatype (ue)
2935 || uentry_isAnyTag (ue)))));
2939 uentry_isPrintfLike (uentry ue)
2941 return (uentry_isFunction (ue)
2942 && (ue->info->fcn->specialCode == SPC_PRINTFLIKE));
2946 uentry_isScanfLike (uentry ue)
2948 return (uentry_isFunction (ue)
2949 && (ue->info->fcn->specialCode == SPC_SCANFLIKE));
2953 uentry_isMessageLike (uentry ue)
2955 return (uentry_isFunction (ue)
2956 && (ue->info->fcn->specialCode == SPC_MESSAGELIKE));
2959 static void checkSpecialFunction (/*@notnull@*/ uentry ue)
2961 uentryList args = uentry_getParams (ue);
2963 if (!uentryList_isMissingParams (args))
2965 uentry last = uentry_undefined;
2967 uentryList_elements (args, current)
2969 if (uentry_isElipsisMarker (current))
2971 if (uentry_isUndefined (last))
2975 message ("Function %q is marked %s, but has no format "
2976 "string argument before elipsis",
2977 uentry_getName (ue),
2978 specCode_unparse (ue->info->fcn->specialCode)),
2979 uentry_whereLast (ue));
2980 ue->info->fcn->specialCode = SPC_NONE;
2984 ctype rt = ctype_realType (uentry_getType (last));
2986 if (!ctype_match (rt, ctype_string))
2990 /* wchar_t * is okay too */
2991 if (ctype_isAP (rt))
2993 ctype base = ctype_baseArrayPtr (rt);
2995 if (ctype_isArbitraryIntegral (base))
3005 message ("Function %q is marked %s, but the argument "
3006 "before the elipsis has type %s (should be char *)",
3007 uentry_getName (ue),
3008 specCode_unparse (ue->info->fcn->specialCode),
3009 ctype_unparse (uentry_getType (last))),
3010 uentry_whereLast (ue));
3012 ue->info->fcn->specialCode = SPC_NONE;
3019 } end_uentryList_elements ;
3023 message ("Function %q is marked %s, but has no elipsis parameter",
3024 uentry_getName (ue),
3025 specCode_unparse (ue->info->fcn->specialCode)),
3026 uentry_whereLast (ue));
3028 ue->info->fcn->specialCode = SPC_NONE;
3033 uentry_setPrintfLike (uentry ue)
3035 uentry_convertVarFunction (ue);
3036 llassertfatal (uentry_isFunction (ue));
3037 ue->info->fcn->specialCode = SPC_PRINTFLIKE;
3038 checkSpecialFunction (ue);
3042 uentry_setScanfLike (uentry ue)
3044 uentry_convertVarFunction (ue);
3045 llassertfatal (uentry_isFunction (ue));
3046 ue->info->fcn->specialCode = SPC_SCANFLIKE;
3047 checkSpecialFunction (ue);
3051 uentry_setMessageLike (uentry ue)
3053 uentry_convertVarFunction (ue);
3054 llassertfatal (uentry_isFunction (ue));
3055 ue->info->fcn->specialCode = SPC_MESSAGELIKE;
3056 checkSpecialFunction (ue);
3060 uentry_isSpecialFunction (uentry ue)
3062 return (uentry_isFunction (ue)
3063 && (ue->info->fcn->specialCode != SPC_NONE));
3066 /*@notnull@*/ uentry uentry_makeParam (idDecl t, int i)
3068 ctype ct = idDecl_getCtype (t);
3070 fileloc loc = setLocation ();
3071 sRef pref = sRef_makeParam (i, ct, stateInfo_makeLoc (loc));
3072 uentry ue = uentry_makeVariableSrefParam (idDecl_observeId (t), ct, loc, pref);
3074 DPRINTF (("Make param: %s", uentry_unparseFull (ue)));
3075 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3076 uentry_implicitParamAnnots (ue);
3078 /* Parameter type [][] or [x][] is invalid */
3080 while (ctype_isFixedArray (base)) {
3081 base = ctype_baseArrayPtr (base);
3084 if (ctype_isIncompleteArray (base)) {
3085 base = ctype_baseArrayPtr (base);
3087 if (ctype_isArray (base)) {
3088 if (!uentry_hasName (ue)) {
3089 (void) optgenerror (FLG_INCOMPLETETYPE,
3090 message ("Unnamed function parameter %d is incomplete type (inner array must have bounds): %s",
3092 ctype_unparse (ct)),
3093 uentry_whereLast (ue));
3095 (void) optgenerror (FLG_INCOMPLETETYPE,
3096 message ("Function parameter %q is incomplete type (inner array must have bounds): %s",
3097 uentry_getName (ue),
3098 ctype_unparse (ct)),
3099 uentry_whereLast (ue));
3104 DPRINTF (("Param: %s", uentry_unparseFull (ue)));
3108 /*@only@*/ /*@notnull@*/ uentry uentry_makeIdVariable (idDecl t)
3110 ctype ct = idDecl_getCtype (t);
3112 if (ctype_isFunction (ct))
3114 return (uentry_makeIdFunction (t));
3118 fileloc loc = setLocation ();
3119 uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
3121 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3123 if (!uentry_isExtern (ue))
3125 uentry_setDefined (ue, loc);
3132 /*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t, fileloc loc)
3134 return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), fileloc_copy (loc), SS_DEFINED));
3141 static /*@only@*/ /*@notnull@*/
3142 uentry uentry_makeConstantAux (cstring n, ctype t,
3143 /*@keep@*/ fileloc f, bool priv, bool macro,
3144 /*@only@*/ multiVal m)
3146 uentry e = uentry_alloc ();
3149 e->uname = cstring_copy (n);
3151 e->storageclass = SCNONE;
3153 e->warn = warnClause_undefined; /*@i32 warnings for constants? */
3155 e->sref = sRef_makeConst (t);
3160 e->uses = filelocList_new ();
3161 e->isPrivate = priv;
3162 e->hasNameError = FALSE;
3164 e->info = (uinfo) dmalloc (sizeof (*e->info));
3165 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
3166 e->info->uconst->access = typeIdSet_undefined;
3167 e->info->uconst->macro = macro;
3169 uentry_setSpecDef (e, f);
3171 if (multiVal_isInt (m) && (multiVal_forceInt (m) == 0))
3173 sRef_setDefNull (e->sref, uentry_whereDeclared (e));
3176 uentry_setConstantValue (e, m);
3181 /*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
3183 uentry ue = uentry_makeConstantAux (n, t, f, FALSE, FALSE, multiVal_unknown ());
3187 /*@notnull@*/ uentry uentry_makeConstantValue (cstring n, ctype t, fileloc f, bool priv, multiVal val)
3189 uentry ue = uentry_makeConstantAux (n, t, f, priv, FALSE, val);
3193 /*@notnull@*/ uentry uentry_makeMacroConstant (cstring n, ctype t, fileloc f)
3195 uentry ue = uentry_makeConstantAux (n, t, f, FALSE, TRUE, multiVal_unknown ());
3199 /*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
3201 uentry ue = uentry_makeConstant (idDecl_observeId (t),
3202 idDecl_getCtype (t),
3205 llassert (fileloc_isUndefined (ue->whereDeclared));
3206 ue->whereDeclared = setLocation ();
3207 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3209 DPRINTF (("Constant: %s", uentry_unparseFull (ue)));
3210 DPRINTF (("Value: %s", multiVal_unparse (uentry_getConstantValue (ue))));
3218 void uentry_setDefState (uentry ue, sstate defstate)
3220 if (uentry_isValid (ue))
3222 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
3224 if (uentry_isVariable (ue))
3226 ue->info->var->defstate = defstate; /* evs 2000-05-17: fixed bug, was SS_DEFINED! */
3231 bool uentry_isCheckedUnknown (uentry ue)
3233 return (uentry_isVar (ue)
3234 && (ue->info->var->checked == CH_UNKNOWN));
3237 bool uentry_isCheckMod (uentry ue)
3239 return (uentry_isVar (ue)
3240 && (ue->info->var->checked == CH_CHECKMOD));
3243 bool uentry_isUnchecked (uentry ue)
3245 return (uentry_isVar (ue)
3246 && (ue->info->var->checked == CH_UNCHECKED));
3249 bool uentry_isChecked (uentry ue)
3251 return (uentry_isVar (ue)
3252 && (ue->info->var->checked == CH_CHECKED));
3255 bool uentry_isCheckedModify (uentry ue)
3257 return (uentry_isVar (ue)
3258 && (ue->info->var->checked == CH_CHECKED
3259 || ue->info->var->checked == CH_CHECKMOD
3260 || ue->info->var->checked == CH_CHECKEDSTRICT));
3263 bool uentry_isCheckedStrict (uentry ue)
3265 return (uentry_isVar (ue)
3266 && (ue->info->var->checked == CH_CHECKEDSTRICT));
3269 void uentry_setUnchecked (uentry ue)
3271 llassert (uentry_isVar (ue));
3273 ue->info->var->checked = CH_UNCHECKED;
3276 void uentry_setChecked (uentry ue)
3278 llassert (uentry_isVar (ue));
3280 ue->info->var->checked = CH_CHECKED;
3283 void uentry_setCheckMod (uentry ue)
3285 llassert (uentry_isVar (ue));
3287 ue->info->var->checked = CH_CHECKMOD;
3290 void uentry_setCheckedStrict (uentry ue)
3292 llassert (uentry_isVar (ue));
3294 ue->info->var->checked = CH_CHECKEDSTRICT;
3297 static /*@only@*/ /*@notnull@*/
3298 uentry uentry_makeVariableAux (cstring n, ctype t,
3300 /*@exposed@*/ sRef s,
3301 bool priv, vkind kind)
3303 uentry e = uentry_alloc ();
3306 DPRINTF (("Make variable: %s %s %s", n, ctype_unparse (t), sRef_unparse (s)));
3309 e->uname = cstring_copy (n);
3312 e->storageclass = SCNONE;
3314 e->warn = warnClause_undefined; /*@i32 warnings for variable @*/
3321 e->uses = filelocList_new ();
3322 e->isPrivate = priv;
3323 e->hasNameError = FALSE;
3325 e->info = (uinfo) dmalloc (sizeof (*e->info));
3326 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
3327 e->info->var->kind = kind;
3329 /*@i523 e->info->var->origsref = sRef_saveCopy (e->sref); */
3330 e->info->var->checked = CH_UNKNOWN;
3332 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3333 uentry_setSpecDef (e, f);
3334 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3336 if (ctype_isFunction (rt))
3338 rt = ctype_getReturnType (rt);
3341 if (ctype_isUA (rt))
3343 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3344 sRef_setStateFromType (e->sref, rt);
3347 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3348 e->info->var->defstate = sRef_getDefState (e->sref);
3349 e->info->var->nullstate = sRef_getNullState (e->sref);
3351 /* start modifications */
3352 /* This function sets the uentry for a pointer or array variable declaration,
3353 it allocates memory and sets the fields. We check if the type of the variable
3354 is a pointer or array and allocate a `bbufinfo' struct accordingly */
3356 if (ctype_isArray (t) || ctype_isPointer(t))
3358 /*@i222@*/ e->info->var->bufinfo = dmalloc (sizeof (*e->info->var->bufinfo));
3359 e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
3360 sRef_setNotNullTerminatedState (s);
3364 e->info->var->bufinfo = NULL;
3366 /* end modification */
3372 uentry_isYield (uentry ue)
3374 return (uentry_isVariable (ue)
3375 && (ue->info->var->kind == VKYIELDPARAM
3376 || ue->info->var->kind == VKREFYIELDPARAM));
3380 uentry_isRefsField (uentry ue)
3382 return (uentry_isVariable (ue) && sRef_isRefsField (ue->sref));
3385 /*@only@*/ /*@notnull@*/
3386 uentry uentry_makeVariable (cstring n, ctype t, fileloc f, bool isPriv)
3388 return (uentry_makeVariableAux (n, t, f, sRef_makeType (t), isPriv,
3389 fileloc_isSpec (f) ? VKSPEC : VKNORMAL));
3396 void uentry_makeVarFunction (uentry ue)
3403 llassert (uentry_isValid (ue));
3404 llassert (!sRef_modInFunction ());
3406 ak = sRef_getOrigAliasKind (ue->sref);
3407 ek = sRef_getOrigExKind (ue->sref);
3409 llassert (uentry_isVariable (ue));
3410 oldInfo = ue->info->var;
3412 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
3413 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ctype_realType (ue->utype)));
3416 ** expanded macro is marked used
3419 ue->used = ue->used || (oldInfo->kind == VKEXPMACRO);
3422 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3423 ue->info->fcn->exitCode = XK_UNKNOWN;
3424 ue->info->fcn->nullPred = qual_createUnknown ();
3425 ue->info->fcn->specialCode = SPC_NONE;
3426 ue->info->fcn->access = typeIdSet_undefined;
3427 ue->info->fcn->hasGlobs = FALSE;
3428 ue->info->fcn->globs = globSet_undefined;
3429 ue->info->fcn->hasMods = FALSE;
3430 ue->info->fcn->mods = sRefSet_undefined;
3431 ue->info->fcn->specclauses = NULL;
3432 ue->info->fcn->defparams = uentryList_undefined;
3435 ue->info->fcn->preconditions = functionConstraint_undefined;
3439 ue->info->fcn->postconditions = functionConstraint_undefined;
3442 if (ctype_isFunction (ue->utype))
3444 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3448 ue->sref = sRef_makeType (ctype_unknown);
3451 if (sRef_isRefCounted (ue->sref))
3457 if (alkind_isUnknown (ak))
3459 if (exkind_isKnown (ek))
3461 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3462 ak = AK_IMPDEPENDENT;
3466 if (context_getFlag (FLG_RETIMPONLY))
3468 if (ctype_isFunction (ue->utype)
3469 && ctype_isVisiblySharable
3470 (ctype_realType (ctype_getReturnType (ue->utype))))
3472 if (uentryList_hasReturned (uentry_getParams (ue)))
3478 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3493 loc = ue->whereDeclared;
3495 sRef_setAliasKind (ue->sref, ak, loc);
3496 sRef_setNullState (ue->sref, oldInfo->nullstate, loc);
3497 sRef_setDefState (ue->sref, oldInfo->defstate, loc);
3498 sRef_setExKind (ue->sref, ek, loc);
3500 if (oldInfo->kind == VKEXPMACRO)
3506 fileloc_free (ue->whereDefined);
3507 ue->whereDefined = fileloc_undefined;
3510 uvinfo_free (oldInfo);
3513 void uentry_makeConstantFunction (uentry ue)
3520 llassert (uentry_isValid (ue));
3521 llassert (!sRef_modInFunction ());
3523 ak = sRef_getOrigAliasKind (ue->sref);
3524 ek = sRef_getOrigExKind (ue->sref);
3526 llassert (uentry_isConstant (ue));
3527 oldInfo = ue->info->uconst;
3529 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
3532 ** expanded macro is marked used (until I write a pre-processor)
3536 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3537 ue->info->fcn->exitCode = XK_UNKNOWN;
3538 ue->info->fcn->nullPred = qual_createUnknown ();
3539 ue->info->fcn->specialCode = SPC_NONE;
3540 ue->info->fcn->access = typeIdSet_undefined;
3541 ue->info->fcn->hasGlobs = FALSE;
3542 ue->info->fcn->globs = globSet_undefined;
3543 ue->info->fcn->hasMods = FALSE;
3544 ue->info->fcn->mods = sRefSet_undefined;
3545 ue->info->fcn->specclauses = NULL;
3546 ue->info->fcn->defparams = uentryList_undefined;
3549 ue->info->fcn->preconditions = functionConstraint_undefined;
3553 ue->info->fcn->postconditions = functionConstraint_undefined;
3557 if (ctype_isFunction (ue->utype))
3559 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3563 ue->sref = sRef_makeType (ctype_unknown);
3566 if (sRef_isRefCounted (ue->sref))
3572 if (alkind_isUnknown (ak))
3574 if (exkind_isKnown (ek))
3576 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3577 ak = AK_IMPDEPENDENT;
3581 if (context_getFlag (FLG_RETIMPONLY))
3583 if (ctype_isFunction (ue->utype)
3584 && ctype_isVisiblySharable
3585 (ctype_realType (ctype_getReturnType (ue->utype))))
3587 if (uentryList_hasReturned (uentry_getParams (ue)))
3593 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3608 loc = ue->whereDeclared;
3610 sRef_setAliasKind (ue->sref, ak, loc);
3611 sRef_setExKind (ue->sref, ek, loc);
3613 fileloc_free (ue->whereDefined);
3614 ue->whereDefined = fileloc_undefined;
3615 ucinfo_free (oldInfo);
3619 uentry_setGlobals (uentry ue, /*@only@*/ globSet globs)
3621 llassert (uentry_isValid (ue));
3623 globSet_markImmutable (globs);
3625 if (uentry_isIter (ue))
3627 ue->info->iter->globs = globSet_unionFree (ue->info->iter->globs, globs);
3631 uentry_convertVarFunction (ue);
3632 llassert (uentry_isFunction (ue));
3634 ue->info->fcn->hasGlobs = TRUE;
3635 ue->info->fcn->globs = globSet_unionFree (ue->info->fcn->globs, globs);
3638 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3640 ue->info->fcn->hasMods = TRUE;
3644 void uentry_addAccessType (uentry ue, typeId tid)
3646 if (uentry_isFunction (ue))
3648 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3650 else if (uentry_isEitherConstant (ue))
3652 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3654 else if (uentry_isIter (ue))
3656 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3658 else if (uentry_isEndIter (ue))
3660 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3664 llbug (message ("no access for: %q", uentry_unparse (ue)));
3668 /*@only@*/ /*@notnull@*/ uentry
3669 uentry_makeFunction (cstring n, ctype t,
3671 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
3672 /*@only@*/ warnClause warn,
3675 llassert (warnClause_isUndefined (warn)); /*@i325 remove parameter! */
3676 return (uentry_makeFunctionAux (n, t,
3677 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3678 : typeIdSet_single (access)),
3684 /*@notnull@*/ uentry
3685 uentry_makePrivFunction2 (cstring n, ctype t,
3687 globSet globs, sRefSet mods,
3690 return (uentry_makeFunctionAux (n, t, access, globs, mods, warnClause_undefined,
3695 /*@notnull@*/ uentry
3696 uentry_makeSpecFunction (cstring n, ctype t,
3698 /*@only@*/ globSet globs,
3699 /*@only@*/ sRefSet mods,
3702 uentry ue = uentry_makeFunctionAux (n, t, access,
3703 globs, mods, warnClause_undefined,
3706 uentry_setHasGlobs (ue);
3707 uentry_setHasMods (ue);
3709 reflectImplicitFunctionQualifiers (ue, TRUE);
3713 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3715 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3716 sRef_undefined, FALSE, VKEXPMACRO);
3718 uentry_setDefined (ue, f);
3722 /*@notnull@*/ /*@notnull@*/ uentry
3723 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3725 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3726 typeIdSet_singleOpt (access),
3727 globSet_undefined, sRefSet_undefined,
3728 warnClause_undefined,
3732 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3736 bool uentry_isForward (uentry e)
3738 if (uentry_isValid (e))
3740 ctype ct = uentry_getType (e);
3742 return (ctype_isUnknown (ct)
3743 || (ctype_isFunction (ct)
3744 && ctype_isUnknown (ctype_getReturnType (ct))));
3750 /*@notnull@*/ uentry
3751 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3753 return (uentry_makeFunctionAux (n, ctype_unknown, access,
3754 globSet_undefined, sRefSet_undefined, warnClause_undefined,
3758 /*@notnull@*/ uentry
3759 uentry_makeUnspecFunction (cstring n, ctype t,
3763 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_undefined,
3764 sRefSet_undefined, warnClause_undefined,
3767 reflectImplicitFunctionQualifiers (ue, TRUE);
3775 /* is exported for use by usymtab_interface */
3777 /*@notnull@*/ uentry
3778 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, ynm abstract,
3779 fileloc f, bool priv)
3781 uentry e = uentry_alloc ();
3783 DPRINTF (("Make datatype: %s / %s",
3784 n, ctype_unparse (t)));
3786 /* e->shallowCopy = FALSE; */
3787 e->ukind = KDATATYPE;
3788 e->uname = cstring_copy (n);
3790 e->storageclass = SCNONE;
3791 e->sref = sRef_makeUnknown ();
3795 sRef_setStateFromType (e->sref, t);
3798 uentry_setSpecDef (e, f);
3800 e->warn = warnClause_undefined; /*@i634@*/
3801 e->uses = filelocList_new ();
3802 e->isPrivate = priv;
3803 e->hasNameError = FALSE;
3808 e->info = (uinfo) dmalloc (sizeof (*e->info));
3809 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3810 e->info->datatype->abs = abstract;
3811 e->info->datatype->mut = mut;
3812 e->info->datatype->type = ctype_undefined;
3814 if (uentry_isDeclared (e))
3816 uentry_setDefined (e, f);
3819 if (ynm_isOn (abstract) && !(uentry_isCodeDefined (e)))
3821 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3827 /*@notnull@*/ uentry
3828 uentry_makeDatatype (cstring n, ctype t, ynm mut, ynm abstract, fileloc f)
3830 return (uentry_makeDatatypeAux (n, t, mut, abstract, f, FALSE));
3833 /*@notnull@*/ uentry uentry_makeBoolDatatype (ynm abstract)
3835 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
3836 ctype_bool, NO, abstract,
3837 fileloc_getBuiltin (),
3840 ret->info->datatype->type = ctype_bool;
3848 static /*@only@*/ /*@notnull@*/ uentry
3849 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3850 /*@only@*/ fileloc f)
3852 uentry e = uentry_alloc ();
3855 e->uname = cstring_copy (n);
3857 e->sref = sRef_makeUnknown ();
3858 e->storageclass = SCNONE;
3862 uentry_setSpecDef (e, f);
3864 e->warn = warnClause_undefined; /*@i452@*/
3865 e->uses = filelocList_new ();
3866 e->isPrivate = FALSE;
3867 e->hasNameError = FALSE;
3869 e->info = (uinfo) dmalloc (sizeof (*e->info));
3870 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3871 e->info->iter->access = access;
3872 e->info->iter->mods = sRefSet_undefined;
3873 e->info->iter->globs = globSet_undefined;
3875 uentry_checkIterArgs (e);
3879 /*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3881 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3884 static /*@notnull@*/ uentry
3885 uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3887 uentry e = uentry_alloc ();
3889 /* e->shallowCopy = FALSE; */
3890 e->ukind = KENDITER;
3891 e->storageclass = SCNONE;
3892 e->uname = message ("end_%s", n);
3893 e->utype = ctype_unknown;
3894 e->sref = sRef_makeUnknown ();
3896 uentry_setSpecDef (e, f);
3901 e->uses = filelocList_new ();
3902 e->isPrivate = FALSE;
3903 e->hasNameError = FALSE;
3905 e->info = (uinfo) dmalloc (sizeof (*e->info));
3906 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3908 e->info->enditer->access = access;
3910 e->warn = warnClause_undefined; /*@i452@*/
3914 /*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3916 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3923 static /*@only@*/ /*@notnull@*/ uentry
3924 uentry_makeTagAux (cstring n, ctype t,
3925 /*@only@*/ fileloc fl,
3926 bool priv, ekind kind)
3928 uentry e = uentry_alloc ();
3930 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3932 llbuglit ("uentry_makeTagAux: not a tag type");
3936 /* e->shallowCopy = FALSE; */
3937 e->uname = cstring_copy (n);
3940 e->sref = sRef_makeUnknown ();
3941 e->storageclass = SCNONE;
3943 uentry_setSpecDef (e, fl);
3948 e->uses = filelocList_new ();
3949 e->isPrivate = priv;
3950 e->hasNameError = FALSE;
3952 e->info = (uinfo) dmalloc (sizeof (*e->info));
3953 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3954 e->info->datatype->abs = NO;
3955 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3956 e->info->datatype->type = t;
3957 e->warn = warnClause_undefined; /*@i452@*/
3959 if (uentry_isDeclared (e))
3961 uentry_setDefined (e, fl);
3967 uentry uentry_makeStructTagLoc (cstring n, ctype t)
3969 cstring sname = makeStruct (n);
3970 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3972 cstring_free (sname);
3977 uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3979 cstring sname = makeStruct (n);
3980 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3982 cstring_free (sname);
3987 uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
3989 cstring uname = makeUnion (n);
3990 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
3992 cstring_free (uname);
3997 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
3999 cstring ename = makeEnum (n);
4000 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
4002 cstring_free (ename);
4007 uentry_makeUnionTagLoc (cstring n, ctype t)
4009 cstring uname = makeUnion (n);
4010 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
4012 cstring_free (uname);
4017 uentry_makeEnumTagLoc (cstring n, ctype t)
4019 cstring ename = makeEnum (n);
4020 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
4022 cstring_free (ename);
4027 uentry_isStructTag (uentry ue)
4029 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
4033 uentry_isUnionTag (uentry ue)
4035 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
4039 uentry_isEnumTag (uentry ue)
4041 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
4045 uentry_isAnyTag (uentry ue)
4047 return (uentry_isStructTag (ue)
4048 || uentry_isUnionTag (ue)
4049 || uentry_isEnumTag (ue));
4052 static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
4054 extern void uentry_destroyMod (void)
4055 /*@globals killed emarker@*/ /*@modifies emarker@*/
4057 static bool wasDestroyed = FALSE;
4059 llassert (!wasDestroyed);
4061 if (emarker != NULL)
4063 uentry_reallyFree (emarker);
4066 wasDestroyed = TRUE;
4070 uentry_makeElipsisMarker (void)
4072 if (emarker == NULL)
4074 emarker = uentry_alloc ();
4076 emarker->ukind = KELIPSMARKER;
4077 emarker->uname = cstring_makeLiteral ("...");
4078 emarker->utype = ctype_elipsMarker;
4079 emarker->sref = sRef_undefined;
4080 emarker->storageclass = SCNONE;
4081 emarker->used = FALSE;
4082 emarker->lset = FALSE;
4083 emarker->info = NULL;
4085 uentry_setSpecDef (emarker, fileloc_undefined);
4086 emarker->uses = filelocList_new ();
4087 emarker->isPrivate = FALSE;
4088 emarker->hasNameError = FALSE;
4091 /*@ignore@*/ return (emarker); /*@end@*/
4099 uentry_equiv (uentry p1, uentry p2)
4101 if (uentry_compare (p1, p2) != 0)
4112 uentry_xcomparealpha (uentry *p1, uentry *p2)
4116 if ((res = uentry_compare (*p1, *p2)) == 0) {
4117 if ((*p1 != NULL) && (*p2 != NULL)) {
4118 res = cstring_compare ((*p1)->uname,
4127 uentry_xcompareuses (uentry *p1, uentry *p2)
4132 if (uentry_isValid (u1))
4134 if (uentry_isValid (u2))
4136 return (-1 * int_compare (filelocList_size (u1->uses),
4137 filelocList_size (u2->uses)));
4146 if (uentry_isValid (u2))
4158 uentry_compareStrict (uentry v1, uentry v2)
4160 COMPARERETURN (uentry_compare (v1, v2));
4162 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
4164 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
4165 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
4166 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
4173 uentry_compare (uentry u1, uentry u2)
4175 if (u1 == u2) return 0;
4177 if (uentry_isInvalid (u1)) return -1;
4178 if (uentry_isInvalid (u2)) return 1;
4180 INTCOMPARERETURN (u1->ukind, u2->ukind);
4181 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
4182 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
4183 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
4189 /* bug detected by splint:
4190 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
4195 return (multiVal_compare (uentry_getConstantValue (u1),
4196 uentry_getConstantValue (u2)));
4200 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
4202 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
4203 uentry_accessType (u2)));
4204 return (uentryList_compareParams (uentry_getParams (u1),
4205 uentry_getParams (u2)));
4207 return (typeIdSet_compare (uentry_accessType (u1),
4208 uentry_accessType (u2)));
4211 ** Functions are never equivalent
4214 if (u1 - u2 < 0) /* evans 2001-08-21: was: ((int) u1 < (int) u2), changed to remove gcc warning */
4224 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
4225 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
4226 sRef_getOrigAliasKind (u2->sref)));
4227 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
4228 sRef_getOrigExKind (u2->sref)));
4229 COMPARERETURN (generic_compare (u1->info->var->checked,
4230 u2->info->var->checked));
4231 COMPARERETURN (generic_compare (u1->info->var->defstate,
4232 u2->info->var->defstate));
4233 return (generic_compare (u1->info->var->nullstate,
4234 u2->info->var->nullstate));
4236 COMPARERETURN (ctype_compare (u1->info->datatype->type,
4237 u2->info->datatype->type));
4238 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
4239 u2->info->datatype->mut));
4240 return (ynm_compare (u1->info->datatype->abs, u2->info->datatype->abs));
4249 ** all entries are: <type>[@<info>]*#<name>
4251 ** info depends on kind:
4255 advanceField (char **s)
4257 reader_checkChar (s, '@');
4261 advanceName (char **s)
4263 reader_checkChar (s, '#');
4267 vkind_fromInt (int i)
4269 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
4271 llbuglit ("vkind_fromInt: out of range");
4278 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
4279 typeIdSet access, nstate nullstate,
4280 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
4282 uentry e = uentry_alloc ();
4287 e->sref = sRef_makeConst (ct);
4289 sRef_setNullState (e->sref, nullstate, loc);
4290 e->storageclass = SCNONE;
4292 if (fileloc_isSpec (loc))
4294 e->whereSpecified = loc;
4295 e->whereDeclared = fileloc_undefined;
4299 e->whereSpecified = fileloc_undefined;
4300 e->whereDeclared = loc;
4303 e->whereDefined = fileloc_undefined;
4304 e->uses = filelocList_new ();
4305 e->isPrivate = FALSE;
4306 e->hasNameError = FALSE;
4311 e->warn = warnClause_undefined; /*@i452@*/
4313 e->info = (uinfo) dmalloc (sizeof (*e->info));
4314 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
4315 e->info->uconst->access = access;
4316 e->info->uconst->macro = FALSE; /*@i523! fix this when macro info added to library */
4317 uentry_setConstantValue (e, m);
4318 sRef_storeState (e->sref);
4323 static /*@only@*/ uentry
4324 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
4325 sstate defstate, nstate isnull, alkind aliased,
4326 exkind exp, chkind checked,
4327 /*@only@*/ fileloc loc)
4329 uentry e = uentry_alloc ();
4334 e->storageclass = SCNONE;
4336 e->sref = sRef_makeType (ct);
4337 sRef_setNullState (e->sref, isnull, loc);
4339 e->whereDefined = fileloc_undefined;
4341 if (fileloc_isSpec (loc))
4343 e->whereSpecified = loc;
4344 e->whereDeclared = fileloc_undefined;
4348 e->whereSpecified = fileloc_undefined;
4349 e->whereDeclared = loc;
4352 e->isPrivate = FALSE;
4353 e->hasNameError = FALSE;
4358 e->uses = filelocList_new ();
4359 e->warn = warnClause_undefined; /*@i452@*/
4361 e->info = (uinfo) dmalloc (sizeof (*e->info));
4362 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
4363 e->info->var->kind = kind;
4364 e->info->var->checked = checked;
4365 e->info->var->defstate = defstate;
4367 sRef_setDefState (e->sref, defstate, loc);
4369 e->info->var->nullstate = sRef_getNullState (e->sref);
4371 sRef_setExKind (e->sref, exp, loc);
4372 sRef_setAliasKind (e->sref, aliased, loc);
4374 sRef_storeState (e->sref);
4376 /*DRL ADDED 9-1-2000 */
4377 e->info->var->bufinfo = NULL;
4382 static /*@only@*/ uentry
4383 uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, ynm abstract,
4384 ynm mut, ctype rtype, alkind ak, exkind exp,
4385 sstate defstate, nstate isnull,
4386 /*@only@*/ fileloc loc)
4388 uentry e = uentry_alloc ();
4390 e->ukind = KDATATYPE;
4391 /* e->shallowCopy = FALSE; */
4394 e->storageclass = SCNONE;
4395 e->sref = sRef_makeUnknown ();
4396 DPRINTF (("Merge null 1: %s", sRef_unparseFull (e->sref)));
4399 ** This is only setting null state. (I think?)
4402 if (ctype_isUA (ct))
4404 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
4406 if (uentry_isValid (te))
4408 sRef_setStateFromUentry (e->sref, te);
4412 /* problem for recursive type definitions */
4416 sRef_setAliasKind (e->sref, ak, loc);
4417 sRef_setExKind (e->sref, exp, loc);
4419 sRef_setDefState (e->sref, defstate, loc);
4421 if (ynm_isOn (abstract) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
4423 isnull = NS_ABSNULL;
4426 DPRINTF (("Merge null: %s", sRef_unparseFull (e->sref)));
4427 sRef_mergeNullState (e->sref, isnull);
4429 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
4431 if (fileloc_isSpec (loc))
4433 e->whereSpecified = loc;
4434 e->whereDeclared = fileloc_undefined;
4438 e->whereSpecified = fileloc_undefined;
4439 e->whereDeclared = loc;
4442 e->isPrivate = FALSE;
4443 e->hasNameError = FALSE;
4445 e->warn = warnClause_undefined; /*@i452@*/
4449 e->uses = filelocList_new ();
4451 e->info = (uinfo) dmalloc (sizeof (*e->info));
4452 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4453 e->info->datatype->abs = abstract;
4454 e->info->datatype->mut = mut;
4455 e->info->datatype->type = rtype;
4457 DPRINTF (("About to store: %s", sRef_unparseFull (e->sref)));
4458 sRef_storeState (e->sref);
4459 DPRINTF (("After store: %s", sRef_unparseFull (e->sref)));
4464 static void uentry_setHasGlobs (uentry ue)
4466 llassert (uentry_isFunction (ue));
4468 ue->info->fcn->hasGlobs = TRUE;
4471 static void uentry_setHasMods (uentry ue)
4473 llassert (uentry_isFunction (ue));
4475 ue->info->fcn->hasMods = TRUE;
4478 bool uentry_hasGlobs (uentry ue)
4480 if (uentry_isFunction (ue))
4482 return (ue->info->fcn->hasGlobs);
4488 bool uentry_hasStateClauseList (uentry ue)
4490 return (uentry_isFunction (ue) && stateClauseList_isDefined (ue->info->fcn->specclauses));
4493 bool uentry_hasConditions (uentry ue)
4495 return (uentry_isFunction (ue)
4496 && (functionConstraint_isDefined (ue->info->fcn->preconditions)
4497 || functionConstraint_isDefined (ue->info->fcn->postconditions)));
4500 stateClauseList uentry_getStateClauseList (uentry ue)
4502 if (!uentry_isFunction (ue))
4504 llassert (uentry_isFunction (ue));
4505 return stateClauseList_undefined;
4508 DPRINTF (("Get state clause list: %s", uentry_unparse (ue)));
4509 return ue->info->fcn->specclauses;
4512 bool uentry_hasMods (uentry ue)
4514 if (uentry_isFunction (ue))
4516 return (ue->info->fcn->hasMods);
4523 uentry_makeFunctionBase (/*@only@*/ cstring name, ctype ct,
4525 bool hasGlobs, /*@only@*/ globSet globs,
4526 bool hasMods, /*@only@*/ sRefSet mods,
4527 alkind ak, exkind exp,
4528 sstate defstate, nstate isnull,
4532 /*@only@*/ stateClauseList specclauses,
4533 /*@only@*/ warnClause warnclause,
4534 /*@only@*/ fileloc loc)
4536 uentry e = uentry_alloc ();
4539 /* e->shallowCopy = FALSE; */
4543 e->storageclass = SCNONE;
4545 if (ctype_isFunction (ct))
4547 ret = ctype_getReturnType (ct);
4551 if (ctype_isKnown (ct))
4553 llbug (message ("not function: %s", ctype_unparse (ct)));
4556 ret = ctype_unknown;
4559 e->sref = sRef_makeType (ret);
4561 if (ctype_isUA (ret))
4563 sRef_setStateFromType (e->sref, ret);
4566 sRef_setDefined (e->sref, loc);
4567 sRef_setNullState (e->sref, isnull, loc);
4569 sRef_setAliasKind (e->sref, ak, loc);
4570 sRef_setExKind (e->sref, exp, loc);
4571 sRef_setDefState (e->sref, defstate, loc);
4573 e->whereSpecified = loc;
4574 e->whereDefined = fileloc_undefined;
4576 e->isPrivate = FALSE;
4577 e->hasNameError = FALSE;
4581 e->uses = filelocList_new ();
4582 e->warn = warnclause;
4584 e->info = (uinfo) dmalloc (sizeof (*e->info));
4585 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
4587 e->info->fcn->exitCode = exitCode;
4588 e->info->fcn->specialCode = sCode;
4589 e->info->fcn->nullPred = nullPred;
4590 e->info->fcn->access = access;
4592 e->info->fcn->specclauses = specclauses;
4593 e->info->fcn->hasGlobs = hasGlobs;
4594 e->info->fcn->globs = globs;
4596 e->info->fcn->hasMods = hasMods;
4597 e->info->fcn->mods = mods;
4599 e->info->fcn->defparams = uentryList_undefined;
4600 e->whereDeclared = fileloc_undefined;
4602 sRef_storeState (e->sref);
4605 e->info->fcn->preconditions = NULL;
4609 e->info->fcn->postconditions = NULL;
4615 static /*@only@*/ uentry
4616 uentry_makeTagBase (/*@only@*/ cstring name, ekind tagkind,
4617 ctype ct, ctype rtype, /*@only@*/ fileloc loc)
4619 uentry e = uentry_alloc ();
4621 if (tagkind != KSTRUCTTAG && tagkind != KUNIONTAG && tagkind != KENUMTAG)
4623 llbuglit ("uentry_makeTagBase: not a tag type");
4626 /* e->shallowCopy = FALSE; */
4630 e->sref = sRef_makeUnknown ();
4631 e->storageclass = SCNONE;
4633 if (fileloc_isSpec (loc))
4635 e->whereSpecified = loc;
4636 e->whereDeclared = fileloc_undefined;
4640 e->whereDeclared = loc;
4641 e->whereSpecified = fileloc_undefined;
4644 e->whereDefined = fileloc_undefined;
4646 e->isPrivate = FALSE;
4647 e->hasNameError = FALSE;
4651 e->uses = filelocList_new ();
4652 e->warn = warnClause_undefined; /*@i452@*/
4654 e->info = (uinfo) dmalloc (sizeof (*e->info));
4655 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4656 e->info->datatype->abs = NO;
4657 e->info->datatype->mut = MAYBE;
4658 e->info->datatype->type = rtype;
4660 sRef_storeState (e->sref);
4666 uentry_makeIterBase (/*@only@*/ cstring name, typeIdSet access,
4667 ctype ct, /*@only@*/ fileloc loc)
4669 uentry e = uentry_alloc ();
4671 /* e->shallowCopy = FALSE; */
4675 e->sref = sRef_makeUnknown ();
4676 e->storageclass = SCNONE;
4678 if (fileloc_isSpec (loc))
4680 e->whereSpecified = loc;
4681 e->whereDeclared = fileloc_undefined;
4685 e->whereDeclared = loc;
4686 e->whereSpecified = fileloc_undefined;
4689 e->whereDefined = fileloc_undefined;
4691 e->isPrivate = FALSE;
4692 e->hasNameError = FALSE;
4696 e->uses = filelocList_new ();
4697 e->warn = warnClause_undefined; /*@i452@*/
4699 e->info = (uinfo) dmalloc (sizeof (*e->info));
4700 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
4701 e->info->iter->access = access;
4702 e->info->iter->mods = sRefSet_undefined;
4703 e->info->iter->globs = globSet_undefined;
4705 sRef_storeState (e->sref);
4710 uentry_makeEndIterBase (/*@only@*/ cstring name, typeIdSet access,
4711 /*@only@*/ fileloc loc)
4713 uentry e = uentry_alloc ();
4715 /* e->shallowCopy = FALSE; */
4716 e->ukind = KENDITER;
4717 e->storageclass = SCNONE;
4719 e->utype = ctype_unknown;
4720 e->sref = sRef_makeUnknown ();
4722 if (fileloc_isSpec (loc))
4724 e->whereSpecified = loc;
4725 e->whereDeclared = fileloc_undefined;
4729 e->whereDeclared = loc;
4730 e->whereSpecified = fileloc_undefined;
4733 e->whereDefined = fileloc_undefined;
4735 e->isPrivate = FALSE;
4736 e->hasNameError = FALSE;
4740 e->uses = filelocList_new ();
4741 e->warn = warnClause_undefined; /*@i452@*/
4743 e->info = (uinfo) dmalloc (sizeof (*e->info));
4744 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
4745 e->info->enditer->access = access;
4746 sRef_storeState (e->sref);
4751 void uentry_markFree (/*@unused@*/ /*@owned@*/ uentry u)
4759 uentry_undump (ekind kind, fileloc loc, char **s)
4763 DPRINTF (("Uentry undump: %s", *s));
4767 reader_checkChar (s, '!');
4768 reader_checkChar (s, '.');
4769 ue = uentry_makeElipsisMarker ();
4773 ctype ct = ctype_undump (s);
4787 reader_checkChar (s, '|');
4789 if (reader_optCheckChar (s, '@'))
4791 tkind = vkind_fromInt (reader_getInt (s));
4792 reader_checkChar (s, '|');
4799 if (reader_optCheckChar (s, '$'))
4801 defstate = SS_UNKNOWN;
4802 isnull = NS_UNKNOWN;
4803 aliased = AK_IMPTEMP;
4805 checked = CH_UNKNOWN;
4807 else if (reader_optCheckChar (s, '&'))
4809 defstate = SS_DEFINED;
4810 isnull = NS_UNKNOWN;
4811 aliased = AK_IMPTEMP;
4813 checked = CH_UNKNOWN;
4815 else if (reader_optCheckChar (s, '^'))
4817 defstate = SS_UNKNOWN;
4818 isnull = NS_UNKNOWN;
4819 aliased = AK_IMPTEMP;
4821 checked = CH_UNKNOWN;
4825 defstate = sstate_fromInt (reader_getInt (s));
4826 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4827 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4829 if (reader_optCheckChar (s, '&'))
4832 checked = CH_UNKNOWN;
4836 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4837 advanceField (s); checked = (chkind) (reader_getInt (s));
4842 name = reader_getStringWord (s);
4844 llassert (!cstring_equal (name, GLOBAL_MARKER_NAME));
4846 ue = uentry_makeVariableBase (name, ct, tkind, defstate,
4847 isnull, aliased, exp,
4848 checked, fileloc_copy (loc));
4861 advanceField (s); abstract = ynm_fromCodeChar (reader_loadChar (s));
4862 advanceField (s); mut = ynm_fromCodeChar (reader_loadChar (s));
4863 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4864 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4865 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4866 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4867 advanceField (s); rtype = ctype_undump (s);
4869 name = reader_getStringWord (s);
4870 DPRINTF (("Datatype %s, Exp = %s", name, exkind_unparse (exp)));
4871 ue = uentry_makeDatatypeBase (name, ct, abstract, mut, rtype,
4872 aliased, exp, defstate, isnull,
4873 fileloc_copy (loc));
4890 stateClauseList specclauses = stateClauseList_undefined;
4891 warnClause warnclause = warnClause_undefined;
4893 if (reader_optCheckChar (s, '$'))
4895 defstate = SS_DEFINED;
4896 isnull = NS_UNKNOWN;
4897 exitCode = XK_UNKNOWN;
4899 nullPred = qual_createUnknown ();
4903 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4904 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4905 advanceField (s); exitCode = exitkind_fromInt (reader_getInt (s));
4906 advanceField (s); specc = specCode_fromInt (reader_getInt (s));
4907 advanceField (s); nullPred = qual_undump (s);
4910 if (reader_optCheckChar (s, '$'))
4913 globs = globSet_undefined;
4915 mods = sRefSet_undefined;
4917 else if (reader_optCheckChar (s, '^'))
4920 globs = globSet_undefined;
4922 mods = sRefSet_undefined;
4926 advanceField (s); hasGlobs = bool_fromInt (reader_getInt (s));
4927 advanceField (s); globs = globSet_undump (s);
4928 advanceField (s); hasMods = bool_fromInt (reader_getInt (s));
4929 advanceField (s); mods = sRefSet_undump (s);
4932 if (reader_optCheckChar (s, '$'))
4939 advanceField (s); ak = alkind_fromInt (reader_getInt (s));
4940 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4943 advanceField (s); access = typeIdSet_undump (s);
4946 ** Optional clauses: Start with @<code>:
4949 while (reader_optCheckChar (s, '@'))
4951 if (reader_optCheckChar (s, 'W')) /* Warn clause */
4953 reader_checkChar (s, ':');
4954 warnclause = warnClause_undump (s);
4956 else if (reader_optCheckChar (s, 'S')) /* stateClause List */
4958 reader_checkChar (s, ':');
4959 specclauses = stateClauseList_undump (s);
4967 advanceName (s); name = reader_getStringWord (s);
4969 ue = uentry_makeFunctionBase (name, ct, access,
4972 ak, exp, defstate, isnull,
4973 exitCode, specc, nullPred,
4976 fileloc_copy (loc));
4977 DPRINTF (("Undump: %s", uentry_unparse (ue)));
4984 advanceField (s); access = typeIdSet_undump (s);
4985 advanceName (s); name = reader_getStringWord (s);
4987 ue = uentry_makeIterBase (name, access, ct,
4988 fileloc_copy (loc));
4995 advanceField (s); access = typeIdSet_undump (s);
4996 advanceName (s); name = reader_getStringWord (s);
4998 ue = uentry_makeEndIterBase (name, access, fileloc_copy (loc));
5008 if (reader_optCheckChar (s, '$'))
5010 val = multiVal_undefined;
5011 access = typeIdSet_undefined;
5012 nullstate = NS_UNKNOWN;
5016 advanceField (s); val = multiVal_undump (s);
5017 advanceField (s); access = typeIdSet_undump (s);
5018 advanceField (s); nullstate = nstate_fromInt (reader_getInt (s));
5021 advanceName (s); name = reader_getStringWord (s);
5023 ue = uentry_makeConstantBase (name, ct, access,
5024 nullstate, fileloc_copy (loc), val);
5033 advanceField (s); rtype = ctype_undump (s);
5034 advanceName (s); name = reader_getStringWord (s);
5035 ue = uentry_makeTagBase (name, kind, ct, rtype, fileloc_copy (loc));
5039 llcontbuglit ("uentry_undump: invalid");
5040 ue = uentry_undefined;
5043 llcontbuglit ("uentry_undump: elips marker");
5044 ue = uentry_undefined;
5053 uentry_dump (uentry v)
5055 return (uentry_dumpAux (v, FALSE));
5059 uentry_dumpParam (uentry v)
5061 llassertprint (uentry_isVariable (v) || uentry_isElipsisMarker (v),
5062 ("dump: %s", uentry_unparseFull (v)));
5064 return (uentry_dumpAux (v, TRUE));
5068 uentry_dumpAux (uentry v, bool isParam)
5070 llassert (uentry_isValid (v));
5071 llassert (!uentry_isGlobalMarker (v));
5073 DPRINTF (("Dump uentry: [%p]", v));
5074 DPRINTF (("Dumping entry: %s", uentry_unparseFull (v)));
5079 llcontbuglit ("uentry_dump: invalid entry");
5080 return cstring_undefined;
5082 return (message ("!."));
5086 vkind vk = v->info->var->kind;
5087 sstate dss = sRef_getDefState (v->sref);
5088 nstate nst = sRef_getNullState (v->sref);
5089 alkind alk = sRef_getAliasKind (v->sref);
5090 exkind exk = sRef_getExKind (v->sref);
5091 chkind chk = v->info->var->checked;
5093 DPRINTF (("Dumping var"));
5095 if (dss == SS_UNKNOWN
5096 && nst == NS_UNKNOWN
5097 && alk == AK_IMPTEMP
5098 && exk == XO_UNKNOWN
5099 && chk == CH_UNKNOWN)
5101 sdump = cstring_makeLiteral ("$");
5103 else if (dss == SS_DEFINED
5104 && nst == NS_UNKNOWN
5105 && alk == AK_IMPTEMP
5106 && exk == XO_UNKNOWN
5107 && chk == CH_UNKNOWN)
5109 sdump = cstring_makeLiteral ("&");
5111 else if (dss == SS_UNKNOWN
5112 && nst == NS_UNKNOWN
5113 && alk == AK_UNKNOWN
5114 && exk == XO_UNKNOWN
5115 && chk == CH_UNKNOWN)
5117 sdump = cstring_makeLiteral ("^");
5119 else if (exk == XO_UNKNOWN
5120 && chk == CH_UNKNOWN)
5122 sdump = message ("%d@%d@%d&",
5129 sdump = message ("%d@%d@%d@%d@%d",
5140 return (message ("%q|@%d|%q#%s",
5141 ctype_dump (v->utype),
5144 isParam ? cstring_undefined : v->uname));
5148 return (message ("%q|%q#%s",
5149 ctype_dump (v->utype),
5151 isParam ? cstring_undefined : v->uname));
5157 DPRINTF (("Dumping datatype: %s -> %s type: %s [%d]",
5159 exkind_unparse (sRef_getExKind (v->sref)),
5160 ctype_unparse (v->utype), (int) v->utype));
5163 return (message ("%q@%s@%s@%d@%d@%d@%d@%q#%s",
5164 ctype_dump (v->utype),
5165 ynm_unparseCode (v->info->datatype->abs),
5166 ynm_unparseCode (v->info->datatype->mut),
5167 (int) sRef_getDefState (v->sref),
5168 (int) sRef_getNullState (v->sref),
5169 (int) sRef_getAliasKind (v->sref),
5170 (int) sRef_getExKind (v->sref),
5171 ctype_dump (v->info->datatype->type),
5175 cstring sdump, gdump, adump, xdump;
5176 alkind alk = sRef_getAliasKind (v->sref);
5177 exkind exk = sRef_getExKind (v->sref);
5179 if (sRef_getDefState (v->sref) == SS_DEFINED
5180 && !nstate_isKnown (sRef_getNullState (v->sref))
5181 && !exitkind_isKnown (v->info->fcn->exitCode)
5182 && v->info->fcn->specialCode == SPC_NONE
5183 && qual_isUnknown (v->info->fcn->nullPred))
5185 sdump = cstring_makeLiteral ("$");
5189 sdump = message ("@%d@%d@%d@%d@%x",
5190 (int) sRef_getDefState (v->sref),
5191 (int) sRef_getNullState (v->sref),
5192 (int) v->info->fcn->exitCode,
5193 (int) v->info->fcn->specialCode,
5194 qual_dump (v->info->fcn->nullPred));
5197 if (!uentry_hasGlobs(v) && !uentry_hasMods (v))
5199 gdump = cstring_makeLiteral ("$");
5201 else if (uentry_hasGlobs (v) && globSet_isEmpty (uentry_getGlobs (v))
5202 && uentry_hasMods (v) && sRefSet_isEmpty (uentry_getMods (v)))
5204 gdump = cstring_makeLiteral ("^");
5208 gdump = message ("@%s@%q@%s@%q",
5209 bool_dump (uentry_hasGlobs (v)),
5210 globSet_dump (uentry_getGlobs (v)),
5211 bool_dump (uentry_hasMods (v)),
5212 sRefSet_dump (uentry_getMods (v)));
5215 if (alk == AK_UNKNOWN && exk == XO_UNKNOWN)
5217 adump = cstring_makeLiteral ("$");
5221 adump = message ("@%d@%d", (int) alk, (int) exk);
5224 xdump = cstring_undefined;
5226 if (uentry_hasWarning (v))
5228 xdump = message ("%q@W:%q", xdump, warnClause_dump (v->warn));
5231 if (uentry_hasStateClauseList (v))
5233 xdump = message ("%q@S:%q", xdump, stateClauseList_dump (v->info->fcn->specclauses));
5236 return (message ("%q%q%q%q@%q%q#%s",
5237 ctype_dump (v->utype),
5241 typeIdSet_dump (uentry_accessType (v)),
5246 return (message ("%q@%q#%s",
5247 ctype_dump (v->utype),
5248 typeIdSet_dump (v->info->iter->access),
5251 return (message ("%q@%q#%s",
5252 ctype_dump (v->utype),
5253 typeIdSet_dump (uentry_accessType (v)),
5260 if (multiVal_isUnknown (uentry_getConstantValue (v))
5261 && typeIdSet_isEmpty (uentry_accessType (v))
5262 && (sRef_getNullState (v->sref) == NS_UNKNOWN))
5264 sdump = cstring_makeLiteral ("$");
5268 sdump = message ("@%q@%q@%d",
5269 multiVal_dump (uentry_getConstantValue (v)),
5270 typeIdSet_dump (uentry_accessType (v)),
5271 (int) sRef_getNullState (v->sref));
5274 return (message ("%q%q#%s",
5275 ctype_dump (v->utype),
5282 return (message ("%q@%q#%s",
5283 ctype_dump (v->utype),
5284 ctype_dump (v->info->datatype->type), v->uname));
5291 uentry_unparseAbbrev (uentry v)
5293 if (!uentry_isVariable (v))
5295 llcontbuglit ("uentry_unparseAbbrev: not variable");
5296 return uentry_unparse (v);
5299 return (message ("%s %q", ctype_unparseDeep (v->utype), uentry_getName (v)));
5303 uentry_unparse (uentry v)
5307 if (uentry_isUndefined (v)) return (cstring_makeLiteral ("<undefined>"));
5308 if (uentry_isElipsisMarker (v)) return (cstring_makeLiteral ("..."));
5310 st = uentry_getName (v);
5312 if (cstring_isDefined (st))
5314 return (ctype_unparseDeclaration (v->utype, st));
5319 return (cstring_copy (ctype_unparse (v->utype)));
5324 uentry_unparseFull (uentry v)
5326 if (uentry_isUndefined (v))
5328 return (cstring_makeLiteral ("<undefined>"));
5334 res = message ("[%w] %s %s: %s [spec: %q; decl: %q; def: %q]",
5335 (unsigned long) v, ekind_unparse (v->ukind), v->uname,
5336 ctype_unparse (v->utype),
5337 fileloc_unparse (uentry_whereSpecified (v)),
5338 fileloc_unparse (uentry_whereDeclared (v)),
5339 fileloc_unparse (uentry_whereDefined (v)));
5341 DPRINTF (("uentry: %s", res));
5343 if (uentry_isDatatype (v))
5345 res = message ("%q / type: %s mut: %s abs: %s state: %q",
5348 (ctype_isDefined (v->info->datatype->type)
5349 ? v->info->datatype->type : ctype_unknown),
5350 ynm_unparse (v->info->datatype->mut),
5351 ynm_unparse (v->info->datatype->abs),
5352 sRef_unparseState (v->sref));
5354 else if (uentry_isFunction (v))
5356 res = message ("%q / sref: %q / mods: %q / "
5357 "globs: %q / clauses: %q / pre: %q / post: %q",
5359 sRef_unparseFull (v->sref),
5360 sRefSet_unparse (v->info->fcn->mods),
5361 globSet_unparse (v->info->fcn->globs),
5362 stateClauseList_unparse (v->info->fcn->specclauses),
5363 functionConstraint_unparse (v->info->fcn->preconditions),
5364 functionConstraint_unparse (v->info->fcn->postconditions));
5366 else if (uentry_isIter (v))
5368 res = message ("%q / sref: %q",
5370 sRef_unparseFull (v->sref));
5372 else if (uentry_isVariable (v))
5374 res = message ("%q / sref: %q / kind <%d> isout <%d> null <%d> used <%d>",
5376 sRef_unparseFull (v->sref),
5377 (int) v->info->var->kind,
5378 (int) v->info->var->defstate,
5379 (int) v->info->var->nullstate,
5381 DPRINTF (("sref: [%p]", v->sref));
5382 DPRINTF (("sref: %s", sRef_unparseDebug (v->sref)));
5383 /* DPRINTF (("sref: %s", sRef_unparseDeep (v->sref))); */
5385 else if (uentry_isConstant (v))
5387 res = message ("%q = %q / %q",
5388 res, multiVal_unparse (uentry_getConstantValue (v)),
5389 sRef_unparseFull (v->sref));
5393 res = message ("%q :: %q", res, uentry_unparse (v));
5400 bool uentry_hasAccessType (uentry e)
5402 if (uentry_isValid (e))
5407 return (!typeIdSet_isEmpty (e->info->iter->access));
5409 return (!typeIdSet_isEmpty (e->info->enditer->access));
5411 return (!typeIdSet_isEmpty (e->info->fcn->access));
5414 return (!typeIdSet_isEmpty (e->info->uconst->access));
5423 typeIdSet uentry_accessType (uentry e)
5425 if (uentry_isValid (e))
5430 return (e->info->iter->access);
5432 return (e->info->enditer->access);
5434 return (e->info->fcn->access);
5437 return (e->info->uconst->access);
5443 return typeIdSet_undefined;
5447 uentry_isVariable (uentry e)
5449 return (uentry_isVar (e));
5453 uentry_isSpecified (uentry e)
5455 return (uentry_isValid (e) && !fileloc_isUndefined (e->whereSpecified));
5459 uentry_isReallySpecified (uentry e)
5461 return (uentry_isValid (e)
5462 && fileloc_isRealSpec (e->whereSpecified));
5466 uentry_isVar (uentry e)
5468 return (!uentry_isUndefined (e) && e->ukind == KVAR);
5472 uentry_isFakeTag (uentry e)
5474 return (uentry_isValid (e) && strchr (cstring_toCharsSafe (e->uname), '!') != 0);
5478 uentry_isDatatype (uentry e)
5480 return (!uentry_isUndefined (e) &&
5481 (e->ukind == KDATATYPE || e->ukind == KSTRUCTTAG ||
5482 e->ukind == KUNIONTAG || e->ukind == KENUMTAG));
5486 uentry_setAbstract (uentry e)
5490 llassert (uentry_isDatatype (e)
5491 && (ynm_isMaybe (e->info->datatype->abs)));
5493 oldid = ctype_typeId (e->info->datatype->type);
5494 e->info->datatype->abs = YES;
5495 e->info->datatype->type = ctype_createAbstract (oldid);
5499 uentry_setConcrete (uentry e)
5501 llassert (uentry_isDatatype (e)
5502 && (ynm_isMaybe (e->info->datatype->abs)));
5504 e->info->datatype->abs = NO;
5508 uentry_isAbstractDatatype (uentry e)
5510 return (uentry_isDatatype (e)
5511 && (ynm_isOn (e->info->datatype->abs)));
5515 uentry_isMaybeAbstract (uentry e)
5517 return (uentry_isDatatype (e)
5518 && (ynm_isMaybe (e->info->datatype->abs)));
5522 uentry_isMutableDatatype (uentry e)
5524 bool res = uentry_isDatatype (e)
5525 && (ynm_toBoolRelaxed (e->info->datatype->mut));
5531 uentry_isRefCountedDatatype (uentry e)
5533 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
5537 uentry_isParam (uentry u)
5539 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
5540 || u->info->var->kind == VKYIELDPARAM));
5544 uentry_isExpandedMacro (uentry u)
5546 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
5550 uentry_isSefParam (uentry u)
5552 return (uentry_isVariable (u)
5553 && (u->info->var->kind == VKSEFPARAM
5554 || u->info->var->kind == VKREFSEFPARAM
5555 || u->info->var->kind == VKSEFRETPARAM
5556 || u->info->var->kind == VKREFSEFRETPARAM));
5560 uentry_isRefParam (uentry u)
5562 return (uentry_isVariable (u)
5563 && (u->info->var->kind == VKREFPARAM
5564 || u->info->var->kind == VKREFYIELDPARAM
5565 || u->info->var->kind == VKREFSEFPARAM
5566 || u->info->var->kind == VKREFSEFRETPARAM));
5570 uentry_isAnyParam (uentry u)
5572 return (uentry_isVariable (u)
5573 && ((u->info->var->kind == VKPARAM)
5574 || (u->info->var->kind == VKSEFPARAM)
5575 || (u->info->var->kind == VKYIELDPARAM)
5576 || (u->info->var->kind == VKRETPARAM)
5577 || (u->info->var->kind == VKSEFRETPARAM)));
5581 uentry_getDefState (uentry u)
5583 if (uentry_isValid (u))
5585 return (sRef_getDefState (u->sref));
5589 return (SS_UNKNOWN);
5594 uentry_isOut (uentry u)
5596 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5597 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5601 uentry_isPartial (uentry u)
5603 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5604 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5608 uentry_isStateSpecial (uentry u)
5610 return ((uentry_isVariable (u)
5611 && (u->info->var->defstate == SS_SPECIAL))
5612 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5615 exitkind uentry_getExitCode (uentry ue)
5617 if (uentry_isFunction (ue))
5619 return ue->info->fcn->exitCode;
5627 qual uentry_nullPred (uentry u)
5629 llassert (uentry_isRealFunction (u));
5631 if (uentry_isFunction (u))
5633 return (u->info->fcn->nullPred);
5637 return qual_createUnknown ();
5642 ** Note for variables, this is checking the declared state, not the current state.
5646 uentry_possiblyNull (uentry u)
5648 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5649 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5653 uentry_getAliasKind (uentry u)
5655 if (uentry_isValid (u))
5657 return (sRef_getAliasKind (uentry_getSref (u)));
5666 uentry_getExpKind (uentry u)
5668 if (uentry_isValid (u))
5670 return (sRef_getExKind (uentry_getSref (u)));
5679 uentry_isIter (uentry e)
5681 return (!uentry_isUndefined (e) && e->ukind == KITER);
5685 uentry_isEndIter (uentry e)
5687 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5691 uentry_isRealFunction (uentry e)
5693 return (uentry_isFunction (e) ||
5694 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5698 uentry_hasName (uentry e)
5700 if (uentry_isValid (e))
5702 cstring s = e->uname;
5704 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")
5705 || uentry_isFakeTag (e)));
5714 ** Returns true for fake tags.
5715 ** This is used for dumping the library
5718 bool uentry_hasRealName (uentry e)
5720 return (uentry_isValid (e)
5721 && cstring_isNonEmpty (e->uname)
5722 && !uentry_isGlobalMarker (e));
5726 /*@observer@*/ globSet
5727 uentry_getGlobs (uentry l)
5729 if (uentry_isInvalid (l))
5731 return globSet_undefined;
5734 if (uentry_isFunction (l))
5736 return l->info->fcn->globs;
5738 else if (uentry_isIter (l))
5740 return l->info->iter->globs;
5742 else if (uentry_isEndIter (l))
5744 return globSet_undefined;
5748 if (l->ukind == KVAR)
5750 llcontbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
5752 ekind_unparse (l->ukind)));
5756 llcontbug (message ("Bad call to uentry_getGlobs: %q (%s)",
5758 ekind_unparse (l->ukind)));
5761 return globSet_undefined;
5765 /*@observer@*/ sRefSet
5766 uentry_getMods (uentry l)
5768 llassert (uentry_isValid (l));
5770 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5772 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5773 return sRefSet_undefined;
5776 if (uentry_isFunction (l))
5778 return l->info->fcn->mods;
5780 else if (uentry_isIter (l))
5782 return l->info->iter->mods;
5784 else if (uentry_isEndIter (l))
5786 return sRefSet_undefined;
5795 uentry_getKind (uentry e)
5797 llassert (uentry_isValid (e));
5802 /*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5804 llassert (uentry_isEitherConstant (e));
5805 return (sRef_getValue (e->sref));
5808 /*@observer@*/ uentryList
5809 uentry_getParams (uentry l)
5811 if (uentry_isInvalid (l)) return uentryList_undefined;
5818 ctype ct = l->utype;
5820 if (ctype_isFunction (ct))
5822 return (ctype_argsFunction (ct));
5826 return uentryList_undefined;
5831 ctype ct = l->utype;
5833 /*drl 12/10/2002 changed to fix bug involving multiple redefines of library functions in macros. Bug was reported by Malcolm Parsons
5835 Old code was simplly llassert (ctype_isFunction (ct) );
5838 llassert (ctype_isFunction (ct) || context_inMacro() );
5840 return (ctype_argsFunction (ct));
5847 /*@observer@*/ cstring
5848 uentry_rawName (uentry e)
5850 if (uentry_isValid (e))
5856 return cstring_undefined;
5861 uentry_getOptName (uentry e)
5863 cstring s = uentry_getName (e);
5865 if (cstring_isDefined (s))
5867 s = cstring_appendChar (s, ' ');
5874 uentry_getName (uentry e)
5876 cstring ret = cstring_undefined;
5878 if (uentry_isValid (e))
5880 if (uentry_isAnyTag (e))
5882 ret = fixTagName (e->uname);
5884 else if (uentry_isAnyParam (e))
5886 ret = cstring_copy (fixParamName (e->uname));
5890 ret = cstring_copy (e->uname);
5897 cstring uentry_observeRealName (uentry e)
5899 cstring ret = cstring_undefined;
5901 if (uentry_isValid (e))
5903 if (uentry_isAnyTag (e))
5905 if (isFakeTag (e->uname))
5907 ret = cstring_undefined;
5911 ret = plainTagName (e->uname);
5914 else if (uentry_isAnyParam (e))
5916 ret = fixParamName (e->uname);
5927 cstring uentry_getRealName (uentry e)
5929 if (uentry_isValid (e))
5931 if (uentry_isAnyTag (e))
5933 return (cstring_undefined);
5940 return cstring_undefined;
5943 ctype uentry_getType (uentry e)
5945 if (uentry_isValid (e))
5951 return ctype_unknown;
5955 fileloc uentry_whereLast (uentry e)
5959 if (uentry_isInvalid (e))
5961 return fileloc_undefined;
5964 loc = e->whereDefined;
5966 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5971 loc = uentry_whereDeclared (e);
5973 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5978 loc = uentry_whereSpecified (e);
5982 fileloc uentry_whereEither (uentry e)
5984 if (uentry_isInvalid (e)) return fileloc_undefined;
5986 if (fileloc_isDefined (e->whereDefined)
5987 && !fileloc_isExternal (e->whereDefined))
5989 return e->whereDefined;
5991 else if (fileloc_isDefined (e->whereDeclared))
5993 return e->whereDeclared;
5997 return e->whereSpecified;
6001 fileloc uentry_whereSpecified (uentry e)
6003 if (uentry_isInvalid (e)) return fileloc_undefined;
6005 return (e->whereSpecified);
6008 fileloc uentry_whereDefined (uentry e)
6010 if (uentry_isInvalid (e)) return fileloc_undefined;
6012 return (e->whereDefined);
6015 fileloc uentry_whereDeclared (uentry e)
6017 if (uentry_isInvalid (e)) return fileloc_undefined;
6019 return (e->whereDeclared);
6022 /*@observer@*/ fileloc
6023 uentry_whereEarliest (uentry e)
6025 if (uentry_isInvalid (e)) return fileloc_undefined;
6027 if (fileloc_isDefined (e->whereSpecified))
6029 return (e->whereSpecified);
6031 else if (fileloc_isDefined (e->whereDeclared))
6033 return (e->whereDeclared);
6037 return e->whereDefined;
6042 uentry_setFunctionDefined (uentry e, fileloc loc)
6044 if (uentry_isValid (e))
6046 llassert (uentry_isFunction (e));
6048 if (fileloc_isUndefined (e->whereDeclared))
6050 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
6053 if (!fileloc_isDefined (e->whereDefined))
6055 e->whereDefined = fileloc_update (e->whereDefined, loc);
6061 uentry_setDeclDef (uentry e, fileloc f)
6063 uentry_setDeclared (e, f);
6065 if (!uentry_isFunction (e)
6066 && !(uentry_isVariable (e) && uentry_isExtern (e)))
6068 uentry_setDefined (e, f);
6073 uentry_setDeclaredForce (uentry e, fileloc f)
6075 llassert (uentry_isValid (e));
6076 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6080 uentry_setDeclaredForceOnly (uentry e, fileloc f)
6082 llassert (uentry_isValid (e));
6083 fileloc_free (e->whereDeclared);
6084 e->whereDeclared = f;
6088 uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
6092 llassert (uentry_isValid (e));
6093 oldloc = e->whereDeclared;
6095 if (fileloc_isDefined (oldloc))
6097 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6099 e->whereDeclared = f;
6100 fileloc_free (oldloc);
6109 e->whereDeclared = f;
6110 fileloc_free (oldloc);
6115 uentry_setDeclared (uentry e, fileloc f)
6119 llassert (uentry_isValid (e));
6120 oldloc = e->whereDeclared;
6122 if (fileloc_isDefined (oldloc))
6124 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6126 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6135 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6140 uentry_clearDefined (uentry e)
6142 if (uentry_isValid (e))
6144 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
6149 uentry_setDefined (uentry e, fileloc f)
6153 llassert (uentry_isValid (e));
6154 oldloc = e->whereDefined;
6156 if (fileloc_isDefined (oldloc))
6158 if (fileloc_isLib (oldloc)
6159 || fileloc_isImport (oldloc)
6160 || fileloc_isBuiltin (oldloc)
6161 || fileloc_isPreproc (oldloc))
6163 e->whereDefined = fileloc_update (e->whereDefined, f);
6167 if (fileloc_equal (oldloc, f) || context_processingMacros ())
6173 if (optgenerror (FLG_REDEF,
6174 message ("%s %q redefined",
6175 ekind_capName (e->ukind),
6176 uentry_getName (e)),
6179 llgenindentmsg (message ("Previous definition of %q",
6180 uentry_getName (e)),
6188 e->whereDefined = fileloc_update (e->whereDefined, f);
6193 uentry_isCodeDefined (uentry e)
6195 llassert (uentry_isValid (e));
6197 return (fileloc_isDefined (e->whereDefined));
6201 uentry_isDeclared (uentry e)
6203 if (uentry_isValid (e))
6205 return (fileloc_isDefined (e->whereDeclared));
6211 sRef uentry_getSref (uentry e)
6213 /* not true, used for functions too (but shouldn't be? */
6214 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
6216 if (uentry_isInvalid (e)) return sRef_undefined;
6221 sRef uentry_getOrigSref (uentry e)
6223 /*@i523*/ /* evans 2001-09-09 - need to fix this
6224 if (uentry_isValid (e))
6226 if (uentry_isVariable (e))
6228 return e->info->var->origsref;
6232 sRef sr = sRef_copy (uentry_getSref (e));
6234 sRef_resetState (sr);
6235 sRef_clearDerived (sr);
6241 return sRef_undefined;
6245 if (uentry_isValid (e))
6247 sRef sr = sRef_copy (uentry_getSref (e));
6249 sRef_resetState (sr);
6250 sRef_clearDerived (sr);
6252 if (uentry_isVariable (e))
6254 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
6255 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
6262 return sRef_undefined;
6267 ** requires: uentry e is not in a hashed symbol table
6271 uentry_setName (uentry e, /*@only@*/ cstring n)
6273 llassert (uentry_isValid (e));
6275 cstring_free (e->uname);
6280 uentry_setType (uentry e, ctype t)
6282 if (uentry_isValid (e))
6285 sRef_setType (e->sref, t);
6290 uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
6293 ctype rettype = ctype_unknown;
6295 llassert (uentry_isValid (ue));
6297 uentry_convertVarFunction (ue);
6298 llassert (uentry_isFunction (ue));
6300 rct = ctype_realType (ue->utype);
6302 if (ctype_isFunction (rct))
6304 rettype = ctype_getReturnType (rct);
6307 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
6311 uentry_setRefParam (uentry e)
6313 if (!uentry_isVar (e))
6315 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6319 if (e->info->var->kind == VKSEFPARAM)
6321 e->info->var->kind = VKREFSEFPARAM;
6323 else if (e->info->var->kind == VKSEFRETPARAM)
6325 e->info->var->kind = VKREFSEFRETPARAM;
6327 else if (e->info->var->kind == VKYIELDPARAM)
6329 e->info->var->kind = VKREFYIELDPARAM;
6333 e->info->var->kind = VKREFPARAM;
6339 uentry_setParam (uentry e)
6341 if (!uentry_isVar (e))
6343 if (uentry_isElipsisMarker (e))
6349 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6356 if (e->info->var->kind == VKYIELDPARAM
6357 || e->info->var->kind == VKSEFPARAM
6358 || e->info->var->kind == VKSEFRETPARAM)
6364 e->info->var->kind = VKPARAM;
6368 e->uname = makeParam (e->uname);
6369 cstring_free (oldname);
6374 uentry_setSref (uentry e, sRef s)
6376 if (uentry_isValid (e))
6378 if (sRef_isValid (e->sref))
6380 sRef_mergeStateQuietReverse (e->sref, s);
6384 e->sref = sRef_saveCopy (s);
6390 uentry_getAbstractType (uentry e)
6392 llassert (uentry_isDatatype (e));
6395 ** This assertion removed.
6396 ** Okay to have undefined type, for system types
6398 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
6399 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
6404 if (ctype_isUndefined (e->info->datatype->type))
6406 return ctype_unknown;
6410 ** Sadly, a kludge...
6413 if (ctype_isUserBool (e->info->datatype->type)) {
6417 return e->info->datatype->type;
6420 ctype uentry_getRealType (uentry e)
6423 typeId uid = USYMIDINVALID;
6425 if (uentry_isInvalid (e))
6427 return ctype_unknown;
6430 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6432 if (uentry_isAnyTag (e))
6437 if (uentry_isAbstractType (e))
6439 ct = uentry_getAbstractType (e);
6441 if (ctype_isManifestBool (ct)) {
6445 llassert (ctype_isUA (ct));
6447 uid = ctype_typeId (ct);
6449 if (!context_hasAccess (uid))
6455 ct = uentry_getType (e);
6457 /* if (ctype_isUserBool (ct)) return ct; */
6459 if (ctype_isManifestBool (ct)) {
6463 if (ctype_isUA (ct))
6465 usymId iid = ctype_typeId (ct);
6467 if (usymId_equal (iid, uid))
6469 llcontbug (message ("uentry_getRealType: recursive type! %s",
6470 ctype_unparse (ct)));
6475 /* evs 2000-07-25: possible infinite recursion ? */
6476 uentry ue2 = usymtab_getTypeEntry (iid);
6480 llcontbug (message ("Bad recursion: %q", uentry_unparseFull (e)));
6481 return ctype_unknown;
6484 return uentry_getRealType (ue2);
6493 ctype uentry_getForceRealType (uentry e)
6496 typeId uid = USYMIDINVALID;
6498 if (uentry_isInvalid (e))
6500 return ctype_unknown;
6503 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6505 if (uentry_isAnyTag (e))
6510 if (uentry_isAbstractType (e))
6512 ct = uentry_getAbstractType (e);
6513 llassert (ctype_isUA (ct));
6515 uid = ctype_typeId (ct);
6516 /* no check for access! */
6519 ct = uentry_getType (e);
6521 /* evs 2000-07-25 */
6522 /* if (ctype_isUserBool (ct)) return ct; */
6524 if (ctype_isManifestBool (ct)) {
6528 if (ctype_isUA (ct))
6530 usymId iid = ctype_typeId (ct);
6532 if (usymId_equal (iid, uid))
6534 llcontbug (message ("uentry_getRealType: recursive type! %s",
6535 ctype_unparse (ct)));
6540 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
6549 uentry uentry_nameCopy (cstring name, uentry e)
6551 uentry enew = uentry_alloc ();
6553 llassert (uentry_isValid (e));
6555 /* enew->shallowCopy = FALSE; */
6556 enew->ukind = e->ukind;
6558 enew->utype = e->utype;
6559 enew->whereSpecified = fileloc_copy (e->whereSpecified);
6560 enew->whereDefined = fileloc_copy (e->whereDefined);
6561 enew->whereDeclared = fileloc_copy (e->whereDeclared);
6562 enew->sref = sRef_copy (e->sref);
6563 enew->used = e->used;
6565 enew->isPrivate = e->isPrivate;
6566 enew->hasNameError = FALSE;
6568 enew->uses = filelocList_new ();
6569 enew->warn = warnClause_undefined;
6571 enew->storageclass = e->storageclass;
6572 enew->info = uinfo_copy (e->info, e->ukind);
6578 uentry_setDatatype (uentry e, usymId uid)
6580 llassert (uentry_isDatatype (e));
6582 if (uentry_isAbstractType (e))
6584 e->info->datatype->type = ctype_createAbstract (uid);
6588 e->info->datatype->type = ctype_createUser (uid);
6593 uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
6594 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
6597 llassert (uentry_isValid (e));
6599 if (fileloc_isSpec (f) || fileloc_isImport (f))
6601 e->whereSpecified = f;
6602 e->whereDeclared = fileloc_undefined;
6603 e->whereDefined = fileloc_undefined;
6607 e->whereSpecified = fileloc_undefined;
6608 e->whereDeclared = f;
6609 e->whereDefined = fileloc_undefined;
6612 llassert (fileloc_storable (f));
6616 ucinfo_free (/*@only@*/ ucinfo u)
6622 uvinfo_free (/*@only@*/ uvinfo u)
6624 /*drl7x added 6/29/01 */
6625 free (u->bufinfo); /* evans - 2001-07-19 fixed this bug */
6630 udinfo_free (/*@only@*/ udinfo u)
6636 ufinfo_free (/*@only@*/ ufinfo u)
6638 globSet_free (u->globs);
6639 sRefSet_free (u->mods);
6640 stateClauseList_free (u->specclauses);
6645 uiinfo_free (/*@only@*/ uiinfo u)
6651 ueinfo_free (/*@only@*/ ueinfo u)
6656 static /*@only@*/ ucinfo
6657 ucinfo_copy (ucinfo u)
6659 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
6660 ret->access = u->access;
6661 ret->macro = u->macro;
6665 static /*@only@*/ uvinfo
6666 uvinfo_copy (uvinfo u)
6668 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
6670 ret->kind = u->kind;
6671 ret->nullstate = u->nullstate;
6672 ret->defstate = u->defstate;
6673 ret->checked = u->checked;
6675 /*@i523 ret->origsref = sRef_copy (u->origsref); */
6677 /* drl added 07-02-001 */
6678 /* copy null terminated information */
6680 if (u->bufinfo != NULL)
6682 ret->bufinfo = (bbufinfo) dmalloc (sizeof( * u->bufinfo ) );
6683 ret->bufinfo->bufstate = u->bufinfo->bufstate;
6684 ret->bufinfo->size = u->bufinfo->size;
6685 ret->bufinfo->len = u->bufinfo->len;
6690 ret->bufinfo = NULL;
6696 static /*@only@*/ udinfo
6697 udinfo_copy (udinfo u)
6699 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6703 ret->type = u->type;
6708 static /*@only@*/ ufinfo
6709 ufinfo_copy (ufinfo u)
6711 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6713 ret->hasGlobs = u->hasGlobs;
6714 ret->hasMods = u->hasMods;
6715 ret->exitCode = u->exitCode;
6716 ret->specialCode = u->specialCode;
6717 ret->nullPred = u->nullPred;
6718 ret->access = u->access;
6719 ret->globs = globSet_newCopy (u->globs);
6720 ret->mods = sRefSet_newCopy (u->mods);
6721 ret->defparams = u->defparams;
6722 ret->specclauses = stateClauseList_copy (u->specclauses);
6724 ret->preconditions = functionConstraint_copy (u->preconditions);
6725 ret->postconditions = functionConstraint_copy (u->postconditions);
6730 static /*@only@*/ uiinfo
6731 uiinfo_copy (uiinfo u)
6733 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6735 ret->access = u->access;
6736 ret->globs = globSet_newCopy (u->globs);
6737 ret->mods = sRefSet_newCopy (u->mods);
6742 static /*@only@*/ ueinfo
6743 ueinfo_copy (ueinfo u)
6745 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6747 ret->access = u->access;
6752 uinfo_free (uinfo u, ekind kind)
6757 case KCONST: ucinfo_free (u->uconst); break;
6758 case KVAR: uvinfo_free (u->var); break;
6762 case KDATATYPE: udinfo_free (u->datatype); break;
6763 case KFCN: ufinfo_free (u->fcn); break;
6764 case KITER: uiinfo_free (u->iter); break;
6765 case KENDITER: ueinfo_free (u->enditer); break;
6766 case KELIPSMARKER: break;
6767 case KINVALID: break;
6773 static /*@only@*/ /*@null@*/ uinfo
6774 uinfo_copy (uinfo u, ekind kind)
6776 if (kind == KELIPSMARKER || kind == KINVALID)
6782 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6787 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6788 case KVAR: ret->var = uvinfo_copy (u->var); break;
6792 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6793 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6794 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6795 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6803 uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6805 filelocList_free (e->uses);
6806 cstring_free (e->uname);
6808 uinfo_free (e->info, e->ukind);
6810 fileloc_free (e->whereSpecified);
6811 fileloc_free (e->whereDefined);
6812 fileloc_free (e->whereDeclared);
6814 warnClause_free (e->warn);
6820 extern void uentry_markOwned (/*@owned@*/ uentry u)
6822 sfreeEventually (u);
6826 uentry_free (/*@only@*/ uentry e)
6828 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6830 uentry_reallyFree (e);
6835 ** For uentry's in the global or file scope
6839 uentry_freeComplete (/*@only@*/ uentry e)
6841 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6843 DPRINTF (("Free complete: %s", sRef_unparseFull (e->sref)));
6844 /*@i@*/ sRef_free (e->sref);
6845 e->sref = sRef_undefined;
6846 uentry_reallyFree (e);
6851 ** requires old->kind != new->kind, old->uname = new->uname
6855 KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6857 llassert (uentry_isValid (old));
6858 llassert (uentry_isValid (unew));
6860 if ((uentry_isEitherConstant (unew) || uentry_isDatatype (unew))
6861 && (fileloc_isPreproc (uentry_whereDeclared (old))
6862 || ctype_isUnknown (old->utype))
6863 && !uentry_isSpecified (old))
6871 if (!uentry_isDeclared (old))
6873 if (uentry_isSpecified (old))
6875 if (uentry_isSpecified (unew))
6877 llbuglit ("Respecification!");
6879 else if (uentry_isDeclared (unew))
6883 message ("%s %q inconsistently declared as %s: %t",
6884 ekind_capName (old->ukind),
6885 uentry_getName (unew),
6886 ekind_unparseLong (unew->ukind),
6888 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6890 uentry_showWhereLastKind (old);
6902 message ("%s %q inconsistently declared as %s: %t",
6903 ekind_capName (old->ukind),
6904 uentry_getName (unew),
6905 ekind_unparseLong (unew->ukind),
6907 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6909 uentry_showWhereLastKind (old);
6915 llassert (uentry_isDeclared (unew));
6917 DPRINTF (("Old: \n\t%s", uentry_unparseFull (old)));
6918 DPRINTF (("New: \n\t%s", uentry_unparseFull (unew)));
6922 message ("%s %q inconsistently redeclared as %s",
6923 ekind_capName (old->ukind),
6924 uentry_getName (unew),
6925 ekind_unparseLong (unew->ukind)),
6926 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6928 uentry_showWhereLastKind (old);
6934 uentry_updateInto (old, unew);
6938 ** def is the definition of spec, modifies spec
6940 ** reports any inconsistencies
6941 ** returns the summary of all available information
6942 ** if spec and def are inconsistent, def is returned
6946 uentry_showWhereLast (uentry spec)
6948 if (uentry_isValid (spec))
6950 if (fileloc_isDefined (spec->whereDefined)
6951 && !fileloc_isLib (spec->whereDefined)
6952 /*!! && !fileloc_isPreproc (spec->whereDefined) */ )
6954 llgenindentmsg (message ("Previous definition of %q: %t",
6955 uentry_getName (spec),
6956 uentry_getType (spec)),
6957 uentry_whereDefined (spec));
6959 else if (uentry_isDeclared (spec))
6961 llgenindentmsg (message ("Previous declaration of %q: %t",
6962 uentry_getName (spec),
6963 uentry_getType (spec)),
6964 uentry_whereDeclared (spec));
6966 else if (uentry_isSpecified (spec))
6968 if (uentry_hasName (spec))
6970 llgenindentmsg (message ("Specification of %q: %t",
6971 uentry_getName (spec),
6972 uentry_getType (spec)),
6973 uentry_whereSpecified (spec));
6977 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
6978 uentry_whereSpecified (spec));
6983 /* nothing to show */
6989 uentry_showWhereLastKind (uentry spec)
6991 if (uentry_isValid (spec))
6993 if (fileloc_isDefined (spec->whereDefined)
6994 && !fileloc_isLib (spec->whereDefined)
6995 /*!! && !fileloc_isPreproc (spec->whereDefined) */ )
6997 llgenindentmsg (message ("Previous definition of %q as %s: %t",
6998 uentry_getName (spec),
6999 ekind_unparseLong (spec->ukind),
7000 uentry_getType (spec)),
7001 uentry_whereDefined (spec));
7003 else if (uentry_isDeclared (spec))
7005 llgenindentmsg (message ("Previous declaration of %q as %s: %t",
7006 uentry_getName (spec),
7007 ekind_unparseLong (spec->ukind),
7008 uentry_getType (spec)),
7009 uentry_whereDeclared (spec));
7011 else if (uentry_isSpecified (spec))
7013 if (uentry_hasName (spec))
7015 llgenindentmsg (message ("Specification of %q as %s: %t",
7016 uentry_getName (spec),
7017 ekind_unparseLong (spec->ukind),
7018 uentry_getType (spec)),
7019 uentry_whereSpecified (spec));
7023 llgenindentmsg (message ("Specification as %s: %t",
7024 ekind_unparseLong (spec->ukind),
7025 uentry_getType (spec)),
7026 uentry_whereSpecified (spec));
7031 /* nothing to show */
7037 uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
7039 fileloc loc = uentry_whereDefined (ce);
7041 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
7043 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
7047 loc = uentry_whereSpecified (ce);
7049 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
7051 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
7056 void uentry_showWhereLastExtra (uentry spec, cstring extra)
7058 if (uentry_isDeclared (spec))
7060 llgenindentmsg (message ("Previous declaration of %q: %q",
7061 uentry_getName (spec), extra),
7062 uentry_whereDeclared (spec));
7064 else if (uentry_isSpecified (spec))
7066 llgenindentmsg (message ("Specification of %q: %q",
7067 uentry_getName (spec), extra),
7068 uentry_whereSpecified (spec));
7072 cstring_free (extra);
7077 uentry_showWhereDeclared (uentry spec)
7079 if (uentry_isDeclared (spec))
7081 if (uentry_hasName (spec))
7083 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7084 uentry_whereDeclared (spec));
7088 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
7091 else if (uentry_isSpecified (spec))
7093 if (uentry_hasName (spec))
7095 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7096 uentry_whereSpecified (spec));
7100 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
7105 /* nothing to show */
7111 uentry_showWhereAny (uentry spec)
7113 if (uentry_isDeclared (spec))
7115 if (uentry_hasName (spec))
7117 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7118 uentry_whereDeclared (spec));
7122 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
7125 else if (uentry_isSpecified (spec))
7127 if (uentry_hasName (spec))
7129 llgenindentmsg (message ("Specification of %q",
7130 uentry_getName (spec)),
7131 uentry_whereSpecified (spec));
7135 llgenindentmsg (cstring_makeLiteral ("Specification"),
7136 uentry_whereSpecified (spec));
7139 else if (fileloc_isDefined (uentry_whereDefined (spec)))
7141 if (uentry_hasName (spec))
7143 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
7144 uentry_whereDefined (spec));
7148 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
7153 /* nothing to show */
7158 uentry_showWhereDefined (uentry spec)
7160 if (uentry_isCodeDefined (spec))
7162 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
7163 uentry_whereDefined (spec));
7168 uentry_showWhereLastPlain (uentry spec)
7170 if (uentry_isDeclared (spec))
7172 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
7173 uentry_whereDeclared (spec));
7175 else if (uentry_isSpecified (spec))
7177 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7178 uentry_whereSpecified (spec));
7186 uentry_showWhereLastVal (uentry spec, cstring val)
7188 if (uentry_isDeclared (spec))
7190 llgenindentmsg (message ("Previous declaration of %q: %s",
7191 uentry_getName (spec), val),
7192 uentry_whereDeclared (spec));
7194 else if (uentry_isSpecified (spec))
7196 llgenindentmsg (message ("Specification of %q: %s",
7197 uentry_getName (spec), val),
7198 uentry_whereSpecified (spec));
7206 uentry_showWhereSpecified (uentry spec)
7208 if (uentry_isSpecified (spec))
7210 if (uentry_hasName (spec))
7212 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7213 uentry_whereSpecified (spec));
7217 llgenindentmsg (cstring_makeLiteral ("Specification"),
7218 uentry_whereSpecified (spec));
7221 else if (uentry_isDeclared (spec))
7223 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7224 uentry_whereDeclared (spec));
7228 /* nothing to show */
7233 uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
7235 if (uentry_isSpecified (spec))
7237 if (uentry_hasName (spec))
7239 llgenindentmsg (message ("Specification of %q: %q",
7240 uentry_getName (spec), s),
7241 uentry_whereSpecified (spec));
7245 llgenindentmsg (message ("Specification: %q", s),
7246 uentry_whereSpecified (spec));
7249 else if (uentry_isDeclared (spec))
7251 llgenindentmsg (message ("Declaration of %q: %q",
7252 uentry_getName (spec), s),
7253 uentry_whereDeclared (spec));
7257 llgenindentmsg (message ("Previous: %q", s),
7258 uentry_whereLast (spec));
7267 checkStructConformance (uentry old, uentry unew)
7270 uentryList fold, fnew;
7273 ** requires: types of old and new are structs or unions
7276 llassert (uentry_isValid (old));
7277 llassert (uentry_isValid (unew));
7279 oldr = ctype_realType (old->utype);
7280 fold = ctype_getFields (oldr);
7282 newr = ctype_realType (unew->utype);
7283 fnew = ctype_getFields (newr);
7285 if (!uentryList_matchFields (fold, fnew))
7287 if (fileloc_equal (uentry_whereLast (old),
7288 uentry_whereLast (unew)))
7296 message ("%q %q %rdeclared with fields { %q }, %s "
7297 "with fields { %q }",
7298 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
7299 uentry_getName (old),
7300 uentry_isDeclared (old),
7301 uentryList_unparseAbbrev (fnew),
7302 uentry_specOrDefName (old),
7303 uentryList_unparseAbbrev (fold)),
7304 uentry_whereDeclared (unew)))
7306 uentry_showWhereLastPlain (old);
7307 uentryList_showFieldDifference (fold, fnew);
7311 old->utype = unew->utype;
7316 checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7319 ** requires old and new are enums
7322 ctype rold = ctype_realType (old->utype);
7323 ctype rnew = ctype_realType (unew->utype);
7324 enumNameList eold = ctype_elist (rold);
7325 enumNameList enew = ctype_elist (rnew);
7327 if (!enumNameList_match (eold, enew))
7331 message ("Enum %q declared with members { %q } but "
7332 "%s with members { %q }",
7333 uentry_getName (old),
7334 enumNameList_unparse (enew),
7335 uentry_specOrDefName (old),
7336 enumNameList_unparse (eold)),
7337 uentry_whereDeclared (unew)))
7339 uentry_showWhereSpecified (old);
7340 old->utype = unew->utype;
7346 ** either oldCurrent or newCurrent may be undefined!
7350 paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
7351 uentry unew, uentry newCurrent, ctype newType,
7354 bool hasError = FALSE;
7356 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
7358 if (uentry_hasName (newCurrent))
7360 hasError = optgenerror
7362 message ("Parameter %d, %q, of function %q has inconsistent type: "
7363 "declared %t, %s %t",
7364 paramno + 1, uentry_getName (newCurrent),
7365 uentry_getName (unew),
7366 newType, uentry_specOrDefName (old), oldType),
7367 uentry_whereDeclared (newCurrent));
7371 hasError = optgenerror
7373 message ("Parameter %d of function %q has inconsistent type: "
7374 "declared %t, %s %t",
7375 paramno + 1, uentry_getName (unew),
7376 newType, uentry_specOrDefName (old), oldType),
7377 uentry_whereDeclared (newCurrent));
7379 DPRINTF (("type: %s / %s",
7380 ctype_unparse (newType),
7381 ctype_unparse (ctype_realType (newType))));
7386 if (uentry_isDeclared (unew))
7388 hasError = optgenerror
7390 message ("Parameter %d of function %s has inconsistent type: "
7391 "declared %t, %s %t",
7392 paramno + 1, unew->uname,
7393 newType, uentry_specOrDefName (old), oldType),
7394 uentry_whereDeclared (unew));
7398 hasError = optgenerror
7400 message ("Parameter %d of function %s has inconsistent type: "
7401 "declared %t, %s %t",
7402 paramno + 1, unew->uname,
7403 newType, uentry_specOrDefName (old), oldType),
7404 uentry_whereDeclared (unew));
7410 DPRINTF (("Here: %s / %s",
7411 uentry_unparseFull (oldCurrent),
7412 uentry_unparseFull (newCurrent)));
7414 if (!uentry_isUndefined (oldCurrent))
7416 if (!uentry_isUndefined (newCurrent)
7417 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
7419 uentry_showWhereLast (oldCurrent);
7423 uentry_showWhereLastPlain (old);
7426 uentry_setType (oldCurrent, newType);
7430 uentry_showWhereLastPlain (old);
7436 nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7440 message ("Function %s %rdeclared with %d arg%&, %s with %d",
7442 uentry_isDeclared (old),
7443 uentryList_size (uentry_getParams (unew)),
7444 uentry_specOrDefName (old),
7445 uentryList_size (uentry_getParams (old))),
7446 uentry_whereDeclared (unew)))
7448 uentry_showWhereLastPlain (old);
7453 returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7457 message ("Function %s inconsistently %rdeclared to return %t",
7459 uentry_isDeclared (old),
7460 ctype_getReturnType (unew->utype)),
7461 uentry_whereDeclared (unew)))
7463 uentry_showWhereLastVal (old, ctype_unparse (ctype_getReturnType (old->utype)));
7467 static cstring paramStorageName (uentry ue)
7469 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
7472 static cstring fcnErrName (uentry ue)
7474 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
7477 extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
7479 if (uentry_isVar (ue))
7481 return (checkedName (ue->info->var->checked));
7485 return (cstring_makeLiteralTemp ("<checked invalid>"));
7489 static cstring checkedName (chkind checked)
7493 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
7494 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
7495 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
7496 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
7497 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
7503 void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
7508 if (uentry_isVar (unew))
7510 llassert (uentry_isVar (old));
7512 oldState = old->info->var->nullstate;
7513 newState = unew->info->var->nullstate;
7517 oldState = sRef_getNullState (old->sref);
7518 newState = sRef_getNullState (unew->sref);
7521 if (oldState == NS_ABSNULL)
7523 if (uentry_isVar (old))
7525 old->info->var->nullstate = newState;
7528 sRef_mergeNullState (old->sref, newState);
7530 else if (newState == NS_UNKNOWN)
7532 if (completeConform && newState != oldState
7533 && uentry_isReallySpecified (old))
7537 message ("%s %q specified as %s, but declared without %s qualifier",
7538 ekind_capName (unew->ukind),
7539 uentry_getName (unew),
7540 nstate_unparse (oldState),
7541 nstate_unparse (oldState)),
7542 uentry_whereDeclared (unew)))
7544 uentry_showWhereSpecified (old);
7548 if (uentry_isVar (unew))
7550 unew->info->var->nullstate = oldState;
7553 sRef_mergeNullState (unew->sref, oldState);
7555 else if (newState == NS_POSNULL)
7557 if (oldState == NS_MNOTNULL
7558 && (ctype_isUA (unew->utype)
7559 || (uentry_isFunction (unew)
7560 && ctype_isUA (ctype_getReturnType (unew->utype)))))
7562 if (uentry_isVar (unew))
7564 unew->info->var->nullstate = oldState;
7567 sRef_mergeNullState (unew->sref, oldState);
7571 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
7572 || oldState == NS_UNKNOWN)
7579 ("%s %q inconsistently %rdeclared %s possibly null storage, "
7581 uentry_ekindName (unew),
7582 uentry_getName (unew),
7583 uentry_isDeclared (old),
7585 uentry_specOrDefName (old),
7586 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
7587 uentry_whereDeclared (unew)))
7589 uentry_showWhereSpecified (old);
7594 if (uentry_isVar (old))
7596 old->info->var->nullstate = newState;
7599 sRef_mergeNullState (old->sref, newState);
7602 else if (newState == NS_MNOTNULL)
7604 if (oldState != NS_MNOTNULL)
7610 message ("%s %q inconsistently %rdeclared %s notnull storage, "
7611 "%s without notnull qualifier",
7612 uentry_ekindName (unew),
7613 uentry_getName (unew),
7614 uentry_isDeclared (old),
7616 uentry_specOrDefName (old)),
7617 uentry_whereDeclared (unew)))
7619 uentry_showWhereSpecified (old);
7623 if (uentry_isVar (old))
7625 old->info->var->nullstate = newState;
7628 sRef_mergeNullState (old->sref, newState);
7633 if (uentry_isVar (unew))
7635 unew->info->var->nullstate = oldState;
7638 sRef_mergeNullState (unew->sref, oldState);
7643 void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7644 bool mustConform, bool completeConform)
7650 if (uentry_isVar (old) && uentry_isVar (unew))
7652 oldState = old->info->var->defstate;
7653 newState = unew->info->var->defstate;
7658 oldState = sRef_getDefState (old->sref);
7659 newState = sRef_getDefState (unew->sref);
7662 if (newState != oldState
7663 && newState != SS_UNKNOWN
7664 && newState != SS_DEFINED)
7670 message ("%s %q inconsistently %rdeclared %s %s %s, "
7672 uentry_ekindName (unew),
7673 uentry_getName (unew),
7674 uentry_isDeclared (old),
7676 sstate_unparse (newState),
7677 paramStorageName (unew),
7678 uentry_specOrDefName (old),
7680 sstate_unparse (oldState),
7681 paramStorageName (unew)),
7682 uentry_whereDeclared (unew)))
7684 uentry_showWhereSpecified (old);
7688 if (vars) old->info->var->defstate = newState;
7689 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
7694 && (newState != oldState) && (oldState != SS_DEFINED)
7695 && uentry_isReallySpecified (old))
7699 message ("%s %q specified as %s, but declared without %s qualifier",
7700 ekind_capName (unew->ukind),
7701 uentry_getName (unew),
7702 sstate_unparse (oldState),
7703 sstate_unparse (oldState)),
7704 uentry_whereDeclared (unew)))
7706 uentry_showWhereSpecified (old);
7710 if (vars) unew->info->var->defstate = oldState;
7711 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
7716 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7717 bool mustConform, bool completeConform)
7722 oldKind = sRef_getAliasKind (old->sref);
7723 newKind = sRef_getAliasKind (unew->sref);
7725 if (alkind_isImplicit (newKind)
7726 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
7728 if (completeConform && !alkind_equal (newKind, oldKind)
7729 && uentry_isReallySpecified (old))
7733 message ("%s %q specified as %s, but declared without "
7734 "explicit alias qualifier",
7735 ekind_capName (unew->ukind),
7736 uentry_getName (unew),
7737 alkind_unparse (oldKind)),
7738 uentry_whereDeclared (unew)))
7740 uentry_showWhereSpecified (old);
7745 ** This really shouldn't be necessary, but it is!
7746 ** Function params (?) use new here.
7749 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7753 if (alkind_isKnown (newKind))
7755 if (!alkind_equal (oldKind, newKind))
7757 if (alkind_isKnown (oldKind))
7762 message ("%s %q inconsistently %rdeclared %s %s storage, "
7764 uentry_ekindName (unew),
7765 uentry_getName (unew),
7766 uentry_isDeclared (old),
7768 alkind_unparse (newKind),
7769 uentry_specOrDefName (old),
7770 alkind_unparse (oldKind)),
7771 uentry_whereDeclared (unew)))
7773 uentry_showWhereSpecified (old);
7775 DPRINTF (("Old: %s", sRef_unparseFull (old->sref)));
7776 DPRINTF (("New: %s", sRef_unparseFull (unew->sref)));
7777 sRef_setAliasKind (old->sref, AK_ERROR,
7778 uentry_whereDeclared (unew));
7782 sRef_setAliasKind (old->sref, newKind,
7783 uentry_whereDeclared (unew));
7788 if (!(alkind_isImplicit (newKind)))
7791 !uentry_isFunction (unew) &&
7794 message ("%s %q inconsistently %rdeclared %s %s storage, "
7795 "implicitly %s as temp storage",
7796 uentry_ekindName (unew),
7797 uentry_getName (unew),
7798 uentry_isDeclared (old),
7800 alkind_unparse (newKind),
7801 uentry_specOrDefName (old)),
7802 uentry_whereDeclared (unew)))
7804 uentry_showWhereSpecified (old);
7808 sRef_setAliasKind (old->sref, newKind,
7809 uentry_whereDeclared (unew));
7811 else /* newKind is temp or refcounted */
7818 else /* newKind unknown */
7825 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7826 bool mustConform, bool completeConform)
7831 oldKind = sRef_getExKind (old->sref);
7832 newKind = sRef_getExKind (unew->sref);
7834 if (exkind_isKnown (newKind))
7836 if (oldKind != newKind)
7838 if (exkind_isKnown (oldKind))
7843 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7844 uentry_ekindName (unew),
7845 uentry_getName (unew),
7846 uentry_isDeclared (old),
7848 exkind_unparse (newKind),
7849 uentry_specOrDefName (old),
7850 exkind_unparse (oldKind)),
7851 uentry_whereDeclared (unew)))
7853 uentry_showWhereSpecified (old);
7856 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7863 message ("%s %q inconsistently %rdeclared %s %s, "
7864 "implicitly %s without exposure qualifier",
7865 uentry_ekindName (unew),
7866 uentry_getName (unew),
7867 uentry_isDeclared (old),
7869 exkind_unparse (newKind),
7870 uentry_specOrDefName (old)),
7871 uentry_whereDeclared (unew)))
7873 uentry_showWhereSpecified (old);
7876 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7882 if (completeConform && exkind_isKnown (oldKind)
7883 && uentry_isReallySpecified (old))
7887 message ("%s %q specified as %s, but declared without "
7888 "exposure qualifier",
7889 ekind_capName (unew->ukind),
7890 uentry_getName (unew),
7891 exkind_unparse (oldKind)),
7892 uentry_whereDeclared (unew)))
7894 uentry_showWhereSpecified (old);
7898 /* yes, this is necessary! (if its a param) */
7899 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7904 checkMetaState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7905 bool mustConform, /*@unused@*/ bool completeConform)
7907 valueTable newvals = sRef_getValueTable (unew->sref);
7909 if (valueTable_isDefined (newvals))
7911 DPRINTF (("Check meta state: %s -> %s",
7912 uentry_unparseFull (old),
7913 uentry_unparseFull (unew)));
7915 DPRINTF (("Check meta state refs: %s -> %s",
7916 sRef_unparseFull (old->sref),
7917 sRef_unparseFull (unew->sref)));
7919 DPRINTF (("Value table: %s", valueTable_unparse (newvals)));
7922 ** Copy the new values into the old ref
7925 valueTable_elements (newvals, key, newval)
7927 metaStateInfo msinfo = context_lookupMetaStateInfo (key);
7928 stateValue oldval = sRef_getMetaStateValue (old->sref, key);
7930 llassert (metaStateInfo_isDefined (msinfo));
7932 if (stateValue_isUndefined (oldval))
7934 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7938 if (stateValue_isError (oldval))
7940 if (!stateValue_isError (newval))
7942 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7946 ; /* No change necessary. */
7951 if (stateValue_getValue (newval) != stateValue_getValue (oldval))
7953 if (fileloc_isXHFile (uentry_whereDeclared (unew)))
7959 if (!stateValue_isError (newval)
7960 && !stateValue_isImplicit (newval))
7962 if (uentry_hasName (unew)
7963 || !sRef_isParam (uentry_getSref (unew)))
7968 message ("%s %q inconsistently %rdeclared %s %q, %s as %q",
7969 uentry_ekindName (unew),
7970 uentry_getName (unew),
7971 uentry_isDeclared (old),
7973 stateValue_unparseValue (newval, msinfo),
7974 uentry_specOrDefName (old),
7975 stateValue_unparseValue (oldval, msinfo)),
7976 uentry_whereDeclared (unew)))
7978 uentry_showWhereSpecified (old);
7986 message ("%s %d inconsistently %rdeclared %s %q, %s as %q",
7987 uentry_ekindName (unew),
7988 sRef_getParam (uentry_getSref (unew)),
7989 uentry_isDeclared (old),
7991 stateValue_unparseValue (newval, msinfo),
7992 uentry_specOrDefName (old),
7993 stateValue_unparseValue (oldval, msinfo)),
7994 uentry_whereDeclared (unew)))
7996 uentry_showWhereSpecified (old);
8002 DPRINTF (("Updating!"));
8003 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
8007 DPRINTF (("Values match"));
8011 } end_valueTable_elements ;
8016 uentry_checkStateConformance (/*@notnull@*/ uentry old,
8017 /*@notnull@*/ uentry unew,
8018 bool mustConform, bool completeConform)
8020 checkDefState (old, unew, mustConform, completeConform);
8021 checkNullState (old, unew, mustConform, completeConform);
8022 checkAliasState (old, unew, mustConform, completeConform);
8023 checkExpState (old, unew, mustConform, completeConform);
8024 checkMetaState (old, unew, mustConform, completeConform);
8026 sRef_storeState (old->sref);
8027 sRef_storeState (unew->sref);
8031 checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
8033 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
8038 llassert (uentry_isVar (old));
8039 llassert (uentry_isVar (unew));
8041 if (cstring_isEmpty (old->uname))
8043 cstring_free (old->uname);
8044 old->uname = cstring_copy (unew->uname);
8047 if (unew->info->var->kind == VKRETPARAM
8048 || unew->info->var->kind == VKSEFRETPARAM)
8050 if (old->info->var->kind != VKRETPARAM
8051 && old->info->var->kind != VKSEFRETPARAM)
8055 message ("Parameter %q inconsistently %rdeclared as "
8056 "returned parameter",
8057 uentry_getName (unew),
8058 uentry_isDeclared (old)),
8059 uentry_whereDeclared (unew)))
8061 uentry_showWhereSpecified (old);
8062 old->info->var->kind = unew->info->var->kind;
8068 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
8070 if (old->info->var->kind != VKSEFPARAM
8071 && old->info->var->kind != VKSEFRETPARAM)
8075 message ("Parameter %qinconsistently %rdeclared as "
8077 uentry_getOptName (unew),
8078 uentry_isDeclared (old)),
8079 uentry_whereDeclared (unew)))
8081 uentry_showWhereSpecified (old);
8082 old->info->var->kind = unew->info->var->kind;
8087 if (old->info->var->kind == VKSPEC)
8089 old->info->var->kind = unew->info->var->kind;
8093 unew->info->var->kind = old->info->var->kind;
8096 if (unew->info->var->checked != CH_UNKNOWN
8097 && unew->info->var->checked != old->info->var->checked)
8099 if (old->info->var->checked == CH_UNKNOWN
8100 && !fileloc_isUser (uentry_whereLast (old)))
8108 message ("Variable %q inconsistently %rdeclared as "
8109 "%s parameter (was %s)",
8110 uentry_getName (unew),
8111 uentry_isDeclared (old),
8112 checkedName (unew->info->var->checked),
8113 checkedName (old->info->var->checked)),
8114 uentry_whereDeclared (unew)))
8116 uentry_showWhereSpecified (old);
8120 old->info->var->checked = unew->info->var->checked;
8125 && (old->info->var->checked != CH_UNKNOWN)
8126 && uentry_isReallySpecified (old))
8130 message ("%s %q specified as %s, but declared without %s qualifier",
8131 ekind_capName (unew->ukind),
8132 uentry_getName (unew),
8133 checkedName (old->info->var->checked),
8134 checkedName (old->info->var->checked)),
8135 uentry_whereDeclared (unew)))
8137 uentry_showWhereSpecified (old);
8141 unew->info->var->checked = old->info->var->checked;
8144 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8147 void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
8149 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
8154 llassert (uentry_isVar (u1));
8155 llassert (uentry_isVar (u2));
8157 if (u1->info->var->kind != u2->info->var->kind) {
8158 if (u1->info->var->kind == VKSEFRETPARAM) {
8159 if (u2->info->var->kind == VKRETPARAM) {
8162 message ("Function types are inconsistent. Parameter %d is "
8163 "sef parameter, but non-sef parameter in "
8164 "assigned function: %s",
8165 paramno, exprNode_unparse (e)),
8167 } else if (u2->info->var->kind == VKSEFPARAM) {
8170 message ("Function types are inconsistent. Parameter %d is "
8171 "returns parameter, but non-returns parameter in "
8172 "assigned function: %s",
8173 paramno, exprNode_unparse (e)),
8178 message ("Function types are inconsistent. Parameter %d is "
8179 "sef returns parameter, but non-sef returns parameter in "
8180 "assigned function: %s",
8181 paramno, exprNode_unparse (e)),
8184 } else if (u1->info->var->kind == VKRETPARAM) {
8187 message ("Function types are inconsistent. Parameter %d is "
8188 "returns parameter, but non-returns parameter in "
8189 "assigned function: %s",
8190 paramno, exprNode_unparse (e)),
8192 } else if (u1->info->var->kind == VKSEFPARAM) {
8195 message ("Function types are inconsistent. Parameter %d is "
8196 "sef parameter, but non-sef parameter in "
8197 "assigned function: %s",
8198 paramno, exprNode_unparse (e)),
8201 if (u2->info->var->kind == VKSEFRETPARAM) {
8204 message ("Function types are inconsistent. Parameter %d is "
8205 "normal parameter, but sef returns parameter in "
8206 "assigned function: %s",
8207 paramno, exprNode_unparse (e)),
8209 } else if (u2->info->var->kind == VKSEFPARAM) {
8212 message ("Function types are inconsistent. Parameter %d is "
8213 "normal parameter, but sef parameter in "
8214 "assigned function: %s",
8215 paramno, exprNode_unparse (e)),
8217 } else if (u2->info->var->kind == VKRETPARAM) {
8220 message ("Function types are inconsistent. Parameter %d is "
8221 "normal parameter, but returns parameter in "
8222 "assigned function: %s",
8223 paramno, exprNode_unparse (e)),
8231 if (u1->info->var->defstate != u2->info->var->defstate)
8235 message ("Function types are inconsistent. Parameter %d is "
8236 "%s, but %s in assigned function: %s",
8238 sstate_unparse (u1->info->var->defstate),
8239 sstate_unparse (u2->info->var->defstate),
8240 exprNode_unparse (e)),
8244 if (u1->info->var->nullstate != u2->info->var->nullstate)
8248 message ("Function types are inconsistent. Parameter %d is "
8249 "%s, but %s in assigned function: %s",
8251 nstate_unparse (u1->info->var->nullstate),
8252 nstate_unparse (u2->info->var->nullstate),
8253 exprNode_unparse (e)),
8257 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
8261 message ("Function types are inconsistent. Parameter %d is "
8262 "%s, but %s in assigned function: %s",
8264 alkind_unparse (sRef_getAliasKind (u1->sref)),
8265 alkind_unparse (sRef_getAliasKind (u2->sref)),
8266 exprNode_unparse (e)),
8270 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
8274 message ("Function types are inconsistent. Parameter %d is "
8275 "%s, but %s in assigned function: %s",
8277 exkind_unparse (sRef_getExKind (u1->sref)),
8278 exkind_unparse (sRef_getExKind (u2->sref)),
8279 exprNode_unparse (e)),
8285 checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8286 /*@notnull@*/ uentry unew,
8287 bool mustConform, /*@unused@*/ bool completeConform)
8289 uentryList oldParams = uentry_getParams (old);
8290 uentryList newParams = uentry_getParams (unew);
8291 ctype newType = unew->utype;
8292 ctype oldType = ctype_realType (old->utype);
8293 ctype oldRetType = ctype_unknown;
8294 ctype newRetType = ctype_unknown;
8296 DPRINTF (("Function conform: %s ==> %s",
8297 uentry_unparseFull (old),
8298 uentry_unparseFull (unew)));
8300 if (uentry_isForward (old))
8302 mustConform = FALSE;
8303 uentry_updateInto (old, unew);
8308 ** check return values
8311 if (ctype_isKnown (oldType))
8313 llassert (ctype_isFunction (oldType));
8314 oldRetType = ctype_getReturnType (oldType);
8317 if (ctype_isKnown (newType))
8319 llassert (ctype_isFunction (newType));
8320 newRetType = ctype_getReturnType (newType);
8323 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
8324 && !ctype_matchDef (newRetType, oldRetType))
8326 if (mustConform) returnValueError (old, unew);
8330 if (ctype_isConj (newRetType))
8332 if (ctype_isConj (oldRetType))
8334 if (!ctype_sameAltTypes (newRetType, oldRetType))
8338 message ("Function %q inconsistently %rdeclared to "
8339 "return alternate types %s "
8340 "(types match, but alternates are not identical, "
8341 "so checking may not be correct)",
8342 uentry_getName (unew),
8343 uentry_isDeclared (old),
8344 ctype_unparse (newRetType)),
8345 uentry_whereDeclared (unew)))
8347 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
8353 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
8358 DPRINTF (("Before state: %s",
8359 uentry_unparseFull (old)));
8360 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8361 DPRINTF (("After state: %s",
8362 uentry_unparseFull (old)));
8364 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
8366 if (exitkind_isKnown (unew->info->fcn->exitCode))
8370 message ("Function %q inconsistently %rdeclared using %s",
8371 uentry_getName (unew),
8372 uentry_isDeclared (old),
8373 exitkind_unparse (unew->info->fcn->exitCode)),
8374 uentry_whereDeclared (unew)))
8376 uentry_showWhereSpecified (old);
8381 unew->info->fcn->exitCode = old->info->fcn->exitCode;
8385 if (!qual_isUnknown (unew->info->fcn->nullPred))
8387 if (!qual_match (old->info->fcn->nullPred, unew->info->fcn->nullPred))
8391 message ("Function %q inconsistently %rdeclared using %s",
8392 uentry_getName (unew),
8393 uentry_isDeclared (old),
8394 qual_unparse (unew->info->fcn->nullPred)),
8395 uentry_whereDeclared (unew)))
8397 uentry_showWhereSpecified (old);
8403 unew->info->fcn->nullPred = old->info->fcn->nullPred;
8406 if (unew->info->fcn->specialCode != SPC_NONE)
8408 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
8412 message ("Function %q inconsistently %rdeclared using %s",
8413 uentry_getName (unew),
8414 uentry_isDeclared (old),
8415 specCode_unparse (unew->info->fcn->specialCode)),
8416 uentry_whereDeclared (unew)))
8418 uentry_showWhereSpecified (old);
8424 unew->info->fcn->specialCode = old->info->fcn->specialCode;
8431 if (!uentryList_sameObject (oldParams, newParams)
8432 && (!uentryList_isMissingParams (oldParams)))
8434 if (!uentryList_isMissingParams (newParams))
8437 int nparams = uentryList_size (oldParams);
8438 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
8440 if (nparams != uentryList_size (newParams))
8442 nargsError (old, unew);
8445 if (uentryList_size (newParams) < nparams)
8447 nparams = uentryList_size (newParams);
8450 while (paramno < nparams)
8452 uentry oldCurrent = uentryList_getN (oldParams, paramno);
8453 uentry newCurrent = uentryList_getN (newParams, paramno);
8454 ctype oldCurrentType = uentry_getType (oldCurrent);
8455 ctype newCurrentType = uentry_getType (newCurrent);
8457 llassert (uentry_isValid (oldCurrent)
8458 && uentry_isValid (newCurrent));
8460 if (!uentry_isElipsisMarker (oldCurrent)
8461 && !uentry_isElipsisMarker (newCurrent))
8463 checkVarConformance (oldCurrent, newCurrent,
8464 mustConform, completeConform);
8469 if (uentry_hasName (oldCurrent)
8470 && uentry_hasName (newCurrent))
8472 cstring oldname = uentry_getName (oldCurrent);
8473 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
8475 cstring nname = uentry_getName (newCurrent);
8478 if (cstring_isDefined (pfx)
8479 && cstring_equalPrefix (oldname, pfx))
8481 oname = cstring_suffix (oldname, cstring_length (pfx));
8486 /*@-branchstate@*/ } /*@=branchstate@*/
8488 if (cstring_isDefined (pfx)
8489 && cstring_equalPrefix (nname, pfx))
8491 nnamefix = cstring_suffix (nname, cstring_length (pfx));
8496 /*@-branchstate@*/ } /*@=branchstate@*/
8498 if (!cstring_equal (oname, nnamefix))
8501 (FLG_DECLPARAMMATCH,
8502 message ("Definition parameter name %s does not match "
8503 "name of corresponding parameter in "
8506 uentry_whereLast (newCurrent)))
8508 uentry_showWhereLastPlain (oldCurrent);
8512 cstring_free (oldname);
8513 cstring_free (nname);
8517 if (!ctype_match (oldCurrentType, newCurrentType))
8519 paramTypeError (old, oldCurrent, oldCurrentType,
8520 unew, newCurrent, newCurrentType, paramno);
8524 if (ctype_isMissingParamsMarker (newCurrentType)
8525 || ctype_isElips (newCurrentType)
8526 || ctype_isMissingParamsMarker (oldCurrentType)
8527 || ctype_isElips (oldCurrentType))
8533 if (ctype_isConj (newCurrentType))
8535 if (ctype_isConj (oldCurrentType))
8537 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
8541 message ("Parameter %q inconsistently %rdeclared with "
8542 "alternate types %s "
8543 "(types match, but alternates are not identical, "
8544 "so checking may not be correct)",
8545 uentry_getName (newCurrent),
8546 uentry_isDeclared (oldCurrent),
8547 ctype_unparse (newCurrentType)),
8548 uentry_whereDeclared (unew)))
8550 uentry_showWhereLastVal (oldCurrent,
8551 ctype_unparse (oldCurrentType));
8559 message ("Parameter %q inconsistently %rdeclared with "
8560 "alternate types %s",
8561 uentry_getName (newCurrent),
8562 uentry_isDeclared (oldCurrent),
8563 ctype_unparse (newCurrentType)),
8564 uentry_whereDeclared (unew)))
8566 uentry_showWhereLastVal (oldCurrent,
8567 ctype_unparse (oldCurrentType));
8574 if (ctype_isConj (oldCurrentType))
8576 uentry_setType (newCurrent, oldCurrentType);
8584 ** Forgot this! detected by splint:
8585 ** uentry.c:1257,15: Suspected infinite loop
8591 if (!uentryList_isMissingParams (newParams))
8593 if (ctype_isConj (oldRetType))
8595 old->utype = ctype_makeFunction (oldRetType,
8596 uentryList_copy (newParams));
8600 old->utype = unew->utype;
8604 checkGlobalsConformance (old, unew, mustConform, completeConform);
8605 checkModifiesConformance (old, unew, mustConform, completeConform);
8607 DPRINTF (("Before list: %s",
8608 uentry_unparseFull (old)));
8610 if (stateClauseList_isDefined (unew->info->fcn->specclauses))
8612 if (!stateClauseList_isDefined (old->info->fcn->specclauses))
8617 message ("Function %q redeclared using special clauses (can only "
8618 "be used in first declaration)",
8619 uentry_getName (unew)),
8620 uentry_whereDeclared (unew)))
8622 uentry_showWhereLast (old);
8626 /*@i23 need checking @*/
8628 old->info->fcn->specclauses = unew->info->fcn->specclauses;
8632 /*@i43 should be able to append? @*/
8634 stateClauseList_checkEqual (old, unew);
8635 stateClauseList_free (unew->info->fcn->specclauses);
8636 unew->info->fcn->specclauses = stateClauseList_undefined;
8640 /*@=branchstate@*/ /*@i23 shouldn't need this@*/
8642 if (fileloc_isUndefined (old->whereDeclared))
8644 old->whereDeclared = fileloc_copy (unew->whereDeclared);
8646 else if (fileloc_isUndefined (unew->whereDeclared))
8648 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8657 uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
8661 llassert (uentry_isValid (ue));
8662 llassert (uentry_isEitherConstant (ue));
8664 DPRINTF (("Constant value: %s / %s", uentry_unparse (ue), multiVal_unparse (m)));
8665 uval = uentry_getConstantValue (ue);
8667 if (multiVal_isDefined (uval))
8669 if (multiVal_isDefined (m))
8671 if (!multiVal_equiv (uval, m))
8675 message ("%s %q defined with inconsistent value: %q",
8676 ekind_capName (ue->ukind),
8677 uentry_getName (ue),
8678 multiVal_unparse (m)),
8681 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
8689 uentry_setConstantValue (ue, m);
8694 bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
8697 bool typeError = FALSE;
8699 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
8701 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
8705 DPRINTF (("Check struct conformance: %s / %s",
8706 uentry_unparseFull (old),
8707 uentry_unparseFull (unew)));
8708 checkStructConformance (old, unew);
8713 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8715 llbug (message ("struct tags: bad types: %t / %t",
8716 old->utype, unew->utype));
8720 else if (uentry_isEnumTag (old))
8722 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
8724 if (mustConform) checkEnumConformance (old, unew);
8728 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8730 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
8731 ctype_unparse (unew->utype)));
8735 else if (!ctype_match (old->utype, unew->utype))
8737 DPRINTF (("Type mismatch: %s / %s",
8738 ctype_unparse (old->utype),
8739 ctype_unparse (unew->utype)));
8741 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
8743 ctype realt = ctype_realType (unew->utype);
8745 if (ctype_isRealInt (realt) || ctype_isChar (realt))
8747 unew->utype = ctype_bool;
8753 typeError = optgenerror
8755 message ("%q defined as %s", uentry_getName (old),
8756 ctype_unparse (realt)),
8757 uentry_whereDeclared (unew));
8765 ctype oldr = ctype_realType (old->utype);
8766 ctype newr = ctype_realType (unew->utype);
8768 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
8770 checkStructConformance (old, unew);
8772 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
8774 checkStructConformance (old, unew);
8776 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
8778 checkEnumConformance (old, unew);
8780 else if (uentry_isConstant (old)
8781 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
8783 /* okay...for now! (should check the type is reset later... */
8787 DPRINTF (("YABA!"));
8790 message ("%s %q %rdeclared with inconsistent type: %t",
8791 ekind_capName (unew->ukind),
8792 uentry_getName (unew),
8793 uentry_isDeclared (old),
8795 uentry_whereDeclared (unew)))
8797 uentry_showWhereLast (old);
8813 uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
8814 /*@notnull@*/ uentry unew,
8815 bool mustConform, bool completeConform)
8817 if (ctype_isDefined (unew->info->datatype->type))
8820 ** bool is hard coded here, since it is built into LCL.
8821 ** For now, we're stuck with LCL's types.
8824 if (ctype_isDirectBool (old->utype) &&
8825 cstring_equalLit (unew->uname, "bool"))
8827 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
8828 evs 2000-07-25: removed
8830 unew->utype = ctype_bool;
8833 if (ctype_isUnknown (old->info->datatype->type))
8835 old->info->datatype->type = unew->info->datatype->type;
8839 DPRINTF (("Old: %s / New: %s",
8840 uentry_unparseFull (old),
8841 uentry_unparseFull (unew)));
8842 DPRINTF (("Types: %s / %s",
8843 ctype_unparse (old->info->datatype->type),
8844 ctype_unparse (unew->info->datatype->type)));
8846 if (ctype_matchDef (old->info->datatype->type,
8847 unew->info->datatype->type))
8856 ("Type %q %s with inconsistent type: %t",
8857 uentry_getName (unew),
8858 uentry_reDefDecl (old, unew),
8859 unew->info->datatype->type),
8860 uentry_whereDeclared (unew)))
8862 uentry_showWhereLastExtra
8863 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
8866 old->info->datatype->type = unew->info->datatype->type;
8871 if (unew->info->datatype->abs != MAYBE)
8873 if (ynm_isOff (old->info->datatype->abs)
8874 && ynm_isOn (unew->info->datatype->abs))
8876 if (!ctype_isDirectBool (old->utype))
8881 ("Datatype %q inconsistently %rdeclared as abstract type",
8882 uentry_getName (unew),
8883 uentry_isDeclared (old)),
8884 uentry_whereDeclared (unew)))
8886 uentry_showWhereLastPlain (old);
8890 else if (ynm_isOn (old->info->datatype->abs)
8891 && ynm_isOff (unew->info->datatype->abs))
8893 if (!ctype_isDirectBool (old->utype))
8898 ("Datatype %q inconsistently %rdeclared as concrete type",
8899 uentry_getName (unew),
8900 uentry_isDeclared (old)),
8901 uentry_whereDeclared (unew)))
8903 uentry_showWhereLastPlain (old);
8914 if (ynm_isOn (old->info->datatype->abs))
8916 old->sref = unew->sref;
8917 unew->info->datatype->mut = old->info->datatype->mut;
8920 && uentry_isReallySpecified (old))
8925 ("Datatype %q specified as abstract, "
8926 "but abstract annotation not used in declaration",
8927 uentry_getName (unew)),
8928 uentry_whereDeclared (unew)))
8930 uentry_showWhereLastPlain (old);
8936 unew->info->datatype->abs = old->info->datatype->abs;
8938 if (ynm_isMaybe (unew->info->datatype->mut))
8940 if (completeConform && ynm_isOff (old->info->datatype->mut)
8941 && uentry_isReallySpecified (old))
8946 ("Datatype %q specified as immutable, "
8947 "but immutable annotation not used in declaration",
8948 uentry_getName (unew)),
8949 uentry_whereDeclared (unew)))
8951 uentry_showWhereLastPlain (old);
8955 unew->info->datatype->mut = old->info->datatype->mut;
8957 else if (ynm_isMaybe (old->info->datatype->mut))
8959 old->info->datatype->mut = unew->info->datatype->mut;
8963 if (ynm_isOn (old->info->datatype->abs))
8965 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
8969 message ("Datatype %q inconsistently %rdeclared as immutable",
8970 uentry_getName (unew),
8971 uentry_isDeclared (old)),
8972 uentry_whereDeclared (unew)))
8974 uentry_showWhereLastPlain (old);
8979 if (ynm_isOff (old->info->datatype->mut)
8980 && ynm_isOn (unew->info->datatype->mut))
8984 message ("Datatype %q inconsistently %rdeclared as mutable",
8985 uentry_getName (unew),
8986 uentry_isDeclared (old)),
8987 uentry_whereDeclared (unew)))
8989 uentry_showWhereLastPlain (old);
8994 old->info->datatype->mut = unew->info->datatype->mut;
8997 uentry_checkStateConformance (old, unew, mustConform, completeConform);
9001 uentry_checkConstantConformance (/*@notnull@*/ uentry old,
9002 /*@notnull@*/ uentry unew,
9004 /*@unused@*/ bool completeConform)
9006 multiVal oldval = uentry_getConstantValue (old);
9007 multiVal newval = uentry_getConstantValue (unew);
9009 if (multiVal_isDefined (oldval))
9011 if (multiVal_isDefined (newval))
9013 if (!multiVal_equiv (oldval, newval))
9018 message ("%s %q %rdeclared with inconsistent value: %q",
9019 ekind_capName (unew->ukind),
9020 uentry_getName (unew),
9021 uentry_isDeclared (old),
9022 multiVal_unparse (newval)),
9023 uentry_whereDeclared (unew)))
9025 uentry_showWhereLastExtra (old, multiVal_unparse (oldval));
9029 uentry_setConstantValue (unew, multiVal_copy (oldval));
9038 uentry_setConstantValue (old, multiVal_copy (newval));
9043 uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
9044 /*@notnull@*/ uentry unew, bool mustConform,
9045 bool completeConform)
9047 bool typeError = FALSE;
9048 bool fcnConformance = FALSE;
9050 if (!ekind_equal (unew->ukind, old->ukind))
9053 ** okay, only if one is a function and the other is
9054 ** a variable of type function.
9057 if (unew->ukind == KENUMCONST
9058 && old->ukind == KCONST)
9060 old->ukind = KENUMCONST;
9064 if (unew->ukind == KFCN
9065 && old->ukind == KCONST
9066 && ctype_isUnknown (old->utype))
9069 ** When a function is defined with an unparam macro
9072 uentry_updateInto (old, unew);
9076 if (uentry_isExpandedMacro (old)
9077 && uentry_isEitherConstant (unew))
9079 uentry_updateInto (old, unew);
9083 if (uentry_isEndIter (unew))
9085 if (ctype_isUnknown (old->utype))
9087 if (!uentry_isSpecified (old)
9088 && uentry_isCodeDefined (unew))
9090 if (!fileloc_withinLines (uentry_whereDefined (old),
9091 uentry_whereDeclared (unew), 2))
9092 { /* bogus! will give errors if there is too much whitespace */
9096 ("Iterator finalized name %q does not match name in "
9097 "previous iter declaration (should be end_%q). This iter "
9098 "is declared at %q",
9099 uentry_getName (unew),
9100 uentry_getName (old),
9101 fileloc_unparse (uentry_whereDefined (old))),
9102 uentry_whereDeclared (old));
9106 uentry_updateInto (old, unew);
9111 KindConformanceError (old, unew, mustConform);
9115 if (uentry_isFunction (unew))
9117 if (uentry_isVariable (old))
9119 if (!ctype_isUnknown (old->utype))
9121 if (ctype_isFunction (old->utype))
9123 uentry_makeVarFunction (old);
9124 checkFunctionConformance (old, unew, mustConform,
9126 fcnConformance = TRUE;
9130 KindConformanceError (old, unew, mustConform);
9135 if (uentry_isExpandedMacro (old))
9137 if (fileloc_isUndefined (unew->whereDefined))
9139 unew->whereDefined = fileloc_update (unew->whereDefined,
9143 uentry_updateInto (old, unew);
9144 old->used = unew->used = TRUE;
9149 /* undeclared identifier */
9150 old->utype = unew->utype;
9151 uentry_makeVarFunction (old);
9152 checkFunctionConformance (old, unew, FALSE, FALSE);
9153 fcnConformance = TRUE;
9159 KindConformanceError (old, unew, mustConform);
9162 else if (uentry_isFunction (old) && uentry_isVariable (unew))
9164 if (!ctype_isUnknown (unew->utype))
9166 if (ctype_isFunction (unew->utype))
9168 uentry_makeVarFunction (unew);
9169 checkFunctionConformance (old, unew, mustConform, completeConform);
9170 fcnConformance = TRUE;
9174 KindConformanceError (old, unew, mustConform);
9179 KindConformanceError (old, unew, mustConform);
9184 KindConformanceError (old, unew, mustConform);
9190 ** check parameter lists for functions
9191 ** (before type errors, to get better messages
9194 if (uentry_isFunction (old))
9196 checkFunctionConformance (old, unew, mustConform, completeConform);
9197 fcnConformance = TRUE;
9201 if (!ctype_isUndefined (old->utype))
9203 typeError = checkTypeConformance (old, unew, mustConform);
9210 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
9212 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
9215 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
9217 DPRINTF (("Check datatype: %s / %s",
9218 uentry_unparseFull (old),
9219 uentry_unparseFull (unew)));
9221 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
9224 if (uentry_isVariable (old) && uentry_isVariable (unew))
9227 !ctype_matchDef (old->utype, unew->utype))
9232 ("Variable %q %s with inconsistent type (arrays and pointers are "
9233 "not identical in variable declarations): %t",
9234 uentry_getName (unew),
9235 uentry_reDefDecl (old, unew),
9237 uentry_whereDeclared (unew)))
9239 uentry_showWhereLast (old);
9242 ** Avoid repeated errors.
9245 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
9247 old->whereDefined = fileloc_update (old->whereDefined,
9255 checkVarConformance (old, unew, mustConform, completeConform);
9260 /* old->utype = unew->utype; */
9264 if (ctype_isConj (old->utype))
9266 if (ctype_isConj (unew->utype))
9268 if (!ctype_sameAltTypes (old->utype, unew->utype))
9272 message ("%s %q inconsistently %rdeclared with "
9273 "alternate types %s "
9274 "(types match, but alternates are not identical, "
9275 "so checking may not be correct)",
9276 ekind_capName (uentry_getKind (old)),
9277 uentry_getName (unew),
9278 uentry_isDeclared (old),
9279 ctype_unparse (unew->utype)),
9280 uentry_whereDeclared (unew)))
9282 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
9286 old->utype = unew->utype;
9293 if (ctype_isUnknown (old->utype))
9295 old->utype = unew->utype;
9300 if (unew->ukind == old->ukind)
9303 unew->info = uinfo_copy (old->info, old->ukind);
9306 sRef_storeState (old->sref);
9307 sRef_storeState (unew->sref);
9310 static void uentry_mergeConstraints (uentry spec, uentry def)
9312 if (uentry_isFunction (def))
9314 DPRINTF (("Here: %s / %s",
9315 uentry_unparseFull (spec),
9316 uentry_unparseFull (def)));
9317 /* evans 2001-07-21 */
9318 llassert (uentry_isFunction (spec));
9320 if (functionConstraint_isDefined (def->info->fcn->preconditions))
9322 if (fileloc_isXHFile (uentry_whereLast (def)))
9324 llassert (uentry_isFunction (spec));
9325 spec->info->fcn->preconditions = functionConstraint_conjoin (spec->info->fcn->preconditions,
9326 def->info->fcn->preconditions);
9328 else if (fileloc_equal (uentry_whereLast (spec), uentry_whereLast (def)))
9334 /* Check if the constraints are identical */
9339 ("Preconditions for %q redeclared. Dropping previous precondition: %q",
9340 uentry_getName (spec),
9341 functionConstraint_unparse (spec->info->fcn->preconditions)),
9342 uentry_whereLast (def)))
9344 uentry_showWhereSpecified (spec);
9347 functionConstraint_free (spec->info->fcn->preconditions);
9348 spec->info->fcn->preconditions = def->info->fcn->preconditions;
9351 def->info->fcn->preconditions = functionConstraint_undefined;
9354 if (functionConstraint_isDefined (def->info->fcn->postconditions))
9356 if (fileloc_isXHFile (uentry_whereLast (def)))
9358 llassert (uentry_isFunction (spec));
9359 DPRINTF (("Post: %s /++/ %s",
9360 functionConstraint_unparse (spec->info->fcn->postconditions),
9361 functionConstraint_unparse (def->info->fcn->postconditions)));
9362 spec->info->fcn->postconditions = functionConstraint_conjoin (spec->info->fcn->postconditions,
9363 def->info->fcn->postconditions);
9364 def->info->fcn->postconditions = functionConstraint_undefined;
9365 DPRINTF (("Conjoined post: %s", functionConstraint_unparse (spec->info->fcn->postconditions)));
9372 ("Postconditions for %q redeclared. Dropping previous postcondition: %q",
9373 uentry_getName (spec),
9374 functionConstraint_unparse (spec->info->fcn->postconditions)),
9375 uentry_whereLast (def)))
9377 uentry_showWhereSpecified (spec);
9380 functionConstraint_free (spec->info->fcn->postconditions);
9381 spec->info->fcn->postconditions = def->info->fcn->postconditions;
9382 def->info->fcn->postconditions = functionConstraint_undefined;
9389 ** modifies spec to reflect def, reports any inconsistencies
9393 uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
9395 llassert (uentry_isValid (spec));
9396 llassert (uentry_isValid (def));
9397 llassert (cstring_equal (spec->uname, def->uname));
9399 if (uentry_isFunction (def))
9401 if (uentry_isConstant (spec))
9403 llassert (ctype_isUnknown (spec->utype) || ctype_isFunction (spec->utype));
9404 uentry_makeConstantFunction (spec);
9408 uentry_convertVarFunction (spec);
9411 llassert (uentry_isFunction (spec));
9414 DPRINTF (("Merge entries: %s / %s",
9415 uentry_unparseFull (spec),
9416 uentry_unparseFull (def)));
9418 uentry_mergeConstraints (spec, def);
9420 uentry_checkConformance (spec, def, TRUE,
9421 context_getFlag (FLG_NEEDSPEC));
9423 DPRINTF (("Merge entries after conform: %s / %s",
9424 uentry_unparseFull (spec),
9425 uentry_unparseFull (def)));
9427 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
9430 ** okay, declarations conform. Propagate extra information.
9433 uentry_setDefined (spec, uentry_whereDefined (def));
9434 uentry_setDeclared (spec, uentry_whereDeclared (def));
9436 if (uentry_isStatic (def))
9440 message ("%s %q specified, but declared as static",
9441 ekind_capName (def->ukind),
9442 uentry_getName (def)),
9443 uentry_whereDeclared (def)))
9445 uentry_showWhereSpecified (spec);
9450 spec->storageclass = def->storageclass;
9453 sRef_storeState (spec->sref);
9455 spec->used = def->used || spec->used;
9456 spec->hasNameError |= def->hasNameError;
9460 if (!spec->hasNameError)
9462 uentry_checkName (spec);
9471 ** Can't generate function redeclaration errors when the
9472 ** entries are merged, since we don't yet know if its the
9473 ** definition of the function.
9477 uentry_clearDecl (void)
9479 posRedeclared = uentry_undefined;
9480 fileloc_free (posLoc);
9481 posLoc = fileloc_undefined;
9485 uentry_checkDecl (void)
9487 if (uentry_isValid (posRedeclared) && !fileloc_isXHFile (posLoc))
9489 llassert (fileloc_isDefined (posLoc));
9491 if (uentry_isCodeDefined (posRedeclared))
9493 if (optgenerror (FLG_REDECL,
9494 message ("%s %q declared after definition",
9495 ekind_capName (posRedeclared->ukind),
9496 uentry_getName (posRedeclared)),
9499 llgenindentmsg (message ("Definition of %q",
9500 uentry_getName (posRedeclared)),
9501 posRedeclared->whereDeclared);
9506 if (optgenerror (FLG_REDECL,
9507 message ("%s %q declared more than once",
9508 ekind_capName (posRedeclared->ukind),
9509 uentry_getName (posRedeclared)),
9512 llgenindentmsg (message ("Previous declaration of %q",
9513 uentry_getName (posRedeclared)),
9514 posRedeclared->whereDeclared);
9519 fileloc_free (posLoc);
9520 posLoc = fileloc_undefined;
9521 posRedeclared = uentry_undefined;
9525 ** Redefinition of old as unew.
9526 ** modifies old to reflect unew, reports any inconsistencies
9530 uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
9532 fileloc olddef = uentry_whereDeclared (old);
9533 fileloc unewdef = uentry_whereDeclared (unew);
9537 DPRINTF (("uentry merge: %s / %s",
9538 uentry_unparseFull (old),
9539 uentry_unparseFull (unew)));
9542 fileloc_isUndefined (olddef)
9543 && fileloc_isDefined (uentry_whereDefined (old))
9544 && !uentry_isExpandedMacro (old);
9546 if (!context_getFlag (FLG_INCONDEFSLIB)
9547 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9549 mustConform = FALSE;
9556 llassert (uentry_isValid (old));
9557 llassert (uentry_isValid (unew));
9558 llassert (cstring_equal (old->uname, unew->uname));
9560 if (uentry_isFunction (unew) && !uentry_isFunction (old))
9562 if (uentry_isConstant (old))
9564 llassert (ctype_isUnknown (old->utype) || ctype_isFunction (old->utype));
9565 uentry_makeConstantFunction (old);
9569 uentry_convertVarFunction (old);
9572 llassert (uentry_isFunction (old));
9575 DPRINTF (("uentry merge: %s / %s",
9576 uentry_unparseFull (old),
9577 uentry_unparseFull (unew)));
9579 if (uentry_isExtern (unew))
9581 uentry_setUsed (old, unewdef);
9585 ** should check old one was extern!
9588 if (uentry_isStatic (old))
9590 if (!(uentry_isStatic (unew)))
9594 message ("%s %q shadows static declaration",
9595 ekind_capName (unew->ukind),
9596 uentry_getName (unew)),
9599 uentry_showWhereLast (old);
9604 uentry_setDeclDef (old, unewdef);
9607 else if (uentry_isStatic (unew))
9609 uentry_setDeclDef (old, unewdef);
9611 else if (uentry_isExtern (old))
9613 uentry_setDeclared (old, unewdef);
9617 if (!uentry_isExtern (unew)
9618 && !uentry_isForward (old)
9619 && !fileloc_equal (olddef, unewdef)
9620 && !fileloc_isUndefined (olddef)
9621 && !fileloc_isUndefined (unewdef)
9622 && !fileloc_isBuiltin (olddef)
9623 && !fileloc_isBuiltin (unewdef)
9624 && !uentry_isYield (old)
9625 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9627 if (uentry_isVariable (old) || uentry_isVariable (unew))
9629 ; /* will report redeclaration error later */
9633 if (fileloc_isDefined (uentry_whereDefined (old)))
9637 message ("%s %q defined more than once",
9638 ekind_capName (unew->ukind),
9639 uentry_getName (unew)),
9640 uentry_whereLast (unew)))
9643 (message ("Previous definition of %q",
9644 uentry_getName (old)),
9645 uentry_whereLast (old));
9648 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
9650 uentry_updateInto (old, unew);
9651 old->sref = sRef_saveCopy (old->sref);
9659 if (fileloc_isLib (olddef)
9660 || fileloc_isUndefined (olddef)
9661 || fileloc_isImport (olddef))
9663 if (uentry_isExtern (unew))
9665 if (uentry_isExtern (old)
9666 || (fileloc_isDefined (uentry_whereDeclared (old))
9667 && (!fileloc_equal (uentry_whereDeclared (old),
9668 uentry_whereDefined (old)))))
9672 message ("%s %q declared more than once",
9673 ekind_capName (unew->ukind),
9674 uentry_getName (unew)),
9675 unew->whereDeclared))
9678 (message ("Previous declaration of %q",
9679 uentry_getName (old)),
9680 old->whereDeclared);
9684 uentry_setExtern (old);
9688 uentry_setDeclared (old, unewdef); /* evans 2001-07-23 was setDefined */
9694 DPRINTF (("uentry merge: %s / %s",
9695 uentry_unparseFull (old),
9696 uentry_unparseFull (unew)));
9698 uentry_mergeConstraints (old, unew);
9699 DPRINTF (("uentry merge: %s / %s",
9700 uentry_unparseFull (old),
9701 uentry_unparseFull (unew)));
9703 uentry_checkConformance (old, unew, mustConform, FALSE);
9704 DPRINTF (("uentry merge: %s / %s",
9705 uentry_unparseFull (old),
9706 uentry_unparseFull (unew)));
9708 old->used = old->used || unew->used;
9709 old->uses = filelocList_append (old->uses, unew->uses);
9710 unew->uses = filelocList_undefined;
9712 sRef_storeState (old->sref);
9713 sRef_storeState (unew->sref);
9717 old->whereDefined = fileloc_update (old->whereDefined,
9721 DPRINTF (("here: %s", uentry_unparseFull (old)));
9724 ** No redeclaration errors for functions here, since we
9725 ** don't know if this is the definition of the function.
9728 if (fileloc_isUser (old->whereDeclared)
9729 && fileloc_isUser (unew->whereDeclared)
9730 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
9731 && !fileloc_isDefined (unew->whereDefined))
9733 if (uentry_isFunction (old))
9735 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
9736 posLoc = fileloc_update (posLoc, unew->whereDeclared);
9740 if (optgenerror (FLG_REDECL,
9741 message ("%s %q declared more than once",
9742 ekind_capName (unew->ukind),
9743 uentry_getName (unew)),
9744 unew->whereDeclared))
9746 llgenindentmsg (message ("Previous declaration of %q",
9747 uentry_getName (old)),
9748 old->whereDeclared);
9753 if (fileloc_isUndefined (old->whereDefined))
9755 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
9759 if (!context_processingMacros ()
9760 && fileloc_isUser (old->whereDefined)
9761 && fileloc_isUser (unew->whereDefined)
9762 && !fileloc_equal (old->whereDefined, unew->whereDefined))
9764 if (uentry_isVariable (unew) || uentry_isFunction (unew))
9766 if (uentry_isVariable (unew)
9767 && uentry_isExtern (unew))
9769 if (optgenerror (FLG_REDECL,
9770 message ("%s %q declared after definition",
9771 ekind_capName (unew->ukind),
9772 uentry_getName (unew)),
9773 unew->whereDeclared))
9775 llgenindentmsg (message ("Definition of %q",
9776 uentry_getName (old)),
9782 if (optgenerror (FLG_REDEF,
9783 message ("%s %q redefined",
9784 ekind_capName (unew->ukind),
9785 uentry_getName (unew)),
9786 unew->whereDefined))
9788 llgenindentmsg (message ("Previous definition of %q",
9789 uentry_getName (old)),
9797 if (uentry_isExternal (unew))
9799 old->whereDefined = fileloc_createExternal ();
9802 if (unew->hasNameError)
9804 old->hasNameError = TRUE;
9809 if (!old->hasNameError)
9811 uentry_checkName (old);
9814 DPRINTF (("After: %s", uentry_unparseFull (old)));
9815 llassert (!ctype_isUndefined (old->utype));
9819 uentry_copyState (uentry res, uentry other)
9821 llassert (uentry_isValid (res));
9822 llassert (uentry_isValid (other));
9824 res->used = other->used;
9826 res->info->var->kind = other->info->var->kind;
9827 res->info->var->defstate = other->info->var->defstate;
9828 res->info->var->nullstate = other->info->var->nullstate;
9829 res->info->var->checked = other->info->var->checked;
9831 sRef_copyState (res->sref, other->sref);
9835 uentry_sameKind (uentry u1, uentry u2)
9837 if (uentry_isValid (u1) && uentry_isValid (u2))
9839 if (uentry_isVar (u1) && uentry_isVar (u2))
9841 ctype c1 = u1->utype;
9842 ctype c2 = u2->utype;
9844 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
9847 ** both functions, or both not functions
9850 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
9854 return ((u1->ukind == u2->ukind));
9861 static void uentry_updateInto (/*@unique@*/ uentry unew, uentry old)
9864 llassert (uentry_isValid (unew));
9865 llassert (uentry_isValid (old));
9867 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9868 okind = unew->ukind;
9869 unew->ukind = old->ukind;
9870 llassert (cstring_equal (unew->uname, old->uname));
9871 unew->utype = old->utype;
9873 if (fileloc_isDefined (unew->whereSpecified)
9874 && !fileloc_isDefined (old->whereSpecified))
9876 ; /* Keep the old value */
9880 fileloc_free (unew->whereSpecified); /*@i523 why no error without this? */
9881 unew->whereSpecified = fileloc_copy (old->whereSpecified);
9884 if (fileloc_isDefined (unew->whereDefined)
9885 && !fileloc_isDefined (old->whereDefined))
9887 ; /* Keep the old value */
9891 fileloc_free (unew->whereDefined); /*@i523 why no error without this? */
9892 unew->whereDefined = fileloc_copy (old->whereDefined);
9895 if (fileloc_isDefined (unew->whereDeclared)
9896 && !fileloc_isDefined (old->whereDeclared))
9898 ; /* Keep the old value */
9902 fileloc_free (unew->whereDeclared); /*@i523 why no error without this? */
9903 unew->whereDeclared = fileloc_copy (old->whereDeclared);
9906 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9908 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
9909 unew->used = old->used;
9911 unew->isPrivate = old->isPrivate;
9912 unew->hasNameError = old->hasNameError;
9913 unew->uses = filelocList_append (unew->uses, old->uses);
9914 old->uses = filelocList_undefined;
9916 unew->storageclass = old->storageclass;
9917 uinfo_free (unew->info, okind);
9918 unew->info = uinfo_copy (old->info, old->ukind);
9922 uentry_copyAux (uentry e, bool saveCopy)
9925 if (uentry_isValid (e))
9927 uentry enew = uentry_alloc ();
9928 DPRINTF (("copy: %s", uentry_unparseFull (e)));
9929 enew->ukind = e->ukind;
9930 enew->uname = cstring_copy (e->uname);
9931 enew->utype = e->utype;
9933 enew->whereSpecified = fileloc_copy (e->whereSpecified);
9934 enew->whereDefined = fileloc_copy (e->whereDefined);
9935 enew->whereDeclared = fileloc_copy (e->whereDeclared);
9939 enew->sref = sRef_saveCopy (e->sref); /* Memory leak! */
9943 enew->sref = sRef_copy (e->sref);
9946 enew->used = e->used;
9948 enew->isPrivate = e->isPrivate;
9949 enew->hasNameError = e->hasNameError;
9950 enew->uses = filelocList_undefined;
9952 enew->storageclass = e->storageclass;
9953 enew->info = uinfo_copy (e->info, e->ukind);
9954 enew->warn = warnClause_copy (e->warn);
9956 DPRINTF (("Here we are..."));
9957 DPRINTF (("original: %s", uentry_unparseFull (e)));
9958 DPRINTF (("copy: %s", uentry_unparse (enew)));
9959 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
9964 return uentry_undefined;
9969 uentry_copy (uentry e)
9971 return uentry_copyAux (e, TRUE);
9975 uentry_copyNoSave (uentry e)
9977 return uentry_copyAux (e, FALSE);
9981 uentry_setState (uentry res, uentry other)
9983 llassert (uentry_isValid (res));
9984 llassert (uentry_isValid (other));
9986 llassert (res->ukind == other->ukind);
9987 llassert (res->ukind == KVAR);
9989 res->sref = sRef_saveCopy (other->sref);
9990 res->used = other->used;
9991 filelocList_free (res->uses);
9992 res->uses = other->uses;
9993 other->uses = filelocList_undefined;
9994 res->lset = other->lset;
9998 uentry_mergeUses (uentry res, uentry other)
10000 llassert (uentry_isValid (res));
10001 llassert (uentry_isValid (other));
10003 res->used = other->used || res->used;
10004 res->lset = other->lset || res->lset;
10005 res->uses = filelocList_append (res->uses, other->uses);
10006 other->uses = filelocList_undefined;
10011 ** This is a really ugly routine.
10013 ** gack...fix this one day.
10018 ** >> res is the false branch, other is the true branch (or continuation)
10020 ** >> res is the true branch, other is the false branch (or continutation)
10027 ** References not effected by res are propagated from other.
10031 branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10032 bool flip, clause cl, fileloc loc)
10036 message ("%s %q is %s %s, but %s %s.",
10037 ekind_capName (res->ukind), uentry_getName (res),
10038 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
10039 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
10042 if (sRef_isDead (res->sref))
10044 sRef_showStateInfo (res->sref);
10045 sRef_showStateInfo (other->sref);
10047 else if (sRef_isKept (res->sref))
10049 sRef_showAliasInfo (res->sref);
10050 sRef_showAliasInfo (other->sref);
10052 else /* dependent */
10054 sRef_showAliasInfo (res->sref);
10055 sRef_showAliasInfo (other->sref);
10058 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
10062 static bool uentry_incompatibleMemoryStates (sRef rs, sRef os)
10064 alkind rk = sRef_getAliasKind (rs);
10065 alkind ok = sRef_getAliasKind (os);
10067 if (alkind_isError (rk) || alkind_isError (ok))
10073 return ((sRef_isDead (rs)
10074 || (alkind_isKept (rk) && !alkind_isKept (ok))
10075 || (alkind_isDependent (rk)
10076 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
10077 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
10082 branchStateAltError (/*@notnull@*/ uentry res,
10083 /*@notnull@*/ uentry other, bool flip,
10084 clause cl, fileloc loc)
10088 message ("%s %q is %s %s, but %s %s.",
10089 ekind_capName (res->ukind), uentry_getName (res),
10090 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
10091 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
10094 if (sRef_isDead (other->sref))
10096 sRef_showStateInfo (other->sref);
10100 sRef_showAliasInfo (other->sref);
10103 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
10104 sRef_setDefinedComplete (res->sref, fileloc_undefined);
10106 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
10107 sRef_setDefinedComplete (other->sref, fileloc_undefined);
10112 ** A reference is relevant for certain checks, only if it
10113 ** is not definitely null on this path (but not declared
10114 ** to always be null.)
10117 static bool uentry_relevantReference (sRef sr, bool flip)
10119 if (sRef_isKept (sr) || sRef_isDependent (sr))
10127 return !sRef_definitelyNullContext (sr);
10131 return !sRef_definitelyNullAltContext (sr);
10137 uentry_mergeAliasStates (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10138 fileloc loc, bool mustReturn, bool flip, bool opt,
10141 sRef rs = res->sref;
10142 sRef os = other->sref;
10144 DPRINTF (("Merge alias states: %s / %s",
10145 uentry_unparseFull (res),
10146 uentry_unparseFull (other)));
10148 if (sRef_isValid (rs))
10152 if (uentry_incompatibleMemoryStates (rs, os))
10154 DPRINTF (("Incompatible: \n\t%s / \n\t%s",
10155 sRef_unparseFull (rs), sRef_unparseFull (os)));
10157 if (sRef_isThroughArrayFetch (rs)
10158 && !context_getFlag (FLG_STRICTBRANCHSTATE))
10160 if (sRef_isKept (rs) || sRef_isKept (os))
10162 sRef_maybeKill (rs, loc);
10164 else if (sRef_isPossiblyDead (os))
10166 sRef_maybeKill (rs, loc);
10175 if (uentry_relevantReference (os, flip))
10177 if (sRef_isLocalParamVar (rs)
10178 && (sRef_isLocalState (os)
10179 || sRef_isDependent (os)))
10181 if (sRef_isDependent (rs))
10183 sRef_setDependent (os, loc);
10187 sRef_setDefState (rs, SS_UNUSEABLE, loc);
10192 branchStateError (res, other, flip, cl, loc);
10197 if (sRef_isKept (rs))
10199 DPRINTF (("Setting kept: %s", sRef_unparseFull (os)));
10200 sRef_setKept (os, loc);
10205 if (uentry_incompatibleMemoryStates (os, rs))
10207 if (uentry_relevantReference (rs, !flip))
10209 if (sRef_isLocalParamVar (rs)
10210 && (sRef_isDependent (rs)
10211 || sRef_isLocalState (rs)))
10213 if (sRef_isDependent (os))
10215 sRef_setDependent (rs, loc);
10219 sRef_setDefState (rs, SS_UNUSEABLE, loc);
10224 if (sRef_isParam (os))
10227 ** If the local variable associated
10228 ** with the param has the correct state,
10230 ** (e.g., free (s); s = new(); ...
10233 uentry uvar = usymtab_lookupSafe (other->uname);
10235 if (uentry_isValid (uvar)
10236 && ((sRef_isDead (os)
10237 && sRef_isOnly (uvar->sref))
10238 || (sRef_isDependent (os)
10239 && sRef_isOwned (uvar->sref))))
10245 branchStateAltError (res, other,
10251 DPRINTF (("Here: %s / %s",
10252 uentry_unparseFull (res),
10253 uentry_unparseFull (other)));
10255 branchStateAltError (res, other,
10262 if (sRef_isKept (os))
10264 sRef_setKept (rs, loc);
10270 DPRINTF (("Merge opt..."));
10271 sRef_mergeOptState (rs, os, cl, loc);
10272 DPRINTF (("Done!"));
10276 DPRINTF (("Merging states: \n\t%s / \n\t%s", sRef_unparseFull (rs), sRef_unparseFull (os)));
10277 sRef_mergeState (rs, os, cl, loc);
10278 DPRINTF (("After merging : \n\t%s / \n\t%s", sRef_unparseFull (rs), sRef_unparseFull (os)));
10283 if (sRef_isModified (os))
10285 sRef_setModified (rs);
10290 DPRINTF (("After merge: %s", sRef_unparseFull (res->sref)));
10294 uentry_mergeValueStates (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10295 fileloc loc, bool mustReturn, /*@unused@*/ bool flip)
10297 valueTable rvalues;
10298 valueTable ovalues;
10300 DPRINTF (("Merge values: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
10308 rvalues = sRef_getValueTable (res->sref);
10309 ovalues = sRef_getValueTable (other->sref);
10311 if (valueTable_isUndefined (ovalues))
10313 DPRINTF (("No value table: %s", sRef_unparseFull (other->sref)));
10316 else if (valueTable_isUndefined (rvalues))
10319 ** Copy values from other
10323 DPRINTF (("Has value table: %s", sRef_unparseFull (other->sref)));
10324 DPRINTF (("No value table: %s", sRef_unparseFull (res->sref)));
10329 valueTable_elements (ovalues, fkey, fval) {
10331 metaStateInfo minfo;
10332 stateCombinationTable sctable;
10336 tval = valueTable_lookup (rvalues, fkey);
10338 DPRINTF (("Merge value: %s / %s X %s", fkey,
10339 stateValue_unparse (fval), stateValue_unparse (tval)));
10341 minfo = context_lookupMetaStateInfo (fkey);
10342 llassert (stateValue_isDefined (tval));
10344 if (metaStateInfo_isUndefined (minfo) || !stateValue_isDefined (tval))
10346 DPRINTF (("Cannot find meta state for: %s", fkey));
10351 llassert (metaStateInfo_isDefined (minfo));
10353 if (stateValue_isError (fval)
10354 || sRef_definitelyNullContext (res->sref))
10356 sRef_setMetaStateValueComplete (res->sref,
10357 fkey, stateValue_getValue (fval),
10358 stateValue_getLoc (fval));
10359 DPRINTF (("Setting res: %s", sRef_unparseFull (res->sref)));
10361 else if (stateValue_isError (tval)
10362 || sRef_definitelyNullAltContext (other->sref))
10364 DPRINTF (("Other branch is definitely null!"));
10366 else if (sRef_isStateUndefined (res->sref)
10367 || sRef_isDead (res->sref))
10369 ; /* Combination state doesn't matter if it is undefined or dead */
10373 DPRINTF (("Check: %s / %s / %s / %s", fkey,
10374 metaStateInfo_unparse (minfo),
10375 stateValue_unparse (fval),
10376 stateValue_unparse (tval)));
10378 DPRINTF (("state values: %d / %d",
10379 stateValue_getValue (fval), stateValue_getValue (tval)));
10381 sctable = metaStateInfo_getMergeTable (minfo);
10383 DPRINTF (("Merge table: %s",
10384 stateCombinationTable_unparse (sctable)));
10386 msg = cstring_undefined;
10388 nval = stateCombinationTable_lookup (sctable,
10389 stateValue_getValue (fval),
10390 stateValue_getValue (tval),
10393 DPRINTF (("nval: %d / %d / %d", nval,
10394 stateValue_getValue (fval), stateValue_getValue (tval)));
10396 if (nval == stateValue_error)
10398 /*@i32 print extra info for assignments@*/
10400 if (uentry_isGlobalMarker (res))
10405 ("Control branches merge with incompatible global states (%s and %s)%q",
10406 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10407 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10408 cstring_isDefined (msg)
10409 ? message (": %s", msg) : cstring_undefined),
10412 sRef_showMetaStateInfo (res->sref, fkey);
10413 sRef_showMetaStateInfo (other->sref, fkey);
10421 ("Control branches merge with incompatible states for %q (%s and %s)%q",
10422 uentry_getName (res),
10423 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10424 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10425 cstring_isDefined (msg)
10426 ? message (": %s", msg) : cstring_undefined),
10429 sRef_showMetaStateInfo (res->sref, fkey);
10430 sRef_showMetaStateInfo (other->sref, fkey);
10431 DPRINTF (("Res: %s", sRef_unparseFull (res->sref)));
10432 DPRINTF (("Other: %s", sRef_unparseFull (other->sref)));
10433 DPRINTF (("Null: %s / %s",
10434 bool_unparse (usymtab_isDefinitelyNull (res->sref)),
10435 bool_unparse (usymtab_isDefinitelyNull (other->sref))));
10441 if (nval == stateValue_getValue (fval)
10442 && nval != stateValue_getValue (tval))
10444 loc = stateValue_getLoc (fval);
10446 else if (nval == stateValue_getValue (tval)
10447 && nval != stateValue_getValue (fval))
10449 loc = stateValue_getLoc (tval);
10456 if (stateValue_getValue (sRef_getMetaStateValue (res->sref, fkey)) == nval
10457 && nval == stateValue_getValue (fval)
10458 && nval == stateValue_getValue (tval))
10464 sRef_setMetaStateValueComplete (res->sref, fkey, nval, loc);
10468 } end_valueTable_elements ;
10474 uentry_mergeSetStates (/*@notnull@*/ uentry res,
10475 /*@notnull@*/ uentry other, /*@unused@*/ fileloc loc,
10476 bool flip, clause cl)
10478 if (cl == DOWHILECLAUSE)
10480 res->used = other->used || res->used;
10481 res->lset = other->lset || res->lset;
10482 res->uses = filelocList_append (res->uses, other->uses);
10483 other->uses = filelocList_undefined;
10487 if (sRef_isMacroParamRef (res->sref)
10488 && !uentry_isSefParam (other)
10489 && !uentry_isSefParam (res))
10491 bool hasError = FALSE;
10493 if (bool_equal (res->used, other->used))
10495 res->used = other->used;
10499 if (other->used && !flip)
10504 message ("Macro parameter %q used in true clause, "
10505 "but not in false clause",
10506 uentry_getName (res)),
10507 uentry_whereDeclared (res));
10514 message ("Macro parameter %q used in false clause, "
10515 "but not in true clause",
10516 uentry_getName (res)),
10517 uentry_whereDeclared (res));
10523 /* make it sef now, prevent more errors */
10524 res->info->var->kind = VKREFSEFPARAM;
10530 res->used = other->used || res->used;
10531 res->lset = other->lset || res->lset;
10532 res->uses = filelocList_append (res->uses, other->uses);
10533 other->uses = filelocList_undefined;
10539 uentry_mergeState (uentry res, uentry other, fileloc loc,
10540 bool mustReturn, bool flip, bool opt,
10543 llassert (uentry_isValid (res));
10544 llassert (uentry_isValid (other));
10546 llassert (res->ukind == other->ukind);
10547 llassert (res->ukind == KVAR);
10549 DPRINTF (("Merge state: %s / %s", uentry_unparseFull (res),
10550 uentry_unparseFull (other)));
10552 uentry_mergeAliasStates (res, other, loc, mustReturn, flip, opt, cl);
10553 uentry_mergeValueStates (res, other, loc, mustReturn, flip);
10554 uentry_mergeSetStates (res, other, loc, flip, cl);
10556 DPRINTF (("Merge ==> %s", uentry_unparseFull (res)));
10559 void uentry_setUsed (uentry e, fileloc loc)
10561 static bool firstTime = TRUE;
10562 static bool showUses = FALSE;
10563 static bool exportLocal = FALSE;
10565 DPRINTF (("Used: %s / %s", uentry_unparse (e), fileloc_unparse (loc)));
10569 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
10571 showUses = context_getFlag (FLG_SHOWUSES);
10572 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
10577 if (uentry_isValid (e))
10581 if (warnClause_isDefined (e->warn))
10583 flagSpec flg = warnClause_getFlag (e->warn);
10586 if (warnClause_hasMessage (e->warn))
10588 msg = cstring_copy (warnClause_getMessage (e->warn));
10592 msg = message ("Use of possibly dangerous %s",
10593 uentry_ekindNameLC (e));
10597 message ("%q: %q", msg, uentry_getName (e)),
10601 if (sRef_isMacroParamRef (e->sref))
10603 if (uentry_isYield (e) || uentry_isSefParam (e))
10609 if (context_inConditional ())
10613 message ("Macro parameter %q used in conditionally "
10614 "executed code (may or may not be "
10615 "evaluated exactly once)",
10616 uentry_getName (e)),
10619 e->info->var->kind = VKREFSEFPARAM;
10628 message ("Macro parameter %q used more than once",
10629 uentry_getName (e)),
10630 uentry_whereDeclared (e)))
10632 e->info->var->kind = VKREFSEFPARAM;
10639 if ((dp = uentry_directParamNo (e)) >= 0)
10641 uentry_setUsed (usymtab_getParam (dp), loc);
10646 if (!sRef_isLocalVar (e->sref))
10650 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
10656 if (context_inMacro ())
10658 e->uses = filelocList_addUndefined (e->uses);
10662 e->uses = filelocList_addDifferentFile
10664 uentry_whereDeclared (e),
10673 bool uentry_isReturned (uentry u)
10675 return (uentry_isValid (u) && uentry_isVar (u)
10676 && (u->info->var->kind == VKRETPARAM
10677 || u->info->var->kind == VKSEFRETPARAM));
10682 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args)
10684 llassert (uentry_isRealFunction (u));
10686 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
10688 stateClauseList clauses = uentry_getStateClauseList (u);
10689 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10691 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
10692 sRef_setAllocated (res, g_currentloc);
10694 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10695 stateClauseList_unparse (clauses)));
10698 ** This should be in exprNode_reflectEnsuresClause
10701 stateClauseList_postElements (clauses, cl)
10703 if (!stateClause_isGlobal (cl))
10705 sRefSet refs = stateClause_getRefs (cl);
10706 sRefMod modf = stateClause_getEffectFunction (cl);
10708 sRefSet_elements (refs, el)
10710 sRef base = sRef_getRootBase (el);
10712 if (sRef_isResult (base))
10716 sRef sr = sRef_fixBase (el, res);
10717 modf (sr, g_currentloc);
10724 } end_sRefSet_elements ;
10726 } end_stateClauseList_postElements ;
10734 sRefSet prefs = sRefSet_new ();
10735 sRef res = sRef_undefined;
10736 sRef tcref = sRef_undefined;
10737 sRef tref = sRef_undefined;
10740 params = uentry_getParams (u);
10743 ** Setting up aliases has to happen *after* setting null state!
10746 uentryList_elements (params, current)
10748 if (uentry_isReturned (current))
10750 if (exprNodeList_size (args) >= paramno)
10752 exprNode ecur = exprNodeList_nth (args, paramno);
10753 tref = exprNode_getSref (ecur);
10755 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10757 if (sRef_isValid (tref))
10759 tcref = sRef_copy (tref);
10761 if (sRef_isDead (tcref))
10763 sRef_setDefined (tcref, g_currentloc);
10764 sRef_setOnly (tcref, g_currentloc);
10767 if (sRef_isRefCounted (tcref))
10769 /* could be a new ref now (but only if its returned) */
10770 sRef_setAliasKindComplete (tcref, AK_ERROR, g_currentloc);
10773 sRef_makeSafe (tcref);
10774 prefs = sRefSet_insert (prefs, tcref);
10780 } end_uentryList_elements ;
10782 if (sRefSet_size (prefs) > 0)
10784 nstate n = sRef_getNullState (u->sref);
10786 if (sRefSet_size (prefs) == 1)
10788 sRef rref = sRefSet_choose (prefs);
10790 res = sRef_makeType (sRef_getType (rref));
10791 sRef_copyState (res, tref);
10795 /* should this ever happen? */ /*@i534 evans 2001-05-27 */
10796 res = sRefSet_mergeIntoOne (prefs);
10799 if (nstate_isKnown (n))
10801 sRef_setNullState (res, n, g_currentloc);
10802 DPRINTF (("Setting null: %s", sRef_unparseFull (res)));
10807 if (ctype_isFunction (u->utype))
10809 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10810 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10814 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10815 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
10818 if (sRef_isRefCounted (res))
10820 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10824 if (sRef_getNullState (res) == NS_ABSNULL)
10826 ctype ct = ctype_realType (u->utype);
10828 if (ctype_isAbstract (ct))
10830 sRef_setNotNull (res, g_currentloc);
10834 if (ctype_isUser (ct))
10836 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
10840 sRef_setNotNull (res, g_currentloc);
10845 if (sRef_isRefCounted (res))
10847 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10849 else if (sRef_isKillRef (res))
10851 sRef_setAliasKind (res, AK_REFCOUNTED, g_currentloc);
10858 ak = sRef_getAliasKind (res);
10860 if (alkind_isImplicit (ak))
10862 sRef_setAliasKind (res, alkind_fixImplicit (ak), g_currentloc);
10866 DPRINTF (("Aliasing: %s / %s", sRef_unparseFull (res), sRef_unparseFull (tref)));
10867 usymtab_addReallyForceMustAlias (tref, res); /* evans 2001-05-27 */
10869 /* evans 2002-03-03 - need to be symettric explicitly, since its not a local now */
10870 usymtab_addReallyForceMustAlias (res, tref);
10873 sRefSet_free (prefs);
10875 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
10881 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args, fileloc loc)
10883 llassert (uentry_isRealFunction (u));
10885 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
10887 stateClauseList clauses = uentry_getStateClauseList (u);
10888 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10890 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
10891 sRef_setAllocated (res, loc);
10893 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10894 stateClauseList_unparse (clauses)));
10897 ** This should be in exprNode_reflectEnsuresClause
10900 stateClauseList_postElements (clauses, cl)
10902 if (!stateClause_isGlobal (cl))
10904 sRefSet refs = stateClause_getRefs (cl);
10905 sRefMod modf = stateClause_getEffectFunction (cl);
10907 sRefSet_elements (refs, el)
10909 sRef base = sRef_getRootBase (el);
10911 if (sRef_isResult (base))
10915 sRef sr = sRef_fixBase (el, res);
10923 } end_sRefSet_elements ;
10925 } end_stateClauseList_postElements ;
10933 sRefSet prefs = sRefSet_new ();
10934 sRef res = sRef_undefined;
10937 params = uentry_getParams (u);
10939 uentryList_elements (params, current)
10941 if (uentry_isReturned (current))
10943 if (exprNodeList_size (args) >= paramno)
10945 exprNode ecur = exprNodeList_nth (args, paramno);
10946 sRef tref = exprNode_getSref (ecur);
10948 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10950 if (sRef_isValid (tref))
10952 sRef tcref = sRef_copy (tref);
10954 usymtab_addForceMustAlias (tcref, tref); /* evans 2001-05-27 */
10956 if (sRef_isNew (tcref))
10958 /* tcref->kind = SK_OBJECT; */ /*!! Not new anymore */
10961 if (sRef_isDead (tcref))
10963 sRef_setDefined (tcref, loc);
10964 sRef_setOnly (tcref, loc);
10967 if (sRef_isRefCounted (tcref))
10969 /* could be a new ref now (but only if its returned) */
10970 sRef_setAliasKindComplete (tcref, AK_ERROR, loc);
10973 sRef_makeSafe (tcref);
10974 DPRINTF (("Returns tcref / %s", sRef_unparseFull (tcref)));
10975 prefs = sRefSet_insert (prefs, tcref);
10981 } end_uentryList_elements ;
10983 if (sRefSet_size (prefs) > 0)
10985 nstate n = sRef_getNullState (u->sref);
10987 if (sRefSet_size (prefs) == 1)
10989 res = sRefSet_choose (prefs);
10993 /* should this ever happen? */ /*@i534 evans 2001-05-27 */
10994 res = sRefSet_mergeIntoOne (prefs);
10997 if (nstate_isKnown (n))
10999 sRef_setNullState (res, n, loc);
11004 if (ctype_isFunction (u->utype))
11006 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
11007 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
11011 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
11014 if (sRef_isRefCounted (res))
11016 sRef_setAliasKind (res, AK_NEWREF, loc);
11021 if (sRef_getNullState (res) == NS_ABSNULL)
11023 ctype ct = ctype_realType (u->utype);
11025 if (ctype_isAbstract (ct))
11027 sRef_setNotNull (res, loc);
11031 if (ctype_isUser (ct))
11033 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
11037 sRef_setNotNull (res, loc);
11042 if (sRef_isRefCounted (res))
11044 sRef_setAliasKind (res, AK_NEWREF, loc);
11046 else if (sRef_isKillRef (res))
11048 sRef_setAliasKind (res, AK_REFCOUNTED, loc);
11055 ak = sRef_getAliasKind (res);
11057 if (alkind_isImplicit (ak))
11059 sRef_setAliasKind (res,
11060 alkind_fixImplicit (ak),
11064 sRefSet_free (prefs);
11067 if (sRef_isOnly (res))
11069 sRef_setFresh (res, loc);
11073 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
11078 static bool uentry_isRefCounted (uentry ue)
11080 ctype ct = uentry_getType (ue);
11082 if (ctype_isFunction (ct))
11084 return (ctype_isRefCounted (ctype_getReturnType (ct)));
11088 return (ctype_isRefCounted (ct));
11093 ** old was declared yield in the specification.
11094 ** new is declared in the iter implementation.
11097 void uentry_checkYieldParam (uentry old, uentry unew)
11101 llassert (uentry_isVariable (old));
11102 llassert (uentry_isVariable (unew));
11104 unew->info->var->kind = VKYIELDPARAM;
11105 (void) checkTypeConformance (old, unew, TRUE);
11106 checkVarConformance (old, unew, TRUE, FALSE);
11108 /* get rid of param marker */
11110 name = uentry_getName (unew);
11111 cstring_free (unew->uname);
11112 unew->uname = name;
11113 unew->info->var->kind = VKREFYIELDPARAM;
11115 uentry_setUsed (old, fileloc_undefined);
11116 uentry_setUsed (unew, fileloc_undefined);
11119 /*@observer@*/ cstring
11120 uentry_ekindName (uentry ue)
11122 if (uentry_isValid (ue))
11127 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
11129 return cstring_makeLiteralTemp ("Datatype");
11131 return cstring_makeLiteralTemp ("Enum member");
11133 return cstring_makeLiteralTemp ("Constant");
11135 if (uentry_isParam (ue))
11137 return cstring_makeLiteralTemp ("Parameter");
11139 else if (uentry_isExpandedMacro (ue))
11141 return cstring_makeLiteralTemp ("Expanded macro");
11145 return cstring_makeLiteralTemp ("Variable");
11148 return cstring_makeLiteralTemp ("Function");
11150 return cstring_makeLiteralTemp ("Iterator");
11152 return cstring_makeLiteralTemp ("Iterator finalizer");
11154 return cstring_makeLiteralTemp ("Struct tag");
11156 return cstring_makeLiteralTemp ("Union tag");
11158 return cstring_makeLiteralTemp ("Enum tag");
11160 return cstring_makeLiteralTemp ("Optional parameters");
11165 return cstring_makeLiteralTemp ("<Undefined>");
11171 /*@observer@*/ cstring
11172 uentry_ekindNameLC (uentry ue)
11174 if (uentry_isValid (ue))
11179 return cstring_makeLiteralTemp ("<error: invalid uentry>");
11181 return cstring_makeLiteralTemp ("datatype");
11183 return cstring_makeLiteralTemp ("enum member");
11185 return cstring_makeLiteralTemp ("constant");
11187 if (uentry_isParam (ue))
11189 return cstring_makeLiteralTemp ("parameter");
11191 else if (uentry_isExpandedMacro (ue))
11193 return cstring_makeLiteralTemp ("expanded macro");
11197 return cstring_makeLiteralTemp ("variable");
11200 return cstring_makeLiteralTemp ("function");
11202 return cstring_makeLiteralTemp ("iterator");
11204 return cstring_makeLiteralTemp ("iterator finalizer");
11206 return cstring_makeLiteralTemp ("struct tag");
11208 return cstring_makeLiteralTemp ("union tag");
11210 return cstring_makeLiteralTemp ("enum tag");
11212 return cstring_makeLiteralTemp ("optional parameters");
11217 return cstring_makeLiteralTemp ("<Undefined>");
11223 void uentry_setHasNameError (uentry ue)
11225 llassert (uentry_isValid (ue));
11227 ue->hasNameError = TRUE;
11230 void uentry_checkName (uentry ue)
11232 DPRINTF (("Checking name: %s / %s / %s", uentry_unparse (ue),
11233 uentry_observeRealName (ue),
11234 bool_unparse (uentry_isVisibleExternally (ue))));
11236 if (uentry_isValid (ue)
11237 && !context_inXHFile ()
11238 && uentry_hasName (ue)
11239 && !uentry_isElipsisMarker (ue)
11240 && context_getFlag (FLG_NAMECHECKS)
11241 && !ue->hasNameError
11242 && !uentry_isEndIter (ue)
11243 && !fileloc_isBuiltin (uentry_whereLast (ue))
11244 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
11246 DPRINTF (("Here..."));
11248 if (uentry_isPriv (ue))
11250 ; /* any checks here? */
11252 else if (fileloc_isExternal (uentry_whereDefined (ue)))
11254 ; /* no errors for externals */
11260 if (uentry_isExpandedMacro (ue))
11266 if (uentry_isExpandedMacro (ue))
11270 else if (uentry_isVariable (ue))
11272 sRef sr = uentry_getSref (ue);
11274 if (sRef_isValid (sr))
11276 scope = sRef_getScope (sr);
11283 else if (uentry_isFunction (ue)
11284 || uentry_isIter (ue)
11285 || uentry_isEndIter (ue)
11286 || uentry_isConstant (ue))
11288 scope = uentry_isStatic (ue) ? fileScope : globScope;
11290 else /* datatypes, etc. must be global */
11295 usymtab_checkDistinctName (ue, scope);
11298 if (context_getFlag (FLG_CPPNAMES))
11303 if (scope == globScope)
11305 checkExternalName (ue);
11307 else if (scope == fileScope)
11309 checkFileScopeName (ue);
11313 checkLocalName (ue);
11317 checkAnsiName (ue);
11322 /*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@only@*/ fileloc loc)
11328 ** Can't but unrecognized ids in macros in global scope, because srefs will break!
11331 if (!context_inMacro ())
11333 sRef_setGlobalScopeSafe ();
11336 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
11337 uentry_setUsed (ue, loc);
11339 tloc = fileloc_createExternal ();
11340 uentry_setDefined (ue, tloc);
11341 fileloc_free (tloc);
11342 uentry_setHasNameError (ue);
11344 if (context_getFlag (FLG_REPEATUNRECOG) || (context_inOldStyleScope()))
11346 uentry_markOwned (ue);
11350 ue = usymtab_supReturnFileEntry (ue);
11353 if (!context_inMacro ())
11355 sRef_clearGlobalScopeSafe ();
11361 uentry uentry_makeGlobalMarker ()
11366 llassert (sRef_inGlobalScope ());
11368 ue = uentry_makeVariableAux
11369 (GLOBAL_MARKER_NAME, ctype_unknown, fileloc_undefined,
11370 sRef_makeGlobalMarker (),
11373 tloc = fileloc_createExternal ();
11374 uentry_setUsed (ue, tloc);
11375 uentry_setDefined (ue, tloc);
11376 fileloc_free (tloc);
11377 uentry_setHasNameError (ue);
11383 bool uentry_isGlobalMarker (uentry ue)
11385 return (uentry_isValid (ue)
11386 && (cstring_equal (uentry_rawName (ue), GLOBAL_MARKER_NAME)));
11389 /* new start modifications */
11391 /* start modifications */
11393 requires: p_e is defined, is a ptr/array variable
11395 effects: sets the state of the variable
11399 void uentry_setPossiblyNullTerminatedState (uentry p_e)
11401 llassert (uentry_isValid (p_e));
11403 if (p_e->info != NULL)
11405 if (p_e->info->var != NULL)
11407 llassert (p_e->info->var->bufinfo != NULL);
11408 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
11409 sRef_setPossiblyNullTerminatedState (p_e->sref);
11415 requires: p_e is defined, is a ptr/array variable
11417 effects: sets the size of the buffer
11420 void uentry_setNullTerminatedState (uentry p_e) {
11421 llassert (uentry_isValid (p_e));
11423 if (p_e->info != NULL)
11425 if (p_e->info->var != NULL)
11427 llassert (p_e->info->var->bufinfo != NULL);
11428 p_e->info->var->bufinfo->bufstate = BB_NULLTERMINATED;
11429 sRef_setNullTerminatedState (p_e->sref);
11435 requires: p_e is defined, is a ptr/array variable
11437 effects: sets the size of the buffer
11440 void uentry_setSize (uentry p_e, int size)
11442 if (uentry_isValid (p_e))
11444 if (p_e->info != NULL)
11446 if (p_e->info->var != NULL)
11448 llassert (p_e->info->var->bufinfo != NULL);
11449 p_e->info->var->bufinfo->size = size;
11450 sRef_setSize (p_e->sref, size);
11457 requires: p_e is defined, is a ptr/array variable
11459 effects: sets the length of the buffer
11462 void uentry_setLen (uentry p_e, int len)
11464 if (uentry_isValid (p_e))
11466 if (p_e->info != NULL
11467 && p_e->info->var != NULL)
11469 llassert (p_e->info->var->bufinfo != NULL);
11470 p_e->info->var->bufinfo->len = len;
11471 sRef_setLen (p_e->sref, len);
11478 bool uentry_hasMetaStateEnsures (uentry e)
11480 if (uentry_isValid (e) && uentry_isFunction (e))
11482 return functionConstraint_hasMetaStateConstraint (e->info->fcn->postconditions);
11490 metaStateConstraintList uentry_getMetaStateEnsures (uentry e)
11492 llassert (uentry_isValid (e) && uentry_isFunction (e));
11493 return functionConstraint_getMetaStateConstraints (e->info->fcn->postconditions);
11496 # ifdef DEBUGSPLINT
11499 ** For debugging only
11502 void uentry_checkValid (uentry ue)
11504 if (uentry_isValid (ue))
11506 sRef_checkCompletelyReasonable (ue->sref);