2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
28 # include "lclintMacros.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_combineModifies (uentry p_ue, /*@owned@*/ sRefSet p_sr)
49 static void uentry_addStateClause (uentry p_ue, /*@only@*/ stateClause p_sc)
53 static void checkAliasState (/*@notnull@*/ uentry p_old,
54 /*@notnull@*/ uentry p_unew,
55 bool p_mustConform, bool p_completeConform)
56 /*@modifies p_old, p_unew@*/ ;
57 static void checkNullState (/*@notnull@*/ uentry p_old,
58 /*@notnull@*/ uentry p_unew,
59 bool p_mustConform, bool p_completeConform)
60 /*@modifies p_old, p_unew@*/ ;
62 static void checkVarConformance (/*@notnull@*/ uentry p_old,
63 /*@notnull@*/ uentry p_unew,
64 bool p_mustConform, bool p_completeConform)
65 /*@modifies p_old, p_unew@*/;
68 static void uentry_setHasMods (uentry p_ue) /*@modifies p_ue@*/;
69 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_msgstream@*/ ;
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 void uentry_convertVarFunction (uentry ue) /*@modifies ue@*/
95 if (uentry_isVariable (ue)
96 && (ctype_isFunction (ctype_realType (uentry_getType (ue)))
97 || ctype_isUnknown (uentry_getType (ue))))
99 uentry_makeVarFunction (ue);
103 static /*@out@*/ /*@notnull@*/ uentry uentry_alloc (void) /*@*/
105 uentry ue = (uentry) dmalloc (sizeof (*ue));
106 ue->warn = warnClause_undefined; /*@i32@*/
113 static cstring uentry_getOptName (uentry p_e) /*@*/ ;
114 static void uentry_updateInto (/*@unique@*/ uentry p_unew, uentry p_old) /*@modifies p_unew, p_old@*/ ;
116 static void uentry_setNullState (/*@notnull@*/ uentry p_ue, nstate p_ns);
117 static void uentry_setAliasKind (/*@notnull@*/ uentry p_ue, alkind p_ak);
118 static /*@only@*/ /*@null@*/ uinfo uinfo_copy (uinfo p_u, ekind p_kind);
119 static void uinfo_free (/*@only@*/ uinfo p_u, ekind p_kind);
120 static void ucinfo_free (/*@only@*/ ucinfo p_u);
121 static void uvinfo_free (/*@only@*/ uvinfo p_u);
125 static /*@only@*/ cstring ancontext_unparse (ancontext an)
129 case AN_UNKNOWN: return cstring_makeLiteral ("unknown");
130 case AN_FCNRETURN: return cstring_makeLiteral ("return value");
131 case AN_FCNPARAM: return cstring_makeLiteral ("function param");
132 case AN_SUFIELD: return cstring_makeLiteral ("su field");
133 case AN_TDEFN: return cstring_makeLiteral ("type definition");
134 case AN_GSVAR: return cstring_makeLiteral ("global/static var");
135 case AN_CONST: return cstring_makeLiteral ("constant");
141 static int annots[AN_LAST][QU_LAST];
142 static int decls[AN_LAST];
143 static int shdecls[AN_LAST];
144 static int idecls[AN_LAST];
150 for (i = AN_UNKNOWN; i < AN_LAST; i++)
156 for (j = QU_UNKNOWN; j < QU_LAST; j++)
163 static void tallyAnnot (ancontext ac, qual q)
177 for (j = QU_UNKNOWN; j < QU_LAST; j++)
182 for (i = AN_UNKNOWN; i < AN_LAST; i++)
188 printf ("Context: %s (%d declarations, %d sharable, %d indirect)\n",
189 ancontext_unparse (i),
190 decls[i], shdecls[i], idecls[i]);
192 totdecls += decls[i];
193 totshdecls += shdecls[i];
194 totidecls += idecls[i];
196 for (j = QU_UNKNOWN; j < QU_LAST; j++)
198 total[j] += annots[i][j];
199 alltotals += annots[i][j];
202 printf (" Allocation:\n");
206 for (j = QU_UNKNOWN; j < QU_LAST; j++)
208 if (qual_isAliasQual (j) && !qual_isUnique (j))
210 if (annots[i][j] > 0)
212 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
213 100.0 * (double)annots[i][j] / (double)decls[i]);
214 tmptot += annots[i][j];
219 printf (" Exposure:\n");
223 for (j = QU_UNKNOWN; j < QU_LAST; j++)
225 if (qual_isExQual (j))
227 if (annots[i][j] > 0)
229 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
230 100.0 * (double)annots[i][j] / (double)decls[i]);
231 tmptot += annots[i][j];
236 printf (" Definition:\n");
238 for (j = QU_UNKNOWN; j < QU_LAST; j++)
240 if (qual_isAllocQual (j))
242 if (annots[i][j] > 0)
244 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
245 100.0 * (double)annots[i][j] / (double)decls[i]);
252 for (j = QU_UNKNOWN; j < QU_LAST; j++)
254 if (qual_isNull (j) || qual_isNotNull (j) || qual_isRelNull (j))
256 if (annots[i][j] > 0)
258 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
259 100.0 * (double)annots[i][j] / (double)decls[i]);
268 for (j = QU_UNKNOWN; j < QU_LAST; j++)
272 for (i = AN_UNKNOWN; i < AN_LAST; i++)
274 if (annots[i][j] > 0)
283 printf ("Annotation: %s\n", qual_unparse (j));
285 for (i = AN_UNKNOWN; i < AN_LAST; i++)
287 if (annots[i][j] > 0)
289 printf ("%25s: %5d\n", ancontext_unparse (i), annots[i][j]);
296 printf ("All Contexts\n");
298 for (j = QU_UNKNOWN; j < QU_LAST; j++)
302 printf ("%10s: %5d (%3.2f%%)\n", qual_unparse (j), total[j],
303 100.0 * (double)total[j] / (double)(totdecls));
308 printf ("Total Annotations: %d (%d decls, %d sharable, %d indirect)\n", alltotals, totdecls, totshdecls, totidecls); }
310 extern void uentry_tallyAnnots (uentry u, ancontext kind)
312 alkind ak = sRef_getAliasKind (u->sref);
313 exkind ek = sRef_getExKind (u->sref);
314 nstate ns = sRef_getNullState (u->sref);
315 sstate ss = sRef_getDefState (u->sref);
316 bool recordUnknown = FALSE;
318 if (kind == AN_UNKNOWN)
326 else if (e == KCONST || e == KENUMCONST)
330 else if (e == KFCN || e == KITER)
332 uentryList params = uentry_getParams (u);
335 uentryList_elements (params, current)
337 if (uentry_isReturned (current))
341 if (!uentry_isElipsisMarker (current))
343 uentry_tallyAnnots (current, AN_FCNPARAM);
345 } end_uentryList_elements;
349 if (ctype_isFunction (u->utype)
351 && ctype_isVisiblySharable (ctype_realType (ctype_getReturnType (u->utype))))
353 recordUnknown = TRUE;
356 else if (e == KDATATYPE || e == KSTRUCTTAG || e == KUNIONTAG || e == KENUMTAG)
358 ctype t = ctype_realType (u->utype);
362 uentryList fields = ctype_getFields (t);
364 uentryList_elements (fields, current)
366 uentry_tallyAnnots (current, AN_SUFIELD);
368 } end_uentryList_elements;
372 if (ctype_isVisiblySharable (u->utype))
374 recordUnknown = TRUE;
382 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
384 recordUnknown = TRUE;
391 if (kind == AN_FCNRETURN)
405 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
410 if (ctype_isRealPointer (ctype_realType (u->utype)))
418 case SS_ALLOCATED: tallyAnnot (kind, QU_OUT); break;
419 case SS_PARTIAL: tallyAnnot (kind, QU_PARTIAL); break;
420 case SS_RELDEF: tallyAnnot (kind, QU_RELDEF); break;
421 case SS_SPECIAL: tallyAnnot (kind, QU_SPECIAL); break;
425 if (uentry_isReturned (u))
427 tallyAnnot (kind, QU_RETURNED);
433 if (ctype_isRefCounted (ctype_realType (u->utype))
434 || (ctype_isFunction (u->utype) &&
435 ctype_isRefCounted (ctype_realType (ctype_getReturnType (u->utype)))))
441 if (kind == AN_FCNPARAM)
443 tallyAnnot (kind, QU_TEMP);
445 else if (recordUnknown)
447 if (kind == AN_FCNRETURN)
450 tallyAnnot (kind, QU_UNKNOWN);
454 case AK_ONLY: tallyAnnot (kind, QU_ONLY); break;
455 case AK_IMPONLY: tallyAnnot (kind, QU_ONLY); break;
456 case AK_KEEP: tallyAnnot (kind, QU_KEEP); break;
457 case AK_KEPT: tallyAnnot (kind, QU_KEPT); break;
459 case AK_TEMP: tallyAnnot (kind, QU_TEMP); break;
460 case AK_SHARED: tallyAnnot (kind, QU_SHARED); break;
461 case AK_UNIQUE: tallyAnnot (kind, QU_UNIQUE); break;
462 case AK_RETURNED: tallyAnnot (kind, QU_RETURNED); break;
463 case AK_REFCOUNTED: tallyAnnot (kind, QU_UNKNOWN); break;
464 case AK_REFS: tallyAnnot (kind, QU_REFS); break;
465 case AK_KILLREF: tallyAnnot (kind, QU_KILLREF); break;
466 case AK_NEWREF: tallyAnnot (kind, QU_NEWREF); break;
467 case AK_OWNED: tallyAnnot (kind, QU_OWNED); break;
468 case AK_IMPDEPENDENT:
469 case AK_DEPENDENT: tallyAnnot (kind, QU_DEPENDENT); break;
479 case XO_EXPOSED: tallyAnnot (kind, QU_EXPOSED); break;
480 case XO_OBSERVER: tallyAnnot (kind, QU_OBSERVER); break;
486 case NS_ERROR: break;
487 case NS_UNKNOWN: break;
488 case NS_NOTNULL: break;
489 case NS_MNOTNULL: tallyAnnot (kind, QU_NOTNULL); break;
490 case NS_RELNULL: tallyAnnot (kind, QU_RELNULL); break;
491 case NS_CONSTNULL: tallyAnnot (kind, QU_NULL); break;
492 case NS_POSNULL: tallyAnnot (kind, QU_NULL); break;
494 case NS_ABSNULL: break;
500 static /*@observer@*/ cstring specCode_unparse (specCode s) /*@*/
504 case SPC_NONE: return cstring_makeLiteralTemp ("normal");
505 case SPC_PRINTFLIKE: return cstring_makeLiteralTemp ("printflike");
506 case SPC_SCANFLIKE: return cstring_makeLiteralTemp ("scanflike");
507 case SPC_MESSAGELIKE: return cstring_makeLiteralTemp ("messagelike");
508 case SPC_LAST: return cstring_makeLiteralTemp ("<error>");
514 static specCode specCode_fromInt (int i)
517 llassert (i >= SPC_NONE && i < SPC_LAST);
519 return ((specCode) i);
523 /*@observer@*/ cstring uentry_specOrDefName (uentry u)
525 if (uentry_isDeclared (u))
527 return cstring_makeLiteralTemp ("previously declared");
531 return cstring_makeLiteralTemp ("specified");
535 /*@observer@*/ cstring uentry_specDeclName (uentry u)
537 if (uentry_isDeclared (u))
539 return cstring_makeLiteralTemp ("previous declaration");
543 return cstring_makeLiteralTemp ("specification");
547 static /*@observer@*/ cstring uentry_reDefDecl (uentry old, uentry unew) /*@*/
549 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
551 return cstring_makeLiteralTemp ("redefined");
553 else if (uentry_isCodeDefined (unew))
555 return cstring_makeLiteralTemp ("defined");
557 else if (uentry_isDeclared (old) && uentry_isDeclared (unew))
559 return cstring_makeLiteralTemp ("redeclared");
563 return cstring_makeLiteralTemp ("declared");
567 static constraintList uentry_getFunctionConditions (uentry ue, bool isPost)
569 if (uentry_isValid (ue))
571 functionConstraint constraint;
573 DPRINTF( (message ("called uentry_getFcnPostconditions on %s",
574 uentry_unparse (ue) ) ) );
576 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
578 DPRINTF( (message ("called uentry_getFunctionConditions on nonfunction %s",
579 uentry_unparse (ue) ) ) );
580 if (!uentry_isFunction (ue) )
582 DPRINTF((message ("called uentry_getFunctionConditions on nonfunction %s",
583 uentry_unparse (ue) ) ));
584 return constraintList_undefined;
588 return constraintList_undefined;
591 if (!uentry_isFunction(ue))
594 DPRINTF( (message ("called uentry_getFunctionConditions on non function %s",
595 uentry_unparse (ue) ) ) );
596 return constraintList_undefined;
600 llassert (uentry_isFunction (ue));
604 constraint = ue->info->fcn->postconditions;
608 constraint = ue->info->fcn->preconditions;
611 return functionConstraint_getBufferConstraints (constraint);
614 return constraintList_undefined;
619 /*@only@*/ constraintList uentry_getFcnPreconditions (uentry ue)
621 return uentry_getFunctionConditions (ue, FALSE);
628 constraintList uentry_getFcnPostconditions (uentry ue)
630 return uentry_getFunctionConditions (ue, TRUE);
633 static /*@only@*/ fileloc setLocation (void)
635 fileloc fl = context_getSaveLocation ();
637 if (fileloc_isDefined (fl))
643 return fileloc_copy (g_currentloc);
647 static void uentry_setConstantValue (uentry ue, /*@only@*/ multiVal val)
649 llassert (uentry_isEitherConstant (ue));
650 sRef_setValue (ue->sref, val);
653 /*@notnull@*/ uentry uentry_makeEnumConstant (cstring n, ctype t)
655 fileloc loc = setLocation ();
656 uentry ue = uentry_makeConstant (n, t, loc);
658 ue->ukind = KENUMCONST;
659 uentry_setDefined (ue, loc);
663 /*@notnull@*/ uentry uentry_makeEnumInitializedConstant (cstring n, ctype t, exprNode expr)
665 fileloc loc = setLocation ();
666 uentry ue = uentry_makeConstant (n, t, loc);
667 ctype etype = exprNode_getType (expr);
669 if (!ctype_isRealInt (etype)) {
673 ("Value of enum member is not an integeral type (type %s): %s",
674 ctype_unparse (etype), exprNode_unparse (expr)),
675 exprNode_loc (expr));
678 ue->ukind = KENUMCONST;
679 uentry_setDefined (ue, loc);
684 /*@notnull@*/ uentry uentry_makeSpecEnumConstant (cstring n, ctype t, fileloc loc)
686 uentry ue = uentry_makeConstant (n, t, loc);
688 ue->ukind = KENUMCONST;
693 /*@notnull@*/ uentry uentry_makeVariableLoc (cstring n, ctype t)
695 return uentry_makeVariable (n, t, setLocation (), FALSE);
699 /*@notnull@*/ /*@only@*/ uentry uentry_makeUnnamedVariable (ctype t)
701 return uentry_makeVariable (cstring_undefined, t, setLocation (), FALSE);
705 /*@notnull@*/ uentry uentry_makeIdDatatype (idDecl id)
707 ctype ct = idDecl_getCtype (id);
708 uentry ue = uentry_makeDatatype (idDecl_observeId (id), ct,
709 MAYBE, MAYBE, setLocation ());
711 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
713 if (!ynm_isOn (ue->info->datatype->abs))
715 if (ctype_isUnknown (ct))
717 ue->info->datatype->mut = MAYBE;
721 ue->info->datatype->mut = ynm_fromBool (ctype_isMutable (ct));
728 void uentry_checkParams (uentry ue)
730 if (uentry_isValid (ue))
732 bool isExt = uentry_isExtern (ue);
734 if (uentry_isRealFunction (ue))
736 uentryList params = uentry_getParams (ue);
738 uentryList_elements (params, current)
740 if (uentry_isValid (current))
742 ctype ct = current->utype;
744 if (ctype_isFixedArray (ct))
746 if (ctype_isArray (ctype_baseArrayPtr (ct))
747 && !ctype_isFixedArray (ctype_baseArrayPtr (ct)))
754 (FLG_FIXEDFORMALARRAY,
755 message ("Function parameter %q declared as "
756 "manifest array (size constant is meaningless)",
757 uentry_getName (current)),
758 uentry_whereDeclared (current));
763 if (ctype_isArray (ct))
767 message ("Function parameter %q declared as "
768 "array (treated as pointer)",
769 uentry_getName (current)),
770 uentry_whereDeclared (current));
774 if (sRef_getNullState (uentry_getSref (current)) == NS_MNOTNULL)
776 if (ctype_isAbstract (ct) &&
777 (isExt || (ctype_isAbstract (ctype_realType (ct))
778 && !context_hasFileAccess (ctype_typeId (ct)))))
783 ("Function %q declared with notnull parameter %q of abstract "
786 uentry_getName (current),
789 ("Since %s is an abstract type, notnull can only be "
790 "used for parameters if the function is static to a "
791 "module where %s is accessible.",
794 uentry_whereDeclared (current));
798 } end_uentryList_elements;
800 if (sRef_getNullState (uentry_getSref (ue)) == NS_MNOTNULL)
802 ctype ct = ue->utype;
804 if (ctype_isAbstract (ct)
805 && (isExt || (ctype_isAbstract (ctype_realType (ct))
806 && !context_hasFileAccess (ctype_typeId (ct)))))
811 ("%s %q declared %s notnull storage of abstract type %s",
812 ekind_capName (uentry_getKind (ue)),
817 ("Since %s is an abstract type, notnull can only be used "
818 "if it is static to a module where %s is accessible.",
821 uentry_whereDeclared (ue));
828 static void reflectImplicitFunctionQualifiers (/*@notnull@*/ uentry ue, bool spec)
830 alkind ak = sRef_getAliasKind (ue->sref);
832 if (alkind_isRefCounted (ak))
834 sRef_setAliasKind (ue->sref, AK_NEWREF, fileloc_undefined);
838 if (alkind_isUnknown (ak))
840 exkind ek = sRef_getExKind (ue->sref);
842 if (exkind_isKnown (ek))
844 DPRINTF (("Setting imp dependent: %s",
845 uentry_unparseFull (ue)));
846 sRef_setAliasKind (ue->sref, AK_IMPDEPENDENT, fileloc_undefined);
850 if (context_getFlag (spec ? FLG_SPECRETIMPONLY : FLG_RETIMPONLY))
852 /* evans 2000-12-22 removed ctype_realType so it will
853 not apply to immutable abstract types. */
855 if (ctype_isVisiblySharable
856 (ctype_realType (ctype_getReturnType (ue->utype))))
858 if (uentryList_hasReturned (uentry_getParams (ue)))
864 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
866 ; /* Immutable objects are not shared. */
870 sRef_setAliasKind (ue->sref, AK_IMPONLY,
872 DPRINTF (("Ret imp only: %s",
873 ctype_unparse (ctype_getReturnType (ue->utype))));
883 static /*@notnull@*/ uentry
884 uentry_makeFunctionAux (cstring n, ctype t,
886 /*@only@*/ globSet globs,
887 /*@only@*/ sRefSet mods,
888 /*@only@*/ warnClause warn,
889 /*@keep@*/ fileloc f, bool priv,
890 /*@unused@*/ bool isForward)
892 uentry e = uentry_alloc ();
895 llassert (warnClause_isUndefined (warn)); /*@i325 remove parameter! */
897 DPRINTF (("Make function: %s", n));
899 if (ctype_isFunction (t))
901 ret = ctype_getReturnType (t);
905 if (ctype_isKnown (t))
907 llbug (message ("not function: %s", ctype_unparse (t)));
914 if (fileloc_isSpec (f) || fileloc_isImport (f))
916 e->whereSpecified = f;
917 e->whereDeclared = fileloc_undefined;
921 e->whereSpecified = fileloc_undefined;
922 e->whereDeclared = f;
925 /* e->shallowCopy = FALSE; */
926 e->uname = cstring_copy (n);
928 e->storageclass = SCNONE;
930 e->sref = sRef_makeResult (ret); /* evans 2001-07-19 - was sRef_makeType */
932 DPRINTF (("Result: %s", sRef_unparseFull (e->sref)));
934 if (ctype_isUA (ret))
936 sRef_setStateFromType (e->sref, ret);
941 e->uses = filelocList_new ();
943 e->hasNameError = FALSE;
947 e->info = (uinfo) dmalloc (sizeof (*e->info));
948 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
950 e->info->fcn->hasMods = sRefSet_isDefined (mods);
951 e->info->fcn->hasGlobs = globSet_isDefined (globs);
953 e->info->fcn->exitCode = XK_UNKNOWN;
954 e->info->fcn->nullPred = qual_createUnknown ();
955 e->info->fcn->specialCode = SPC_NONE;
957 e->info->fcn->access = access;
958 e->info->fcn->globs = globs;
959 e->info->fcn->defparams = uentryList_undefined;
961 sRef_setDefined (e->sref, f);
962 e->whereDefined = fileloc_undefined;
964 e->info->fcn->mods = sRefSet_undefined;
965 e->info->fcn->specclauses = NULL;
968 e->info->fcn->preconditions = NULL;
972 e->info->fcn->postconditions = NULL;
975 checkGlobalsModifies (e, mods);
976 e->info->fcn->mods = mods;
981 static void uentry_reflectClauses (uentry ue, functionClauseList clauses)
983 functionClauseList_elements (clauses, el)
985 DPRINTF (("Reflect clause: %s on %s",
986 functionClause_unparse (el), uentry_getName (ue)));
988 if (functionClause_isNoMods (el))
990 modifiesClause mel = functionClause_getModifies (el);
992 if (uentry_hasGlobs (ue))
997 ("No globals and modifies inconsistent to globals clause for %q: %q",
999 globSet_unparse (uentry_getGlobs (ue))),
1000 modifiesClause_getLoc (mel));
1004 if (uentry_hasMods (ue))
1009 ("No globals and modifies inconsistent to modifies clause for %q: %q",
1010 uentry_getName (ue),
1011 sRefSet_unparse (uentry_getMods (ue))),
1012 modifiesClause_getLoc (mel));
1015 uentry_setGlobals (ue, globSet_undefined);
1016 uentry_setModifies (ue, sRefSet_undefined);
1018 else if (functionClause_isGlobals (el))
1020 globalsClause glc = functionClause_getGlobals (el);
1022 DPRINTF (("Globals: %s / %s", uentry_unparse (ue),
1023 globalsClause_unparse (glc)));
1025 if (uentry_hasGlobs (ue))
1030 ("Multiple globals clauses for %q: %q",
1031 uentry_getName (ue),
1032 globalsClause_unparse (glc)),
1033 globalsClause_getLoc (glc));
1034 uentry_setGlobals (ue, globalsClause_takeGlobs (glc)); /*@i32@*/
1038 uentry_setGlobals (ue, globalsClause_takeGlobs (glc));
1041 else if (functionClause_isModifies (el))
1043 modifiesClause mlc = functionClause_getModifies (el);
1045 DPRINTF (("Has modifies: %s", uentry_unparseFull (ue)));
1047 if (uentry_hasMods (ue))
1055 ("Multiple modifies clauses for %s: %s",
1056 uentry_getName (ue),
1057 modifiesClause_unparse (mlc)),
1058 modifiesClause_getLoc (mlc)))
1060 llhint (message ("Previous modifies clause: ",
1061 sRefSet_unparse (uentry_getMods (ue))));
1067 uentry_combineModifies (ue, modifiesClause_takeMods (mlc)); /*@i32@*/
1071 uentry_setModifies (ue, modifiesClause_takeMods (mlc));
1074 else if (functionClause_isEnsures (el))
1076 functionConstraint cl = functionClause_takeEnsures (el);
1077 DPRINTF (("Setting post: %s / %s",
1078 uentry_unparse (ue), functionConstraint_unparse (cl)));
1079 uentry_setPostconditions (ue, cl);
1081 else if (functionClause_isRequires (el))
1083 functionConstraint cl = functionClause_takeRequires (el);
1084 uentry_setPreconditions (ue, cl);
1086 else if (functionClause_isState (el))
1088 stateClause sc = functionClause_takeState (el);
1090 if (stateClause_isBefore (sc) && stateClause_setsMetaState (sc))
1092 sRefSet rfs = stateClause_getRefs (sc);
1094 sRefSet_elements (rfs, s)
1096 if (sRef_isParam (s))
1099 ** Can't use requires on parameters
1103 (FLG_ANNOTATIONERROR,
1104 message ("Requires clauses for %q concerns parameters %q should be "
1105 "a parameter annotation instead: %q",
1106 uentry_unparse (ue),
1108 stateClause_unparse (sc)),
1109 stateClause_loc (sc));
1111 } end_sRefSet_elements ;
1114 DPRINTF (("State clause: %s", stateClause_unparse (sc)));
1115 uentry_addStateClause (ue, sc);
1117 else if (functionClause_isWarn (el))
1119 warnClause wc = functionClause_takeWarn (el);
1120 uentry_addWarning (ue, wc);
1124 DPRINTF (("Unhandled clause: %s", functionClause_unparse (el)));
1126 } end_functionClauseList_elements ;
1128 DPRINTF (("Checking all: %s", sRef_unparseFull (ue->sref)));
1129 stateClauseList_checkAll (ue);
1132 /*@notnull@*/ uentry uentry_makeIdFunction (idDecl id)
1134 bool leaveFunc = FALSE;
1136 uentry_makeFunction (idDecl_observeId (id), idDecl_getCtype (id),
1137 typeId_invalid, globSet_undefined,
1138 sRefSet_undefined, warnClause_undefined,
1141 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1144 ** This makes parameters names print out correctly.
1145 ** (But we might be a local variable declaration for a function type...)
1148 if (context_inFunctionLike ())
1150 DPRINTF (("Header: %s / %s",
1151 uentry_unparse (context_getHeader ()),
1152 idDecl_unparse (id)));
1156 context_enterFunctionDeclaration (ue);
1160 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1161 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
1162 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1163 reflectImplicitFunctionQualifiers (ue, FALSE);
1164 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1165 uentry_reflectClauses (ue, idDecl_getClauses (id));
1166 DPRINTF (("Id function: %s", sRef_unparseFull (ue->sref)));
1168 if (!uentry_isStatic (ue)
1169 && cstring_equalLit (ue->uname, "main"))
1171 ctype typ = ue->utype;
1175 llassert (ctype_isFunction (typ));
1177 retval = ctype_getReturnType (typ);
1179 if (!ctype_isInt (retval))
1183 message ("Function main declared to return %s, should return int",
1184 ctype_unparse (retval)),
1185 uentry_whereDeclared (ue));
1188 args = ctype_argsFunction (typ);
1190 if (uentryList_isMissingParams (args)
1191 || uentryList_size (args) == 0)
1197 if (uentryList_size (args) != 2)
1201 message ("Function main declared with %d arg%&, "
1202 "should have 2 (int argc, char *argv[])",
1203 uentryList_size (args)),
1204 uentry_whereLast (ue));
1208 uentry arg = uentryList_getN (args, 0);
1209 ctype ct = uentry_getType (arg);
1211 if (!ctype_isInt (ct))
1215 message ("Parameter 1, %q, of function main declared "
1216 "with type %t, should have type int",
1217 uentry_getName (arg), ct),
1218 uentry_whereDeclared (arg));
1221 arg = uentryList_getN (args, 1);
1222 ct = uentry_getType (arg);
1224 if (ctype_isArrayPtr (ct)
1225 && ctype_isArrayPtr (ctype_baseArrayPtr (ct))
1226 && ctype_isChar (ctype_baseArrayPtr (ctype_baseArrayPtr (ct))))
1234 message ("Parameter 2, %q, of function main declared "
1235 "with type %t, should have type char **",
1236 uentry_getName (arg), ct),
1237 uentry_whereDeclared (arg));
1245 context_exitFunctionDeclaration ();
1251 static void uentry_implicitParamAnnots (/*@notnull@*/ uentry e)
1253 alkind ak = sRef_getAliasKind (e->sref);
1255 if ((alkind_isUnknown (ak) || alkind_isImplicit (ak))
1256 && context_getFlag (FLG_PARAMIMPTEMP))
1258 exkind ek = sRef_getExKind (e->sref);
1260 if (exkind_isKnown (ek))
1262 DPRINTF (("imp dep: %s", uentry_unparseFull (e)));
1263 sRef_setAliasKind (e->sref, AK_IMPDEPENDENT, fileloc_undefined);
1264 sRef_setOrigAliasKind (e->sref, AK_IMPDEPENDENT);
1268 sRef_setAliasKind (e->sref, AK_IMPTEMP, fileloc_undefined);
1269 sRef_setOrigAliasKind (e->sref, AK_IMPTEMP);
1274 static /*@only@*/ /*@notnull@*/ uentry
1275 uentry_makeVariableParamAux (cstring n, ctype t, /*@dependent@*/ sRef s,
1276 /*@only@*/ fileloc loc, sstate defstate) /*@i32 exposed*/
1278 cstring pname = makeParam (n);
1281 DPRINTF (("Sref: %s", sRef_unparseFull (s)));
1282 e = uentry_makeVariableAux (pname, t, loc, s, FALSE, VKPARAM);
1284 cstring_free (pname);
1285 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1286 uentry_implicitParamAnnots (e);
1287 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1289 if (!sRef_isAllocated (e->sref) && !sRef_isPartial (e->sref))
1291 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1292 sRef_setDefState (e->sref, defstate, uentry_whereDeclared (e));
1293 e->info->var->defstate = defstate;
1296 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1302 uentry_setRefCounted (uentry e)
1304 if (uentry_isValid (e))
1306 uentry_setAliasKind (e, AK_REFCOUNTED);
1307 sRef_storeState (e->sref);
1313 uentry_setStatic (uentry c)
1315 if (uentry_isValid (c))
1317 alkind ak = sRef_getAliasKind (c->sref);
1318 c->storageclass = SCSTATIC;
1320 if (uentry_isVariable (c) && !ctype_isFunction (uentry_getType (c)))
1322 if (!alkind_isUnknown (ak)
1323 && !alkind_isStatic (ak))
1325 if (!(ctype_isRealPointer (uentry_getType (c)))
1326 && !(ctype_isAbstract (ctype_realType (uentry_getType (c))))
1327 && !alkind_isRefCounted (ak))
1329 if (alkind_isImplicit (ak)
1330 && alkind_isDependent (ak)
1331 && ctype_isArray (uentry_getType (c)))
1333 ; /* no error for observer arrays */
1339 message ("Static storage %q declared as %s",
1341 alkind_unparse (ak)),
1342 uentry_whereDeclared (c));
1348 if (alkind_isUnknown (ak)
1349 || (alkind_isImplicit (sRef_getAliasKind (c->sref))
1350 && !alkind_isDependent (sRef_getAliasKind (c->sref))))
1352 sRef_setAliasKind (c->sref, AK_STATIC, fileloc_undefined);
1353 sRef_setOrigAliasKind (c->sref, AK_STATIC);
1361 uentry_setExtern (uentry c)
1363 if (uentry_isValid (c))
1364 c->storageclass = SCEXTERN;
1368 uentry_setParamNo (uentry ue, int pno)
1370 llassert (uentry_isAnyParam (ue) && sRef_isParam (ue->sref));
1371 sRef_setParamNo (ue->sref, pno);
1375 void checkGlobalsModifies (/*@notnull@*/ uentry ue, sRefSet sr)
1377 sRefSet_allElements (sr, el)
1379 sRef base = sRef_getRootBase (el);
1381 if (sRef_isFileOrGlobalScope (base) || sRef_isInternalState (base)
1382 || (sRef_isKindSpecial (base) && !sRef_isNothing (base)))
1384 if (!globSet_member (ue->info->fcn->globs, base))
1386 if (uentry_hasGlobs (ue)
1387 || context_getFlag (FLG_WARNMISSINGGLOBALSNOGLOBS))
1390 (FLG_WARNMISSINGGLOBALS,
1392 ("Modifies list for %q uses global %q, "
1393 "not included in globals list.",
1394 uentry_getName (ue),
1395 sRef_unparse (base)),
1396 uentry_whereLast (ue)))
1398 uentry_showWhereSpecified (ue);
1402 ue->info->fcn->globs = globSet_insert (ue->info->fcn->globs,
1404 if (sRef_isFileStatic (base))
1406 context_recordFileGlobals (ue->info->fcn->globs);
1410 } end_sRefSet_allElements;
1414 uentry_makeVariableSrefParam (cstring n, ctype t, /*@only@*/ fileloc loc, /*@exposed@*/ sRef s)
1416 return (uentry_makeVariableParamAux (n, t, s, loc, SS_UNKNOWN));
1420 uentry_fixupSref (uentry ue)
1424 if (uentry_isUndefined (ue) || uentry_isElipsisMarker (ue))
1429 sr = uentry_getSref (ue);
1431 sRef_resetState (sr);
1432 sRef_clearDerived (sr);
1434 llassertprint (uentry_isVariable (ue), ("fixing: %s", uentry_unparseFull (ue)));
1435 llassert (sRef_isValid (sr));
1437 if (uentry_isVariable (ue))
1439 /*@i634 ue->sref = sRef_saveCopyShallow (ue->info->var->origsref); */
1440 sRef_setDefState (sr, ue->info->var->defstate, fileloc_undefined);
1441 sRef_setNullState (sr, ue->info->var->nullstate, fileloc_undefined);
1445 static void uentry_addStateClause (uentry ue, stateClause sc)
1448 ** Okay to allow multiple clauses of the same kind.
1449 */ /*@i834 is this true?@*/
1451 ue->info->fcn->specclauses =
1452 stateClauseList_add (ue->info->fcn->specclauses, sc);
1454 /* Will call checkAll to check later... */
1457 void uentry_setStateClauseList (uentry ue, stateClauseList clauses)
1459 llassert (uentry_isFunction (ue));
1460 llassert (!stateClauseList_isDefined (ue->info->fcn->specclauses));
1462 DPRINTF (("checked clauses: %s", stateClauseList_unparse (clauses)));
1463 ue->info->fcn->specclauses = clauses;
1464 stateClauseList_checkAll (ue);
1465 DPRINTF (("checked clauses: %s", uentry_unparseFull (ue)));
1469 ** Used for @modifies@ @endmodifies@ syntax.
1471 ** If ue is specified, sr must contain *only*:
1473 ** o file static globals
1474 ** o sRef's derived from modifies spec (i.e., more specific than
1475 ** what was specified)
1477 ** Otherwise, if sr has modifies it must match sr.
1479 ** If it doesn't have modifies, set them to sr.
1483 uentry_checkModifiesContext (void)
1485 if (sRef_modInFunction ())
1489 ("Modifies list not in function context. "
1490 "A modifies list can only appear following the parameter list "
1491 "in a function declaration or header."));
1500 uentry_setModifies (uentry ue, /*@owned@*/ sRefSet sr)
1502 if (!uentry_checkModifiesContext ())
1508 if (uentry_isValid (ue))
1510 if (uentry_isIter (ue))
1512 llassert (sRefSet_isUndefined (ue->info->iter->mods));
1513 ue->info->iter->mods = sr;
1517 uentry_convertVarFunction (ue);
1518 llassertfatal (uentry_isFunction (ue));
1519 llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1521 ue->info->fcn->mods = sr;
1522 ue->info->fcn->hasMods = TRUE;
1524 checkGlobalsModifies (ue, sr);
1527 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1529 ue->info->fcn->hasGlobs = TRUE;
1532 if (sRefSet_hasStatic (ue->info->fcn->mods))
1534 context_recordFileModifies (ue->info->fcn->mods);
1544 uentry_combineModifies (uentry ue, /*@owned@*/ sRefSet sr)
1547 ** Function already has one modifies clause (possibly from
1548 ** a specification).
1551 if (!uentry_checkModifiesContext ())
1556 llassert (uentry_isValid (ue));
1558 if (uentry_isIter (ue))
1560 ue->info->iter->mods = sRefSet_unionFree (ue->info->iter->mods, sr);
1564 llassertfatal (uentry_isFunction (ue));
1565 llassert (ue->info->fcn->hasMods);
1567 checkGlobalsModifies (ue, sr);
1568 ue->info->fcn->mods = sRefSet_unionFree (ue->info->fcn->mods, sr);
1570 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1572 ue->info->fcn->hasGlobs = TRUE;
1576 if (sRefSet_hasStatic (ue->info->fcn->mods))
1578 context_recordFileModifies (ue->info->fcn->mods);
1582 bool uentry_hasWarning (uentry ue)
1584 return (uentry_isValid (ue)
1585 && warnClause_isDefined (ue->warn));
1588 void uentry_addWarning (uentry ue, /*@only@*/ warnClause warn)
1590 llassert (warnClause_isUndefined (ue->warn));
1595 uentry_setPreconditions (uentry ue, /*@only@*/ functionConstraint preconditions)
1597 if (sRef_modInFunction ())
1600 (message ("Precondition list not in function context. "
1601 "A precondition list can only appear following the parameter list "
1602 "in a function declaration or header."));
1604 /*@-mustfree@*/ return; /*@=mustfree@*/
1607 if (uentry_isValid (ue))
1609 uentry_convertVarFunction (ue);
1610 llassertfatal (uentry_isFunction (ue));
1612 if (functionConstraint_isDefined (ue->info->fcn->preconditions))
1614 BADBRANCH; /* should conjoin constraints? */
1616 ue->info->fcn->preconditions = functionConstraint_conjoin (ue->info->fcn->preconditions, preconditions);
1620 ue->info->fcn->preconditions = preconditions;
1625 llfatalbug ( (message("uentry_setPreconditions called with invalid uentry") ));
1634 uentry_setPostconditions (uentry ue, /*@only@*/ functionConstraint postconditions)
1636 if (sRef_modInFunction ())
1639 (message ("Postcondition list not in function context. "
1640 "A postcondition list can only appear following the parameter list "
1641 "in a function declaration or header."));
1643 /*@-mustfree@*/ return; /*@=mustfree@*/
1646 if (uentry_isValid (ue))
1648 uentry_convertVarFunction (ue);
1649 llassertfatal (uentry_isFunction (ue));
1651 if (functionConstraint_isUndefined (ue->info->fcn->postconditions))
1653 ue->info->fcn->postconditions = postconditions;
1657 ue->info->fcn->postconditions = functionConstraint_conjoin (ue->info->fcn->postconditions, postconditions);
1662 llfatalbug ( (message("uentry_setPostconditions called with invalid uentry") ));
1667 ** requires: new and old are functions
1671 checkGlobalsConformance (/*@notnull@*/ uentry old,
1672 /*@notnull@*/ uentry unew,
1673 bool mustConform, bool completeConform)
1675 bool hasInternalState = FALSE;
1677 old->info->fcn->hasGlobs |= unew->info->fcn->hasGlobs;
1679 if (globSet_isDefined (unew->info->fcn->globs))
1681 globSet_allElements (unew->info->fcn->globs, el)
1683 if (sRef_isFileStatic (el))
1685 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1687 if (sRef_isInvalid (sr))
1689 bool hasError = FALSE;
1691 if (!hasInternalState
1692 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1693 sRef_makeInternalState ()))
1694 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1695 sRef_makeSpecState ())))
1698 && !uentry_isStatic (old)
1701 message ("Globals list for %q includes internal state, %q, "
1702 "but %s without globals internalState.",
1703 uentry_getName (old),
1705 uentry_specOrDefName (old)),
1706 uentry_whereLast (unew)))
1708 uentry_showWhereSpecified (old);
1712 old->info->fcn->globs = globSet_insert (old->info->fcn->globs,
1713 sRef_makeInternalState ());
1714 hasInternalState = TRUE;
1718 && fileloc_sameFile (uentry_whereDeclared (unew),
1719 uentry_whereDeclared (old)))
1724 message ("Function %q inconsistently %rdeclared (in "
1725 "same file) with file static global %q in "
1727 uentry_getName (unew),
1728 uentry_isDeclared (old),
1730 uentry_whereDeclared (unew)))
1732 uentry_showWhereSpecified (old);
1737 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1738 context_recordFileGlobals (old->info->fcn->globs);
1742 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1744 if (sRef_isInvalid (sr))
1749 message ("Function %q inconsistently %rdeclared with "
1750 "%q in globals list",
1751 uentry_getName (unew),
1752 uentry_isDeclared (old),
1754 uentry_whereDeclared (unew)))
1756 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1757 uentry_showWhereSpecified (old);
1762 if (!bool_equal (sRef_isAllocated (el), sRef_isAllocated (sr)))
1768 ("Function %q global %q inconsistently "
1769 "%rdeclared as %qout global",
1770 uentry_getName (unew),
1772 uentry_isDeclared (old),
1773 cstring_makeLiteral (sRef_isAllocated (el) ? "" : "non-")),
1774 uentry_whereDeclared (unew)))
1776 uentry_showWhereSpecified (old);
1781 } end_globSet_allElements ;
1783 if (completeConform)
1785 globSet_allElements (old->info->fcn->globs, el)
1787 sRef sr = globSet_lookup (unew->info->fcn->globs, el);
1789 if (sRef_isInvalid (sr))
1792 && uentry_isReallySpecified (old)
1795 message ("Function %q specified with %q in globals list, "
1796 "but declared without %q",
1797 uentry_getName (unew),
1800 uentry_whereDeclared (unew)))
1802 uentry_showWhereSpecified (old);
1805 } end_globSet_allElements;
1810 if (completeConform && !globSet_isEmpty (old->info->fcn->globs))
1812 if (uentry_isReallySpecified (old)
1815 message ("%s %q specified with globals list, but "
1816 "declared with no globals",
1817 ekind_capName (unew->ukind),
1818 uentry_getName (unew)),
1819 uentry_whereDeclared (unew)))
1822 (message ("Specification globals: %q",
1823 globSet_unparse (old->info->fcn->globs)),
1824 uentry_whereSpecified (old));
1828 unew->info->fcn->globs = globSet_copyInto (unew->info->fcn->globs,
1829 old->info->fcn->globs);
1834 ** new modifies list must be included by old modifies list.
1836 ** file static state may be added to new, if old has internal.
1840 checkModifiesConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
1841 bool mustConform, bool completeConform)
1844 bool changedMods = FALSE;
1845 bool modInternal = FALSE;
1847 llassert (uentry_isFunction (old) && uentry_isFunction (unew));
1849 old->info->fcn->hasMods |= unew->info->fcn->hasMods;
1850 newMods = unew->info->fcn->mods;
1852 if (sRefSet_isEmpty (newMods))
1854 if (completeConform && !sRefSet_isEmpty (old->info->fcn->mods)
1855 && uentry_isReallySpecified (old))
1859 message ("%s %q specified with modifies clause, "
1860 "but declared with no modifies clause",
1861 ekind_capName (unew->ukind),
1862 uentry_getName (unew)),
1863 uentry_whereDeclared (unew)))
1865 llgenindentmsg (message ("Specification has modifies %q",
1866 sRefSet_unparse (old->info->fcn->mods)),
1867 uentry_whereSpecified (old));
1874 sRefSet_allElements (newMods, current)
1876 if (sRef_isValid (current))
1878 sRef rb = sRef_getRootBase (current);
1880 if (sRef_isFileStatic (rb))
1884 if (!sRefSet_isSameMember (old->info->fcn->mods,
1885 sRef_makeInternalState ())
1886 && !sRefSet_isSameMember (old->info->fcn->mods,
1887 sRef_makeSpecState ()))
1890 && !uentry_isStatic (old)
1894 ("Modifies list for %q includes internal state, "
1895 "but %s without modifies internal.",
1896 uentry_getName (old),
1897 uentry_specOrDefName (old)),
1898 uentry_whereLast (unew)))
1900 uentry_showWhereSpecified (old);
1903 old->info->fcn->mods =
1904 sRefSet_insert (old->info->fcn->mods,
1905 sRef_makeInternalState ());
1910 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1916 if (sRef_canModifyVal (current, old->info->fcn->mods))
1918 int size = sRefSet_size (old->info->fcn->mods);
1920 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1923 if (sRefSet_size (old->info->fcn->mods) != size)
1934 ("Modifies list for %q contains %q, not modifiable "
1936 uentry_getName (old),
1937 sRef_unparse (current),
1938 uentry_specDeclName (old)),
1939 uentry_whereLast (unew)))
1941 uentry_showWhereSpecified (old);
1946 } end_sRefSet_allElements;
1948 if (completeConform && uentry_isReallySpecified (old))
1950 sRefSet_allElements (old->info->fcn->mods, el)
1952 if (sRef_canModify (el, newMods))
1961 ("Specification modifies clause for %q contains %q, "
1962 "not included in declaration modifies clause",
1963 uentry_getName (old),
1965 uentry_whereLast (unew)))
1967 uentry_showWhereSpecified (old);
1970 } end_sRefSet_allElements ;
1974 ** Make sure file static elements will be removed.
1979 context_recordFileModifies (old->info->fcn->mods);
1984 uentry_checkMutableType (uentry ue)
1986 ctype ct = uentry_getType (ue);
1988 if (!ctype_isRealPointer (ct) && !ctype_isRealAbstract (ct))
1990 DPRINTF (("Check mutable: %s", uentry_unparseFull (ue)));
1992 voptgenerror (FLG_MUTREP,
1993 message ("Mutable abstract type %q declared without pointer "
1994 "indirection: %t (violates assignment semantics)",
1995 uentry_getName (ue), ct),
1996 uentry_whereDeclared (ue));
2001 uentry_setMutable (uentry e)
2003 llassert (uentry_isDatatype (e));
2004 e->info->datatype->mut = YES;
2008 uentry_checkIterArgs (uentry ue)
2010 bool hasYield = FALSE;
2013 llassert (uentry_isIter (ue));
2015 args = uentry_getParams (ue);
2017 uentryList_elements (args, el)
2019 sstate ds = uentry_getDefState (el);
2021 if (uentry_isYield (el))
2026 if (sstate_isUnknown (ds))
2028 uentry_setDefState (el, SS_DEFINED);
2034 } end_uentryList_elements;
2038 voptgenerror (FLG_HASYIELD,
2039 message ("Iterator %q declared with no yield parameters",
2040 uentry_getName (ue)),
2041 uentry_whereDeclared (ue));
2046 chkind_fromQual (qual qel)
2048 if (qual_isChecked (qel))
2052 else if (qual_isCheckMod (qel))
2056 else if (qual_isCheckedStrict (qel))
2058 return CH_CHECKEDSTRICT;
2060 else if (qual_isUnchecked (qel))
2062 return CH_UNCHECKED;
2067 /*@notreached@*/ return CH_UNKNOWN;
2072 uentry_reflectOtherQualifier (/*@notnull@*/ uentry ue, qual qel)
2074 if (qual_isKillRef (qel) || qual_isNewRef (qel) || qual_isTempRef (qel))
2076 if (!uentry_isRefCounted (ue))
2079 (FLG_ANNOTATIONERROR,
2080 message ("Reference counting qualifier %s used on non-reference "
2081 "counted storage: %q",
2083 uentry_unparse (ue)),
2084 uentry_whereLast (ue));
2088 alkind ak = alkind_fromQual (qel);
2090 uentry_setAliasKind (ue, ak);
2093 else if (qual_isRefCounted (qel))
2095 ctype ct = ctype_realType (uentry_getType (ue));
2098 if (ctype_isPointer (ct)
2099 && (ctype_isStruct (rt = ctype_realType (ctype_baseArrayPtr (ct)))))
2101 /* check there is a refs field */
2102 uentryList fields = ctype_getFields (rt);
2103 uentry refs = uentry_undefined;
2105 uentryList_elements (fields, field)
2107 if (uentry_isRefsField (field))
2109 if (uentry_isValid (refs))
2112 (FLG_ANNOTATIONERROR,
2113 message ("Reference counted structure type %s has "
2114 "multiple refs fields: %q and %q",
2116 uentry_getName (refs),
2117 uentry_getName (field)),
2118 uentry_whereLast (field));
2123 } end_uentryList_elements;
2125 if (uentry_isInvalid (refs))
2129 message ("Reference counted structure type %s has "
2131 ctype_unparse (ct)),
2133 ("To count reference, the structure must have a field named "
2134 "refs of type int."),
2137 else if (!ctype_isInt (uentry_getType (refs)))
2140 (FLG_ANNOTATIONERROR,
2141 message ("Reference counted structure type %s refs field has "
2142 "type %s (should be int)", ctype_unparse (ct),
2143 ctype_unparse (uentry_getType (refs))),
2144 uentry_whereLast (refs));
2148 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2149 uentry_whereDeclared (ue));
2154 if ((ctype_isPointer (ct)
2155 && ctype_isUnknown (ctype_realType (ctype_baseArrayPtr (ct))))
2156 ||ctype_isAbstract (ct) || ctype_isUnknown (ct))
2158 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
2159 uentry_whereDeclared (ue));
2164 (FLG_ANNOTATIONERROR,
2165 message ("Non-pointer to structure type %s declared with "
2166 "refcounted qualifier",
2167 ctype_unparse (ct)),
2168 uentry_whereLast (ue));
2172 else if (qual_isRefs (qel))
2174 if (uentry_isVariable (ue) && !uentry_isParam (ue))
2176 uentry_setAliasKind (ue, AK_REFS);
2181 (FLG_ANNOTATIONERROR,
2182 message ("Refs qualifier used on non-structure field: %q",
2183 uentry_unparse (ue)),
2184 uentry_whereLast (ue));
2187 else if (qual_isAliasQual (qel))
2189 alkind ak = alkind_fromQual (qel);
2191 alkind oldak = uentry_getAliasKind (ue);
2192 ctype ut = uentry_getType (ue);
2194 if (alkind_isImplicit (ak)
2195 && (alkind_isKnown (oldak) && !alkind_isImplicit (oldak)))
2197 /* ignore the implied qualifier */
2201 if (uentry_isEitherConstant (ue))
2204 (FLG_ANNOTATIONERROR,
2205 message ("Alias qualifier %s used on constant: %q",
2206 alkind_unparse (ak), uentry_unparse (ue)),
2207 uentry_whereLast (ue));
2212 if (ctype_isFunction (ut))
2214 ut = ctype_getReturnType (ut);
2217 if (!(ctype_isVisiblySharable (ut)
2218 || ctype_isRealArray (ut)
2219 || ctype_isRealSU (ut)))
2221 if (!qual_isImplied (qel))
2224 (FLG_ANNOTATIONERROR,
2225 message ("Alias qualifier %s used on unsharable storage type %t: %q",
2226 alkind_unparse (ak), ut, uentry_getName (ue)),
2227 uentry_whereLast (ue));
2234 if (uentry_isRefCounted (ue))
2236 if (!(qual_isRefQual (qel) || qual_isOnly (qel)
2237 || qual_isExposed (qel)
2238 || qual_isObserver (qel)))
2240 if (!qual_isImplied (qel))
2243 (FLG_ANNOTATIONERROR,
2245 ("Alias qualifier %s used on reference counted storage: %q",
2246 alkind_unparse (ak),
2247 uentry_unparse (ue)),
2248 uentry_whereLast (ue));
2256 if (qual_isRefQual (qel))
2259 (FLG_ANNOTATIONERROR,
2260 message ("Qualifier %s used on non-reference counted storage: %q",
2261 alkind_unparse (ak), uentry_unparse (ue)),
2262 uentry_whereLast (ue));
2271 uentry_setAliasKind (ue, ak);
2274 else if (qual_isNull (qel))
2276 if (uentry_isConstant (ue))
2280 ctype_isAbstract (ue->utype) ? NS_CONSTNULL : NS_DEFNULL,
2281 uentry_whereDeclared (ue));
2285 uentry_setNullState (ue, NS_POSNULL);
2288 else if (qual_isRelNull (qel))
2290 uentry_setNullState (ue, NS_RELNULL);
2292 else if (qual_isNotNull (qel))
2294 uentry_setNullState (ue, NS_MNOTNULL);
2296 else if (qual_isAbstract (qel)
2297 || qual_isConcrete (qel))
2299 if (!uentry_isDatatype (ue))
2302 (FLG_ANNOTATIONERROR,
2303 message ("Qualifier %s used with non-datatype",
2304 qual_unparse (qel)),
2305 uentry_whereLast (ue));
2309 ue->info->datatype->abs = ynm_fromBool (qual_isAbstract (qel));
2312 else if (qual_isMutable (qel))
2314 if (!uentry_isDatatype (ue))
2317 (FLG_ANNOTATIONERROR,
2318 message ("Qualifier %s used with non-datatype", qual_unparse (qel)),
2319 uentry_whereLast (ue));
2323 if (!ynm_isOn (ue->info->datatype->mut))
2325 uentry_checkMutableType (ue);
2328 ue->info->datatype->mut = YES;
2331 else if (qual_isImmutable (qel))
2333 if (!uentry_isDatatype (ue))
2335 voptgenerror (FLG_ANNOTATIONERROR,
2336 message ("Qualifier %s used with non-datatype",
2337 qual_unparse (qel)),
2338 uentry_whereLast (ue));
2342 ue->info->datatype->mut = NO;
2345 else if (qual_isNullPred (qel))
2347 uentry_convertVarFunction (ue);
2349 if (uentry_isFunction (ue))
2351 ctype typ = uentry_getType (ue);
2352 ctype rtype = ctype_getReturnType (uentry_getType (ue));
2354 if (ctype_isRealBool (rtype))
2356 uentryList pl = ctype_argsFunction (typ);
2358 if (uentryList_size (pl) == 1)
2360 ue->info->fcn->nullPred = qel;
2364 voptgenerror (FLG_ANNOTATIONERROR,
2365 message ("Qualifier %s used with function having %d "
2366 "arguments (should have 1)",
2368 uentryList_size (pl)),
2369 uentry_whereLast (ue));
2374 voptgenerror (FLG_ANNOTATIONERROR,
2375 message ("Qualifier %s used with function returning %s "
2376 "(should return bool)",
2378 ctype_unparse (rtype)),
2379 uentry_whereLast (ue));
2384 voptgenerror (FLG_ANNOTATIONERROR,
2385 message ("Qualifier %s used with non-function",
2386 qual_unparse (qel)),
2387 uentry_whereLast (ue));
2390 else if (qual_isExitQual (qel))
2392 exitkind exk = exitkind_fromQual (qel);
2394 if (uentry_isFunction (ue))
2396 if (exitkind_isKnown (ue->info->fcn->exitCode))
2398 voptgenerror (FLG_ANNOTATIONERROR,
2399 message ("Multiple exit qualifiers used on function %q: %s, %s",
2400 uentry_getName (ue),
2401 exitkind_unparse (ue->info->fcn->exitCode),
2402 exitkind_unparse (exk)),
2403 uentry_whereLast (ue));
2406 ue->info->fcn->exitCode = exk;
2410 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2412 uentry_makeVarFunction (ue);
2413 ue->info->fcn->exitCode = exk;
2417 voptgenerror (FLG_ANNOTATIONERROR,
2418 message ("Exit qualifier %s used with non-function (type %s)",
2420 ctype_unparse (uentry_getType (ue))),
2421 uentry_whereLast (ue));
2425 else if (qual_isMetaState (qel))
2427 annotationInfo ainfo = qual_getAnnotationInfo (qel);
2429 if (annotationInfo_matchesContext (ainfo, ue))
2431 DPRINTF (("Reflecting %s on %s",
2432 annotationInfo_unparse (ainfo),
2433 uentry_unparseFull (ue)));
2435 sRef_reflectAnnotation (ue->sref, ainfo, g_currentloc);
2436 DPRINTF (("==> %s", sRef_unparseFull (ue->sref)));
2437 DPRINTF (("==> %s", uentry_unparseFull (ue)));
2442 (FLG_ANNOTATIONERROR,
2443 message ("Attribute annotation %s used in inconsistent context: %q",
2445 uentry_unparse (ue)),
2446 uentry_whereLast (ue)))
2448 /*@i! annotationInfo_showContextError (ainfo, ue); */
2454 if (qual_isCQual (qel))
2460 llbug (message ("Unhandled qualifier: %s", qual_unparse (qel)));
2466 uentry_reflectQualifiers (uentry ue, qualList q)
2468 llassert (uentry_isValid (ue));
2470 DPRINTF (("Reflect qualifiers: %s / %s",
2471 uentry_unparseFull (ue), qualList_unparse (q)));
2473 qualList_elements (q, qel)
2475 if (qual_isStatic (qel))
2477 uentry_setStatic (ue);
2479 else if (qual_isUnused (qel))
2481 uentry_setUsed (ue, fileloc_undefined);
2483 else if (qual_isExternal (qel))
2485 fileloc_free (ue->whereDefined);
2486 ue->whereDefined = fileloc_createExternal ();
2488 else if (qual_isSef (qel))
2490 if (uentry_isVariable (ue))
2492 vkind vk = ue->info->var->kind;
2494 llassert (vk != VKREFPARAM);
2496 if (vk == VKYIELDPARAM)
2499 (FLG_ANNOTATIONERROR,
2500 message ("Qualifier sef cannot be used with %s: %q",
2501 cstring_makeLiteralTemp (vk == VKYIELDPARAM ? "yield" : "returned"),
2502 uentry_unparse (ue)),
2503 uentry_whereLast (ue));
2505 else if (vk == VKRETPARAM)
2507 ue->info->var->kind = VKSEFRETPARAM;
2511 ue->info->var->kind = VKSEFPARAM;
2517 (FLG_ANNOTATIONERROR,
2518 message ("Qualifier sef is meaningful only on parameters: %q",
2519 uentry_unparse (ue)),
2520 uentry_whereLast (ue));
2523 else if (qual_isExtern (qel))
2525 ue->storageclass = SCEXTERN;
2527 else if (qual_isGlobalQual (qel)) /* undef, killed */
2529 DPRINTF (("Reflecting qual: %s / %s",
2530 qual_unparse (qel), uentry_unparse (ue)));
2532 if (uentry_isVariable (ue))
2534 sstate oldstate = ue->info->var->defstate;
2535 sstate defstate = sstate_fromQual (qel);
2538 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
2539 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
2541 defstate = SS_UNDEFKILLED;
2548 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2549 ue->info->var->defstate = defstate;
2554 (FLG_ANNOTATIONERROR,
2555 message ("Qualifier %s used on non-variable: %q",
2556 qual_unparse (qel), uentry_unparse (ue)),
2557 uentry_whereLast (ue));
2560 DPRINTF (("After: %s", uentry_unparseFull (ue)));
2562 /* start modifications */
2563 else if( qual_isBufQualifier(qel) ) {
2564 ctype ct = ctype_realType(uentry_getType(ue));
2565 if( ctype_isArray(ct) || ctype_isPointer(ct) ) {
2567 if( uentry_hasBufStateInfo(ue) ) {
2568 if( qual_isNullTerminated(qel) ) { /* handle Nullterm */
2570 if (uentry_isAnyParam(ue) || uentry_isReturned (ue)) {
2571 /* If formal func param */
2572 uentry_setNullTerminatedState(ue);
2573 uentry_setLen (ue, 1);
2574 uentry_setSize (ue, 1);
2576 sRef_setNullTerminatedState(uentry_getSref(ue));
2577 sRef_setLen (uentry_getSref(ue), 1);
2578 sRef_setSize (uentry_getSref(ue), 1);
2580 uentry_setPossiblyNullTerminatedState(ue);
2582 sRef_setPossiblyNullTerminatedState(uentry_getSref(ue));
2586 /* put other BufState Qualifiers here */
2588 cstring s = uentry_getName(ue);
2589 llfatalbug(message("INTERNAL Error: we have a NULL BufState \
2590 struct for identifier %s\n", s) );
2592 } else if (ctype_isFunction (ct)) { /* We have to handle function */
2594 sRef retSref = uentry_getSref (ue);
2595 ctype retType = sRef_getType (retSref);
2597 if (ctype_isPointer (retType) || ctype_isArray (retType)) {
2598 sRef_setNullTerminatedState (retSref);
2604 message ("Qualifier %s used on non-pointer on \
2605 function return: %q", qual_unparse (qel),
2606 uentry_unparse (ue)));
2613 message ("Qualifier %s used on non-pointer: %q",
2614 qual_unparse (qel), uentry_unparse (ue)));
2616 DPRINTF (("After: %s", uentry_unparseFull (ue)));
2618 else if (qual_isAllocQual (qel)) /* out, partial, reldef, special, etc. */
2620 ctype realType = ctype_realType (ue->utype);
2621 sstate defstate = sstate_fromQual (qel);
2623 if (ctype_isFunction (realType))
2625 realType = ctype_realType (ctype_getReturnType (realType));
2628 if (qual_isRelDef (qel))
2630 ; /* okay anywhere */
2634 if (!ctype_isAP (realType)
2635 && !ctype_isSU (realType)
2636 && !ctype_isUnknown (realType)
2637 && !ctype_isAbstract (ue->utype))
2640 (FLG_ANNOTATIONERROR,
2641 message ("Qualifier %s used on non-pointer or struct: %q",
2642 qual_unparse (qel), uentry_unparse (ue)),
2643 uentry_whereLast (ue));
2647 uentry_setDefState (ue, defstate);
2649 if (sRef_isStateSpecial (ue->sref)
2650 && alkind_isImplicit (sRef_getAliasKind (ue->sref)))
2652 sRef_setAliasKind (ue->sref, AK_ERROR, fileloc_undefined);
2655 else if (qual_isYield (qel))
2657 if (uentry_isVariable (ue))
2659 ue->info->var->kind = VKYIELDPARAM;
2664 (FLG_ANNOTATIONERROR,
2665 message ("Qualifier %s used on non-iterator parameter: %q",
2666 qual_unparse (qel), uentry_unparse (ue)),
2667 uentry_whereLast (ue));
2670 else if (qual_isExQual (qel))
2672 exkind ek = exkind_fromQual (qel);
2673 ctype ut = uentry_getType (ue);
2675 DPRINTF (("Reflect ex qual: %s / %s",
2676 uentry_unparse (ue), exkind_unparse (ek)));
2678 if (ctype_isFunction (ut))
2680 ut = ctype_getReturnType (ut);
2683 if (!(ctype_isVisiblySharable (ut))
2684 && !(ctype_isArray (ut)) /* can apply to arrays also! */
2685 && !(ctype_isStruct (ctype_realType (ut)))) /* applies to structure fields! */
2687 if (!qual_isImplied (qel))
2689 if (ctype_isImmutableAbstract (ut)) {
2691 (FLG_REDUNDANTSHAREQUAL,
2692 message ("Qualifier %s used on unsharable storage type %t: %q",
2693 exkind_unparse (ek), ut, uentry_getName (ue)),
2694 uentry_whereLast (ue));
2697 (FLG_MISPLACEDSHAREQUAL,
2698 message ("Qualifier %s used on unsharable storage type %t: %q",
2699 exkind_unparse (ek), ut, uentry_getName (ue)),
2700 uentry_whereLast (ue));
2706 alkind ak = sRef_getAliasKind (ue->sref);
2708 sRef_setExKind (ue->sref, ek, uentry_whereDeclared (ue));
2709 DPRINTF (("Set exkind: %s", sRef_unparseFull (ue->sref)));
2711 if (alkind_isUnknown (ak) || alkind_isImplicit (ak) || alkind_isStatic (ak))
2713 if (!alkind_isTemp (ak))
2715 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
2716 uentry_setAliasKind (ue, AK_IMPDEPENDENT);
2719 else if (alkind_isDependent (ak) || alkind_isTemp (ak)
2720 || alkind_isOwned (ak))
2728 message ("Exposure qualifier %s used on %s storage (should "
2729 "be dependent): %q",
2731 alkind_unparse (ak),
2732 uentry_unparse (ue)));
2736 else if (qual_isGlobCheck (qel))
2738 if (uentry_isVariable (ue))
2740 chkind ch = chkind_fromQual (qel);
2742 if (ue->info->var->checked != CH_UNKNOWN)
2744 if (ch == ue->info->var->checked)
2746 llerror (FLG_SYNTAX,
2747 message ("Redundant %s qualifier on %q",
2749 uentry_getName (ue)));
2753 llerror (FLG_SYNTAX,
2755 ("Contradictory %s and %s qualifiers on %q",
2757 checkedName (ue->info->var->checked),
2758 uentry_getName (ue)));
2762 ue->info->var->checked = ch;
2768 message ("Qualifier %s used with non-variable",
2769 qual_unparse (qel)));
2772 else if (qual_isReturned (qel))
2774 if (uentry_isVariable (ue))
2776 ue->info->var->kind = VKRETPARAM;
2780 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-variable",
2781 qual_unparse (qel)));
2786 uentry_reflectOtherQualifier (ue, qel);
2789 sRef_storeState (ue->sref);
2790 } end_qualList_elements;
2794 DPRINTF (("Done: %s", sRef_unparseFull (ue->sref)));
2798 uentry_isOnly (uentry ue)
2800 return (!uentry_isUndefined (ue)
2801 && uentry_isVariable (ue)
2802 && alkind_isOnly (sRef_getOrigAliasKind (ue->sref)));
2806 uentry_setAliasKind (/*@notnull@*/ uentry ue, alkind ak)
2808 sRef_setAliasKind (ue->sref, ak, uentry_whereDeclared (ue));
2809 sRef_setOrigAliasKind (ue->sref, ak);
2813 uentry_setNullState (/*@notnull@*/ uentry ue, nstate ns)
2815 if (uentry_isVariable (ue))
2817 ue->info->var->nullstate = ns;
2820 sRef_setNullState (ue->sref, ns, uentry_whereDeclared (ue));
2824 uentry_isUnique (uentry ue)
2826 return (!uentry_isUndefined (ue)
2827 && uentry_isVariable (ue)
2828 && alkind_isUnique (sRef_getOrigAliasKind (ue->sref)));
2832 uentry_isFileStatic (uentry ue)
2834 return (uentry_isStatic (ue)
2835 && (!uentry_isVariable (ue)
2836 || sRef_isFileStatic (uentry_getSref (ue))));
2840 uentry_isExported (uentry ue)
2842 if (uentry_isValid (ue))
2844 if (uentry_isVariable (ue))
2846 return (sRef_isRealGlobal (uentry_getSref (ue)));
2850 return !uentry_isStatic (ue);
2858 uentry_isNonLocal (uentry ue)
2860 return (uentry_isValid (ue) && uentry_isVariable (ue)
2861 && (sRef_isFileOrGlobalScope (ue->sref) || uentry_isStatic (ue)));
2865 uentry_isGlobalVariable (uentry ue)
2867 return (uentry_isValid (ue) && uentry_isVariable (ue)
2868 && sRef_isFileOrGlobalScope (ue->sref));
2872 uentry_isVisibleExternally (uentry ue)
2874 return (uentry_isValid (ue)
2875 && ((uentry_isVariable (ue) && sRef_isRealGlobal (ue->sref))
2876 || (!uentry_isStatic (ue)
2877 && (uentry_isFunction (ue)
2878 || uentry_isIter (ue)
2879 || uentry_isEndIter (ue)
2880 || uentry_isConstant (ue)
2881 || uentry_isDatatype (ue)
2882 || uentry_isAnyTag (ue)))));
2886 uentry_isPrintfLike (uentry ue)
2888 return (uentry_isFunction (ue)
2889 && (ue->info->fcn->specialCode == SPC_PRINTFLIKE));
2893 uentry_isScanfLike (uentry ue)
2895 return (uentry_isFunction (ue)
2896 && (ue->info->fcn->specialCode == SPC_SCANFLIKE));
2900 uentry_isMessageLike (uentry ue)
2902 return (uentry_isFunction (ue)
2903 && (ue->info->fcn->specialCode == SPC_MESSAGELIKE));
2906 static void checkSpecialFunction (/*@notnull@*/ uentry ue)
2908 uentryList args = uentry_getParams (ue);
2910 if (!uentryList_isMissingParams (args))
2912 uentry last = uentry_undefined;
2914 uentryList_elements (args, current)
2916 if (uentry_isElipsisMarker (current))
2918 if (uentry_isUndefined (last))
2922 message ("Function %q is marked %s, but has no format "
2923 "string argument before elipsis",
2924 uentry_getName (ue),
2925 specCode_unparse (ue->info->fcn->specialCode)),
2926 uentry_whereLast (ue));
2927 ue->info->fcn->specialCode = SPC_NONE;
2931 ctype rt = ctype_realType (uentry_getType (last));
2933 if (!ctype_match (rt, ctype_string))
2937 /* wchar_t * is okay too */
2938 if (ctype_isAP (rt))
2940 ctype base = ctype_baseArrayPtr (rt);
2942 if (ctype_isArbitraryIntegral (base))
2952 message ("Function %q is marked %s, but the argument "
2953 "before the elipsis has type %s (should be char *)",
2954 uentry_getName (ue),
2955 specCode_unparse (ue->info->fcn->specialCode),
2956 ctype_unparse (uentry_getType (last))),
2957 uentry_whereLast (ue));
2959 ue->info->fcn->specialCode = SPC_NONE;
2966 } end_uentryList_elements ;
2970 message ("Function %q is marked %s, but has no elipsis parameter",
2971 uentry_getName (ue),
2972 specCode_unparse (ue->info->fcn->specialCode)),
2973 uentry_whereLast (ue));
2975 ue->info->fcn->specialCode = SPC_NONE;
2980 uentry_setPrintfLike (uentry ue)
2982 uentry_convertVarFunction (ue);
2983 llassertfatal (uentry_isFunction (ue));
2984 ue->info->fcn->specialCode = SPC_PRINTFLIKE;
2985 checkSpecialFunction (ue);
2989 uentry_setScanfLike (uentry ue)
2991 uentry_convertVarFunction (ue);
2992 llassertfatal (uentry_isFunction (ue));
2993 ue->info->fcn->specialCode = SPC_SCANFLIKE;
2994 checkSpecialFunction (ue);
2998 uentry_setMessageLike (uentry ue)
3000 uentry_convertVarFunction (ue);
3001 llassertfatal (uentry_isFunction (ue));
3002 ue->info->fcn->specialCode = SPC_MESSAGELIKE;
3003 checkSpecialFunction (ue);
3007 uentry_isSpecialFunction (uentry ue)
3009 return (uentry_isFunction (ue)
3010 && (ue->info->fcn->specialCode != SPC_NONE));
3013 /*@notnull@*/ uentry uentry_makeParam (idDecl t, int i)
3015 ctype ct = idDecl_getCtype (t);
3017 fileloc loc = setLocation ();
3018 sRef pref = sRef_makeParam (i, ct, stateInfo_makeLoc (loc));
3019 uentry ue = uentry_makeVariableSrefParam (idDecl_observeId (t), ct, loc, pref);
3021 DPRINTF (("Make param: %s", uentry_unparseFull (ue)));
3022 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3023 uentry_implicitParamAnnots (ue);
3025 /* Parameter type [][] or [x][] is invalid */
3027 while (ctype_isFixedArray (base)) {
3028 base = ctype_baseArrayPtr (base);
3031 if (ctype_isIncompleteArray (base)) {
3032 base = ctype_baseArrayPtr (base);
3034 if (ctype_isArray (base)) {
3035 if (!uentry_hasName (ue)) {
3036 (void) optgenerror (FLG_INCOMPLETETYPE,
3037 message ("Unnamed function parameter %d is incomplete type (inner array must have bounds): %s",
3039 ctype_unparse (ct)),
3040 uentry_whereLast (ue));
3042 (void) optgenerror (FLG_INCOMPLETETYPE,
3043 message ("Function parameter %q is incomplete type (inner array must have bounds): %s",
3044 uentry_getName (ue),
3045 ctype_unparse (ct)),
3046 uentry_whereLast (ue));
3051 DPRINTF (("Param: %s", uentry_unparseFull (ue)));
3055 /*@only@*/ /*@notnull@*/ uentry uentry_makeIdVariable (idDecl t)
3057 ctype ct = idDecl_getCtype (t);
3059 if (ctype_isFunction (ct))
3061 return (uentry_makeIdFunction (t));
3065 fileloc loc = setLocation ();
3066 uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
3068 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3070 if (!uentry_isExtern (ue))
3072 uentry_setDefined (ue, loc);
3080 /*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t, fileloc loc)
3082 return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), fileloc_copy (loc), SS_DEFINED));
3090 /*@only@*/ /*@notnull@*/
3091 uentry uentry_makeConstantAux (cstring n, ctype t,
3092 /*@keep@*/ fileloc f, bool priv,
3093 /*@only@*/ multiVal m)
3095 uentry e = uentry_alloc ();
3098 e->uname = cstring_copy (n);
3100 e->storageclass = SCNONE;
3102 e->warn = warnClause_undefined; /*@i32 warnings for constants? */
3104 e->sref = sRef_makeConst (t);
3109 e->uses = filelocList_new ();
3110 e->isPrivate = priv;
3111 e->hasNameError = FALSE;
3113 e->info = (uinfo) dmalloc (sizeof (*e->info));
3114 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
3115 e->info->uconst->access = typeIdSet_undefined;
3117 uentry_setSpecDef (e, f);
3119 if (multiVal_isInt (m) && (multiVal_forceInt (m) == 0))
3121 sRef_setDefNull (e->sref, uentry_whereDeclared (e));
3124 uentry_setConstantValue (e, m);
3129 /*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
3131 return (uentry_makeConstantAux (n, t, f, FALSE, multiVal_unknown ()));
3134 /*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
3136 uentry ue = uentry_makeConstant (idDecl_observeId (t),
3137 idDecl_getCtype (t),
3140 llassert (fileloc_isUndefined (ue->whereDeclared));
3141 ue->whereDeclared = setLocation ();
3142 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3144 DPRINTF (("Constant: %s", uentry_unparseFull (ue)));
3152 void uentry_setDefState (uentry ue, sstate defstate)
3154 if (uentry_isValid (ue))
3156 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
3158 if (uentry_isVariable (ue))
3160 ue->info->var->defstate = defstate; /* evs 2000-05-17: fixed bug, was SS_DEFINED! */
3165 bool uentry_isCheckedUnknown (uentry ue)
3167 return (uentry_isVar (ue)
3168 && (ue->info->var->checked == CH_UNKNOWN));
3171 bool uentry_isCheckMod (uentry ue)
3173 return (uentry_isVar (ue)
3174 && (ue->info->var->checked == CH_CHECKMOD));
3177 bool uentry_isUnchecked (uentry ue)
3179 return (uentry_isVar (ue)
3180 && (ue->info->var->checked == CH_UNCHECKED));
3183 bool uentry_isChecked (uentry ue)
3185 return (uentry_isVar (ue)
3186 && (ue->info->var->checked == CH_CHECKED));
3189 bool uentry_isCheckedModify (uentry ue)
3191 return (uentry_isVar (ue)
3192 && (ue->info->var->checked == CH_CHECKED
3193 || ue->info->var->checked == CH_CHECKMOD
3194 || ue->info->var->checked == CH_CHECKEDSTRICT));
3197 bool uentry_isCheckedStrict (uentry ue)
3199 return (uentry_isVar (ue)
3200 && (ue->info->var->checked == CH_CHECKEDSTRICT));
3203 void uentry_setUnchecked (uentry ue)
3205 llassert (uentry_isVar (ue));
3207 ue->info->var->checked = CH_UNCHECKED;
3210 void uentry_setChecked (uentry ue)
3212 llassert (uentry_isVar (ue));
3214 ue->info->var->checked = CH_CHECKED;
3217 void uentry_setCheckMod (uentry ue)
3219 llassert (uentry_isVar (ue));
3221 ue->info->var->checked = CH_CHECKMOD;
3224 void uentry_setCheckedStrict (uentry ue)
3226 llassert (uentry_isVar (ue));
3228 ue->info->var->checked = CH_CHECKEDSTRICT;
3231 static /*@only@*/ /*@notnull@*/
3232 uentry uentry_makeVariableAux (cstring n, ctype t,
3234 /*@exposed@*/ sRef s,
3235 bool priv, vkind kind)
3237 uentry e = uentry_alloc ();
3240 DPRINTF (("Make variable: %s %s %s", n, ctype_unparse (t), sRef_unparse (s)));
3243 e->uname = cstring_copy (n);
3246 e->storageclass = SCNONE;
3248 e->warn = warnClause_undefined; /*@i32 warnings for variable @*/
3255 e->uses = filelocList_new ();
3256 e->isPrivate = priv;
3257 e->hasNameError = FALSE;
3259 e->info = (uinfo) dmalloc (sizeof (*e->info));
3260 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
3261 e->info->var->kind = kind;
3263 /*@i523 e->info->var->origsref = sRef_saveCopy (e->sref); */
3264 e->info->var->checked = CH_UNKNOWN;
3266 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3267 uentry_setSpecDef (e, f);
3268 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3270 if (ctype_isFunction (rt))
3272 rt = ctype_getReturnType (rt);
3275 if (ctype_isUA (rt))
3277 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3278 sRef_setStateFromType (e->sref, rt);
3281 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3282 e->info->var->defstate = sRef_getDefState (e->sref);
3283 e->info->var->nullstate = sRef_getNullState (e->sref);
3285 /* start modifications */
3286 /* This function sets the uentry for a pointer or array variable declaration,
3287 it allocates memory and sets the fields. We check if the type of the variable
3288 is a pointer or array and allocate a `bbufinfo' struct accordingly */
3290 if( ctype_isArray (t) || ctype_isPointer(t)) {
3291 /*@i222@*/e->info->var->bufinfo = dmalloc( sizeof(*e->info->var->bufinfo) );
3292 e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
3293 /*@access sRef@*/ /*i@222*/
3294 /* It probably isn't necessary to violate the abstraction here
3297 s->bufinfo.bufstate = BB_NOTNULLTERMINATED;
3300 e->info->var->bufinfo = NULL;
3302 /* end modification */
3308 uentry_isYield (uentry ue)
3310 return (uentry_isVariable (ue)
3311 && (ue->info->var->kind == VKYIELDPARAM
3312 || ue->info->var->kind == VKREFYIELDPARAM));
3316 uentry_isRefsField (uentry ue)
3318 return (uentry_isVariable (ue) && sRef_isRefsField (ue->sref));
3321 /*@only@*/ /*@notnull@*/
3322 uentry uentry_makeVariable (cstring n, ctype t, fileloc f, bool isPriv)
3324 return (uentry_makeVariableAux (n, t, f, sRef_makeType (t), isPriv,
3325 fileloc_isSpec (f) ? VKSPEC : VKNORMAL));
3332 void uentry_makeVarFunction (uentry ue)
3339 llassert (uentry_isValid (ue));
3340 llassert (!sRef_modInFunction ());
3342 ak = sRef_getOrigAliasKind (ue->sref);
3343 ek = sRef_getOrigExKind (ue->sref);
3345 llassert (uentry_isVariable (ue));
3346 oldInfo = ue->info->var;
3348 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
3351 ** expanded macro is marked used (until I write a pre-processor)
3354 ue->used = ue->used || (oldInfo->kind == VKEXPMACRO);
3357 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3358 ue->info->fcn->exitCode = XK_UNKNOWN;
3359 ue->info->fcn->nullPred = qual_createUnknown ();
3360 ue->info->fcn->specialCode = SPC_NONE;
3361 ue->info->fcn->access = typeIdSet_undefined;
3362 ue->info->fcn->hasGlobs = FALSE;
3363 ue->info->fcn->globs = globSet_undefined;
3364 ue->info->fcn->hasMods = FALSE;
3365 ue->info->fcn->mods = sRefSet_undefined;
3366 ue->info->fcn->specclauses = NULL;
3367 ue->info->fcn->defparams = uentryList_undefined;
3370 ue->info->fcn->preconditions = functionConstraint_undefined;
3374 ue->info->fcn->postconditions = functionConstraint_undefined;
3377 if (ctype_isFunction (ue->utype))
3379 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3383 ue->sref = sRef_makeType (ctype_unknown);
3386 if (sRef_isRefCounted (ue->sref))
3392 if (alkind_isUnknown (ak))
3394 if (exkind_isKnown (ek))
3396 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3397 ak = AK_IMPDEPENDENT;
3401 if (context_getFlag (FLG_RETIMPONLY))
3403 if (ctype_isFunction (ue->utype)
3404 && ctype_isVisiblySharable
3405 (ctype_realType (ctype_getReturnType (ue->utype))))
3407 if (uentryList_hasReturned (uentry_getParams (ue)))
3413 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3428 loc = ue->whereDeclared;
3430 sRef_setAliasKind (ue->sref, ak, loc);
3431 sRef_setNullState (ue->sref, oldInfo->nullstate, loc);
3432 sRef_setDefState (ue->sref, oldInfo->defstate, loc);
3433 sRef_setExKind (ue->sref, ek, loc);
3435 if (oldInfo->kind == VKEXPMACRO)
3441 fileloc_free (ue->whereDefined);
3442 ue->whereDefined = fileloc_undefined;
3445 uvinfo_free (oldInfo);
3448 void uentry_makeConstantFunction (uentry ue)
3455 llassert (uentry_isValid (ue));
3456 llassert (!sRef_modInFunction ());
3458 ak = sRef_getOrigAliasKind (ue->sref);
3459 ek = sRef_getOrigExKind (ue->sref);
3461 llassert (uentry_isConstant (ue));
3462 oldInfo = ue->info->uconst;
3464 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
3467 ** expanded macro is marked used (until I write a pre-processor)
3471 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3472 ue->info->fcn->exitCode = XK_UNKNOWN;
3473 ue->info->fcn->nullPred = qual_createUnknown ();
3474 ue->info->fcn->specialCode = SPC_NONE;
3475 ue->info->fcn->access = typeIdSet_undefined;
3476 ue->info->fcn->hasGlobs = FALSE;
3477 ue->info->fcn->globs = globSet_undefined;
3478 ue->info->fcn->hasMods = FALSE;
3479 ue->info->fcn->mods = sRefSet_undefined;
3480 ue->info->fcn->specclauses = NULL;
3481 ue->info->fcn->defparams = uentryList_undefined;
3484 ue->info->fcn->preconditions = functionConstraint_undefined;
3488 ue->info->fcn->postconditions = functionConstraint_undefined;
3492 if (ctype_isFunction (ue->utype))
3494 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3498 ue->sref = sRef_makeType (ctype_unknown);
3501 if (sRef_isRefCounted (ue->sref))
3507 if (alkind_isUnknown (ak))
3509 if (exkind_isKnown (ek))
3511 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3512 ak = AK_IMPDEPENDENT;
3516 if (context_getFlag (FLG_RETIMPONLY))
3518 if (ctype_isFunction (ue->utype)
3519 && ctype_isVisiblySharable
3520 (ctype_realType (ctype_getReturnType (ue->utype))))
3522 if (uentryList_hasReturned (uentry_getParams (ue)))
3528 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3543 loc = ue->whereDeclared;
3545 sRef_setAliasKind (ue->sref, ak, loc);
3546 sRef_setExKind (ue->sref, ek, loc);
3548 fileloc_free (ue->whereDefined);
3549 ue->whereDefined = fileloc_undefined;
3550 ucinfo_free (oldInfo);
3554 uentry_setGlobals (uentry ue, /*@owned@*/ globSet globs)
3556 llassert (uentry_isValid (ue));
3558 if (uentry_isIter (ue))
3560 llassert (globSet_isUndefined (ue->info->iter->globs));
3561 ue->info->iter->globs = globs;
3565 uentry_convertVarFunction (ue);
3567 llassert (uentry_isFunction (ue));
3568 llassert (!ue->info->fcn->hasGlobs
3569 && globSet_isUndefined (ue->info->fcn->globs));
3571 ue->info->fcn->hasGlobs = TRUE;
3572 globSet_markImmutable (globs);
3573 /*@-mustfree@*/ ue->info->fcn->globs = globs;
3578 /* ??? - evans 2001-09-09 not sure what's going on here...?
3579 if (globSet_hasStatic (globs))
3581 context_recordFileGlobals (globs);
3585 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3587 ue->info->fcn->hasMods = TRUE;
3591 void uentry_addAccessType (uentry ue, typeId tid)
3593 if (uentry_isFunction (ue))
3595 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3597 else if (uentry_isEitherConstant (ue))
3599 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3601 else if (uentry_isIter (ue))
3603 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3605 else if (uentry_isEndIter (ue))
3607 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3611 llbug (message ("no access for: %q", uentry_unparse (ue)));
3615 /*@only@*/ /*@notnull@*/ uentry
3616 uentry_makeFunction (cstring n, ctype t,
3618 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
3619 /*@only@*/ warnClause warn,
3622 llassert (warnClause_isUndefined (warn)); /*@i325 remove parameter! */
3623 return (uentry_makeFunctionAux (n, t,
3624 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3625 : typeIdSet_single (access)),
3632 /*@notnull@*/ uentry
3633 uentry_makePrivFunction2 (cstring n, ctype t,
3635 globSet globs, sRefSet mods,
3638 return (uentry_makeFunctionAux (n, t, access, globs, mods, warnClause_undefined,
3643 /*@notnull@*/ uentry
3644 uentry_makeSpecFunction (cstring n, ctype t,
3646 /*@only@*/ globSet globs,
3647 /*@only@*/ sRefSet mods,
3650 uentry ue = uentry_makeFunctionAux (n, t, access,
3651 globs, mods, warnClause_undefined,
3654 uentry_setHasGlobs (ue);
3655 uentry_setHasMods (ue);
3657 reflectImplicitFunctionQualifiers (ue, TRUE);
3662 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3664 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3665 sRef_undefined, FALSE, VKEXPMACRO);
3667 uentry_setDefined (ue, f);
3671 /*@notnull@*/ /*@notnull@*/ uentry
3672 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3674 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3675 typeIdSet_singleOpt (access),
3676 globSet_undefined, sRefSet_undefined,
3677 warnClause_undefined,
3681 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3685 bool uentry_isForward (uentry e)
3687 if (uentry_isValid (e))
3689 ctype ct = uentry_getType (e);
3691 return (ctype_isUnknown (ct)
3692 || (ctype_isFunction (ct)
3693 && ctype_isUnknown (ctype_getReturnType (ct))));
3700 /*@notnull@*/ uentry
3701 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3703 return (uentry_makeFunctionAux (n, ctype_unknown, access,
3704 globSet_undefined, sRefSet_undefined, warnClause_undefined,
3708 /*@notnull@*/ uentry
3709 uentry_makeUnspecFunction (cstring n, ctype t,
3713 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_undefined,
3714 sRefSet_undefined, warnClause_undefined,
3717 reflectImplicitFunctionQualifiers (ue, TRUE);
3726 /* is exported for use by usymtab_interface */
3728 /*@notnull@*/ uentry
3729 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, ynm abstract,
3730 fileloc f, bool priv)
3732 uentry e = uentry_alloc ();
3734 DPRINTF (("Make datatype: %s / %s",
3735 n, ctype_unparse (t)));
3737 /* e->shallowCopy = FALSE; */
3738 e->ukind = KDATATYPE;
3739 e->uname = cstring_copy (n);
3741 e->storageclass = SCNONE;
3742 e->sref = sRef_makeUnknown ();
3746 sRef_setStateFromType (e->sref, t);
3749 uentry_setSpecDef (e, f);
3751 e->warn = warnClause_undefined; /*@i634@*/
3752 e->uses = filelocList_new ();
3753 e->isPrivate = priv;
3754 e->hasNameError = FALSE;
3759 e->info = (uinfo) dmalloc (sizeof (*e->info));
3760 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3761 e->info->datatype->abs = abstract;
3762 e->info->datatype->mut = mut;
3763 e->info->datatype->type = ctype_undefined;
3765 if (uentry_isDeclared (e))
3767 uentry_setDefined (e, f);
3770 if (ynm_isOn (abstract) && !(uentry_isCodeDefined (e)))
3772 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3778 /*@notnull@*/ uentry
3779 uentry_makeDatatype (cstring n, ctype t, ynm mut, ynm abstract, fileloc f)
3781 return (uentry_makeDatatypeAux (n, t, mut, abstract, f, FALSE));
3784 /*@notnull@*/ uentry uentry_makeBoolDatatype (ynm abstract)
3786 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
3787 ctype_bool, NO, abstract,
3788 fileloc_getBuiltin (),
3791 ret->info->datatype->type = ctype_bool;
3799 static /*@only@*/ /*@notnull@*/ uentry
3800 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3801 /*@only@*/ fileloc f)
3803 uentry e = uentry_alloc ();
3806 e->uname = cstring_copy (n);
3808 e->sref = sRef_makeUnknown ();
3809 e->storageclass = SCNONE;
3813 uentry_setSpecDef (e, f);
3815 e->warn = warnClause_undefined; /*@i452@*/
3816 e->uses = filelocList_new ();
3817 e->isPrivate = FALSE;
3818 e->hasNameError = FALSE;
3820 e->info = (uinfo) dmalloc (sizeof (*e->info));
3821 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3822 e->info->iter->access = access;
3823 e->info->iter->mods = sRefSet_undefined;
3824 e->info->iter->globs = globSet_undefined;
3826 uentry_checkIterArgs (e);
3830 /*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3832 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3835 static /*@notnull@*/ uentry
3836 uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3838 uentry e = uentry_alloc ();
3840 /* e->shallowCopy = FALSE; */
3841 e->ukind = KENDITER;
3842 e->storageclass = SCNONE;
3843 e->uname = message ("end_%s", n);
3844 e->utype = ctype_unknown;
3845 e->sref = sRef_makeUnknown ();
3847 uentry_setSpecDef (e, f);
3852 e->uses = filelocList_new ();
3853 e->isPrivate = FALSE;
3854 e->hasNameError = FALSE;
3856 e->info = (uinfo) dmalloc (sizeof (*e->info));
3857 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3859 e->info->enditer->access = access;
3861 e->warn = warnClause_undefined; /*@i452@*/
3865 /*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3867 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3874 static /*@only@*/ /*@notnull@*/ uentry
3875 uentry_makeTagAux (cstring n, ctype t,
3876 /*@only@*/ fileloc fl,
3877 bool priv, ekind kind)
3879 uentry e = uentry_alloc ();
3881 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3883 llbuglit ("uentry_makeTagAux: not a tag type");
3887 /* e->shallowCopy = FALSE; */
3888 e->uname = cstring_copy (n);
3891 e->sref = sRef_makeUnknown ();
3892 e->storageclass = SCNONE;
3894 uentry_setSpecDef (e, fl);
3899 e->uses = filelocList_new ();
3900 e->isPrivate = priv;
3901 e->hasNameError = FALSE;
3903 e->info = (uinfo) dmalloc (sizeof (*e->info));
3904 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3905 e->info->datatype->abs = NO;
3906 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3907 e->info->datatype->type = t;
3908 e->warn = warnClause_undefined; /*@i452@*/
3910 if (uentry_isDeclared (e))
3912 uentry_setDefined (e, fl);
3918 uentry uentry_makeStructTagLoc (cstring n, ctype t)
3920 cstring sname = makeStruct (n);
3921 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3923 cstring_free (sname);
3928 uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3930 cstring sname = makeStruct (n);
3931 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3933 cstring_free (sname);
3938 uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
3940 cstring uname = makeUnion (n);
3941 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
3943 cstring_free (uname);
3949 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
3951 cstring ename = makeEnum (n);
3952 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
3954 cstring_free (ename);
3960 uentry_makeUnionTagLoc (cstring n, ctype t)
3962 cstring uname = makeUnion (n);
3963 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
3965 cstring_free (uname);
3970 uentry_makeEnumTagLoc (cstring n, ctype t)
3972 cstring ename = makeEnum (n);
3973 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
3975 cstring_free (ename);
3980 uentry_isStructTag (uentry ue)
3982 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
3986 uentry_isUnionTag (uentry ue)
3988 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
3992 uentry_isEnumTag (uentry ue)
3994 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
3998 uentry_isAnyTag (uentry ue)
4000 return (uentry_isStructTag (ue)
4001 || uentry_isUnionTag (ue)
4002 || uentry_isEnumTag (ue));
4005 static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
4007 extern void uentry_destroyMod (void)
4008 /*@globals killed emarker@*/ /*@modifies emarker@*/
4010 static bool wasDestroyed = FALSE;
4012 llassert (!wasDestroyed);
4014 if (emarker != NULL)
4016 uentry_reallyFree (emarker);
4019 wasDestroyed = TRUE;
4023 uentry_makeElipsisMarker (void)
4025 if (emarker == NULL)
4027 emarker = uentry_alloc ();
4029 emarker->ukind = KELIPSMARKER;
4030 emarker->uname = cstring_makeLiteral ("...");
4031 emarker->utype = ctype_elipsMarker;
4032 emarker->sref = sRef_undefined;
4033 emarker->storageclass = SCNONE;
4034 emarker->used = FALSE;
4035 emarker->lset = FALSE;
4036 emarker->info = NULL;
4038 uentry_setSpecDef (emarker, fileloc_undefined);
4039 emarker->uses = filelocList_new ();
4040 emarker->isPrivate = FALSE;
4041 emarker->hasNameError = FALSE;
4044 /*@ignore@*/ return (emarker); /*@end@*/
4052 uentry_equiv (uentry p1, uentry p2)
4054 if (uentry_compare (p1, p2) != 0)
4065 uentry_xcomparealpha (uentry *p1, uentry *p2)
4069 if ((res = uentry_compare (*p1, *p2)) == 0) {
4070 if ((*p1 != NULL) && (*p2 != NULL)) {
4071 res = cstring_compare ((*p1)->uname,
4080 uentry_xcompareuses (uentry *p1, uentry *p2)
4085 if (uentry_isValid (u1))
4087 if (uentry_isValid (u2))
4089 return (-1 * int_compare (filelocList_size (u1->uses),
4090 filelocList_size (u2->uses)));
4099 if (uentry_isValid (u2))
4111 uentry_compareStrict (uentry v1, uentry v2)
4113 COMPARERETURN (uentry_compare (v1, v2));
4115 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
4117 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
4118 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
4119 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
4126 uentry_compare (uentry u1, uentry u2)
4128 if (u1 == u2) return 0;
4130 if (uentry_isInvalid (u1)) return -1;
4131 if (uentry_isInvalid (u2)) return 1;
4133 INTCOMPARERETURN (u1->ukind, u2->ukind);
4134 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
4135 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
4136 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
4142 /* bug detected by lclint:
4143 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
4148 return (multiVal_compare (uentry_getConstantValue (u1),
4149 uentry_getConstantValue (u2)));
4153 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
4155 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
4156 uentry_accessType (u2)));
4157 return (uentryList_compareParams (uentry_getParams (u1),
4158 uentry_getParams (u2)));
4160 return (typeIdSet_compare (uentry_accessType (u1),
4161 uentry_accessType (u2)));
4164 ** Functions are never equivalent
4167 if (u1 - u2 < 0) /* evans 2001-08-21: was: ((int) u1 < (int) u2), changed to remove gcc warning */
4177 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
4178 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
4179 sRef_getOrigAliasKind (u2->sref)));
4180 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
4181 sRef_getOrigExKind (u2->sref)));
4182 COMPARERETURN (generic_compare (u1->info->var->checked,
4183 u2->info->var->checked));
4184 COMPARERETURN (generic_compare (u1->info->var->defstate,
4185 u2->info->var->defstate));
4186 return (generic_compare (u1->info->var->nullstate,
4187 u2->info->var->nullstate));
4189 COMPARERETURN (ctype_compare (u1->info->datatype->type,
4190 u2->info->datatype->type));
4191 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
4192 u2->info->datatype->mut));
4193 return (ynm_compare (u1->info->datatype->abs, u2->info->datatype->abs));
4202 ** all entries are: <type>[@<info>]*#<name>
4204 ** info depends on kind:
4208 advanceField (char **s)
4210 reader_checkChar (s, '@');
4214 advanceName (char **s)
4216 reader_checkChar (s, '#');
4220 vkind_fromInt (int i)
4222 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
4224 llbuglit ("vkind_fromInt: out of range");
4231 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
4232 typeIdSet access, nstate nullstate,
4233 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
4235 uentry e = uentry_alloc ();
4240 e->sref = sRef_makeConst (ct);
4242 sRef_setNullState (e->sref, nullstate, loc);
4243 e->storageclass = SCNONE;
4245 if (fileloc_isSpec (loc))
4247 e->whereSpecified = loc;
4248 e->whereDeclared = fileloc_undefined;
4252 e->whereSpecified = fileloc_undefined;
4253 e->whereDeclared = loc;
4256 e->whereDefined = fileloc_undefined;
4257 e->uses = filelocList_new ();
4258 e->isPrivate = FALSE;
4259 e->hasNameError = FALSE;
4264 e->warn = warnClause_undefined; /*@i452@*/
4266 e->info = (uinfo) dmalloc (sizeof (*e->info));
4267 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
4268 e->info->uconst->access = access;
4270 uentry_setConstantValue (e, m);
4271 sRef_storeState (e->sref);
4276 static /*@only@*/ uentry
4277 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
4278 sstate defstate, nstate isnull, alkind aliased,
4279 exkind exp, chkind checked,
4280 /*@only@*/ fileloc loc)
4282 uentry e = uentry_alloc ();
4287 e->storageclass = SCNONE;
4289 e->sref = sRef_makeType (ct);
4290 sRef_setNullState (e->sref, isnull, loc);
4292 e->whereDefined = fileloc_undefined;
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->isPrivate = FALSE;
4306 e->hasNameError = FALSE;
4311 e->uses = filelocList_new ();
4312 e->warn = warnClause_undefined; /*@i452@*/
4314 e->info = (uinfo) dmalloc (sizeof (*e->info));
4315 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
4316 e->info->var->kind = kind;
4317 e->info->var->checked = checked;
4318 e->info->var->defstate = defstate;
4320 sRef_setDefState (e->sref, defstate, loc);
4322 e->info->var->nullstate = sRef_getNullState (e->sref);
4324 sRef_setExKind (e->sref, exp, loc);
4325 sRef_setAliasKind (e->sref, aliased, loc);
4327 sRef_storeState (e->sref);
4329 /*DRL ADDED 9-1-2000 */
4330 e->info->var->bufinfo = NULL;
4335 static /*@only@*/ uentry
4336 uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, ynm abstract,
4337 ynm mut, ctype rtype, alkind ak, exkind exp,
4338 sstate defstate, nstate isnull,
4339 /*@only@*/ fileloc loc)
4341 uentry e = uentry_alloc ();
4343 e->ukind = KDATATYPE;
4344 /* e->shallowCopy = FALSE; */
4347 e->storageclass = SCNONE;
4348 e->sref = sRef_makeUnknown ();
4349 DPRINTF (("Merge null 1: %s", sRef_unparseFull (e->sref)));
4352 ** This is only setting null state. (I think?)
4355 if (ctype_isUA (ct))
4357 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
4359 if (uentry_isValid (te))
4361 sRef_setStateFromUentry (e->sref, te);
4365 /* problem for recursive type definitions */
4369 sRef_setAliasKind (e->sref, ak, loc);
4370 sRef_setExKind (e->sref, exp, loc);
4372 sRef_setDefState (e->sref, defstate, loc);
4374 if (ynm_isOn (abstract) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
4376 isnull = NS_ABSNULL;
4379 DPRINTF (("Merge null: %s", sRef_unparseFull (e->sref)));
4380 sRef_mergeNullState (e->sref, isnull);
4382 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
4384 if (fileloc_isSpec (loc))
4386 e->whereSpecified = loc;
4387 e->whereDeclared = fileloc_undefined;
4391 e->whereSpecified = fileloc_undefined;
4392 e->whereDeclared = loc;
4395 e->isPrivate = FALSE;
4396 e->hasNameError = FALSE;
4398 e->warn = warnClause_undefined; /*@i452@*/
4402 e->uses = filelocList_new ();
4404 e->info = (uinfo) dmalloc (sizeof (*e->info));
4405 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4406 e->info->datatype->abs = abstract;
4407 e->info->datatype->mut = mut;
4408 e->info->datatype->type = rtype;
4410 DPRINTF (("About to store: %s", sRef_unparseFull (e->sref)));
4411 sRef_storeState (e->sref);
4412 DPRINTF (("After store: %s", sRef_unparseFull (e->sref)));
4418 static void uentry_setHasGlobs (uentry ue)
4420 llassert (uentry_isFunction (ue));
4422 ue->info->fcn->hasGlobs = TRUE;
4425 static void uentry_setHasMods (uentry ue)
4427 llassert (uentry_isFunction (ue));
4429 ue->info->fcn->hasMods = TRUE;
4433 bool uentry_hasGlobs (uentry ue)
4435 if (uentry_isFunction (ue))
4437 return (ue->info->fcn->hasGlobs);
4443 bool uentry_hasStateClauseList (uentry ue)
4445 return (uentry_isFunction (ue) && stateClauseList_isDefined (ue->info->fcn->specclauses));
4448 bool uentry_hasConditions (uentry ue)
4450 return (uentry_isFunction (ue)
4451 && (functionConstraint_isDefined (ue->info->fcn->preconditions)
4452 || functionConstraint_isDefined (ue->info->fcn->postconditions)));
4455 stateClauseList uentry_getStateClauseList (uentry ue)
4457 if (!uentry_isFunction (ue))
4459 llassert (uentry_isFunction (ue));
4460 return stateClauseList_undefined;
4463 DPRINTF (("Get state clause list: %s", uentry_unparse (ue)));
4464 return ue->info->fcn->specclauses;
4467 bool uentry_hasMods (uentry ue)
4469 if (uentry_isFunction (ue))
4471 return (ue->info->fcn->hasMods);
4478 uentry_makeFunctionBase (/*@only@*/ cstring name, ctype ct,
4480 bool hasGlobs, /*@only@*/ globSet globs,
4481 bool hasMods, /*@only@*/ sRefSet mods,
4482 alkind ak, exkind exp,
4483 sstate defstate, nstate isnull,
4487 /*@only@*/ stateClauseList specclauses,
4488 /*@only@*/ warnClause warnclause,
4489 /*@only@*/ fileloc loc)
4491 uentry e = uentry_alloc ();
4494 /* e->shallowCopy = FALSE; */
4498 e->storageclass = SCNONE;
4500 if (ctype_isFunction (ct))
4502 ret = ctype_getReturnType (ct);
4506 if (ctype_isKnown (ct))
4508 llbug (message ("not function: %s", ctype_unparse (ct)));
4511 ret = ctype_unknown;
4514 e->sref = sRef_makeType (ret);
4516 if (ctype_isUA (ret))
4518 sRef_setStateFromType (e->sref, ret);
4521 sRef_setDefined (e->sref, loc);
4522 sRef_setNullState (e->sref, isnull, loc);
4524 sRef_setAliasKind (e->sref, ak, loc);
4525 sRef_setExKind (e->sref, exp, loc);
4526 sRef_setDefState (e->sref, defstate, loc);
4528 e->whereSpecified = loc;
4529 e->whereDefined = fileloc_undefined;
4531 e->isPrivate = FALSE;
4532 e->hasNameError = FALSE;
4536 e->uses = filelocList_new ();
4537 e->warn = warnclause;
4539 e->info = (uinfo) dmalloc (sizeof (*e->info));
4540 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
4542 e->info->fcn->exitCode = exitCode;
4543 e->info->fcn->specialCode = sCode;
4544 e->info->fcn->nullPred = nullPred;
4545 e->info->fcn->access = access;
4547 e->info->fcn->specclauses = specclauses;
4548 e->info->fcn->hasGlobs = hasGlobs;
4549 e->info->fcn->globs = globs;
4551 e->info->fcn->hasMods = hasMods;
4552 e->info->fcn->mods = mods;
4554 e->info->fcn->defparams = uentryList_undefined;
4555 e->whereDeclared = fileloc_undefined;
4557 sRef_storeState (e->sref);
4560 e->info->fcn->preconditions = NULL;
4564 e->info->fcn->postconditions = NULL;
4570 static /*@only@*/ uentry
4571 uentry_makeTagBase (/*@only@*/ cstring name, ekind tagkind,
4572 ctype ct, ctype rtype, /*@only@*/ fileloc loc)
4574 uentry e = uentry_alloc ();
4576 if (tagkind != KSTRUCTTAG && tagkind != KUNIONTAG && tagkind != KENUMTAG)
4578 llbuglit ("uentry_makeTagBase: not a tag type");
4581 /* e->shallowCopy = FALSE; */
4585 e->sref = sRef_makeUnknown ();
4586 e->storageclass = SCNONE;
4588 if (fileloc_isSpec (loc))
4590 e->whereSpecified = loc;
4591 e->whereDeclared = fileloc_undefined;
4595 e->whereDeclared = loc;
4596 e->whereSpecified = fileloc_undefined;
4599 e->whereDefined = fileloc_undefined;
4601 e->isPrivate = FALSE;
4602 e->hasNameError = FALSE;
4606 e->uses = filelocList_new ();
4607 e->warn = warnClause_undefined; /*@i452@*/
4609 e->info = (uinfo) dmalloc (sizeof (*e->info));
4610 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4611 e->info->datatype->abs = NO;
4612 e->info->datatype->mut = MAYBE;
4613 e->info->datatype->type = rtype;
4615 sRef_storeState (e->sref);
4621 uentry_makeIterBase (/*@only@*/ cstring name, typeIdSet access,
4622 ctype ct, /*@only@*/ fileloc loc)
4624 uentry e = uentry_alloc ();
4626 /* e->shallowCopy = FALSE; */
4630 e->sref = sRef_makeUnknown ();
4631 e->storageclass = SCNONE;
4633 if (fileloc_isSpec (loc))
4635 e->whereSpecified = loc;
4636 e->whereDeclared = fileloc_undefined;
4640 e->whereDeclared = loc;
4641 e->whereSpecified = fileloc_undefined;
4644 e->whereDefined = fileloc_undefined;
4646 e->isPrivate = FALSE;
4647 e->hasNameError = FALSE;
4651 e->uses = filelocList_new ();
4652 e->warn = warnClause_undefined; /*@i452@*/
4654 e->info = (uinfo) dmalloc (sizeof (*e->info));
4655 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
4656 e->info->iter->access = access;
4657 e->info->iter->mods = sRefSet_undefined;
4658 e->info->iter->globs = globSet_undefined;
4660 sRef_storeState (e->sref);
4665 uentry_makeEndIterBase (/*@only@*/ cstring name, typeIdSet access,
4666 /*@only@*/ fileloc loc)
4668 uentry e = uentry_alloc ();
4670 /* e->shallowCopy = FALSE; */
4671 e->ukind = KENDITER;
4672 e->storageclass = SCNONE;
4674 e->utype = ctype_unknown;
4675 e->sref = sRef_makeUnknown ();
4677 if (fileloc_isSpec (loc))
4679 e->whereSpecified = loc;
4680 e->whereDeclared = fileloc_undefined;
4684 e->whereDeclared = loc;
4685 e->whereSpecified = fileloc_undefined;
4688 e->whereDefined = fileloc_undefined;
4690 e->isPrivate = FALSE;
4691 e->hasNameError = FALSE;
4695 e->uses = filelocList_new ();
4696 e->warn = warnClause_undefined; /*@i452@*/
4698 e->info = (uinfo) dmalloc (sizeof (*e->info));
4699 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
4700 e->info->enditer->access = access;
4701 sRef_storeState (e->sref);
4706 void uentry_markFree (/*@unused@*/ /*@owned@*/ uentry u)
4714 uentry_undump (ekind kind, fileloc loc, char **s)
4718 DPRINTF (("Uentry undump: %s", *s));
4722 reader_checkChar (s, '!');
4723 reader_checkChar (s, '.');
4724 ue = uentry_makeElipsisMarker ();
4728 ctype ct = ctype_undump (s);
4742 reader_checkChar (s, '|');
4744 if (reader_optCheckChar (s, '@'))
4746 tkind = vkind_fromInt (reader_getInt (s));
4747 reader_checkChar (s, '|');
4754 if (reader_optCheckChar (s, '$'))
4756 defstate = SS_UNKNOWN;
4757 isnull = NS_UNKNOWN;
4758 aliased = AK_IMPTEMP;
4760 checked = CH_UNKNOWN;
4762 else if (reader_optCheckChar (s, '&'))
4764 defstate = SS_DEFINED;
4765 isnull = NS_UNKNOWN;
4766 aliased = AK_IMPTEMP;
4768 checked = CH_UNKNOWN;
4770 else if (reader_optCheckChar (s, '^'))
4772 defstate = SS_UNKNOWN;
4773 isnull = NS_UNKNOWN;
4774 aliased = AK_IMPTEMP;
4776 checked = CH_UNKNOWN;
4780 defstate = sstate_fromInt (reader_getInt (s));
4781 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4782 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4784 if (reader_optCheckChar (s, '&'))
4787 checked = CH_UNKNOWN;
4791 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4792 advanceField (s); checked = (chkind) (reader_getInt (s));
4797 name = reader_getStringWord (s);
4799 llassert (!cstring_equal (name, GLOBAL_MARKER_NAME));
4801 ue = uentry_makeVariableBase (name, ct, tkind, defstate,
4802 isnull, aliased, exp,
4803 checked, fileloc_copy (loc));
4816 advanceField (s); abstract = ynm_fromCodeChar (reader_loadChar (s));
4817 advanceField (s); mut = ynm_fromCodeChar (reader_loadChar (s));
4818 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4819 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4820 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4821 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4822 advanceField (s); rtype = ctype_undump (s);
4824 name = reader_getStringWord (s);
4825 DPRINTF (("Datatype %s, Exp = %s", name, exkind_unparse (exp)));
4826 ue = uentry_makeDatatypeBase (name, ct, abstract, mut, rtype,
4827 aliased, exp, defstate, isnull,
4828 fileloc_copy (loc));
4845 stateClauseList specclauses = stateClauseList_undefined;
4846 warnClause warnclause = warnClause_undefined;
4848 if (reader_optCheckChar (s, '$'))
4850 defstate = SS_DEFINED;
4851 isnull = NS_UNKNOWN;
4852 exitCode = XK_UNKNOWN;
4854 nullPred = qual_createUnknown ();
4858 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4859 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4860 advanceField (s); exitCode = exitkind_fromInt (reader_getInt (s));
4861 advanceField (s); specc = specCode_fromInt (reader_getInt (s));
4862 advanceField (s); nullPred = qual_undump (s);
4865 if (reader_optCheckChar (s, '$'))
4868 globs = globSet_undefined;
4870 mods = sRefSet_undefined;
4872 else if (reader_optCheckChar (s, '^'))
4875 globs = globSet_undefined;
4877 mods = sRefSet_undefined;
4881 advanceField (s); hasGlobs = bool_fromInt (reader_getInt (s));
4882 advanceField (s); globs = globSet_undump (s);
4883 advanceField (s); hasMods = bool_fromInt (reader_getInt (s));
4884 advanceField (s); mods = sRefSet_undump (s);
4887 if (reader_optCheckChar (s, '$'))
4894 advanceField (s); ak = alkind_fromInt (reader_getInt (s));
4895 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4898 advanceField (s); access = typeIdSet_undump (s);
4901 ** Optional clauses: Start with @<code>:
4904 while (reader_optCheckChar (s, '@'))
4906 if (reader_optCheckChar (s, 'W')) /* Warn clause */
4908 reader_checkChar (s, ':');
4909 warnclause = warnClause_undump (s);
4911 else if (reader_optCheckChar (s, 'S')) /* stateClause List */
4913 reader_checkChar (s, ':');
4914 specclauses = stateClauseList_undump (s);
4922 advanceName (s); name = reader_getStringWord (s);
4924 ue = uentry_makeFunctionBase (name, ct, access,
4927 ak, exp, defstate, isnull,
4928 exitCode, specc, nullPred,
4931 fileloc_copy (loc));
4932 DPRINTF (("Undump: %s", uentry_unparse (ue)));
4939 advanceField (s); access = typeIdSet_undump (s);
4940 advanceName (s); name = reader_getStringWord (s);
4942 ue = uentry_makeIterBase (name, access, ct,
4943 fileloc_copy (loc));
4950 advanceField (s); access = typeIdSet_undump (s);
4951 advanceName (s); name = reader_getStringWord (s);
4953 ue = uentry_makeEndIterBase (name, access, fileloc_copy (loc));
4963 if (reader_optCheckChar (s, '$'))
4965 val = multiVal_undefined;
4966 access = typeIdSet_undefined;
4967 nullstate = NS_UNKNOWN;
4971 advanceField (s); val = multiVal_undump (s);
4972 advanceField (s); access = typeIdSet_undump (s);
4973 advanceField (s); nullstate = nstate_fromInt (reader_getInt (s));
4976 advanceName (s); name = reader_getStringWord (s);
4978 ue = uentry_makeConstantBase (name, ct, access,
4979 nullstate, fileloc_copy (loc), val);
4988 advanceField (s); rtype = ctype_undump (s);
4989 advanceName (s); name = reader_getStringWord (s);
4990 ue = uentry_makeTagBase (name, kind, ct, rtype, fileloc_copy (loc));
4994 llcontbuglit ("uentry_undump: invalid");
4995 ue = uentry_undefined;
4998 llcontbuglit ("uentry_undump: elips marker");
4999 ue = uentry_undefined;
5008 uentry_dump (uentry v)
5010 return (uentry_dumpAux (v, FALSE));
5014 uentry_dumpParam (uentry v)
5016 llassertprint (uentry_isVariable (v) || uentry_isElipsisMarker (v),
5017 ("dump: %s", uentry_unparseFull (v)));
5019 return (uentry_dumpAux (v, TRUE));
5023 uentry_dumpAux (uentry v, bool isParam)
5025 llassert (uentry_isValid (v));
5026 llassert (!uentry_isGlobalMarker (v));
5028 DPRINTF (("Dump uentry: [%p]", v));
5029 DPRINTF (("Dumping entry: %s", uentry_unparseFull (v)));
5034 llcontbuglit ("uentry_dump: invalid entry");
5035 return cstring_undefined;
5037 return (message ("!."));
5041 vkind vk = v->info->var->kind;
5042 sstate dss = sRef_getDefState (v->sref);
5043 nstate nst = sRef_getNullState (v->sref);
5044 alkind alk = sRef_getAliasKind (v->sref);
5045 exkind exk = sRef_getExKind (v->sref);
5046 chkind chk = v->info->var->checked;
5048 DPRINTF (("Dumping var"));
5050 if (dss == SS_UNKNOWN
5051 && nst == NS_UNKNOWN
5052 && alk == AK_IMPTEMP
5053 && exk == XO_UNKNOWN
5054 && chk == CH_UNKNOWN)
5056 sdump = cstring_makeLiteral ("$");
5058 else if (dss == SS_DEFINED
5059 && nst == NS_UNKNOWN
5060 && alk == AK_IMPTEMP
5061 && exk == XO_UNKNOWN
5062 && chk == CH_UNKNOWN)
5064 sdump = cstring_makeLiteral ("&");
5066 else if (dss == SS_UNKNOWN
5067 && nst == NS_UNKNOWN
5068 && alk == AK_UNKNOWN
5069 && exk == XO_UNKNOWN
5070 && chk == CH_UNKNOWN)
5072 sdump = cstring_makeLiteral ("^");
5074 else if (exk == XO_UNKNOWN
5075 && chk == CH_UNKNOWN)
5077 sdump = message ("%d@%d@%d&",
5084 sdump = message ("%d@%d@%d@%d@%d",
5095 return (message ("%q|@%d|%q#%s",
5096 ctype_dump (v->utype),
5099 isParam ? cstring_undefined : v->uname));
5103 return (message ("%q|%q#%s",
5104 ctype_dump (v->utype),
5106 isParam ? cstring_undefined : v->uname));
5112 DPRINTF (("Dumping datatype: %s -> %s type: %s [%d]",
5114 exkind_unparse (sRef_getExKind (v->sref)),
5115 ctype_unparse (v->utype), (int) v->utype));
5118 return (message ("%q@%s@%s@%d@%d@%d@%d@%q#%s",
5119 ctype_dump (v->utype),
5120 ynm_unparseCode (v->info->datatype->abs),
5121 ynm_unparseCode (v->info->datatype->mut),
5122 (int) sRef_getDefState (v->sref),
5123 (int) sRef_getNullState (v->sref),
5124 (int) sRef_getAliasKind (v->sref),
5125 (int) sRef_getExKind (v->sref),
5126 ctype_dump (v->info->datatype->type),
5130 cstring sdump, gdump, adump, xdump;
5131 alkind alk = sRef_getAliasKind (v->sref);
5132 exkind exk = sRef_getExKind (v->sref);
5134 if (sRef_getDefState (v->sref) == SS_DEFINED
5135 && !nstate_isKnown (sRef_getNullState (v->sref))
5136 && !exitkind_isKnown (v->info->fcn->exitCode)
5137 && v->info->fcn->specialCode == SPC_NONE
5138 && qual_isUnknown (v->info->fcn->nullPred))
5140 sdump = cstring_makeLiteral ("$");
5144 sdump = message ("@%d@%d@%d@%d@%x",
5145 (int) sRef_getDefState (v->sref),
5146 (int) sRef_getNullState (v->sref),
5147 (int) v->info->fcn->exitCode,
5148 (int) v->info->fcn->specialCode,
5149 qual_dump (v->info->fcn->nullPred));
5152 if (!uentry_hasGlobs(v) && !uentry_hasMods (v))
5154 gdump = cstring_makeLiteral ("$");
5156 else if (uentry_hasGlobs (v) && globSet_isEmpty (uentry_getGlobs (v))
5157 && uentry_hasMods (v) && sRefSet_isEmpty (uentry_getMods (v)))
5159 gdump = cstring_makeLiteral ("^");
5163 gdump = message ("@%s@%q@%s@%q",
5164 bool_dump (uentry_hasGlobs (v)),
5165 globSet_dump (uentry_getGlobs (v)),
5166 bool_dump (uentry_hasMods (v)),
5167 sRefSet_dump (uentry_getMods (v)));
5170 if (alk == AK_UNKNOWN && exk == XO_UNKNOWN)
5172 adump = cstring_makeLiteral ("$");
5176 adump = message ("@%d@%d", (int) alk, (int) exk);
5179 xdump = cstring_undefined;
5181 if (uentry_hasWarning (v))
5183 xdump = message ("%q@W:%q", xdump, warnClause_dump (v->warn));
5186 if (uentry_hasStateClauseList (v))
5188 xdump = message ("%q@S:%q", xdump, stateClauseList_dump (v->info->fcn->specclauses));
5191 return (message ("%q%q%q%q@%q%q#%s",
5192 ctype_dump (v->utype),
5196 typeIdSet_dump (uentry_accessType (v)),
5201 return (message ("%q@%q#%s",
5202 ctype_dump (v->utype),
5203 typeIdSet_dump (v->info->iter->access),
5206 return (message ("%q@%q#%s",
5207 ctype_dump (v->utype),
5208 typeIdSet_dump (uentry_accessType (v)),
5215 if (multiVal_isUnknown (uentry_getConstantValue (v))
5216 && typeIdSet_isEmpty (uentry_accessType (v))
5217 && (sRef_getNullState (v->sref) == NS_UNKNOWN))
5219 sdump = cstring_makeLiteral ("$");
5223 sdump = message ("@%q@%q@%d",
5224 multiVal_dump (uentry_getConstantValue (v)),
5225 typeIdSet_dump (uentry_accessType (v)),
5226 (int) sRef_getNullState (v->sref));
5229 return (message ("%q%q#%s",
5230 ctype_dump (v->utype),
5237 return (message ("%q@%q#%s",
5238 ctype_dump (v->utype),
5239 ctype_dump (v->info->datatype->type), v->uname));
5246 uentry_unparseAbbrev (uentry v)
5248 if (!uentry_isVariable (v))
5250 llcontbuglit ("uentry_unparseAbbrev: not variable");
5251 return uentry_unparse (v);
5254 return (message ("%s %q", ctype_unparseDeep (v->utype), uentry_getName (v)));
5258 uentry_unparse (uentry v)
5262 if (uentry_isUndefined (v)) return (cstring_makeLiteral ("<undefined>"));
5263 if (uentry_isElipsisMarker (v)) return (cstring_makeLiteral ("..."));
5265 st = uentry_getName (v);
5267 if (cstring_isDefined (st))
5269 return (ctype_unparseDeclaration (v->utype, st));
5274 return (cstring_copy (ctype_unparse (v->utype)));
5279 uentry_unparseFull (uentry v)
5281 if (uentry_isUndefined (v))
5283 return (cstring_makeLiteral ("<undefined>"));
5289 res = message ("[%w] %s %s: %s [spec: %q; decl: %q; def: %q]",
5290 (unsigned long) v, ekind_unparse (v->ukind), v->uname,
5291 ctype_unparse (v->utype),
5292 fileloc_unparse (uentry_whereSpecified (v)),
5293 fileloc_unparse (uentry_whereDeclared (v)),
5294 fileloc_unparse (uentry_whereDefined (v)));
5296 DPRINTF (("uentry: %s", res));
5298 if (uentry_isDatatype (v))
5300 res = message ("%q / type: %s mut: %s abs: %s state: %q",
5303 (ctype_isDefined (v->info->datatype->type)
5304 ? v->info->datatype->type : ctype_unknown),
5305 ynm_unparse (v->info->datatype->mut),
5306 ynm_unparse (v->info->datatype->abs),
5307 sRef_unparseState (v->sref));
5309 else if (uentry_isFunction (v))
5311 res = message ("%q / sref: %q / mods: %q / "
5312 "globs: %q / clauses: %q / pre: %q / post: %q",
5314 sRef_unparseFull (v->sref),
5315 sRefSet_unparse (v->info->fcn->mods),
5316 globSet_unparse (v->info->fcn->globs),
5317 stateClauseList_unparse (v->info->fcn->specclauses),
5318 functionConstraint_unparse (v->info->fcn->preconditions),
5319 functionConstraint_unparse (v->info->fcn->postconditions));
5321 else if (uentry_isIter (v))
5323 res = message ("%q / sref: %q",
5325 sRef_unparseFull (v->sref));
5327 else if (uentry_isVariable (v))
5329 res = message ("%q / sref: %q / kind <%d> isout <%d> null <%d> used <%d>",
5331 sRef_unparseFull (v->sref),
5332 (int) v->info->var->kind,
5333 (int) v->info->var->defstate,
5334 (int) v->info->var->nullstate,
5336 DPRINTF (("sref: [%p]", v->sref));
5337 DPRINTF (("sref: %s", sRef_unparseDebug (v->sref)));
5338 /* DPRINTF (("sref: %s", sRef_unparseDeep (v->sref))); */
5340 else if (uentry_isConstant (v))
5342 res = message ("%q = %q",
5343 res, multiVal_unparse (uentry_getConstantValue (v)));
5347 res = message ("%q :: %q", res, uentry_unparse (v));
5354 bool uentry_hasAccessType (uentry e)
5356 if (uentry_isValid (e))
5361 return (!typeIdSet_isEmpty (e->info->iter->access));
5363 return (!typeIdSet_isEmpty (e->info->enditer->access));
5365 return (!typeIdSet_isEmpty (e->info->fcn->access));
5368 return (!typeIdSet_isEmpty (e->info->uconst->access));
5377 typeIdSet uentry_accessType (uentry e)
5379 if (uentry_isValid (e))
5384 return (e->info->iter->access);
5386 return (e->info->enditer->access);
5388 return (e->info->fcn->access);
5391 return (e->info->uconst->access);
5397 return typeIdSet_undefined;
5401 uentry_isVariable (uentry e)
5403 return (uentry_isVar (e));
5407 uentry_isSpecified (uentry e)
5409 return (uentry_isValid (e) && !fileloc_isUndefined (e->whereSpecified));
5413 uentry_isReallySpecified (uentry e)
5415 return (uentry_isValid (e)
5416 && fileloc_isRealSpec (e->whereSpecified));
5420 uentry_isVar (uentry e)
5422 return (!uentry_isUndefined (e) && e->ukind == KVAR);
5426 uentry_isFakeTag (uentry e)
5428 return (uentry_isValid (e) && strchr (cstring_toCharsSafe (e->uname), '!') != 0);
5432 uentry_isDatatype (uentry e)
5434 return (!uentry_isUndefined (e) &&
5435 (e->ukind == KDATATYPE || e->ukind == KSTRUCTTAG ||
5436 e->ukind == KUNIONTAG || e->ukind == KENUMTAG));
5440 uentry_setAbstract (uentry e)
5444 llassert (uentry_isDatatype (e)
5445 && (ynm_isMaybe (e->info->datatype->abs)));
5447 oldid = ctype_typeId (e->info->datatype->type);
5448 e->info->datatype->abs = YES;
5449 e->info->datatype->type = ctype_createAbstract (oldid);
5453 uentry_setConcrete (uentry e)
5455 llassert (uentry_isDatatype (e)
5456 && (ynm_isMaybe (e->info->datatype->abs)));
5458 e->info->datatype->abs = NO;
5462 uentry_isAbstractDatatype (uentry e)
5464 return (uentry_isDatatype (e)
5465 && (ynm_isOn (e->info->datatype->abs)));
5469 uentry_isMaybeAbstract (uentry e)
5471 return (uentry_isDatatype (e)
5472 && (ynm_isMaybe (e->info->datatype->abs)));
5476 uentry_isMutableDatatype (uentry e)
5478 bool res = uentry_isDatatype (e)
5479 && (ynm_toBoolRelaxed (e->info->datatype->mut));
5485 uentry_isRefCountedDatatype (uentry e)
5487 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
5491 uentry_isParam (uentry u)
5493 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
5494 || u->info->var->kind == VKYIELDPARAM));
5498 uentry_isExpandedMacro (uentry u)
5500 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
5504 uentry_isSefParam (uentry u)
5506 return (uentry_isVariable (u)
5507 && (u->info->var->kind == VKSEFPARAM
5508 || u->info->var->kind == VKREFSEFPARAM
5509 || u->info->var->kind == VKSEFRETPARAM
5510 || u->info->var->kind == VKREFSEFRETPARAM));
5514 uentry_isRefParam (uentry u)
5516 return (uentry_isVariable (u)
5517 && (u->info->var->kind == VKREFPARAM
5518 || u->info->var->kind == VKREFYIELDPARAM
5519 || u->info->var->kind == VKREFSEFPARAM
5520 || u->info->var->kind == VKREFSEFRETPARAM));
5524 uentry_isAnyParam (uentry u)
5526 return (uentry_isVariable (u)
5527 && ((u->info->var->kind == VKPARAM)
5528 || (u->info->var->kind == VKSEFPARAM)
5529 || (u->info->var->kind == VKYIELDPARAM)
5530 || (u->info->var->kind == VKRETPARAM)
5531 || (u->info->var->kind == VKSEFRETPARAM)));
5535 uentry_getDefState (uentry u)
5537 if (uentry_isValid (u))
5539 return (sRef_getDefState (u->sref));
5543 return (SS_UNKNOWN);
5548 uentry_isOut (uentry u)
5550 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5551 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5555 uentry_isPartial (uentry u)
5557 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5558 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5562 uentry_isStateSpecial (uentry u)
5564 return ((uentry_isVariable (u)
5565 && (u->info->var->defstate == SS_SPECIAL))
5566 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5569 exitkind uentry_getExitCode (uentry ue)
5571 if (uentry_isFunction (ue))
5573 return ue->info->fcn->exitCode;
5581 qual uentry_nullPred (uentry u)
5583 llassert (uentry_isRealFunction (u));
5585 if (uentry_isFunction (u))
5587 return (u->info->fcn->nullPred);
5591 return qual_createUnknown ();
5596 ** Note for variables, this is checking the declared state, not the current state.
5600 uentry_possiblyNull (uentry u)
5602 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5603 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5607 uentry_getAliasKind (uentry u)
5609 if (uentry_isValid (u))
5611 return (sRef_getAliasKind (uentry_getSref (u)));
5620 uentry_getExpKind (uentry u)
5622 if (uentry_isValid (u))
5624 return (sRef_getExKind (uentry_getSref (u)));
5633 uentry_isIter (uentry e)
5635 return (!uentry_isUndefined (e) && e->ukind == KITER);
5639 uentry_isEndIter (uentry e)
5641 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5645 uentry_isRealFunction (uentry e)
5647 return (uentry_isFunction (e) ||
5648 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5652 uentry_hasName (uentry e)
5654 if (uentry_isValid (e))
5656 cstring s = e->uname;
5658 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")
5659 || uentry_isFakeTag (e)));
5668 ** Returns true for fake tags.
5669 ** This is used for dumping the library
5672 bool uentry_hasRealName (uentry e)
5674 return (uentry_isValid (e)
5675 && cstring_isNonEmpty (e->uname)
5676 && !uentry_isGlobalMarker (e));
5680 /*@observer@*/ globSet
5681 uentry_getGlobs (uentry l)
5683 if (uentry_isInvalid (l))
5685 return globSet_undefined;
5688 if (l->ukind != KFCN)
5690 if (l->ukind != KITER && l->ukind != KENDITER)
5692 if (l->ukind == KVAR)
5694 llbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
5696 ekind_unparse (l->ukind)));
5700 llbug (message ("Bad call to uentry_getGlobs: %q (%s)",
5702 ekind_unparse (l->ukind)));
5705 return globSet_undefined;
5708 return l->info->fcn->globs;
5711 /*@observer@*/ sRefSet
5712 uentry_getMods (uentry l)
5714 llassert (uentry_isValid (l));
5716 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5718 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5719 return sRefSet_undefined;
5722 return l->info->fcn->mods;
5726 uentry_getKind (uentry e)
5728 llassert (uentry_isValid (e));
5733 /*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5735 llassert (uentry_isEitherConstant (e));
5736 return (sRef_getValue (e->sref));
5739 /*@observer@*/ uentryList
5740 uentry_getParams (uentry l)
5742 if (uentry_isInvalid (l)) return uentryList_undefined;
5749 ctype ct = l->utype;
5751 if (ctype_isFunction (ct))
5753 return (ctype_argsFunction (ct));
5757 return uentryList_undefined;
5762 ctype ct = l->utype;
5764 llassert (ctype_isFunction (ct));
5765 return (ctype_argsFunction (ct));
5772 /*@observer@*/ cstring
5773 uentry_rawName (uentry e)
5775 if (uentry_isValid (e))
5781 return cstring_undefined;
5786 uentry_getOptName (uentry e)
5788 cstring s = uentry_getName (e);
5790 if (cstring_isDefined (s))
5792 s = cstring_appendChar (s, ' ');
5799 uentry_getName (uentry e)
5801 cstring ret = cstring_undefined;
5803 if (uentry_isValid (e))
5805 if (uentry_isAnyTag (e))
5807 ret = fixTagName (e->uname);
5809 else if (uentry_isAnyParam (e))
5811 ret = cstring_copy (fixParamName (e->uname));
5815 ret = cstring_copy (e->uname);
5822 cstring uentry_observeRealName (uentry e)
5824 cstring ret = cstring_undefined;
5826 if (uentry_isValid (e))
5828 if (uentry_isAnyTag (e))
5830 if (isFakeTag (e->uname))
5832 ret = cstring_undefined;
5836 ret = plainTagName (e->uname);
5839 else if (uentry_isAnyParam (e))
5841 ret = fixParamName (e->uname);
5852 cstring uentry_getRealName (uentry e)
5854 if (uentry_isValid (e))
5856 if (uentry_isAnyTag (e))
5858 return (cstring_undefined);
5865 return cstring_undefined;
5868 ctype uentry_getType (uentry e)
5870 if (uentry_isValid (e))
5876 return ctype_unknown;
5880 fileloc uentry_whereLast (uentry e)
5884 if (uentry_isInvalid (e))
5886 return fileloc_undefined;
5889 loc = e->whereDefined;
5891 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5896 loc = uentry_whereDeclared (e);
5898 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5903 loc = uentry_whereSpecified (e);
5907 fileloc uentry_whereEither (uentry e)
5909 if (uentry_isInvalid (e)) return fileloc_undefined;
5911 if (fileloc_isDefined (e->whereDefined)
5912 && !fileloc_isExternal (e->whereDefined))
5914 return e->whereDefined;
5916 else if (fileloc_isDefined (e->whereDeclared))
5918 return e->whereDeclared;
5922 return e->whereSpecified;
5926 fileloc uentry_whereSpecified (uentry e)
5928 if (uentry_isInvalid (e)) return fileloc_undefined;
5930 return (e->whereSpecified);
5933 fileloc uentry_whereDefined (uentry e)
5935 if (uentry_isInvalid (e)) return fileloc_undefined;
5937 return (e->whereDefined);
5940 fileloc uentry_whereDeclared (uentry e)
5942 if (uentry_isInvalid (e)) return fileloc_undefined;
5944 return (e->whereDeclared);
5947 /*@observer@*/ fileloc
5948 uentry_whereEarliest (uentry e)
5950 if (uentry_isInvalid (e)) return fileloc_undefined;
5952 if (fileloc_isDefined (e->whereSpecified))
5954 return (e->whereSpecified);
5956 else if (fileloc_isDefined (e->whereDeclared))
5958 return (e->whereDeclared);
5962 return e->whereDefined;
5967 uentry_setFunctionDefined (uentry e, fileloc loc)
5969 if (uentry_isValid (e))
5971 llassert (uentry_isFunction (e));
5973 if (fileloc_isUndefined (e->whereDeclared))
5975 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
5978 if (!fileloc_isDefined (e->whereDefined))
5980 e->whereDefined = fileloc_update (e->whereDefined, loc);
5986 uentry_setDeclDef (uentry e, fileloc f)
5988 uentry_setDeclared (e, f);
5990 if (!uentry_isFunction (e)
5991 && !(uentry_isVariable (e) && uentry_isExtern (e)))
5993 uentry_setDefined (e, f);
5998 uentry_setDeclaredForce (uentry e, fileloc f)
6000 llassert (uentry_isValid (e));
6001 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6005 uentry_setDeclaredForceOnly (uentry e, fileloc f)
6007 llassert (uentry_isValid (e));
6008 fileloc_free (e->whereDeclared);
6009 e->whereDeclared = f;
6013 uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
6017 llassert (uentry_isValid (e));
6018 oldloc = e->whereDeclared;
6020 if (fileloc_isDefined (oldloc))
6022 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6024 e->whereDeclared = f;
6025 fileloc_free (oldloc);
6034 e->whereDeclared = f;
6035 fileloc_free (oldloc);
6040 uentry_setDeclared (uentry e, fileloc f)
6044 llassert (uentry_isValid (e));
6045 oldloc = e->whereDeclared;
6047 if (fileloc_isDefined (oldloc))
6049 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6051 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6060 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6065 uentry_clearDefined (uentry e)
6067 if (uentry_isValid (e))
6069 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
6074 uentry_setDefined (uentry e, fileloc f)
6078 llassert (uentry_isValid (e));
6079 oldloc = e->whereDefined;
6081 if (fileloc_isDefined (oldloc))
6083 if (fileloc_isLib (oldloc)
6084 || fileloc_isImport (oldloc)
6085 || fileloc_isBuiltin (oldloc)
6086 || fileloc_isPreproc (oldloc))
6088 e->whereDefined = fileloc_update (e->whereDefined, f);
6092 if (fileloc_equal (oldloc, f) || context_processingMacros ())
6098 if (optgenerror (FLG_REDEF,
6099 message ("%s %q redefined",
6100 ekind_capName (e->ukind),
6101 uentry_getName (e)),
6104 llgenindentmsg (message ("Previous definition of %q",
6105 uentry_getName (e)),
6113 e->whereDefined = fileloc_update (e->whereDefined, f);
6118 uentry_isCodeDefined (uentry e)
6120 llassert (uentry_isValid (e));
6122 return (fileloc_isDefined (e->whereDefined));
6126 uentry_isDeclared (uentry e)
6128 if (uentry_isValid (e))
6130 return (fileloc_isDefined (e->whereDeclared));
6136 sRef uentry_getSref (uentry e)
6138 /* not true, used for functions too (but shouldn't be? */
6139 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
6141 if (uentry_isInvalid (e)) return sRef_undefined;
6146 sRef uentry_getOrigSref (uentry e)
6148 /*@i523*/ /* evans 2001-09-09 - need to fix this
6149 if (uentry_isValid (e))
6151 if (uentry_isVariable (e))
6153 return e->info->var->origsref;
6157 sRef sr = sRef_copy (uentry_getSref (e));
6159 sRef_resetState (sr);
6160 sRef_clearDerived (sr);
6166 return sRef_undefined;
6170 if (uentry_isValid (e))
6172 sRef sr = sRef_copy (uentry_getSref (e));
6174 sRef_resetState (sr);
6175 sRef_clearDerived (sr);
6177 if (uentry_isVariable (e))
6179 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
6180 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
6187 return sRef_undefined;
6192 ** requires: uentry e is not in a hashed symbol table
6196 uentry_setName (uentry e, /*@only@*/ cstring n)
6198 llassert (uentry_isValid (e));
6200 cstring_free (e->uname);
6205 uentry_setType (uentry e, ctype t)
6207 if (uentry_isValid (e))
6210 sRef_setType (e->sref, t);
6215 uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
6218 ctype rettype = ctype_unknown;
6220 llassert (uentry_isValid (ue));
6222 uentry_convertVarFunction (ue);
6223 llassert (uentry_isFunction (ue));
6225 rct = ctype_realType (ue->utype);
6227 if (ctype_isFunction (rct))
6229 rettype = ctype_getReturnType (rct);
6232 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
6236 uentry_setRefParam (uentry e)
6238 if (!uentry_isVar (e))
6240 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6244 if (e->info->var->kind == VKSEFPARAM)
6246 e->info->var->kind = VKREFSEFPARAM;
6248 else if (e->info->var->kind == VKSEFRETPARAM)
6250 e->info->var->kind = VKREFSEFRETPARAM;
6252 else if (e->info->var->kind == VKYIELDPARAM)
6254 e->info->var->kind = VKREFYIELDPARAM;
6258 e->info->var->kind = VKREFPARAM;
6264 uentry_setParam (uentry e)
6266 if (!uentry_isVar (e))
6268 if (uentry_isElipsisMarker (e))
6274 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6281 if (e->info->var->kind == VKYIELDPARAM
6282 || e->info->var->kind == VKSEFPARAM
6283 || e->info->var->kind == VKSEFRETPARAM)
6289 e->info->var->kind = VKPARAM;
6293 e->uname = makeParam (e->uname);
6294 cstring_free (oldname);
6299 uentry_setSref (uentry e, sRef s)
6301 if (uentry_isValid (e))
6303 if (sRef_isValid (e->sref))
6305 sRef_mergeStateQuietReverse (e->sref, s);
6309 e->sref = sRef_saveCopy (s);
6315 uentry_getAbstractType (uentry e)
6317 llassert (uentry_isDatatype (e));
6320 ** This assertion removed.
6321 ** Okay to have undefined type, for system types
6323 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
6324 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
6329 if (ctype_isUndefined (e->info->datatype->type))
6331 return ctype_unknown;
6335 ** Sadly, a kludge...
6338 if (ctype_isUserBool (e->info->datatype->type)) {
6342 return e->info->datatype->type;
6345 ctype uentry_getRealType (uentry e)
6348 typeId uid = USYMIDINVALID;
6350 if (uentry_isInvalid (e))
6352 return ctype_unknown;
6355 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6357 if (uentry_isAnyTag (e))
6362 if (uentry_isAbstractType (e))
6364 ct = uentry_getAbstractType (e);
6366 if (ctype_isManifestBool (ct)) {
6370 llassert (ctype_isUA (ct));
6372 uid = ctype_typeId (ct);
6374 if (!context_hasAccess (uid))
6380 ct = uentry_getType (e);
6382 /* if (ctype_isUserBool (ct)) return ct; */
6384 if (ctype_isManifestBool (ct)) {
6388 if (ctype_isUA (ct))
6390 usymId iid = ctype_typeId (ct);
6392 if (usymId_equal (iid, uid))
6394 llcontbug (message ("uentry_getRealType: recursive type! %s",
6395 ctype_unparse (ct)));
6400 /* evs 2000-07-25: possible infinite recursion ? */
6401 uentry ue2 = usymtab_getTypeEntry (iid);
6405 llcontbug (message ("Bad recursion: %q", uentry_unparseFull (e)));
6406 return ctype_unknown;
6409 return uentry_getRealType (ue2);
6418 ctype uentry_getForceRealType (uentry e)
6421 typeId uid = USYMIDINVALID;
6423 if (uentry_isInvalid (e))
6425 return ctype_unknown;
6428 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6430 if (uentry_isAnyTag (e))
6435 if (uentry_isAbstractType (e))
6437 ct = uentry_getAbstractType (e);
6438 llassert (ctype_isUA (ct));
6440 uid = ctype_typeId (ct);
6441 /* no check for access! */
6444 ct = uentry_getType (e);
6446 /* evs 2000-07-25 */
6447 /* if (ctype_isUserBool (ct)) return ct; */
6449 if (ctype_isManifestBool (ct)) {
6453 if (ctype_isUA (ct))
6455 usymId iid = ctype_typeId (ct);
6457 if (usymId_equal (iid, uid))
6459 llcontbug (message ("uentry_getRealType: recursive type! %s",
6460 ctype_unparse (ct)));
6465 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
6474 uentry uentry_nameCopy (cstring name, uentry e)
6476 uentry enew = uentry_alloc ();
6478 llassert (uentry_isValid (e));
6480 /* enew->shallowCopy = FALSE; */
6481 enew->ukind = e->ukind;
6483 enew->utype = e->utype;
6484 enew->whereSpecified = fileloc_copy (e->whereSpecified);
6485 enew->whereDefined = fileloc_copy (e->whereDefined);
6486 enew->whereDeclared = fileloc_copy (e->whereDeclared);
6487 enew->sref = sRef_copy (e->sref);
6488 enew->used = e->used;
6490 enew->isPrivate = e->isPrivate;
6491 enew->hasNameError = FALSE;
6493 enew->uses = filelocList_new ();
6494 enew->warn = warnClause_undefined;
6496 enew->storageclass = e->storageclass;
6497 enew->info = uinfo_copy (e->info, e->ukind);
6503 uentry_setDatatype (uentry e, usymId uid)
6505 llassert (uentry_isDatatype (e));
6507 if (uentry_isAbstractType (e))
6509 e->info->datatype->type = ctype_createAbstract (uid);
6513 e->info->datatype->type = ctype_createUser (uid);
6518 uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
6519 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
6522 llassert (uentry_isValid (e));
6524 if (fileloc_isSpec (f) || fileloc_isImport (f))
6526 e->whereSpecified = f;
6527 e->whereDeclared = fileloc_undefined;
6528 e->whereDefined = fileloc_undefined;
6532 e->whereSpecified = fileloc_undefined;
6533 e->whereDeclared = f;
6534 e->whereDefined = fileloc_undefined;
6537 llassert (fileloc_storable (f));
6541 ucinfo_free (/*@only@*/ ucinfo u)
6547 uvinfo_free (/*@only@*/ uvinfo u)
6549 /*drl7x added 6/29/01 */
6550 free (u->bufinfo); /* evans - 2001-07-19 fixed this bug */
6555 udinfo_free (/*@only@*/ udinfo u)
6561 ufinfo_free (/*@only@*/ ufinfo u)
6563 globSet_free (u->globs);
6564 sRefSet_free (u->mods);
6565 stateClauseList_free (u->specclauses);
6570 uiinfo_free (/*@only@*/ uiinfo u)
6576 ueinfo_free (/*@only@*/ ueinfo u)
6581 static /*@only@*/ ucinfo
6582 ucinfo_copy (ucinfo u)
6584 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
6585 ret->access = u->access;
6589 static /*@only@*/ uvinfo
6590 uvinfo_copy (uvinfo u)
6592 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
6594 ret->kind = u->kind;
6595 ret->nullstate = u->nullstate;
6596 ret->defstate = u->defstate;
6597 ret->checked = u->checked;
6599 /*@i523 ret->origsref = sRef_copy (u->origsref); */
6601 /* drl added 07-02-001 */
6602 /* copy null terminated information */
6604 if (u->bufinfo != NULL)
6606 ret->bufinfo = (bbufinfo) dmalloc (sizeof( * u->bufinfo ) );
6607 ret->bufinfo->bufstate = u->bufinfo->bufstate;
6608 ret->bufinfo->size = u->bufinfo->size;
6609 ret->bufinfo->len = u->bufinfo->len;
6614 ret->bufinfo = NULL;
6620 static /*@only@*/ udinfo
6621 udinfo_copy (udinfo u)
6623 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6627 ret->type = u->type;
6632 static /*@only@*/ ufinfo
6633 ufinfo_copy (ufinfo u)
6635 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6637 ret->hasGlobs = u->hasGlobs;
6638 ret->hasMods = u->hasMods;
6639 ret->exitCode = u->exitCode;
6640 ret->specialCode = u->specialCode;
6641 ret->nullPred = u->nullPred;
6642 ret->access = u->access;
6643 ret->globs = globSet_newCopy (u->globs);
6644 ret->mods = sRefSet_newCopy (u->mods);
6645 ret->defparams = u->defparams;
6646 ret->specclauses = stateClauseList_copy (u->specclauses);
6648 ret->preconditions = functionConstraint_copy (u->preconditions);
6649 ret->postconditions = functionConstraint_copy (u->postconditions);
6654 static /*@only@*/ uiinfo
6655 uiinfo_copy (uiinfo u)
6657 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6659 ret->access = u->access;
6660 ret->globs = globSet_newCopy (u->globs);
6661 ret->mods = sRefSet_newCopy (u->mods);
6666 static /*@only@*/ ueinfo
6667 ueinfo_copy (ueinfo u)
6669 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6671 ret->access = u->access;
6676 uinfo_free (uinfo u, ekind kind)
6681 case KCONST: ucinfo_free (u->uconst); break;
6682 case KVAR: uvinfo_free (u->var); break;
6686 case KDATATYPE: udinfo_free (u->datatype); break;
6687 case KFCN: ufinfo_free (u->fcn); break;
6688 case KITER: uiinfo_free (u->iter); break;
6689 case KENDITER: ueinfo_free (u->enditer); break;
6690 case KELIPSMARKER: break;
6691 case KINVALID: break;
6697 static /*@only@*/ /*@null@*/ uinfo
6698 uinfo_copy (uinfo u, ekind kind)
6700 if (kind == KELIPSMARKER || kind == KINVALID)
6706 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6711 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6712 case KVAR: ret->var = uvinfo_copy (u->var); break;
6716 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6717 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6718 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6719 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6727 uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6729 filelocList_free (e->uses);
6730 cstring_free (e->uname);
6732 uinfo_free (e->info, e->ukind);
6734 fileloc_free (e->whereSpecified);
6735 fileloc_free (e->whereDefined);
6736 fileloc_free (e->whereDeclared);
6738 warnClause_free (e->warn);
6744 extern void uentry_markOwned (/*@owned@*/ uentry u)
6746 sfreeEventually (u);
6750 uentry_free (/*@only@*/ uentry e)
6752 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6754 uentry_reallyFree (e);
6759 ** For uentry's in the global or file scope
6763 uentry_freeComplete (/*@only@*/ uentry e)
6765 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6767 DPRINTF (("Free complete: %s", sRef_unparseFull (e->sref)));
6768 /*@i@*/ sRef_free (e->sref);
6769 e->sref = sRef_undefined;
6770 uentry_reallyFree (e);
6775 ** requires old->kind != new->kind, old->uname = new->uname
6779 KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6781 llassert (uentry_isValid (old));
6782 llassert (uentry_isValid (unew));
6784 if (uentry_isEitherConstant (unew)
6785 && (fileloc_isPreproc (uentry_whereDeclared (old))
6786 || ctype_isUnknown (old->utype))
6787 && !uentry_isSpecified (old))
6795 if (!uentry_isDeclared (old))
6797 if (uentry_isSpecified (old))
6799 if (uentry_isSpecified (unew))
6801 llbuglit ("Respecification!");
6803 else if (uentry_isDeclared (unew))
6807 message ("%s %q inconsistently declared as %s: %t",
6808 ekind_capName (old->ukind),
6809 uentry_getName (unew),
6810 ekind_unparseLong (unew->ukind),
6812 uentry_whereDeclared (unew)))
6814 uentry_showWhereLast (old);
6826 message ("%s %q inconsistently declared as %s: %t",
6827 ekind_capName (old->ukind),
6828 uentry_getName (unew),
6829 ekind_unparseLong (unew->ukind),
6831 uentry_whereDeclared (unew)))
6833 uentry_showWhereLast (old);
6839 llassert (uentry_isDeclared (unew));
6843 message ("%s %q inconsistently redeclared as %s",
6844 ekind_capName (old->ukind),
6845 uentry_getName (unew),
6846 ekind_unparseLong (unew->ukind)),
6847 uentry_whereDeclared (unew)))
6849 uentry_showWhereLast (old);
6855 uentry_updateInto (old, unew);
6859 ** def is the definition of spec, modifies spec
6861 ** reports any inconsistencies
6862 ** returns the summary of all available information
6863 ** if spec and def are inconsistent, def is returned
6867 uentry_showWhereLast (uentry spec)
6869 if (uentry_isValid (spec))
6871 if (fileloc_isDefined (spec->whereDefined)
6872 && !fileloc_isLib (spec->whereDefined)
6873 && !fileloc_isPreproc (spec->whereDefined))
6875 llgenindentmsg (message ("Previous definition of %q: %t",
6876 uentry_getName (spec),
6877 uentry_getType (spec)),
6878 uentry_whereDefined (spec));
6880 else if (uentry_isDeclared (spec))
6882 llgenindentmsg (message ("Previous declaration of %q: %t",
6883 uentry_getName (spec),
6884 uentry_getType (spec)),
6885 uentry_whereDeclared (spec));
6887 else if (uentry_isSpecified (spec))
6889 if (uentry_hasName (spec))
6891 llgenindentmsg (message ("Specification of %q: %t",
6892 uentry_getName (spec),
6893 uentry_getType (spec)),
6894 uentry_whereSpecified (spec));
6898 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
6899 uentry_whereSpecified (spec));
6904 /* nothing to show */
6910 uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
6912 fileloc loc = uentry_whereDefined (ce);
6914 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6916 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
6920 loc = uentry_whereSpecified (ce);
6922 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6924 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
6929 void uentry_showWhereLastExtra (uentry spec, cstring extra)
6931 if (uentry_isDeclared (spec))
6933 llgenindentmsg (message ("Previous declaration of %q: %q",
6934 uentry_getName (spec), extra),
6935 uentry_whereDeclared (spec));
6937 else if (uentry_isSpecified (spec))
6939 llgenindentmsg (message ("Specification of %q: %q",
6940 uentry_getName (spec), extra),
6941 uentry_whereSpecified (spec));
6945 cstring_free (extra);
6950 uentry_showWhereDeclared (uentry spec)
6952 if (uentry_isDeclared (spec))
6954 if (uentry_hasName (spec))
6956 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6957 uentry_whereDeclared (spec));
6961 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6964 else if (uentry_isSpecified (spec))
6966 if (uentry_hasName (spec))
6968 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6969 uentry_whereSpecified (spec));
6973 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
6978 /* nothing to show */
6984 uentry_showWhereAny (uentry spec)
6986 if (uentry_isDeclared (spec))
6988 if (uentry_hasName (spec))
6990 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6991 uentry_whereDeclared (spec));
6995 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6998 else if (uentry_isSpecified (spec))
7000 if (uentry_hasName (spec))
7002 llgenindentmsg (message ("Specification of %q",
7003 uentry_getName (spec)),
7004 uentry_whereSpecified (spec));
7008 llgenindentmsg (cstring_makeLiteral ("Specification"),
7009 uentry_whereSpecified (spec));
7012 else if (fileloc_isDefined (uentry_whereDefined (spec)))
7014 if (uentry_hasName (spec))
7016 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
7017 uentry_whereDefined (spec));
7021 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
7026 /* nothing to show */
7031 uentry_showWhereDefined (uentry spec)
7033 if (uentry_isCodeDefined (spec))
7035 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
7036 uentry_whereDefined (spec));
7041 uentry_showWhereLastPlain (uentry spec)
7043 if (uentry_isDeclared (spec))
7045 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
7046 uentry_whereDeclared (spec));
7048 else if (uentry_isSpecified (spec))
7050 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7051 uentry_whereSpecified (spec));
7059 uentry_showWhereLastVal (uentry spec, cstring val)
7061 if (uentry_isDeclared (spec))
7063 llgenindentmsg (message ("Previous declaration of %q: %s",
7064 uentry_getName (spec), val),
7065 uentry_whereDeclared (spec));
7067 else if (uentry_isSpecified (spec))
7069 llgenindentmsg (message ("Specification of %q: %s",
7070 uentry_getName (spec), val),
7071 uentry_whereSpecified (spec));
7079 uentry_showWhereSpecified (uentry spec)
7081 if (uentry_isSpecified (spec))
7083 if (uentry_hasName (spec))
7085 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7086 uentry_whereSpecified (spec));
7090 llgenindentmsg (cstring_makeLiteral ("Specification"),
7091 uentry_whereSpecified (spec));
7094 else if (uentry_isDeclared (spec))
7096 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7097 uentry_whereDeclared (spec));
7101 /* nothing to show */
7106 uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
7108 if (uentry_isSpecified (spec))
7110 if (uentry_hasName (spec))
7112 llgenindentmsg (message ("Specification of %q: %q",
7113 uentry_getName (spec), s),
7114 uentry_whereSpecified (spec));
7118 llgenindentmsg (message ("Specification: %q", s),
7119 uentry_whereSpecified (spec));
7122 else if (uentry_isDeclared (spec))
7124 llgenindentmsg (message ("Declaration of %q: %q",
7125 uentry_getName (spec), s),
7126 uentry_whereDeclared (spec));
7130 llgenindentmsg (message ("Previous: %q", s),
7131 uentry_whereLast (spec));
7140 checkStructConformance (uentry old, uentry unew)
7143 uentryList fold, fnew;
7146 ** requires: types of old and new are structs or unions
7149 llassert (uentry_isValid (old));
7150 llassert (uentry_isValid (unew));
7152 oldr = ctype_realType (old->utype);
7153 fold = ctype_getFields (oldr);
7155 newr = ctype_realType (unew->utype);
7156 fnew = ctype_getFields (newr);
7158 if (!uentryList_matchFields (fold, fnew))
7160 if (fileloc_equal (uentry_whereLast (old),
7161 uentry_whereLast (unew)))
7169 message ("%q %q %rdeclared with fields { %q }, %s "
7170 "with fields { %q }",
7171 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
7172 uentry_getName (old),
7173 uentry_isDeclared (old),
7174 uentryList_unparseAbbrev (fnew),
7175 uentry_specOrDefName (old),
7176 uentryList_unparseAbbrev (fold)),
7177 uentry_whereDeclared (unew)))
7179 uentry_showWhereLastPlain (old);
7180 uentryList_showFieldDifference (fold, fnew);
7184 old->utype = unew->utype;
7189 checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7192 ** requires old and new are enums
7195 ctype rold = ctype_realType (old->utype);
7196 ctype rnew = ctype_realType (unew->utype);
7197 enumNameList eold = ctype_elist (rold);
7198 enumNameList enew = ctype_elist (rnew);
7200 if (!enumNameList_match (eold, enew))
7204 message ("Enum %q declared with members { %q } but "
7205 "specified with members { %q }",
7206 uentry_getName (old),
7207 enumNameList_unparse (enew),
7208 enumNameList_unparse (eold)),
7209 uentry_whereDeclared (unew)))
7211 uentry_showWhereSpecified (old);
7212 old->utype = unew->utype;
7218 ** either oldCurrent or newCurrent may be undefined!
7222 paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
7223 uentry unew, uentry newCurrent, ctype newType,
7226 bool hasError = FALSE;
7228 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
7230 if (uentry_hasName (newCurrent))
7232 hasError = optgenerror
7234 message ("Parameter %d, %q, of function %q has inconsistent type: "
7235 "declared %t, %s %t",
7236 paramno + 1, uentry_getName (newCurrent),
7237 uentry_getName (unew),
7238 newType, uentry_specOrDefName (old), oldType),
7239 uentry_whereDeclared (newCurrent));
7243 hasError = optgenerror
7245 message ("Parameter %d of function %q has inconsistent type: "
7246 "declared %t, %s %t",
7247 paramno + 1, uentry_getName (unew),
7248 newType, uentry_specOrDefName (old), oldType),
7249 uentry_whereDeclared (newCurrent));
7251 DPRINTF (("type: %s / %s",
7252 ctype_unparse (newType),
7253 ctype_unparse (ctype_realType (newType))));
7258 if (uentry_isDeclared (unew))
7260 hasError = optgenerror
7262 message ("Parameter %d of function %s has inconsistent type: "
7263 "declared %t, %s %t",
7264 paramno + 1, unew->uname,
7265 newType, uentry_specOrDefName (old), oldType),
7266 uentry_whereDeclared (unew));
7270 hasError = optgenerror
7272 message ("Parameter %d of function %s has inconsistent type: "
7273 "declared %t, %s %t",
7274 paramno + 1, unew->uname,
7275 newType, uentry_specOrDefName (old), oldType),
7276 uentry_whereDeclared (unew));
7282 DPRINTF (("Here: %s / %s",
7283 uentry_unparseFull (oldCurrent),
7284 uentry_unparseFull (newCurrent)));
7286 if (!uentry_isUndefined (oldCurrent))
7288 if (!uentry_isUndefined (newCurrent)
7289 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
7291 uentry_showWhereLast (oldCurrent);
7295 uentry_showWhereLastPlain (old);
7298 uentry_setType (oldCurrent, newType);
7302 uentry_showWhereLastPlain (old);
7308 nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7312 message ("Function %s %rdeclared with %d arg%&, %s with %d",
7314 uentry_isDeclared (old),
7315 uentryList_size (uentry_getParams (unew)),
7316 uentry_specOrDefName (old),
7317 uentryList_size (uentry_getParams (old))),
7318 uentry_whereDeclared (unew)))
7320 uentry_showWhereLastPlain (old);
7325 returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7329 message ("Function %s inconsistently %rdeclared to return %t",
7331 uentry_isDeclared (old),
7332 ctype_getReturnType (unew->utype)),
7333 uentry_whereDeclared (unew)))
7335 uentry_showWhereLastVal (old, ctype_unparse (ctype_getReturnType (old->utype)));
7339 static cstring paramStorageName (uentry ue)
7341 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
7344 static cstring fcnErrName (uentry ue)
7346 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
7349 extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
7351 if (uentry_isVar (ue))
7353 return (checkedName (ue->info->var->checked));
7357 return (cstring_makeLiteralTemp ("<checked invalid>"));
7361 static cstring checkedName (chkind checked)
7365 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
7366 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
7367 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
7368 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
7369 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
7375 void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
7380 if (uentry_isVar (unew))
7382 llassert (uentry_isVar (old));
7384 oldState = old->info->var->nullstate;
7385 newState = unew->info->var->nullstate;
7389 oldState = sRef_getNullState (old->sref);
7390 newState = sRef_getNullState (unew->sref);
7393 if (oldState == NS_ABSNULL)
7395 if (uentry_isVar (old))
7397 old->info->var->nullstate = newState;
7400 sRef_mergeNullState (old->sref, newState);
7402 else if (newState == NS_UNKNOWN)
7404 if (completeConform && newState != oldState
7405 && uentry_isReallySpecified (old))
7409 message ("%s %q specified as %s, but declared without %s qualifier",
7410 ekind_capName (unew->ukind),
7411 uentry_getName (unew),
7412 nstate_unparse (oldState),
7413 nstate_unparse (oldState)),
7414 uentry_whereDeclared (unew)))
7416 uentry_showWhereSpecified (old);
7420 if (uentry_isVar (unew))
7422 unew->info->var->nullstate = oldState;
7425 sRef_mergeNullState (unew->sref, oldState);
7427 else if (newState == NS_POSNULL)
7429 if (oldState == NS_MNOTNULL
7430 && (ctype_isUA (unew->utype)
7431 || (uentry_isFunction (unew)
7432 && ctype_isUA (ctype_getReturnType (unew->utype)))))
7434 if (uentry_isVar (unew))
7436 unew->info->var->nullstate = oldState;
7439 sRef_mergeNullState (unew->sref, oldState);
7443 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
7444 || oldState == NS_UNKNOWN)
7451 ("%s %q inconsistently %rdeclared %s possibly null storage, "
7453 uentry_ekindName (unew),
7454 uentry_getName (unew),
7455 uentry_isDeclared (old),
7457 uentry_specOrDefName (old),
7458 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
7459 uentry_whereDeclared (unew)))
7461 uentry_showWhereSpecified (old);
7466 if (uentry_isVar (old))
7468 old->info->var->nullstate = newState;
7471 sRef_mergeNullState (old->sref, newState);
7474 else if (newState == NS_MNOTNULL)
7476 if (oldState != NS_MNOTNULL)
7482 message ("%s %q inconsistently %rdeclared %s notnull storage, "
7483 "%s without notnull qualifier",
7484 uentry_ekindName (unew),
7485 uentry_getName (unew),
7486 uentry_isDeclared (old),
7488 uentry_specOrDefName (old)),
7489 uentry_whereDeclared (unew)))
7491 uentry_showWhereSpecified (old);
7495 if (uentry_isVar (old))
7497 old->info->var->nullstate = newState;
7500 sRef_mergeNullState (old->sref, newState);
7505 if (uentry_isVar (unew))
7507 unew->info->var->nullstate = oldState;
7510 sRef_mergeNullState (unew->sref, oldState);
7515 void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7516 bool mustConform, bool completeConform)
7522 if (uentry_isVar (old) && uentry_isVar (unew))
7524 oldState = old->info->var->defstate;
7525 newState = unew->info->var->defstate;
7530 oldState = sRef_getDefState (old->sref);
7531 newState = sRef_getDefState (unew->sref);
7534 if (newState != oldState
7535 && newState != SS_UNKNOWN
7536 && newState != SS_DEFINED)
7542 message ("%s %q inconsistently %rdeclared %s %s %s, "
7544 uentry_ekindName (unew),
7545 uentry_getName (unew),
7546 uentry_isDeclared (old),
7548 sstate_unparse (newState),
7549 paramStorageName (unew),
7550 uentry_specOrDefName (old),
7552 sstate_unparse (oldState),
7553 paramStorageName (unew)),
7554 uentry_whereDeclared (unew)))
7556 uentry_showWhereSpecified (old);
7560 if (vars) old->info->var->defstate = newState;
7561 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
7566 && (newState != oldState) && (oldState != SS_DEFINED)
7567 && uentry_isReallySpecified (old))
7571 message ("%s %q specified as %s, but declared without %s qualifier",
7572 ekind_capName (unew->ukind),
7573 uentry_getName (unew),
7574 sstate_unparse (oldState),
7575 sstate_unparse (oldState)),
7576 uentry_whereDeclared (unew)))
7578 uentry_showWhereSpecified (old);
7582 if (vars) unew->info->var->defstate = oldState;
7583 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
7588 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7589 bool mustConform, bool completeConform)
7594 oldKind = sRef_getAliasKind (old->sref);
7595 newKind = sRef_getAliasKind (unew->sref);
7597 if (alkind_isImplicit (newKind)
7598 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
7600 if (completeConform && !alkind_equal (newKind, oldKind)
7601 && uentry_isReallySpecified (old))
7605 message ("%s %q specified as %s, but declared without "
7606 "explicit alias qualifier",
7607 ekind_capName (unew->ukind),
7608 uentry_getName (unew),
7609 alkind_unparse (oldKind)),
7610 uentry_whereDeclared (unew)))
7612 uentry_showWhereSpecified (old);
7617 ** This really shouldn't be necessary, but it is!
7618 ** Function params (?) use new here.
7621 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7625 if (alkind_isKnown (newKind))
7627 if (!alkind_equal (oldKind, newKind))
7629 if (alkind_isKnown (oldKind))
7634 message ("%s %q inconsistently %rdeclared %s %s storage, "
7636 uentry_ekindName (unew),
7637 uentry_getName (unew),
7638 uentry_isDeclared (old),
7640 alkind_unparse (newKind),
7641 uentry_specOrDefName (old),
7642 alkind_unparse (oldKind)),
7643 uentry_whereDeclared (unew)))
7645 uentry_showWhereSpecified (old);
7647 DPRINTF (("Old: %s", sRef_unparseFull (old->sref)));
7648 DPRINTF (("New: %s", sRef_unparseFull (unew->sref)));
7649 sRef_setAliasKind (old->sref, AK_ERROR,
7650 uentry_whereDeclared (unew));
7654 sRef_setAliasKind (old->sref, newKind,
7655 uentry_whereDeclared (unew));
7660 if (!(alkind_isImplicit (newKind)))
7663 !uentry_isFunction (unew) &&
7666 message ("%s %q inconsistently %rdeclared %s %s storage, "
7667 "implicitly %s as temp storage",
7668 uentry_ekindName (unew),
7669 uentry_getName (unew),
7670 uentry_isDeclared (old),
7672 alkind_unparse (newKind),
7673 uentry_specOrDefName (old)),
7674 uentry_whereDeclared (unew)))
7676 uentry_showWhereSpecified (old);
7680 sRef_setAliasKind (old->sref, newKind,
7681 uentry_whereDeclared (unew));
7683 else /* newKind is temp or refcounted */
7690 else /* newKind unknown */
7697 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7698 bool mustConform, bool completeConform)
7703 oldKind = sRef_getExKind (old->sref);
7704 newKind = sRef_getExKind (unew->sref);
7706 if (exkind_isKnown (newKind))
7708 if (oldKind != newKind)
7710 if (exkind_isKnown (oldKind))
7715 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7716 uentry_ekindName (unew),
7717 uentry_getName (unew),
7718 uentry_isDeclared (old),
7720 exkind_unparse (newKind),
7721 uentry_specOrDefName (old),
7722 exkind_unparse (oldKind)),
7723 uentry_whereDeclared (unew)))
7725 uentry_showWhereSpecified (old);
7728 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7735 message ("%s %q inconsistently %rdeclared %s %s, "
7736 "implicitly %s without exposure qualifier",
7737 uentry_ekindName (unew),
7738 uentry_getName (unew),
7739 uentry_isDeclared (old),
7741 exkind_unparse (newKind),
7742 uentry_specOrDefName (old)),
7743 uentry_whereDeclared (unew)))
7745 uentry_showWhereSpecified (old);
7748 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7754 if (completeConform && exkind_isKnown (oldKind)
7755 && uentry_isReallySpecified (old))
7759 message ("%s %q specified as %s, but declared without "
7760 "exposure qualifier",
7761 ekind_capName (unew->ukind),
7762 uentry_getName (unew),
7763 exkind_unparse (oldKind)),
7764 uentry_whereDeclared (unew)))
7766 uentry_showWhereSpecified (old);
7770 /* yes, this is necessary! (if its a param) */
7771 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7776 checkMetaState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7777 bool mustConform, /*@unused@*/ bool completeConform)
7779 valueTable newvals = sRef_getValueTable (unew->sref);
7781 if (valueTable_isDefined (newvals))
7783 DPRINTF (("Check meta state: %s -> %s",
7784 uentry_unparseFull (old),
7785 uentry_unparseFull (unew)));
7787 DPRINTF (("Check meta state refs: %s -> %s",
7788 sRef_unparseFull (old->sref),
7789 sRef_unparseFull (unew->sref)));
7791 DPRINTF (("Value table: %s", valueTable_unparse (newvals)));
7794 ** Copy the new values into the old ref
7797 valueTable_elements (newvals, key, newval)
7799 metaStateInfo msinfo = context_lookupMetaStateInfo (key);
7800 stateValue oldval = sRef_getMetaStateValue (old->sref, key);
7802 llassert (metaStateInfo_isDefined (msinfo));
7804 if (stateValue_isUndefined (oldval))
7806 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7810 if (stateValue_isError (oldval))
7812 if (!stateValue_isError (newval))
7814 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7818 ; /* No change necessary. */
7823 if (stateValue_getValue (newval) != stateValue_getValue (oldval))
7825 if (fileloc_isXHFile (uentry_whereDeclared (unew)))
7831 if (!stateValue_isError (newval)
7832 && !stateValue_isImplicit (newval))
7834 if (uentry_hasName (unew)
7835 || !sRef_isParam (uentry_getSref (unew)))
7840 message ("%s %q inconsistently %rdeclared %s %q, %s as %q",
7841 uentry_ekindName (unew),
7842 uentry_getName (unew),
7843 uentry_isDeclared (old),
7845 stateValue_unparseValue (newval, msinfo),
7846 uentry_specOrDefName (old),
7847 stateValue_unparseValue (oldval, msinfo)),
7848 uentry_whereDeclared (unew)))
7850 uentry_showWhereSpecified (old);
7858 message ("%s %d inconsistently %rdeclared %s %q, %s as %q",
7859 uentry_ekindName (unew),
7860 sRef_getParam (uentry_getSref (unew)),
7861 uentry_isDeclared (old),
7863 stateValue_unparseValue (newval, msinfo),
7864 uentry_specOrDefName (old),
7865 stateValue_unparseValue (oldval, msinfo)),
7866 uentry_whereDeclared (unew)))
7868 uentry_showWhereSpecified (old);
7874 DPRINTF (("Updating!"));
7875 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7879 DPRINTF (("Values match"));
7883 } end_valueTable_elements ;
7888 uentry_checkStateConformance (/*@notnull@*/ uentry old,
7889 /*@notnull@*/ uentry unew,
7890 bool mustConform, bool completeConform)
7892 checkDefState (old, unew, mustConform, completeConform);
7893 checkNullState (old, unew, mustConform, completeConform);
7894 checkAliasState (old, unew, mustConform, completeConform);
7895 checkExpState (old, unew, mustConform, completeConform);
7896 checkMetaState (old, unew, mustConform, completeConform);
7898 sRef_storeState (old->sref);
7899 sRef_storeState (unew->sref);
7903 checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
7905 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
7910 llassert (uentry_isVar (old));
7911 llassert (uentry_isVar (unew));
7913 if (cstring_isEmpty (old->uname))
7915 cstring_free (old->uname);
7916 old->uname = cstring_copy (unew->uname);
7919 if (unew->info->var->kind == VKRETPARAM
7920 || unew->info->var->kind == VKSEFRETPARAM)
7922 if (old->info->var->kind != VKRETPARAM
7923 && old->info->var->kind != VKSEFRETPARAM)
7927 message ("Parameter %q inconsistently %rdeclared as "
7928 "returned parameter",
7929 uentry_getName (unew),
7930 uentry_isDeclared (old)),
7931 uentry_whereDeclared (unew)))
7933 uentry_showWhereSpecified (old);
7934 old->info->var->kind = unew->info->var->kind;
7940 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
7942 if (old->info->var->kind != VKSEFPARAM
7943 && old->info->var->kind != VKSEFRETPARAM)
7947 message ("Parameter %qinconsistently %rdeclared as "
7949 uentry_getOptName (unew),
7950 uentry_isDeclared (old)),
7951 uentry_whereDeclared (unew)))
7953 uentry_showWhereSpecified (old);
7954 old->info->var->kind = unew->info->var->kind;
7959 if (old->info->var->kind == VKSPEC)
7961 old->info->var->kind = unew->info->var->kind;
7965 unew->info->var->kind = old->info->var->kind;
7968 if (unew->info->var->checked != CH_UNKNOWN
7969 && unew->info->var->checked != old->info->var->checked)
7971 if (old->info->var->checked == CH_UNKNOWN
7972 && !fileloc_isUser (uentry_whereLast (old)))
7980 message ("Variable %q inconsistently %rdeclared as "
7981 "%s parameter (was %s)",
7982 uentry_getName (unew),
7983 uentry_isDeclared (old),
7984 checkedName (unew->info->var->checked),
7985 checkedName (old->info->var->checked)),
7986 uentry_whereDeclared (unew)))
7988 uentry_showWhereSpecified (old);
7992 old->info->var->checked = unew->info->var->checked;
7997 && (old->info->var->checked != CH_UNKNOWN)
7998 && uentry_isReallySpecified (old))
8002 message ("%s %q specified as %s, but declared without %s qualifier",
8003 ekind_capName (unew->ukind),
8004 uentry_getName (unew),
8005 checkedName (old->info->var->checked),
8006 checkedName (old->info->var->checked)),
8007 uentry_whereDeclared (unew)))
8009 uentry_showWhereSpecified (old);
8013 unew->info->var->checked = old->info->var->checked;
8016 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8019 void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
8021 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
8026 llassert (uentry_isVar (u1));
8027 llassert (uentry_isVar (u2));
8029 if (u1->info->var->kind != u2->info->var->kind) {
8030 if (u1->info->var->kind == VKSEFRETPARAM) {
8031 if (u2->info->var->kind == VKRETPARAM) {
8034 message ("Function types are inconsistent. Parameter %d is "
8035 "sef parameter, but non-sef parameter in "
8036 "assigned function: %s",
8037 paramno, exprNode_unparse (e)),
8039 } else if (u2->info->var->kind == VKSEFPARAM) {
8042 message ("Function types are inconsistent. Parameter %d is "
8043 "returns parameter, but non-returns parameter in "
8044 "assigned function: %s",
8045 paramno, exprNode_unparse (e)),
8050 message ("Function types are inconsistent. Parameter %d is "
8051 "sef returns parameter, but non-sef returns parameter in "
8052 "assigned function: %s",
8053 paramno, exprNode_unparse (e)),
8056 } else if (u1->info->var->kind == VKRETPARAM) {
8059 message ("Function types are inconsistent. Parameter %d is "
8060 "returns parameter, but non-returns parameter in "
8061 "assigned function: %s",
8062 paramno, exprNode_unparse (e)),
8064 } else if (u1->info->var->kind == VKSEFPARAM) {
8067 message ("Function types are inconsistent. Parameter %d is "
8068 "sef parameter, but non-sef parameter in "
8069 "assigned function: %s",
8070 paramno, exprNode_unparse (e)),
8073 if (u2->info->var->kind == VKSEFRETPARAM) {
8076 message ("Function types are inconsistent. Parameter %d is "
8077 "normal parameter, but sef returns parameter in "
8078 "assigned function: %s",
8079 paramno, exprNode_unparse (e)),
8081 } else if (u2->info->var->kind == VKSEFPARAM) {
8084 message ("Function types are inconsistent. Parameter %d is "
8085 "normal parameter, but sef parameter in "
8086 "assigned function: %s",
8087 paramno, exprNode_unparse (e)),
8089 } else if (u2->info->var->kind == VKRETPARAM) {
8092 message ("Function types are inconsistent. Parameter %d is "
8093 "normal parameter, but returns parameter in "
8094 "assigned function: %s",
8095 paramno, exprNode_unparse (e)),
8103 if (u1->info->var->defstate != u2->info->var->defstate)
8107 message ("Function types are inconsistent. Parameter %d is "
8108 "%s, but %s in assigned function: %s",
8110 sstate_unparse (u1->info->var->defstate),
8111 sstate_unparse (u2->info->var->defstate),
8112 exprNode_unparse (e)),
8116 if (u1->info->var->nullstate != u2->info->var->nullstate)
8120 message ("Function types are inconsistent. Parameter %d is "
8121 "%s, but %s in assigned function: %s",
8123 nstate_unparse (u1->info->var->nullstate),
8124 nstate_unparse (u2->info->var->nullstate),
8125 exprNode_unparse (e)),
8129 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
8133 message ("Function types are inconsistent. Parameter %d is "
8134 "%s, but %s in assigned function: %s",
8136 alkind_unparse (sRef_getAliasKind (u1->sref)),
8137 alkind_unparse (sRef_getAliasKind (u2->sref)),
8138 exprNode_unparse (e)),
8142 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
8146 message ("Function types are inconsistent. Parameter %d is "
8147 "%s, but %s in assigned function: %s",
8149 exkind_unparse (sRef_getExKind (u1->sref)),
8150 exkind_unparse (sRef_getExKind (u2->sref)),
8151 exprNode_unparse (e)),
8157 checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8158 /*@notnull@*/ uentry unew,
8159 bool mustConform, /*@unused@*/ bool completeConform)
8161 uentryList oldParams = uentry_getParams (old);
8162 uentryList newParams = uentry_getParams (unew);
8163 ctype newType = unew->utype;
8164 ctype oldType = old->utype;
8165 ctype oldRetType = ctype_unknown;
8166 ctype newRetType = ctype_unknown;
8168 DPRINTF (("Function conform: %s ==> %s",
8169 uentry_unparseFull (old),
8170 uentry_unparseFull (unew)));
8172 if (uentry_isForward (old))
8174 mustConform = FALSE;
8175 uentry_updateInto (old, unew);
8180 ** check return values
8183 if (ctype_isKnown (oldType))
8185 llassert (ctype_isFunction (oldType));
8187 oldRetType = ctype_getReturnType (oldType);
8190 if (ctype_isKnown (newType))
8192 llassert (ctype_isFunction (newType));
8194 newRetType = ctype_getReturnType (newType);
8197 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
8198 && !ctype_matchDef (newRetType, oldRetType))
8200 if (mustConform) returnValueError (old, unew);
8204 if (ctype_isConj (newRetType))
8206 if (ctype_isConj (oldRetType))
8208 if (!ctype_sameAltTypes (newRetType, oldRetType))
8212 message ("Function %q inconsistently %rdeclared to "
8213 "return alternate types %s "
8214 "(types match, but alternates are not identical, "
8215 "so checking may not be correct)",
8216 uentry_getName (unew),
8217 uentry_isDeclared (old),
8218 ctype_unparse (newRetType)),
8219 uentry_whereDeclared (unew)))
8221 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
8227 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
8232 DPRINTF (("Before state: %s",
8233 uentry_unparseFull (old)));
8234 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8235 DPRINTF (("After state: %s",
8236 uentry_unparseFull (old)));
8238 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
8240 if (exitkind_isKnown (unew->info->fcn->exitCode))
8244 message ("Function %q inconsistently %rdeclared using %s",
8245 uentry_getName (unew),
8246 uentry_isDeclared (old),
8247 exitkind_unparse (unew->info->fcn->exitCode)),
8248 uentry_whereDeclared (unew)))
8250 uentry_showWhereSpecified (old);
8255 unew->info->fcn->exitCode = old->info->fcn->exitCode;
8259 if (!qual_isUnknown (unew->info->fcn->nullPred))
8261 if (!qual_match (old->info->fcn->nullPred, unew->info->fcn->nullPred))
8265 message ("Function %q inconsistently %rdeclared using %s",
8266 uentry_getName (unew),
8267 uentry_isDeclared (old),
8268 qual_unparse (unew->info->fcn->nullPred)),
8269 uentry_whereDeclared (unew)))
8271 uentry_showWhereSpecified (old);
8277 unew->info->fcn->nullPred = old->info->fcn->nullPred;
8280 if (unew->info->fcn->specialCode != SPC_NONE)
8282 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
8286 message ("Function %q inconsistently %rdeclared using %s",
8287 uentry_getName (unew),
8288 uentry_isDeclared (old),
8289 specCode_unparse (unew->info->fcn->specialCode)),
8290 uentry_whereDeclared (unew)))
8292 uentry_showWhereSpecified (old);
8298 unew->info->fcn->specialCode = old->info->fcn->specialCode;
8305 if (!uentryList_sameObject (oldParams, newParams)
8306 && (!uentryList_isMissingParams (oldParams)))
8308 if (!uentryList_isMissingParams (newParams))
8311 int nparams = uentryList_size (oldParams);
8312 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
8314 if (nparams != uentryList_size (newParams))
8316 nargsError (old, unew);
8319 if (uentryList_size (newParams) < nparams)
8321 nparams = uentryList_size (newParams);
8324 while (paramno < nparams)
8326 uentry oldCurrent = uentryList_getN (oldParams, paramno);
8327 uentry newCurrent = uentryList_getN (newParams, paramno);
8328 ctype oldCurrentType = uentry_getType (oldCurrent);
8329 ctype newCurrentType = uentry_getType (newCurrent);
8331 llassert (uentry_isValid (oldCurrent)
8332 && uentry_isValid (newCurrent));
8334 if (!uentry_isElipsisMarker (oldCurrent)
8335 && !uentry_isElipsisMarker (newCurrent))
8337 checkVarConformance (oldCurrent, newCurrent,
8338 mustConform, completeConform);
8343 if (uentry_hasName (oldCurrent)
8344 && uentry_hasName (newCurrent))
8346 cstring oldname = uentry_getName (oldCurrent);
8347 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
8349 cstring nname = uentry_getName (newCurrent);
8352 if (cstring_isDefined (pfx)
8353 && cstring_equalPrefix (oldname, pfx))
8355 oname = cstring_suffix (oldname, cstring_length (pfx));
8360 /*@-branchstate@*/ } /*@=branchstate@*/
8362 if (cstring_isDefined (pfx)
8363 && cstring_equalPrefix (nname, pfx))
8365 nnamefix = cstring_suffix (nname, cstring_length (pfx));
8370 /*@-branchstate@*/ } /*@=branchstate@*/
8372 if (!cstring_equal (oname, nnamefix))
8375 (FLG_DECLPARAMMATCH,
8376 message ("Definition parameter name %s does not match "
8377 "name of corresponding parameter in "
8380 uentry_whereLast (newCurrent)))
8382 uentry_showWhereLastPlain (oldCurrent);
8386 cstring_free (oldname);
8387 cstring_free (nname);
8391 if (!ctype_match (oldCurrentType, newCurrentType))
8393 paramTypeError (old, oldCurrent, oldCurrentType,
8394 unew, newCurrent, newCurrentType, paramno);
8398 if (ctype_isMissingParamsMarker (newCurrentType)
8399 || ctype_isElips (newCurrentType)
8400 || ctype_isMissingParamsMarker (oldCurrentType)
8401 || ctype_isElips (oldCurrentType))
8407 if (ctype_isConj (newCurrentType))
8409 if (ctype_isConj (oldCurrentType))
8411 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
8415 message ("Parameter %q inconsistently %rdeclared with "
8416 "alternate types %s "
8417 "(types match, but alternates are not identical, "
8418 "so checking may not be correct)",
8419 uentry_getName (newCurrent),
8420 uentry_isDeclared (oldCurrent),
8421 ctype_unparse (newCurrentType)),
8422 uentry_whereDeclared (unew)))
8424 uentry_showWhereLastVal (oldCurrent,
8425 ctype_unparse (oldCurrentType));
8433 message ("Parameter %q inconsistently %rdeclared with "
8434 "alternate types %s",
8435 uentry_getName (newCurrent),
8436 uentry_isDeclared (oldCurrent),
8437 ctype_unparse (newCurrentType)),
8438 uentry_whereDeclared (unew)))
8440 uentry_showWhereLastVal (oldCurrent,
8441 ctype_unparse (oldCurrentType));
8448 if (ctype_isConj (oldCurrentType))
8450 uentry_setType (newCurrent, oldCurrentType);
8458 ** Forgot this! detected by lclint:
8459 ** uentry.c:1257,15: Suspected infinite loop
8465 if (!uentryList_isMissingParams (newParams))
8467 if (ctype_isConj (oldRetType))
8469 old->utype = ctype_makeFunction (oldRetType,
8470 uentryList_copy (newParams));
8474 old->utype = unew->utype;
8478 checkGlobalsConformance (old, unew, mustConform, completeConform);
8479 checkModifiesConformance (old, unew, mustConform, completeConform);
8481 DPRINTF (("Before list: %s",
8482 uentry_unparseFull (old)));
8484 if (stateClauseList_isDefined (unew->info->fcn->specclauses))
8486 if (!stateClauseList_isDefined (old->info->fcn->specclauses))
8491 message ("Function %q redeclared using special clauses (can only "
8492 "be used in first declaration)",
8493 uentry_getName (unew)),
8494 uentry_whereDeclared (unew)))
8496 uentry_showWhereLast (old);
8500 /*@i23 need checking @*/
8502 old->info->fcn->specclauses = unew->info->fcn->specclauses;
8506 /*@i43 should be able to append? @*/
8508 stateClauseList_checkEqual (old, unew);
8509 stateClauseList_free (unew->info->fcn->specclauses);
8510 unew->info->fcn->specclauses = stateClauseList_undefined;
8513 /*@=branchstate@*/ /*@i23 shouldn't need this@*/
8516 if (fileloc_isUndefined (old->whereDeclared))
8518 old->whereDeclared = fileloc_copy (unew->whereDeclared);
8520 else if (fileloc_isUndefined (unew->whereDeclared))
8522 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8531 uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
8535 llassert (uentry_isValid (ue));
8536 llassert (uentry_isEitherConstant (ue));
8538 DPRINTF (("Constant value: %s / %s", uentry_unparse (ue), multiVal_unparse (m)));
8539 uval = uentry_getConstantValue (ue);
8541 if (multiVal_isDefined (uval))
8543 if (multiVal_isDefined (m))
8545 if (!multiVal_equiv (uval, m))
8549 message ("%s %q defined with inconsistent value: %q",
8550 ekind_capName (ue->ukind),
8551 uentry_getName (ue),
8552 multiVal_unparse (m)),
8555 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
8563 uentry_setConstantValue (ue, m);
8568 bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
8571 bool typeError = FALSE;
8573 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
8575 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
8579 DPRINTF (("Check struct conformance: %s / %s",
8580 uentry_unparseFull (old),
8581 uentry_unparseFull (unew)));
8582 checkStructConformance (old, unew);
8587 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8589 llbug (message ("struct tags: bad types: %t / %t",
8590 old->utype, unew->utype));
8594 else if (uentry_isEnumTag (old))
8596 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
8598 if (mustConform) checkEnumConformance (old, unew);
8602 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8604 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
8605 ctype_unparse (unew->utype)));
8609 else if (!ctype_match (old->utype, unew->utype))
8611 DPRINTF (("Type mismatch: %s / %s",
8612 ctype_unparse (old->utype),
8613 ctype_unparse (unew->utype)));
8615 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
8617 ctype realt = ctype_realType (unew->utype);
8619 if (ctype_isRealInt (realt) || ctype_isChar (realt))
8621 unew->utype = ctype_bool;
8627 typeError = optgenerror
8629 message ("%q defined as %s", uentry_getName (old),
8630 ctype_unparse (realt)),
8631 uentry_whereDeclared (unew));
8639 ctype oldr = ctype_realType (old->utype);
8640 ctype newr = ctype_realType (unew->utype);
8642 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
8644 checkStructConformance (old, unew);
8646 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
8648 checkStructConformance (old, unew);
8650 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
8652 checkEnumConformance (old, unew);
8654 else if (uentry_isConstant (old)
8655 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
8657 /* okay...for now! (should check the type is reset later... */
8661 DPRINTF (("YABA!"));
8664 message ("%s %q %rdeclared with inconsistent type: %t",
8665 ekind_capName (unew->ukind),
8666 uentry_getName (unew),
8667 uentry_isDeclared (old),
8669 uentry_whereDeclared (unew)))
8671 uentry_showWhereLast (old);
8687 uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
8688 /*@notnull@*/ uentry unew,
8689 bool mustConform, bool completeConform)
8691 if (ctype_isDefined (unew->info->datatype->type))
8694 ** bool is hard coded here, since it is built into LCL.
8695 ** For now, we're stuck with LCL's types.
8698 if (ctype_isDirectBool (old->utype) &&
8699 cstring_equalLit (unew->uname, "bool"))
8701 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
8702 evs 2000-07-25: removed
8704 unew->utype = ctype_bool;
8707 if (ctype_isUnknown (old->info->datatype->type))
8709 old->info->datatype->type = unew->info->datatype->type;
8713 DPRINTF (("Old: %s / New: %s",
8714 uentry_unparseFull (old),
8715 uentry_unparseFull (unew)));
8716 DPRINTF (("Types: %s / %s",
8717 ctype_unparse (old->info->datatype->type),
8718 ctype_unparse (unew->info->datatype->type)));
8720 if (ctype_matchDef (old->info->datatype->type,
8721 unew->info->datatype->type))
8730 ("Type %q %s with inconsistent type: %t",
8731 uentry_getName (unew),
8732 uentry_reDefDecl (old, unew),
8733 unew->info->datatype->type),
8734 uentry_whereDeclared (unew)))
8736 uentry_showWhereLastExtra
8737 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
8740 old->info->datatype->type = unew->info->datatype->type;
8745 if (unew->info->datatype->abs != MAYBE)
8747 if (ynm_isOff (old->info->datatype->abs)
8748 && ynm_isOn (unew->info->datatype->abs))
8750 if (!ctype_isDirectBool (old->utype))
8755 ("Datatype %q inconsistently %rdeclared as abstract type",
8756 uentry_getName (unew),
8757 uentry_isDeclared (old)),
8758 uentry_whereDeclared (unew)))
8760 uentry_showWhereLastPlain (old);
8764 else if (ynm_isOn (old->info->datatype->abs)
8765 && ynm_isOff (unew->info->datatype->abs))
8767 if (!ctype_isDirectBool (old->utype))
8772 ("Datatype %q inconsistently %rdeclared as concrete type",
8773 uentry_getName (unew),
8774 uentry_isDeclared (old)),
8775 uentry_whereDeclared (unew)))
8777 uentry_showWhereLastPlain (old);
8788 if (ynm_isOn (old->info->datatype->abs))
8790 old->sref = unew->sref;
8791 unew->info->datatype->mut = old->info->datatype->mut;
8794 && uentry_isReallySpecified (old))
8799 ("Datatype %q specified as abstract, "
8800 "but abstract annotation not used in declaration",
8801 uentry_getName (unew)),
8802 uentry_whereDeclared (unew)))
8804 uentry_showWhereLastPlain (old);
8810 unew->info->datatype->abs = old->info->datatype->abs;
8812 if (ynm_isMaybe (unew->info->datatype->mut))
8814 if (completeConform && ynm_isOff (old->info->datatype->mut)
8815 && uentry_isReallySpecified (old))
8820 ("Datatype %q specified as immutable, "
8821 "but immutable annotation not used in declaration",
8822 uentry_getName (unew)),
8823 uentry_whereDeclared (unew)))
8825 uentry_showWhereLastPlain (old);
8829 unew->info->datatype->mut = old->info->datatype->mut;
8831 else if (ynm_isMaybe (old->info->datatype->mut))
8833 old->info->datatype->mut = unew->info->datatype->mut;
8837 if (ynm_isOn (old->info->datatype->abs))
8839 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
8843 message ("Datatype %q inconsistently %rdeclared as immutable",
8844 uentry_getName (unew),
8845 uentry_isDeclared (old)),
8846 uentry_whereDeclared (unew)))
8848 uentry_showWhereLastPlain (old);
8853 if (ynm_isOff (old->info->datatype->mut)
8854 && ynm_isOn (unew->info->datatype->mut))
8858 message ("Datatype %q inconsistently %rdeclared as mutable",
8859 uentry_getName (unew),
8860 uentry_isDeclared (old)),
8861 uentry_whereDeclared (unew)))
8863 uentry_showWhereLastPlain (old);
8868 old->info->datatype->mut = unew->info->datatype->mut;
8871 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8875 uentry_checkConstantConformance (/*@notnull@*/ uentry old,
8876 /*@notnull@*/ uentry unew,
8878 /*@unused@*/ bool completeConform)
8880 multiVal oldval = uentry_getConstantValue (old);
8881 multiVal newval = uentry_getConstantValue (unew);
8883 if (multiVal_isDefined (oldval))
8885 if (multiVal_isDefined (newval))
8887 if (!multiVal_equiv (oldval, newval))
8892 message ("%s %q %rdeclared with inconsistent value: %q",
8893 ekind_capName (unew->ukind),
8894 uentry_getName (unew),
8895 uentry_isDeclared (old),
8896 multiVal_unparse (newval)),
8897 uentry_whereDeclared (unew)))
8899 uentry_showWhereLastExtra (old, multiVal_unparse (oldval));
8903 uentry_setConstantValue (unew, multiVal_copy (oldval));
8912 uentry_setConstantValue (old, multiVal_copy (newval));
8917 uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8918 /*@notnull@*/ uentry unew, bool mustConform,
8919 bool completeConform)
8921 bool typeError = FALSE;
8922 bool fcnConformance = FALSE;
8924 if (!ekind_equal (unew->ukind, old->ukind))
8927 ** okay, only if one is a function and the other is
8928 ** a variable of type function.
8931 if (unew->ukind == KENUMCONST
8932 && old->ukind == KCONST)
8934 old->ukind = KENUMCONST;
8938 if (unew->ukind == KFCN
8939 && old->ukind == KCONST
8940 && ctype_isUnknown (old->utype))
8943 ** When a function is defined with an unparam macro
8946 uentry_updateInto (old, unew);
8950 if (uentry_isExpandedMacro (old)
8951 && uentry_isEitherConstant (unew))
8953 uentry_updateInto (old, unew);
8957 if (uentry_isEndIter (unew))
8959 if (ctype_isUnknown (old->utype))
8961 if (!uentry_isSpecified (old)
8962 && uentry_isCodeDefined (unew))
8964 if (!fileloc_withinLines (uentry_whereDefined (old),
8965 uentry_whereDeclared (unew), 2))
8966 { /* bogus! will give errors if there is too much whitespace */
8970 ("Iterator finalized name %q does not match name in "
8971 "previous iter declaration (should be end_%q). This iter "
8972 "is declared at %q",
8973 uentry_getName (unew),
8974 uentry_getName (old),
8975 fileloc_unparse (uentry_whereDefined (old))),
8976 uentry_whereDeclared (old));
8980 uentry_updateInto (old, unew);
8985 KindConformanceError (old, unew, mustConform);
8989 if (uentry_isFunction (unew))
8991 if (uentry_isVariable (old))
8993 if (!ctype_isUnknown (old->utype))
8995 if (ctype_isFunction (old->utype))
8997 uentry_makeVarFunction (old);
8998 checkFunctionConformance (old, unew, mustConform,
9000 fcnConformance = TRUE;
9004 KindConformanceError (old, unew, mustConform);
9009 if (uentry_isExpandedMacro (old))
9011 if (fileloc_isUndefined (unew->whereDefined))
9013 unew->whereDefined = fileloc_update (unew->whereDefined,
9017 uentry_updateInto (old, unew);
9018 old->used = unew->used = TRUE;
9023 /* undeclared identifier */
9024 old->utype = unew->utype;
9025 uentry_makeVarFunction (old);
9026 checkFunctionConformance (old, unew, FALSE, FALSE);
9027 fcnConformance = TRUE;
9033 KindConformanceError (old, unew, mustConform);
9036 else if (uentry_isFunction (old) && uentry_isVariable (unew))
9038 if (!ctype_isUnknown (unew->utype))
9040 if (ctype_isFunction (unew->utype))
9042 uentry_makeVarFunction (unew);
9043 checkFunctionConformance (old, unew, mustConform, completeConform);
9044 fcnConformance = TRUE;
9048 KindConformanceError (old, unew, mustConform);
9053 KindConformanceError (old, unew, mustConform);
9058 KindConformanceError (old, unew, mustConform);
9064 ** check parameter lists for functions
9065 ** (before type errors, to get better messages
9068 if (uentry_isFunction (old))
9070 checkFunctionConformance (old, unew, mustConform, completeConform);
9071 fcnConformance = TRUE;
9075 if (!ctype_isUndefined (old->utype))
9077 typeError = checkTypeConformance (old, unew, mustConform);
9084 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
9086 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
9089 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
9091 DPRINTF (("Check datatype: %s / %s",
9092 uentry_unparseFull (old),
9093 uentry_unparseFull (unew)));
9095 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
9098 if (uentry_isVariable (old) && uentry_isVariable (unew))
9101 !ctype_matchDef (old->utype, unew->utype))
9106 ("Variable %q %s with inconsistent type (arrays and pointers are "
9107 "not identical in variable declarations): %t",
9108 uentry_getName (unew),
9109 uentry_reDefDecl (old, unew),
9111 uentry_whereDeclared (unew)))
9113 uentry_showWhereLast (old);
9116 ** Avoid repeated errors.
9119 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
9121 old->whereDefined = fileloc_update (old->whereDefined,
9129 checkVarConformance (old, unew, mustConform, completeConform);
9134 /* old->utype = unew->utype; */
9138 if (ctype_isConj (old->utype))
9140 if (ctype_isConj (unew->utype))
9142 if (!ctype_sameAltTypes (old->utype, unew->utype))
9146 message ("%s %q inconsistently %rdeclared with "
9147 "alternate types %s "
9148 "(types match, but alternates are not identical, "
9149 "so checking may not be correct)",
9150 ekind_capName (uentry_getKind (old)),
9151 uentry_getName (unew),
9152 uentry_isDeclared (old),
9153 ctype_unparse (unew->utype)),
9154 uentry_whereDeclared (unew)))
9156 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
9160 old->utype = unew->utype;
9167 if (ctype_isUnknown (old->utype))
9169 old->utype = unew->utype;
9174 if (unew->ukind == old->ukind)
9177 unew->info = uinfo_copy (old->info, old->ukind);
9180 sRef_storeState (old->sref);
9181 sRef_storeState (unew->sref);
9184 static void uentry_mergeConstraints (uentry spec, uentry def)
9186 if (uentry_isFunction (def))
9188 DPRINTF (("Here: %s / %s",
9189 uentry_unparseFull (spec),
9190 uentry_unparseFull (def)));
9191 /* evans 2001-07-21 */
9192 llassert (uentry_isFunction (spec));
9194 if (functionConstraint_isDefined (def->info->fcn->preconditions))
9196 if (fileloc_isXHFile (uentry_whereLast (def)))
9198 llassert (uentry_isFunction (spec));
9199 spec->info->fcn->preconditions = functionConstraint_conjoin (spec->info->fcn->preconditions,
9200 def->info->fcn->preconditions);
9202 else if (fileloc_equal (uentry_whereLast (spec), uentry_whereLast (def)))
9208 /* Check if the constraints are identical */
9213 ("Preconditions for %q redeclared. Dropping previous precondition: %q",
9214 uentry_getName (spec),
9215 functionConstraint_unparse (spec->info->fcn->preconditions)),
9216 uentry_whereLast (def)))
9218 uentry_showWhereSpecified (spec);
9221 functionConstraint_free (spec->info->fcn->preconditions);
9222 spec->info->fcn->preconditions = def->info->fcn->preconditions;
9225 def->info->fcn->preconditions = functionConstraint_undefined;
9228 if (functionConstraint_isDefined (def->info->fcn->postconditions))
9230 if (fileloc_isXHFile (uentry_whereLast (def)))
9232 llassert (uentry_isFunction (spec));
9233 DPRINTF (("Post: %s /++/ %s",
9234 functionConstraint_unparse (spec->info->fcn->postconditions),
9235 functionConstraint_unparse (def->info->fcn->postconditions)));
9236 spec->info->fcn->postconditions = functionConstraint_conjoin (spec->info->fcn->postconditions,
9237 def->info->fcn->postconditions);
9238 def->info->fcn->postconditions = functionConstraint_undefined;
9239 DPRINTF (("Conjoined post: %s", functionConstraint_unparse (spec->info->fcn->postconditions)));
9246 ("Postconditions for %q redeclared. Dropping previous postcondition: %q",
9247 uentry_getName (spec),
9248 functionConstraint_unparse (spec->info->fcn->postconditions)),
9249 uentry_whereLast (def)))
9251 uentry_showWhereSpecified (spec);
9254 functionConstraint_free (spec->info->fcn->postconditions);
9255 spec->info->fcn->postconditions = def->info->fcn->postconditions;
9256 def->info->fcn->postconditions = functionConstraint_undefined;
9263 ** modifies spec to reflect def, reports any inconsistencies
9267 uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
9269 llassert (uentry_isValid (spec));
9270 llassert (uentry_isValid (def));
9271 llassert (cstring_equal (spec->uname, def->uname));
9273 if (uentry_isFunction (def))
9275 if (uentry_isConstant (spec))
9277 llassert (ctype_isUnknown (spec->utype) || ctype_isFunction (spec->utype));
9278 uentry_makeConstantFunction (spec);
9282 uentry_convertVarFunction (spec);
9285 llassert (uentry_isFunction (spec));
9288 DPRINTF (("Merge entries: %s / %s",
9289 uentry_unparseFull (spec),
9290 uentry_unparseFull (def)));
9292 uentry_mergeConstraints (spec, def);
9294 uentry_checkConformance (spec, def, TRUE,
9295 context_getFlag (FLG_NEEDSPEC));
9297 DPRINTF (("Merge entries after conform: %s / %s",
9298 uentry_unparseFull (spec),
9299 uentry_unparseFull (def)));
9301 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
9304 ** okay, declarations conform. Propagate extra information.
9307 uentry_setDefined (spec, uentry_whereDefined (def));
9308 uentry_setDeclared (spec, uentry_whereDeclared (def));
9310 if (uentry_isStatic (def))
9314 message ("%s %q specified, but declared as static",
9315 ekind_capName (def->ukind),
9316 uentry_getName (def)),
9317 uentry_whereDeclared (def)))
9319 uentry_showWhereSpecified (spec);
9324 spec->storageclass = def->storageclass;
9327 sRef_storeState (spec->sref);
9329 spec->used = def->used || spec->used;
9330 spec->hasNameError |= def->hasNameError;
9334 if (!spec->hasNameError)
9336 uentry_checkName (spec);
9345 ** Can't generate function redeclaration errors when the
9346 ** entries are merged, since we don't yet know if its the
9347 ** definition of the function.
9351 uentry_clearDecl (void)
9353 posRedeclared = uentry_undefined;
9354 fileloc_free (posLoc);
9355 posLoc = fileloc_undefined;
9359 uentry_checkDecl (void)
9361 if (uentry_isValid (posRedeclared) && !fileloc_isXHFile (posLoc))
9363 llassert (fileloc_isDefined (posLoc));
9365 if (uentry_isCodeDefined (posRedeclared))
9367 if (optgenerror (FLG_REDECL,
9368 message ("%s %q declared after definition",
9369 ekind_capName (posRedeclared->ukind),
9370 uentry_getName (posRedeclared)),
9373 llgenindentmsg (message ("Definition of %q",
9374 uentry_getName (posRedeclared)),
9375 posRedeclared->whereDeclared);
9380 if (optgenerror (FLG_REDECL,
9381 message ("%s %q declared more than once",
9382 ekind_capName (posRedeclared->ukind),
9383 uentry_getName (posRedeclared)),
9386 llgenindentmsg (message ("Previous declaration of %q",
9387 uentry_getName (posRedeclared)),
9388 posRedeclared->whereDeclared);
9393 fileloc_free (posLoc);
9394 posLoc = fileloc_undefined;
9395 posRedeclared = uentry_undefined;
9399 ** Redefinition of old as unew.
9400 ** modifies old to reflect unew, reports any inconsistencies
9404 uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
9406 fileloc olddef = uentry_whereDeclared (old);
9407 fileloc unewdef = uentry_whereDeclared (unew);
9411 DPRINTF (("uentry merge: %s / %s",
9412 uentry_unparseFull (old),
9413 uentry_unparseFull (unew)));
9416 fileloc_isUndefined (olddef)
9417 && fileloc_isDefined (uentry_whereDefined (old))
9418 && !uentry_isExpandedMacro (old);
9420 if (!context_getFlag (FLG_INCONDEFSLIB)
9421 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9423 mustConform = FALSE;
9430 llassert (uentry_isValid (old));
9431 llassert (uentry_isValid (unew));
9432 llassert (cstring_equal (old->uname, unew->uname));
9434 if (uentry_isFunction (unew) && !uentry_isFunction (old))
9436 if (uentry_isConstant (old))
9438 llassert (ctype_isUnknown (old->utype) || ctype_isFunction (old->utype));
9439 uentry_makeConstantFunction (old);
9443 uentry_convertVarFunction (old);
9446 llassert (uentry_isFunction (old));
9449 DPRINTF (("uentry merge: %s / %s",
9450 uentry_unparseFull (old),
9451 uentry_unparseFull (unew)));
9453 if (uentry_isExtern (unew))
9455 uentry_setUsed (old, unewdef);
9459 ** should check old one was extern!
9462 if (uentry_isStatic (old))
9464 if (!(uentry_isStatic (unew)))
9468 message ("%s %q shadows static declaration",
9469 ekind_capName (unew->ukind),
9470 uentry_getName (unew)),
9473 uentry_showWhereLast (old);
9478 uentry_setDeclDef (old, unewdef);
9481 else if (uentry_isStatic (unew))
9483 uentry_setDeclDef (old, unewdef);
9485 else if (uentry_isExtern (old))
9487 uentry_setDeclared (old, unewdef);
9491 if (!uentry_isExtern (unew)
9492 && !uentry_isForward (old)
9493 && !fileloc_equal (olddef, unewdef)
9494 && !fileloc_isUndefined (olddef)
9495 && !fileloc_isUndefined (unewdef)
9496 && !fileloc_isBuiltin (olddef)
9497 && !fileloc_isBuiltin (unewdef)
9498 && !uentry_isYield (old)
9499 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9501 if (uentry_isVariable (old) || uentry_isVariable (unew))
9503 ; /* will report redeclaration error later */
9507 if (fileloc_isDefined (uentry_whereDefined (old)))
9511 message ("%s %q defined more than once",
9512 ekind_capName (unew->ukind),
9513 uentry_getName (unew)),
9514 uentry_whereLast (unew)))
9517 (message ("Previous definition of %q",
9518 uentry_getName (old)),
9519 uentry_whereLast (old));
9522 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
9524 uentry_updateInto (old, unew);
9525 old->sref = sRef_saveCopy (old->sref);
9533 if (fileloc_isLib (olddef)
9534 || fileloc_isUndefined (olddef)
9535 || fileloc_isImport (olddef))
9537 if (uentry_isExtern (unew))
9539 if (uentry_isExtern (old)
9540 || (fileloc_isDefined (uentry_whereDeclared (old))
9541 && (!fileloc_equal (uentry_whereDeclared (old),
9542 uentry_whereDefined (old)))))
9546 message ("%s %q declared more than once",
9547 ekind_capName (unew->ukind),
9548 uentry_getName (unew)),
9549 unew->whereDeclared))
9552 (message ("Previous declaration of %q",
9553 uentry_getName (old)),
9554 old->whereDeclared);
9558 uentry_setExtern (old);
9562 uentry_setDeclared (old, unewdef); /* evans 2001-07-23 was setDefined */
9568 DPRINTF (("uentry merge: %s / %s",
9569 uentry_unparseFull (old),
9570 uentry_unparseFull (unew)));
9572 uentry_mergeConstraints (old, unew);
9573 DPRINTF (("uentry merge: %s / %s",
9574 uentry_unparseFull (old),
9575 uentry_unparseFull (unew)));
9577 uentry_checkConformance (old, unew, mustConform, FALSE);
9578 DPRINTF (("uentry merge: %s / %s",
9579 uentry_unparseFull (old),
9580 uentry_unparseFull (unew)));
9582 old->used = old->used || unew->used;
9583 old->uses = filelocList_append (old->uses, unew->uses);
9584 unew->uses = filelocList_undefined;
9586 sRef_storeState (old->sref);
9587 sRef_storeState (unew->sref);
9591 old->whereDefined = fileloc_update (old->whereDefined,
9595 DPRINTF (("here: %s", uentry_unparseFull (old)));
9598 ** No redeclaration errors for functions here, since we
9599 ** don't know if this is the definition of the function.
9602 if (fileloc_isUser (old->whereDeclared)
9603 && fileloc_isUser (unew->whereDeclared)
9604 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
9605 && !fileloc_isDefined (unew->whereDefined))
9607 if (uentry_isFunction (old))
9609 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
9610 posLoc = fileloc_update (posLoc, unew->whereDeclared);
9614 if (optgenerror (FLG_REDECL,
9615 message ("%s %q declared more than once",
9616 ekind_capName (unew->ukind),
9617 uentry_getName (unew)),
9618 unew->whereDeclared))
9620 llgenindentmsg (message ("Previous declaration of %q",
9621 uentry_getName (old)),
9622 old->whereDeclared);
9627 if (fileloc_isUndefined (old->whereDefined))
9629 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
9633 if (!context_processingMacros ()
9634 && fileloc_isUser (old->whereDefined)
9635 && fileloc_isUser (unew->whereDefined)
9636 && !fileloc_equal (old->whereDefined, unew->whereDefined))
9638 if (uentry_isVariable (unew) || uentry_isFunction (unew))
9640 if (uentry_isVariable (unew)
9641 && uentry_isExtern (unew))
9643 if (optgenerror (FLG_REDECL,
9644 message ("%s %q declared after definition",
9645 ekind_capName (unew->ukind),
9646 uentry_getName (unew)),
9647 unew->whereDeclared))
9649 llgenindentmsg (message ("Definition of %q",
9650 uentry_getName (old)),
9656 if (optgenerror (FLG_REDEF,
9657 message ("%s %q redefined",
9658 ekind_capName (unew->ukind),
9659 uentry_getName (unew)),
9660 unew->whereDefined))
9662 llgenindentmsg (message ("Previous definition of %q",
9663 uentry_getName (old)),
9671 if (uentry_isExternal (unew))
9673 old->whereDefined = fileloc_createExternal ();
9676 if (unew->hasNameError)
9678 old->hasNameError = TRUE;
9683 if (!old->hasNameError)
9685 uentry_checkName (old);
9688 DPRINTF (("After: %s", uentry_unparseFull (old)));
9689 llassert (!ctype_isUndefined (old->utype));
9693 uentry_copyState (uentry res, uentry other)
9695 llassert (uentry_isValid (res));
9696 llassert (uentry_isValid (other));
9698 res->used = other->used;
9700 res->info->var->kind = other->info->var->kind;
9701 res->info->var->defstate = other->info->var->defstate;
9702 res->info->var->nullstate = other->info->var->nullstate;
9703 res->info->var->checked = other->info->var->checked;
9705 sRef_copyState (res->sref, other->sref);
9709 uentry_sameKind (uentry u1, uentry u2)
9711 if (uentry_isValid (u1) && uentry_isValid (u2))
9713 if (uentry_isVar (u1) && uentry_isVar (u2))
9715 ctype c1 = u1->utype;
9716 ctype c2 = u2->utype;
9718 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
9721 ** both functions, or both not functions
9724 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
9728 return ((u1->ukind == u2->ukind));
9735 static void uentry_updateInto (/*@unique@*/ uentry unew, uentry old)
9737 ekind okind = unew->ukind;
9738 llassert (uentry_isValid (unew));
9739 llassert (uentry_isValid (old));
9741 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9743 unew->ukind = old->ukind;
9744 llassert (cstring_equal (unew->uname, old->uname));
9745 unew->utype = old->utype;
9747 if (fileloc_isDefined (unew->whereSpecified)
9748 && !fileloc_isDefined (old->whereSpecified))
9750 ; /* Keep the old value */
9754 fileloc_free (unew->whereSpecified); /*@i523 why no error without this? */
9755 unew->whereSpecified = fileloc_copy (old->whereSpecified);
9758 if (fileloc_isDefined (unew->whereDefined)
9759 && !fileloc_isDefined (old->whereDefined))
9761 ; /* Keep the old value */
9765 fileloc_free (unew->whereDefined); /*@i523 why no error without this? */
9766 unew->whereDefined = fileloc_copy (old->whereDefined);
9769 if (fileloc_isDefined (unew->whereDeclared)
9770 && !fileloc_isDefined (old->whereDeclared))
9772 ; /* Keep the old value */
9776 fileloc_free (unew->whereDeclared); /*@i523 why no error without this? */
9777 unew->whereDeclared = fileloc_copy (old->whereDeclared);
9780 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9782 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
9783 unew->used = old->used;
9785 unew->isPrivate = old->isPrivate;
9786 unew->hasNameError = old->hasNameError;
9787 unew->uses = filelocList_append (unew->uses, old->uses);
9788 old->uses = filelocList_undefined;
9790 unew->storageclass = old->storageclass;
9791 uinfo_free (unew->info, okind);
9792 unew->info = uinfo_copy (old->info, old->ukind);
9797 uentry_copy (uentry e)
9799 if (uentry_isValid (e))
9801 uentry enew = uentry_alloc ();
9802 DPRINTF (("copy: %s", uentry_unparseFull (e)));
9803 enew->ukind = e->ukind;
9804 enew->uname = cstring_copy (e->uname);
9805 enew->utype = e->utype;
9807 enew->whereSpecified = fileloc_copy (e->whereSpecified);
9808 enew->whereDefined = fileloc_copy (e->whereDefined);
9809 enew->whereDeclared = fileloc_copy (e->whereDeclared);
9811 enew->sref = sRef_saveCopy (e->sref); /* Memory leak! */
9812 enew->used = e->used;
9814 enew->isPrivate = e->isPrivate;
9815 enew->hasNameError = e->hasNameError;
9816 enew->uses = filelocList_undefined;
9818 enew->storageclass = e->storageclass;
9819 enew->info = uinfo_copy (e->info, e->ukind);
9820 enew->warn = warnClause_copy (e->warn);
9822 DPRINTF (("Here we are..."));
9823 DPRINTF (("original: %s", uentry_unparseFull (e)));
9824 DPRINTF (("copy: %s", uentry_unparse (enew)));
9825 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
9830 return uentry_undefined;
9835 uentry_setState (uentry res, uentry other)
9837 llassert (uentry_isValid (res));
9838 llassert (uentry_isValid (other));
9840 llassert (res->ukind == other->ukind);
9841 llassert (res->ukind == KVAR);
9843 res->sref = sRef_saveCopy (other->sref);
9844 res->used = other->used;
9845 filelocList_free (res->uses);
9846 res->uses = other->uses;
9847 other->uses = filelocList_undefined;
9848 res->lset = other->lset;
9852 uentry_mergeUses (uentry res, uentry other)
9854 llassert (uentry_isValid (res));
9855 llassert (uentry_isValid (other));
9857 res->used = other->used || res->used;
9858 res->lset = other->lset || res->lset;
9859 res->uses = filelocList_append (res->uses, other->uses);
9860 other->uses = filelocList_undefined;
9865 ** This is a really ugly routine.
9867 ** gack...fix this one day.
9872 ** >> res is the false branch, other is the true branch (or continuation)
9874 ** >> res is the true branch, other is the false branch (or continutation)
9881 ** References not effected by res are propagated from other.
9885 branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
9886 bool flip, clause cl, fileloc loc)
9890 message ("%s %q is %s %s, but %s %s.",
9891 ekind_capName (res->ukind), uentry_getName (res),
9892 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
9893 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
9896 if (sRef_isDead (res->sref))
9898 sRef_showStateInfo (res->sref);
9900 else if (sRef_isKept (res->sref))
9902 sRef_showAliasInfo (res->sref);
9904 else /* dependent */
9906 sRef_showAliasInfo (res->sref);
9907 sRef_showAliasInfo (other->sref);
9910 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
9914 static bool incompatibleStates (sRef rs, sRef os)
9916 alkind rk = sRef_getAliasKind (rs);
9917 alkind ok = sRef_getAliasKind (os);
9919 if (alkind_isError (rk) || alkind_isError (ok))
9925 return ((sRef_isDead (rs)
9926 || (alkind_isKept (rk) && !alkind_isKept (ok))
9927 || (alkind_isDependent (rk)
9928 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
9929 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
9934 branchStateAltError (/*@notnull@*/ uentry res,
9935 /*@notnull@*/ uentry other, bool flip,
9936 clause cl, fileloc loc)
9940 message ("%s %q is %s %s, but %s %s.",
9941 ekind_capName (res->ukind), uentry_getName (res),
9942 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
9943 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
9946 if (sRef_isDead (other->sref))
9948 sRef_showStateInfo (other->sref);
9952 sRef_showAliasInfo (other->sref);
9955 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
9956 sRef_setDefinedComplete (res->sref, fileloc_undefined);
9958 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
9959 sRef_setDefinedComplete (other->sref, fileloc_undefined);
9964 ** A reference is relevant for certain checks, only if it
9965 ** is not definitely null on this path (but not declared
9966 ** to always be null.)
9969 static bool uentry_relevantReference (sRef sr, bool flip)
9971 if (sRef_isKept (sr) || sRef_isDependent (sr))
9979 return !sRef_definitelyNullContext (sr);
9983 return !sRef_definitelyNullAltContext (sr);
9989 uentry_mergeAliasStates (uentry res, uentry other, fileloc loc,
9990 bool mustReturn, bool flip, bool opt,
9993 DPRINTF (("Merge alias states: %s / %s",
9994 uentry_unparseFull (res),
9995 uentry_unparseFull (other)));
9997 if (sRef_isValid (res->sref))
10002 if (incompatibleStates (res->sref, other->sref))
10006 if (sRef_isThroughArrayFetch (res->sref)
10007 && !context_getFlag (FLG_STRICTBRANCHSTATE))
10009 if (sRef_isKept (res->sref) || sRef_isKept (other->sref))
10011 sRef_maybeKill (res->sref, loc);
10013 else if (sRef_isPossiblyDead (other->sref))
10015 sRef_maybeKill (res->sref, loc);
10024 if (uentry_relevantReference (other->sref, flip))
10027 if (sRef_isLocalParamVar (res->sref)
10028 && (sRef_isLocalState (other->sref)
10029 || sRef_isDependent (other->sref)))
10031 if (sRef_isDependent (res->sref))
10033 sRef_setDependent (other->sref, loc);
10037 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
10042 branchStateError (res, other, flip, cl, loc);
10047 if (sRef_isKept (res->sref))
10049 sRef_setKept (other->sref, loc);
10054 if (incompatibleStates (other->sref, res->sref))
10056 if (uentry_relevantReference (res->sref, !flip))
10058 if (sRef_isLocalParamVar (res->sref)
10059 && (sRef_isDependent (res->sref)
10060 || sRef_isLocalState (res->sref)))
10062 if (sRef_isDependent (other->sref))
10064 sRef_setDependent (res->sref, loc);
10068 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
10073 if (sRef_isParam (other->sref))
10076 ** If the local variable associated
10077 ** with the param has the correct state,
10079 ** (e.g., free (s); s = new(); ...
10082 uentry uvar = usymtab_lookupSafe (other->uname);
10084 if (uentry_isValid (uvar)
10085 && ((sRef_isDead (other->sref)
10086 && sRef_isOnly (uvar->sref))
10087 || (sRef_isDependent (other->sref)
10088 && sRef_isOwned (uvar->sref))))
10094 branchStateAltError (res, other,
10100 DPRINTF (("Here: %s / %s",
10101 uentry_unparseFull (res),
10102 uentry_unparseFull (other)));
10104 branchStateAltError (res, other,
10111 if (sRef_isKept (other->sref))
10113 sRef_setKept (res->sref, loc);
10119 DPRINTF (("Merge opt..."));
10120 sRef_mergeOptState (res->sref, other->sref, cl, loc);
10121 DPRINTF (("Done!"));
10125 sRef_mergeState (res->sref, other->sref, cl, loc);
10130 if (sRef_isModified (other->sref))
10132 sRef_setModified (res->sref);
10139 uentry_mergeValueStates (uentry res, uentry other, fileloc loc, bool mustReturn, /*@unused@*/ bool flip)
10141 valueTable rvalues;
10142 valueTable ovalues;
10144 DPRINTF (("Merge values: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
10152 rvalues = sRef_getValueTable (res->sref);
10153 ovalues = sRef_getValueTable (other->sref);
10155 if (valueTable_isUndefined (ovalues))
10157 DPRINTF (("No value table: %s", sRef_unparseFull (other->sref)));
10160 else if (valueTable_isUndefined (rvalues))
10163 ** Copy values from other
10167 DPRINTF (("Has value table: %s", sRef_unparseFull (other->sref)));
10168 DPRINTF (("No value table: %s", sRef_unparseFull (res->sref)));
10173 valueTable_elements (ovalues, fkey, fval) {
10175 metaStateInfo minfo;
10176 stateCombinationTable sctable;
10180 tval = valueTable_lookup (rvalues, fkey);
10182 DPRINTF (("Merge value: %s / %s X %s", fkey,
10183 stateValue_unparse (fval), stateValue_unparse (tval)));
10185 minfo = context_lookupMetaStateInfo (fkey);
10186 llassert (stateValue_isDefined (tval));
10188 if (metaStateInfo_isUndefined (minfo) || !stateValue_isDefined (tval))
10190 DPRINTF (("Cannot find meta state for: %s", fkey));
10195 llassert (metaStateInfo_isDefined (minfo));
10197 if (stateValue_isError (fval)
10198 || sRef_definitelyNullContext (res->sref))
10200 sRef_setMetaStateValueComplete (res->sref,
10201 fkey, stateValue_getValue (fval),
10202 stateValue_getLoc (fval));
10203 DPRINTF (("Setting res: %s", sRef_unparseFull (res->sref)));
10205 else if (stateValue_isError (tval)
10206 || sRef_definitelyNullAltContext (other->sref))
10208 DPRINTF (("Other branch is definitely null!"));
10210 else if (sRef_isStateUndefined (res->sref)
10211 || sRef_isDead (res->sref))
10213 ; /* Combination state doesn't matter if it is undefined or dead */
10217 DPRINTF (("Check: %s / %s / %s / %s", fkey,
10218 metaStateInfo_unparse (minfo),
10219 stateValue_unparse (fval),
10220 stateValue_unparse (tval)));
10222 DPRINTF (("state values: %d / %d",
10223 stateValue_getValue (fval), stateValue_getValue (tval)));
10225 sctable = metaStateInfo_getMergeTable (minfo);
10227 DPRINTF (("Merge table: %s",
10228 stateCombinationTable_unparse (sctable)));
10230 msg = cstring_undefined;
10232 nval = stateCombinationTable_lookup (sctable,
10233 stateValue_getValue (fval),
10234 stateValue_getValue (tval),
10237 DPRINTF (("nval: %d / %d / %d", nval,
10238 stateValue_getValue (fval), stateValue_getValue (tval)));
10240 if (nval == stateValue_error)
10242 /*@i32 print extra info for assignments@*/
10244 if (uentry_isGlobalMarker (res))
10249 ("Control branches merge with incompatible global states (%s and %s)%q",
10250 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10251 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10252 cstring_isDefined (msg)
10253 ? message (": %s", msg) : cstring_undefined),
10256 sRef_showMetaStateInfo (res->sref, fkey);
10257 sRef_showMetaStateInfo (other->sref, fkey);
10265 ("Control branches merge with incompatible states for %q (%s and %s)%q",
10266 uentry_getName (res),
10267 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10268 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10269 cstring_isDefined (msg)
10270 ? message (": %s", msg) : cstring_undefined),
10273 sRef_showMetaStateInfo (res->sref, fkey);
10274 sRef_showMetaStateInfo (other->sref, fkey);
10275 DPRINTF (("Res: %s", sRef_unparseFull (res->sref)));
10276 DPRINTF (("Other: %s", sRef_unparseFull (other->sref)));
10277 DPRINTF (("Null: %s / %s",
10278 bool_unparse (usymtab_isDefinitelyNull (res->sref)),
10279 bool_unparse (usymtab_isDefinitelyNull (other->sref))));
10285 if (nval == stateValue_getValue (fval)
10286 && nval != stateValue_getValue (tval))
10288 loc = stateValue_getLoc (fval);
10290 else if (nval == stateValue_getValue (tval)
10291 && nval != stateValue_getValue (fval))
10293 loc = stateValue_getLoc (tval);
10300 if (stateValue_getValue (sRef_getMetaStateValue (res->sref, fkey)) == nval
10301 && nval == stateValue_getValue (fval)
10302 && nval == stateValue_getValue (tval))
10308 sRef_setMetaStateValueComplete (res->sref, fkey, nval, loc);
10312 } end_valueTable_elements ;
10318 uentry_mergeSetStates (uentry res, uentry other, /*@unused@*/ fileloc loc,
10319 bool flip, clause cl)
10321 if (cl == DOWHILECLAUSE)
10323 res->used = other->used || res->used;
10324 res->lset = other->lset || res->lset;
10325 res->uses = filelocList_append (res->uses, other->uses);
10326 other->uses = filelocList_undefined;
10330 if (sRef_isMacroParamRef (res->sref)
10331 && !uentry_isSefParam (other)
10332 && !uentry_isSefParam (res))
10334 bool hasError = FALSE;
10336 if (bool_equal (res->used, other->used))
10338 res->used = other->used;
10342 if (other->used && !flip)
10347 message ("Macro parameter %q used in true clause, "
10348 "but not in false clause",
10349 uentry_getName (res)),
10350 uentry_whereDeclared (res));
10357 message ("Macro parameter %q used in false clause, "
10358 "but not in true clause",
10359 uentry_getName (res)),
10360 uentry_whereDeclared (res));
10366 /* make it sef now, prevent more errors */
10367 res->info->var->kind = VKREFSEFPARAM;
10373 res->used = other->used || res->used;
10374 res->lset = other->lset || res->lset;
10375 res->uses = filelocList_append (res->uses, other->uses);
10376 other->uses = filelocList_undefined;
10382 uentry_mergeState (uentry res, uentry other, fileloc loc,
10383 bool mustReturn, bool flip, bool opt,
10386 llassert (uentry_isValid (res));
10387 llassert (uentry_isValid (other));
10389 llassert (res->ukind == other->ukind);
10390 llassert (res->ukind == KVAR);
10392 DPRINTF (("Merge state: %s / %s", uentry_unparseFull (res),
10393 uentry_unparseFull (other)));
10395 uentry_mergeAliasStates (res, other, loc, mustReturn, flip, opt, cl);
10396 uentry_mergeValueStates (res, other, loc, mustReturn, flip);
10397 uentry_mergeSetStates (res, other, loc, flip, cl);
10400 void uentry_setUsed (uentry e, fileloc loc)
10402 static bool firstTime = TRUE;
10403 static bool showUses = FALSE;
10404 static bool exportLocal = FALSE;
10406 DPRINTF (("Used: %s / %s", uentry_unparse (e), fileloc_unparse (loc)));
10410 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
10412 showUses = context_getFlag (FLG_SHOWUSES);
10413 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
10418 if (uentry_isValid (e))
10422 if (warnClause_isDefined (e->warn))
10424 flagSpec flg = warnClause_getFlag (e->warn);
10427 if (warnClause_hasMessage (e->warn))
10429 msg = cstring_copy (warnClause_getMessage (e->warn));
10433 msg = message ("Use of possibly dangerous %s",
10434 uentry_ekindNameLC (e));
10438 message ("%q: %q", msg, uentry_getName (e)),
10442 if (sRef_isMacroParamRef (e->sref))
10444 if (uentry_isYield (e) || uentry_isSefParam (e))
10450 if (context_inConditional ())
10454 message ("Macro parameter %q used in conditionally "
10455 "executed code (may or may not be "
10456 "evaluated exactly once)",
10457 uentry_getName (e)),
10460 e->info->var->kind = VKREFSEFPARAM;
10469 message ("Macro parameter %q used more than once",
10470 uentry_getName (e)),
10471 uentry_whereDeclared (e)))
10473 e->info->var->kind = VKREFSEFPARAM;
10480 if ((dp = uentry_directParamNo (e)) >= 0)
10482 uentry_setUsed (usymtab_getParam (dp), loc);
10487 if (!sRef_isLocalVar (e->sref))
10491 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
10497 if (context_inMacro ())
10499 e->uses = filelocList_addUndefined (e->uses);
10503 e->uses = filelocList_addDifferentFile
10505 uentry_whereDeclared (e),
10514 bool uentry_isReturned (uentry u)
10516 return (uentry_isValid (u) && uentry_isVar (u)
10517 && (u->info->var->kind == VKRETPARAM
10518 || u->info->var->kind == VKSEFRETPARAM));
10521 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args)
10523 llassert (uentry_isRealFunction (u));
10525 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
10527 stateClauseList clauses = uentry_getStateClauseList (u);
10528 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10530 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
10531 sRef_setAllocated (res, g_currentloc);
10533 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10534 stateClauseList_unparse (clauses)));
10537 ** This should be in exprNode_reflectEnsuresClause
10540 stateClauseList_postElements (clauses, cl)
10542 if (!stateClause_isGlobal (cl))
10544 sRefSet refs = stateClause_getRefs (cl);
10545 sRefMod modf = stateClause_getEffectFunction (cl);
10547 sRefSet_elements (refs, el)
10549 sRef base = sRef_getRootBase (el);
10551 if (sRef_isResult (base))
10555 sRef sr = sRef_fixBase (el, res);
10556 modf (sr, g_currentloc);
10563 } end_sRefSet_elements ;
10565 } end_stateClauseList_postElements ;
10573 sRefSet prefs = sRefSet_new ();
10574 sRef res = sRef_undefined;
10577 params = uentry_getParams (u);
10579 uentryList_elements (params, current)
10581 if (uentry_isReturned (current))
10583 if (exprNodeList_size (args) >= paramno)
10585 exprNode ecur = exprNodeList_nth (args, paramno);
10586 sRef tref = exprNode_getSref (ecur);
10588 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10590 if (sRef_isValid (tref))
10592 sRef tcref = sRef_copy (tref);
10594 usymtab_addForceMustAlias (tcref, tref); /* evans 2001-05-27 */
10596 if (sRef_isDead (tcref))
10598 sRef_setDefined (tcref, g_currentloc);
10599 sRef_setOnly (tcref, g_currentloc);
10602 if (sRef_isRefCounted (tcref))
10604 /* could be a new ref now (but only if its returned) */
10605 sRef_setAliasKindComplete (tcref, AK_ERROR, g_currentloc);
10608 sRef_makeSafe (tcref);
10609 prefs = sRefSet_insert (prefs, tcref);
10615 } end_uentryList_elements ;
10617 if (sRefSet_size (prefs) > 0)
10619 nstate n = sRef_getNullState (u->sref);
10621 if (sRefSet_size (prefs) == 1)
10623 res = sRefSet_choose (prefs);
10627 /* should this ever happen? */ /*@i534 evans 2001-05-27 */
10628 res = sRefSet_mergeIntoOne (prefs);
10631 if (nstate_isKnown (n))
10633 sRef_setNullState (res, n, g_currentloc);
10638 if (ctype_isFunction (u->utype))
10640 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10641 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10645 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
10648 if (sRef_isRefCounted (res))
10650 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10655 if (sRef_getNullState (res) == NS_ABSNULL)
10657 ctype ct = ctype_realType (u->utype);
10659 if (ctype_isAbstract (ct))
10661 sRef_setNotNull (res, g_currentloc);
10665 if (ctype_isUser (ct))
10667 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
10671 sRef_setNotNull (res, g_currentloc);
10676 if (sRef_isRefCounted (res))
10678 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10680 else if (sRef_isKillRef (res))
10682 sRef_setAliasKind (res, AK_REFCOUNTED, g_currentloc);
10689 ak = sRef_getAliasKind (res);
10691 if (alkind_isImplicit (ak))
10693 sRef_setAliasKind (res,
10694 alkind_fixImplicit (ak),
10698 sRefSet_free (prefs);
10700 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
10705 static bool uentry_isRefCounted (uentry ue)
10707 ctype ct = uentry_getType (ue);
10709 if (ctype_isFunction (ct))
10711 return (ctype_isRefCounted (ctype_getReturnType (ct)));
10715 return (ctype_isRefCounted (ct));
10720 ** old was declared yield in the specification.
10721 ** new is declared in the iter implementation.
10724 void uentry_checkYieldParam (uentry old, uentry unew)
10728 llassert (uentry_isVariable (old));
10729 llassert (uentry_isVariable (unew));
10731 unew->info->var->kind = VKYIELDPARAM;
10732 (void) checkTypeConformance (old, unew, TRUE);
10733 checkVarConformance (old, unew, TRUE, FALSE);
10735 /* get rid of param marker */
10737 name = uentry_getName (unew);
10738 cstring_free (unew->uname);
10739 unew->uname = name;
10740 unew->info->var->kind = VKREFYIELDPARAM;
10742 uentry_setUsed (old, fileloc_undefined);
10743 uentry_setUsed (unew, fileloc_undefined);
10746 /*@observer@*/ cstring
10747 uentry_ekindName (uentry ue)
10749 if (uentry_isValid (ue))
10754 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
10756 return cstring_makeLiteralTemp ("Datatype");
10758 return cstring_makeLiteralTemp ("Enum member");
10760 return cstring_makeLiteralTemp ("Constant");
10762 if (uentry_isParam (ue))
10764 return cstring_makeLiteralTemp ("Parameter");
10766 else if (uentry_isExpandedMacro (ue))
10768 return cstring_makeLiteralTemp ("Expanded macro");
10772 return cstring_makeLiteralTemp ("Variable");
10775 return cstring_makeLiteralTemp ("Function");
10777 return cstring_makeLiteralTemp ("Iterator");
10779 return cstring_makeLiteralTemp ("Iterator finalizer");
10781 return cstring_makeLiteralTemp ("Struct tag");
10783 return cstring_makeLiteralTemp ("Union tag");
10785 return cstring_makeLiteralTemp ("Enum tag");
10787 return cstring_makeLiteralTemp ("Optional parameters");
10792 return cstring_makeLiteralTemp ("<Undefined>");
10798 /*@observer@*/ cstring
10799 uentry_ekindNameLC (uentry ue)
10801 if (uentry_isValid (ue))
10806 return cstring_makeLiteralTemp ("<error: invalid uentry>");
10808 return cstring_makeLiteralTemp ("datatype");
10810 return cstring_makeLiteralTemp ("enum member");
10812 return cstring_makeLiteralTemp ("constant");
10814 if (uentry_isParam (ue))
10816 return cstring_makeLiteralTemp ("parameter");
10818 else if (uentry_isExpandedMacro (ue))
10820 return cstring_makeLiteralTemp ("expanded macro");
10824 return cstring_makeLiteralTemp ("variable");
10827 return cstring_makeLiteralTemp ("function");
10829 return cstring_makeLiteralTemp ("iterator");
10831 return cstring_makeLiteralTemp ("iterator finalizer");
10833 return cstring_makeLiteralTemp ("struct tag");
10835 return cstring_makeLiteralTemp ("union tag");
10837 return cstring_makeLiteralTemp ("enum tag");
10839 return cstring_makeLiteralTemp ("optional parameters");
10844 return cstring_makeLiteralTemp ("<Undefined>");
10850 void uentry_setHasNameError (uentry ue)
10852 llassert (uentry_isValid (ue));
10854 ue->hasNameError = TRUE;
10857 void uentry_checkName (uentry ue)
10859 DPRINTF (("Checking name: %s / %s / %s", uentry_unparse (ue),
10860 uentry_observeRealName (ue),
10861 bool_unparse (uentry_isVisibleExternally (ue))));
10863 if (uentry_isValid (ue)
10864 && !context_inXHFile ()
10865 && uentry_hasName (ue)
10866 && !uentry_isElipsisMarker (ue)
10867 && context_getFlag (FLG_NAMECHECKS)
10868 && !ue->hasNameError
10869 && !uentry_isEndIter (ue)
10870 && !fileloc_isBuiltin (uentry_whereLast (ue))
10871 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
10873 DPRINTF (("Here..."));
10875 if (uentry_isPriv (ue))
10877 ; /* any checks here? */
10879 else if (fileloc_isExternal (uentry_whereDefined (ue)))
10881 ; /* no errors for externals */
10887 if (uentry_isExpandedMacro (ue))
10893 if (uentry_isExpandedMacro (ue))
10897 else if (uentry_isVariable (ue))
10899 sRef sr = uentry_getSref (ue);
10901 if (sRef_isValid (sr))
10903 scope = sRef_getScope (sr);
10910 else if (uentry_isFunction (ue)
10911 || uentry_isIter (ue)
10912 || uentry_isEndIter (ue)
10913 || uentry_isConstant (ue))
10915 scope = uentry_isStatic (ue) ? fileScope : globScope;
10917 else /* datatypes, etc. must be global */
10922 usymtab_checkDistinctName (ue, scope);
10925 if (context_getFlag (FLG_CPPNAMES))
10930 if (scope == globScope)
10932 checkExternalName (ue);
10934 else if (scope == fileScope)
10936 checkFileScopeName (ue);
10940 checkLocalName (ue);
10944 checkAnsiName (ue);
10949 /*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@only@*/ fileloc loc)
10955 ** Can't but unrecognized ids in macros in global scope, because srefs will break!
10958 if (!context_inMacro ())
10960 sRef_setGlobalScopeSafe ();
10963 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
10964 uentry_setUsed (ue, loc);
10966 tloc = fileloc_createExternal ();
10967 uentry_setDefined (ue, tloc);
10968 fileloc_free (tloc);
10969 uentry_setHasNameError (ue);
10971 if (context_getFlag (FLG_REPEATUNRECOG))
10973 uentry_markOwned (ue);
10977 ue = usymtab_supReturnFileEntry (ue);
10980 if (!context_inMacro ())
10982 sRef_clearGlobalScopeSafe ();
10988 uentry uentry_makeGlobalMarker ()
10993 llassert (sRef_inGlobalScope ());
10995 ue = uentry_makeVariableAux
10996 (GLOBAL_MARKER_NAME, ctype_unknown, fileloc_undefined,
10997 sRef_makeGlobalMarker (),
11000 tloc = fileloc_createExternal ();
11001 uentry_setUsed (ue, tloc);
11002 uentry_setDefined (ue, tloc);
11003 fileloc_free (tloc);
11004 uentry_setHasNameError (ue);
11010 bool uentry_isGlobalMarker (uentry ue)
11012 return (uentry_isValid (ue)
11013 && (cstring_equal (uentry_rawName (ue), GLOBAL_MARKER_NAME)));
11016 /* new start modifications */
11018 /* start modifications */
11020 requires: p_e is defined, is a ptr/array variable
11022 effects: sets the state of the variable
11026 void uentry_setPossiblyNullTerminatedState (uentry p_e) {
11027 /*@access sRef@*/ /*i523 shouldn't do this! */
11028 if( uentry_isValid(p_e) ) {
11029 if( p_e->info != NULL) {
11030 if( p_e->info->var != NULL) {
11031 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
11032 p_e->sref->bufinfo.bufstate = BB_POSSIBLYNULLTERMINATED;
11037 /*@noaccess sRef@*/
11039 fprintf(stderr, "uentry:Error in setPossiblyNullTerminatedState\n");
11043 requires: p_e is defined, is a ptr/array variable
11045 effects: sets the size of the buffer
11048 void uentry_setNullTerminatedState (uentry p_e) {
11049 if( uentry_isValid(p_e) ) {
11050 if( p_e->info != NULL) {
11051 if( p_e->info->var != NULL) {
11052 p_e->info->var->bufinfo->bufstate = BB_NULLTERMINATED;
11053 /*@access sRef@*/ /*@i523 bad!*/
11054 p_e->sref->bufinfo.bufstate = BB_NULLTERMINATED;
11055 /*@noaccess sRef@*/
11061 fprintf(stderr, "uentry:Error in setNullTerminatedState\n");
11065 requires: p_e is defined, is a ptr/array variable
11067 effects: sets the size of the buffer
11070 void uentry_setSize (uentry p_e, int size) {
11071 if( uentry_isValid(p_e) ) {
11072 if( p_e->info != NULL) {
11073 if( p_e->info->var != NULL) {
11074 p_e->info->var->bufinfo->size = size;
11075 /*@access sRef@*/ /*@i523 bad!*/
11076 p_e->sref->bufinfo.size = size;
11077 /*@noaccess sRef@*/
11083 fprintf(stderr, "uentry:Error in setSize\n");
11088 requires: p_e is defined, is a ptr/array variable
11090 effects: sets the length of the buffer
11093 void uentry_setLen (uentry p_e, int len) {
11094 if( uentry_isValid(p_e) ) {
11095 if( p_e->info != NULL) {
11096 if( p_e->info->var != NULL) {
11097 p_e->info->var->bufinfo->len = len;
11098 /*@access sRef@*/ /*@i523 bad!*/
11099 p_e->sref->bufinfo.len = len;
11100 /*@noaccess sRef@*/
11106 fprintf(stderr, "uentry:Error in setLen\n");
11111 bool uentry_hasMetaStateEnsures (uentry e)
11113 if (uentry_isValid (e) && uentry_isFunction (e))
11115 return functionConstraint_hasMetaStateConstraint (e->info->fcn->postconditions);
11123 metaStateConstraintList uentry_getMetaStateEnsures (uentry e)
11125 llassert (uentry_isValid (e) && uentry_isFunction (e));
11126 return functionConstraint_getMetaStateConstraints (e->info->fcn->postconditions);