2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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;
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, qual_createUnknown (),
718 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
720 if (!qual_isEitherAbstract (ue->info->datatype->abs))
722 if (ctype_isUnknown (ct))
724 ue->info->datatype->mut = MAYBE;
728 ue->info->datatype->mut = ynm_fromBool (ctype_isMutable (ct));
735 void uentry_checkParams (uentry ue)
737 if (uentry_isValid (ue))
739 bool isExt = uentry_isExtern (ue);
741 if (uentry_isRealFunction (ue))
743 uentryList params = uentry_getParams (ue);
746 uentryList_elements (params, current)
750 if (uentry_isValid (current))
752 ctype ct = current->utype;
754 if (ctype_isFixedArray (ct))
756 if (ctype_isArray (ctype_baseArrayPtr (ct))
757 && !ctype_isFixedArray (ctype_baseArrayPtr (ct)))
763 if (uentry_hasName (current))
766 (FLG_FIXEDFORMALARRAY,
767 message ("Function parameter %q declared as "
768 "manifest array (size constant is meaningless)",
769 uentry_getName (current)),
770 uentry_whereDeclared (current));
775 (FLG_FIXEDFORMALARRAY,
776 message ("Unnamed function parameter %d declared as "
777 "manifest array (size constant is meaningless)",
779 uentry_whereDeclared (current));
785 if (ctype_isArray (ct))
787 if (uentry_hasName (current))
791 message ("Function parameter %q declared as "
792 "array (treated as pointer)",
793 uentry_getName (current)),
794 uentry_whereDeclared (current));
800 message ("Unnamed function parameter %d declared as "
801 "array (treated as pointer)",
803 uentry_whereDeclared (current));
808 if (sRef_getNullState (uentry_getSref (current)) == NS_MNOTNULL)
810 if (ctype_isAbstract (ct) &&
811 (isExt || (ctype_isAbstract (ctype_realType (ct))
812 && !context_hasFileAccess (ctype_typeId (ct)))))
817 ("Function %q declared with notnull parameter %q of abstract "
820 uentry_getName (current),
823 ("Since %s is an abstract type, notnull can only be "
824 "used for parameters if the function is static to a "
825 "module where %s is accessible.",
828 uentry_whereDeclared (current));
832 } end_uentryList_elements;
834 if (sRef_getNullState (uentry_getSref (ue)) == NS_MNOTNULL)
836 ctype ct = ue->utype;
838 if (ctype_isAbstract (ct)
839 && (isExt || (ctype_isAbstract (ctype_realType (ct))
840 && !context_hasFileAccess (ctype_typeId (ct)))))
845 ("%s %q declared %s notnull storage of abstract type %s",
846 ekind_capName (uentry_getKind (ue)),
851 ("Since %s is an abstract type, notnull can only be used "
852 "if it is static to a module where %s is accessible.",
855 uentry_whereDeclared (ue));
862 static void reflectImplicitFunctionQualifiers (/*@notnull@*/ uentry ue, bool spec)
864 alkind ak = sRef_getAliasKind (ue->sref);
866 if (alkind_isRefCounted (ak))
868 sRef_setAliasKind (ue->sref, AK_NEWREF, fileloc_undefined);
872 if (alkind_isUnknown (ak))
874 exkind ek = sRef_getExKind (ue->sref);
876 if (exkind_isKnown (ek))
878 DPRINTF (("Setting imp dependent: %s",
879 uentry_unparseFull (ue)));
880 sRef_setAliasKind (ue->sref, AK_IMPDEPENDENT, fileloc_undefined);
884 if (context_getFlag (spec ? FLG_SPECRETIMPONLY : FLG_RETIMPONLY))
886 /* evans 2000-12-22 removed ctype_realType so it will
887 not apply to immutable abstract types. */
889 if (ctype_isVisiblySharable
890 (ctype_realType (ctype_getReturnType (ue->utype))))
892 if (uentryList_hasReturned (uentry_getParams (ue)))
898 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype))
899 || ctype_isNumAbstract (ctype_getReturnType (ue->utype)))
901 ; /* Immutable objects are not shared. */
905 sRef_setAliasKind (ue->sref, AK_IMPONLY,
907 DPRINTF (("Ret imp only: %s",
908 ctype_unparse (ctype_getReturnType (ue->utype))));
918 static /*@notnull@*/ uentry
919 uentry_makeFunctionAux (cstring n, ctype t,
921 /*@only@*/ globSet globs,
922 /*@only@*/ sRefSet mods,
923 /*@only@*/ warnClause warn,
924 /*@keep@*/ fileloc f, bool priv,
925 /*@unused@*/ bool isForward)
927 uentry e = uentry_alloc ();
930 llassert (warnClause_isUndefined (warn));
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));
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)
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))
1476 /* removed this: no need to copy? ue->sref = sRef_saveCopyShallow (ue->info->var->origsref); */
1477 sRef_setDefState (sr, ue->info->var->defstate, fileloc_undefined);
1478 sRef_setNullState (sr, ue->info->var->nullstate, fileloc_undefined);
1482 static void uentry_addStateClause (/*@notnull@*/ uentry ue, stateClause sc)
1485 ** Okay to allow multiple clauses of the same kind.
1488 ue->info->fcn->specclauses =
1489 stateClauseList_add (ue->info->fcn->specclauses, sc);
1491 /* Will call checkAll to check later... */
1494 void uentry_setStateClauseList (uentry ue, stateClauseList clauses)
1496 llassert (uentry_isFunction (ue));
1497 llassert (!stateClauseList_isDefined (ue->info->fcn->specclauses));
1499 DPRINTF (("checked clauses: %s", stateClauseList_unparse (clauses)));
1500 ue->info->fcn->specclauses = clauses;
1501 stateClauseList_checkAll (ue);
1502 DPRINTF (("checked clauses: %s", uentry_unparseFull (ue)));
1506 ** Used for @modifies@ @endmodifies@ syntax.
1508 ** If ue is specified, sr must contain *only*:
1510 ** o file static globals
1511 ** o sRef's derived from modifies spec (i.e., more specific than
1512 ** what was specified)
1514 ** Otherwise, if sr has modifies it must match sr.
1516 ** If it doesn't have modifies, set them to sr.
1520 uentry_checkModifiesContext (void)
1522 if (sRef_modInFunction ())
1526 ("Modifies list not in function context. "
1527 "A modifies list can only appear following the parameter list "
1528 "in a function declaration or header."));
1537 uentry_setModifies (uentry ue, /*@owned@*/ sRefSet sr)
1539 if (!uentry_checkModifiesContext ())
1545 if (uentry_isValid (ue))
1547 if (uentry_isIter (ue))
1549 llassert (sRefSet_isUndefined (ue->info->iter->mods));
1550 ue->info->iter->mods = sr;
1554 uentry_convertVarFunction (ue);
1555 llassertfatal (uentry_isFunction (ue));
1556 llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1558 ue->info->fcn->mods = sr;
1559 ue->info->fcn->hasMods = TRUE;
1561 checkGlobalsModifies (ue, sr);
1564 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1566 ue->info->fcn->hasGlobs = TRUE;
1569 if (sRefSet_hasStatic (ue->info->fcn->mods))
1571 context_recordFileModifies (ue->info->fcn->mods);
1581 uentry_combineModifies (uentry ue, /*@owned@*/ sRefSet sr)
1584 ** Function already has one modifies clause (possibly from
1585 ** a specification).
1588 if (!uentry_checkModifiesContext ())
1593 llassert (uentry_isValid (ue));
1595 if (uentry_isIter (ue))
1597 ue->info->iter->mods = sRefSet_unionFree (ue->info->iter->mods, sr);
1601 llassertfatal (uentry_isFunction (ue));
1602 llassert (ue->info->fcn->hasMods);
1604 checkGlobalsModifies (ue, sr);
1605 ue->info->fcn->mods = sRefSet_unionFree (ue->info->fcn->mods, sr);
1607 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1609 ue->info->fcn->hasGlobs = TRUE;
1613 if (sRefSet_hasStatic (ue->info->fcn->mods))
1615 context_recordFileModifies (ue->info->fcn->mods);
1619 bool uentry_hasWarning (uentry ue)
1621 return (uentry_isValid (ue)
1622 && warnClause_isDefined (ue->warn));
1625 void uentry_addWarning (uentry ue, /*@only@*/ warnClause warn)
1627 llassert (uentry_isValid (ue));
1628 llassert (warnClause_isUndefined (ue->warn));
1633 uentry_setPreconditions (uentry ue, /*@only@*/ functionConstraint preconditions)
1635 if (sRef_modInFunction ())
1638 (message ("Precondition list not in function context. "
1639 "A precondition list can only appear following the parameter list "
1640 "in a function declaration or header."));
1642 /*@-mustfree@*/ return; /*@=mustfree@*/
1645 if (uentry_isValid (ue))
1647 uentry_convertVarFunction (ue);
1648 llassertfatal (uentry_isFunction (ue));
1650 if (functionConstraint_isDefined (ue->info->fcn->preconditions))
1652 /*drl oops this date is wronge...*/
1654 I changed this so it didn't appear as a Splint bug
1655 among other things this gets triggered when there is
1656 a function with two requires clauses. Now Splint
1657 prints an error and tries to conjoin the lists.
1660 (message ("Duplicate precondition list"
1661 "Attemping the conjoin the requires clauses"
1665 /* should conjoin constraints? */
1667 ue->info->fcn->preconditions = functionConstraint_conjoin (ue->info->fcn->preconditions, preconditions);
1671 ue->info->fcn->preconditions = preconditions;
1676 llfatalbug ((message("uentry_setPreconditions called with invalid uentry") ));
1685 uentry_setPostconditions (uentry ue, /*@only@*/ functionConstraint postconditions)
1687 if (sRef_modInFunction ())
1690 (message ("Postcondition list not in function context. "
1691 "A postcondition list can only appear following the parameter list "
1692 "in a function declaration or header."));
1694 /*@-mustfree@*/ return; /*@=mustfree@*/
1697 if (uentry_isValid (ue))
1699 uentry_convertVarFunction (ue);
1700 llassertfatal (uentry_isFunction (ue));
1702 if (functionConstraint_isUndefined (ue->info->fcn->postconditions))
1704 ue->info->fcn->postconditions = postconditions;
1708 ue->info->fcn->postconditions = functionConstraint_conjoin (ue->info->fcn->postconditions, postconditions);
1713 llfatalbug ((message("uentry_setPostconditions called with invalid uentry") ));
1718 ** requires: new and old are functions
1722 checkGlobalsConformance (/*@notnull@*/ uentry old,
1723 /*@notnull@*/ uentry unew,
1724 bool mustConform, bool completeConform)
1726 bool hasInternalState = FALSE;
1728 old->info->fcn->hasGlobs |= unew->info->fcn->hasGlobs;
1730 if (globSet_isDefined (unew->info->fcn->globs))
1732 globSet_allElements (unew->info->fcn->globs, el)
1734 if (sRef_isFileStatic (el))
1736 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1738 if (sRef_isInvalid (sr))
1740 bool hasError = FALSE;
1742 if (!hasInternalState
1743 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1744 sRef_makeInternalState ()))
1745 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1746 sRef_makeSpecState ())))
1749 && !uentry_isStatic (old)
1752 message ("Globals list for %q includes internal state, %q, "
1753 "but %s without globals internalState.",
1754 uentry_getName (old),
1756 uentry_specOrDefName (old)),
1757 uentry_whereLast (unew)))
1759 uentry_showWhereSpecified (old);
1763 old->info->fcn->globs = globSet_insert (old->info->fcn->globs,
1764 sRef_makeInternalState ());
1765 hasInternalState = TRUE;
1769 && fileloc_sameFile (uentry_whereDeclared (unew),
1770 uentry_whereDeclared (old)))
1775 message ("Function %q inconsistently %rdeclared (in "
1776 "same file) with file static global %q in "
1778 uentry_getName (unew),
1779 uentry_isDeclared (old),
1781 uentry_whereDeclared (unew)))
1783 uentry_showWhereSpecified (old);
1788 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1789 context_recordFileGlobals (old->info->fcn->globs);
1793 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1795 if (sRef_isInvalid (sr))
1800 message ("Function %q inconsistently %rdeclared with "
1801 "%q in globals list",
1802 uentry_getName (unew),
1803 uentry_isDeclared (old),
1805 uentry_whereDeclared (unew)))
1807 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1808 uentry_showWhereSpecified (old);
1813 if (!bool_equal (sRef_isAllocated (el), sRef_isAllocated (sr)))
1819 ("Function %q global %q inconsistently "
1820 "%rdeclared as %qout global",
1821 uentry_getName (unew),
1823 uentry_isDeclared (old),
1824 cstring_makeLiteral (sRef_isAllocated (el) ? "" : "non-")),
1825 uentry_whereDeclared (unew)))
1827 uentry_showWhereSpecified (old);
1832 } end_globSet_allElements ;
1834 if (completeConform)
1836 globSet_allElements (old->info->fcn->globs, el)
1838 sRef sr = globSet_lookup (unew->info->fcn->globs, el);
1840 if (sRef_isInvalid (sr))
1843 && uentry_isReallySpecified (old)
1846 message ("Function %q specified with %q in globals list, "
1847 "but declared without %q",
1848 uentry_getName (unew),
1851 uentry_whereDeclared (unew)))
1853 uentry_showWhereSpecified (old);
1856 } end_globSet_allElements;
1861 if (completeConform && !globSet_isEmpty (old->info->fcn->globs))
1863 if (uentry_isReallySpecified (old)
1866 message ("%s %q specified with globals list, but "
1867 "declared with no globals",
1868 ekind_capName (unew->ukind),
1869 uentry_getName (unew)),
1870 uentry_whereDeclared (unew)))
1873 (message ("Specification globals: %q",
1874 globSet_unparse (old->info->fcn->globs)),
1875 uentry_whereSpecified (old));
1879 unew->info->fcn->globs = globSet_copyInto (unew->info->fcn->globs,
1880 old->info->fcn->globs);
1885 ** new modifies list must be included by old modifies list.
1887 ** file static state may be added to new, if old has internal.
1891 checkModifiesConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
1892 bool mustConform, bool completeConform)
1895 bool changedMods = FALSE;
1896 bool modInternal = FALSE;
1898 llassert (uentry_isFunction (old) && uentry_isFunction (unew));
1900 old->info->fcn->hasMods |= unew->info->fcn->hasMods;
1901 newMods = unew->info->fcn->mods;
1903 if (sRefSet_isEmpty (newMods))
1905 if (completeConform && !sRefSet_isEmpty (old->info->fcn->mods)
1906 && uentry_isReallySpecified (old))
1910 message ("%s %q specified with modifies clause, "
1911 "but declared with no modifies clause",
1912 ekind_capName (unew->ukind),
1913 uentry_getName (unew)),
1914 uentry_whereDeclared (unew)))
1916 llgenindentmsg (message ("Specification has modifies %q",
1917 sRefSet_unparse (old->info->fcn->mods)),
1918 uentry_whereSpecified (old));
1925 sRefSet_allElements (newMods, current)
1927 if (sRef_isValid (current))
1929 sRef rb = sRef_getRootBase (current);
1931 if (sRef_isFileStatic (rb))
1935 if (!sRefSet_isSameMember (old->info->fcn->mods,
1936 sRef_makeInternalState ())
1937 && !sRefSet_isSameMember (old->info->fcn->mods,
1938 sRef_makeSpecState ()))
1941 && !uentry_isStatic (old)
1945 ("Modifies list for %q includes internal state, "
1946 "but %s without modifies internal.",
1947 uentry_getName (old),
1948 uentry_specOrDefName (old)),
1949 uentry_whereLast (unew)))
1951 uentry_showWhereSpecified (old);
1954 old->info->fcn->mods =
1955 sRefSet_insert (old->info->fcn->mods,
1956 sRef_makeInternalState ());
1961 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1967 if (sRef_canModifyVal (current, old->info->fcn->mods))
1969 int size = sRefSet_size (old->info->fcn->mods);
1971 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1974 if (sRefSet_size (old->info->fcn->mods) != size)
1985 ("Modifies list for %q contains %q, not modifiable "
1987 uentry_getName (old),
1988 sRef_unparse (current),
1989 uentry_specDeclName (old)),
1990 uentry_whereLast (unew)))
1992 uentry_showWhereSpecified (old);
1997 } end_sRefSet_allElements;
1999 if (completeConform && uentry_isReallySpecified (old))
2001 sRefSet_allElements (old->info->fcn->mods, el)
2003 if (sRef_canModify (el, newMods))
2012 ("Specification modifies clause for %q contains %q, "
2013 "not included in declaration modifies clause",
2014 uentry_getName (old),
2016 uentry_whereLast (unew)))
2018 uentry_showWhereSpecified (old);
2021 } end_sRefSet_allElements ;
2025 ** Make sure file static elements will be removed.
2030 context_recordFileModifies (old->info->fcn->mods);
2035 uentry_checkMutableType (uentry ue)
2037 ctype ct = uentry_getType (ue);
2039 if (!ctype_isRealPointer (ct) && !ctype_isRealAbstract (ct))
2041 DPRINTF (("Check mutable: %s", uentry_unparseFull (ue)));
2043 voptgenerror (FLG_MUTREP,
2044 message ("Mutable abstract type %q declared without pointer "
2045 "indirection: %t (violates assignment semantics)",
2046 uentry_getName (ue), ct),
2047 uentry_whereDeclared (ue));
2052 uentry_setMutable (uentry e)
2054 llassert (uentry_isDatatype (e));
2055 e->info->datatype->mut = YES;
2059 uentry_checkIterArgs (uentry ue)
2061 bool hasYield = FALSE;
2064 llassert (uentry_isIter (ue));
2066 args = uentry_getParams (ue);
2068 uentryList_elements (args, el)
2070 sstate ds = uentry_getDefState (el);
2072 if (uentry_isYield (el))
2077 if (sstate_isUnknown (ds))
2079 uentry_setDefState (el, SS_DEFINED);
2085 } end_uentryList_elements;
2089 voptgenerror (FLG_HASYIELD,
2090 message ("Iterator %q declared with no yield parameters",
2091 uentry_getName (ue)),
2092 uentry_whereDeclared (ue));
2097 chkind_fromQual (qual qel)
2099 if (qual_isChecked (qel))
2103 else if (qual_isCheckMod (qel))
2107 else if (qual_isCheckedStrict (qel))
2109 return CH_CHECKEDSTRICT;
2111 else if (qual_isUnchecked (qel))
2113 return CH_UNCHECKED;
2118 /*@notreached@*/ return CH_UNKNOWN;
2123 uentry_reflectOtherQualifier (/*@notnull@*/ uentry ue, qual qel)
2125 if (qual_isKillRef (qel) || qual_isNewRef (qel) || qual_isTempRef (qel))
2127 if (!uentry_isRefCounted (ue))
2130 (FLG_ANNOTATIONERROR,
2131 message ("Reference counting qualifier %s used on non-reference "
2132 "counted storage: %q",
2134 uentry_unparse (ue)),
2135 uentry_whereLast (ue));
2139 alkind ak = alkind_fromQual (qel);
2141 uentry_setAliasKind (ue, ak);
2144 else if (qual_isRefCounted (qel))
2146 ctype ct = ctype_realType (uentry_getType (ue));
2149 if (ctype_isPointer (ct)
2150 && (ctype_isStruct (rt = ctype_realType (ctype_baseArrayPtr (ct)))))
2152 /* check there is a refs field */
2153 uentryList fields = ctype_getFields (rt);
2154 uentry refs = uentry_undefined;
2156 uentryList_elements (fields, field)
2158 if (uentry_isRefsField (field))
2160 if (uentry_isValid (refs))
2163 (FLG_ANNOTATIONERROR,
2164 message ("Reference counted structure type %s has "
2165 "multiple refs fields: %q and %q",
2167 uentry_getName (refs),
2168 uentry_getName (field)),
2169 uentry_whereLast (field));
2174 } end_uentryList_elements;
2176 if (uentry_isInvalid (refs))
2180 message ("Reference counted structure type %s has "
2182 ctype_unparse (ct)),
2184 ("To count reference, the structure must have a field named "
2185 "refs of type int."),
2188 else if (!ctype_isInt (uentry_getType (refs)))
2191 (FLG_ANNOTATIONERROR,
2192 message ("Reference counted structure type %s refs field has "
2193 "type %s (should be int)", ctype_unparse (ct),
2194 ctype_unparse (uentry_getType (refs))),
2195 uentry_whereLast (refs));
2199 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2200 uentry_whereDeclared (ue));
2205 if ((ctype_isPointer (ct)
2206 && ctype_isUnknown (ctype_realType (ctype_baseArrayPtr (ct))))
2207 ||ctype_isAbstract (ct) || ctype_isUnknown (ct))
2209 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2210 uentry_whereDeclared (ue));
2215 (FLG_ANNOTATIONERROR,
2216 message ("Non-pointer to structure type %s declared with "
2217 "refcounted qualifier",
2218 ctype_unparse (ct)),
2219 uentry_whereLast (ue));
2223 else if (qual_isRefs (qel))
2225 if (uentry_isVariable (ue) && !uentry_isParam (ue))
2227 uentry_setAliasKind (ue, AK_REFS);
2232 (FLG_ANNOTATIONERROR,
2233 message ("Refs qualifier used on non-structure field: %q",
2234 uentry_unparse (ue)),
2235 uentry_whereLast (ue));
2238 else if (qual_isAliasQual (qel))
2240 alkind ak = alkind_fromQual (qel);
2242 alkind oldak = uentry_getAliasKind (ue);
2243 ctype ut = uentry_getType (ue);
2245 if (alkind_isImplicit (ak)
2246 && (alkind_isKnown (oldak) && !alkind_isImplicit (oldak)))
2248 /* ignore the implied qualifier */
2252 if (uentry_isEitherConstant (ue))
2255 (FLG_ANNOTATIONERROR,
2256 message ("Alias qualifier %s used on constant: %q",
2257 alkind_unparse (ak), uentry_unparse (ue)),
2258 uentry_whereLast (ue));
2263 if (ctype_isFunction (ut))
2265 ut = ctype_getReturnType (ut);
2268 if (!(ctype_isVisiblySharable (ut)
2269 || ctype_isRealArray (ut)
2270 || ctype_isRealSU (ut)))
2272 if (!qual_isImplied (qel))
2275 (FLG_ANNOTATIONERROR,
2276 message ("Alias qualifier %s used on unsharable storage type %t: %q",
2277 alkind_unparse (ak), ut, uentry_getName (ue)),
2278 uentry_whereLast (ue));
2285 if (uentry_isRefCounted (ue))
2287 if (!(qual_isRefQual (qel) || qual_isOnly (qel)
2288 || qual_isExposed (qel)
2289 || qual_isObserver (qel)))
2291 if (!qual_isImplied (qel))
2294 (FLG_ANNOTATIONERROR,
2296 ("Alias qualifier %s used on reference counted storage: %q",
2297 alkind_unparse (ak),
2298 uentry_unparse (ue)),
2299 uentry_whereLast (ue));
2307 if (qual_isRefQual (qel))
2310 (FLG_ANNOTATIONERROR,
2311 message ("Qualifier %s used on non-reference counted storage: %q",
2312 alkind_unparse (ak), uentry_unparse (ue)),
2313 uentry_whereLast (ue));
2322 uentry_setAliasKind (ue, ak);
2325 else if (qual_isNull (qel))
2327 if (uentry_isConstant (ue))
2331 ctype_isAbstract (ue->utype) ? NS_CONSTNULL : NS_DEFNULL,
2332 uentry_whereDeclared (ue));
2336 uentry_setNullState (ue, NS_POSNULL);
2339 else if (qual_isRelNull (qel))
2341 uentry_setNullState (ue, NS_RELNULL);
2343 else if (qual_isNotNull (qel))
2345 uentry_setNullState (ue, NS_MNOTNULL);
2347 else if (qual_isAbstract (qel)
2348 || qual_isNumAbstract (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 = qel;
2362 DPRINTF (("Setting abstract %s: %s",
2363 uentry_unparse (ue), qual_unparse (qel)));
2366 else if (qual_isMutable (qel))
2368 if (!uentry_isDatatype (ue))
2371 (FLG_ANNOTATIONERROR,
2372 message ("Qualifier %s used with non-datatype", qual_unparse (qel)),
2373 uentry_whereLast (ue));
2377 if (!ynm_isOn (ue->info->datatype->mut))
2379 uentry_checkMutableType (ue);
2382 ue->info->datatype->mut = YES;
2385 else if (qual_isImmutable (qel))
2387 if (!uentry_isDatatype (ue))
2389 voptgenerror (FLG_ANNOTATIONERROR,
2390 message ("Qualifier %s used with non-datatype",
2391 qual_unparse (qel)),
2392 uentry_whereLast (ue));
2396 ue->info->datatype->mut = NO;
2399 else if (qual_isNullPred (qel))
2401 uentry_convertVarFunction (ue);
2403 if (uentry_isFunction (ue))
2405 ctype typ = uentry_getType (ue);
2406 ctype rtype = ctype_getReturnType (uentry_getType (ue));
2408 if (ctype_isRealBool (rtype))
2410 uentryList pl = ctype_argsFunction (typ);
2412 if (uentryList_size (pl) == 1)
2414 ue->info->fcn->nullPred = qel;
2418 voptgenerror (FLG_ANNOTATIONERROR,
2419 message ("Qualifier %s used with function having %d "
2420 "arguments (should have 1)",
2422 uentryList_size (pl)),
2423 uentry_whereLast (ue));
2428 voptgenerror (FLG_ANNOTATIONERROR,
2429 message ("Qualifier %s used with function returning %s "
2430 "(should return bool)",
2432 ctype_unparse (rtype)),
2433 uentry_whereLast (ue));
2438 voptgenerror (FLG_ANNOTATIONERROR,
2439 message ("Qualifier %s used with non-function",
2440 qual_unparse (qel)),
2441 uentry_whereLast (ue));
2444 else if (qual_isExitQual (qel))
2446 exitkind exk = exitkind_fromQual (qel);
2448 if (uentry_isFunction (ue))
2450 if (exitkind_isKnown (ue->info->fcn->exitCode))
2452 voptgenerror (FLG_ANNOTATIONERROR,
2453 message ("Multiple exit qualifiers used on function %q: %s, %s",
2454 uentry_getName (ue),
2455 exitkind_unparse (ue->info->fcn->exitCode),
2456 exitkind_unparse (exk)),
2457 uentry_whereLast (ue));
2460 ue->info->fcn->exitCode = exk;
2464 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2466 uentry_makeVarFunction (ue);
2467 ue->info->fcn->exitCode = exk;
2471 voptgenerror (FLG_ANNOTATIONERROR,
2472 message ("Exit qualifier %s used with non-function (type %s)",
2474 ctype_unparse (uentry_getType (ue))),
2475 uentry_whereLast (ue));
2479 else if (qual_isMetaState (qel))
2481 annotationInfo ainfo = qual_getAnnotationInfo (qel);
2483 if (annotationInfo_matchesContext (ainfo, ue))
2485 DPRINTF (("Reflecting %s on %s",
2486 annotationInfo_unparse (ainfo),
2487 uentry_unparseFull (ue)));
2489 sRef_reflectAnnotation (ue->sref, ainfo, g_currentloc);
2490 DPRINTF (("==> %s", sRef_unparseFull (ue->sref)));
2491 DPRINTF (("==> %s", uentry_unparseFull (ue)));
2496 (FLG_ANNOTATIONERROR,
2497 message ("Attribute annotation %s used in inconsistent context: %q",
2499 uentry_unparse (ue)),
2500 uentry_whereLast (ue)))
2502 /* annotationInfo_showContextError (ainfo, ue); */
2508 if (qual_isCQual (qel))
2514 llbug (message ("Unhandled qualifier: %s", qual_unparse (qel)));
2520 uentry_reflectQualifiers (uentry ue, qualList q)
2522 llassert (uentry_isValid (ue));
2524 DPRINTF (("Reflect qualifiers: %s / %s",
2525 uentry_unparseFull (ue), qualList_unparse (q)));
2527 qualList_elements (q, qel)
2529 if (qual_isStatic (qel))
2531 uentry_setStatic (ue);
2533 else if (qual_isUnused (qel))
2535 uentry_setUsed (ue, fileloc_undefined);
2536 DPRINTF (("Used: %s", uentry_unparseFull (ue)));
2538 else if (qual_isExternal (qel))
2540 fileloc_free (ue->whereDefined);
2541 ue->whereDefined = fileloc_createExternal ();
2543 else if (qual_isSef (qel))
2545 if (uentry_isVariable (ue))
2547 vkind vk = ue->info->var->kind;
2549 llassert (vk != VKREFPARAM);
2551 if (vk == VKYIELDPARAM)
2554 (FLG_ANNOTATIONERROR,
2555 message ("Qualifier sef cannot be used with %s: %q",
2556 cstring_makeLiteralTemp (vk == VKYIELDPARAM ? "yield" : "returned"),
2557 uentry_unparse (ue)),
2558 uentry_whereLast (ue));
2560 else if (vk == VKRETPARAM)
2562 ue->info->var->kind = VKSEFRETPARAM;
2566 ue->info->var->kind = VKSEFPARAM;
2572 (FLG_ANNOTATIONERROR,
2573 message ("Qualifier sef is meaningful only on parameters: %q",
2574 uentry_unparse (ue)),
2575 uentry_whereLast (ue));
2578 else if (qual_isExtern (qel))
2580 ue->storageclass = SCEXTERN;
2582 else if (qual_isGlobalQual (qel)) /* undef, killed */
2584 DPRINTF (("Reflecting qual: %s / %s",
2585 qual_unparse (qel), uentry_unparse (ue)));
2587 if (uentry_isVariable (ue))
2589 sstate oldstate = ue->info->var->defstate;
2590 sstate defstate = sstate_fromQual (qel);
2593 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
2594 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
2596 defstate = SS_UNDEFKILLED;
2603 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2604 ue->info->var->defstate = defstate;
2609 (FLG_ANNOTATIONERROR,
2610 message ("Qualifier %s used on non-variable: %q",
2611 qual_unparse (qel), uentry_unparse (ue)),
2612 uentry_whereLast (ue));
2615 DPRINTF (("After: %s", uentry_unparseFull (ue)));
2617 /* start modifications */
2618 else if( qual_isBufQualifier(qel) ) {
2619 ctype ct = ctype_realType(uentry_getType(ue));
2620 if( ctype_isArray(ct) || ctype_isPointer(ct) ) {
2622 if( uentry_hasBufStateInfo(ue) ) {
2623 if( qual_isNullTerminated(qel) ) { /* handle Nullterm */
2625 if (uentry_isAnyParam(ue) || uentry_isReturned (ue)) {
2626 /* If formal func param */
2627 uentry_setNullTerminatedState(ue);
2628 uentry_setLen (ue, 1);
2629 uentry_setSize (ue, 1);
2631 sRef_setNullTerminatedState(uentry_getSref(ue));
2632 sRef_setLen (uentry_getSref(ue), 1);
2633 sRef_setSize (uentry_getSref(ue), 1);
2635 uentry_setPossiblyNullTerminatedState(ue);
2637 sRef_setPossiblyNullTerminatedState(uentry_getSref(ue));
2641 /* put other BufState Qualifiers here */
2643 cstring s = uentry_getName(ue);
2644 llfatalbug(message("INTERNAL Error: we have a NULL BufState \
2645 struct for identifier %s\n", s) );
2647 } else if (ctype_isFunction (ct)) { /* We have to handle function */
2649 sRef retSref = uentry_getSref (ue);
2650 ctype retType = sRef_getType (retSref);
2652 if (ctype_isPointer (retType) || ctype_isArray (retType)) {
2653 sRef_setNullTerminatedState (retSref);
2659 message ("Qualifier %s used on non-pointer on \
2660 function return: %q", qual_unparse (qel),
2661 uentry_unparse (ue)));
2668 message ("Qualifier %s used on non-pointer: %q",
2669 qual_unparse (qel), uentry_unparse (ue)));
2671 DPRINTF (("After: %s", uentry_unparseFull (ue)));
2673 else if (qual_isAllocQual (qel)) /* out, partial, reldef, special, etc. */
2675 ctype realType = ctype_realType (ue->utype);
2676 sstate defstate = sstate_fromQual (qel);
2678 if (ctype_isFunction (realType))
2680 realType = ctype_realType (ctype_getReturnType (realType));
2683 if (qual_isRelDef (qel))
2685 ; /* okay anywhere */
2689 if (!ctype_isAP (realType)
2690 && !ctype_isSU (realType)
2691 && !ctype_isUnknown (realType)
2692 && !ctype_isAbstract (ue->utype))
2695 (FLG_ANNOTATIONERROR,
2696 message ("Qualifier %s used on non-pointer or struct: %q",
2697 qual_unparse (qel), uentry_unparse (ue)),
2698 uentry_whereLast (ue));
2702 uentry_setDefState (ue, defstate);
2704 if (sRef_isStateSpecial (ue->sref)
2705 && alkind_isImplicit (sRef_getAliasKind (ue->sref)))
2707 sRef_setAliasKind (ue->sref, AK_ERROR, fileloc_undefined);
2710 else if (qual_isYield (qel))
2712 if (uentry_isVariable (ue))
2714 ue->info->var->kind = VKYIELDPARAM;
2719 (FLG_ANNOTATIONERROR,
2720 message ("Qualifier %s used on non-iterator parameter: %q",
2721 qual_unparse (qel), uentry_unparse (ue)),
2722 uentry_whereLast (ue));
2725 else if (qual_isExQual (qel))
2727 exkind ek = exkind_fromQual (qel);
2728 ctype ut = uentry_getType (ue);
2730 DPRINTF (("Reflect ex qual: %s / %s",
2731 uentry_unparse (ue), exkind_unparse (ek)));
2733 if (ctype_isFunction (ut))
2735 ut = ctype_getReturnType (ut);
2738 if (!(ctype_isVisiblySharable (ut))
2739 && !(ctype_isArray (ut)) /* can apply to arrays also! */
2740 && !(ctype_isStruct (ctype_realType (ut)))) /* applies to structure fields! */
2742 if (!qual_isImplied (qel))
2744 if (ctype_isImmutableAbstract (ut)) {
2746 (FLG_REDUNDANTSHAREQUAL,
2747 message ("Qualifier %s used on unsharable storage type %t: %q",
2748 exkind_unparse (ek), ut, uentry_getName (ue)),
2749 uentry_whereLast (ue));
2752 (FLG_MISPLACEDSHAREQUAL,
2753 message ("Qualifier %s used on unsharable storage type %t: %q",
2754 exkind_unparse (ek), ut, uentry_getName (ue)),
2755 uentry_whereLast (ue));
2761 alkind ak = sRef_getAliasKind (ue->sref);
2763 sRef_setExKind (ue->sref, ek, uentry_whereDeclared (ue));
2764 DPRINTF (("Set exkind: %s", sRef_unparseFull (ue->sref)));
2766 if (alkind_isUnknown (ak) || alkind_isImplicit (ak) || alkind_isStatic (ak))
2768 if (!alkind_isTemp (ak))
2770 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
2771 uentry_setAliasKind (ue, AK_IMPDEPENDENT);
2774 else if (alkind_isDependent (ak) || alkind_isTemp (ak)
2775 || alkind_isOwned (ak))
2783 message ("Exposure qualifier %s used on %s storage (should "
2784 "be dependent): %q",
2786 alkind_unparse (ak),
2787 uentry_unparse (ue)));
2791 else if (qual_isGlobCheck (qel))
2793 if (uentry_isVariable (ue))
2795 chkind ch = chkind_fromQual (qel);
2797 if (ue->info->var->checked != CH_UNKNOWN)
2799 if (ch == ue->info->var->checked)
2801 llerror (FLG_SYNTAX,
2802 message ("Redundant %s qualifier on %q",
2804 uentry_getName (ue)));
2808 llerror (FLG_SYNTAX,
2810 ("Contradictory %s and %s qualifiers on %q",
2812 checkedName (ue->info->var->checked),
2813 uentry_getName (ue)));
2817 ue->info->var->checked = ch;
2823 message ("Qualifier %s used with non-variable",
2824 qual_unparse (qel)));
2827 else if (qual_isReturned (qel))
2829 if (uentry_isVariable (ue))
2831 ue->info->var->kind = VKRETPARAM;
2835 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-variable",
2836 qual_unparse (qel)));
2841 uentry_reflectOtherQualifier (ue, qel);
2844 sRef_storeState (ue->sref);
2845 } end_qualList_elements;
2849 DPRINTF (("Done: %s", sRef_unparseFull (ue->sref)));
2853 uentry_isOnly (uentry ue)
2855 return (!uentry_isUndefined (ue)
2856 && uentry_isVariable (ue)
2857 && alkind_isOnly (sRef_getOrigAliasKind (ue->sref)));
2861 uentry_setAliasKind (/*@notnull@*/ uentry ue, alkind ak)
2863 sRef_setAliasKind (ue->sref, ak, uentry_whereDeclared (ue));
2864 sRef_setOrigAliasKind (ue->sref, ak);
2868 uentry_setNullState (/*@notnull@*/ uentry ue, nstate ns)
2870 if (uentry_isVariable (ue))
2872 ue->info->var->nullstate = ns;
2875 sRef_setNullState (ue->sref, ns, uentry_whereDeclared (ue));
2879 uentry_isUnique (uentry ue)
2881 return (!uentry_isUndefined (ue)
2882 && uentry_isVariable (ue)
2883 && alkind_isUnique (sRef_getOrigAliasKind (ue->sref)));
2887 uentry_isFileStatic (uentry ue)
2889 return (uentry_isStatic (ue)
2890 && (!uentry_isVariable (ue)
2891 || sRef_isFileStatic (uentry_getSref (ue))));
2895 uentry_isExported (uentry ue)
2897 if (uentry_isValid (ue))
2899 if (uentry_isVariable (ue))
2901 return (sRef_isRealGlobal (uentry_getSref (ue)));
2905 return !uentry_isStatic (ue);
2913 uentry_isNonLocal (uentry ue)
2915 return (uentry_isValid (ue) && uentry_isVariable (ue)
2916 && (sRef_isFileOrGlobalScope (ue->sref) || uentry_isStatic (ue)));
2920 uentry_isGlobalVariable (uentry ue)
2922 return (uentry_isValid (ue) && uentry_isVariable (ue)
2923 && sRef_isFileOrGlobalScope (ue->sref));
2927 uentry_isVisibleExternally (uentry ue)
2929 return (uentry_isValid (ue)
2930 && ((uentry_isVariable (ue) && sRef_isRealGlobal (ue->sref))
2931 || (!uentry_isStatic (ue)
2932 && (uentry_isFunction (ue)
2933 || uentry_isIter (ue)
2934 || uentry_isEndIter (ue)
2935 || uentry_isConstant (ue)
2936 || uentry_isDatatype (ue)
2937 || uentry_isAnyTag (ue)))));
2941 uentry_isPrintfLike (uentry ue)
2943 return (uentry_isFunction (ue)
2944 && (ue->info->fcn->specialCode == SPC_PRINTFLIKE));
2948 uentry_isScanfLike (uentry ue)
2950 return (uentry_isFunction (ue)
2951 && (ue->info->fcn->specialCode == SPC_SCANFLIKE));
2955 uentry_isMessageLike (uentry ue)
2957 return (uentry_isFunction (ue)
2958 && (ue->info->fcn->specialCode == SPC_MESSAGELIKE));
2961 static void checkSpecialFunction (/*@notnull@*/ uentry ue)
2963 uentryList args = uentry_getParams (ue);
2965 if (!uentryList_isMissingParams (args))
2967 uentry last = uentry_undefined;
2969 uentryList_elements (args, current)
2971 if (uentry_isElipsisMarker (current))
2973 if (uentry_isUndefined (last))
2977 message ("Function %q is marked %s, but has no format "
2978 "string argument before elipsis",
2979 uentry_getName (ue),
2980 specCode_unparse (ue->info->fcn->specialCode)),
2981 uentry_whereLast (ue));
2982 ue->info->fcn->specialCode = SPC_NONE;
2986 ctype rt = ctype_realType (uentry_getType (last));
2988 if (!ctype_match (rt, ctype_string))
2992 /* wchar_t * is okay too */
2993 if (ctype_isAP (rt))
2995 ctype base = ctype_baseArrayPtr (rt);
2997 if (ctype_isArbitraryIntegral (base))
3007 message ("Function %q is marked %s, but the argument "
3008 "before the elipsis has type %s (should be char *)",
3009 uentry_getName (ue),
3010 specCode_unparse (ue->info->fcn->specialCode),
3011 ctype_unparse (uentry_getType (last))),
3012 uentry_whereLast (ue));
3014 ue->info->fcn->specialCode = SPC_NONE;
3021 } end_uentryList_elements ;
3025 message ("Function %q is marked %s, but has no elipsis parameter",
3026 uentry_getName (ue),
3027 specCode_unparse (ue->info->fcn->specialCode)),
3028 uentry_whereLast (ue));
3030 ue->info->fcn->specialCode = SPC_NONE;
3035 uentry_setPrintfLike (uentry ue)
3037 uentry_convertVarFunction (ue);
3038 llassertfatal (uentry_isFunction (ue));
3039 ue->info->fcn->specialCode = SPC_PRINTFLIKE;
3040 checkSpecialFunction (ue);
3044 uentry_setScanfLike (uentry ue)
3046 uentry_convertVarFunction (ue);
3047 llassertfatal (uentry_isFunction (ue));
3048 ue->info->fcn->specialCode = SPC_SCANFLIKE;
3049 checkSpecialFunction (ue);
3053 uentry_setMessageLike (uentry ue)
3055 uentry_convertVarFunction (ue);
3056 llassertfatal (uentry_isFunction (ue));
3057 ue->info->fcn->specialCode = SPC_MESSAGELIKE;
3058 checkSpecialFunction (ue);
3062 uentry_isSpecialFunction (uentry ue)
3064 return (uentry_isFunction (ue)
3065 && (ue->info->fcn->specialCode != SPC_NONE));
3068 /*@notnull@*/ uentry uentry_makeParam (idDecl t, int i)
3070 ctype ct = idDecl_getCtype (t);
3072 fileloc loc = setLocation ();
3073 sRef pref = sRef_makeParam (i, ct, stateInfo_makeLoc (loc, SA_CREATED));
3074 uentry ue = uentry_makeVariableSrefParam (idDecl_observeId (t), ct, loc, pref);
3076 DPRINTF (("Make param: %s", uentry_unparseFull (ue)));
3077 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3078 uentry_implicitParamAnnots (ue);
3080 /* Parameter type [][] or [x][] is invalid */
3082 while (ctype_isFixedArray (base)) {
3083 base = ctype_baseArrayPtr (base);
3086 if (ctype_isIncompleteArray (base)) {
3087 base = ctype_baseArrayPtr (base);
3089 if (ctype_isArray (base)) {
3090 if (!uentry_hasName (ue)) {
3091 (void) optgenerror (FLG_INCOMPLETETYPE,
3092 message ("Unnamed function parameter %d is incomplete type (inner array must have bounds): %s",
3094 ctype_unparse (ct)),
3095 uentry_whereLast (ue));
3097 (void) optgenerror (FLG_INCOMPLETETYPE,
3098 message ("Function parameter %q is incomplete type (inner array must have bounds): %s",
3099 uentry_getName (ue),
3100 ctype_unparse (ct)),
3101 uentry_whereLast (ue));
3106 DPRINTF (("Param: %s", uentry_unparseFull (ue)));
3110 /*@only@*/ /*@notnull@*/ uentry uentry_makeIdVariable (idDecl t)
3112 ctype ct = idDecl_getCtype (t);
3114 if (ctype_isFunction (ct))
3116 return (uentry_makeIdFunction (t));
3120 fileloc loc = setLocation ();
3121 uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
3123 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3125 if (!uentry_isExtern (ue))
3127 uentry_setDefined (ue, loc);
3134 /*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t, fileloc loc)
3136 return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), fileloc_copy (loc), SS_DEFINED));
3143 static /*@only@*/ /*@notnull@*/
3144 uentry uentry_makeConstantAux (cstring n, ctype t,
3145 /*@keep@*/ fileloc f, bool priv, bool macro,
3146 /*@only@*/ multiVal m)
3148 uentry e = uentry_alloc ();
3151 e->uname = cstring_copy (n);
3153 e->storageclass = SCNONE;
3155 e->warn = warnClause_undefined; /* Don't support warnings for constants */
3157 e->sref = sRef_makeConst (t);
3162 e->uses = filelocList_new ();
3163 e->isPrivate = priv;
3164 e->hasNameError = FALSE;
3166 e->info = (uinfo) dmalloc (sizeof (*e->info));
3167 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
3168 e->info->uconst->access = typeIdSet_undefined;
3169 e->info->uconst->macro = macro;
3171 uentry_setSpecDef (e, f);
3173 if (multiVal_isInt (m) && (multiVal_forceInt (m) == 0))
3175 sRef_setDefNull (e->sref, uentry_whereDeclared (e));
3178 uentry_setConstantValue (e, m);
3183 /*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
3185 uentry ue = uentry_makeConstantAux (n, t, f, FALSE, FALSE, multiVal_unknown ());
3189 /*@notnull@*/ uentry uentry_makeConstantValue (cstring n, ctype t, fileloc f, bool priv, multiVal val)
3191 uentry ue = uentry_makeConstantAux (n, t, f, priv, FALSE, val);
3195 /*@notnull@*/ uentry uentry_makeMacroConstant (cstring n, ctype t, fileloc f)
3197 uentry ue = uentry_makeConstantAux (n, t, f, FALSE, TRUE, multiVal_unknown ());
3201 /*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
3203 uentry ue = uentry_makeConstant (idDecl_observeId (t),
3204 idDecl_getCtype (t),
3207 llassert (fileloc_isUndefined (ue->whereDeclared));
3208 ue->whereDeclared = setLocation ();
3209 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3211 DPRINTF (("Constant: %s", uentry_unparseFull (ue)));
3212 DPRINTF (("Value: %s", multiVal_unparse (uentry_getConstantValue (ue))));
3220 void uentry_setDefState (uentry ue, sstate defstate)
3222 if (uentry_isValid (ue))
3224 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
3226 if (uentry_isVariable (ue))
3228 ue->info->var->defstate = defstate; /* evs 2000-05-17: fixed bug, was SS_DEFINED! */
3233 bool uentry_isCheckedUnknown (uentry ue)
3235 return (uentry_isVar (ue)
3236 && (ue->info->var->checked == CH_UNKNOWN));
3239 bool uentry_isCheckMod (uentry ue)
3241 return (uentry_isVar (ue)
3242 && (ue->info->var->checked == CH_CHECKMOD));
3245 bool uentry_isUnchecked (uentry ue)
3247 return (uentry_isVar (ue)
3248 && (ue->info->var->checked == CH_UNCHECKED));
3251 bool uentry_isChecked (uentry ue)
3253 return (uentry_isVar (ue)
3254 && (ue->info->var->checked == CH_CHECKED));
3257 bool uentry_isCheckedModify (uentry ue)
3259 return (uentry_isVar (ue)
3260 && (ue->info->var->checked == CH_CHECKED
3261 || ue->info->var->checked == CH_CHECKMOD
3262 || ue->info->var->checked == CH_CHECKEDSTRICT));
3265 bool uentry_isCheckedStrict (uentry ue)
3267 return (uentry_isVar (ue)
3268 && (ue->info->var->checked == CH_CHECKEDSTRICT));
3271 void uentry_setUnchecked (uentry ue)
3273 llassert (uentry_isVar (ue));
3275 ue->info->var->checked = CH_UNCHECKED;
3278 void uentry_setChecked (uentry ue)
3280 llassert (uentry_isVar (ue));
3282 ue->info->var->checked = CH_CHECKED;
3285 void uentry_setCheckMod (uentry ue)
3287 llassert (uentry_isVar (ue));
3289 ue->info->var->checked = CH_CHECKMOD;
3292 void uentry_setCheckedStrict (uentry ue)
3294 llassert (uentry_isVar (ue));
3296 ue->info->var->checked = CH_CHECKEDSTRICT;
3299 static /*@only@*/ /*@notnull@*/
3300 uentry uentry_makeVariableAux (cstring n, ctype t,
3302 /*@exposed@*/ sRef s,
3303 bool priv, vkind kind)
3305 uentry e = uentry_alloc ();
3308 DPRINTF (("Make variable: %s %s %s", n, ctype_unparse (t), sRef_unparse (s)));
3311 e->uname = cstring_copy (n);
3314 e->storageclass = SCNONE;
3316 e->warn = warnClause_undefined; /* Don't support warnings for variables yet @*/
3323 e->uses = filelocList_new ();
3324 e->isPrivate = priv;
3325 e->hasNameError = FALSE;
3327 e->info = (uinfo) dmalloc (sizeof (*e->info));
3328 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
3329 e->info->var->kind = kind;
3331 /* removed: e->info->var->origsref = sRef_saveCopy (e->sref); */
3332 e->info->var->checked = CH_UNKNOWN;
3334 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3335 uentry_setSpecDef (e, f);
3336 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3338 if (ctype_isFunction (rt))
3340 rt = ctype_getReturnType (rt);
3343 if (ctype_isUA (rt))
3345 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3346 sRef_setStateFromType (e->sref, rt);
3349 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3350 e->info->var->defstate = sRef_getDefState (e->sref);
3351 e->info->var->nullstate = sRef_getNullState (e->sref);
3353 /* start modifications */
3354 /* This function sets the uentry for a pointer or array variable declaration,
3355 it allocates memory and sets the fields. We check if the type of the variable
3356 is a pointer or array and allocate a `bbufinfo' struct accordingly */
3358 if (ctype_isArray (t) || ctype_isPointer(t))
3360 e->info->var->bufinfo = dmalloc (sizeof (*e->info->var->bufinfo));
3361 e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
3362 sRef_setNotNullTerminatedState (s);
3366 e->info->var->bufinfo = NULL;
3368 /* end modification */
3374 uentry_isYield (uentry ue)
3376 return (uentry_isVariable (ue)
3377 && (ue->info->var->kind == VKYIELDPARAM
3378 || ue->info->var->kind == VKREFYIELDPARAM));
3382 uentry_isRefsField (uentry ue)
3384 return (uentry_isVariable (ue) && sRef_isRefsField (ue->sref));
3387 /*@only@*/ /*@notnull@*/
3388 uentry uentry_makeVariable (cstring n, ctype t, fileloc f, bool isPriv)
3390 return (uentry_makeVariableAux (n, t, f, sRef_makeType (t), isPriv,
3391 fileloc_isSpec (f) ? VKSPEC : VKNORMAL));
3398 void uentry_makeVarFunction (uentry ue)
3405 llassert (uentry_isValid (ue));
3406 llassert (!sRef_modInFunction ());
3408 ak = sRef_getOrigAliasKind (ue->sref);
3409 ek = sRef_getOrigExKind (ue->sref);
3411 llassert (uentry_isVariable (ue));
3412 oldInfo = ue->info->var;
3414 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
3415 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ctype_realType (ue->utype)));
3418 ** expanded macro is marked used
3421 ue->used = ue->used || (oldInfo->kind == VKEXPMACRO);
3424 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3425 ue->info->fcn->exitCode = XK_UNKNOWN;
3426 ue->info->fcn->nullPred = qual_createUnknown ();
3427 ue->info->fcn->specialCode = SPC_NONE;
3428 ue->info->fcn->access = typeIdSet_undefined;
3429 ue->info->fcn->hasGlobs = FALSE;
3430 ue->info->fcn->globs = globSet_undefined;
3431 ue->info->fcn->hasMods = FALSE;
3432 ue->info->fcn->mods = sRefSet_undefined;
3433 ue->info->fcn->specclauses = NULL;
3434 ue->info->fcn->defparams = uentryList_undefined;
3437 ue->info->fcn->preconditions = functionConstraint_undefined;
3441 ue->info->fcn->postconditions = functionConstraint_undefined;
3444 if (ctype_isFunction (ue->utype))
3446 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3450 ue->sref = sRef_makeType (ctype_unknown);
3453 if (sRef_isRefCounted (ue->sref))
3459 if (alkind_isUnknown (ak))
3461 if (exkind_isKnown (ek))
3463 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3464 ak = AK_IMPDEPENDENT;
3468 if (context_getFlag (FLG_RETIMPONLY))
3470 if (ctype_isFunction (ue->utype)
3471 && ctype_isVisiblySharable
3472 (ctype_realType (ctype_getReturnType (ue->utype))))
3474 if (uentryList_hasReturned (uentry_getParams (ue)))
3480 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3495 loc = ue->whereDeclared;
3497 sRef_setAliasKind (ue->sref, ak, loc);
3498 sRef_setNullState (ue->sref, oldInfo->nullstate, loc);
3499 sRef_setDefState (ue->sref, oldInfo->defstate, loc);
3500 sRef_setExKind (ue->sref, ek, loc);
3502 if (oldInfo->kind == VKEXPMACRO)
3508 fileloc_free (ue->whereDefined);
3509 ue->whereDefined = fileloc_undefined;
3512 uvinfo_free (oldInfo);
3515 void uentry_makeConstantFunction (uentry ue)
3522 llassert (uentry_isValid (ue));
3523 llassert (!sRef_modInFunction ());
3525 ak = sRef_getOrigAliasKind (ue->sref);
3526 ek = sRef_getOrigExKind (ue->sref);
3528 llassert (uentry_isConstant (ue));
3529 oldInfo = ue->info->uconst;
3531 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
3534 ** expanded macro is marked used (until I write a pre-processor)
3538 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3539 ue->info->fcn->exitCode = XK_UNKNOWN;
3540 ue->info->fcn->nullPred = qual_createUnknown ();
3541 ue->info->fcn->specialCode = SPC_NONE;
3542 ue->info->fcn->access = typeIdSet_undefined;
3543 ue->info->fcn->hasGlobs = FALSE;
3544 ue->info->fcn->globs = globSet_undefined;
3545 ue->info->fcn->hasMods = FALSE;
3546 ue->info->fcn->mods = sRefSet_undefined;
3547 ue->info->fcn->specclauses = NULL;
3548 ue->info->fcn->defparams = uentryList_undefined;
3551 ue->info->fcn->preconditions = functionConstraint_undefined;
3555 ue->info->fcn->postconditions = functionConstraint_undefined;
3559 if (ctype_isFunction (ue->utype))
3561 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3565 ue->sref = sRef_makeType (ctype_unknown);
3568 if (sRef_isRefCounted (ue->sref))
3574 if (alkind_isUnknown (ak))
3576 if (exkind_isKnown (ek))
3578 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3579 ak = AK_IMPDEPENDENT;
3583 if (context_getFlag (FLG_RETIMPONLY))
3585 if (ctype_isFunction (ue->utype)
3586 && ctype_isVisiblySharable
3587 (ctype_realType (ctype_getReturnType (ue->utype))))
3589 if (uentryList_hasReturned (uentry_getParams (ue)))
3595 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3610 loc = ue->whereDeclared;
3612 sRef_setAliasKind (ue->sref, ak, loc);
3613 sRef_setExKind (ue->sref, ek, loc);
3615 fileloc_free (ue->whereDefined);
3616 ue->whereDefined = fileloc_undefined;
3617 ucinfo_free (oldInfo);
3621 uentry_setGlobals (uentry ue, /*@only@*/ globSet globs)
3623 llassert (uentry_isValid (ue));
3625 globSet_markImmutable (globs);
3627 if (uentry_isIter (ue))
3629 ue->info->iter->globs = globSet_unionFree (ue->info->iter->globs, globs);
3633 uentry_convertVarFunction (ue);
3634 llassert (uentry_isFunction (ue));
3636 ue->info->fcn->hasGlobs = TRUE;
3637 ue->info->fcn->globs = globSet_unionFree (ue->info->fcn->globs, globs);
3640 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3642 ue->info->fcn->hasMods = TRUE;
3646 void uentry_addAccessType (uentry ue, typeId tid)
3648 if (uentry_isFunction (ue))
3650 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3652 else if (uentry_isEitherConstant (ue))
3654 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3656 else if (uentry_isIter (ue))
3658 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3660 else if (uentry_isEndIter (ue))
3662 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3666 llbug (message ("no access for: %q", uentry_unparse (ue)));
3670 /*@only@*/ /*@notnull@*/ uentry
3671 uentry_makeFunction (cstring n, ctype t,
3673 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
3674 /*@only@*/ warnClause warn,
3677 llassert (warnClause_isUndefined (warn));
3678 return (uentry_makeFunctionAux (n, t,
3679 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3680 : typeIdSet_single (access)),
3686 /*@notnull@*/ uentry
3687 uentry_makePrivFunction2 (cstring n, ctype t,
3689 globSet globs, sRefSet mods,
3692 return (uentry_makeFunctionAux (n, t, access, globs, mods, warnClause_undefined,
3697 /*@notnull@*/ uentry
3698 uentry_makeSpecFunction (cstring n, ctype t,
3700 /*@only@*/ globSet globs,
3701 /*@only@*/ sRefSet mods,
3704 uentry ue = uentry_makeFunctionAux (n, t, access,
3705 globs, mods, warnClause_undefined,
3708 uentry_setHasGlobs (ue);
3709 uentry_setHasMods (ue);
3711 reflectImplicitFunctionQualifiers (ue, TRUE);
3715 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3717 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3718 sRef_undefined, FALSE, VKEXPMACRO);
3720 uentry_setDefined (ue, f);
3724 /*@notnull@*/ /*@notnull@*/ uentry
3725 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3727 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3728 typeIdSet_singleOpt (access),
3729 globSet_undefined, sRefSet_undefined,
3730 warnClause_undefined,
3734 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3738 bool uentry_isForward (uentry e)
3740 if (uentry_isValid (e))
3742 ctype ct = uentry_getType (e);
3744 return (ctype_isUnknown (ct)
3745 || (ctype_isFunction (ct)
3746 && ctype_isUnknown (ctype_getReturnType (ct))));
3752 /*@notnull@*/ uentry
3753 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3755 return (uentry_makeFunctionAux (n, ctype_unknown, access,
3756 globSet_undefined, sRefSet_undefined, warnClause_undefined,
3760 /*@notnull@*/ uentry
3761 uentry_makeUnspecFunction (cstring n, ctype t,
3765 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_undefined,
3766 sRefSet_undefined, warnClause_undefined,
3769 reflectImplicitFunctionQualifiers (ue, TRUE);
3777 /* is exported for use by usymtab_interface */
3779 /*@notnull@*/ uentry
3780 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, qual abstract,
3781 fileloc f, bool priv)
3783 uentry e = uentry_alloc ();
3785 DPRINTF (("Make datatype: %s / %s",
3786 n, ctype_unparse (t)));
3788 /* e->shallowCopy = FALSE; */
3789 e->ukind = KDATATYPE;
3790 e->uname = cstring_copy (n);
3792 e->storageclass = SCNONE;
3793 e->sref = sRef_makeUnknown ();
3797 sRef_setStateFromType (e->sref, t);
3800 uentry_setSpecDef (e, f);
3802 e->warn = warnClause_undefined;
3803 e->uses = filelocList_new ();
3804 e->isPrivate = priv;
3805 e->hasNameError = FALSE;
3810 e->info = (uinfo) dmalloc (sizeof (*e->info));
3811 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3812 e->info->datatype->abs = abstract;
3813 e->info->datatype->mut = mut;
3814 e->info->datatype->type = ctype_undefined;
3816 if (uentry_isDeclared (e))
3818 uentry_setDefined (e, f);
3821 if (qual_isAbstract (abstract) && !(uentry_isCodeDefined (e)))
3823 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3829 /*@notnull@*/ uentry
3830 uentry_makeDatatype (cstring n, ctype t, ynm mut, qual abstract, fileloc f)
3832 return (uentry_makeDatatypeAux (n, t, mut, abstract, f, FALSE));
3835 /*@notnull@*/ uentry uentry_makeBoolDatatype (qual abstract)
3837 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
3838 ctype_bool, NO, abstract,
3839 fileloc_getBuiltin (),
3842 ret->info->datatype->type = ctype_bool;
3850 static /*@only@*/ /*@notnull@*/ uentry
3851 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3852 /*@only@*/ fileloc f)
3854 uentry e = uentry_alloc ();
3857 e->uname = cstring_copy (n);
3859 e->sref = sRef_makeUnknown ();
3860 e->storageclass = SCNONE;
3864 uentry_setSpecDef (e, f);
3866 e->warn = warnClause_undefined;
3867 e->uses = filelocList_new ();
3868 e->isPrivate = FALSE;
3869 e->hasNameError = FALSE;
3871 e->info = (uinfo) dmalloc (sizeof (*e->info));
3872 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3873 e->info->iter->access = access;
3874 e->info->iter->mods = sRefSet_undefined;
3875 e->info->iter->globs = globSet_undefined;
3877 uentry_checkIterArgs (e);
3881 /*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3883 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3886 static /*@notnull@*/ uentry
3887 uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3889 uentry e = uentry_alloc ();
3891 /* e->shallowCopy = FALSE; */
3892 e->ukind = KENDITER;
3893 e->storageclass = SCNONE;
3894 e->uname = message ("end_%s", n);
3895 e->utype = ctype_unknown;
3896 e->sref = sRef_makeUnknown ();
3898 uentry_setSpecDef (e, f);
3903 e->uses = filelocList_new ();
3904 e->isPrivate = FALSE;
3905 e->hasNameError = FALSE;
3907 e->info = (uinfo) dmalloc (sizeof (*e->info));
3908 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3910 e->info->enditer->access = access;
3911 e->warn = warnClause_undefined;
3916 /*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3918 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3925 static /*@only@*/ /*@notnull@*/ uentry
3926 uentry_makeTagAux (cstring n, ctype t,
3927 /*@only@*/ fileloc fl,
3928 bool priv, ekind kind)
3930 uentry e = uentry_alloc ();
3932 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3934 llbuglit ("uentry_makeTagAux: not a tag type");
3938 /* e->shallowCopy = FALSE; */
3939 e->uname = cstring_copy (n);
3942 e->sref = sRef_makeUnknown ();
3943 e->storageclass = SCNONE;
3945 uentry_setSpecDef (e, fl);
3950 e->uses = filelocList_new ();
3951 e->isPrivate = priv;
3952 e->hasNameError = FALSE;
3954 e->info = (uinfo) dmalloc (sizeof (*e->info));
3955 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3956 e->info->datatype->abs = qual_createUnknown ();
3957 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3958 e->info->datatype->type = t;
3959 e->warn = warnClause_undefined;
3961 if (uentry_isDeclared (e))
3963 uentry_setDefined (e, fl);
3969 uentry uentry_makeStructTagLoc (cstring n, ctype t)
3971 cstring sname = makeStruct (n);
3972 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3974 cstring_free (sname);
3979 uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3981 cstring sname = makeStruct (n);
3982 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3984 cstring_free (sname);
3989 uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
3991 cstring uname = makeUnion (n);
3992 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
3994 cstring_free (uname);
3999 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
4001 cstring ename = makeEnum (n);
4002 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
4004 cstring_free (ename);
4009 uentry_makeUnionTagLoc (cstring n, ctype t)
4011 cstring uname = makeUnion (n);
4012 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
4014 cstring_free (uname);
4019 uentry_makeEnumTagLoc (cstring n, ctype t)
4021 cstring ename = makeEnum (n);
4022 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
4024 cstring_free (ename);
4029 uentry_isStructTag (uentry ue)
4031 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
4035 uentry_isUnionTag (uentry ue)
4037 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
4041 uentry_isEnumTag (uentry ue)
4043 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
4047 uentry_isAnyTag (uentry ue)
4049 return (uentry_isStructTag (ue)
4050 || uentry_isUnionTag (ue)
4051 || uentry_isEnumTag (ue));
4054 static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
4056 extern void uentry_destroyMod (void)
4057 /*@globals killed emarker@*/ /*@modifies emarker@*/
4059 static bool wasDestroyed = FALSE;
4061 llassert (!wasDestroyed);
4063 if (emarker != NULL)
4065 uentry_reallyFree (emarker);
4068 wasDestroyed = TRUE;
4072 uentry_makeElipsisMarker (void)
4074 if (emarker == NULL)
4076 emarker = uentry_alloc ();
4078 emarker->ukind = KELIPSMARKER;
4079 emarker->uname = cstring_makeLiteral ("...");
4080 emarker->utype = ctype_elipsMarker;
4081 emarker->sref = sRef_undefined;
4082 emarker->storageclass = SCNONE;
4083 emarker->used = FALSE;
4084 emarker->lset = FALSE;
4085 emarker->info = NULL;
4087 uentry_setSpecDef (emarker, fileloc_undefined);
4088 emarker->uses = filelocList_new ();
4089 emarker->isPrivate = FALSE;
4090 emarker->hasNameError = FALSE;
4093 /*@ignore@*/ return (emarker); /*@end@*/
4101 uentry_equiv (uentry p1, uentry p2)
4103 if (uentry_compare (p1, p2) != 0)
4114 uentry_xcomparealpha (uentry *p1, uentry *p2)
4118 if ((res = uentry_compare (*p1, *p2)) == 0) {
4119 if ((*p1 != NULL) && (*p2 != NULL)) {
4120 res = cstring_compare ((*p1)->uname,
4129 uentry_xcompareuses (uentry *p1, uentry *p2)
4134 if (uentry_isValid (u1))
4136 if (uentry_isValid (u2))
4138 return (-1 * int_compare (filelocList_size (u1->uses),
4139 filelocList_size (u2->uses)));
4148 if (uentry_isValid (u2))
4160 uentry_compareStrict (uentry v1, uentry v2)
4162 COMPARERETURN (uentry_compare (v1, v2));
4164 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
4166 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
4167 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
4168 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
4175 uentry_compare (uentry u1, uentry u2)
4177 if (u1 == u2) return 0;
4179 if (uentry_isInvalid (u1)) return -1;
4180 if (uentry_isInvalid (u2)) return 1;
4182 INTCOMPARERETURN (u1->ukind, u2->ukind);
4183 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
4184 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
4185 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
4191 /* bug detected by splint:
4192 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
4197 return (multiVal_compare (uentry_getConstantValue (u1),
4198 uentry_getConstantValue (u2)));
4202 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
4204 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
4205 uentry_accessType (u2)));
4206 return (uentryList_compareParams (uentry_getParams (u1),
4207 uentry_getParams (u2)));
4209 return (typeIdSet_compare (uentry_accessType (u1),
4210 uentry_accessType (u2)));
4213 ** Functions are never equivalent
4216 if (u1 - u2 < 0) /* evans 2001-08-21: was: ((int) u1 < (int) u2), changed to remove gcc warning */
4226 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
4227 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
4228 sRef_getOrigAliasKind (u2->sref)));
4229 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
4230 sRef_getOrigExKind (u2->sref)));
4231 COMPARERETURN (generic_compare (u1->info->var->checked,
4232 u2->info->var->checked));
4233 COMPARERETURN (generic_compare (u1->info->var->defstate,
4234 u2->info->var->defstate));
4235 return (generic_compare (u1->info->var->nullstate,
4236 u2->info->var->nullstate));
4238 COMPARERETURN (ctype_compare (u1->info->datatype->type,
4239 u2->info->datatype->type));
4240 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
4241 u2->info->datatype->mut));
4242 return (generic_compare (u1->info->datatype->abs, u2->info->datatype->abs));
4251 ** all entries are: <type>[@<info>]*#<name>
4253 ** info depends on kind:
4257 advanceField (char **s)
4259 reader_checkChar (s, '@');
4263 advanceName (char **s)
4265 reader_checkChar (s, '#');
4269 vkind_fromInt (int i)
4271 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
4273 llbuglit ("vkind_fromInt: out of range");
4280 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
4281 typeIdSet access, nstate nullstate,
4282 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
4284 uentry e = uentry_alloc ();
4289 e->sref = sRef_makeConst (ct);
4291 sRef_setNullState (e->sref, nullstate, loc);
4292 e->storageclass = SCNONE;
4294 if (fileloc_isSpec (loc))
4296 e->whereSpecified = loc;
4297 e->whereDeclared = fileloc_undefined;
4301 e->whereSpecified = fileloc_undefined;
4302 e->whereDeclared = loc;
4305 e->whereDefined = fileloc_undefined;
4306 e->uses = filelocList_new ();
4307 e->isPrivate = FALSE;
4308 e->hasNameError = FALSE;
4313 e->warn = warnClause_undefined;
4315 e->info = (uinfo) dmalloc (sizeof (*e->info));
4316 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
4317 e->info->uconst->access = access;
4318 e->info->uconst->macro = FALSE; /* fix this when macro info added to library */
4319 uentry_setConstantValue (e, m);
4320 sRef_storeState (e->sref);
4325 static /*@only@*/ uentry
4326 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
4327 sstate defstate, nstate isnull, alkind aliased,
4328 exkind exp, chkind checked,
4329 /*@only@*/ fileloc loc)
4331 uentry e = uentry_alloc ();
4336 e->storageclass = SCNONE;
4338 e->sref = sRef_makeType (ct);
4339 sRef_setNullState (e->sref, isnull, loc);
4341 e->whereDefined = fileloc_undefined;
4343 if (fileloc_isSpec (loc))
4345 e->whereSpecified = loc;
4346 e->whereDeclared = fileloc_undefined;
4350 e->whereSpecified = fileloc_undefined;
4351 e->whereDeclared = loc;
4354 e->isPrivate = FALSE;
4355 e->hasNameError = FALSE;
4360 e->uses = filelocList_new ();
4361 e->warn = warnClause_undefined;
4363 e->info = (uinfo) dmalloc (sizeof (*e->info));
4364 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
4365 e->info->var->kind = kind;
4366 e->info->var->checked = checked;
4367 e->info->var->defstate = defstate;
4369 sRef_setDefState (e->sref, defstate, loc);
4371 e->info->var->nullstate = sRef_getNullState (e->sref);
4373 sRef_setExKind (e->sref, exp, loc);
4374 sRef_setAliasKind (e->sref, aliased, loc);
4376 sRef_storeState (e->sref);
4378 /*DRL ADDED 9-1-2000 */
4379 e->info->var->bufinfo = NULL;
4384 static /*@only@*/ uentry
4385 uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, qual abstract,
4386 ynm mut, ctype rtype, alkind ak, exkind exp,
4387 sstate defstate, nstate isnull,
4388 /*@only@*/ fileloc loc)
4390 uentry e = uentry_alloc ();
4392 e->ukind = KDATATYPE;
4393 /* e->shallowCopy = FALSE; */
4396 e->storageclass = SCNONE;
4397 e->sref = sRef_makeUnknown ();
4398 DPRINTF (("Merge null 1: %s", sRef_unparseFull (e->sref)));
4401 ** This is only setting null state. (I think?)
4404 if (ctype_isUA (ct))
4406 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
4408 if (uentry_isValid (te))
4410 sRef_setStateFromUentry (e->sref, te);
4414 /* problem for recursive type definitions */
4418 sRef_setAliasKind (e->sref, ak, loc);
4419 sRef_setExKind (e->sref, exp, loc);
4421 sRef_setDefState (e->sref, defstate, loc);
4423 if (qual_isEitherAbstract (abstract) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
4425 isnull = NS_ABSNULL;
4428 DPRINTF (("Merge null: %s", sRef_unparseFull (e->sref)));
4429 sRef_mergeNullState (e->sref, isnull);
4431 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
4433 if (fileloc_isSpec (loc))
4435 e->whereSpecified = loc;
4436 e->whereDeclared = fileloc_undefined;
4440 e->whereSpecified = fileloc_undefined;
4441 e->whereDeclared = loc;
4444 e->isPrivate = FALSE;
4445 e->hasNameError = FALSE;
4446 e->warn = warnClause_undefined;
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;
4654 e->info = (uinfo) dmalloc (sizeof (*e->info));
4655 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4656 e->info->datatype->abs = qual_createUnknown ();
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;
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;
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 = qual_abstractFromCodeChar (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@%c@%s@%d@%d@%d@%d@%q#%s",
5164 ctype_dump (v->utype),
5165 qual_abstractCode (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 ("[%p] %s %s: %s [spec: %q; decl: %q; def: %q]",
5335 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 qual_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 && (qual_isUnknown (e->info->datatype->abs)));
5493 oldid = ctype_typeId (e->info->datatype->type);
5494 e->info->datatype->abs = qual_createAbstract ();
5495 e->info->datatype->type = ctype_createAbstract (oldid);
5499 uentry_setConcrete (uentry e)
5501 llassert (uentry_isDatatype (e)
5502 && (qual_isUnknown (e->info->datatype->abs)
5503 || qual_isConcrete (e->info->datatype->abs)));
5505 e->info->datatype->abs = qual_createConcrete ();
5509 uentry_isAbstractDatatype (uentry e)
5511 return (uentry_isDatatype (e)
5512 && (qual_isEitherAbstract (e->info->datatype->abs)));
5516 uentry_isMaybeAbstract (uentry e)
5518 return (uentry_isDatatype (e)
5519 && (!qual_isConcrete (e->info->datatype->abs)));
5523 uentry_isMutableDatatype (uentry e)
5525 if (uentry_isDatatype (e))
5527 if (ctype_isNumAbstract (e->info->datatype->type))
5533 return ynm_toBoolRelaxed (e->info->datatype->mut);
5541 uentry_isRefCountedDatatype (uentry e)
5543 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
5547 uentry_isParam (uentry u)
5549 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
5550 || u->info->var->kind == VKYIELDPARAM));
5554 uentry_isExpandedMacro (uentry u)
5556 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
5560 uentry_isSefParam (uentry u)
5562 return (uentry_isVariable (u)
5563 && (u->info->var->kind == VKSEFPARAM
5564 || u->info->var->kind == VKREFSEFPARAM
5565 || u->info->var->kind == VKSEFRETPARAM
5566 || u->info->var->kind == VKREFSEFRETPARAM));
5570 uentry_isRefParam (uentry u)
5572 return (uentry_isVariable (u)
5573 && (u->info->var->kind == VKREFPARAM
5574 || u->info->var->kind == VKREFYIELDPARAM
5575 || u->info->var->kind == VKREFSEFPARAM
5576 || u->info->var->kind == VKREFSEFRETPARAM));
5580 uentry_isAnyParam (uentry u)
5582 return (uentry_isVariable (u)
5583 && ((u->info->var->kind == VKPARAM)
5584 || (u->info->var->kind == VKSEFPARAM)
5585 || (u->info->var->kind == VKYIELDPARAM)
5586 || (u->info->var->kind == VKRETPARAM)
5587 || (u->info->var->kind == VKSEFRETPARAM)));
5591 uentry_getDefState (uentry u)
5593 if (uentry_isValid (u))
5595 return (sRef_getDefState (u->sref));
5599 return (SS_UNKNOWN);
5604 uentry_isOut (uentry u)
5606 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5607 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5611 uentry_isPartial (uentry u)
5613 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5614 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5618 uentry_isStateSpecial (uentry u)
5620 return ((uentry_isVariable (u)
5621 && (u->info->var->defstate == SS_SPECIAL))
5622 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5625 exitkind uentry_getExitCode (uentry ue)
5627 if (uentry_isFunction (ue))
5629 return ue->info->fcn->exitCode;
5637 qual uentry_nullPred (uentry u)
5639 llassert (uentry_isRealFunction (u));
5641 if (uentry_isFunction (u))
5643 return (u->info->fcn->nullPred);
5647 return qual_createUnknown ();
5652 ** Note for variables, this is checking the declared state, not the current state.
5656 uentry_possiblyNull (uentry u)
5658 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5659 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5663 uentry_getAliasKind (uentry u)
5665 if (uentry_isValid (u))
5667 return (sRef_getAliasKind (uentry_getSref (u)));
5676 uentry_getExpKind (uentry u)
5678 if (uentry_isValid (u))
5680 return (sRef_getExKind (uentry_getSref (u)));
5689 uentry_isIter (uentry e)
5691 return (!uentry_isUndefined (e) && e->ukind == KITER);
5695 uentry_isEndIter (uentry e)
5697 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5701 uentry_isRealFunction (uentry e)
5703 return (uentry_isFunction (e) ||
5704 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5708 uentry_hasName (uentry e)
5710 if (uentry_isValid (e))
5712 cstring s = e->uname;
5714 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")
5715 || uentry_isFakeTag (e)));
5724 ** Returns true for fake tags.
5725 ** This is used for dumping the library
5728 bool uentry_hasRealName (uentry e)
5730 return (uentry_isValid (e)
5731 && cstring_isNonEmpty (e->uname)
5732 && !uentry_isGlobalMarker (e));
5736 /*@observer@*/ globSet
5737 uentry_getGlobs (uentry l)
5739 if (uentry_isInvalid (l))
5741 return globSet_undefined;
5744 if (uentry_isFunction (l))
5746 return l->info->fcn->globs;
5748 else if (uentry_isIter (l))
5750 return l->info->iter->globs;
5752 else if (uentry_isEndIter (l))
5754 return globSet_undefined;
5758 if (l->ukind == KVAR)
5760 llcontbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
5762 ekind_unparse (l->ukind)));
5766 llcontbug (message ("Bad call to uentry_getGlobs: %q (%s)",
5768 ekind_unparse (l->ukind)));
5771 return globSet_undefined;
5776 /* Make Microsoft VC++ happy */
5777 # pragma warning (disable : 4715)
5780 /*@observer@*/ sRefSet
5781 uentry_getMods (uentry l)
5783 llassert (uentry_isValid (l));
5785 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5787 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5788 return sRefSet_undefined;
5791 if (uentry_isFunction (l))
5793 return l->info->fcn->mods;
5795 else if (uentry_isIter (l))
5797 return l->info->iter->mods;
5799 else if (uentry_isEndIter (l))
5801 return sRefSet_undefined;
5810 uentry_getKind (uentry e)
5812 llassert (uentry_isValid (e));
5816 /*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5818 llassert (uentry_isEitherConstant (e));
5819 return (sRef_getValue (e->sref));
5822 /*@observer@*/ uentryList
5823 uentry_getParams (uentry l)
5825 if (uentry_isInvalid (l)) return uentryList_undefined;
5832 ctype ct = l->utype;
5834 if (ctype_isFunction (ct))
5836 return (ctype_argsFunction (ct));
5840 return uentryList_undefined;
5845 ctype ct = l->utype;
5847 /*drl 12/10/2002 changed to fix bug involving multiple redefines of library functions in macros. Bug was reported by Malcolm Parsons
5849 Old code was simplly llassert (ctype_isFunction (ct) );
5852 llassert (ctype_isFunction (ct) || context_inMacro() );
5854 return (ctype_argsFunction (ct));
5861 /*@observer@*/ cstring
5862 uentry_rawName (uentry e)
5864 if (uentry_isValid (e))
5870 return cstring_undefined;
5875 uentry_getOptName (uentry e)
5877 cstring s = uentry_getName (e);
5879 if (cstring_isDefined (s))
5881 s = cstring_appendChar (s, ' ');
5888 uentry_getName (uentry e)
5890 cstring ret = cstring_undefined;
5892 if (uentry_isValid (e))
5894 if (uentry_isAnyTag (e))
5896 ret = fixTagName (e->uname);
5898 else if (uentry_isAnyParam (e))
5900 ret = cstring_copy (fixParamName (e->uname));
5904 ret = cstring_copy (e->uname);
5911 cstring uentry_observeRealName (uentry e)
5913 cstring ret = cstring_undefined;
5915 if (uentry_isValid (e))
5917 if (uentry_isAnyTag (e))
5919 if (isFakeTag (e->uname))
5921 ret = cstring_undefined;
5925 ret = plainTagName (e->uname);
5928 else if (uentry_isAnyParam (e))
5930 ret = fixParamName (e->uname);
5941 cstring uentry_getRealName (uentry e)
5943 if (uentry_isValid (e))
5945 if (uentry_isAnyTag (e))
5947 return (cstring_undefined);
5954 return cstring_undefined;
5957 ctype uentry_getType (uentry e)
5959 if (uentry_isValid (e))
5965 return ctype_unknown;
5969 fileloc uentry_whereLast (uentry e)
5973 if (uentry_isInvalid (e))
5975 return fileloc_undefined;
5978 loc = e->whereDefined;
5980 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5985 loc = uentry_whereDeclared (e);
5987 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5992 loc = uentry_whereSpecified (e);
5996 fileloc uentry_whereEither (uentry e)
5998 if (uentry_isInvalid (e)) return fileloc_undefined;
6000 if (fileloc_isDefined (e->whereDefined)
6001 && !fileloc_isExternal (e->whereDefined))
6003 return e->whereDefined;
6005 else if (fileloc_isDefined (e->whereDeclared))
6007 return e->whereDeclared;
6011 return e->whereSpecified;
6015 fileloc uentry_whereSpecified (uentry e)
6017 if (uentry_isInvalid (e)) return fileloc_undefined;
6019 return (e->whereSpecified);
6022 fileloc uentry_whereDefined (uentry e)
6024 if (uentry_isInvalid (e)) return fileloc_undefined;
6026 return (e->whereDefined);
6029 fileloc uentry_whereDeclared (uentry e)
6031 if (uentry_isInvalid (e)) return fileloc_undefined;
6033 return (e->whereDeclared);
6036 /*@observer@*/ fileloc
6037 uentry_whereEarliest (uentry e)
6039 if (uentry_isInvalid (e)) return fileloc_undefined;
6041 if (fileloc_isDefined (e->whereSpecified))
6043 return (e->whereSpecified);
6045 else if (fileloc_isDefined (e->whereDeclared))
6047 return (e->whereDeclared);
6051 return e->whereDefined;
6056 uentry_setFunctionDefined (uentry e, fileloc loc)
6058 if (uentry_isValid (e))
6060 llassert (uentry_isFunction (e));
6062 if (fileloc_isUndefined (e->whereDeclared))
6064 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
6067 if (!fileloc_isDefined (e->whereDefined))
6069 e->whereDefined = fileloc_update (e->whereDefined, loc);
6075 uentry_setDeclDef (uentry e, fileloc f)
6077 uentry_setDeclared (e, f);
6079 if (!uentry_isFunction (e)
6080 && !(uentry_isVariable (e) && uentry_isExtern (e)))
6082 uentry_setDefined (e, f);
6087 uentry_setDeclaredForce (uentry e, fileloc f)
6089 llassert (uentry_isValid (e));
6090 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6094 uentry_setDeclaredForceOnly (uentry e, fileloc f)
6096 llassert (uentry_isValid (e));
6097 fileloc_free (e->whereDeclared);
6098 e->whereDeclared = f;
6102 uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
6106 llassert (uentry_isValid (e));
6107 oldloc = e->whereDeclared;
6109 if (fileloc_isDefined (oldloc))
6111 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6113 e->whereDeclared = f;
6114 fileloc_free (oldloc);
6123 e->whereDeclared = f;
6124 fileloc_free (oldloc);
6129 uentry_setDeclared (uentry e, fileloc f)
6133 llassert (uentry_isValid (e));
6134 oldloc = e->whereDeclared;
6136 if (fileloc_isDefined (oldloc))
6138 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6140 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6149 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6154 uentry_clearDefined (uentry e)
6156 if (uentry_isValid (e))
6158 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
6163 uentry_setDefined (uentry e, fileloc f)
6167 llassert (uentry_isValid (e));
6168 oldloc = e->whereDefined;
6170 if (fileloc_isDefined (oldloc))
6172 if (fileloc_isLib (oldloc)
6173 || fileloc_isImport (oldloc)
6174 || fileloc_isBuiltin (oldloc)
6175 || fileloc_isPreproc (oldloc))
6177 e->whereDefined = fileloc_update (e->whereDefined, f);
6181 if (fileloc_equal (oldloc, f) || context_processingMacros ())
6187 if (optgenerror (FLG_REDEF,
6188 message ("%s %q redefined",
6189 ekind_capName (e->ukind),
6190 uentry_getName (e)),
6193 llgenindentmsg (message ("Previous definition of %q",
6194 uentry_getName (e)),
6202 e->whereDefined = fileloc_update (e->whereDefined, f);
6207 uentry_isCodeDefined (uentry e)
6209 llassert (uentry_isValid (e));
6211 return (fileloc_isDefined (e->whereDefined));
6215 uentry_isDeclared (uentry e)
6217 if (uentry_isValid (e))
6219 return (fileloc_isDefined (e->whereDeclared));
6225 sRef uentry_getSref (uentry e)
6227 /* not true, used for functions too (but shouldn't be? */
6228 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
6230 if (uentry_isInvalid (e)) return sRef_undefined;
6235 sRef uentry_getOrigSref (uentry e)
6237 /* evans 2003-04-12 - removed for now */
6238 /* evans 2001-09-09 - need to fix this
6239 if (uentry_isValid (e))
6241 if (uentry_isVariable (e))
6243 return e->info->var->origsref;
6247 sRef sr = sRef_copy (uentry_getSref (e));
6249 sRef_resetState (sr);
6250 sRef_clearDerived (sr);
6256 return sRef_undefined;
6260 if (uentry_isValid (e))
6262 sRef sr = sRef_copy (uentry_getSref (e));
6264 sRef_resetState (sr);
6265 sRef_clearDerived (sr);
6267 if (uentry_isVariable (e))
6269 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
6270 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
6277 return sRef_undefined;
6282 ** requires: uentry e is not in a hashed symbol table
6286 uentry_setName (uentry e, /*@only@*/ cstring n)
6288 llassert (uentry_isValid (e));
6290 cstring_free (e->uname);
6295 uentry_setType (uentry e, ctype t)
6297 if (uentry_isValid (e))
6300 sRef_setType (e->sref, t);
6305 uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
6308 ctype rettype = ctype_unknown;
6310 llassert (uentry_isValid (ue));
6312 uentry_convertVarFunction (ue);
6313 llassert (uentry_isFunction (ue));
6315 rct = ctype_realType (ue->utype);
6317 if (ctype_isFunction (rct))
6319 rettype = ctype_getReturnType (rct);
6322 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
6326 uentry_setRefParam (uentry e)
6328 if (!uentry_isVar (e))
6330 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6334 if (e->info->var->kind == VKSEFPARAM)
6336 e->info->var->kind = VKREFSEFPARAM;
6338 else if (e->info->var->kind == VKSEFRETPARAM)
6340 e->info->var->kind = VKREFSEFRETPARAM;
6342 else if (e->info->var->kind == VKYIELDPARAM)
6344 e->info->var->kind = VKREFYIELDPARAM;
6348 e->info->var->kind = VKREFPARAM;
6354 uentry_setParam (uentry e)
6356 if (!uentry_isVar (e))
6358 if (uentry_isElipsisMarker (e))
6364 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6371 if (e->info->var->kind == VKYIELDPARAM
6372 || e->info->var->kind == VKSEFPARAM
6373 || e->info->var->kind == VKSEFRETPARAM)
6379 e->info->var->kind = VKPARAM;
6383 e->uname = makeParam (e->uname);
6384 cstring_free (oldname);
6389 uentry_setSref (uentry e, sRef s)
6391 if (uentry_isValid (e))
6393 if (sRef_isValid (e->sref))
6395 sRef_mergeStateQuietReverse (e->sref, s);
6399 e->sref = sRef_saveCopy (s);
6405 uentry_getAbstractType (uentry e)
6407 llassert (uentry_isDatatype (e));
6410 ** This assertion removed.
6411 ** Okay to have undefined type, for system types
6413 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
6414 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
6419 if (ctype_isUndefined (e->info->datatype->type))
6421 return ctype_unknown;
6425 ** Sadly, a kludge...
6428 if (ctype_isUserBool (e->info->datatype->type)) {
6432 return e->info->datatype->type;
6435 ctype uentry_getRealType (uentry e)
6438 typeId uid = typeId_invalid;
6440 if (uentry_isInvalid (e))
6442 return ctype_unknown;
6445 if (!uentry_isDatatype (e))
6447 /* This shouldn't happen, except when types are redeclared in strange ways */
6448 return ctype_unknown;
6451 if (uentry_isAnyTag (e))
6456 if (uentry_isAbstractType (e))
6458 ct = uentry_getAbstractType (e);
6460 if (ctype_isManifestBool (ct)) {
6464 llassert (ctype_isUA (ct));
6466 uid = ctype_typeId (ct);
6468 if (!context_hasAccess (uid))
6474 ct = uentry_getType (e);
6476 /* if (ctype_isUserBool (ct)) return ct; */
6478 if (ctype_isManifestBool (ct)) {
6482 if (ctype_isUA (ct))
6484 typeId iid = ctype_typeId (ct);
6486 if (typeId_equal (iid, uid))
6488 llcontbug (message ("uentry_getRealType: recursive type! %s",
6489 ctype_unparse (ct)));
6494 /* evs 2000-07-25: possible infinite recursion ? */
6495 uentry ue2 = usymtab_getTypeEntry (iid);
6499 llcontbug (message ("Bad recursion: %q", uentry_unparseFull (e)));
6500 return ctype_unknown;
6503 return uentry_getRealType (ue2);
6512 ctype uentry_getForceRealType (uentry e)
6515 typeId uid = typeId_invalid;
6517 if (uentry_isInvalid (e))
6519 return ctype_unknown;
6522 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6524 if (uentry_isAnyTag (e))
6529 if (uentry_isAbstractType (e))
6531 ct = uentry_getAbstractType (e);
6532 llassert (ctype_isUA (ct));
6534 uid = ctype_typeId (ct);
6535 /* no check for access! */
6538 ct = uentry_getType (e);
6540 /* evs 2000-07-25 */
6541 /* if (ctype_isUserBool (ct)) return ct; */
6543 if (ctype_isManifestBool (ct)) {
6547 if (ctype_isUA (ct))
6549 typeId iid = ctype_typeId (ct);
6551 if (typeId_equal (iid, uid))
6553 llcontbug (message ("uentry_getRealType: recursive type! %s",
6554 ctype_unparse (ct)));
6559 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
6568 uentry uentry_nameCopy (cstring name, uentry e)
6570 uentry enew = uentry_alloc ();
6572 llassert (uentry_isValid (e));
6574 /* enew->shallowCopy = FALSE; */
6575 enew->ukind = e->ukind;
6577 enew->utype = e->utype;
6578 enew->whereSpecified = fileloc_copy (e->whereSpecified);
6579 enew->whereDefined = fileloc_copy (e->whereDefined);
6580 enew->whereDeclared = fileloc_copy (e->whereDeclared);
6581 enew->sref = sRef_copy (e->sref);
6582 enew->used = e->used;
6584 enew->isPrivate = e->isPrivate;
6585 enew->hasNameError = FALSE;
6587 enew->uses = filelocList_new ();
6588 enew->warn = warnClause_undefined;
6590 enew->storageclass = e->storageclass;
6591 enew->info = uinfo_copy (e->info, e->ukind);
6597 uentry_setDatatype (uentry e, typeId uid)
6599 llassert (uentry_isDatatype (e));
6601 if (uentry_isAbstractType (e))
6603 if (qual_isNumAbstract (e->info->datatype->abs))
6605 e->info->datatype->type = ctype_createNumAbstract (uid);
6609 llassert (qual_isAbstract (e->info->datatype->abs));
6610 e->info->datatype->type = ctype_createAbstract (uid);
6615 e->info->datatype->type = ctype_createUser (uid);
6620 uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
6621 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
6624 llassert (uentry_isValid (e));
6626 if (fileloc_isSpec (f) || fileloc_isImport (f))
6628 e->whereSpecified = f;
6629 e->whereDeclared = fileloc_undefined;
6630 e->whereDefined = fileloc_undefined;
6634 e->whereSpecified = fileloc_undefined;
6635 e->whereDeclared = f;
6636 e->whereDefined = fileloc_undefined;
6639 llassert (fileloc_storable (f));
6643 ucinfo_free (/*@only@*/ ucinfo u)
6649 uvinfo_free (/*@only@*/ uvinfo u)
6651 /*drl7x added 6/29/01 */
6652 free (u->bufinfo); /* evans - 2001-07-19 fixed this bug */
6657 udinfo_free (/*@only@*/ udinfo u)
6663 ufinfo_free (/*@only@*/ ufinfo u)
6665 globSet_free (u->globs);
6666 sRefSet_free (u->mods);
6667 stateClauseList_free (u->specclauses);
6672 uiinfo_free (/*@only@*/ uiinfo u)
6678 ueinfo_free (/*@only@*/ ueinfo u)
6683 static /*@only@*/ ucinfo
6684 ucinfo_copy (ucinfo u)
6686 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
6687 ret->access = u->access;
6688 ret->macro = u->macro;
6692 static /*@only@*/ uvinfo
6693 uvinfo_copy (uvinfo u)
6695 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
6697 ret->kind = u->kind;
6698 ret->nullstate = u->nullstate;
6699 ret->defstate = u->defstate;
6700 ret->checked = u->checked;
6703 /* drl added 07-02-001 */
6704 /* copy null terminated information */
6706 if (u->bufinfo != NULL)
6708 ret->bufinfo = (bbufinfo) dmalloc (sizeof( * u->bufinfo ) );
6709 ret->bufinfo->bufstate = u->bufinfo->bufstate;
6710 ret->bufinfo->size = u->bufinfo->size;
6711 ret->bufinfo->len = u->bufinfo->len;
6716 ret->bufinfo = NULL;
6722 static /*@only@*/ udinfo
6723 udinfo_copy (udinfo u)
6725 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6729 ret->type = u->type;
6734 static /*@only@*/ ufinfo
6735 ufinfo_copy (ufinfo u)
6737 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6739 ret->hasGlobs = u->hasGlobs;
6740 ret->hasMods = u->hasMods;
6741 ret->exitCode = u->exitCode;
6742 ret->specialCode = u->specialCode;
6743 ret->nullPred = u->nullPred;
6744 ret->access = u->access;
6745 ret->globs = globSet_newCopy (u->globs);
6746 ret->mods = sRefSet_newCopy (u->mods);
6747 ret->defparams = u->defparams;
6748 ret->specclauses = stateClauseList_copy (u->specclauses);
6750 ret->preconditions = functionConstraint_copy (u->preconditions);
6751 ret->postconditions = functionConstraint_copy (u->postconditions);
6756 static /*@only@*/ uiinfo
6757 uiinfo_copy (uiinfo u)
6759 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6761 ret->access = u->access;
6762 ret->globs = globSet_newCopy (u->globs);
6763 ret->mods = sRefSet_newCopy (u->mods);
6768 static /*@only@*/ ueinfo
6769 ueinfo_copy (ueinfo u)
6771 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6773 ret->access = u->access;
6778 uinfo_free (uinfo u, ekind kind)
6783 case KCONST: ucinfo_free (u->uconst); break;
6784 case KVAR: uvinfo_free (u->var); break;
6788 case KDATATYPE: udinfo_free (u->datatype); break;
6789 case KFCN: ufinfo_free (u->fcn); break;
6790 case KITER: uiinfo_free (u->iter); break;
6791 case KENDITER: ueinfo_free (u->enditer); break;
6792 case KELIPSMARKER: break;
6793 case KINVALID: break;
6799 static /*@only@*/ /*@null@*/ uinfo
6800 uinfo_copy (uinfo u, ekind kind)
6802 if (kind == KELIPSMARKER || kind == KINVALID)
6808 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6813 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6814 case KVAR: ret->var = uvinfo_copy (u->var); break;
6818 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6819 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6820 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6821 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6829 uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6831 filelocList_free (e->uses);
6832 cstring_free (e->uname);
6834 uinfo_free (e->info, e->ukind);
6836 fileloc_free (e->whereSpecified);
6837 fileloc_free (e->whereDefined);
6838 fileloc_free (e->whereDeclared);
6840 warnClause_free (e->warn);
6846 extern void uentry_markOwned (/*@owned@*/ uentry u)
6848 sfreeEventually (u);
6852 uentry_free (/*@only@*/ uentry e)
6854 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6856 uentry_reallyFree (e);
6861 ** For uentry's in the global or file scope
6865 uentry_freeComplete (/*@only@*/ uentry e)
6867 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6869 DPRINTF (("Free complete: %s", sRef_unparseFull (e->sref)));
6870 /*@i@*/ sRef_free (e->sref);
6871 e->sref = sRef_undefined;
6872 uentry_reallyFree (e);
6877 ** requires old->kind != new->kind, old->uname = new->uname
6881 KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6883 llassert (uentry_isValid (old));
6884 llassert (uentry_isValid (unew));
6886 if ((uentry_isEitherConstant (unew) || uentry_isDatatype (unew))
6887 && (fileloc_isPreproc (uentry_whereDeclared (old))
6888 || ctype_isUnknown (old->utype))
6889 && !uentry_isSpecified (old))
6897 if (!uentry_isDeclared (old))
6899 if (uentry_isSpecified (old))
6901 if (uentry_isSpecified (unew))
6903 llbuglit ("Respecification!");
6905 else if (uentry_isDeclared (unew))
6909 message ("%s %q inconsistently declared as %s: %t",
6910 ekind_capName (old->ukind),
6911 uentry_getName (unew),
6912 ekind_unparseLong (unew->ukind),
6914 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6916 uentry_showWhereLastKind (old);
6928 message ("%s %q inconsistently declared as %s: %t",
6929 ekind_capName (old->ukind),
6930 uentry_getName (unew),
6931 ekind_unparseLong (unew->ukind),
6933 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6935 uentry_showWhereLastKind (old);
6941 llassert (uentry_isDeclared (unew));
6943 DPRINTF (("Old: \n\t%s", uentry_unparseFull (old)));
6944 DPRINTF (("New: \n\t%s", uentry_unparseFull (unew)));
6948 message ("%s %q inconsistently redeclared as %s",
6949 ekind_capName (old->ukind),
6950 uentry_getName (unew),
6951 ekind_unparseLong (unew->ukind)),
6952 uentry_whereLast (unew))) /* evans 2001-12-30: was uentry_whereDeclared */
6954 uentry_showWhereLastKind (old);
6960 uentry_updateInto (old, unew);
6964 ** def is the definition of spec, modifies spec
6966 ** reports any inconsistencies
6967 ** returns the summary of all available information
6968 ** if spec and def are inconsistent, def is returned
6972 uentry_showWhereLast (uentry spec)
6974 if (uentry_isValid (spec))
6976 if (fileloc_isDefined (spec->whereDefined)
6977 && !fileloc_isLib (spec->whereDefined)
6978 /*!! && !fileloc_isPreproc (spec->whereDefined) */ )
6980 llgenindentmsg (message ("Previous definition of %q: %t",
6981 uentry_getName (spec),
6982 uentry_getType (spec)),
6983 uentry_whereDefined (spec));
6985 else if (uentry_isDeclared (spec))
6987 llgenindentmsg (message ("Previous declaration of %q: %t",
6988 uentry_getName (spec),
6989 uentry_getType (spec)),
6990 uentry_whereDeclared (spec));
6992 else if (uentry_isSpecified (spec))
6994 if (uentry_hasName (spec))
6996 llgenindentmsg (message ("Specification of %q: %t",
6997 uentry_getName (spec),
6998 uentry_getType (spec)),
6999 uentry_whereSpecified (spec));
7003 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
7004 uentry_whereSpecified (spec));
7009 /* nothing to show */
7015 uentry_showWhereLastKind (uentry spec)
7017 if (uentry_isValid (spec))
7019 if (fileloc_isDefined (spec->whereDefined)
7020 && !fileloc_isLib (spec->whereDefined)
7021 /*!! && !fileloc_isPreproc (spec->whereDefined) */ )
7023 llgenindentmsg (message ("Previous definition of %q as %s: %t",
7024 uentry_getName (spec),
7025 ekind_unparseLong (spec->ukind),
7026 uentry_getType (spec)),
7027 uentry_whereDefined (spec));
7029 else if (uentry_isDeclared (spec))
7031 llgenindentmsg (message ("Previous declaration of %q as %s: %t",
7032 uentry_getName (spec),
7033 ekind_unparseLong (spec->ukind),
7034 uentry_getType (spec)),
7035 uentry_whereDeclared (spec));
7037 else if (uentry_isSpecified (spec))
7039 if (uentry_hasName (spec))
7041 llgenindentmsg (message ("Specification of %q as %s: %t",
7042 uentry_getName (spec),
7043 ekind_unparseLong (spec->ukind),
7044 uentry_getType (spec)),
7045 uentry_whereSpecified (spec));
7049 llgenindentmsg (message ("Specification as %s: %t",
7050 ekind_unparseLong (spec->ukind),
7051 uentry_getType (spec)),
7052 uentry_whereSpecified (spec));
7057 /* nothing to show */
7063 uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
7065 fileloc loc = uentry_whereDefined (ce);
7067 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
7069 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
7073 loc = uentry_whereSpecified (ce);
7075 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
7077 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
7082 void uentry_showWhereLastExtra (uentry spec, cstring extra)
7084 if (uentry_isDeclared (spec))
7086 llgenindentmsg (message ("Previous declaration of %q: %q",
7087 uentry_getName (spec), extra),
7088 uentry_whereDeclared (spec));
7090 else if (uentry_isSpecified (spec))
7092 llgenindentmsg (message ("Specification of %q: %q",
7093 uentry_getName (spec), extra),
7094 uentry_whereSpecified (spec));
7098 cstring_free (extra);
7103 uentry_showWhereDeclared (uentry spec)
7105 if (uentry_isDeclared (spec))
7107 if (uentry_hasName (spec))
7109 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7110 uentry_whereDeclared (spec));
7114 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
7117 else if (uentry_isSpecified (spec))
7119 if (uentry_hasName (spec))
7121 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7122 uentry_whereSpecified (spec));
7126 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
7131 /* nothing to show */
7137 uentry_showWhereAny (uentry spec)
7139 if (uentry_isDeclared (spec))
7141 if (uentry_hasName (spec))
7143 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7144 uentry_whereDeclared (spec));
7148 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
7151 else if (uentry_isSpecified (spec))
7153 if (uentry_hasName (spec))
7155 llgenindentmsg (message ("Specification of %q",
7156 uentry_getName (spec)),
7157 uentry_whereSpecified (spec));
7161 llgenindentmsg (cstring_makeLiteral ("Specification"),
7162 uentry_whereSpecified (spec));
7165 else if (fileloc_isDefined (uentry_whereDefined (spec)))
7167 if (uentry_hasName (spec))
7169 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
7170 uentry_whereDefined (spec));
7174 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
7179 /* nothing to show */
7184 uentry_showWhereDefined (uentry spec)
7186 if (uentry_isCodeDefined (spec))
7188 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
7189 uentry_whereDefined (spec));
7194 uentry_showWhereLastPlain (uentry spec)
7196 if (uentry_isDeclared (spec))
7198 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
7199 uentry_whereDeclared (spec));
7201 else if (uentry_isSpecified (spec))
7203 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7204 uentry_whereSpecified (spec));
7212 uentry_showWhereLastVal (uentry spec, cstring val)
7214 if (uentry_isDeclared (spec))
7216 llgenindentmsg (message ("Previous declaration of %q: %s",
7217 uentry_getName (spec), val),
7218 uentry_whereDeclared (spec));
7220 else if (uentry_isSpecified (spec))
7222 llgenindentmsg (message ("Specification of %q: %s",
7223 uentry_getName (spec), val),
7224 uentry_whereSpecified (spec));
7232 uentry_showWhereSpecified (uentry spec)
7234 if (uentry_isSpecified (spec))
7236 if (uentry_hasName (spec))
7238 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7239 uentry_whereSpecified (spec));
7243 llgenindentmsg (cstring_makeLiteral ("Specification"),
7244 uentry_whereSpecified (spec));
7247 else if (uentry_isDeclared (spec))
7249 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7250 uentry_whereDeclared (spec));
7254 /* nothing to show */
7259 uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
7261 if (uentry_isSpecified (spec))
7263 if (uentry_hasName (spec))
7265 llgenindentmsg (message ("Specification of %q: %q",
7266 uentry_getName (spec), s),
7267 uentry_whereSpecified (spec));
7271 llgenindentmsg (message ("Specification: %q", s),
7272 uentry_whereSpecified (spec));
7275 else if (uentry_isDeclared (spec))
7277 llgenindentmsg (message ("Declaration of %q: %q",
7278 uentry_getName (spec), s),
7279 uentry_whereDeclared (spec));
7283 llgenindentmsg (message ("Previous: %q", s),
7284 uentry_whereLast (spec));
7293 checkStructConformance (uentry old, uentry unew)
7296 uentryList fold, fnew;
7299 ** requires: types of old and new are structs or unions
7302 llassert (uentry_isValid (old));
7303 llassert (uentry_isValid (unew));
7305 oldr = ctype_realType (old->utype);
7306 fold = ctype_getFields (oldr);
7308 newr = ctype_realType (unew->utype);
7309 fnew = ctype_getFields (newr);
7311 if (!uentryList_matchFields (fold, fnew))
7313 if (fileloc_equal (uentry_whereLast (old),
7314 uentry_whereLast (unew)))
7322 message ("%q %q %rdeclared with fields { %q }, %s "
7323 "with fields { %q }",
7324 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
7325 uentry_getName (old),
7326 uentry_isDeclared (old),
7327 uentryList_unparseAbbrev (fnew),
7328 uentry_specOrDefName (old),
7329 uentryList_unparseAbbrev (fold)),
7330 uentry_whereDeclared (unew)))
7332 uentry_showWhereLastPlain (old);
7333 uentryList_showFieldDifference (fold, fnew);
7337 old->utype = unew->utype;
7342 checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7345 ** requires old and new are enums
7348 ctype rold = ctype_realType (old->utype);
7349 ctype rnew = ctype_realType (unew->utype);
7350 enumNameList eold = ctype_elist (rold);
7351 enumNameList enew = ctype_elist (rnew);
7353 if (!enumNameList_match (eold, enew))
7357 message ("Enum %q declared with members { %q } but "
7358 "%s with members { %q }",
7359 uentry_getName (old),
7360 enumNameList_unparse (enew),
7361 uentry_specOrDefName (old),
7362 enumNameList_unparse (eold)),
7363 uentry_whereDeclared (unew)))
7365 uentry_showWhereSpecified (old);
7366 old->utype = unew->utype;
7372 ** either oldCurrent or newCurrent may be undefined!
7376 paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
7377 uentry unew, uentry newCurrent, ctype newType,
7380 bool hasError = FALSE;
7382 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
7384 if (uentry_hasName (newCurrent))
7386 hasError = optgenerror
7388 message ("Parameter %d, %q, of function %q has inconsistent type: "
7389 "declared %t, %s %t",
7390 paramno + 1, uentry_getName (newCurrent),
7391 uentry_getName (unew),
7392 newType, uentry_specOrDefName (old), oldType),
7393 uentry_whereDeclared (newCurrent));
7397 hasError = optgenerror
7399 message ("Parameter %d of function %q has inconsistent type: "
7400 "declared %t, %s %t",
7401 paramno + 1, uentry_getName (unew),
7402 newType, uentry_specOrDefName (old), oldType),
7403 uentry_whereDeclared (newCurrent));
7405 DPRINTF (("type: %s / %s",
7406 ctype_unparse (newType),
7407 ctype_unparse (ctype_realType (newType))));
7412 if (uentry_isDeclared (unew))
7414 hasError = optgenerror
7416 message ("Parameter %d of function %s has inconsistent type: "
7417 "declared %t, %s %t",
7418 paramno + 1, unew->uname,
7419 newType, uentry_specOrDefName (old), oldType),
7420 uentry_whereDeclared (unew));
7424 hasError = optgenerror
7426 message ("Parameter %d of function %s has inconsistent type: "
7427 "declared %t, %s %t",
7428 paramno + 1, unew->uname,
7429 newType, uentry_specOrDefName (old), oldType),
7430 uentry_whereDeclared (unew));
7436 DPRINTF (("Here: %s / %s",
7437 uentry_unparseFull (oldCurrent),
7438 uentry_unparseFull (newCurrent)));
7440 if (!uentry_isUndefined (oldCurrent))
7442 if (!uentry_isUndefined (newCurrent)
7443 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
7445 uentry_showWhereLast (oldCurrent);
7449 uentry_showWhereLastPlain (old);
7452 uentry_setType (oldCurrent, newType);
7456 uentry_showWhereLastPlain (old);
7462 nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7466 message ("Function %s %rdeclared with %d arg%&, %s with %d",
7468 uentry_isDeclared (old),
7469 uentryList_size (uentry_getParams (unew)),
7470 uentry_specOrDefName (old),
7471 uentryList_size (uentry_getParams (old))),
7472 uentry_whereDeclared (unew)))
7474 uentry_showWhereLastPlain (old);
7479 returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7483 message ("Function %s inconsistently %rdeclared to return %t",
7485 uentry_isDeclared (old),
7486 ctype_getReturnType (unew->utype)),
7487 uentry_whereDeclared (unew)))
7489 uentry_showWhereLastVal (old, ctype_unparse (ctype_getReturnType (old->utype)));
7493 static cstring paramStorageName (uentry ue)
7495 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
7498 static cstring fcnErrName (uentry ue)
7500 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
7503 extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
7505 if (uentry_isVar (ue))
7507 return (checkedName (ue->info->var->checked));
7511 return (cstring_makeLiteralTemp ("<checked invalid>"));
7515 static cstring checkedName (chkind checked)
7519 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
7520 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
7521 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
7522 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
7523 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
7529 void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
7534 if (uentry_isVar (unew))
7536 llassert (uentry_isVar (old));
7538 oldState = old->info->var->nullstate;
7539 newState = unew->info->var->nullstate;
7543 oldState = sRef_getNullState (old->sref);
7544 newState = sRef_getNullState (unew->sref);
7547 if (oldState == NS_ABSNULL)
7549 if (uentry_isVar (old))
7551 old->info->var->nullstate = newState;
7554 sRef_mergeNullState (old->sref, newState);
7556 else if (newState == NS_UNKNOWN)
7558 if (completeConform && newState != oldState
7559 && uentry_isReallySpecified (old))
7563 message ("%s %q specified as %s, but declared without %s qualifier",
7564 ekind_capName (unew->ukind),
7565 uentry_getName (unew),
7566 nstate_unparse (oldState),
7567 nstate_unparse (oldState)),
7568 uentry_whereDeclared (unew)))
7570 uentry_showWhereSpecified (old);
7574 if (uentry_isVar (unew))
7576 unew->info->var->nullstate = oldState;
7579 sRef_mergeNullState (unew->sref, oldState);
7581 else if (newState == NS_POSNULL)
7583 if (oldState == NS_MNOTNULL
7584 && (ctype_isUA (unew->utype)
7585 || (uentry_isFunction (unew)
7586 && ctype_isUA (ctype_getReturnType (unew->utype)))))
7588 if (uentry_isVar (unew))
7590 unew->info->var->nullstate = oldState;
7593 sRef_mergeNullState (unew->sref, oldState);
7597 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
7598 || oldState == NS_UNKNOWN)
7605 ("%s %q inconsistently %rdeclared %s possibly null storage, "
7607 uentry_ekindName (unew),
7608 uentry_getName (unew),
7609 uentry_isDeclared (old),
7611 uentry_specOrDefName (old),
7612 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
7613 uentry_whereDeclared (unew)))
7615 uentry_showWhereSpecified (old);
7620 if (uentry_isVar (old))
7622 old->info->var->nullstate = newState;
7625 sRef_mergeNullState (old->sref, newState);
7628 else if (newState == NS_MNOTNULL)
7630 if (oldState != NS_MNOTNULL)
7636 message ("%s %q inconsistently %rdeclared %s notnull storage, "
7637 "%s without notnull qualifier",
7638 uentry_ekindName (unew),
7639 uentry_getName (unew),
7640 uentry_isDeclared (old),
7642 uentry_specOrDefName (old)),
7643 uentry_whereDeclared (unew)))
7645 uentry_showWhereSpecified (old);
7649 if (uentry_isVar (old))
7651 old->info->var->nullstate = newState;
7654 sRef_mergeNullState (old->sref, newState);
7659 if (uentry_isVar (unew))
7661 unew->info->var->nullstate = oldState;
7664 sRef_mergeNullState (unew->sref, oldState);
7669 void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7670 bool mustConform, bool completeConform)
7676 if (uentry_isVar (old) && uentry_isVar (unew))
7678 oldState = old->info->var->defstate;
7679 newState = unew->info->var->defstate;
7684 oldState = sRef_getDefState (old->sref);
7685 newState = sRef_getDefState (unew->sref);
7688 if (newState != oldState
7689 && newState != SS_UNKNOWN
7690 && newState != SS_DEFINED)
7696 message ("%s %q inconsistently %rdeclared %s %s %s, "
7698 uentry_ekindName (unew),
7699 uentry_getName (unew),
7700 uentry_isDeclared (old),
7702 sstate_unparse (newState),
7703 paramStorageName (unew),
7704 uentry_specOrDefName (old),
7706 sstate_unparse (oldState),
7707 paramStorageName (unew)),
7708 uentry_whereDeclared (unew)))
7710 uentry_showWhereSpecified (old);
7714 if (vars) old->info->var->defstate = newState;
7715 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
7720 && (newState != oldState) && (oldState != SS_DEFINED)
7721 && uentry_isReallySpecified (old))
7725 message ("%s %q specified as %s, but declared without %s qualifier",
7726 ekind_capName (unew->ukind),
7727 uentry_getName (unew),
7728 sstate_unparse (oldState),
7729 sstate_unparse (oldState)),
7730 uentry_whereDeclared (unew)))
7732 uentry_showWhereSpecified (old);
7736 if (vars) unew->info->var->defstate = oldState;
7737 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
7742 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7743 bool mustConform, bool completeConform)
7748 oldKind = sRef_getAliasKind (old->sref);
7749 newKind = sRef_getAliasKind (unew->sref);
7751 if (alkind_isImplicit (newKind)
7752 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
7754 if (completeConform && !alkind_equal (newKind, oldKind)
7755 && uentry_isReallySpecified (old))
7759 message ("%s %q specified as %s, but declared without "
7760 "explicit alias qualifier",
7761 ekind_capName (unew->ukind),
7762 uentry_getName (unew),
7763 alkind_unparse (oldKind)),
7764 uentry_whereDeclared (unew)))
7766 uentry_showWhereSpecified (old);
7771 ** This really shouldn't be necessary, but it is!
7772 ** Function params (?) use new here.
7775 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7779 if (alkind_isKnown (newKind))
7781 if (!alkind_equal (oldKind, newKind))
7783 if (alkind_isKnown (oldKind))
7788 message ("%s %q inconsistently %rdeclared %s %s storage, "
7790 uentry_ekindName (unew),
7791 uentry_getName (unew),
7792 uentry_isDeclared (old),
7794 alkind_unparse (newKind),
7795 uentry_specOrDefName (old),
7796 alkind_unparse (oldKind)),
7797 uentry_whereDeclared (unew)))
7799 uentry_showWhereSpecified (old);
7801 DPRINTF (("Old: %s", sRef_unparseFull (old->sref)));
7802 DPRINTF (("New: %s", sRef_unparseFull (unew->sref)));
7803 sRef_setAliasKind (old->sref, AK_ERROR,
7804 uentry_whereDeclared (unew));
7808 sRef_setAliasKind (old->sref, newKind,
7809 uentry_whereDeclared (unew));
7814 if (!(alkind_isImplicit (newKind)))
7817 !uentry_isFunction (unew) &&
7820 message ("%s %q inconsistently %rdeclared %s %s storage, "
7821 "implicitly %s as temp storage",
7822 uentry_ekindName (unew),
7823 uentry_getName (unew),
7824 uentry_isDeclared (old),
7826 alkind_unparse (newKind),
7827 uentry_specOrDefName (old)),
7828 uentry_whereDeclared (unew)))
7830 uentry_showWhereSpecified (old);
7834 sRef_setAliasKind (old->sref, newKind,
7835 uentry_whereDeclared (unew));
7837 else /* newKind is temp or refcounted */
7844 else /* newKind unknown */
7851 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7852 bool mustConform, bool completeConform)
7857 oldKind = sRef_getExKind (old->sref);
7858 newKind = sRef_getExKind (unew->sref);
7860 if (exkind_isKnown (newKind))
7862 if (oldKind != newKind)
7864 if (exkind_isKnown (oldKind))
7869 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7870 uentry_ekindName (unew),
7871 uentry_getName (unew),
7872 uentry_isDeclared (old),
7874 exkind_unparse (newKind),
7875 uentry_specOrDefName (old),
7876 exkind_unparse (oldKind)),
7877 uentry_whereDeclared (unew)))
7879 uentry_showWhereSpecified (old);
7882 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7889 message ("%s %q inconsistently %rdeclared %s %s, "
7890 "implicitly %s without exposure qualifier",
7891 uentry_ekindName (unew),
7892 uentry_getName (unew),
7893 uentry_isDeclared (old),
7895 exkind_unparse (newKind),
7896 uentry_specOrDefName (old)),
7897 uentry_whereDeclared (unew)))
7899 uentry_showWhereSpecified (old);
7902 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7908 if (completeConform && exkind_isKnown (oldKind)
7909 && uentry_isReallySpecified (old))
7913 message ("%s %q specified as %s, but declared without "
7914 "exposure qualifier",
7915 ekind_capName (unew->ukind),
7916 uentry_getName (unew),
7917 exkind_unparse (oldKind)),
7918 uentry_whereDeclared (unew)))
7920 uentry_showWhereSpecified (old);
7924 /* yes, this is necessary! (if its a param) */
7925 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7930 checkMetaState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7931 bool mustConform, /*@unused@*/ bool completeConform)
7933 valueTable newvals = sRef_getValueTable (unew->sref);
7935 if (valueTable_isDefined (newvals))
7937 DPRINTF (("Check meta state: %s -> %s",
7938 uentry_unparseFull (old),
7939 uentry_unparseFull (unew)));
7941 DPRINTF (("Check meta state refs: %s -> %s",
7942 sRef_unparseFull (old->sref),
7943 sRef_unparseFull (unew->sref)));
7945 DPRINTF (("Value table: %s", valueTable_unparse (newvals)));
7948 ** Copy the new values into the old ref
7951 valueTable_elements (newvals, key, newval)
7953 metaStateInfo msinfo = context_lookupMetaStateInfo (key);
7954 stateValue oldval = sRef_getMetaStateValue (old->sref, key);
7956 llassert (metaStateInfo_isDefined (msinfo));
7958 if (stateValue_isUndefined (oldval))
7960 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7964 if (stateValue_isError (oldval))
7966 if (!stateValue_isError (newval))
7968 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7972 ; /* No change necessary. */
7977 if (stateValue_getValue (newval) != stateValue_getValue (oldval))
7979 if (fileloc_isXHFile (uentry_whereDeclared (unew)))
7985 if (!stateValue_isError (newval)
7986 && !stateValue_isImplicit (newval))
7988 if (uentry_hasName (unew)
7989 || !sRef_isParam (uentry_getSref (unew)))
7994 message ("%s %q inconsistently %rdeclared %s %q, %s as %q",
7995 uentry_ekindName (unew),
7996 uentry_getName (unew),
7997 uentry_isDeclared (old),
7999 stateValue_unparseValue (newval, msinfo),
8000 uentry_specOrDefName (old),
8001 stateValue_unparseValue (oldval, msinfo)),
8002 uentry_whereDeclared (unew)))
8004 uentry_showWhereSpecified (old);
8012 message ("%s %d inconsistently %rdeclared %s %q, %s as %q",
8013 uentry_ekindName (unew),
8014 sRef_getParam (uentry_getSref (unew)),
8015 uentry_isDeclared (old),
8017 stateValue_unparseValue (newval, msinfo),
8018 uentry_specOrDefName (old),
8019 stateValue_unparseValue (oldval, msinfo)),
8020 uentry_whereDeclared (unew)))
8022 uentry_showWhereSpecified (old);
8028 DPRINTF (("Updating!"));
8029 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
8033 DPRINTF (("Values match"));
8037 } end_valueTable_elements ;
8042 uentry_checkStateConformance (/*@notnull@*/ uentry old,
8043 /*@notnull@*/ uentry unew,
8044 bool mustConform, bool completeConform)
8046 checkDefState (old, unew, mustConform, completeConform);
8047 checkNullState (old, unew, mustConform, completeConform);
8048 checkAliasState (old, unew, mustConform, completeConform);
8049 checkExpState (old, unew, mustConform, completeConform);
8050 checkMetaState (old, unew, mustConform, completeConform);
8052 sRef_storeState (old->sref);
8053 sRef_storeState (unew->sref);
8057 checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
8059 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
8064 llassert (uentry_isVar (old));
8065 llassert (uentry_isVar (unew));
8067 if (cstring_isEmpty (old->uname))
8069 cstring_free (old->uname);
8070 old->uname = cstring_copy (unew->uname);
8073 if (unew->info->var->kind == VKRETPARAM
8074 || unew->info->var->kind == VKSEFRETPARAM)
8076 if (old->info->var->kind != VKRETPARAM
8077 && old->info->var->kind != VKSEFRETPARAM)
8081 message ("Parameter %q inconsistently %rdeclared as "
8082 "returned parameter",
8083 uentry_getName (unew),
8084 uentry_isDeclared (old)),
8085 uentry_whereDeclared (unew)))
8087 uentry_showWhereSpecified (old);
8088 old->info->var->kind = unew->info->var->kind;
8094 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
8096 if (old->info->var->kind != VKSEFPARAM
8097 && old->info->var->kind != VKSEFRETPARAM)
8101 message ("Parameter %qinconsistently %rdeclared as "
8103 uentry_getOptName (unew),
8104 uentry_isDeclared (old)),
8105 uentry_whereDeclared (unew)))
8107 uentry_showWhereSpecified (old);
8108 old->info->var->kind = unew->info->var->kind;
8113 if (old->info->var->kind == VKSPEC)
8115 old->info->var->kind = unew->info->var->kind;
8119 unew->info->var->kind = old->info->var->kind;
8122 if (unew->info->var->checked != CH_UNKNOWN
8123 && unew->info->var->checked != old->info->var->checked)
8125 if (old->info->var->checked == CH_UNKNOWN
8126 && !fileloc_isUser (uentry_whereLast (old)))
8134 message ("Variable %q inconsistently %rdeclared as "
8135 "%s parameter (was %s)",
8136 uentry_getName (unew),
8137 uentry_isDeclared (old),
8138 checkedName (unew->info->var->checked),
8139 checkedName (old->info->var->checked)),
8140 uentry_whereDeclared (unew)))
8142 uentry_showWhereSpecified (old);
8146 old->info->var->checked = unew->info->var->checked;
8151 && (old->info->var->checked != CH_UNKNOWN)
8152 && uentry_isReallySpecified (old))
8156 message ("%s %q specified as %s, but declared without %s qualifier",
8157 ekind_capName (unew->ukind),
8158 uentry_getName (unew),
8159 checkedName (old->info->var->checked),
8160 checkedName (old->info->var->checked)),
8161 uentry_whereDeclared (unew)))
8163 uentry_showWhereSpecified (old);
8167 unew->info->var->checked = old->info->var->checked;
8170 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8173 void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
8175 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
8180 llassert (uentry_isVar (u1));
8181 llassert (uentry_isVar (u2));
8183 if (u1->info->var->kind != u2->info->var->kind) {
8184 if (u1->info->var->kind == VKSEFRETPARAM) {
8185 if (u2->info->var->kind == VKRETPARAM) {
8188 message ("Function types are inconsistent. Parameter %d is "
8189 "sef parameter, but non-sef parameter in "
8190 "assigned function: %s",
8191 paramno, exprNode_unparse (e)),
8193 } else if (u2->info->var->kind == VKSEFPARAM) {
8196 message ("Function types are inconsistent. Parameter %d is "
8197 "returns parameter, but non-returns parameter in "
8198 "assigned function: %s",
8199 paramno, exprNode_unparse (e)),
8204 message ("Function types are inconsistent. Parameter %d is "
8205 "sef returns parameter, but non-sef returns parameter in "
8206 "assigned function: %s",
8207 paramno, exprNode_unparse (e)),
8210 } else if (u1->info->var->kind == VKRETPARAM) {
8213 message ("Function types are inconsistent. Parameter %d is "
8214 "returns parameter, but non-returns parameter in "
8215 "assigned function: %s",
8216 paramno, exprNode_unparse (e)),
8218 } else if (u1->info->var->kind == VKSEFPARAM) {
8221 message ("Function types are inconsistent. Parameter %d is "
8222 "sef parameter, but non-sef parameter in "
8223 "assigned function: %s",
8224 paramno, exprNode_unparse (e)),
8227 if (u2->info->var->kind == VKSEFRETPARAM) {
8230 message ("Function types are inconsistent. Parameter %d is "
8231 "normal parameter, but sef returns parameter in "
8232 "assigned function: %s",
8233 paramno, exprNode_unparse (e)),
8235 } else if (u2->info->var->kind == VKSEFPARAM) {
8238 message ("Function types are inconsistent. Parameter %d is "
8239 "normal parameter, but sef parameter in "
8240 "assigned function: %s",
8241 paramno, exprNode_unparse (e)),
8243 } else if (u2->info->var->kind == VKRETPARAM) {
8246 message ("Function types are inconsistent. Parameter %d is "
8247 "normal parameter, but returns parameter in "
8248 "assigned function: %s",
8249 paramno, exprNode_unparse (e)),
8257 if (u1->info->var->defstate != u2->info->var->defstate)
8261 message ("Function types are inconsistent. Parameter %d is "
8262 "%s, but %s in assigned function: %s",
8264 sstate_unparse (u1->info->var->defstate),
8265 sstate_unparse (u2->info->var->defstate),
8266 exprNode_unparse (e)),
8270 if (u1->info->var->nullstate != u2->info->var->nullstate)
8274 message ("Function types are inconsistent. Parameter %d is "
8275 "%s, but %s in assigned function: %s",
8277 nstate_unparse (u1->info->var->nullstate),
8278 nstate_unparse (u2->info->var->nullstate),
8279 exprNode_unparse (e)),
8283 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
8287 message ("Function types are inconsistent. Parameter %d is "
8288 "%s, but %s in assigned function: %s",
8290 alkind_unparse (sRef_getAliasKind (u1->sref)),
8291 alkind_unparse (sRef_getAliasKind (u2->sref)),
8292 exprNode_unparse (e)),
8296 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
8300 message ("Function types are inconsistent. Parameter %d is "
8301 "%s, but %s in assigned function: %s",
8303 exkind_unparse (sRef_getExKind (u1->sref)),
8304 exkind_unparse (sRef_getExKind (u2->sref)),
8305 exprNode_unparse (e)),
8310 static void uentry_convertIntoFunction (/*@notnull@*/ uentry old)
8313 ** Convert old into a function
8317 old->utype = ctype_unknown;
8318 old->info->fcn = (ufinfo) dmalloc (sizeof (*old->info->fcn));
8319 old->info->fcn->hasMods = FALSE;
8320 old->info->fcn->hasGlobs = FALSE;
8321 old->info->fcn->exitCode = XK_UNKNOWN;
8322 old->info->fcn->nullPred = qual_createUnknown ();
8323 old->info->fcn->specialCode = SPC_NONE;
8324 old->info->fcn->access = typeIdSet_undefined;
8325 old->info->fcn->globs = globSet_undefined;
8326 old->info->fcn->defparams = uentryList_undefined;
8327 old->info->fcn->mods = sRefSet_undefined;
8328 old->info->fcn->specclauses = NULL;
8329 old->info->fcn->preconditions = NULL;
8330 old->info->fcn->postconditions = NULL;
8334 checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8335 /*@notnull@*/ uentry unew,
8336 bool mustConform, /*@unused@*/ bool completeConform)
8338 uentryList oldParams = uentry_getParams (old);
8339 uentryList newParams = uentry_getParams (unew);
8340 ctype newType = unew->utype;
8341 ctype oldType = ctype_realType (old->utype);
8342 ctype oldRetType = ctype_unknown;
8343 ctype newRetType = ctype_unknown;
8345 DPRINTF (("Function conform: %s ==> %s",
8346 uentry_unparseFull (old),
8347 uentry_unparseFull (unew)));
8349 if (uentry_isForward (old))
8351 mustConform = FALSE;
8352 uentry_updateInto (old, unew);
8357 ** check return values
8360 if (ctype_isKnown (oldType))
8362 if (ctype_isFunction (oldType))
8364 oldRetType = ctype_getReturnType (oldType);
8370 message ("%s %q declared as function, but previously declared as %s",
8371 ekind_capName (unew->ukind),
8372 uentry_getName (unew),
8373 ekind_unparseLong (old->ukind)),
8374 uentry_whereDeclared (unew)))
8376 uentry_showWhereLast (old);
8379 uentry_convertIntoFunction (old);
8384 if (ctype_isKnown (newType))
8386 llassert (ctype_isFunction (newType));
8387 newRetType = ctype_getReturnType (newType);
8390 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
8391 && !ctype_matchDef (newRetType, oldRetType))
8393 if (mustConform) returnValueError (old, unew);
8397 if (ctype_isConj (newRetType))
8399 if (ctype_isConj (oldRetType))
8401 if (!ctype_sameAltTypes (newRetType, oldRetType))
8405 message ("Function %q inconsistently %rdeclared to "
8406 "return alternate types %s "
8407 "(types match, but alternates are not identical, "
8408 "so checking may not be correct)",
8409 uentry_getName (unew),
8410 uentry_isDeclared (old),
8411 ctype_unparse (newRetType)),
8412 uentry_whereDeclared (unew)))
8414 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
8420 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
8425 DPRINTF (("Before state: %s",
8426 uentry_unparseFull (old)));
8427 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8428 DPRINTF (("After state: %s",
8429 uentry_unparseFull (old)));
8431 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
8433 if (exitkind_isKnown (unew->info->fcn->exitCode))
8437 message ("Function %q inconsistently %rdeclared using %s",
8438 uentry_getName (unew),
8439 uentry_isDeclared (old),
8440 exitkind_unparse (unew->info->fcn->exitCode)),
8441 uentry_whereDeclared (unew)))
8443 uentry_showWhereSpecified (old);
8448 unew->info->fcn->exitCode = old->info->fcn->exitCode;
8452 if (!qual_isUnknown (unew->info->fcn->nullPred))
8454 if (!qual_match (old->info->fcn->nullPred, unew->info->fcn->nullPred))
8458 message ("Function %q inconsistently %rdeclared using %s",
8459 uentry_getName (unew),
8460 uentry_isDeclared (old),
8461 qual_unparse (unew->info->fcn->nullPred)),
8462 uentry_whereDeclared (unew)))
8464 uentry_showWhereSpecified (old);
8470 unew->info->fcn->nullPred = old->info->fcn->nullPred;
8473 if (unew->info->fcn->specialCode != SPC_NONE)
8475 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
8479 message ("Function %q inconsistently %rdeclared using %s",
8480 uentry_getName (unew),
8481 uentry_isDeclared (old),
8482 specCode_unparse (unew->info->fcn->specialCode)),
8483 uentry_whereDeclared (unew)))
8485 uentry_showWhereSpecified (old);
8491 unew->info->fcn->specialCode = old->info->fcn->specialCode;
8498 if (!uentryList_sameObject (oldParams, newParams)
8499 && (!uentryList_isMissingParams (oldParams)))
8501 if (!uentryList_isMissingParams (newParams))
8504 int nparams = uentryList_size (oldParams);
8505 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
8507 if (nparams != uentryList_size (newParams))
8509 nargsError (old, unew);
8512 if (uentryList_size (newParams) < nparams)
8514 nparams = uentryList_size (newParams);
8517 while (paramno < nparams)
8519 uentry oldCurrent = uentryList_getN (oldParams, paramno);
8520 uentry newCurrent = uentryList_getN (newParams, paramno);
8521 ctype oldCurrentType = uentry_getType (oldCurrent);
8522 ctype newCurrentType = uentry_getType (newCurrent);
8524 llassert (uentry_isValid (oldCurrent)
8525 && uentry_isValid (newCurrent));
8527 if (!uentry_isElipsisMarker (oldCurrent)
8528 && !uentry_isElipsisMarker (newCurrent))
8530 checkVarConformance (oldCurrent, newCurrent,
8531 mustConform, completeConform);
8536 if (uentry_hasName (oldCurrent)
8537 && uentry_hasName (newCurrent))
8539 cstring oldname = uentry_getName (oldCurrent);
8540 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
8542 cstring nname = uentry_getName (newCurrent);
8545 if (cstring_isDefined (pfx)
8546 && cstring_equalPrefix (oldname, pfx))
8548 oname = cstring_suffix (oldname, cstring_length (pfx));
8553 /*@-branchstate@*/ } /*@=branchstate@*/
8555 if (cstring_isDefined (pfx)
8556 && cstring_equalPrefix (nname, pfx))
8558 nnamefix = cstring_suffix (nname, cstring_length (pfx));
8563 /*@-branchstate@*/ } /*@=branchstate@*/
8565 if (!cstring_equal (oname, nnamefix))
8568 (FLG_DECLPARAMMATCH,
8569 message ("Definition parameter name %s does not match "
8570 "name of corresponding parameter in "
8573 uentry_whereLast (newCurrent)))
8575 uentry_showWhereLastPlain (oldCurrent);
8579 cstring_free (oldname);
8580 cstring_free (nname);
8584 if (!ctype_match (oldCurrentType, newCurrentType))
8586 paramTypeError (old, oldCurrent, oldCurrentType,
8587 unew, newCurrent, newCurrentType, paramno);
8591 if (ctype_isMissingParamsMarker (newCurrentType)
8592 || ctype_isElips (newCurrentType)
8593 || ctype_isMissingParamsMarker (oldCurrentType)
8594 || ctype_isElips (oldCurrentType))
8600 if (ctype_isConj (newCurrentType))
8602 if (ctype_isConj (oldCurrentType))
8604 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
8608 message ("Parameter %q inconsistently %rdeclared with "
8609 "alternate types %s "
8610 "(types match, but alternates are not identical, "
8611 "so checking may not be correct)",
8612 uentry_getName (newCurrent),
8613 uentry_isDeclared (oldCurrent),
8614 ctype_unparse (newCurrentType)),
8615 uentry_whereDeclared (unew)))
8617 uentry_showWhereLastVal (oldCurrent,
8618 ctype_unparse (oldCurrentType));
8626 message ("Parameter %q inconsistently %rdeclared with "
8627 "alternate types %s",
8628 uentry_getName (newCurrent),
8629 uentry_isDeclared (oldCurrent),
8630 ctype_unparse (newCurrentType)),
8631 uentry_whereDeclared (unew)))
8633 uentry_showWhereLastVal (oldCurrent,
8634 ctype_unparse (oldCurrentType));
8641 if (ctype_isConj (oldCurrentType))
8643 uentry_setType (newCurrent, oldCurrentType);
8651 ** Forgot this! detected by splint:
8652 ** uentry.c:1257,15: Suspected infinite loop
8658 if (!uentryList_isMissingParams (newParams))
8660 if (ctype_isConj (oldRetType))
8662 old->utype = ctype_makeFunction (oldRetType,
8663 uentryList_copy (newParams));
8667 old->utype = unew->utype;
8671 checkGlobalsConformance (old, unew, mustConform, completeConform);
8672 checkModifiesConformance (old, unew, mustConform, completeConform);
8674 DPRINTF (("Before list: %s",
8675 uentry_unparseFull (old)));
8677 if (stateClauseList_isDefined (unew->info->fcn->specclauses))
8679 if (!stateClauseList_isDefined (old->info->fcn->specclauses))
8684 message ("Function %q redeclared using special clauses (can only "
8685 "be used in first declaration)",
8686 uentry_getName (unew)),
8687 uentry_whereDeclared (unew)))
8689 uentry_showWhereLast (old);
8693 /* need to add some checking @*/
8694 old->info->fcn->specclauses = unew->info->fcn->specclauses;
8698 /* should be able to append? */
8700 stateClauseList_checkEqual (old, unew);
8701 stateClauseList_free (unew->info->fcn->specclauses);
8702 unew->info->fcn->specclauses = stateClauseList_undefined;
8706 /*@=branchstate@*/ /* shouldn't need this */
8708 if (fileloc_isUndefined (old->whereDeclared))
8710 old->whereDeclared = fileloc_copy (unew->whereDeclared);
8712 else if (fileloc_isUndefined (unew->whereDeclared))
8714 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8721 } /*@=compmempass@*/ /* I think this is a spurious warning */
8724 uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
8728 llassert (uentry_isValid (ue));
8729 llassert (uentry_isEitherConstant (ue));
8731 DPRINTF (("Constant value: %s / %s", uentry_unparse (ue), multiVal_unparse (m)));
8732 uval = uentry_getConstantValue (ue);
8734 if (multiVal_isDefined (uval))
8736 if (multiVal_isDefined (m))
8738 if (!multiVal_equiv (uval, m))
8742 message ("%s %q defined with inconsistent value: %q",
8743 ekind_capName (ue->ukind),
8744 uentry_getName (ue),
8745 multiVal_unparse (m)),
8748 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
8756 uentry_setConstantValue (ue, m);
8761 bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
8764 bool typeError = FALSE;
8766 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
8768 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
8772 DPRINTF (("Check struct conformance: %s / %s",
8773 uentry_unparseFull (old),
8774 uentry_unparseFull (unew)));
8775 checkStructConformance (old, unew);
8780 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8782 llbug (message ("struct tags: bad types: %t / %t",
8783 old->utype, unew->utype));
8787 else if (uentry_isEnumTag (old))
8789 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
8791 if (mustConform) checkEnumConformance (old, unew);
8795 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8797 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
8798 ctype_unparse (unew->utype)));
8802 else if (!ctype_match (old->utype, unew->utype))
8804 DPRINTF (("Type mismatch: %s / %s",
8805 ctype_unparse (old->utype),
8806 ctype_unparse (unew->utype)));
8808 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
8810 ctype realt = ctype_realType (unew->utype);
8812 if (ctype_isRealInt (realt) || ctype_isChar (realt))
8814 unew->utype = ctype_bool;
8820 typeError = optgenerror
8822 message ("%q defined as %s", uentry_getName (old),
8823 ctype_unparse (realt)),
8824 uentry_whereDeclared (unew));
8832 ctype oldr = ctype_realType (old->utype);
8833 ctype newr = ctype_realType (unew->utype);
8835 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
8837 checkStructConformance (old, unew);
8839 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
8841 checkStructConformance (old, unew);
8843 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
8845 checkEnumConformance (old, unew);
8847 else if (uentry_isConstant (old)
8848 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
8850 /* okay...for now! (should check the type is reset later... */
8854 DPRINTF (("YABA!"));
8857 message ("%s %q %rdeclared with inconsistent type: %t",
8858 ekind_capName (unew->ukind),
8859 uentry_getName (unew),
8860 uentry_isDeclared (old),
8862 uentry_whereDeclared (unew)))
8864 uentry_showWhereLast (old);
8880 uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
8881 /*@notnull@*/ uentry unew,
8882 bool mustConform, bool completeConform)
8884 if (ctype_isDefined (unew->info->datatype->type))
8887 ** bool is hard coded here, since it is built into LCL.
8888 ** For now, we're stuck with LCL's types.
8891 if (ctype_isDirectBool (old->utype) &&
8892 cstring_equalLit (unew->uname, "bool"))
8894 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
8895 evs 2000-07-25: removed
8897 unew->utype = ctype_bool;
8900 if (ctype_isUnknown (old->info->datatype->type))
8902 old->info->datatype->type = unew->info->datatype->type;
8906 DPRINTF (("Old: %s / New: %s",
8907 uentry_unparseFull (old),
8908 uentry_unparseFull (unew)));
8909 DPRINTF (("Types: %s / %s",
8910 ctype_unparse (old->info->datatype->type),
8911 ctype_unparse (unew->info->datatype->type)));
8913 if (ctype_matchDef (old->info->datatype->type,
8914 unew->info->datatype->type))
8923 ("Type %q %s with inconsistent type: %t",
8924 uentry_getName (unew),
8925 uentry_reDefDecl (old, unew),
8926 unew->info->datatype->type),
8927 uentry_whereDeclared (unew)))
8929 uentry_showWhereLastExtra
8930 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
8933 old->info->datatype->type = unew->info->datatype->type;
8938 if (!qual_isUnknown (unew->info->datatype->abs))
8940 if (qual_isConcrete (old->info->datatype->abs)
8941 && qual_isEitherAbstract (unew->info->datatype->abs))
8943 if (!ctype_isDirectBool (old->utype))
8948 ("Datatype %q inconsistently %rdeclared as abstract type",
8949 uentry_getName (unew),
8950 uentry_isDeclared (old)),
8951 uentry_whereDeclared (unew)))
8953 uentry_showWhereLastPlain (old);
8957 else if (qual_isEitherAbstract (old->info->datatype->abs)
8958 && qual_isConcrete (unew->info->datatype->abs))
8960 if (!ctype_isDirectBool (old->utype))
8965 ("Datatype %q inconsistently %rdeclared as concrete type",
8966 uentry_getName (unew),
8967 uentry_isDeclared (old)),
8968 uentry_whereDeclared (unew)))
8970 uentry_showWhereLastPlain (old);
8981 if (qual_isEitherAbstract (old->info->datatype->abs))
8983 old->sref = unew->sref;
8984 unew->info->datatype->mut = old->info->datatype->mut;
8987 && uentry_isReallySpecified (old))
8992 ("Datatype %q specified as abstract, "
8993 "but abstract annotation not used in declaration",
8994 uentry_getName (unew)),
8995 uentry_whereDeclared (unew)))
8997 uentry_showWhereLastPlain (old);
9003 unew->info->datatype->abs = old->info->datatype->abs;
9005 if (ynm_isMaybe (unew->info->datatype->mut))
9007 if (completeConform && ynm_isOff (old->info->datatype->mut)
9008 && uentry_isReallySpecified (old))
9013 ("Datatype %q specified as immutable, "
9014 "but immutable annotation not used in declaration",
9015 uentry_getName (unew)),
9016 uentry_whereDeclared (unew)))
9018 uentry_showWhereLastPlain (old);
9022 unew->info->datatype->mut = old->info->datatype->mut;
9024 else if (ynm_isMaybe (old->info->datatype->mut))
9026 old->info->datatype->mut = unew->info->datatype->mut;
9030 if (qual_isEitherAbstract (old->info->datatype->abs))
9032 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
9036 message ("Datatype %q inconsistently %rdeclared as immutable",
9037 uentry_getName (unew),
9038 uentry_isDeclared (old)),
9039 uentry_whereDeclared (unew)))
9041 uentry_showWhereLastPlain (old);
9046 if (ynm_isOff (old->info->datatype->mut)
9047 && ynm_isOn (unew->info->datatype->mut))
9051 message ("Datatype %q inconsistently %rdeclared as mutable",
9052 uentry_getName (unew),
9053 uentry_isDeclared (old)),
9054 uentry_whereDeclared (unew)))
9056 uentry_showWhereLastPlain (old);
9061 old->info->datatype->mut = unew->info->datatype->mut;
9064 uentry_checkStateConformance (old, unew, mustConform, completeConform);
9068 uentry_checkConstantConformance (/*@notnull@*/ uentry old,
9069 /*@notnull@*/ uentry unew,
9071 /*@unused@*/ bool completeConform)
9073 multiVal oldval = uentry_getConstantValue (old);
9074 multiVal newval = uentry_getConstantValue (unew);
9076 if (multiVal_isDefined (oldval))
9078 if (multiVal_isDefined (newval))
9080 if (!multiVal_equiv (oldval, newval))
9085 message ("%s %q %rdeclared with inconsistent value: %q",
9086 ekind_capName (unew->ukind),
9087 uentry_getName (unew),
9088 uentry_isDeclared (old),
9089 multiVal_unparse (newval)),
9090 uentry_whereDeclared (unew)))
9092 uentry_showWhereLastExtra (old, multiVal_unparse (oldval));
9096 uentry_setConstantValue (unew, multiVal_copy (oldval));
9105 uentry_setConstantValue (old, multiVal_copy (newval));
9110 uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
9111 /*@notnull@*/ uentry unew, bool mustConform,
9112 bool completeConform)
9114 bool typeError = FALSE;
9115 bool fcnConformance = FALSE;
9117 if (!ekind_equal (unew->ukind, old->ukind))
9120 ** okay, only if one is a function and the other is
9121 ** a variable of type function.
9124 if (unew->ukind == KENUMCONST
9125 && old->ukind == KCONST)
9127 old->ukind = KENUMCONST;
9131 if (unew->ukind == KFCN
9132 && old->ukind == KCONST
9133 && ctype_isUnknown (old->utype))
9136 ** When a function is defined with an unparam macro
9139 uentry_updateInto (old, unew);
9143 if (uentry_isExpandedMacro (old)
9144 && uentry_isEitherConstant (unew))
9146 uentry_updateInto (old, unew);
9150 if (uentry_isEndIter (unew))
9152 if (ctype_isUnknown (old->utype))
9154 if (!uentry_isSpecified (old)
9155 && uentry_isCodeDefined (unew))
9157 if (!fileloc_withinLines (uentry_whereDefined (old),
9158 uentry_whereDeclared (unew), 2))
9159 { /* bogus! will give errors if there is too much whitespace */
9163 ("Iterator finalized name %q does not match name in "
9164 "previous iter declaration (should be end_%q). This iter "
9165 "is declared at %q",
9166 uentry_getName (unew),
9167 uentry_getName (old),
9168 fileloc_unparse (uentry_whereDefined (old))),
9169 uentry_whereDeclared (old));
9173 uentry_updateInto (old, unew);
9178 KindConformanceError (old, unew, mustConform);
9182 if (uentry_isFunction (unew))
9184 if (uentry_isVariable (old))
9186 if (!ctype_isUnknown (old->utype))
9188 if (ctype_isFunction (old->utype))
9190 uentry_makeVarFunction (old);
9191 checkFunctionConformance (old, unew, mustConform,
9193 fcnConformance = TRUE;
9197 KindConformanceError (old, unew, mustConform);
9202 if (uentry_isExpandedMacro (old))
9204 if (fileloc_isUndefined (unew->whereDefined))
9206 unew->whereDefined = fileloc_update (unew->whereDefined,
9210 uentry_updateInto (old, unew);
9211 old->used = unew->used = TRUE;
9216 /* undeclared identifier */
9217 old->utype = unew->utype;
9218 uentry_makeVarFunction (old);
9219 checkFunctionConformance (old, unew, FALSE, FALSE);
9220 fcnConformance = TRUE;
9226 KindConformanceError (old, unew, mustConform);
9229 else if (uentry_isFunction (old) && uentry_isVariable (unew))
9231 if (!ctype_isUnknown (unew->utype))
9233 if (ctype_isFunction (unew->utype))
9235 uentry_makeVarFunction (unew);
9236 checkFunctionConformance (old, unew, mustConform, completeConform);
9237 fcnConformance = TRUE;
9241 KindConformanceError (old, unew, mustConform);
9246 KindConformanceError (old, unew, mustConform);
9251 KindConformanceError (old, unew, mustConform);
9257 ** check parameter lists for functions
9258 ** (before type errors, to get better messages
9261 if (uentry_isFunction (old))
9263 checkFunctionConformance (old, unew, mustConform, completeConform);
9264 fcnConformance = TRUE;
9268 if (!ctype_isUndefined (old->utype))
9270 typeError = checkTypeConformance (old, unew, mustConform);
9277 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
9279 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
9282 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
9284 DPRINTF (("Check datatype: %s / %s",
9285 uentry_unparseFull (old),
9286 uentry_unparseFull (unew)));
9288 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
9291 if (uentry_isVariable (old) && uentry_isVariable (unew))
9294 !ctype_matchDef (old->utype, unew->utype))
9299 ("Variable %q %s with inconsistent type (arrays and pointers are "
9300 "not identical in variable declarations): %t",
9301 uentry_getName (unew),
9302 uentry_reDefDecl (old, unew),
9304 uentry_whereDeclared (unew)))
9306 uentry_showWhereLast (old);
9309 ** Avoid repeated errors.
9312 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
9314 old->whereDefined = fileloc_update (old->whereDefined,
9322 checkVarConformance (old, unew, mustConform, completeConform);
9327 /* old->utype = unew->utype; */
9331 if (ctype_isConj (old->utype))
9333 if (ctype_isConj (unew->utype))
9335 if (!ctype_sameAltTypes (old->utype, unew->utype))
9339 message ("%s %q inconsistently %rdeclared with "
9340 "alternate types %s "
9341 "(types match, but alternates are not identical, "
9342 "so checking may not be correct)",
9343 ekind_capName (uentry_getKind (old)),
9344 uentry_getName (unew),
9345 uentry_isDeclared (old),
9346 ctype_unparse (unew->utype)),
9347 uentry_whereDeclared (unew)))
9349 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
9353 old->utype = unew->utype;
9360 if (ctype_isUnknown (old->utype))
9362 old->utype = unew->utype;
9367 if (unew->ukind == old->ukind)
9370 unew->info = uinfo_copy (old->info, old->ukind);
9373 sRef_storeState (old->sref);
9374 sRef_storeState (unew->sref);
9377 static void uentry_mergeConstraints (uentry spec, uentry def)
9379 if (uentry_isFunction (def))
9381 DPRINTF (("Here: %s / %s",
9382 uentry_unparseFull (spec),
9383 uentry_unparseFull (def)));
9384 /* evans 2001-07-21 */
9385 llassert (uentry_isFunction (spec));
9387 if (functionConstraint_isDefined (def->info->fcn->preconditions))
9389 if (fileloc_isXHFile (uentry_whereLast (def)))
9391 llassert (uentry_isFunction (spec));
9392 spec->info->fcn->preconditions = functionConstraint_conjoin (spec->info->fcn->preconditions,
9393 def->info->fcn->preconditions);
9395 else if (fileloc_equal (uentry_whereLast (spec), uentry_whereLast (def)))
9401 /* Check if the constraints are identical */
9406 ("Preconditions for %q redeclared. Dropping previous precondition: %q",
9407 uentry_getName (spec),
9408 functionConstraint_unparse (spec->info->fcn->preconditions)),
9409 uentry_whereLast (def)))
9411 uentry_showWhereSpecified (spec);
9414 functionConstraint_free (spec->info->fcn->preconditions);
9415 spec->info->fcn->preconditions = def->info->fcn->preconditions;
9418 def->info->fcn->preconditions = functionConstraint_undefined;
9421 if (functionConstraint_isDefined (def->info->fcn->postconditions))
9423 if (fileloc_isXHFile (uentry_whereLast (def)))
9425 llassert (uentry_isFunction (spec));
9426 DPRINTF (("Post: %s /++/ %s",
9427 functionConstraint_unparse (spec->info->fcn->postconditions),
9428 functionConstraint_unparse (def->info->fcn->postconditions)));
9429 spec->info->fcn->postconditions = functionConstraint_conjoin (spec->info->fcn->postconditions,
9430 def->info->fcn->postconditions);
9431 def->info->fcn->postconditions = functionConstraint_undefined;
9432 DPRINTF (("Conjoined post: %s", functionConstraint_unparse (spec->info->fcn->postconditions)));
9439 ("Postconditions for %q redeclared. Dropping previous postcondition: %q",
9440 uentry_getName (spec),
9441 functionConstraint_unparse (spec->info->fcn->postconditions)),
9442 uentry_whereLast (def)))
9444 uentry_showWhereSpecified (spec);
9447 functionConstraint_free (spec->info->fcn->postconditions);
9448 spec->info->fcn->postconditions = def->info->fcn->postconditions;
9449 def->info->fcn->postconditions = functionConstraint_undefined;
9456 ** modifies spec to reflect def, reports any inconsistencies
9460 uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
9462 llassert (uentry_isValid (spec));
9463 llassert (uentry_isValid (def));
9464 llassert (cstring_equal (spec->uname, def->uname));
9466 if (uentry_isFunction (def))
9468 if (uentry_isConstant (spec))
9470 llassert (ctype_isUnknown (spec->utype) || ctype_isFunction (spec->utype));
9471 uentry_makeConstantFunction (spec);
9475 uentry_convertVarFunction (spec);
9478 llassert (uentry_isFunction (spec));
9481 DPRINTF (("Merge entries: %s / %s",
9482 uentry_unparseFull (spec),
9483 uentry_unparseFull (def)));
9485 uentry_mergeConstraints (spec, def);
9487 uentry_checkConformance (spec, def, TRUE,
9488 context_getFlag (FLG_NEEDSPEC));
9490 DPRINTF (("Merge entries after conform: %s / %s",
9491 uentry_unparseFull (spec),
9492 uentry_unparseFull (def)));
9494 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
9497 ** okay, declarations conform. Propagate extra information.
9500 uentry_setDefined (spec, uentry_whereDefined (def));
9501 uentry_setDeclared (spec, uentry_whereDeclared (def));
9503 if (uentry_isStatic (def))
9507 message ("%s %q specified, but declared as static",
9508 ekind_capName (def->ukind),
9509 uentry_getName (def)),
9510 uentry_whereDeclared (def)))
9512 uentry_showWhereSpecified (spec);
9517 spec->storageclass = def->storageclass;
9520 sRef_storeState (spec->sref);
9522 spec->used = def->used || spec->used;
9523 spec->hasNameError |= def->hasNameError;
9527 if (!spec->hasNameError)
9529 uentry_checkName (spec);
9538 ** Can't generate function redeclaration errors when the
9539 ** entries are merged, since we don't yet know if its the
9540 ** definition of the function.
9544 uentry_clearDecl (void)
9546 posRedeclared = uentry_undefined;
9547 fileloc_free (posLoc);
9548 posLoc = fileloc_undefined;
9552 uentry_checkDecl (void)
9554 if (uentry_isValid (posRedeclared) && !fileloc_isXHFile (posLoc))
9556 llassert (fileloc_isDefined (posLoc));
9558 if (uentry_isCodeDefined (posRedeclared))
9560 if (optgenerror (FLG_REDECL,
9561 message ("%s %q declared after definition",
9562 ekind_capName (posRedeclared->ukind),
9563 uentry_getName (posRedeclared)),
9566 llgenindentmsg (message ("Definition of %q",
9567 uentry_getName (posRedeclared)),
9568 posRedeclared->whereDeclared);
9573 if (optgenerror (FLG_REDECL,
9574 message ("%s %q declared more than once",
9575 ekind_capName (posRedeclared->ukind),
9576 uentry_getName (posRedeclared)),
9579 llgenindentmsg (message ("Previous declaration of %q",
9580 uentry_getName (posRedeclared)),
9581 posRedeclared->whereDeclared);
9586 fileloc_free (posLoc);
9587 posLoc = fileloc_undefined;
9588 posRedeclared = uentry_undefined;
9592 ** Redefinition of old as unew.
9593 ** modifies old to reflect unew, reports any inconsistencies
9597 uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
9599 fileloc olddef = uentry_whereDeclared (old);
9600 fileloc unewdef = uentry_whereDeclared (unew);
9604 DPRINTF (("uentry merge: %s / %s",
9605 uentry_unparseFull (old),
9606 uentry_unparseFull (unew)));
9609 fileloc_isUndefined (olddef)
9610 && fileloc_isDefined (uentry_whereDefined (old))
9611 && !uentry_isExpandedMacro (old);
9613 if (!context_getFlag (FLG_INCONDEFSLIB)
9614 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9616 mustConform = FALSE;
9623 llassert (uentry_isValid (old));
9624 llassert (uentry_isValid (unew));
9625 llassert (cstring_equal (old->uname, unew->uname));
9627 if (uentry_isFunction (unew) && !uentry_isFunction (old))
9629 if (uentry_isConstant (old))
9631 llassert (ctype_isUnknown (old->utype) || ctype_isFunction (old->utype));
9632 uentry_makeConstantFunction (old);
9636 uentry_convertVarFunction (old);
9639 if (!uentry_isFunction (old))
9643 message ("%s %q declared as function, but previously declared as %s",
9644 ekind_capName (unew->ukind),
9645 uentry_getName (unew),
9646 ekind_unparseLong (old->ukind)),
9647 uentry_whereDeclared (unew)))
9649 uentry_showWhereLast (old);
9652 uentry_convertIntoFunction (old);
9657 DPRINTF (("uentry merge: %s / %s",
9658 uentry_unparseFull (old),
9659 uentry_unparseFull (unew)));
9661 if (uentry_isExtern (unew))
9663 uentry_setUsed (old, unewdef);
9667 ** should check old one was extern!
9670 if (uentry_isStatic (old))
9672 if (!(uentry_isStatic (unew)))
9676 message ("%s %q shadows static declaration",
9677 ekind_capName (unew->ukind),
9678 uentry_getName (unew)),
9681 uentry_showWhereLast (old);
9686 uentry_setDeclDef (old, unewdef);
9689 else if (uentry_isStatic (unew))
9691 uentry_setDeclDef (old, unewdef);
9693 else if (uentry_isExtern (old))
9695 uentry_setDeclared (old, unewdef);
9699 if (!uentry_isExtern (unew)
9700 && !uentry_isForward (old)
9701 && !fileloc_equal (olddef, unewdef)
9702 && !fileloc_isUndefined (olddef)
9703 && !fileloc_isUndefined (unewdef)
9704 && !fileloc_isBuiltin (olddef)
9705 && !fileloc_isBuiltin (unewdef)
9706 && !uentry_isYield (old)
9707 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9709 if (uentry_isVariable (old) || uentry_isVariable (unew))
9711 ; /* will report redeclaration error later */
9715 if (fileloc_isDefined (uentry_whereDefined (old)))
9719 message ("%s %q defined more than once",
9720 ekind_capName (unew->ukind),
9721 uentry_getName (unew)),
9722 uentry_whereLast (unew)))
9725 (message ("Previous definition of %q",
9726 uentry_getName (old)),
9727 uentry_whereLast (old));
9730 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
9732 uentry_updateInto (old, unew);
9733 old->sref = sRef_saveCopy (old->sref);
9741 if (fileloc_isLib (olddef)
9742 || fileloc_isUndefined (olddef)
9743 || fileloc_isImport (olddef))
9745 if (uentry_isExtern (unew))
9747 if (uentry_isExtern (old)
9748 || (fileloc_isDefined (uentry_whereDeclared (old))
9749 && (!fileloc_equal (uentry_whereDeclared (old),
9750 uentry_whereDefined (old)))))
9754 message ("%s %q declared more than once",
9755 ekind_capName (unew->ukind),
9756 uentry_getName (unew)),
9757 unew->whereDeclared))
9760 (message ("Previous declaration of %q",
9761 uentry_getName (old)),
9762 old->whereDeclared);
9766 uentry_setExtern (old);
9770 uentry_setDeclared (old, unewdef); /* evans 2001-07-23 was setDefined */
9776 DPRINTF (("uentry merge: %s / %s",
9777 uentry_unparseFull (old),
9778 uentry_unparseFull (unew)));
9780 uentry_mergeConstraints (old, unew);
9781 DPRINTF (("uentry merge: %s / %s",
9782 uentry_unparseFull (old),
9783 uentry_unparseFull (unew)));
9785 uentry_checkConformance (old, unew, mustConform, FALSE);
9786 DPRINTF (("uentry merge: %s / %s",
9787 uentry_unparseFull (old),
9788 uentry_unparseFull (unew)));
9790 old->used = old->used || unew->used;
9791 old->uses = filelocList_append (old->uses, unew->uses);
9792 unew->uses = filelocList_undefined;
9794 sRef_storeState (old->sref);
9795 sRef_storeState (unew->sref);
9799 old->whereDefined = fileloc_update (old->whereDefined,
9803 DPRINTF (("here: %s", uentry_unparseFull (old)));
9806 ** No redeclaration errors for functions here, since we
9807 ** don't know if this is the definition of the function.
9810 if (fileloc_isUser (old->whereDeclared)
9811 && fileloc_isUser (unew->whereDeclared)
9812 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
9813 && !fileloc_isDefined (unew->whereDefined))
9815 if (uentry_isFunction (old))
9817 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
9818 posLoc = fileloc_update (posLoc, unew->whereDeclared);
9822 if (optgenerror (FLG_REDECL,
9823 message ("%s %q declared more than once",
9824 ekind_capName (unew->ukind),
9825 uentry_getName (unew)),
9826 unew->whereDeclared))
9828 llgenindentmsg (message ("Previous declaration of %q",
9829 uentry_getName (old)),
9830 old->whereDeclared);
9835 if (fileloc_isUndefined (old->whereDefined))
9837 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
9841 if (!context_processingMacros ()
9842 && fileloc_isUser (old->whereDefined)
9843 && fileloc_isUser (unew->whereDefined)
9844 && !fileloc_equal (old->whereDefined, unew->whereDefined))
9846 if (uentry_isVariable (unew) || uentry_isFunction (unew))
9848 if (uentry_isVariable (unew)
9849 && uentry_isExtern (unew))
9851 if (optgenerror (FLG_REDECL,
9852 message ("%s %q declared after definition",
9853 ekind_capName (unew->ukind),
9854 uentry_getName (unew)),
9855 unew->whereDeclared))
9857 llgenindentmsg (message ("Definition of %q",
9858 uentry_getName (old)),
9864 if (optgenerror (FLG_REDEF,
9865 message ("%s %q redefined",
9866 ekind_capName (unew->ukind),
9867 uentry_getName (unew)),
9868 unew->whereDefined))
9870 llgenindentmsg (message ("Previous definition of %q",
9871 uentry_getName (old)),
9879 if (uentry_isExternal (unew))
9881 old->whereDefined = fileloc_createExternal ();
9884 if (unew->hasNameError)
9886 old->hasNameError = TRUE;
9891 if (!old->hasNameError)
9893 uentry_checkName (old);
9896 DPRINTF (("After: %s", uentry_unparseFull (old)));
9897 llassert (!ctype_isUndefined (old->utype));
9901 uentry_copyState (uentry res, uentry other)
9903 llassert (uentry_isValid (res));
9904 llassert (uentry_isValid (other));
9906 res->used = other->used;
9908 res->info->var->kind = other->info->var->kind;
9909 res->info->var->defstate = other->info->var->defstate;
9910 res->info->var->nullstate = other->info->var->nullstate;
9911 res->info->var->checked = other->info->var->checked;
9913 sRef_copyState (res->sref, other->sref);
9917 uentry_sameKind (uentry u1, uentry u2)
9919 if (uentry_isValid (u1) && uentry_isValid (u2))
9921 if (uentry_isVar (u1) && uentry_isVar (u2))
9923 ctype c1 = u1->utype;
9924 ctype c2 = u2->utype;
9926 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
9929 ** both functions, or both not functions
9932 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
9936 return ((u1->ukind == u2->ukind));
9943 static void uentry_updateInto (/*@unique@*/ uentry unew, uentry old)
9946 llassert (uentry_isValid (unew));
9947 llassert (uentry_isValid (old));
9949 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9950 okind = unew->ukind;
9951 unew->ukind = old->ukind;
9952 llassert (cstring_equal (unew->uname, old->uname));
9953 unew->utype = old->utype;
9955 if (fileloc_isDefined (unew->whereSpecified)
9956 && !fileloc_isDefined (old->whereSpecified))
9958 ; /* Keep the old value */
9962 fileloc_free (unew->whereSpecified);
9963 unew->whereSpecified = fileloc_copy (old->whereSpecified);
9966 if (fileloc_isDefined (unew->whereDefined)
9967 && !fileloc_isDefined (old->whereDefined))
9969 ; /* Keep the old value */
9973 fileloc_free (unew->whereDefined);
9974 unew->whereDefined = fileloc_copy (old->whereDefined);
9977 if (fileloc_isDefined (unew->whereDeclared)
9978 && !fileloc_isDefined (old->whereDeclared))
9980 ; /* Keep the old value */
9984 fileloc_free (unew->whereDeclared);
9985 unew->whereDeclared = fileloc_copy (old->whereDeclared);
9988 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9990 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
9991 unew->used = old->used;
9993 unew->isPrivate = old->isPrivate;
9994 unew->hasNameError = old->hasNameError;
9995 unew->uses = filelocList_append (unew->uses, old->uses);
9996 old->uses = filelocList_undefined;
9998 unew->storageclass = old->storageclass;
9999 uinfo_free (unew->info, okind);
10000 unew->info = uinfo_copy (old->info, old->ukind);
10004 uentry_copyAux (uentry e, bool saveCopy)
10007 if (uentry_isValid (e))
10009 uentry enew = uentry_alloc ();
10010 DPRINTF (("copy: %s", uentry_unparseFull (e)));
10011 enew->ukind = e->ukind;
10012 enew->uname = cstring_copy (e->uname);
10013 enew->utype = e->utype;
10015 enew->whereSpecified = fileloc_copy (e->whereSpecified);
10016 enew->whereDefined = fileloc_copy (e->whereDefined);
10017 enew->whereDeclared = fileloc_copy (e->whereDeclared);
10021 enew->sref = sRef_saveCopy (e->sref); /* Memory leak! */
10025 enew->sref = sRef_copy (e->sref);
10028 enew->used = e->used;
10029 enew->lset = FALSE;
10030 enew->isPrivate = e->isPrivate;
10031 enew->hasNameError = e->hasNameError;
10032 enew->uses = filelocList_undefined;
10034 enew->storageclass = e->storageclass;
10035 enew->info = uinfo_copy (e->info, e->ukind);
10036 enew->warn = warnClause_copy (e->warn);
10038 DPRINTF (("Here we are..."));
10039 DPRINTF (("original: %s", uentry_unparseFull (e)));
10040 DPRINTF (("copy: %s", uentry_unparse (enew)));
10041 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
10046 return uentry_undefined;
10051 uentry_copy (uentry e)
10053 return uentry_copyAux (e, TRUE);
10057 uentry_copyNoSave (uentry e)
10059 return uentry_copyAux (e, FALSE);
10063 uentry_setState (uentry res, uentry other)
10065 llassert (uentry_isValid (res));
10066 llassert (uentry_isValid (other));
10068 llassert (res->ukind == other->ukind);
10069 llassert (res->ukind == KVAR);
10071 res->sref = sRef_saveCopy (other->sref);
10072 res->used = other->used;
10073 filelocList_free (res->uses);
10074 res->uses = other->uses;
10075 other->uses = filelocList_undefined;
10076 res->lset = other->lset;
10080 uentry_mergeUses (uentry res, uentry other)
10082 llassert (uentry_isValid (res));
10083 llassert (uentry_isValid (other));
10085 res->used = other->used || res->used;
10086 res->lset = other->lset || res->lset;
10087 res->uses = filelocList_append (res->uses, other->uses);
10088 other->uses = filelocList_undefined;
10093 ** This is a really ugly routine.
10095 ** gack...fix this one day.
10100 ** >> res is the false branch, other is the true branch (or continuation)
10102 ** >> res is the true branch, other is the false branch (or continutation)
10109 ** References not effected by res are propagated from other.
10113 branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10114 bool flip, clause cl, fileloc loc)
10118 message ("%s %q is %s %s, but %s %s.",
10119 ekind_capName (res->ukind), uentry_getName (res),
10120 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
10121 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
10124 DPRINTF (("Here: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
10126 if (sRef_isDead (res->sref))
10128 if (sRef_hasStateInfoLoc (res->sref)) {
10129 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10130 sRef_showStateInfo (res->sref);
10133 if (sRef_hasStateInfoLoc (other->sref)) {
10134 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10135 sRef_showStateInfo (other->sref);
10138 else if (sRef_isKept (res->sref))
10140 if (sRef_hasAliasInfoLoc (res->sref)) {
10141 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10142 sRef_showAliasInfo (res->sref);
10145 if (sRef_hasAliasInfoLoc (other->sref)) {
10146 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10147 sRef_showAliasInfo (other->sref);
10150 else /* dependent */
10152 if (sRef_hasAliasInfoLoc (res->sref)) {
10153 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10154 sRef_showAliasInfo (res->sref);
10157 if (sRef_hasAliasInfoLoc (other->sref)) {
10158 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10159 sRef_showAliasInfo (other->sref);
10163 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
10167 static bool uentry_incompatibleMemoryStates (sRef rs, sRef os)
10169 alkind rk = sRef_getAliasKind (rs);
10170 alkind ok = sRef_getAliasKind (os);
10172 if (alkind_isError (rk) || alkind_isError (ok))
10178 return ((sRef_isDead (rs)
10179 || (alkind_isKept (rk) && !alkind_isKept (ok))
10180 || (alkind_isDependent (rk)
10181 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
10182 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
10187 branchStateAltError (/*@notnull@*/ uentry res,
10188 /*@notnull@*/ uentry other, bool flip,
10189 clause cl, fileloc loc)
10193 message ("%s %q is %s %s, but %s %s.",
10194 ekind_capName (res->ukind), uentry_getName (res),
10195 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
10196 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
10199 if (sRef_isDead (other->sref))
10201 if (sRef_hasStateInfoLoc (other->sref)) {
10202 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10203 sRef_showStateInfo (other->sref);
10206 if (sRef_hasStateInfoLoc (res->sref)) {
10207 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10208 sRef_showStateInfo (res->sref);
10213 if (sRef_hasAliasInfoLoc (other->sref)) {
10214 llgenindentmsg (message ("%s:", clause_nameFlip (cl, flip)), loc);
10215 sRef_showAliasInfo (other->sref);
10218 if (sRef_hasAliasInfoLoc (res->sref)) {
10219 llgenindentmsg (message ("%s:", clause_nameFlip (cl, !flip)), loc);
10220 sRef_showAliasInfo (res->sref);
10224 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
10225 sRef_setDefinedComplete (res->sref, fileloc_undefined);
10227 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
10228 sRef_setDefinedComplete (other->sref, fileloc_undefined);
10233 ** A reference is relevant for certain checks, only if it
10234 ** is not definitely null on this path (but not declared
10235 ** to always be null.)
10238 static bool uentry_relevantReference (sRef sr, bool flip)
10240 if (sRef_isKept (sr) || sRef_isDependent (sr))
10248 return !sRef_definitelyNullContext (sr);
10252 return !sRef_definitelyNullAltContext (sr);
10258 uentry_mergeAliasStates (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10259 fileloc loc, bool mustReturn, bool flip, bool opt,
10262 sRef rs = res->sref;
10263 sRef os = other->sref;
10265 DPRINTF (("Merge alias states: %s / %s",
10266 uentry_unparseFull (res),
10267 uentry_unparseFull (other)));
10269 if (sRef_isValid (rs))
10273 if (uentry_incompatibleMemoryStates (rs, os))
10275 DPRINTF (("Incompatible: \n\t%s / \n\t%s",
10276 sRef_unparseFull (rs), sRef_unparseFull (os)));
10278 if (sRef_isThroughArrayFetch (rs)
10279 && !context_getFlag (FLG_STRICTBRANCHSTATE))
10281 if (sRef_isKept (rs) || sRef_isKept (os))
10283 sRef_maybeKill (rs, loc);
10285 else if (sRef_isPossiblyDead (os))
10287 sRef_maybeKill (rs, loc);
10296 if (uentry_relevantReference (os, flip))
10298 if (sRef_isLocalParamVar (rs)
10299 && (sRef_isLocalState (os)
10300 || sRef_isDependent (os)))
10302 if (sRef_isDependent (rs))
10304 sRef_setDependent (os, loc);
10308 sRef_setDefState (rs, SS_UNUSEABLE, loc);
10313 branchStateError (res, other, !flip, cl, loc); /* evans 2002-12-15: changed flip to !flip */
10318 if (sRef_isKept (rs))
10320 DPRINTF (("Setting kept: %s", sRef_unparseFull (os)));
10321 sRef_setKept (os, loc);
10326 if (uentry_incompatibleMemoryStates (os, rs))
10328 if (uentry_relevantReference (rs, !flip))
10330 if (sRef_isLocalParamVar (rs)
10331 && (sRef_isDependent (rs)
10332 || sRef_isLocalState (rs)))
10334 if (sRef_isDependent (os))
10336 sRef_setDependent (rs, loc);
10340 sRef_setDefState (rs, SS_UNUSEABLE, loc);
10345 if (sRef_isParam (os))
10348 ** If the local variable associated
10349 ** with the param has the correct state,
10351 ** (e.g., free (s); s = new(); ...
10354 uentry uvar = usymtab_lookupSafe (other->uname);
10356 if (uentry_isValid (uvar)
10357 && ((sRef_isDead (os)
10358 && sRef_isOnly (uvar->sref))
10359 || (sRef_isDependent (os)
10360 && sRef_isOwned (uvar->sref))))
10366 branchStateAltError (res, other,
10372 DPRINTF (("Here: %s / %s",
10373 uentry_unparseFull (res),
10374 uentry_unparseFull (other)));
10376 branchStateAltError (res, other,
10383 if (sRef_isKept (os))
10385 sRef_setKept (rs, loc);
10391 DPRINTF (("Merge opt..."));
10392 sRef_mergeOptState (rs, os, cl, loc);
10393 DPRINTF (("Done!"));
10397 DPRINTF (("Merging states: \n\t%s / \n\t%s", sRef_unparseFull (rs), sRef_unparseFull (os)));
10398 sRef_mergeState (rs, os, cl, loc);
10399 DPRINTF (("After merging : \n\t%s / \n\t%s", sRef_unparseFull (rs), sRef_unparseFull (os)));
10404 if (sRef_isModified (os))
10406 sRef_setModified (rs);
10411 DPRINTF (("After merge: %s", sRef_unparseFull (res->sref)));
10415 uentry_mergeValueStates (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
10416 fileloc loc, bool mustReturn, /*@unused@*/ bool flip)
10418 valueTable rvalues;
10419 valueTable ovalues;
10421 DPRINTF (("Merge values: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
10429 rvalues = sRef_getValueTable (res->sref);
10430 ovalues = sRef_getValueTable (other->sref);
10432 if (valueTable_isUndefined (ovalues))
10434 DPRINTF (("No value table: %s", sRef_unparseFull (other->sref)));
10437 else if (valueTable_isUndefined (rvalues))
10440 ** Copy values from other
10447 valueTable_elements (ovalues, fkey, fval) {
10449 metaStateInfo minfo;
10450 stateCombinationTable sctable;
10454 tval = valueTable_lookup (rvalues, fkey);
10456 DPRINTF (("Merge value: %s / %s X %s", fkey,
10457 stateValue_unparse (fval), stateValue_unparse (tval)));
10459 minfo = context_lookupMetaStateInfo (fkey);
10460 llassert (stateValue_isDefined (tval));
10462 if (metaStateInfo_isUndefined (minfo) || !stateValue_isDefined (tval))
10464 DPRINTF (("Cannot find meta state for: %s", fkey));
10469 llassert (metaStateInfo_isDefined (minfo));
10471 if (stateValue_isError (fval)
10472 || sRef_definitelyNullContext (res->sref))
10474 sRef_setMetaStateValueComplete (res->sref,
10475 fkey, stateValue_getValue (fval),
10476 stateValue_getLoc (fval));
10477 DPRINTF (("Setting res: %s", sRef_unparseFull (res->sref)));
10479 else if (stateValue_isError (tval)
10480 || sRef_definitelyNullAltContext (other->sref))
10482 DPRINTF (("Other branch is definitely null!"));
10484 else if (sRef_isStateUndefined (res->sref)
10485 || sRef_isDead (res->sref))
10487 ; /* Combination state doesn't matter if it is undefined or dead */
10491 DPRINTF (("Check: %s / %s / %s / %s", fkey,
10492 metaStateInfo_unparse (minfo),
10493 stateValue_unparse (fval),
10494 stateValue_unparse (tval)));
10496 DPRINTF (("state values: %d / %d",
10497 stateValue_getValue (fval), stateValue_getValue (tval)));
10499 sctable = metaStateInfo_getMergeTable (minfo);
10501 DPRINTF (("Merge table: %s",
10502 stateCombinationTable_unparse (sctable)));
10504 msg = cstring_undefined;
10506 nval = stateCombinationTable_lookup (sctable,
10507 stateValue_getValue (fval),
10508 stateValue_getValue (tval),
10511 DPRINTF (("nval: %d / %d / %d", nval,
10512 stateValue_getValue (fval), stateValue_getValue (tval)));
10514 if (nval == stateValue_error)
10516 if (uentry_isGlobalMarker (res))
10521 ("Control branches merge with incompatible global states (%s and %s)%q",
10522 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10523 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10524 cstring_isDefined (msg)
10525 ? message (": %s", msg) : cstring_undefined),
10528 sRef_showMetaStateInfo (res->sref, fkey);
10529 sRef_showMetaStateInfo (other->sref, fkey);
10537 ("Control branches merge with incompatible states for %q (%s and %s)%q",
10538 uentry_getName (res),
10539 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10540 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10541 cstring_isDefined (msg)
10542 ? message (": %s", msg) : cstring_undefined),
10545 sRef_showMetaStateInfo (res->sref, fkey);
10546 sRef_showMetaStateInfo (other->sref, fkey);
10547 DPRINTF (("Res: %s", sRef_unparseFull (res->sref)));
10548 DPRINTF (("Other: %s", sRef_unparseFull (other->sref)));
10549 DPRINTF (("Null: %s / %s",
10550 bool_unparse (usymtab_isDefinitelyNull (res->sref)),
10551 bool_unparse (usymtab_isDefinitelyNull (other->sref))));
10557 if (nval == stateValue_getValue (fval)
10558 && nval != stateValue_getValue (tval))
10560 loc = stateValue_getLoc (fval);
10562 else if (nval == stateValue_getValue (tval)
10563 && nval != stateValue_getValue (fval))
10565 loc = stateValue_getLoc (tval);
10572 if (stateValue_getValue (sRef_getMetaStateValue (res->sref, fkey)) == nval
10573 && nval == stateValue_getValue (fval)
10574 && nval == stateValue_getValue (tval))
10580 sRef_setMetaStateValueComplete (res->sref, fkey, nval, loc);
10584 } end_valueTable_elements ;
10590 uentry_mergeSetStates (/*@notnull@*/ uentry res,
10591 /*@notnull@*/ uentry other, /*@unused@*/ fileloc loc,
10592 bool flip, clause cl)
10594 if (cl == DOWHILECLAUSE)
10596 res->used = other->used || res->used;
10597 res->lset = other->lset || res->lset;
10598 res->uses = filelocList_append (res->uses, other->uses);
10599 other->uses = filelocList_undefined;
10603 if (sRef_isMacroParamRef (res->sref)
10604 && !uentry_isSefParam (other)
10605 && !uentry_isSefParam (res))
10607 bool hasError = FALSE;
10609 if (bool_equal (res->used, other->used))
10611 res->used = other->used;
10615 if (other->used && !flip)
10620 message ("Macro parameter %q used in true clause, "
10621 "but not in false clause",
10622 uentry_getName (res)),
10623 uentry_whereDeclared (res));
10630 message ("Macro parameter %q used in false clause, "
10631 "but not in true clause",
10632 uentry_getName (res)),
10633 uentry_whereDeclared (res));
10639 /* make it sef now, prevent more errors */
10640 res->info->var->kind = VKREFSEFPARAM;
10646 res->used = other->used || res->used;
10647 res->lset = other->lset || res->lset;
10648 res->uses = filelocList_append (res->uses, other->uses);
10649 other->uses = filelocList_undefined;
10655 uentry_mergeState (uentry res, uentry other, fileloc loc,
10656 bool mustReturn, bool flip, bool opt,
10659 llassert (uentry_isValid (res));
10660 llassert (uentry_isValid (other));
10662 llassert (res->ukind == other->ukind);
10663 llassert (res->ukind == KVAR);
10665 DPRINTF (("Merge state: %s / %s", uentry_unparseFull (res),
10666 uentry_unparseFull (other)));
10668 uentry_mergeAliasStates (res, other, loc, mustReturn, flip, opt, cl);
10669 uentry_mergeValueStates (res, other, loc, mustReturn, flip);
10670 uentry_mergeSetStates (res, other, loc, flip, cl);
10672 DPRINTF (("Merge ==> %s", uentry_unparseFull (res)));
10675 void uentry_setUsed (uentry e, fileloc loc)
10677 static bool firstTime = TRUE;
10678 static bool showUses = FALSE;
10679 static bool exportLocal = FALSE;
10681 DPRINTF (("Used: %s / %s", uentry_unparse (e), fileloc_unparse (loc)));
10685 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
10687 showUses = context_getFlag (FLG_SHOWUSES);
10688 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
10693 if (uentry_isValid (e))
10695 if (warnClause_isDefined (e->warn))
10697 flagSpec flg = warnClause_getFlag (e->warn);
10700 if (warnClause_hasMessage (e->warn))
10702 msg = cstring_copy (warnClause_getMessage (e->warn));
10706 msg = message ("Use of possibly dangerous %s",
10707 uentry_ekindNameLC (e));
10711 message ("%q: %q", msg, uentry_getName (e)),
10715 if (sRef_isMacroParamRef (e->sref))
10717 if (uentry_isYield (e) || uentry_isSefParam (e))
10723 if (context_inConditional ())
10727 message ("Macro parameter %q used in conditionally "
10728 "executed code (may or may not be "
10729 "evaluated exactly once)",
10730 uentry_getName (e)),
10733 e->info->var->kind = VKREFSEFPARAM;
10742 message ("Macro parameter %q used more than once",
10743 uentry_getName (e)),
10744 uentry_whereDeclared (e)))
10746 e->info->var->kind = VKREFSEFPARAM;
10753 if (usymId_isValid (usymtab_directParamNo (e)))
10755 uentry_setUsed (usymtab_getParam (usymId_toInt (usymtab_directParamNo (e))), loc);
10760 if (!sRef_isLocalVar (e->sref))
10764 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
10770 if (context_inMacro ())
10772 e->uses = filelocList_addUndefined (e->uses);
10776 e->uses = filelocList_addDifferentFile
10778 uentry_whereDeclared (e),
10787 bool uentry_isReturned (uentry u)
10789 return (uentry_isValid (u) && uentry_isVar (u)
10790 && (u->info->var->kind == VKRETPARAM
10791 || u->info->var->kind == VKSEFRETPARAM));
10794 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args, fileloc loc)
10796 llassert (uentry_isRealFunction (u));
10798 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
10800 stateClauseList clauses = uentry_getStateClauseList (u);
10801 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10803 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
10804 sRef_setAllocated (res, loc);
10806 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10807 stateClauseList_unparse (clauses)));
10810 ** This should be in exprNode_reflectEnsuresClause
10813 stateClauseList_postElements (clauses, cl)
10815 if (!stateClause_isGlobal (cl))
10817 sRefSet refs = stateClause_getRefs (cl);
10818 sRefMod modf = stateClause_getEffectFunction (cl);
10820 sRefSet_elements (refs, el)
10822 sRef base = sRef_getRootBase (el);
10824 if (sRef_isResult (base))
10828 sRef sr = sRef_fixBase (el, res);
10836 } end_sRefSet_elements ;
10838 } end_stateClauseList_postElements ;
10846 sRefSet prefs = sRefSet_new ();
10847 sRef res = sRef_undefined;
10850 params = uentry_getParams (u);
10852 uentryList_elements (params, current)
10854 if (uentry_isReturned (current))
10856 if (exprNodeList_size (args) >= paramno)
10858 exprNode ecur = exprNodeList_nth (args, paramno);
10859 sRef tref = exprNode_getSref (ecur);
10861 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10863 if (sRef_isValid (tref))
10865 sRef tcref = sRef_copy (tref);
10867 usymtab_addForceMustAlias (tcref, tref); /* evans 2001-05-27 */
10869 if (sRef_isNew (tcref))
10871 /* tcref->kind = SK_OBJECT; */ /*!! Not new anymore */
10874 if (sRef_isDead (tcref))
10876 sRef_setDefined (tcref, loc);
10877 sRef_setOnly (tcref, loc);
10880 if (sRef_isRefCounted (tcref))
10882 /* could be a new ref now (but only if its returned) */
10883 sRef_setAliasKindComplete (tcref, AK_ERROR, loc);
10886 sRef_makeSafe (tcref);
10887 DPRINTF (("Returns tcref / %s", sRef_unparseFull (tcref)));
10888 prefs = sRefSet_insert (prefs, tcref);
10894 } end_uentryList_elements ;
10896 if (sRefSet_size (prefs) > 0)
10898 nstate n = sRef_getNullState (u->sref);
10900 if (sRefSet_size (prefs) == 1)
10902 res = sRefSet_choose (prefs);
10906 /* should this ever happen? */
10907 res = sRefSet_mergeIntoOne (prefs);
10910 if (nstate_isKnown (n))
10912 sRef_setNullState (res, n, loc);
10917 if (ctype_isFunction (u->utype))
10919 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10920 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10924 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
10927 if (sRef_isRefCounted (res))
10929 sRef_setAliasKind (res, AK_NEWREF, loc);
10934 if (sRef_getNullState (res) == NS_ABSNULL)
10936 ctype ct = ctype_realType (u->utype);
10938 if (ctype_isAbstract (ct))
10940 sRef_setNotNull (res, loc);
10944 if (ctype_isUser (ct))
10946 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
10950 sRef_setNotNull (res, loc);
10955 if (sRef_isRefCounted (res))
10957 sRef_setAliasKind (res, AK_NEWREF, loc);
10959 else if (sRef_isKillRef (res))
10961 sRef_setAliasKind (res, AK_REFCOUNTED, loc);
10968 ak = sRef_getAliasKind (res);
10970 if (alkind_isImplicit (ak))
10972 sRef_setAliasKind (res,
10973 alkind_fixImplicit (ak),
10977 sRefSet_free (prefs);
10980 if (sRef_isOnly (res))
10982 sRef_setFresh (res, loc);
10986 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
10991 static bool uentry_isRefCounted (uentry ue)
10993 ctype ct = uentry_getType (ue);
10995 if (ctype_isFunction (ct))
10997 return (ctype_isRefCounted (ctype_getReturnType (ct)));
11001 return (ctype_isRefCounted (ct));
11006 ** old was declared yield in the specification.
11007 ** new is declared in the iter implementation.
11010 void uentry_checkYieldParam (uentry old, uentry unew)
11014 llassert (uentry_isVariable (old));
11015 llassert (uentry_isVariable (unew));
11017 unew->info->var->kind = VKYIELDPARAM;
11018 (void) checkTypeConformance (old, unew, TRUE);
11019 checkVarConformance (old, unew, TRUE, FALSE);
11021 /* get rid of param marker */
11023 name = uentry_getName (unew);
11024 cstring_free (unew->uname);
11025 unew->uname = name;
11026 unew->info->var->kind = VKREFYIELDPARAM;
11028 uentry_setUsed (old, fileloc_undefined);
11029 uentry_setUsed (unew, fileloc_undefined);
11032 /*@observer@*/ cstring
11033 uentry_ekindName (uentry ue)
11035 if (uentry_isValid (ue))
11040 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
11042 return cstring_makeLiteralTemp ("Datatype");
11044 return cstring_makeLiteralTemp ("Enum member");
11046 return cstring_makeLiteralTemp ("Constant");
11048 if (uentry_isParam (ue))
11050 return cstring_makeLiteralTemp ("Parameter");
11052 else if (uentry_isExpandedMacro (ue))
11054 return cstring_makeLiteralTemp ("Expanded macro");
11058 return cstring_makeLiteralTemp ("Variable");
11061 return cstring_makeLiteralTemp ("Function");
11063 return cstring_makeLiteralTemp ("Iterator");
11065 return cstring_makeLiteralTemp ("Iterator finalizer");
11067 return cstring_makeLiteralTemp ("Struct tag");
11069 return cstring_makeLiteralTemp ("Union tag");
11071 return cstring_makeLiteralTemp ("Enum tag");
11073 return cstring_makeLiteralTemp ("Optional parameters");
11078 return cstring_makeLiteralTemp ("<Undefined>");
11084 /*@observer@*/ cstring
11085 uentry_ekindNameLC (uentry ue)
11087 if (uentry_isValid (ue))
11092 return cstring_makeLiteralTemp ("<error: invalid uentry>");
11094 return cstring_makeLiteralTemp ("datatype");
11096 return cstring_makeLiteralTemp ("enum member");
11098 return cstring_makeLiteralTemp ("constant");
11100 if (uentry_isParam (ue))
11102 return cstring_makeLiteralTemp ("parameter");
11104 else if (uentry_isExpandedMacro (ue))
11106 return cstring_makeLiteralTemp ("expanded macro");
11110 return cstring_makeLiteralTemp ("variable");
11113 return cstring_makeLiteralTemp ("function");
11115 return cstring_makeLiteralTemp ("iterator");
11117 return cstring_makeLiteralTemp ("iterator finalizer");
11119 return cstring_makeLiteralTemp ("struct tag");
11121 return cstring_makeLiteralTemp ("union tag");
11123 return cstring_makeLiteralTemp ("enum tag");
11125 return cstring_makeLiteralTemp ("optional parameters");
11130 return cstring_makeLiteralTemp ("<Undefined>");
11136 void uentry_setHasNameError (uentry ue)
11138 llassert (uentry_isValid (ue));
11140 ue->hasNameError = TRUE;
11143 void uentry_checkName (uentry ue)
11145 DPRINTF (("Checking name: %s / %s / %s", uentry_unparse (ue),
11146 uentry_observeRealName (ue),
11147 bool_unparse (uentry_isVisibleExternally (ue))));
11149 if (uentry_isValid (ue)
11150 && !context_inXHFile ()
11151 && uentry_hasName (ue)
11152 && !uentry_isElipsisMarker (ue)
11153 && context_getFlag (FLG_NAMECHECKS)
11154 && !ue->hasNameError
11155 && !uentry_isEndIter (ue)
11156 && !fileloc_isBuiltin (uentry_whereLast (ue))
11157 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
11159 DPRINTF (("Here..."));
11161 if (uentry_isPriv (ue))
11163 ; /* any checks here? */
11165 else if (fileloc_isExternal (uentry_whereDefined (ue)))
11167 ; /* no errors for externals */
11173 if (uentry_isExpandedMacro (ue))
11179 if (uentry_isExpandedMacro (ue))
11183 else if (uentry_isVariable (ue))
11185 sRef sr = uentry_getSref (ue);
11187 if (sRef_isValid (sr))
11189 scope = sRef_getScope (sr);
11196 else if (uentry_isFunction (ue)
11197 || uentry_isIter (ue)
11198 || uentry_isEndIter (ue)
11199 || uentry_isConstant (ue))
11201 scope = uentry_isStatic (ue) ? fileScope : globScope;
11203 else /* datatypes, etc. must be global */
11208 usymtab_checkDistinctName (ue, scope);
11211 if (context_getFlag (FLG_CPPNAMES))
11216 if (scope == globScope)
11218 checkExternalName (ue);
11220 else if (scope == fileScope)
11222 checkFileScopeName (ue);
11226 checkLocalName (ue);
11230 checkAnsiName (ue);
11235 /*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@only@*/ fileloc loc)
11241 ** Can't but unrecognized ids in macros in global scope, because srefs will break!
11244 if (!context_inMacro ())
11246 sRef_setGlobalScopeSafe ();
11249 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
11250 uentry_setUsed (ue, loc);
11252 tloc = fileloc_createExternal ();
11253 uentry_setDefined (ue, tloc);
11254 fileloc_free (tloc);
11255 uentry_setHasNameError (ue);
11257 if (context_getFlag (FLG_REPEATUNRECOG) || (context_inOldStyleScope()))
11259 uentry_markOwned (ue);
11263 ue = usymtab_supReturnFileEntry (ue);
11266 if (!context_inMacro ())
11268 sRef_clearGlobalScopeSafe ();
11274 uentry uentry_makeGlobalMarker ()
11279 llassert (sRef_inGlobalScope ());
11281 ue = uentry_makeVariableAux
11282 (GLOBAL_MARKER_NAME, ctype_unknown, fileloc_undefined,
11283 sRef_makeGlobalMarker (),
11286 tloc = fileloc_createExternal ();
11287 uentry_setUsed (ue, tloc);
11288 uentry_setDefined (ue, tloc);
11289 fileloc_free (tloc);
11290 uentry_setHasNameError (ue);
11296 bool uentry_isGlobalMarker (uentry ue)
11298 return (uentry_isValid (ue)
11299 && (cstring_equal (uentry_rawName (ue), GLOBAL_MARKER_NAME)));
11302 /* new start modifications */
11304 /* start modifications */
11306 requires: p_e is defined, is a ptr/array variable
11308 effects: sets the state of the variable
11312 void uentry_setPossiblyNullTerminatedState (uentry p_e)
11314 llassert (uentry_isValid (p_e));
11316 if (p_e->info != NULL)
11318 if (p_e->info->var != NULL)
11320 llassert (p_e->info->var->bufinfo != NULL);
11321 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
11322 sRef_setPossiblyNullTerminatedState (p_e->sref);
11328 requires: p_e is defined, is a ptr/array variable
11330 effects: sets the size of the buffer
11333 void uentry_setNullTerminatedState (uentry p_e) {
11334 llassert (uentry_isValid (p_e));
11336 if (p_e->info != NULL)
11338 if (p_e->info->var != NULL)
11340 llassert (p_e->info->var->bufinfo != NULL);
11341 p_e->info->var->bufinfo->bufstate = BB_NULLTERMINATED;
11342 sRef_setNullTerminatedState (p_e->sref);
11348 requires: p_e is defined, is a ptr/array variable
11350 effects: sets the size of the buffer
11353 void uentry_setSize (uentry p_e, int size)
11355 if (uentry_isValid (p_e))
11357 if (p_e->info != NULL)
11359 if (p_e->info->var != NULL)
11361 llassert (p_e->info->var->bufinfo != NULL);
11362 p_e->info->var->bufinfo->size = size;
11363 sRef_setSize (p_e->sref, size);
11370 requires: p_e is defined, is a ptr/array variable
11372 effects: sets the length of the buffer
11375 void uentry_setLen (uentry p_e, int len)
11377 if (uentry_isValid (p_e))
11379 if (p_e->info != NULL
11380 && p_e->info->var != NULL)
11382 llassert (p_e->info->var->bufinfo != NULL);
11383 p_e->info->var->bufinfo->len = len;
11384 sRef_setLen (p_e->sref, len);
11391 bool uentry_hasMetaStateEnsures (uentry e)
11393 if (uentry_isValid (e) && uentry_isFunction (e))
11395 return functionConstraint_hasMetaStateConstraint (e->info->fcn->postconditions);
11403 metaStateConstraintList uentry_getMetaStateEnsures (uentry e)
11405 llassert (uentry_isValid (e) && uentry_isFunction (e));
11406 return functionConstraint_getMetaStateConstraints (e->info->fcn->postconditions);
11410 bool uentry_hasBufStateInfo (uentry ue)
11412 llassert (uentry_isValid (ue));
11413 return (ue->info->var->bufinfo != NULL);
11416 bool uentry_isNullTerminated (uentry ue)
11418 llassert (uentry_hasBufStateInfo (ue));
11419 llassert (ue->info->var->bufinfo != NULL);
11420 return ue->info->var->bufinfo->bufstate == BB_NULLTERMINATED;
11423 bool uentry_isPossiblyNullTerminated (uentry ue)
11425 llassert (uentry_hasBufStateInfo (ue));
11426 llassert (ue->info->var->bufinfo != NULL);
11427 return (ue->info->var->bufinfo->bufstate == BB_POSSIBLYNULLTERMINATED);
11430 bool uentry_isNotNullTerminated (uentry ue)
11432 llassert (uentry_hasBufStateInfo (ue));
11433 llassert (ue->info->var->bufinfo != NULL);
11434 return (ue->info->var->bufinfo->bufstate == BB_NOTNULLTERMINATED);
11437 # ifdef DEBUGSPLINT
11440 ** For debugging only
11443 void uentry_checkValid (uentry ue)
11445 if (uentry_isValid (ue))
11447 sRef_checkCompletelyReasonable (ue->sref);