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 if (globSet_hasStatic (globs))
3580 context_recordFileGlobals (globs);
3584 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3586 ue->info->fcn->hasMods = TRUE;
3590 void uentry_addAccessType (uentry ue, typeId tid)
3592 if (uentry_isFunction (ue))
3594 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3596 else if (uentry_isEitherConstant (ue))
3598 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3600 else if (uentry_isIter (ue))
3602 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3604 else if (uentry_isEndIter (ue))
3606 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3610 llbug (message ("no access for: %q", uentry_unparse (ue)));
3614 /*@only@*/ /*@notnull@*/ uentry
3615 uentry_makeFunction (cstring n, ctype t,
3617 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
3618 /*@only@*/ warnClause warn,
3621 llassert (warnClause_isUndefined (warn)); /*@i325 remove parameter! */
3622 return (uentry_makeFunctionAux (n, t,
3623 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3624 : typeIdSet_single (access)),
3631 /*@notnull@*/ uentry
3632 uentry_makePrivFunction2 (cstring n, ctype t,
3634 globSet globs, sRefSet mods,
3637 return (uentry_makeFunctionAux (n, t, access, globs, mods, warnClause_undefined,
3642 /*@notnull@*/ uentry
3643 uentry_makeSpecFunction (cstring n, ctype t,
3645 /*@only@*/ globSet globs,
3646 /*@only@*/ sRefSet mods,
3649 uentry ue = uentry_makeFunctionAux (n, t, access,
3650 globs, mods, warnClause_undefined,
3653 uentry_setHasGlobs (ue);
3654 uentry_setHasMods (ue);
3656 reflectImplicitFunctionQualifiers (ue, TRUE);
3661 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3663 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3664 sRef_undefined, FALSE, VKEXPMACRO);
3666 uentry_setDefined (ue, f);
3670 /*@notnull@*/ /*@notnull@*/ uentry
3671 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3673 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3674 typeIdSet_singleOpt (access),
3675 globSet_undefined, sRefSet_undefined,
3676 warnClause_undefined,
3680 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3684 bool uentry_isForward (uentry e)
3686 if (uentry_isValid (e))
3688 ctype ct = uentry_getType (e);
3690 return (ctype_isUnknown (ct)
3691 || (ctype_isFunction (ct)
3692 && ctype_isUnknown (ctype_getReturnType (ct))));
3699 /*@notnull@*/ uentry
3700 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3702 return (uentry_makeFunctionAux (n, ctype_unknown, access,
3703 globSet_undefined, sRefSet_undefined, warnClause_undefined,
3707 /*@notnull@*/ uentry
3708 uentry_makeUnspecFunction (cstring n, ctype t,
3712 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_undefined,
3713 sRefSet_undefined, warnClause_undefined,
3716 reflectImplicitFunctionQualifiers (ue, TRUE);
3725 /* is exported for use by usymtab_interface */
3727 /*@notnull@*/ uentry
3728 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, ynm abstract,
3729 fileloc f, bool priv)
3731 uentry e = uentry_alloc ();
3733 DPRINTF (("Make datatype: %s / %s",
3734 n, ctype_unparse (t)));
3736 /* e->shallowCopy = FALSE; */
3737 e->ukind = KDATATYPE;
3738 e->uname = cstring_copy (n);
3740 e->storageclass = SCNONE;
3741 e->sref = sRef_makeUnknown ();
3745 sRef_setStateFromType (e->sref, t);
3748 uentry_setSpecDef (e, f);
3750 e->warn = warnClause_undefined; /*@i634@*/
3751 e->uses = filelocList_new ();
3752 e->isPrivate = priv;
3753 e->hasNameError = FALSE;
3758 e->info = (uinfo) dmalloc (sizeof (*e->info));
3759 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3760 e->info->datatype->abs = abstract;
3761 e->info->datatype->mut = mut;
3762 e->info->datatype->type = ctype_undefined;
3764 if (uentry_isDeclared (e))
3766 uentry_setDefined (e, f);
3769 if (ynm_isOn (abstract) && !(uentry_isCodeDefined (e)))
3771 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3777 /*@notnull@*/ uentry
3778 uentry_makeDatatype (cstring n, ctype t, ynm mut, ynm abstract, fileloc f)
3780 return (uentry_makeDatatypeAux (n, t, mut, abstract, f, FALSE));
3783 /*@notnull@*/ uentry uentry_makeBoolDatatype (ynm abstract)
3785 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
3786 ctype_bool, NO, abstract,
3787 fileloc_getBuiltin (),
3790 ret->info->datatype->type = ctype_bool;
3798 static /*@only@*/ /*@notnull@*/ uentry
3799 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3800 /*@only@*/ fileloc f)
3802 uentry e = uentry_alloc ();
3805 e->uname = cstring_copy (n);
3807 e->sref = sRef_makeUnknown ();
3808 e->storageclass = SCNONE;
3812 uentry_setSpecDef (e, f);
3814 e->warn = warnClause_undefined; /*@i452@*/
3815 e->uses = filelocList_new ();
3816 e->isPrivate = FALSE;
3817 e->hasNameError = FALSE;
3819 e->info = (uinfo) dmalloc (sizeof (*e->info));
3820 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3821 e->info->iter->access = access;
3822 e->info->iter->mods = sRefSet_undefined;
3823 e->info->iter->globs = globSet_undefined;
3825 uentry_checkIterArgs (e);
3829 /*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3831 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3834 static /*@notnull@*/ uentry
3835 uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3837 uentry e = uentry_alloc ();
3839 /* e->shallowCopy = FALSE; */
3840 e->ukind = KENDITER;
3841 e->storageclass = SCNONE;
3842 e->uname = message ("end_%s", n);
3843 e->utype = ctype_unknown;
3844 e->sref = sRef_makeUnknown ();
3846 uentry_setSpecDef (e, f);
3851 e->uses = filelocList_new ();
3852 e->isPrivate = FALSE;
3853 e->hasNameError = FALSE;
3855 e->info = (uinfo) dmalloc (sizeof (*e->info));
3856 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3858 e->info->enditer->access = access;
3860 e->warn = warnClause_undefined; /*@i452@*/
3864 /*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3866 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3873 static /*@only@*/ /*@notnull@*/ uentry
3874 uentry_makeTagAux (cstring n, ctype t,
3875 /*@only@*/ fileloc fl,
3876 bool priv, ekind kind)
3878 uentry e = uentry_alloc ();
3880 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3882 llbuglit ("uentry_makeTagAux: not a tag type");
3886 /* e->shallowCopy = FALSE; */
3887 e->uname = cstring_copy (n);
3890 e->sref = sRef_makeUnknown ();
3891 e->storageclass = SCNONE;
3893 uentry_setSpecDef (e, fl);
3898 e->uses = filelocList_new ();
3899 e->isPrivate = priv;
3900 e->hasNameError = FALSE;
3902 e->info = (uinfo) dmalloc (sizeof (*e->info));
3903 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3904 e->info->datatype->abs = NO;
3905 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3906 e->info->datatype->type = t;
3907 e->warn = warnClause_undefined; /*@i452@*/
3909 if (uentry_isDeclared (e))
3911 uentry_setDefined (e, fl);
3917 uentry uentry_makeStructTagLoc (cstring n, ctype t)
3919 cstring sname = makeStruct (n);
3920 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3922 cstring_free (sname);
3927 uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3929 cstring sname = makeStruct (n);
3930 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3932 cstring_free (sname);
3937 uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
3939 cstring uname = makeUnion (n);
3940 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
3942 cstring_free (uname);
3948 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
3950 cstring ename = makeEnum (n);
3951 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
3953 cstring_free (ename);
3959 uentry_makeUnionTagLoc (cstring n, ctype t)
3961 cstring uname = makeUnion (n);
3962 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
3964 cstring_free (uname);
3969 uentry_makeEnumTagLoc (cstring n, ctype t)
3971 cstring ename = makeEnum (n);
3972 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
3974 cstring_free (ename);
3979 uentry_isStructTag (uentry ue)
3981 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
3985 uentry_isUnionTag (uentry ue)
3987 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
3991 uentry_isEnumTag (uentry ue)
3993 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
3997 uentry_isAnyTag (uentry ue)
3999 return (uentry_isStructTag (ue)
4000 || uentry_isUnionTag (ue)
4001 || uentry_isEnumTag (ue));
4004 static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
4006 extern void uentry_destroyMod (void)
4007 /*@globals killed emarker@*/ /*@modifies emarker@*/
4009 static bool wasDestroyed = FALSE;
4011 llassert (!wasDestroyed);
4013 if (emarker != NULL)
4015 uentry_reallyFree (emarker);
4018 wasDestroyed = TRUE;
4022 uentry_makeElipsisMarker (void)
4024 if (emarker == NULL)
4026 emarker = uentry_alloc ();
4028 emarker->ukind = KELIPSMARKER;
4029 emarker->uname = cstring_makeLiteral ("...");
4030 emarker->utype = ctype_elipsMarker;
4031 emarker->sref = sRef_undefined;
4032 emarker->storageclass = SCNONE;
4033 emarker->used = FALSE;
4034 emarker->lset = FALSE;
4035 emarker->info = NULL;
4037 uentry_setSpecDef (emarker, fileloc_undefined);
4038 emarker->uses = filelocList_new ();
4039 emarker->isPrivate = FALSE;
4040 emarker->hasNameError = FALSE;
4043 /*@ignore@*/ return (emarker); /*@end@*/
4051 uentry_equiv (uentry p1, uentry p2)
4053 if (uentry_compare (p1, p2) != 0)
4064 uentry_xcomparealpha (uentry *p1, uentry *p2)
4068 if ((res = uentry_compare (*p1, *p2)) == 0) {
4069 if ((*p1 != NULL) && (*p2 != NULL)) {
4070 res = cstring_compare ((*p1)->uname,
4079 uentry_xcompareuses (uentry *p1, uentry *p2)
4084 if (uentry_isValid (u1))
4086 if (uentry_isValid (u2))
4088 return (-1 * int_compare (filelocList_size (u1->uses),
4089 filelocList_size (u2->uses)));
4098 if (uentry_isValid (u2))
4110 uentry_compareStrict (uentry v1, uentry v2)
4112 COMPARERETURN (uentry_compare (v1, v2));
4114 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
4116 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
4117 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
4118 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
4125 uentry_compare (uentry u1, uentry u2)
4127 if (u1 == u2) return 0;
4129 if (uentry_isInvalid (u1)) return -1;
4130 if (uentry_isInvalid (u2)) return 1;
4132 INTCOMPARERETURN (u1->ukind, u2->ukind);
4133 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
4134 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
4135 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
4141 /* bug detected by lclint:
4142 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
4147 return (multiVal_compare (uentry_getConstantValue (u1),
4148 uentry_getConstantValue (u2)));
4152 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
4154 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
4155 uentry_accessType (u2)));
4156 return (uentryList_compareParams (uentry_getParams (u1),
4157 uentry_getParams (u2)));
4159 return (typeIdSet_compare (uentry_accessType (u1),
4160 uentry_accessType (u2)));
4163 ** Functions are never equivalent
4166 if (u1 - u2 < 0) /* evans 2001-08-21: was: ((int) u1 < (int) u2), changed to remove gcc warning */
4176 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
4177 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
4178 sRef_getOrigAliasKind (u2->sref)));
4179 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
4180 sRef_getOrigExKind (u2->sref)));
4181 COMPARERETURN (generic_compare (u1->info->var->checked,
4182 u2->info->var->checked));
4183 COMPARERETURN (generic_compare (u1->info->var->defstate,
4184 u2->info->var->defstate));
4185 return (generic_compare (u1->info->var->nullstate,
4186 u2->info->var->nullstate));
4188 COMPARERETURN (ctype_compare (u1->info->datatype->type,
4189 u2->info->datatype->type));
4190 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
4191 u2->info->datatype->mut));
4192 return (ynm_compare (u1->info->datatype->abs, u2->info->datatype->abs));
4201 ** all entries are: <type>[@<info>]*#<name>
4203 ** info depends on kind:
4207 advanceField (char **s)
4209 reader_checkChar (s, '@');
4213 advanceName (char **s)
4215 reader_checkChar (s, '#');
4219 vkind_fromInt (int i)
4221 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
4223 llbuglit ("vkind_fromInt: out of range");
4230 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
4231 typeIdSet access, nstate nullstate,
4232 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
4234 uentry e = uentry_alloc ();
4239 e->sref = sRef_makeConst (ct);
4241 sRef_setNullState (e->sref, nullstate, loc);
4242 e->storageclass = SCNONE;
4244 if (fileloc_isSpec (loc))
4246 e->whereSpecified = loc;
4247 e->whereDeclared = fileloc_undefined;
4251 e->whereSpecified = fileloc_undefined;
4252 e->whereDeclared = loc;
4255 e->whereDefined = fileloc_undefined;
4256 e->uses = filelocList_new ();
4257 e->isPrivate = FALSE;
4258 e->hasNameError = FALSE;
4263 e->warn = warnClause_undefined; /*@i452@*/
4265 e->info = (uinfo) dmalloc (sizeof (*e->info));
4266 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
4267 e->info->uconst->access = access;
4269 uentry_setConstantValue (e, m);
4270 sRef_storeState (e->sref);
4275 static /*@only@*/ uentry
4276 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
4277 sstate defstate, nstate isnull, alkind aliased,
4278 exkind exp, chkind checked,
4279 /*@only@*/ fileloc loc)
4281 uentry e = uentry_alloc ();
4286 e->storageclass = SCNONE;
4288 e->sref = sRef_makeType (ct);
4289 sRef_setNullState (e->sref, isnull, loc);
4291 e->whereDefined = fileloc_undefined;
4293 if (fileloc_isSpec (loc))
4295 e->whereSpecified = loc;
4296 e->whereDeclared = fileloc_undefined;
4300 e->whereSpecified = fileloc_undefined;
4301 e->whereDeclared = loc;
4304 e->isPrivate = FALSE;
4305 e->hasNameError = FALSE;
4310 e->uses = filelocList_new ();
4311 e->warn = warnClause_undefined; /*@i452@*/
4313 e->info = (uinfo) dmalloc (sizeof (*e->info));
4314 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
4315 e->info->var->kind = kind;
4316 e->info->var->checked = checked;
4317 e->info->var->defstate = defstate;
4319 sRef_setDefState (e->sref, defstate, loc);
4321 e->info->var->nullstate = sRef_getNullState (e->sref);
4323 sRef_setExKind (e->sref, exp, loc);
4324 sRef_setAliasKind (e->sref, aliased, loc);
4326 sRef_storeState (e->sref);
4328 /*DRL ADDED 9-1-2000 */
4329 e->info->var->bufinfo = NULL;
4334 static /*@only@*/ uentry
4335 uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, ynm abstract,
4336 ynm mut, ctype rtype, alkind ak, exkind exp,
4337 sstate defstate, nstate isnull,
4338 /*@only@*/ fileloc loc)
4340 uentry e = uentry_alloc ();
4342 e->ukind = KDATATYPE;
4343 /* e->shallowCopy = FALSE; */
4346 e->storageclass = SCNONE;
4347 e->sref = sRef_makeUnknown ();
4348 DPRINTF (("Merge null 1: %s", sRef_unparseFull (e->sref)));
4351 ** This is only setting null state. (I think?)
4354 if (ctype_isUA (ct))
4356 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
4358 if (uentry_isValid (te))
4360 sRef_setStateFromUentry (e->sref, te);
4364 /* problem for recursive type definitions */
4368 sRef_setAliasKind (e->sref, ak, loc);
4369 sRef_setExKind (e->sref, exp, loc);
4371 sRef_setDefState (e->sref, defstate, loc);
4373 if (ynm_isOn (abstract) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
4375 isnull = NS_ABSNULL;
4378 DPRINTF (("Merge null: %s", sRef_unparseFull (e->sref)));
4379 sRef_mergeNullState (e->sref, isnull);
4381 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
4383 if (fileloc_isSpec (loc))
4385 e->whereSpecified = loc;
4386 e->whereDeclared = fileloc_undefined;
4390 e->whereSpecified = fileloc_undefined;
4391 e->whereDeclared = loc;
4394 e->isPrivate = FALSE;
4395 e->hasNameError = FALSE;
4397 e->warn = warnClause_undefined; /*@i452@*/
4401 e->uses = filelocList_new ();
4403 e->info = (uinfo) dmalloc (sizeof (*e->info));
4404 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4405 e->info->datatype->abs = abstract;
4406 e->info->datatype->mut = mut;
4407 e->info->datatype->type = rtype;
4409 DPRINTF (("About to store: %s", sRef_unparseFull (e->sref)));
4410 sRef_storeState (e->sref);
4411 DPRINTF (("After store: %s", sRef_unparseFull (e->sref)));
4417 static void uentry_setHasGlobs (uentry ue)
4419 llassert (uentry_isFunction (ue));
4421 ue->info->fcn->hasGlobs = TRUE;
4424 static void uentry_setHasMods (uentry ue)
4426 llassert (uentry_isFunction (ue));
4428 ue->info->fcn->hasMods = TRUE;
4432 bool uentry_hasGlobs (uentry ue)
4434 if (uentry_isFunction (ue))
4436 return (ue->info->fcn->hasGlobs);
4442 bool uentry_hasStateClauseList (uentry ue)
4444 return (uentry_isFunction (ue) && stateClauseList_isDefined (ue->info->fcn->specclauses));
4447 bool uentry_hasConditions (uentry ue)
4449 return (uentry_isFunction (ue)
4450 && (functionConstraint_isDefined (ue->info->fcn->preconditions)
4451 || functionConstraint_isDefined (ue->info->fcn->postconditions)));
4454 stateClauseList uentry_getStateClauseList (uentry ue)
4456 if (!uentry_isFunction (ue))
4458 llassert (uentry_isFunction (ue));
4459 return stateClauseList_undefined;
4462 DPRINTF (("Get state clause list: %s", uentry_unparse (ue)));
4463 return ue->info->fcn->specclauses;
4466 bool uentry_hasMods (uentry ue)
4468 if (uentry_isFunction (ue))
4470 return (ue->info->fcn->hasMods);
4477 uentry_makeFunctionBase (/*@only@*/ cstring name, ctype ct,
4479 bool hasGlobs, /*@only@*/ globSet globs,
4480 bool hasMods, /*@only@*/ sRefSet mods,
4481 alkind ak, exkind exp,
4482 sstate defstate, nstate isnull,
4486 /*@only@*/ stateClauseList specclauses,
4487 /*@only@*/ warnClause warnclause,
4488 /*@only@*/ fileloc loc)
4490 uentry e = uentry_alloc ();
4493 /* e->shallowCopy = FALSE; */
4497 e->storageclass = SCNONE;
4499 if (ctype_isFunction (ct))
4501 ret = ctype_getReturnType (ct);
4505 if (ctype_isKnown (ct))
4507 llbug (message ("not function: %s", ctype_unparse (ct)));
4510 ret = ctype_unknown;
4513 e->sref = sRef_makeType (ret);
4515 if (ctype_isUA (ret))
4517 sRef_setStateFromType (e->sref, ret);
4520 sRef_setDefined (e->sref, loc);
4521 sRef_setNullState (e->sref, isnull, loc);
4523 sRef_setAliasKind (e->sref, ak, loc);
4524 sRef_setExKind (e->sref, exp, loc);
4525 sRef_setDefState (e->sref, defstate, loc);
4527 e->whereSpecified = loc;
4528 e->whereDefined = fileloc_undefined;
4530 e->isPrivate = FALSE;
4531 e->hasNameError = FALSE;
4535 e->uses = filelocList_new ();
4536 e->warn = warnclause;
4538 e->info = (uinfo) dmalloc (sizeof (*e->info));
4539 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
4541 e->info->fcn->exitCode = exitCode;
4542 e->info->fcn->specialCode = sCode;
4543 e->info->fcn->nullPred = nullPred;
4544 e->info->fcn->access = access;
4546 e->info->fcn->specclauses = specclauses;
4547 e->info->fcn->hasGlobs = hasGlobs;
4548 e->info->fcn->globs = globs;
4550 e->info->fcn->hasMods = hasMods;
4551 e->info->fcn->mods = mods;
4553 e->info->fcn->defparams = uentryList_undefined;
4554 e->whereDeclared = fileloc_undefined;
4556 sRef_storeState (e->sref);
4559 e->info->fcn->preconditions = NULL;
4563 e->info->fcn->postconditions = NULL;
4569 static /*@only@*/ uentry
4570 uentry_makeTagBase (/*@only@*/ cstring name, ekind tagkind,
4571 ctype ct, ctype rtype, /*@only@*/ fileloc loc)
4573 uentry e = uentry_alloc ();
4575 if (tagkind != KSTRUCTTAG && tagkind != KUNIONTAG && tagkind != KENUMTAG)
4577 llbuglit ("uentry_makeTagBase: not a tag type");
4580 /* e->shallowCopy = FALSE; */
4584 e->sref = sRef_makeUnknown ();
4585 e->storageclass = SCNONE;
4587 if (fileloc_isSpec (loc))
4589 e->whereSpecified = loc;
4590 e->whereDeclared = fileloc_undefined;
4594 e->whereDeclared = loc;
4595 e->whereSpecified = fileloc_undefined;
4598 e->whereDefined = fileloc_undefined;
4600 e->isPrivate = FALSE;
4601 e->hasNameError = FALSE;
4605 e->uses = filelocList_new ();
4606 e->warn = warnClause_undefined; /*@i452@*/
4608 e->info = (uinfo) dmalloc (sizeof (*e->info));
4609 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4610 e->info->datatype->abs = NO;
4611 e->info->datatype->mut = MAYBE;
4612 e->info->datatype->type = rtype;
4614 sRef_storeState (e->sref);
4620 uentry_makeIterBase (/*@only@*/ cstring name, typeIdSet access,
4621 ctype ct, /*@only@*/ fileloc loc)
4623 uentry e = uentry_alloc ();
4625 /* e->shallowCopy = FALSE; */
4629 e->sref = sRef_makeUnknown ();
4630 e->storageclass = SCNONE;
4632 if (fileloc_isSpec (loc))
4634 e->whereSpecified = loc;
4635 e->whereDeclared = fileloc_undefined;
4639 e->whereDeclared = loc;
4640 e->whereSpecified = fileloc_undefined;
4643 e->whereDefined = fileloc_undefined;
4645 e->isPrivate = FALSE;
4646 e->hasNameError = FALSE;
4650 e->uses = filelocList_new ();
4651 e->warn = warnClause_undefined; /*@i452@*/
4653 e->info = (uinfo) dmalloc (sizeof (*e->info));
4654 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
4655 e->info->iter->access = access;
4656 e->info->iter->mods = sRefSet_undefined;
4657 e->info->iter->globs = globSet_undefined;
4659 sRef_storeState (e->sref);
4664 uentry_makeEndIterBase (/*@only@*/ cstring name, typeIdSet access,
4665 /*@only@*/ fileloc loc)
4667 uentry e = uentry_alloc ();
4669 /* e->shallowCopy = FALSE; */
4670 e->ukind = KENDITER;
4671 e->storageclass = SCNONE;
4673 e->utype = ctype_unknown;
4674 e->sref = sRef_makeUnknown ();
4676 if (fileloc_isSpec (loc))
4678 e->whereSpecified = loc;
4679 e->whereDeclared = fileloc_undefined;
4683 e->whereDeclared = loc;
4684 e->whereSpecified = fileloc_undefined;
4687 e->whereDefined = fileloc_undefined;
4689 e->isPrivate = FALSE;
4690 e->hasNameError = FALSE;
4694 e->uses = filelocList_new ();
4695 e->warn = warnClause_undefined; /*@i452@*/
4697 e->info = (uinfo) dmalloc (sizeof (*e->info));
4698 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
4699 e->info->enditer->access = access;
4700 sRef_storeState (e->sref);
4705 void uentry_markFree (/*@unused@*/ /*@owned@*/ uentry u)
4713 uentry_undump (ekind kind, fileloc loc, char **s)
4717 DPRINTF (("Uentry undump: %s", *s));
4721 reader_checkChar (s, '!');
4722 reader_checkChar (s, '.');
4723 ue = uentry_makeElipsisMarker ();
4727 ctype ct = ctype_undump (s);
4741 reader_checkChar (s, '|');
4743 if (reader_optCheckChar (s, '@'))
4745 tkind = vkind_fromInt (reader_getInt (s));
4746 reader_checkChar (s, '|');
4753 if (reader_optCheckChar (s, '$'))
4755 defstate = SS_UNKNOWN;
4756 isnull = NS_UNKNOWN;
4757 aliased = AK_IMPTEMP;
4759 checked = CH_UNKNOWN;
4761 else if (reader_optCheckChar (s, '&'))
4763 defstate = SS_DEFINED;
4764 isnull = NS_UNKNOWN;
4765 aliased = AK_IMPTEMP;
4767 checked = CH_UNKNOWN;
4769 else if (reader_optCheckChar (s, '^'))
4771 defstate = SS_UNKNOWN;
4772 isnull = NS_UNKNOWN;
4773 aliased = AK_IMPTEMP;
4775 checked = CH_UNKNOWN;
4779 defstate = sstate_fromInt (reader_getInt (s));
4780 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4781 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4783 if (reader_optCheckChar (s, '&'))
4786 checked = CH_UNKNOWN;
4790 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4791 advanceField (s); checked = (chkind) (reader_getInt (s));
4796 name = reader_getStringWord (s);
4798 llassert (!cstring_equal (name, GLOBAL_MARKER_NAME));
4800 ue = uentry_makeVariableBase (name, ct, tkind, defstate,
4801 isnull, aliased, exp,
4802 checked, fileloc_copy (loc));
4815 advanceField (s); abstract = ynm_fromCodeChar (reader_loadChar (s));
4816 advanceField (s); mut = ynm_fromCodeChar (reader_loadChar (s));
4817 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4818 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4819 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4820 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4821 advanceField (s); rtype = ctype_undump (s);
4823 name = reader_getStringWord (s);
4824 DPRINTF (("Datatype %s, Exp = %s", name, exkind_unparse (exp)));
4825 ue = uentry_makeDatatypeBase (name, ct, abstract, mut, rtype,
4826 aliased, exp, defstate, isnull,
4827 fileloc_copy (loc));
4844 stateClauseList specclauses = stateClauseList_undefined;
4845 warnClause warnclause = warnClause_undefined;
4847 if (reader_optCheckChar (s, '$'))
4849 defstate = SS_DEFINED;
4850 isnull = NS_UNKNOWN;
4851 exitCode = XK_UNKNOWN;
4853 nullPred = qual_createUnknown ();
4857 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4858 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4859 advanceField (s); exitCode = exitkind_fromInt (reader_getInt (s));
4860 advanceField (s); specc = specCode_fromInt (reader_getInt (s));
4861 advanceField (s); nullPred = qual_undump (s);
4864 if (reader_optCheckChar (s, '$'))
4867 globs = globSet_undefined;
4869 mods = sRefSet_undefined;
4871 else if (reader_optCheckChar (s, '^'))
4874 globs = globSet_undefined;
4876 mods = sRefSet_undefined;
4880 advanceField (s); hasGlobs = bool_fromInt (reader_getInt (s));
4881 advanceField (s); globs = globSet_undump (s);
4882 advanceField (s); hasMods = bool_fromInt (reader_getInt (s));
4883 advanceField (s); mods = sRefSet_undump (s);
4886 if (reader_optCheckChar (s, '$'))
4893 advanceField (s); ak = alkind_fromInt (reader_getInt (s));
4894 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4897 advanceField (s); access = typeIdSet_undump (s);
4900 ** Optional clauses: Start with @<code>:
4903 while (reader_optCheckChar (s, '@'))
4905 if (reader_optCheckChar (s, 'W')) /* Warn clause */
4907 reader_checkChar (s, ':');
4908 warnclause = warnClause_undump (s);
4910 else if (reader_optCheckChar (s, 'S')) /* stateClause List */
4912 reader_checkChar (s, ':');
4913 specclauses = stateClauseList_undump (s);
4921 advanceName (s); name = reader_getStringWord (s);
4923 ue = uentry_makeFunctionBase (name, ct, access,
4926 ak, exp, defstate, isnull,
4927 exitCode, specc, nullPred,
4930 fileloc_copy (loc));
4931 DPRINTF (("Undump: %s", uentry_unparse (ue)));
4938 advanceField (s); access = typeIdSet_undump (s);
4939 advanceName (s); name = reader_getStringWord (s);
4941 ue = uentry_makeIterBase (name, access, ct,
4942 fileloc_copy (loc));
4949 advanceField (s); access = typeIdSet_undump (s);
4950 advanceName (s); name = reader_getStringWord (s);
4952 ue = uentry_makeEndIterBase (name, access, fileloc_copy (loc));
4962 if (reader_optCheckChar (s, '$'))
4964 val = multiVal_undefined;
4965 access = typeIdSet_undefined;
4966 nullstate = NS_UNKNOWN;
4970 advanceField (s); val = multiVal_undump (s);
4971 advanceField (s); access = typeIdSet_undump (s);
4972 advanceField (s); nullstate = nstate_fromInt (reader_getInt (s));
4975 advanceName (s); name = reader_getStringWord (s);
4977 ue = uentry_makeConstantBase (name, ct, access,
4978 nullstate, fileloc_copy (loc), val);
4987 advanceField (s); rtype = ctype_undump (s);
4988 advanceName (s); name = reader_getStringWord (s);
4989 ue = uentry_makeTagBase (name, kind, ct, rtype, fileloc_copy (loc));
4993 llcontbuglit ("uentry_undump: invalid");
4994 ue = uentry_undefined;
4997 llcontbuglit ("uentry_undump: elips marker");
4998 ue = uentry_undefined;
5007 uentry_dump (uentry v)
5009 return (uentry_dumpAux (v, FALSE));
5013 uentry_dumpParam (uentry v)
5015 llassertprint (uentry_isVariable (v) || uentry_isElipsisMarker (v),
5016 ("dump: %s", uentry_unparseFull (v)));
5018 return (uentry_dumpAux (v, TRUE));
5022 uentry_dumpAux (uentry v, bool isParam)
5024 llassert (uentry_isValid (v));
5025 llassert (!uentry_isGlobalMarker (v));
5027 DPRINTF (("Dump uentry: [%p]", v));
5028 DPRINTF (("Dumping entry: %s", uentry_unparseFull (v)));
5033 llcontbuglit ("uentry_dump: invalid entry");
5034 return cstring_undefined;
5036 return (message ("!."));
5040 vkind vk = v->info->var->kind;
5041 sstate dss = sRef_getDefState (v->sref);
5042 nstate nst = sRef_getNullState (v->sref);
5043 alkind alk = sRef_getAliasKind (v->sref);
5044 exkind exk = sRef_getExKind (v->sref);
5045 chkind chk = v->info->var->checked;
5047 DPRINTF (("Dumping var"));
5049 if (dss == SS_UNKNOWN
5050 && nst == NS_UNKNOWN
5051 && alk == AK_IMPTEMP
5052 && exk == XO_UNKNOWN
5053 && chk == CH_UNKNOWN)
5055 sdump = cstring_makeLiteral ("$");
5057 else if (dss == SS_DEFINED
5058 && nst == NS_UNKNOWN
5059 && alk == AK_IMPTEMP
5060 && exk == XO_UNKNOWN
5061 && chk == CH_UNKNOWN)
5063 sdump = cstring_makeLiteral ("&");
5065 else if (dss == SS_UNKNOWN
5066 && nst == NS_UNKNOWN
5067 && alk == AK_UNKNOWN
5068 && exk == XO_UNKNOWN
5069 && chk == CH_UNKNOWN)
5071 sdump = cstring_makeLiteral ("^");
5073 else if (exk == XO_UNKNOWN
5074 && chk == CH_UNKNOWN)
5076 sdump = message ("%d@%d@%d&",
5083 sdump = message ("%d@%d@%d@%d@%d",
5094 return (message ("%q|@%d|%q#%s",
5095 ctype_dump (v->utype),
5098 isParam ? cstring_undefined : v->uname));
5102 return (message ("%q|%q#%s",
5103 ctype_dump (v->utype),
5105 isParam ? cstring_undefined : v->uname));
5111 DPRINTF (("Dumping datatype: %s -> %s type: %s [%d]",
5113 exkind_unparse (sRef_getExKind (v->sref)),
5114 ctype_unparse (v->utype), (int) v->utype));
5117 return (message ("%q@%s@%s@%d@%d@%d@%d@%q#%s",
5118 ctype_dump (v->utype),
5119 ynm_unparseCode (v->info->datatype->abs),
5120 ynm_unparseCode (v->info->datatype->mut),
5121 (int) sRef_getDefState (v->sref),
5122 (int) sRef_getNullState (v->sref),
5123 (int) sRef_getAliasKind (v->sref),
5124 (int) sRef_getExKind (v->sref),
5125 ctype_dump (v->info->datatype->type),
5129 cstring sdump, gdump, adump, xdump;
5130 alkind alk = sRef_getAliasKind (v->sref);
5131 exkind exk = sRef_getExKind (v->sref);
5133 if (sRef_getDefState (v->sref) == SS_DEFINED
5134 && !nstate_isKnown (sRef_getNullState (v->sref))
5135 && !exitkind_isKnown (v->info->fcn->exitCode)
5136 && v->info->fcn->specialCode == SPC_NONE
5137 && qual_isUnknown (v->info->fcn->nullPred))
5139 sdump = cstring_makeLiteral ("$");
5143 sdump = message ("@%d@%d@%d@%d@%x",
5144 (int) sRef_getDefState (v->sref),
5145 (int) sRef_getNullState (v->sref),
5146 (int) v->info->fcn->exitCode,
5147 (int) v->info->fcn->specialCode,
5148 qual_dump (v->info->fcn->nullPred));
5151 if (!uentry_hasGlobs(v) && !uentry_hasMods (v))
5153 gdump = cstring_makeLiteral ("$");
5155 else if (uentry_hasGlobs (v) && globSet_isEmpty (uentry_getGlobs (v))
5156 && uentry_hasMods (v) && sRefSet_isEmpty (uentry_getMods (v)))
5158 gdump = cstring_makeLiteral ("^");
5162 gdump = message ("@%s@%q@%s@%q",
5163 bool_dump (uentry_hasGlobs (v)),
5164 globSet_dump (uentry_getGlobs (v)),
5165 bool_dump (uentry_hasMods (v)),
5166 sRefSet_dump (uentry_getMods (v)));
5169 if (alk == AK_UNKNOWN && exk == XO_UNKNOWN)
5171 adump = cstring_makeLiteral ("$");
5175 adump = message ("@%d@%d", (int) alk, (int) exk);
5178 xdump = cstring_undefined;
5180 if (uentry_hasWarning (v))
5182 xdump = message ("%q@W:%q", xdump, warnClause_dump (v->warn));
5185 if (uentry_hasStateClauseList (v))
5187 xdump = message ("%q@S:%q", xdump, stateClauseList_dump (v->info->fcn->specclauses));
5190 return (message ("%q%q%q%q@%q%q#%s",
5191 ctype_dump (v->utype),
5195 typeIdSet_dump (uentry_accessType (v)),
5200 return (message ("%q@%q#%s",
5201 ctype_dump (v->utype),
5202 typeIdSet_dump (v->info->iter->access),
5205 return (message ("%q@%q#%s",
5206 ctype_dump (v->utype),
5207 typeIdSet_dump (uentry_accessType (v)),
5214 if (multiVal_isUnknown (uentry_getConstantValue (v))
5215 && typeIdSet_isEmpty (uentry_accessType (v))
5216 && (sRef_getNullState (v->sref) == NS_UNKNOWN))
5218 sdump = cstring_makeLiteral ("$");
5222 sdump = message ("@%q@%q@%d",
5223 multiVal_dump (uentry_getConstantValue (v)),
5224 typeIdSet_dump (uentry_accessType (v)),
5225 (int) sRef_getNullState (v->sref));
5228 return (message ("%q%q#%s",
5229 ctype_dump (v->utype),
5236 return (message ("%q@%q#%s",
5237 ctype_dump (v->utype),
5238 ctype_dump (v->info->datatype->type), v->uname));
5245 uentry_unparseAbbrev (uentry v)
5247 if (!uentry_isVariable (v))
5249 llcontbuglit ("uentry_unparseAbbrev: not variable");
5250 return uentry_unparse (v);
5253 return (message ("%s %q", ctype_unparseDeep (v->utype), uentry_getName (v)));
5257 uentry_unparse (uentry v)
5261 if (uentry_isUndefined (v)) return (cstring_makeLiteral ("<undefined>"));
5262 if (uentry_isElipsisMarker (v)) return (cstring_makeLiteral ("..."));
5264 st = uentry_getName (v);
5266 if (cstring_isDefined (st))
5268 return (ctype_unparseDeclaration (v->utype, st));
5273 return (cstring_copy (ctype_unparse (v->utype)));
5278 uentry_unparseFull (uentry v)
5280 if (uentry_isUndefined (v))
5282 return (cstring_makeLiteral ("<undefined>"));
5288 res = message ("[%w] %s %s: %s [spec: %q; decl: %q; def: %q]",
5289 (unsigned long) v, ekind_unparse (v->ukind), v->uname,
5290 ctype_unparse (v->utype),
5291 fileloc_unparse (uentry_whereSpecified (v)),
5292 fileloc_unparse (uentry_whereDeclared (v)),
5293 fileloc_unparse (uentry_whereDefined (v)));
5295 DPRINTF (("uentry: %s", res));
5297 if (uentry_isDatatype (v))
5299 res = message ("%q / type: %s mut: %s abs: %s state: %q",
5302 (ctype_isDefined (v->info->datatype->type)
5303 ? v->info->datatype->type : ctype_unknown),
5304 ynm_unparse (v->info->datatype->mut),
5305 ynm_unparse (v->info->datatype->abs),
5306 sRef_unparseState (v->sref));
5308 else if (uentry_isFunction (v))
5310 res = message ("%q / sref: %q / mods: %q / "
5311 "globs: %q / clauses: %q / pre: %q / post: %q",
5313 sRef_unparseFull (v->sref),
5314 sRefSet_unparse (v->info->fcn->mods),
5315 globSet_unparse (v->info->fcn->globs),
5316 stateClauseList_unparse (v->info->fcn->specclauses),
5317 functionConstraint_unparse (v->info->fcn->preconditions),
5318 functionConstraint_unparse (v->info->fcn->postconditions));
5320 else if (uentry_isIter (v))
5322 res = message ("%q / sref: %q",
5324 sRef_unparseFull (v->sref));
5326 else if (uentry_isVariable (v))
5328 res = message ("%q / sref: %q / kind <%d> isout <%d> null <%d> used <%d>",
5330 sRef_unparseFull (v->sref),
5331 (int) v->info->var->kind,
5332 (int) v->info->var->defstate,
5333 (int) v->info->var->nullstate,
5335 DPRINTF (("sref: [%p]", v->sref));
5336 DPRINTF (("sref: %s", sRef_unparseDebug (v->sref)));
5337 /* DPRINTF (("sref: %s", sRef_unparseDeep (v->sref))); */
5339 else if (uentry_isConstant (v))
5341 res = message ("%q = %q",
5342 res, multiVal_unparse (uentry_getConstantValue (v)));
5346 res = message ("%q :: %q", res, uentry_unparse (v));
5353 bool uentry_hasAccessType (uentry e)
5355 if (uentry_isValid (e))
5360 return (!typeIdSet_isEmpty (e->info->iter->access));
5362 return (!typeIdSet_isEmpty (e->info->enditer->access));
5364 return (!typeIdSet_isEmpty (e->info->fcn->access));
5367 return (!typeIdSet_isEmpty (e->info->uconst->access));
5376 typeIdSet uentry_accessType (uentry e)
5378 if (uentry_isValid (e))
5383 return (e->info->iter->access);
5385 return (e->info->enditer->access);
5387 return (e->info->fcn->access);
5390 return (e->info->uconst->access);
5396 return typeIdSet_undefined;
5400 uentry_isVariable (uentry e)
5402 return (uentry_isVar (e));
5406 uentry_isSpecified (uentry e)
5408 return (uentry_isValid (e) && !fileloc_isUndefined (e->whereSpecified));
5412 uentry_isReallySpecified (uentry e)
5414 return (uentry_isValid (e)
5415 && fileloc_isRealSpec (e->whereSpecified));
5419 uentry_isVar (uentry e)
5421 return (!uentry_isUndefined (e) && e->ukind == KVAR);
5425 uentry_isFakeTag (uentry e)
5427 return (uentry_isValid (e) && strchr (cstring_toCharsSafe (e->uname), '!') != 0);
5431 uentry_isDatatype (uentry e)
5433 return (!uentry_isUndefined (e) &&
5434 (e->ukind == KDATATYPE || e->ukind == KSTRUCTTAG ||
5435 e->ukind == KUNIONTAG || e->ukind == KENUMTAG));
5439 uentry_setAbstract (uentry e)
5443 llassert (uentry_isDatatype (e)
5444 && (ynm_isMaybe (e->info->datatype->abs)));
5446 oldid = ctype_typeId (e->info->datatype->type);
5447 e->info->datatype->abs = YES;
5448 e->info->datatype->type = ctype_createAbstract (oldid);
5452 uentry_setConcrete (uentry e)
5454 llassert (uentry_isDatatype (e)
5455 && (ynm_isMaybe (e->info->datatype->abs)));
5457 e->info->datatype->abs = NO;
5461 uentry_isAbstractDatatype (uentry e)
5463 return (uentry_isDatatype (e)
5464 && (ynm_isOn (e->info->datatype->abs)));
5468 uentry_isMaybeAbstract (uentry e)
5470 return (uentry_isDatatype (e)
5471 && (ynm_isMaybe (e->info->datatype->abs)));
5475 uentry_isMutableDatatype (uentry e)
5477 bool res = uentry_isDatatype (e)
5478 && (ynm_toBoolRelaxed (e->info->datatype->mut));
5484 uentry_isRefCountedDatatype (uentry e)
5486 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
5490 uentry_isParam (uentry u)
5492 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
5493 || u->info->var->kind == VKYIELDPARAM));
5497 uentry_isExpandedMacro (uentry u)
5499 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
5503 uentry_isSefParam (uentry u)
5505 return (uentry_isVariable (u)
5506 && (u->info->var->kind == VKSEFPARAM
5507 || u->info->var->kind == VKREFSEFPARAM
5508 || u->info->var->kind == VKSEFRETPARAM
5509 || u->info->var->kind == VKREFSEFRETPARAM));
5513 uentry_isRefParam (uentry u)
5515 return (uentry_isVariable (u)
5516 && (u->info->var->kind == VKREFPARAM
5517 || u->info->var->kind == VKREFYIELDPARAM
5518 || u->info->var->kind == VKREFSEFPARAM
5519 || u->info->var->kind == VKREFSEFRETPARAM));
5523 uentry_isAnyParam (uentry u)
5525 return (uentry_isVariable (u)
5526 && ((u->info->var->kind == VKPARAM)
5527 || (u->info->var->kind == VKSEFPARAM)
5528 || (u->info->var->kind == VKYIELDPARAM)
5529 || (u->info->var->kind == VKRETPARAM)
5530 || (u->info->var->kind == VKSEFRETPARAM)));
5534 uentry_getDefState (uentry u)
5536 if (uentry_isValid (u))
5538 return (sRef_getDefState (u->sref));
5542 return (SS_UNKNOWN);
5547 uentry_isOut (uentry u)
5549 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5550 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5554 uentry_isPartial (uentry u)
5556 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5557 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5561 uentry_isStateSpecial (uentry u)
5563 return ((uentry_isVariable (u)
5564 && (u->info->var->defstate == SS_SPECIAL))
5565 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5568 exitkind uentry_getExitCode (uentry ue)
5570 if (uentry_isFunction (ue))
5572 return ue->info->fcn->exitCode;
5580 qual uentry_nullPred (uentry u)
5582 llassert (uentry_isRealFunction (u));
5584 if (uentry_isFunction (u))
5586 return (u->info->fcn->nullPred);
5590 return qual_createUnknown ();
5595 ** Note for variables, this is checking the declared state, not the current state.
5599 uentry_possiblyNull (uentry u)
5601 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5602 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5606 uentry_getAliasKind (uentry u)
5608 if (uentry_isValid (u))
5610 return (sRef_getAliasKind (uentry_getSref (u)));
5619 uentry_getExpKind (uentry u)
5621 if (uentry_isValid (u))
5623 return (sRef_getExKind (uentry_getSref (u)));
5632 uentry_isIter (uentry e)
5634 return (!uentry_isUndefined (e) && e->ukind == KITER);
5638 uentry_isEndIter (uentry e)
5640 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5644 uentry_isRealFunction (uentry e)
5646 return (uentry_isFunction (e) ||
5647 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5651 uentry_hasName (uentry e)
5653 if (uentry_isValid (e))
5655 cstring s = e->uname;
5657 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")
5658 || uentry_isFakeTag (e)));
5667 ** Returns true for fake tags.
5668 ** This is used for dumping the library
5671 bool uentry_hasRealName (uentry e)
5673 return (uentry_isValid (e)
5674 && cstring_isNonEmpty (e->uname)
5675 && !uentry_isGlobalMarker (e));
5679 /*@observer@*/ globSet
5680 uentry_getGlobs (uentry l)
5682 if (uentry_isInvalid (l))
5684 return globSet_undefined;
5687 if (l->ukind != KFCN)
5689 if (l->ukind != KITER && l->ukind != KENDITER)
5691 if (l->ukind == KVAR)
5693 llbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
5695 ekind_unparse (l->ukind)));
5699 llbug (message ("Bad call to uentry_getGlobs: %q (%s)",
5701 ekind_unparse (l->ukind)));
5704 return globSet_undefined;
5707 return l->info->fcn->globs;
5710 /*@observer@*/ sRefSet
5711 uentry_getMods (uentry l)
5713 llassert (uentry_isValid (l));
5715 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5717 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5718 return sRefSet_undefined;
5721 return l->info->fcn->mods;
5725 uentry_getKind (uentry e)
5727 llassert (uentry_isValid (e));
5732 /*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5734 llassert (uentry_isEitherConstant (e));
5735 return (sRef_getValue (e->sref));
5738 /*@observer@*/ uentryList
5739 uentry_getParams (uentry l)
5741 if (uentry_isInvalid (l)) return uentryList_undefined;
5748 ctype ct = l->utype;
5750 if (ctype_isFunction (ct))
5752 return (ctype_argsFunction (ct));
5756 return uentryList_undefined;
5761 ctype ct = l->utype;
5763 llassert (ctype_isFunction (ct));
5764 return (ctype_argsFunction (ct));
5771 /*@observer@*/ cstring
5772 uentry_rawName (uentry e)
5774 if (uentry_isValid (e))
5780 return cstring_undefined;
5785 uentry_getOptName (uentry e)
5787 cstring s = uentry_getName (e);
5789 if (cstring_isDefined (s))
5791 s = cstring_appendChar (s, ' ');
5798 uentry_getName (uentry e)
5800 cstring ret = cstring_undefined;
5802 if (uentry_isValid (e))
5804 if (uentry_isAnyTag (e))
5806 ret = fixTagName (e->uname);
5808 else if (uentry_isAnyParam (e))
5810 ret = cstring_copy (fixParamName (e->uname));
5814 ret = cstring_copy (e->uname);
5821 cstring uentry_observeRealName (uentry e)
5823 cstring ret = cstring_undefined;
5825 if (uentry_isValid (e))
5827 if (uentry_isAnyTag (e))
5829 if (isFakeTag (e->uname))
5831 ret = cstring_undefined;
5835 ret = plainTagName (e->uname);
5838 else if (uentry_isAnyParam (e))
5840 ret = fixParamName (e->uname);
5851 cstring uentry_getRealName (uentry e)
5853 if (uentry_isValid (e))
5855 if (uentry_isAnyTag (e))
5857 return (cstring_undefined);
5864 return cstring_undefined;
5867 ctype uentry_getType (uentry e)
5869 if (uentry_isValid (e))
5875 return ctype_unknown;
5879 fileloc uentry_whereLast (uentry e)
5883 if (uentry_isInvalid (e))
5885 return fileloc_undefined;
5888 loc = e->whereDefined;
5890 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5895 loc = uentry_whereDeclared (e);
5897 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5902 loc = uentry_whereSpecified (e);
5906 fileloc uentry_whereEither (uentry e)
5908 if (uentry_isInvalid (e)) return fileloc_undefined;
5910 if (fileloc_isDefined (e->whereDefined)
5911 && !fileloc_isExternal (e->whereDefined))
5913 return e->whereDefined;
5915 else if (fileloc_isDefined (e->whereDeclared))
5917 return e->whereDeclared;
5921 return e->whereSpecified;
5925 fileloc uentry_whereSpecified (uentry e)
5927 if (uentry_isInvalid (e)) return fileloc_undefined;
5929 return (e->whereSpecified);
5932 fileloc uentry_whereDefined (uentry e)
5934 if (uentry_isInvalid (e)) return fileloc_undefined;
5936 return (e->whereDefined);
5939 fileloc uentry_whereDeclared (uentry e)
5941 if (uentry_isInvalid (e)) return fileloc_undefined;
5943 return (e->whereDeclared);
5946 /*@observer@*/ fileloc
5947 uentry_whereEarliest (uentry e)
5949 if (uentry_isInvalid (e)) return fileloc_undefined;
5951 if (fileloc_isDefined (e->whereSpecified))
5953 return (e->whereSpecified);
5955 else if (fileloc_isDefined (e->whereDeclared))
5957 return (e->whereDeclared);
5961 return e->whereDefined;
5966 uentry_setFunctionDefined (uentry e, fileloc loc)
5968 if (uentry_isValid (e))
5970 llassert (uentry_isFunction (e));
5972 if (fileloc_isUndefined (e->whereDeclared))
5974 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
5977 if (!fileloc_isDefined (e->whereDefined))
5979 e->whereDefined = fileloc_update (e->whereDefined, loc);
5985 uentry_setDeclDef (uentry e, fileloc f)
5987 uentry_setDeclared (e, f);
5989 if (!uentry_isFunction (e)
5990 && !(uentry_isVariable (e) && uentry_isExtern (e)))
5992 uentry_setDefined (e, f);
5997 uentry_setDeclaredForce (uentry e, fileloc f)
5999 llassert (uentry_isValid (e));
6000 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6004 uentry_setDeclaredForceOnly (uentry e, fileloc f)
6006 llassert (uentry_isValid (e));
6007 fileloc_free (e->whereDeclared);
6008 e->whereDeclared = f;
6012 uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
6016 llassert (uentry_isValid (e));
6017 oldloc = e->whereDeclared;
6019 if (fileloc_isDefined (oldloc))
6021 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6023 e->whereDeclared = f;
6024 fileloc_free (oldloc);
6033 e->whereDeclared = f;
6034 fileloc_free (oldloc);
6039 uentry_setDeclared (uentry e, fileloc f)
6043 llassert (uentry_isValid (e));
6044 oldloc = e->whereDeclared;
6046 if (fileloc_isDefined (oldloc))
6048 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
6050 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6059 e->whereDeclared = fileloc_update (e->whereDeclared, f);
6064 uentry_clearDefined (uentry e)
6066 if (uentry_isValid (e))
6068 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
6073 uentry_setDefined (uentry e, fileloc f)
6077 llassert (uentry_isValid (e));
6078 oldloc = e->whereDefined;
6080 if (fileloc_isDefined (oldloc))
6082 if (fileloc_isLib (oldloc)
6083 || fileloc_isImport (oldloc)
6084 || fileloc_isBuiltin (oldloc)
6085 || fileloc_isPreproc (oldloc))
6087 e->whereDefined = fileloc_update (e->whereDefined, f);
6091 if (fileloc_equal (oldloc, f) || context_processingMacros ())
6097 if (optgenerror (FLG_REDEF,
6098 message ("%s %q redefined",
6099 ekind_capName (e->ukind),
6100 uentry_getName (e)),
6103 llgenindentmsg (message ("Previous definition of %q",
6104 uentry_getName (e)),
6112 e->whereDefined = fileloc_update (e->whereDefined, f);
6117 uentry_isCodeDefined (uentry e)
6119 llassert (uentry_isValid (e));
6121 return (fileloc_isDefined (e->whereDefined));
6125 uentry_isDeclared (uentry e)
6127 if (uentry_isValid (e))
6129 return (fileloc_isDefined (e->whereDeclared));
6135 sRef uentry_getSref (uentry e)
6137 /* not true, used for functions too (but shouldn't be? */
6138 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
6140 if (uentry_isInvalid (e)) return sRef_undefined;
6145 sRef uentry_getOrigSref (uentry e)
6148 if (uentry_isValid (e))
6150 if (uentry_isVariable (e))
6152 return e->info->var->origsref;
6156 sRef sr = sRef_copy (uentry_getSref (e));
6158 sRef_resetState (sr);
6159 sRef_clearDerived (sr);
6165 return sRef_undefined;
6169 if (uentry_isValid (e))
6171 sRef sr = sRef_copy (uentry_getSref (e));
6173 sRef_resetState (sr);
6174 sRef_clearDerived (sr);
6176 if (uentry_isVariable (e))
6178 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
6179 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
6186 return sRef_undefined;
6191 ** requires: uentry e is not in a hashed symbol table
6195 uentry_setName (uentry e, /*@only@*/ cstring n)
6197 llassert (uentry_isValid (e));
6199 cstring_free (e->uname);
6204 uentry_setType (uentry e, ctype t)
6206 if (uentry_isValid (e))
6209 sRef_setType (e->sref, t);
6214 uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
6217 ctype rettype = ctype_unknown;
6219 llassert (uentry_isValid (ue));
6221 uentry_convertVarFunction (ue);
6222 llassert (uentry_isFunction (ue));
6224 rct = ctype_realType (ue->utype);
6226 if (ctype_isFunction (rct))
6228 rettype = ctype_getReturnType (rct);
6231 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
6235 uentry_setRefParam (uentry e)
6237 if (!uentry_isVar (e))
6239 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6243 if (e->info->var->kind == VKSEFPARAM)
6245 e->info->var->kind = VKREFSEFPARAM;
6247 else if (e->info->var->kind == VKSEFRETPARAM)
6249 e->info->var->kind = VKREFSEFRETPARAM;
6251 else if (e->info->var->kind == VKYIELDPARAM)
6253 e->info->var->kind = VKREFYIELDPARAM;
6257 e->info->var->kind = VKREFPARAM;
6263 uentry_setParam (uentry e)
6265 if (!uentry_isVar (e))
6267 if (uentry_isElipsisMarker (e))
6273 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6280 if (e->info->var->kind == VKYIELDPARAM
6281 || e->info->var->kind == VKSEFPARAM
6282 || e->info->var->kind == VKSEFRETPARAM)
6288 e->info->var->kind = VKPARAM;
6292 e->uname = makeParam (e->uname);
6293 cstring_free (oldname);
6298 uentry_setSref (uentry e, sRef s)
6300 if (uentry_isValid (e))
6302 if (sRef_isValid (e->sref))
6304 sRef_mergeStateQuietReverse (e->sref, s);
6308 e->sref = sRef_saveCopy (s);
6314 uentry_getAbstractType (uentry e)
6316 llassert (uentry_isDatatype (e));
6319 ** This assertion removed.
6320 ** Okay to have undefined type, for system types
6322 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
6323 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
6328 if (ctype_isUndefined (e->info->datatype->type))
6330 return ctype_unknown;
6334 ** Sadly, a kludge...
6337 if (ctype_isUserBool (e->info->datatype->type)) {
6341 return e->info->datatype->type;
6344 ctype uentry_getRealType (uentry e)
6347 typeId uid = USYMIDINVALID;
6349 if (uentry_isInvalid (e))
6351 return ctype_unknown;
6354 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6356 if (uentry_isAnyTag (e))
6361 if (uentry_isAbstractType (e))
6363 ct = uentry_getAbstractType (e);
6365 if (ctype_isManifestBool (ct)) {
6369 llassert (ctype_isUA (ct));
6371 uid = ctype_typeId (ct);
6373 if (!context_hasAccess (uid))
6379 ct = uentry_getType (e);
6381 /* if (ctype_isUserBool (ct)) return ct; */
6383 if (ctype_isManifestBool (ct)) {
6387 if (ctype_isUA (ct))
6389 usymId iid = ctype_typeId (ct);
6391 if (usymId_equal (iid, uid))
6393 llcontbug (message ("uentry_getRealType: recursive type! %s",
6394 ctype_unparse (ct)));
6399 /* evs 2000-07-25: possible infinite recursion ? */
6400 uentry ue2 = usymtab_getTypeEntry (iid);
6404 llcontbug (message ("Bad recursion: %q", uentry_unparseFull (e)));
6405 return ctype_unknown;
6408 return uentry_getRealType (ue2);
6417 ctype uentry_getForceRealType (uentry e)
6420 typeId uid = USYMIDINVALID;
6422 if (uentry_isInvalid (e))
6424 return ctype_unknown;
6427 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6429 if (uentry_isAnyTag (e))
6434 if (uentry_isAbstractType (e))
6436 ct = uentry_getAbstractType (e);
6437 llassert (ctype_isUA (ct));
6439 uid = ctype_typeId (ct);
6440 /* no check for access! */
6443 ct = uentry_getType (e);
6445 /* evs 2000-07-25 */
6446 /* if (ctype_isUserBool (ct)) return ct; */
6448 if (ctype_isManifestBool (ct)) {
6452 if (ctype_isUA (ct))
6454 usymId iid = ctype_typeId (ct);
6456 if (usymId_equal (iid, uid))
6458 llcontbug (message ("uentry_getRealType: recursive type! %s",
6459 ctype_unparse (ct)));
6464 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
6473 uentry uentry_nameCopy (cstring name, uentry e)
6475 uentry enew = uentry_alloc ();
6477 llassert (uentry_isValid (e));
6479 /* enew->shallowCopy = FALSE; */
6480 enew->ukind = e->ukind;
6482 enew->utype = e->utype;
6483 enew->whereSpecified = fileloc_copy (e->whereSpecified);
6484 enew->whereDefined = fileloc_copy (e->whereDefined);
6485 enew->whereDeclared = fileloc_copy (e->whereDeclared);
6486 enew->sref = sRef_copy (e->sref);
6487 enew->used = e->used;
6489 enew->isPrivate = e->isPrivate;
6490 enew->hasNameError = FALSE;
6492 enew->uses = filelocList_new ();
6493 enew->warn = warnClause_undefined;
6495 enew->storageclass = e->storageclass;
6496 enew->info = uinfo_copy (e->info, e->ukind);
6502 uentry_setDatatype (uentry e, usymId uid)
6504 llassert (uentry_isDatatype (e));
6506 if (uentry_isAbstractType (e))
6508 e->info->datatype->type = ctype_createAbstract (uid);
6512 e->info->datatype->type = ctype_createUser (uid);
6517 uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
6518 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
6521 llassert (uentry_isValid (e));
6523 if (fileloc_isSpec (f) || fileloc_isImport (f))
6525 e->whereSpecified = f;
6526 e->whereDeclared = fileloc_undefined;
6527 e->whereDefined = fileloc_undefined;
6531 e->whereSpecified = fileloc_undefined;
6532 e->whereDeclared = f;
6533 e->whereDefined = fileloc_undefined;
6536 llassert (fileloc_storable (f));
6540 ucinfo_free (/*@only@*/ ucinfo u)
6546 uvinfo_free (/*@only@*/ uvinfo u)
6548 /*drl7x added 6/29/01 */
6549 free (u->bufinfo); /* evans - 2001-07-19 fixed this bug */
6554 udinfo_free (/*@only@*/ udinfo u)
6560 ufinfo_free (/*@only@*/ ufinfo u)
6562 globSet_free (u->globs);
6563 sRefSet_free (u->mods);
6564 stateClauseList_free (u->specclauses);
6569 uiinfo_free (/*@only@*/ uiinfo u)
6575 ueinfo_free (/*@only@*/ ueinfo u)
6580 static /*@only@*/ ucinfo
6581 ucinfo_copy (ucinfo u)
6583 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
6584 ret->access = u->access;
6588 static /*@only@*/ uvinfo
6589 uvinfo_copy (uvinfo u)
6591 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
6593 ret->kind = u->kind;
6594 ret->nullstate = u->nullstate;
6595 ret->defstate = u->defstate;
6596 ret->checked = u->checked;
6598 /*@i523 ret->origsref = sRef_copy (u->origsref); */
6600 /* drl added 07-02-001 */
6601 /* copy null terminated information */
6603 if (u->bufinfo != NULL)
6605 ret->bufinfo = (bbufinfo) dmalloc (sizeof( * u->bufinfo ) );
6606 ret->bufinfo->bufstate = u->bufinfo->bufstate;
6607 ret->bufinfo->size = u->bufinfo->size;
6608 ret->bufinfo->len = u->bufinfo->len;
6613 ret->bufinfo = NULL;
6619 static /*@only@*/ udinfo
6620 udinfo_copy (udinfo u)
6622 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6626 ret->type = u->type;
6631 static /*@only@*/ ufinfo
6632 ufinfo_copy (ufinfo u)
6634 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6636 ret->hasGlobs = u->hasGlobs;
6637 ret->hasMods = u->hasMods;
6638 ret->exitCode = u->exitCode;
6639 ret->specialCode = u->specialCode;
6640 ret->nullPred = u->nullPred;
6641 ret->access = u->access;
6642 ret->globs = globSet_newCopy (u->globs);
6643 ret->mods = sRefSet_newCopy (u->mods);
6644 ret->defparams = u->defparams;
6645 ret->specclauses = stateClauseList_copy (u->specclauses);
6647 ret->preconditions = functionConstraint_copy (u->preconditions);
6648 ret->postconditions = functionConstraint_copy (u->postconditions);
6653 static /*@only@*/ uiinfo
6654 uiinfo_copy (uiinfo u)
6656 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6658 ret->access = u->access;
6659 ret->globs = globSet_newCopy (u->globs);
6660 ret->mods = sRefSet_newCopy (u->mods);
6665 static /*@only@*/ ueinfo
6666 ueinfo_copy (ueinfo u)
6668 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6670 ret->access = u->access;
6675 uinfo_free (uinfo u, ekind kind)
6680 case KCONST: ucinfo_free (u->uconst); break;
6681 case KVAR: uvinfo_free (u->var); break;
6685 case KDATATYPE: udinfo_free (u->datatype); break;
6686 case KFCN: ufinfo_free (u->fcn); break;
6687 case KITER: uiinfo_free (u->iter); break;
6688 case KENDITER: ueinfo_free (u->enditer); break;
6689 case KELIPSMARKER: break;
6690 case KINVALID: break;
6696 static /*@only@*/ /*@null@*/ uinfo
6697 uinfo_copy (uinfo u, ekind kind)
6699 if (kind == KELIPSMARKER || kind == KINVALID)
6705 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6710 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6711 case KVAR: ret->var = uvinfo_copy (u->var); break;
6715 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6716 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6717 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6718 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6726 uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6728 filelocList_free (e->uses);
6729 cstring_free (e->uname);
6731 uinfo_free (e->info, e->ukind);
6733 fileloc_free (e->whereSpecified);
6734 fileloc_free (e->whereDefined);
6735 fileloc_free (e->whereDeclared);
6737 warnClause_free (e->warn);
6743 extern void uentry_markOwned (/*@owned@*/ uentry u)
6745 sfreeEventually (u);
6749 uentry_free (/*@only@*/ uentry e)
6751 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6753 uentry_reallyFree (e);
6758 ** For uentry's in the global or file scope
6762 uentry_freeComplete (/*@only@*/ uentry e)
6764 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6766 DPRINTF (("Free complete: %s", sRef_unparseFull (e->sref)));
6767 /*@i@*/ sRef_free (e->sref);
6768 e->sref = sRef_undefined;
6769 uentry_reallyFree (e);
6774 ** requires old->kind != new->kind, old->uname = new->uname
6778 KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6780 llassert (uentry_isValid (old));
6781 llassert (uentry_isValid (unew));
6783 if (uentry_isEitherConstant (unew)
6784 && (fileloc_isPreproc (uentry_whereDeclared (old))
6785 || ctype_isUnknown (old->utype))
6786 && !uentry_isSpecified (old))
6794 if (!uentry_isDeclared (old))
6796 if (uentry_isSpecified (old))
6798 if (uentry_isSpecified (unew))
6800 llbuglit ("Respecification!");
6802 else if (uentry_isDeclared (unew))
6806 message ("%s %q inconsistently declared as %s: %t",
6807 ekind_capName (old->ukind),
6808 uentry_getName (unew),
6809 ekind_unparseLong (unew->ukind),
6811 uentry_whereDeclared (unew)))
6813 uentry_showWhereLast (old);
6825 message ("%s %q inconsistently declared as %s: %t",
6826 ekind_capName (old->ukind),
6827 uentry_getName (unew),
6828 ekind_unparseLong (unew->ukind),
6830 uentry_whereDeclared (unew)))
6832 uentry_showWhereLast (old);
6838 llassert (uentry_isDeclared (unew));
6842 message ("%s %q inconsistently redeclared as %s",
6843 ekind_capName (old->ukind),
6844 uentry_getName (unew),
6845 ekind_unparseLong (unew->ukind)),
6846 uentry_whereDeclared (unew)))
6848 uentry_showWhereLast (old);
6854 uentry_updateInto (old, unew);
6858 ** def is the definition of spec, modifies spec
6860 ** reports any inconsistencies
6861 ** returns the summary of all available information
6862 ** if spec and def are inconsistent, def is returned
6866 uentry_showWhereLast (uentry spec)
6868 if (uentry_isValid (spec))
6870 if (fileloc_isDefined (spec->whereDefined)
6871 && !fileloc_isLib (spec->whereDefined)
6872 && !fileloc_isPreproc (spec->whereDefined))
6874 llgenindentmsg (message ("Previous definition of %q: %t",
6875 uentry_getName (spec),
6876 uentry_getType (spec)),
6877 uentry_whereDefined (spec));
6879 else if (uentry_isDeclared (spec))
6881 llgenindentmsg (message ("Previous declaration of %q: %t",
6882 uentry_getName (spec),
6883 uentry_getType (spec)),
6884 uentry_whereDeclared (spec));
6886 else if (uentry_isSpecified (spec))
6888 if (uentry_hasName (spec))
6890 llgenindentmsg (message ("Specification of %q: %t",
6891 uentry_getName (spec),
6892 uentry_getType (spec)),
6893 uentry_whereSpecified (spec));
6897 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
6898 uentry_whereSpecified (spec));
6903 /* nothing to show */
6909 uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
6911 fileloc loc = uentry_whereDefined (ce);
6913 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6915 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
6919 loc = uentry_whereSpecified (ce);
6921 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6923 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
6928 void uentry_showWhereLastExtra (uentry spec, cstring extra)
6930 if (uentry_isDeclared (spec))
6932 llgenindentmsg (message ("Previous declaration of %q: %q",
6933 uentry_getName (spec), extra),
6934 uentry_whereDeclared (spec));
6936 else if (uentry_isSpecified (spec))
6938 llgenindentmsg (message ("Specification of %q: %q",
6939 uentry_getName (spec), extra),
6940 uentry_whereSpecified (spec));
6944 cstring_free (extra);
6949 uentry_showWhereDeclared (uentry spec)
6951 if (uentry_isDeclared (spec))
6953 if (uentry_hasName (spec))
6955 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6956 uentry_whereDeclared (spec));
6960 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6963 else if (uentry_isSpecified (spec))
6965 if (uentry_hasName (spec))
6967 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6968 uentry_whereSpecified (spec));
6972 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
6977 /* nothing to show */
6983 uentry_showWhereAny (uentry spec)
6985 if (uentry_isDeclared (spec))
6987 if (uentry_hasName (spec))
6989 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6990 uentry_whereDeclared (spec));
6994 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6997 else if (uentry_isSpecified (spec))
6999 if (uentry_hasName (spec))
7001 llgenindentmsg (message ("Specification of %q",
7002 uentry_getName (spec)),
7003 uentry_whereSpecified (spec));
7007 llgenindentmsg (cstring_makeLiteral ("Specification"),
7008 uentry_whereSpecified (spec));
7011 else if (fileloc_isDefined (uentry_whereDefined (spec)))
7013 if (uentry_hasName (spec))
7015 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
7016 uentry_whereDefined (spec));
7020 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
7025 /* nothing to show */
7030 uentry_showWhereDefined (uentry spec)
7032 if (uentry_isCodeDefined (spec))
7034 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
7035 uentry_whereDefined (spec));
7040 uentry_showWhereLastPlain (uentry spec)
7042 if (uentry_isDeclared (spec))
7044 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
7045 uentry_whereDeclared (spec));
7047 else if (uentry_isSpecified (spec))
7049 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7050 uentry_whereSpecified (spec));
7058 uentry_showWhereLastVal (uentry spec, cstring val)
7060 if (uentry_isDeclared (spec))
7062 llgenindentmsg (message ("Previous declaration of %q: %s",
7063 uentry_getName (spec), val),
7064 uentry_whereDeclared (spec));
7066 else if (uentry_isSpecified (spec))
7068 llgenindentmsg (message ("Specification of %q: %s",
7069 uentry_getName (spec), val),
7070 uentry_whereSpecified (spec));
7078 uentry_showWhereSpecified (uentry spec)
7080 if (uentry_isSpecified (spec))
7082 if (uentry_hasName (spec))
7084 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
7085 uentry_whereSpecified (spec));
7089 llgenindentmsg (cstring_makeLiteral ("Specification"),
7090 uentry_whereSpecified (spec));
7093 else if (uentry_isDeclared (spec))
7095 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
7096 uentry_whereDeclared (spec));
7100 /* nothing to show */
7105 uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
7107 if (uentry_isSpecified (spec))
7109 if (uentry_hasName (spec))
7111 llgenindentmsg (message ("Specification of %q: %q",
7112 uentry_getName (spec), s),
7113 uentry_whereSpecified (spec));
7117 llgenindentmsg (message ("Specification: %q", s),
7118 uentry_whereSpecified (spec));
7121 else if (uentry_isDeclared (spec))
7123 llgenindentmsg (message ("Declaration of %q: %q",
7124 uentry_getName (spec), s),
7125 uentry_whereDeclared (spec));
7129 llgenindentmsg (message ("Previous: %q", s),
7130 uentry_whereLast (spec));
7139 checkStructConformance (uentry old, uentry unew)
7142 uentryList fold, fnew;
7145 ** requires: types of old and new are structs or unions
7148 llassert (uentry_isValid (old));
7149 llassert (uentry_isValid (unew));
7151 oldr = ctype_realType (old->utype);
7152 fold = ctype_getFields (oldr);
7154 newr = ctype_realType (unew->utype);
7155 fnew = ctype_getFields (newr);
7157 if (!uentryList_matchFields (fold, fnew))
7159 if (fileloc_equal (uentry_whereLast (old),
7160 uentry_whereLast (unew)))
7168 message ("%q %q %rdeclared with fields { %q }, %s "
7169 "with fields { %q }",
7170 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
7171 uentry_getName (old),
7172 uentry_isDeclared (old),
7173 uentryList_unparseAbbrev (fnew),
7174 uentry_specOrDefName (old),
7175 uentryList_unparseAbbrev (fold)),
7176 uentry_whereDeclared (unew)))
7178 uentry_showWhereLastPlain (old);
7179 uentryList_showFieldDifference (fold, fnew);
7183 old->utype = unew->utype;
7188 checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7191 ** requires old and new are enums
7194 ctype rold = ctype_realType (old->utype);
7195 ctype rnew = ctype_realType (unew->utype);
7196 enumNameList eold = ctype_elist (rold);
7197 enumNameList enew = ctype_elist (rnew);
7199 if (!enumNameList_match (eold, enew))
7203 message ("Enum %q declared with members { %q } but "
7204 "specified with members { %q }",
7205 uentry_getName (old),
7206 enumNameList_unparse (enew),
7207 enumNameList_unparse (eold)),
7208 uentry_whereDeclared (unew)))
7210 uentry_showWhereSpecified (old);
7211 old->utype = unew->utype;
7217 ** either oldCurrent or newCurrent may be undefined!
7221 paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
7222 uentry unew, uentry newCurrent, ctype newType,
7225 bool hasError = FALSE;
7227 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
7229 if (uentry_hasName (newCurrent))
7231 hasError = optgenerror
7233 message ("Parameter %d, %q, of function %q has inconsistent type: "
7234 "declared %t, %s %t",
7235 paramno + 1, uentry_getName (newCurrent),
7236 uentry_getName (unew),
7237 newType, uentry_specOrDefName (old), oldType),
7238 uentry_whereDeclared (newCurrent));
7242 hasError = optgenerror
7244 message ("Parameter %d of function %q has inconsistent type: "
7245 "declared %t, %s %t",
7246 paramno + 1, uentry_getName (unew),
7247 newType, uentry_specOrDefName (old), oldType),
7248 uentry_whereDeclared (newCurrent));
7250 DPRINTF (("type: %s / %s",
7251 ctype_unparse (newType),
7252 ctype_unparse (ctype_realType (newType))));
7257 if (uentry_isDeclared (unew))
7259 hasError = optgenerror
7261 message ("Parameter %d of function %s has inconsistent type: "
7262 "declared %t, %s %t",
7263 paramno + 1, unew->uname,
7264 newType, uentry_specOrDefName (old), oldType),
7265 uentry_whereDeclared (unew));
7269 hasError = optgenerror
7271 message ("Parameter %d of function %s has inconsistent type: "
7272 "declared %t, %s %t",
7273 paramno + 1, unew->uname,
7274 newType, uentry_specOrDefName (old), oldType),
7275 uentry_whereDeclared (unew));
7281 DPRINTF (("Here: %s / %s",
7282 uentry_unparseFull (oldCurrent),
7283 uentry_unparseFull (newCurrent)));
7285 if (!uentry_isUndefined (oldCurrent))
7287 if (!uentry_isUndefined (newCurrent)
7288 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
7290 uentry_showWhereLast (oldCurrent);
7294 uentry_showWhereLastPlain (old);
7297 uentry_setType (oldCurrent, newType);
7301 uentry_showWhereLastPlain (old);
7307 nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7311 message ("Function %s %rdeclared with %d arg%&, %s with %d",
7313 uentry_isDeclared (old),
7314 uentryList_size (uentry_getParams (unew)),
7315 uentry_specOrDefName (old),
7316 uentryList_size (uentry_getParams (old))),
7317 uentry_whereDeclared (unew)))
7319 uentry_showWhereLastPlain (old);
7324 returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7328 message ("Function %s inconsistently %rdeclared to return %t",
7330 uentry_isDeclared (old),
7331 ctype_getReturnType (unew->utype)),
7332 uentry_whereDeclared (unew)))
7334 uentry_showWhereLastVal (old, ctype_unparse (ctype_getReturnType (old->utype)));
7338 static cstring paramStorageName (uentry ue)
7340 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
7343 static cstring fcnErrName (uentry ue)
7345 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
7348 extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
7350 if (uentry_isVar (ue))
7352 return (checkedName (ue->info->var->checked));
7356 return (cstring_makeLiteralTemp ("<checked invalid>"));
7360 static cstring checkedName (chkind checked)
7364 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
7365 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
7366 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
7367 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
7368 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
7374 void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
7379 if (uentry_isVar (unew))
7381 llassert (uentry_isVar (old));
7383 oldState = old->info->var->nullstate;
7384 newState = unew->info->var->nullstate;
7388 oldState = sRef_getNullState (old->sref);
7389 newState = sRef_getNullState (unew->sref);
7392 if (oldState == NS_ABSNULL)
7394 if (uentry_isVar (old))
7396 old->info->var->nullstate = newState;
7399 sRef_mergeNullState (old->sref, newState);
7401 else if (newState == NS_UNKNOWN)
7403 if (completeConform && newState != oldState
7404 && uentry_isReallySpecified (old))
7408 message ("%s %q specified as %s, but declared without %s qualifier",
7409 ekind_capName (unew->ukind),
7410 uentry_getName (unew),
7411 nstate_unparse (oldState),
7412 nstate_unparse (oldState)),
7413 uentry_whereDeclared (unew)))
7415 uentry_showWhereSpecified (old);
7419 if (uentry_isVar (unew))
7421 unew->info->var->nullstate = oldState;
7424 sRef_mergeNullState (unew->sref, oldState);
7426 else if (newState == NS_POSNULL)
7428 if (oldState == NS_MNOTNULL
7429 && (ctype_isUA (unew->utype)
7430 || (uentry_isFunction (unew)
7431 && ctype_isUA (ctype_getReturnType (unew->utype)))))
7433 if (uentry_isVar (unew))
7435 unew->info->var->nullstate = oldState;
7438 sRef_mergeNullState (unew->sref, oldState);
7442 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
7443 || oldState == NS_UNKNOWN)
7450 ("%s %q inconsistently %rdeclared %s possibly null storage, "
7452 uentry_ekindName (unew),
7453 uentry_getName (unew),
7454 uentry_isDeclared (old),
7456 uentry_specOrDefName (old),
7457 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
7458 uentry_whereDeclared (unew)))
7460 uentry_showWhereSpecified (old);
7465 if (uentry_isVar (old))
7467 old->info->var->nullstate = newState;
7470 sRef_mergeNullState (old->sref, newState);
7473 else if (newState == NS_MNOTNULL)
7475 if (oldState != NS_MNOTNULL)
7481 message ("%s %q inconsistently %rdeclared %s notnull storage, "
7482 "%s without notnull qualifier",
7483 uentry_ekindName (unew),
7484 uentry_getName (unew),
7485 uentry_isDeclared (old),
7487 uentry_specOrDefName (old)),
7488 uentry_whereDeclared (unew)))
7490 uentry_showWhereSpecified (old);
7494 if (uentry_isVar (old))
7496 old->info->var->nullstate = newState;
7499 sRef_mergeNullState (old->sref, newState);
7504 if (uentry_isVar (unew))
7506 unew->info->var->nullstate = oldState;
7509 sRef_mergeNullState (unew->sref, oldState);
7514 void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7515 bool mustConform, bool completeConform)
7521 if (uentry_isVar (old) && uentry_isVar (unew))
7523 oldState = old->info->var->defstate;
7524 newState = unew->info->var->defstate;
7529 oldState = sRef_getDefState (old->sref);
7530 newState = sRef_getDefState (unew->sref);
7533 if (newState != oldState
7534 && newState != SS_UNKNOWN
7535 && newState != SS_DEFINED)
7541 message ("%s %q inconsistently %rdeclared %s %s %s, "
7543 uentry_ekindName (unew),
7544 uentry_getName (unew),
7545 uentry_isDeclared (old),
7547 sstate_unparse (newState),
7548 paramStorageName (unew),
7549 uentry_specOrDefName (old),
7551 sstate_unparse (oldState),
7552 paramStorageName (unew)),
7553 uentry_whereDeclared (unew)))
7555 uentry_showWhereSpecified (old);
7559 if (vars) old->info->var->defstate = newState;
7560 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
7565 && (newState != oldState) && (oldState != SS_DEFINED)
7566 && uentry_isReallySpecified (old))
7570 message ("%s %q specified as %s, but declared without %s qualifier",
7571 ekind_capName (unew->ukind),
7572 uentry_getName (unew),
7573 sstate_unparse (oldState),
7574 sstate_unparse (oldState)),
7575 uentry_whereDeclared (unew)))
7577 uentry_showWhereSpecified (old);
7581 if (vars) unew->info->var->defstate = oldState;
7582 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
7587 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7588 bool mustConform, bool completeConform)
7593 oldKind = sRef_getAliasKind (old->sref);
7594 newKind = sRef_getAliasKind (unew->sref);
7596 if (alkind_isImplicit (newKind)
7597 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
7599 if (completeConform && !alkind_equal (newKind, oldKind)
7600 && uentry_isReallySpecified (old))
7604 message ("%s %q specified as %s, but declared without "
7605 "explicit alias qualifier",
7606 ekind_capName (unew->ukind),
7607 uentry_getName (unew),
7608 alkind_unparse (oldKind)),
7609 uentry_whereDeclared (unew)))
7611 uentry_showWhereSpecified (old);
7616 ** This really shouldn't be necessary, but it is!
7617 ** Function params (?) use new here.
7620 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7624 if (alkind_isKnown (newKind))
7626 if (!alkind_equal (oldKind, newKind))
7628 if (alkind_isKnown (oldKind))
7633 message ("%s %q inconsistently %rdeclared %s %s storage, "
7635 uentry_ekindName (unew),
7636 uentry_getName (unew),
7637 uentry_isDeclared (old),
7639 alkind_unparse (newKind),
7640 uentry_specOrDefName (old),
7641 alkind_unparse (oldKind)),
7642 uentry_whereDeclared (unew)))
7644 uentry_showWhereSpecified (old);
7646 DPRINTF (("Old: %s", sRef_unparseFull (old->sref)));
7647 DPRINTF (("New: %s", sRef_unparseFull (unew->sref)));
7648 sRef_setAliasKind (old->sref, AK_ERROR,
7649 uentry_whereDeclared (unew));
7653 sRef_setAliasKind (old->sref, newKind,
7654 uentry_whereDeclared (unew));
7659 if (!(alkind_isImplicit (newKind)))
7662 !uentry_isFunction (unew) &&
7665 message ("%s %q inconsistently %rdeclared %s %s storage, "
7666 "implicitly %s as temp storage",
7667 uentry_ekindName (unew),
7668 uentry_getName (unew),
7669 uentry_isDeclared (old),
7671 alkind_unparse (newKind),
7672 uentry_specOrDefName (old)),
7673 uentry_whereDeclared (unew)))
7675 uentry_showWhereSpecified (old);
7679 sRef_setAliasKind (old->sref, newKind,
7680 uentry_whereDeclared (unew));
7682 else /* newKind is temp or refcounted */
7689 else /* newKind unknown */
7696 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7697 bool mustConform, bool completeConform)
7702 oldKind = sRef_getExKind (old->sref);
7703 newKind = sRef_getExKind (unew->sref);
7705 if (exkind_isKnown (newKind))
7707 if (oldKind != newKind)
7709 if (exkind_isKnown (oldKind))
7714 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7715 uentry_ekindName (unew),
7716 uentry_getName (unew),
7717 uentry_isDeclared (old),
7719 exkind_unparse (newKind),
7720 uentry_specOrDefName (old),
7721 exkind_unparse (oldKind)),
7722 uentry_whereDeclared (unew)))
7724 uentry_showWhereSpecified (old);
7727 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7734 message ("%s %q inconsistently %rdeclared %s %s, "
7735 "implicitly %s without exposure qualifier",
7736 uentry_ekindName (unew),
7737 uentry_getName (unew),
7738 uentry_isDeclared (old),
7740 exkind_unparse (newKind),
7741 uentry_specOrDefName (old)),
7742 uentry_whereDeclared (unew)))
7744 uentry_showWhereSpecified (old);
7747 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7753 if (completeConform && exkind_isKnown (oldKind)
7754 && uentry_isReallySpecified (old))
7758 message ("%s %q specified as %s, but declared without "
7759 "exposure qualifier",
7760 ekind_capName (unew->ukind),
7761 uentry_getName (unew),
7762 exkind_unparse (oldKind)),
7763 uentry_whereDeclared (unew)))
7765 uentry_showWhereSpecified (old);
7769 /* yes, this is necessary! (if its a param) */
7770 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7775 checkMetaState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7776 bool mustConform, /*@unused@*/ bool completeConform)
7778 valueTable newvals = sRef_getValueTable (unew->sref);
7780 if (valueTable_isDefined (newvals))
7782 DPRINTF (("Check meta state: %s -> %s",
7783 uentry_unparseFull (old),
7784 uentry_unparseFull (unew)));
7786 DPRINTF (("Check meta state refs: %s -> %s",
7787 sRef_unparseFull (old->sref),
7788 sRef_unparseFull (unew->sref)));
7790 DPRINTF (("Value table: %s", valueTable_unparse (newvals)));
7793 ** Copy the new values into the old ref
7796 valueTable_elements (newvals, key, newval)
7798 metaStateInfo msinfo = context_lookupMetaStateInfo (key);
7799 stateValue oldval = sRef_getMetaStateValue (old->sref, key);
7801 llassert (metaStateInfo_isDefined (msinfo));
7803 if (stateValue_isUndefined (oldval))
7805 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7809 if (stateValue_isError (oldval))
7811 if (!stateValue_isError (newval))
7813 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7817 ; /* No change necessary. */
7822 if (stateValue_getValue (newval) != stateValue_getValue (oldval))
7824 if (fileloc_isXHFile (uentry_whereDeclared (unew)))
7830 if (!stateValue_isError (newval)
7831 && !stateValue_isImplicit (newval))
7833 if (uentry_hasName (unew)
7834 || !sRef_isParam (uentry_getSref (unew)))
7839 message ("%s %q inconsistently %rdeclared %s %q, %s as %q",
7840 uentry_ekindName (unew),
7841 uentry_getName (unew),
7842 uentry_isDeclared (old),
7844 stateValue_unparseValue (newval, msinfo),
7845 uentry_specOrDefName (old),
7846 stateValue_unparseValue (oldval, msinfo)),
7847 uentry_whereDeclared (unew)))
7849 uentry_showWhereSpecified (old);
7857 message ("%s %d inconsistently %rdeclared %s %q, %s as %q",
7858 uentry_ekindName (unew),
7859 sRef_getParam (uentry_getSref (unew)),
7860 uentry_isDeclared (old),
7862 stateValue_unparseValue (newval, msinfo),
7863 uentry_specOrDefName (old),
7864 stateValue_unparseValue (oldval, msinfo)),
7865 uentry_whereDeclared (unew)))
7867 uentry_showWhereSpecified (old);
7873 DPRINTF (("Updating!"));
7874 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7878 DPRINTF (("Values match"));
7882 } end_valueTable_elements ;
7887 uentry_checkStateConformance (/*@notnull@*/ uentry old,
7888 /*@notnull@*/ uentry unew,
7889 bool mustConform, bool completeConform)
7891 checkDefState (old, unew, mustConform, completeConform);
7892 checkNullState (old, unew, mustConform, completeConform);
7893 checkAliasState (old, unew, mustConform, completeConform);
7894 checkExpState (old, unew, mustConform, completeConform);
7895 checkMetaState (old, unew, mustConform, completeConform);
7897 sRef_storeState (old->sref);
7898 sRef_storeState (unew->sref);
7902 checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
7904 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
7909 llassert (uentry_isVar (old));
7910 llassert (uentry_isVar (unew));
7912 if (cstring_isEmpty (old->uname))
7914 cstring_free (old->uname);
7915 old->uname = cstring_copy (unew->uname);
7918 if (unew->info->var->kind == VKRETPARAM
7919 || unew->info->var->kind == VKSEFRETPARAM)
7921 if (old->info->var->kind != VKRETPARAM
7922 && old->info->var->kind != VKSEFRETPARAM)
7926 message ("Parameter %q inconsistently %rdeclared as "
7927 "returned parameter",
7928 uentry_getName (unew),
7929 uentry_isDeclared (old)),
7930 uentry_whereDeclared (unew)))
7932 uentry_showWhereSpecified (old);
7933 old->info->var->kind = unew->info->var->kind;
7939 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
7941 if (old->info->var->kind != VKSEFPARAM
7942 && old->info->var->kind != VKSEFRETPARAM)
7946 message ("Parameter %qinconsistently %rdeclared as "
7948 uentry_getOptName (unew),
7949 uentry_isDeclared (old)),
7950 uentry_whereDeclared (unew)))
7952 uentry_showWhereSpecified (old);
7953 old->info->var->kind = unew->info->var->kind;
7958 if (old->info->var->kind == VKSPEC)
7960 old->info->var->kind = unew->info->var->kind;
7964 unew->info->var->kind = old->info->var->kind;
7967 if (unew->info->var->checked != CH_UNKNOWN
7968 && unew->info->var->checked != old->info->var->checked)
7970 if (old->info->var->checked == CH_UNKNOWN
7971 && !fileloc_isUser (uentry_whereLast (old)))
7979 message ("Variable %q inconsistently %rdeclared as "
7980 "%s parameter (was %s)",
7981 uentry_getName (unew),
7982 uentry_isDeclared (old),
7983 checkedName (unew->info->var->checked),
7984 checkedName (old->info->var->checked)),
7985 uentry_whereDeclared (unew)))
7987 uentry_showWhereSpecified (old);
7991 old->info->var->checked = unew->info->var->checked;
7996 && (old->info->var->checked != CH_UNKNOWN)
7997 && uentry_isReallySpecified (old))
8001 message ("%s %q specified as %s, but declared without %s qualifier",
8002 ekind_capName (unew->ukind),
8003 uentry_getName (unew),
8004 checkedName (old->info->var->checked),
8005 checkedName (old->info->var->checked)),
8006 uentry_whereDeclared (unew)))
8008 uentry_showWhereSpecified (old);
8012 unew->info->var->checked = old->info->var->checked;
8015 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8018 void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
8020 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
8025 llassert (uentry_isVar (u1));
8026 llassert (uentry_isVar (u2));
8028 if (u1->info->var->kind != u2->info->var->kind) {
8029 if (u1->info->var->kind == VKSEFRETPARAM) {
8030 if (u2->info->var->kind == VKRETPARAM) {
8033 message ("Function types are inconsistent. Parameter %d is "
8034 "sef parameter, but non-sef parameter in "
8035 "assigned function: %s",
8036 paramno, exprNode_unparse (e)),
8038 } else if (u2->info->var->kind == VKSEFPARAM) {
8041 message ("Function types are inconsistent. Parameter %d is "
8042 "returns parameter, but non-returns parameter in "
8043 "assigned function: %s",
8044 paramno, exprNode_unparse (e)),
8049 message ("Function types are inconsistent. Parameter %d is "
8050 "sef returns parameter, but non-sef returns parameter in "
8051 "assigned function: %s",
8052 paramno, exprNode_unparse (e)),
8055 } else if (u1->info->var->kind == VKRETPARAM) {
8058 message ("Function types are inconsistent. Parameter %d is "
8059 "returns parameter, but non-returns parameter in "
8060 "assigned function: %s",
8061 paramno, exprNode_unparse (e)),
8063 } else if (u1->info->var->kind == VKSEFPARAM) {
8066 message ("Function types are inconsistent. Parameter %d is "
8067 "sef parameter, but non-sef parameter in "
8068 "assigned function: %s",
8069 paramno, exprNode_unparse (e)),
8072 if (u2->info->var->kind == VKSEFRETPARAM) {
8075 message ("Function types are inconsistent. Parameter %d is "
8076 "normal parameter, but sef returns parameter in "
8077 "assigned function: %s",
8078 paramno, exprNode_unparse (e)),
8080 } else if (u2->info->var->kind == VKSEFPARAM) {
8083 message ("Function types are inconsistent. Parameter %d is "
8084 "normal parameter, but sef parameter in "
8085 "assigned function: %s",
8086 paramno, exprNode_unparse (e)),
8088 } else if (u2->info->var->kind == VKRETPARAM) {
8091 message ("Function types are inconsistent. Parameter %d is "
8092 "normal parameter, but returns parameter in "
8093 "assigned function: %s",
8094 paramno, exprNode_unparse (e)),
8102 if (u1->info->var->defstate != u2->info->var->defstate)
8106 message ("Function types are inconsistent. Parameter %d is "
8107 "%s, but %s in assigned function: %s",
8109 sstate_unparse (u1->info->var->defstate),
8110 sstate_unparse (u2->info->var->defstate),
8111 exprNode_unparse (e)),
8115 if (u1->info->var->nullstate != u2->info->var->nullstate)
8119 message ("Function types are inconsistent. Parameter %d is "
8120 "%s, but %s in assigned function: %s",
8122 nstate_unparse (u1->info->var->nullstate),
8123 nstate_unparse (u2->info->var->nullstate),
8124 exprNode_unparse (e)),
8128 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
8132 message ("Function types are inconsistent. Parameter %d is "
8133 "%s, but %s in assigned function: %s",
8135 alkind_unparse (sRef_getAliasKind (u1->sref)),
8136 alkind_unparse (sRef_getAliasKind (u2->sref)),
8137 exprNode_unparse (e)),
8141 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
8145 message ("Function types are inconsistent. Parameter %d is "
8146 "%s, but %s in assigned function: %s",
8148 exkind_unparse (sRef_getExKind (u1->sref)),
8149 exkind_unparse (sRef_getExKind (u2->sref)),
8150 exprNode_unparse (e)),
8156 checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8157 /*@notnull@*/ uentry unew,
8158 bool mustConform, /*@unused@*/ bool completeConform)
8160 uentryList oldParams = uentry_getParams (old);
8161 uentryList newParams = uentry_getParams (unew);
8162 ctype newType = unew->utype;
8163 ctype oldType = old->utype;
8164 ctype oldRetType = ctype_unknown;
8165 ctype newRetType = ctype_unknown;
8167 DPRINTF (("Function conform: %s ==> %s",
8168 uentry_unparseFull (old),
8169 uentry_unparseFull (unew)));
8171 if (uentry_isForward (old))
8173 mustConform = FALSE;
8174 uentry_updateInto (old, unew);
8179 ** check return values
8182 if (ctype_isKnown (oldType))
8184 llassert (ctype_isFunction (oldType));
8186 oldRetType = ctype_getReturnType (oldType);
8189 if (ctype_isKnown (newType))
8191 llassert (ctype_isFunction (newType));
8193 newRetType = ctype_getReturnType (newType);
8196 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
8197 && !ctype_matchDef (newRetType, oldRetType))
8199 if (mustConform) returnValueError (old, unew);
8203 if (ctype_isConj (newRetType))
8205 if (ctype_isConj (oldRetType))
8207 if (!ctype_sameAltTypes (newRetType, oldRetType))
8211 message ("Function %q inconsistently %rdeclared to "
8212 "return alternate types %s "
8213 "(types match, but alternates are not identical, "
8214 "so checking may not be correct)",
8215 uentry_getName (unew),
8216 uentry_isDeclared (old),
8217 ctype_unparse (newRetType)),
8218 uentry_whereDeclared (unew)))
8220 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
8226 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
8231 DPRINTF (("Before state: %s",
8232 uentry_unparseFull (old)));
8233 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8234 DPRINTF (("After state: %s",
8235 uentry_unparseFull (old)));
8237 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
8239 if (exitkind_isKnown (unew->info->fcn->exitCode))
8243 message ("Function %q inconsistently %rdeclared using %s",
8244 uentry_getName (unew),
8245 uentry_isDeclared (old),
8246 exitkind_unparse (unew->info->fcn->exitCode)),
8247 uentry_whereDeclared (unew)))
8249 uentry_showWhereSpecified (old);
8254 unew->info->fcn->exitCode = old->info->fcn->exitCode;
8258 if (!qual_isUnknown (unew->info->fcn->nullPred))
8260 if (!qual_match (old->info->fcn->nullPred, unew->info->fcn->nullPred))
8264 message ("Function %q inconsistently %rdeclared using %s",
8265 uentry_getName (unew),
8266 uentry_isDeclared (old),
8267 qual_unparse (unew->info->fcn->nullPred)),
8268 uentry_whereDeclared (unew)))
8270 uentry_showWhereSpecified (old);
8276 unew->info->fcn->nullPred = old->info->fcn->nullPred;
8279 if (unew->info->fcn->specialCode != SPC_NONE)
8281 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
8285 message ("Function %q inconsistently %rdeclared using %s",
8286 uentry_getName (unew),
8287 uentry_isDeclared (old),
8288 specCode_unparse (unew->info->fcn->specialCode)),
8289 uentry_whereDeclared (unew)))
8291 uentry_showWhereSpecified (old);
8297 unew->info->fcn->specialCode = old->info->fcn->specialCode;
8304 if (!uentryList_sameObject (oldParams, newParams)
8305 && (!uentryList_isMissingParams (oldParams)))
8307 if (!uentryList_isMissingParams (newParams))
8310 int nparams = uentryList_size (oldParams);
8311 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
8313 if (nparams != uentryList_size (newParams))
8315 nargsError (old, unew);
8318 if (uentryList_size (newParams) < nparams)
8320 nparams = uentryList_size (newParams);
8323 while (paramno < nparams)
8325 uentry oldCurrent = uentryList_getN (oldParams, paramno);
8326 uentry newCurrent = uentryList_getN (newParams, paramno);
8327 ctype oldCurrentType = uentry_getType (oldCurrent);
8328 ctype newCurrentType = uentry_getType (newCurrent);
8330 llassert (uentry_isValid (oldCurrent)
8331 && uentry_isValid (newCurrent));
8333 if (!uentry_isElipsisMarker (oldCurrent)
8334 && !uentry_isElipsisMarker (newCurrent))
8336 checkVarConformance (oldCurrent, newCurrent,
8337 mustConform, completeConform);
8342 if (uentry_hasName (oldCurrent)
8343 && uentry_hasName (newCurrent))
8345 cstring oldname = uentry_getName (oldCurrent);
8346 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
8348 cstring nname = uentry_getName (newCurrent);
8351 if (cstring_isDefined (pfx)
8352 && cstring_equalPrefix (oldname, cstring_toCharsSafe (pfx)))
8354 oname = cstring_suffix (oldname, cstring_length (pfx));
8359 /*@-branchstate@*/ } /*@=branchstate@*/
8361 if (cstring_isDefined (pfx)
8362 && cstring_equalPrefix (nname, cstring_toCharsSafe (pfx)))
8364 nnamefix = cstring_suffix (nname, cstring_length (pfx));
8369 /*@-branchstate@*/ } /*@=branchstate@*/
8371 if (!cstring_equal (oname, nnamefix))
8374 (FLG_DECLPARAMMATCH,
8375 message ("Definition parameter name %s does not match "
8376 "name of corresponding parameter in "
8379 uentry_whereLast (newCurrent)))
8381 uentry_showWhereLastPlain (oldCurrent);
8385 cstring_free (oldname);
8386 cstring_free (nname);
8390 if (!ctype_match (oldCurrentType, newCurrentType))
8392 paramTypeError (old, oldCurrent, oldCurrentType,
8393 unew, newCurrent, newCurrentType, paramno);
8397 if (ctype_isMissingParamsMarker (newCurrentType)
8398 || ctype_isElips (newCurrentType)
8399 || ctype_isMissingParamsMarker (oldCurrentType)
8400 || ctype_isElips (oldCurrentType))
8406 if (ctype_isConj (newCurrentType))
8408 if (ctype_isConj (oldCurrentType))
8410 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
8414 message ("Parameter %q inconsistently %rdeclared with "
8415 "alternate types %s "
8416 "(types match, but alternates are not identical, "
8417 "so checking may not be correct)",
8418 uentry_getName (newCurrent),
8419 uentry_isDeclared (oldCurrent),
8420 ctype_unparse (newCurrentType)),
8421 uentry_whereDeclared (unew)))
8423 uentry_showWhereLastVal (oldCurrent,
8424 ctype_unparse (oldCurrentType));
8432 message ("Parameter %q inconsistently %rdeclared with "
8433 "alternate types %s",
8434 uentry_getName (newCurrent),
8435 uentry_isDeclared (oldCurrent),
8436 ctype_unparse (newCurrentType)),
8437 uentry_whereDeclared (unew)))
8439 uentry_showWhereLastVal (oldCurrent,
8440 ctype_unparse (oldCurrentType));
8447 if (ctype_isConj (oldCurrentType))
8449 uentry_setType (newCurrent, oldCurrentType);
8457 ** Forgot this! detected by lclint:
8458 ** uentry.c:1257,15: Suspected infinite loop
8464 if (!uentryList_isMissingParams (newParams))
8466 if (ctype_isConj (oldRetType))
8468 old->utype = ctype_makeFunction (oldRetType,
8469 uentryList_copy (newParams));
8473 old->utype = unew->utype;
8477 checkGlobalsConformance (old, unew, mustConform, completeConform);
8478 checkModifiesConformance (old, unew, mustConform, completeConform);
8480 DPRINTF (("Before list: %s",
8481 uentry_unparseFull (old)));
8483 if (stateClauseList_isDefined (unew->info->fcn->specclauses))
8485 if (!stateClauseList_isDefined (old->info->fcn->specclauses))
8490 message ("Function %q redeclared using special clauses (can only "
8491 "be used in first declaration)",
8492 uentry_getName (unew)),
8493 uentry_whereDeclared (unew)))
8495 uentry_showWhereLast (old);
8499 /*@i23 need checking @*/
8501 old->info->fcn->specclauses = unew->info->fcn->specclauses;
8505 /*@i43 should be able to append? @*/
8507 stateClauseList_checkEqual (old, unew);
8508 stateClauseList_free (unew->info->fcn->specclauses);
8509 unew->info->fcn->specclauses = stateClauseList_undefined;
8512 /*@=branchstate@*/ /*@i23 shouldn't need this@*/
8515 if (fileloc_isUndefined (old->whereDeclared))
8517 old->whereDeclared = fileloc_copy (unew->whereDeclared);
8519 else if (fileloc_isUndefined (unew->whereDeclared))
8521 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8530 uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
8534 llassert (uentry_isValid (ue));
8535 llassert (uentry_isEitherConstant (ue));
8537 DPRINTF (("Constant value: %s / %s", uentry_unparse (ue), multiVal_unparse (m)));
8538 uval = uentry_getConstantValue (ue);
8540 if (multiVal_isDefined (uval))
8542 if (multiVal_isDefined (m))
8544 if (!multiVal_equiv (uval, m))
8548 message ("%s %q defined with inconsistent value: %q",
8549 ekind_capName (ue->ukind),
8550 uentry_getName (ue),
8551 multiVal_unparse (m)),
8554 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
8562 uentry_setConstantValue (ue, m);
8567 bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
8570 bool typeError = FALSE;
8572 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
8574 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
8578 DPRINTF (("Check struct conformance: %s / %s",
8579 uentry_unparseFull (old),
8580 uentry_unparseFull (unew)));
8581 checkStructConformance (old, unew);
8586 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8588 llbug (message ("struct tags: bad types: %t / %t",
8589 old->utype, unew->utype));
8593 else if (uentry_isEnumTag (old))
8595 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
8597 if (mustConform) checkEnumConformance (old, unew);
8601 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8603 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
8604 ctype_unparse (unew->utype)));
8608 else if (!ctype_match (old->utype, unew->utype))
8610 DPRINTF (("Type mismatch: %s / %s",
8611 ctype_unparse (old->utype),
8612 ctype_unparse (unew->utype)));
8614 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
8616 ctype realt = ctype_realType (unew->utype);
8618 if (ctype_isRealInt (realt) || ctype_isChar (realt))
8620 unew->utype = ctype_bool;
8626 typeError = optgenerror
8628 message ("%q defined as %s", uentry_getName (old),
8629 ctype_unparse (realt)),
8630 uentry_whereDeclared (unew));
8638 ctype oldr = ctype_realType (old->utype);
8639 ctype newr = ctype_realType (unew->utype);
8641 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
8643 checkStructConformance (old, unew);
8645 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
8647 checkStructConformance (old, unew);
8649 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
8651 checkEnumConformance (old, unew);
8653 else if (uentry_isConstant (old)
8654 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
8656 /* okay...for now! (should check the type is reset later... */
8660 DPRINTF (("YABA!"));
8663 message ("%s %q %rdeclared with inconsistent type: %t",
8664 ekind_capName (unew->ukind),
8665 uentry_getName (unew),
8666 uentry_isDeclared (old),
8668 uentry_whereDeclared (unew)))
8670 uentry_showWhereLast (old);
8686 uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
8687 /*@notnull@*/ uentry unew,
8688 bool mustConform, bool completeConform)
8690 if (ctype_isDefined (unew->info->datatype->type))
8693 ** bool is hard coded here, since it is built into LCL.
8694 ** For now, we're stuck with LCL's types.
8697 if (ctype_isDirectBool (old->utype) &&
8698 cstring_equalLit (unew->uname, "bool"))
8700 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
8701 evs 2000-07-25: removed
8703 unew->utype = ctype_bool;
8706 if (ctype_isUnknown (old->info->datatype->type))
8708 old->info->datatype->type = unew->info->datatype->type;
8712 DPRINTF (("Old: %s / New: %s",
8713 uentry_unparseFull (old),
8714 uentry_unparseFull (unew)));
8715 DPRINTF (("Types: %s / %s",
8716 ctype_unparse (old->info->datatype->type),
8717 ctype_unparse (unew->info->datatype->type)));
8719 if (ctype_matchDef (old->info->datatype->type,
8720 unew->info->datatype->type))
8729 ("Type %q %s with inconsistent type: %t",
8730 uentry_getName (unew),
8731 uentry_reDefDecl (old, unew),
8732 unew->info->datatype->type),
8733 uentry_whereDeclared (unew)))
8735 uentry_showWhereLastExtra
8736 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
8739 old->info->datatype->type = unew->info->datatype->type;
8744 if (unew->info->datatype->abs != MAYBE)
8746 if (ynm_isOff (old->info->datatype->abs)
8747 && ynm_isOn (unew->info->datatype->abs))
8749 if (!ctype_isDirectBool (old->utype))
8754 ("Datatype %q inconsistently %rdeclared as abstract type",
8755 uentry_getName (unew),
8756 uentry_isDeclared (old)),
8757 uentry_whereDeclared (unew)))
8759 uentry_showWhereLastPlain (old);
8763 else if (ynm_isOn (old->info->datatype->abs)
8764 && ynm_isOff (unew->info->datatype->abs))
8766 if (!ctype_isDirectBool (old->utype))
8771 ("Datatype %q inconsistently %rdeclared as concrete type",
8772 uentry_getName (unew),
8773 uentry_isDeclared (old)),
8774 uentry_whereDeclared (unew)))
8776 uentry_showWhereLastPlain (old);
8787 if (ynm_isOn (old->info->datatype->abs))
8789 old->sref = unew->sref;
8790 unew->info->datatype->mut = old->info->datatype->mut;
8793 && uentry_isReallySpecified (old))
8798 ("Datatype %q specified as abstract, "
8799 "but abstract annotation not used in declaration",
8800 uentry_getName (unew)),
8801 uentry_whereDeclared (unew)))
8803 uentry_showWhereLastPlain (old);
8809 unew->info->datatype->abs = old->info->datatype->abs;
8811 if (ynm_isMaybe (unew->info->datatype->mut))
8813 if (completeConform && ynm_isOff (old->info->datatype->mut)
8814 && uentry_isReallySpecified (old))
8819 ("Datatype %q specified as immutable, "
8820 "but immutable annotation not used in declaration",
8821 uentry_getName (unew)),
8822 uentry_whereDeclared (unew)))
8824 uentry_showWhereLastPlain (old);
8828 unew->info->datatype->mut = old->info->datatype->mut;
8830 else if (ynm_isMaybe (old->info->datatype->mut))
8832 old->info->datatype->mut = unew->info->datatype->mut;
8836 if (ynm_isOn (old->info->datatype->abs))
8838 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
8842 message ("Datatype %q inconsistently %rdeclared as immutable",
8843 uentry_getName (unew),
8844 uentry_isDeclared (old)),
8845 uentry_whereDeclared (unew)))
8847 uentry_showWhereLastPlain (old);
8852 if (ynm_isOff (old->info->datatype->mut)
8853 && ynm_isOn (unew->info->datatype->mut))
8857 message ("Datatype %q inconsistently %rdeclared as mutable",
8858 uentry_getName (unew),
8859 uentry_isDeclared (old)),
8860 uentry_whereDeclared (unew)))
8862 uentry_showWhereLastPlain (old);
8867 old->info->datatype->mut = unew->info->datatype->mut;
8870 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8874 uentry_checkConstantConformance (/*@notnull@*/ uentry old,
8875 /*@notnull@*/ uentry unew,
8877 /*@unused@*/ bool completeConform)
8879 multiVal oldval = uentry_getConstantValue (old);
8880 multiVal newval = uentry_getConstantValue (unew);
8882 if (multiVal_isDefined (oldval))
8884 if (multiVal_isDefined (newval))
8886 if (!multiVal_equiv (oldval, newval))
8891 message ("%s %q %rdeclared with inconsistent value: %q",
8892 ekind_capName (unew->ukind),
8893 uentry_getName (unew),
8894 uentry_isDeclared (old),
8895 multiVal_unparse (newval)),
8896 uentry_whereDeclared (unew)))
8898 uentry_showWhereLastExtra (old, multiVal_unparse (oldval));
8902 uentry_setConstantValue (unew, multiVal_copy (oldval));
8911 uentry_setConstantValue (old, multiVal_copy (newval));
8916 uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8917 /*@notnull@*/ uentry unew, bool mustConform,
8918 bool completeConform)
8920 bool typeError = FALSE;
8921 bool fcnConformance = FALSE;
8923 if (!ekind_equal (unew->ukind, old->ukind))
8926 ** okay, only if one is a function and the other is
8927 ** a variable of type function.
8930 if (unew->ukind == KENUMCONST
8931 && old->ukind == KCONST)
8933 old->ukind = KENUMCONST;
8937 if (unew->ukind == KFCN
8938 && old->ukind == KCONST
8939 && ctype_isUnknown (old->utype))
8942 ** When a function is defined with an unparam macro
8945 uentry_updateInto (old, unew);
8949 if (uentry_isExpandedMacro (old)
8950 && uentry_isEitherConstant (unew))
8952 uentry_updateInto (old, unew);
8956 if (uentry_isEndIter (unew))
8958 if (ctype_isUnknown (old->utype))
8960 if (!uentry_isSpecified (old)
8961 && uentry_isCodeDefined (unew))
8963 if (!fileloc_withinLines (uentry_whereDefined (old),
8964 uentry_whereDeclared (unew), 2))
8965 { /* bogus! will give errors if there is too much whitespace */
8969 ("Iterator finalized name %q does not match name in "
8970 "previous iter declaration (should be end_%q). This iter "
8971 "is declared at %q",
8972 uentry_getName (unew),
8973 uentry_getName (old),
8974 fileloc_unparse (uentry_whereDefined (old))),
8975 uentry_whereDeclared (old));
8979 uentry_updateInto (old, unew);
8984 KindConformanceError (old, unew, mustConform);
8988 if (uentry_isFunction (unew))
8990 if (uentry_isVariable (old))
8992 if (!ctype_isUnknown (old->utype))
8994 if (ctype_isFunction (old->utype))
8996 uentry_makeVarFunction (old);
8997 checkFunctionConformance (old, unew, mustConform,
8999 fcnConformance = TRUE;
9003 KindConformanceError (old, unew, mustConform);
9008 if (uentry_isExpandedMacro (old))
9010 if (fileloc_isUndefined (unew->whereDefined))
9012 unew->whereDefined = fileloc_update (unew->whereDefined,
9016 uentry_updateInto (old, unew);
9017 old->used = unew->used = TRUE;
9022 /* undeclared identifier */
9023 old->utype = unew->utype;
9024 uentry_makeVarFunction (old);
9025 checkFunctionConformance (old, unew, FALSE, FALSE);
9026 fcnConformance = TRUE;
9032 KindConformanceError (old, unew, mustConform);
9035 else if (uentry_isFunction (old) && uentry_isVariable (unew))
9037 if (!ctype_isUnknown (unew->utype))
9039 if (ctype_isFunction (unew->utype))
9041 uentry_makeVarFunction (unew);
9042 checkFunctionConformance (old, unew, mustConform, completeConform);
9043 fcnConformance = TRUE;
9047 KindConformanceError (old, unew, mustConform);
9052 KindConformanceError (old, unew, mustConform);
9057 KindConformanceError (old, unew, mustConform);
9063 ** check parameter lists for functions
9064 ** (before type errors, to get better messages
9067 if (uentry_isFunction (old))
9069 checkFunctionConformance (old, unew, mustConform, completeConform);
9070 fcnConformance = TRUE;
9074 if (!ctype_isUndefined (old->utype))
9076 typeError = checkTypeConformance (old, unew, mustConform);
9083 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
9085 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
9088 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
9090 DPRINTF (("Check datatype: %s / %s",
9091 uentry_unparseFull (old),
9092 uentry_unparseFull (unew)));
9094 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
9097 if (uentry_isVariable (old) && uentry_isVariable (unew))
9100 !ctype_matchDef (old->utype, unew->utype))
9105 ("Variable %q %s with inconsistent type (arrays and pointers are "
9106 "not identical in variable declarations): %t",
9107 uentry_getName (unew),
9108 uentry_reDefDecl (old, unew),
9110 uentry_whereDeclared (unew)))
9112 uentry_showWhereLast (old);
9115 ** Avoid repeated errors.
9118 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
9120 old->whereDefined = fileloc_update (old->whereDefined,
9128 checkVarConformance (old, unew, mustConform, completeConform);
9133 /* old->utype = unew->utype; */
9137 if (ctype_isConj (old->utype))
9139 if (ctype_isConj (unew->utype))
9141 if (!ctype_sameAltTypes (old->utype, unew->utype))
9145 message ("%s %q inconsistently %rdeclared with "
9146 "alternate types %s "
9147 "(types match, but alternates are not identical, "
9148 "so checking may not be correct)",
9149 ekind_capName (uentry_getKind (old)),
9150 uentry_getName (unew),
9151 uentry_isDeclared (old),
9152 ctype_unparse (unew->utype)),
9153 uentry_whereDeclared (unew)))
9155 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
9159 old->utype = unew->utype;
9166 if (ctype_isUnknown (old->utype))
9168 old->utype = unew->utype;
9173 if (unew->ukind == old->ukind)
9176 unew->info = uinfo_copy (old->info, old->ukind);
9179 sRef_storeState (old->sref);
9180 sRef_storeState (unew->sref);
9183 static void uentry_mergeConstraints (uentry spec, uentry def)
9185 if (uentry_isFunction (def))
9187 DPRINTF (("Here: %s / %s",
9188 uentry_unparseFull (spec),
9189 uentry_unparseFull (def)));
9190 /* evans 2001-07-21 */
9191 llassert (uentry_isFunction (spec));
9193 if (functionConstraint_isDefined (def->info->fcn->preconditions))
9195 if (fileloc_isXHFile (uentry_whereLast (def)))
9197 llassert (uentry_isFunction (spec));
9198 spec->info->fcn->preconditions = functionConstraint_conjoin (spec->info->fcn->preconditions,
9199 def->info->fcn->preconditions);
9201 else if (fileloc_equal (uentry_whereLast (spec), uentry_whereLast (def)))
9207 /* Check if the constraints are identical */
9212 ("Preconditions for %q redeclared. Dropping previous precondition: %q",
9213 uentry_getName (spec),
9214 functionConstraint_unparse (spec->info->fcn->preconditions)),
9215 uentry_whereLast (def)))
9217 uentry_showWhereSpecified (spec);
9220 functionConstraint_free (spec->info->fcn->preconditions);
9221 spec->info->fcn->preconditions = def->info->fcn->preconditions;
9224 def->info->fcn->preconditions = functionConstraint_undefined;
9227 if (functionConstraint_isDefined (def->info->fcn->postconditions))
9229 if (fileloc_isXHFile (uentry_whereLast (def)))
9231 llassert (uentry_isFunction (spec));
9232 DPRINTF (("Post: %s /++/ %s",
9233 functionConstraint_unparse (spec->info->fcn->postconditions),
9234 functionConstraint_unparse (def->info->fcn->postconditions)));
9235 spec->info->fcn->postconditions = functionConstraint_conjoin (spec->info->fcn->postconditions,
9236 def->info->fcn->postconditions);
9237 def->info->fcn->postconditions = functionConstraint_undefined;
9238 DPRINTF (("Conjoined post: %s", functionConstraint_unparse (spec->info->fcn->postconditions)));
9245 ("Postconditions for %q redeclared. Dropping previous postcondition: %q",
9246 uentry_getName (spec),
9247 functionConstraint_unparse (spec->info->fcn->postconditions)),
9248 uentry_whereLast (def)))
9250 uentry_showWhereSpecified (spec);
9253 functionConstraint_free (spec->info->fcn->postconditions);
9254 spec->info->fcn->postconditions = def->info->fcn->postconditions;
9255 def->info->fcn->postconditions = functionConstraint_undefined;
9262 ** modifies spec to reflect def, reports any inconsistencies
9266 uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
9268 llassert (uentry_isValid (spec));
9269 llassert (uentry_isValid (def));
9270 llassert (cstring_equal (spec->uname, def->uname));
9272 if (uentry_isFunction (def))
9274 if (uentry_isConstant (spec))
9276 llassert (ctype_isUnknown (spec->utype) || ctype_isFunction (spec->utype));
9277 uentry_makeConstantFunction (spec);
9281 uentry_convertVarFunction (spec);
9284 llassert (uentry_isFunction (spec));
9287 DPRINTF (("Merge entries: %s / %s",
9288 uentry_unparseFull (spec),
9289 uentry_unparseFull (def)));
9291 uentry_mergeConstraints (spec, def);
9293 uentry_checkConformance (spec, def, TRUE,
9294 context_getFlag (FLG_NEEDSPEC));
9296 DPRINTF (("Merge entries after conform: %s / %s",
9297 uentry_unparseFull (spec),
9298 uentry_unparseFull (def)));
9300 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
9303 ** okay, declarations conform. Propagate extra information.
9306 uentry_setDefined (spec, uentry_whereDefined (def));
9307 uentry_setDeclared (spec, uentry_whereDeclared (def));
9309 if (uentry_isStatic (def))
9313 message ("%s %q specified, but declared as static",
9314 ekind_capName (def->ukind),
9315 uentry_getName (def)),
9316 uentry_whereDeclared (def)))
9318 uentry_showWhereSpecified (spec);
9323 spec->storageclass = def->storageclass;
9326 sRef_storeState (spec->sref);
9328 spec->used = def->used || spec->used;
9329 spec->hasNameError |= def->hasNameError;
9333 if (!spec->hasNameError)
9335 uentry_checkName (spec);
9344 ** Can't generate function redeclaration errors when the
9345 ** entries are merged, since we don't yet know if its the
9346 ** definition of the function.
9350 uentry_clearDecl (void)
9352 posRedeclared = uentry_undefined;
9353 fileloc_free (posLoc);
9354 posLoc = fileloc_undefined;
9358 uentry_checkDecl (void)
9360 if (uentry_isValid (posRedeclared) && !fileloc_isXHFile (posLoc))
9362 llassert (fileloc_isDefined (posLoc));
9364 if (uentry_isCodeDefined (posRedeclared))
9366 if (optgenerror (FLG_REDECL,
9367 message ("%s %q declared after definition",
9368 ekind_capName (posRedeclared->ukind),
9369 uentry_getName (posRedeclared)),
9372 llgenindentmsg (message ("Definition of %q",
9373 uentry_getName (posRedeclared)),
9374 posRedeclared->whereDeclared);
9379 if (optgenerror (FLG_REDECL,
9380 message ("%s %q declared more than once",
9381 ekind_capName (posRedeclared->ukind),
9382 uentry_getName (posRedeclared)),
9385 llgenindentmsg (message ("Previous declaration of %q",
9386 uentry_getName (posRedeclared)),
9387 posRedeclared->whereDeclared);
9392 fileloc_free (posLoc);
9393 posLoc = fileloc_undefined;
9394 posRedeclared = uentry_undefined;
9398 ** Redefinition of old as unew.
9399 ** modifies old to reflect unew, reports any inconsistencies
9403 uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
9405 fileloc olddef = uentry_whereDeclared (old);
9406 fileloc unewdef = uentry_whereDeclared (unew);
9410 DPRINTF (("uentry merge: %s / %s",
9411 uentry_unparseFull (old),
9412 uentry_unparseFull (unew)));
9415 fileloc_isUndefined (olddef)
9416 && fileloc_isDefined (uentry_whereDefined (old))
9417 && !uentry_isExpandedMacro (old);
9419 if (!context_getFlag (FLG_INCONDEFSLIB)
9420 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9422 mustConform = FALSE;
9429 llassert (uentry_isValid (old));
9430 llassert (uentry_isValid (unew));
9431 llassert (cstring_equal (old->uname, unew->uname));
9433 if (uentry_isFunction (unew) && !uentry_isFunction (old))
9435 if (uentry_isConstant (old))
9437 llassert (ctype_isUnknown (old->utype) || ctype_isFunction (old->utype));
9438 uentry_makeConstantFunction (old);
9442 uentry_convertVarFunction (old);
9445 llassert (uentry_isFunction (old));
9448 DPRINTF (("uentry merge: %s / %s",
9449 uentry_unparseFull (old),
9450 uentry_unparseFull (unew)));
9452 if (uentry_isExtern (unew))
9454 uentry_setUsed (old, unewdef);
9458 ** should check old one was extern!
9461 if (uentry_isStatic (old))
9463 if (!(uentry_isStatic (unew)))
9467 message ("%s %q shadows static declaration",
9468 ekind_capName (unew->ukind),
9469 uentry_getName (unew)),
9472 uentry_showWhereLast (old);
9477 uentry_setDeclDef (old, unewdef);
9480 else if (uentry_isStatic (unew))
9482 uentry_setDeclDef (old, unewdef);
9484 else if (uentry_isExtern (old))
9486 uentry_setDeclared (old, unewdef);
9490 if (!uentry_isExtern (unew)
9491 && !uentry_isForward (old)
9492 && !fileloc_equal (olddef, unewdef)
9493 && !fileloc_isUndefined (olddef)
9494 && !fileloc_isUndefined (unewdef)
9495 && !fileloc_isBuiltin (olddef)
9496 && !fileloc_isBuiltin (unewdef)
9497 && !uentry_isYield (old)
9498 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9500 if (uentry_isVariable (old) || uentry_isVariable (unew))
9502 ; /* will report redeclaration error later */
9506 if (fileloc_isDefined (uentry_whereDefined (old)))
9510 message ("%s %q defined more than once",
9511 ekind_capName (unew->ukind),
9512 uentry_getName (unew)),
9513 uentry_whereLast (unew)))
9516 (message ("Previous definition of %q",
9517 uentry_getName (old)),
9518 uentry_whereLast (old));
9521 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
9523 uentry_updateInto (old, unew);
9524 old->sref = sRef_saveCopy (old->sref);
9532 if (fileloc_isLib (olddef)
9533 || fileloc_isUndefined (olddef)
9534 || fileloc_isImport (olddef))
9536 if (uentry_isExtern (unew))
9538 if (uentry_isExtern (old)
9539 || (fileloc_isDefined (uentry_whereDeclared (old))
9540 && (!fileloc_equal (uentry_whereDeclared (old),
9541 uentry_whereDefined (old)))))
9545 message ("%s %q declared more than once",
9546 ekind_capName (unew->ukind),
9547 uentry_getName (unew)),
9548 unew->whereDeclared))
9551 (message ("Previous declaration of %q",
9552 uentry_getName (old)),
9553 old->whereDeclared);
9557 uentry_setExtern (old);
9561 uentry_setDeclared (old, unewdef); /* evans 2001-07-23 was setDefined */
9567 DPRINTF (("uentry merge: %s / %s",
9568 uentry_unparseFull (old),
9569 uentry_unparseFull (unew)));
9571 uentry_mergeConstraints (old, unew);
9572 DPRINTF (("uentry merge: %s / %s",
9573 uentry_unparseFull (old),
9574 uentry_unparseFull (unew)));
9576 uentry_checkConformance (old, unew, mustConform, FALSE);
9577 DPRINTF (("uentry merge: %s / %s",
9578 uentry_unparseFull (old),
9579 uentry_unparseFull (unew)));
9581 old->used = old->used || unew->used;
9582 old->uses = filelocList_append (old->uses, unew->uses);
9583 unew->uses = filelocList_undefined;
9585 sRef_storeState (old->sref);
9586 sRef_storeState (unew->sref);
9590 old->whereDefined = fileloc_update (old->whereDefined,
9594 DPRINTF (("here: %s", uentry_unparseFull (old)));
9597 ** No redeclaration errors for functions here, since we
9598 ** don't know if this is the definition of the function.
9601 if (fileloc_isUser (old->whereDeclared)
9602 && fileloc_isUser (unew->whereDeclared)
9603 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
9604 && !fileloc_isDefined (unew->whereDefined))
9606 if (uentry_isFunction (old))
9608 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
9609 posLoc = fileloc_update (posLoc, unew->whereDeclared);
9613 if (optgenerror (FLG_REDECL,
9614 message ("%s %q declared more than once",
9615 ekind_capName (unew->ukind),
9616 uentry_getName (unew)),
9617 unew->whereDeclared))
9619 llgenindentmsg (message ("Previous declaration of %q",
9620 uentry_getName (old)),
9621 old->whereDeclared);
9626 if (fileloc_isUndefined (old->whereDefined))
9628 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
9632 if (!context_processingMacros ()
9633 && fileloc_isUser (old->whereDefined)
9634 && fileloc_isUser (unew->whereDefined)
9635 && !fileloc_equal (old->whereDefined, unew->whereDefined))
9637 if (uentry_isVariable (unew) || uentry_isFunction (unew))
9639 if (uentry_isVariable (unew)
9640 && uentry_isExtern (unew))
9642 if (optgenerror (FLG_REDECL,
9643 message ("%s %q declared after definition",
9644 ekind_capName (unew->ukind),
9645 uentry_getName (unew)),
9646 unew->whereDeclared))
9648 llgenindentmsg (message ("Definition of %q",
9649 uentry_getName (old)),
9655 if (optgenerror (FLG_REDEF,
9656 message ("%s %q redefined",
9657 ekind_capName (unew->ukind),
9658 uentry_getName (unew)),
9659 unew->whereDefined))
9661 llgenindentmsg (message ("Previous definition of %q",
9662 uentry_getName (old)),
9670 if (uentry_isExternal (unew))
9672 old->whereDefined = fileloc_createExternal ();
9675 if (unew->hasNameError)
9677 old->hasNameError = TRUE;
9682 if (!old->hasNameError)
9684 uentry_checkName (old);
9687 DPRINTF (("After: %s", uentry_unparseFull (old)));
9688 llassert (!ctype_isUndefined (old->utype));
9692 uentry_copyState (uentry res, uentry other)
9694 llassert (uentry_isValid (res));
9695 llassert (uentry_isValid (other));
9697 res->used = other->used;
9699 res->info->var->kind = other->info->var->kind;
9700 res->info->var->defstate = other->info->var->defstate;
9701 res->info->var->nullstate = other->info->var->nullstate;
9702 res->info->var->checked = other->info->var->checked;
9704 sRef_copyState (res->sref, other->sref);
9708 uentry_sameKind (uentry u1, uentry u2)
9710 if (uentry_isValid (u1) && uentry_isValid (u2))
9712 if (uentry_isVar (u1) && uentry_isVar (u2))
9714 ctype c1 = u1->utype;
9715 ctype c2 = u2->utype;
9717 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
9720 ** both functions, or both not functions
9723 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
9727 return ((u1->ukind == u2->ukind));
9734 static void uentry_updateInto (/*@unique@*/ uentry unew, uentry old)
9736 ekind okind = unew->ukind;
9737 llassert (uentry_isValid (unew));
9738 llassert (uentry_isValid (old));
9740 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9742 unew->ukind = old->ukind;
9743 llassert (cstring_equal (unew->uname, old->uname));
9744 unew->utype = old->utype;
9746 if (fileloc_isDefined (unew->whereSpecified)
9747 && !fileloc_isDefined (old->whereSpecified))
9749 ; /* Keep the old value */
9753 fileloc_free (unew->whereSpecified); /*@i523 why no error without this? */
9754 unew->whereSpecified = fileloc_copy (old->whereSpecified);
9757 if (fileloc_isDefined (unew->whereDefined)
9758 && !fileloc_isDefined (old->whereDefined))
9760 ; /* Keep the old value */
9764 fileloc_free (unew->whereDefined); /*@i523 why no error without this? */
9765 unew->whereDefined = fileloc_copy (old->whereDefined);
9768 if (fileloc_isDefined (unew->whereDeclared)
9769 && !fileloc_isDefined (old->whereDeclared))
9771 ; /* Keep the old value */
9775 fileloc_free (unew->whereDeclared); /*@i523 why no error without this? */
9776 unew->whereDeclared = fileloc_copy (old->whereDeclared);
9779 DPRINTF (("Update into: %s / %s", uentry_unparseFull (unew), uentry_unparseFull (old)));
9781 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
9782 unew->used = old->used;
9784 unew->isPrivate = old->isPrivate;
9785 unew->hasNameError = old->hasNameError;
9786 unew->uses = filelocList_append (unew->uses, old->uses);
9787 old->uses = filelocList_undefined;
9789 unew->storageclass = old->storageclass;
9790 uinfo_free (unew->info, okind);
9791 unew->info = uinfo_copy (old->info, old->ukind);
9796 uentry_copy (uentry e)
9798 if (uentry_isValid (e))
9800 uentry enew = uentry_alloc ();
9801 DPRINTF (("copy: %s", uentry_unparseFull (e)));
9802 enew->ukind = e->ukind;
9803 enew->uname = cstring_copy (e->uname);
9804 enew->utype = e->utype;
9806 enew->whereSpecified = fileloc_copy (e->whereSpecified);
9807 enew->whereDefined = fileloc_copy (e->whereDefined);
9808 enew->whereDeclared = fileloc_copy (e->whereDeclared);
9810 enew->sref = sRef_saveCopy (e->sref); /* Memory leak! */
9811 enew->used = e->used;
9813 enew->isPrivate = e->isPrivate;
9814 enew->hasNameError = e->hasNameError;
9815 enew->uses = filelocList_undefined;
9817 enew->storageclass = e->storageclass;
9818 enew->info = uinfo_copy (e->info, e->ukind);
9819 enew->warn = warnClause_copy (e->warn);
9821 DPRINTF (("Here we are..."));
9822 DPRINTF (("original: %s", uentry_unparseFull (e)));
9823 DPRINTF (("copy: %s", uentry_unparse (enew)));
9824 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
9829 return uentry_undefined;
9834 uentry_setState (uentry res, uentry other)
9836 llassert (uentry_isValid (res));
9837 llassert (uentry_isValid (other));
9839 llassert (res->ukind == other->ukind);
9840 llassert (res->ukind == KVAR);
9842 res->sref = sRef_saveCopy (other->sref);
9843 res->used = other->used;
9844 filelocList_free (res->uses);
9845 res->uses = other->uses;
9846 other->uses = filelocList_undefined;
9847 res->lset = other->lset;
9851 uentry_mergeUses (uentry res, uentry other)
9853 llassert (uentry_isValid (res));
9854 llassert (uentry_isValid (other));
9856 res->used = other->used || res->used;
9857 res->lset = other->lset || res->lset;
9858 res->uses = filelocList_append (res->uses, other->uses);
9859 other->uses = filelocList_undefined;
9864 ** This is a really ugly routine.
9866 ** gack...fix this one day.
9871 ** >> res is the false branch, other is the true branch (or continuation)
9873 ** >> res is the true branch, other is the false branch (or continutation)
9880 ** References not effected by res are propagated from other.
9884 branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
9885 bool flip, clause cl, fileloc loc)
9889 message ("%s %q is %s %s, but %s %s.",
9890 ekind_capName (res->ukind), uentry_getName (res),
9891 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
9892 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
9895 if (sRef_isDead (res->sref))
9897 sRef_showStateInfo (res->sref);
9899 else if (sRef_isKept (res->sref))
9901 sRef_showAliasInfo (res->sref);
9903 else /* dependent */
9905 sRef_showAliasInfo (res->sref);
9906 sRef_showAliasInfo (other->sref);
9909 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
9913 static bool incompatibleStates (sRef rs, sRef os)
9915 alkind rk = sRef_getAliasKind (rs);
9916 alkind ok = sRef_getAliasKind (os);
9918 if (alkind_isError (rk) || alkind_isError (ok))
9924 return ((sRef_isDead (rs)
9925 || (alkind_isKept (rk) && !alkind_isKept (ok))
9926 || (alkind_isDependent (rk)
9927 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
9928 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
9933 branchStateAltError (/*@notnull@*/ uentry res,
9934 /*@notnull@*/ uentry other, bool flip,
9935 clause cl, fileloc loc)
9939 message ("%s %q is %s %s, but %s %s.",
9940 ekind_capName (res->ukind), uentry_getName (res),
9941 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
9942 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
9945 if (sRef_isDead (other->sref))
9947 sRef_showStateInfo (other->sref);
9951 sRef_showAliasInfo (other->sref);
9954 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
9955 sRef_setDefinedComplete (res->sref, fileloc_undefined);
9957 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
9958 sRef_setDefinedComplete (other->sref, fileloc_undefined);
9963 ** A reference is relevant for certain checks, only if it
9964 ** is not definitely null on this path (but not declared
9965 ** to always be null.)
9968 static bool uentry_relevantReference (sRef sr, bool flip)
9970 if (sRef_isKept (sr) || sRef_isDependent (sr))
9978 return !sRef_definitelyNullContext (sr);
9982 return !sRef_definitelyNullAltContext (sr);
9988 uentry_mergeAliasStates (uentry res, uentry other, fileloc loc,
9989 bool mustReturn, bool flip, bool opt,
9992 DPRINTF (("Merge alias states: %s / %s",
9993 uentry_unparseFull (res),
9994 uentry_unparseFull (other)));
9996 if (sRef_isValid (res->sref))
10001 if (incompatibleStates (res->sref, other->sref))
10005 if (sRef_isThroughArrayFetch (res->sref)
10006 && !context_getFlag (FLG_STRICTBRANCHSTATE))
10008 if (sRef_isKept (res->sref) || sRef_isKept (other->sref))
10010 sRef_maybeKill (res->sref, loc);
10012 else if (sRef_isPossiblyDead (other->sref))
10014 sRef_maybeKill (res->sref, loc);
10023 if (uentry_relevantReference (other->sref, flip))
10026 if (sRef_isLocalParamVar (res->sref)
10027 && (sRef_isLocalState (other->sref)
10028 || sRef_isDependent (other->sref)))
10030 if (sRef_isDependent (res->sref))
10032 sRef_setDependent (other->sref, loc);
10036 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
10041 branchStateError (res, other, flip, cl, loc);
10046 if (sRef_isKept (res->sref))
10048 sRef_setKept (other->sref, loc);
10053 if (incompatibleStates (other->sref, res->sref))
10055 if (uentry_relevantReference (res->sref, !flip))
10057 if (sRef_isLocalParamVar (res->sref)
10058 && (sRef_isDependent (res->sref)
10059 || sRef_isLocalState (res->sref)))
10061 if (sRef_isDependent (other->sref))
10063 sRef_setDependent (res->sref, loc);
10067 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
10072 if (sRef_isParam (other->sref))
10075 ** If the local variable associated
10076 ** with the param has the correct state,
10078 ** (e.g., free (s); s = new(); ...
10081 uentry uvar = usymtab_lookupSafe (other->uname);
10083 if (uentry_isValid (uvar)
10084 && ((sRef_isDead (other->sref)
10085 && sRef_isOnly (uvar->sref))
10086 || (sRef_isDependent (other->sref)
10087 && sRef_isOwned (uvar->sref))))
10093 branchStateAltError (res, other,
10099 DPRINTF (("Here: %s / %s",
10100 uentry_unparseFull (res),
10101 uentry_unparseFull (other)));
10103 branchStateAltError (res, other,
10110 if (sRef_isKept (other->sref))
10112 sRef_setKept (res->sref, loc);
10118 DPRINTF (("Merge opt..."));
10119 sRef_mergeOptState (res->sref, other->sref, cl, loc);
10120 DPRINTF (("Done!"));
10124 sRef_mergeState (res->sref, other->sref, cl, loc);
10129 if (sRef_isModified (other->sref))
10131 sRef_setModified (res->sref);
10138 uentry_mergeValueStates (uentry res, uentry other, fileloc loc, bool mustReturn, /*@unused@*/ bool flip)
10140 valueTable rvalues;
10141 valueTable ovalues;
10143 DPRINTF (("Merge values: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
10151 rvalues = sRef_getValueTable (res->sref);
10152 ovalues = sRef_getValueTable (other->sref);
10154 if (valueTable_isUndefined (ovalues))
10156 DPRINTF (("No value table: %s", sRef_unparseFull (other->sref)));
10159 else if (valueTable_isUndefined (rvalues))
10162 ** Copy values from other
10166 DPRINTF (("Has value table: %s", sRef_unparseFull (other->sref)));
10167 DPRINTF (("No value table: %s", sRef_unparseFull (res->sref)));
10172 valueTable_elements (ovalues, fkey, fval) {
10174 metaStateInfo minfo;
10175 stateCombinationTable sctable;
10179 tval = valueTable_lookup (rvalues, fkey);
10181 DPRINTF (("Merge value: %s / %s X %s", fkey,
10182 stateValue_unparse (fval), stateValue_unparse (tval)));
10184 minfo = context_lookupMetaStateInfo (fkey);
10185 llassert (stateValue_isDefined (tval));
10187 if (metaStateInfo_isUndefined (minfo) || !stateValue_isDefined (tval))
10189 DPRINTF (("Cannot find meta state for: %s", fkey));
10194 llassert (metaStateInfo_isDefined (minfo));
10196 if (stateValue_isError (fval)
10197 || sRef_definitelyNullContext (res->sref))
10199 sRef_setMetaStateValueComplete (res->sref,
10200 fkey, stateValue_getValue (fval),
10201 stateValue_getLoc (fval));
10202 DPRINTF (("Setting res: %s", sRef_unparseFull (res->sref)));
10204 else if (stateValue_isError (tval)
10205 || sRef_definitelyNullAltContext (other->sref))
10207 DPRINTF (("Other branch is definitely null!"));
10209 else if (sRef_isStateUndefined (res->sref)
10210 || sRef_isDead (res->sref))
10212 ; /* Combination state doesn't matter if it is undefined or dead */
10216 DPRINTF (("Check: %s / %s / %s / %s", fkey,
10217 metaStateInfo_unparse (minfo),
10218 stateValue_unparse (fval),
10219 stateValue_unparse (tval)));
10221 DPRINTF (("state values: %d / %d",
10222 stateValue_getValue (fval), stateValue_getValue (tval)));
10224 sctable = metaStateInfo_getMergeTable (minfo);
10226 DPRINTF (("Merge table: %s",
10227 stateCombinationTable_unparse (sctable)));
10229 msg = cstring_undefined;
10231 nval = stateCombinationTable_lookup (sctable,
10232 stateValue_getValue (fval),
10233 stateValue_getValue (tval),
10236 DPRINTF (("nval: %d / %d / %d", nval,
10237 stateValue_getValue (fval), stateValue_getValue (tval)));
10239 if (nval == stateValue_error)
10241 /*@i32 print extra info for assignments@*/
10243 if (uentry_isGlobalMarker (res))
10248 ("Control branches merge with incompatible global states (%s and %s)%q",
10249 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10250 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10251 cstring_isDefined (msg)
10252 ? message (": %s", msg) : cstring_undefined),
10255 sRef_showMetaStateInfo (res->sref, fkey);
10256 sRef_showMetaStateInfo (other->sref, fkey);
10264 ("Control branches merge with incompatible states for %q (%s and %s)%q",
10265 uentry_getName (res),
10266 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
10267 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
10268 cstring_isDefined (msg)
10269 ? message (": %s", msg) : cstring_undefined),
10272 sRef_showMetaStateInfo (res->sref, fkey);
10273 sRef_showMetaStateInfo (other->sref, fkey);
10274 DPRINTF (("Res: %s", sRef_unparseFull (res->sref)));
10275 DPRINTF (("Other: %s", sRef_unparseFull (other->sref)));
10276 DPRINTF (("Null: %s / %s",
10277 bool_unparse (usymtab_isDefinitelyNull (res->sref)),
10278 bool_unparse (usymtab_isDefinitelyNull (other->sref))));
10284 if (nval == stateValue_getValue (fval)
10285 && nval != stateValue_getValue (tval))
10287 loc = stateValue_getLoc (fval);
10289 else if (nval == stateValue_getValue (tval)
10290 && nval != stateValue_getValue (fval))
10292 loc = stateValue_getLoc (tval);
10299 if (stateValue_getValue (sRef_getMetaStateValue (res->sref, fkey)) == nval
10300 && nval == stateValue_getValue (fval)
10301 && nval == stateValue_getValue (tval))
10307 sRef_setMetaStateValueComplete (res->sref, fkey, nval, loc);
10311 } end_valueTable_elements ;
10317 uentry_mergeSetStates (uentry res, uentry other, /*@unused@*/ fileloc loc,
10318 bool flip, clause cl)
10320 if (cl == DOWHILECLAUSE)
10322 res->used = other->used || res->used;
10323 res->lset = other->lset || res->lset;
10324 res->uses = filelocList_append (res->uses, other->uses);
10325 other->uses = filelocList_undefined;
10329 if (sRef_isMacroParamRef (res->sref)
10330 && !uentry_isSefParam (other)
10331 && !uentry_isSefParam (res))
10333 bool hasError = FALSE;
10335 if (bool_equal (res->used, other->used))
10337 res->used = other->used;
10341 if (other->used && !flip)
10346 message ("Macro parameter %q used in true clause, "
10347 "but not in false clause",
10348 uentry_getName (res)),
10349 uentry_whereDeclared (res));
10356 message ("Macro parameter %q used in false clause, "
10357 "but not in true clause",
10358 uentry_getName (res)),
10359 uentry_whereDeclared (res));
10365 /* make it sef now, prevent more errors */
10366 res->info->var->kind = VKREFSEFPARAM;
10372 res->used = other->used || res->used;
10373 res->lset = other->lset || res->lset;
10374 res->uses = filelocList_append (res->uses, other->uses);
10375 other->uses = filelocList_undefined;
10381 uentry_mergeState (uentry res, uentry other, fileloc loc,
10382 bool mustReturn, bool flip, bool opt,
10385 llassert (uentry_isValid (res));
10386 llassert (uentry_isValid (other));
10388 llassert (res->ukind == other->ukind);
10389 llassert (res->ukind == KVAR);
10391 DPRINTF (("Merge state: %s / %s", uentry_unparseFull (res),
10392 uentry_unparseFull (other)));
10394 uentry_mergeAliasStates (res, other, loc, mustReturn, flip, opt, cl);
10395 uentry_mergeValueStates (res, other, loc, mustReturn, flip);
10396 uentry_mergeSetStates (res, other, loc, flip, cl);
10399 void uentry_setUsed (uentry e, fileloc loc)
10401 static bool firstTime = TRUE;
10402 static bool showUses = FALSE;
10403 static bool exportLocal = FALSE;
10405 DPRINTF (("Used: %s / %s", uentry_unparse (e), fileloc_unparse (loc)));
10409 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
10411 showUses = context_getFlag (FLG_SHOWUSES);
10412 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
10417 if (uentry_isValid (e))
10421 if (warnClause_isDefined (e->warn))
10423 flagSpec flg = warnClause_getFlag (e->warn);
10426 if (warnClause_hasMessage (e->warn))
10428 msg = cstring_copy (warnClause_getMessage (e->warn));
10432 msg = message ("Use of possibly dangerous %s",
10433 uentry_ekindNameLC (e));
10437 message ("%q: %q", msg, uentry_getName (e)),
10441 if (sRef_isMacroParamRef (e->sref))
10443 if (uentry_isYield (e) || uentry_isSefParam (e))
10449 if (context_inConditional ())
10453 message ("Macro parameter %q used in conditionally "
10454 "executed code (may or may not be "
10455 "evaluated exactly once)",
10456 uentry_getName (e)),
10459 e->info->var->kind = VKREFSEFPARAM;
10468 message ("Macro parameter %q used more than once",
10469 uentry_getName (e)),
10470 uentry_whereDeclared (e)))
10472 e->info->var->kind = VKREFSEFPARAM;
10479 if ((dp = uentry_directParamNo (e)) >= 0)
10481 uentry_setUsed (usymtab_getParam (dp), loc);
10486 if (!sRef_isLocalVar (e->sref))
10490 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
10496 if (context_inMacro ())
10498 e->uses = filelocList_addUndefined (e->uses);
10502 e->uses = filelocList_addDifferentFile
10504 uentry_whereDeclared (e),
10513 bool uentry_isReturned (uentry u)
10515 return (uentry_isValid (u) && uentry_isVar (u)
10516 && (u->info->var->kind == VKRETPARAM
10517 || u->info->var->kind == VKSEFRETPARAM));
10520 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args)
10522 llassert (uentry_isRealFunction (u));
10524 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
10526 stateClauseList clauses = uentry_getStateClauseList (u);
10527 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10529 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
10530 sRef_setAllocated (res, g_currentloc);
10532 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10533 stateClauseList_unparse (clauses)));
10536 ** This should be in exprNode_reflectEnsuresClause
10539 stateClauseList_postElements (clauses, cl)
10541 if (!stateClause_isGlobal (cl))
10543 sRefSet refs = stateClause_getRefs (cl);
10544 sRefMod modf = stateClause_getEffectFunction (cl);
10546 sRefSet_elements (refs, el)
10548 sRef base = sRef_getRootBase (el);
10550 if (sRef_isResult (base))
10554 sRef sr = sRef_fixBase (el, res);
10555 modf (sr, g_currentloc);
10562 } end_sRefSet_elements ;
10564 } end_stateClauseList_postElements ;
10572 sRefSet prefs = sRefSet_new ();
10573 sRef res = sRef_undefined;
10576 params = uentry_getParams (u);
10578 uentryList_elements (params, current)
10580 if (uentry_isReturned (current))
10582 if (exprNodeList_size (args) >= paramno)
10584 exprNode ecur = exprNodeList_nth (args, paramno);
10585 sRef tref = exprNode_getSref (ecur);
10587 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10589 if (sRef_isValid (tref))
10591 sRef tcref = sRef_copy (tref);
10593 usymtab_addForceMustAlias (tcref, tref); /* evans 2001-05-27 */
10595 if (sRef_isDead (tcref))
10597 sRef_setDefined (tcref, g_currentloc);
10598 sRef_setOnly (tcref, g_currentloc);
10601 if (sRef_isRefCounted (tcref))
10603 /* could be a new ref now (but only if its returned) */
10604 sRef_setAliasKindComplete (tcref, AK_ERROR, g_currentloc);
10607 sRef_makeSafe (tcref);
10608 prefs = sRefSet_insert (prefs, tcref);
10614 } end_uentryList_elements ;
10616 if (sRefSet_size (prefs) > 0)
10618 nstate n = sRef_getNullState (u->sref);
10620 if (sRefSet_size (prefs) == 1)
10622 res = sRefSet_choose (prefs);
10626 /* should this ever happen? */ /*@i534 evans 2001-05-27 */
10627 res = sRefSet_mergeIntoOne (prefs);
10630 if (nstate_isKnown (n))
10632 sRef_setNullState (res, n, g_currentloc);
10637 if (ctype_isFunction (u->utype))
10639 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10640 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10644 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
10647 if (sRef_isRefCounted (res))
10649 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10654 if (sRef_getNullState (res) == NS_ABSNULL)
10656 ctype ct = ctype_realType (u->utype);
10658 if (ctype_isAbstract (ct))
10660 sRef_setNotNull (res, g_currentloc);
10664 if (ctype_isUser (ct))
10666 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
10670 sRef_setNotNull (res, g_currentloc);
10675 if (sRef_isRefCounted (res))
10677 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10679 else if (sRef_isKillRef (res))
10681 sRef_setAliasKind (res, AK_REFCOUNTED, g_currentloc);
10688 ak = sRef_getAliasKind (res);
10690 if (alkind_isImplicit (ak))
10692 sRef_setAliasKind (res,
10693 alkind_fixImplicit (ak),
10697 sRefSet_free (prefs);
10699 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
10704 static bool uentry_isRefCounted (uentry ue)
10706 ctype ct = uentry_getType (ue);
10708 if (ctype_isFunction (ct))
10710 return (ctype_isRefCounted (ctype_getReturnType (ct)));
10714 return (ctype_isRefCounted (ct));
10719 ** old was declared yield in the specification.
10720 ** new is declared in the iter implementation.
10723 void uentry_checkYieldParam (uentry old, uentry unew)
10727 llassert (uentry_isVariable (old));
10728 llassert (uentry_isVariable (unew));
10730 unew->info->var->kind = VKYIELDPARAM;
10731 (void) checkTypeConformance (old, unew, TRUE);
10732 checkVarConformance (old, unew, TRUE, FALSE);
10734 /* get rid of param marker */
10736 name = uentry_getName (unew);
10737 cstring_free (unew->uname);
10738 unew->uname = name;
10739 unew->info->var->kind = VKREFYIELDPARAM;
10741 uentry_setUsed (old, fileloc_undefined);
10742 uentry_setUsed (unew, fileloc_undefined);
10745 /*@observer@*/ cstring
10746 uentry_ekindName (uentry ue)
10748 if (uentry_isValid (ue))
10753 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
10755 return cstring_makeLiteralTemp ("Datatype");
10757 return cstring_makeLiteralTemp ("Enum member");
10759 return cstring_makeLiteralTemp ("Constant");
10761 if (uentry_isParam (ue))
10763 return cstring_makeLiteralTemp ("Parameter");
10765 else if (uentry_isExpandedMacro (ue))
10767 return cstring_makeLiteralTemp ("Expanded macro");
10771 return cstring_makeLiteralTemp ("Variable");
10774 return cstring_makeLiteralTemp ("Function");
10776 return cstring_makeLiteralTemp ("Iterator");
10778 return cstring_makeLiteralTemp ("Iterator finalizer");
10780 return cstring_makeLiteralTemp ("Struct tag");
10782 return cstring_makeLiteralTemp ("Union tag");
10784 return cstring_makeLiteralTemp ("Enum tag");
10786 return cstring_makeLiteralTemp ("Optional parameters");
10791 return cstring_makeLiteralTemp ("<Undefined>");
10797 /*@observer@*/ cstring
10798 uentry_ekindNameLC (uentry ue)
10800 if (uentry_isValid (ue))
10805 return cstring_makeLiteralTemp ("<error: invalid uentry>");
10807 return cstring_makeLiteralTemp ("datatype");
10809 return cstring_makeLiteralTemp ("enum member");
10811 return cstring_makeLiteralTemp ("constant");
10813 if (uentry_isParam (ue))
10815 return cstring_makeLiteralTemp ("parameter");
10817 else if (uentry_isExpandedMacro (ue))
10819 return cstring_makeLiteralTemp ("expanded macro");
10823 return cstring_makeLiteralTemp ("variable");
10826 return cstring_makeLiteralTemp ("function");
10828 return cstring_makeLiteralTemp ("iterator");
10830 return cstring_makeLiteralTemp ("iterator finalizer");
10832 return cstring_makeLiteralTemp ("struct tag");
10834 return cstring_makeLiteralTemp ("union tag");
10836 return cstring_makeLiteralTemp ("enum tag");
10838 return cstring_makeLiteralTemp ("optional parameters");
10843 return cstring_makeLiteralTemp ("<Undefined>");
10849 void uentry_setHasNameError (uentry ue)
10851 llassert (uentry_isValid (ue));
10853 ue->hasNameError = TRUE;
10856 void uentry_checkName (uentry ue)
10858 DPRINTF (("Checking name: %s / %s / %s", uentry_unparse (ue),
10859 uentry_observeRealName (ue),
10860 bool_unparse (uentry_isVisibleExternally (ue))));
10862 if (uentry_isValid (ue)
10863 && !context_inXHFile ()
10864 && uentry_hasName (ue)
10865 && !uentry_isElipsisMarker (ue)
10866 && context_getFlag (FLG_NAMECHECKS)
10867 && !ue->hasNameError
10868 && !uentry_isEndIter (ue)
10869 && !fileloc_isBuiltin (uentry_whereLast (ue))
10870 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
10872 DPRINTF (("Here..."));
10874 if (uentry_isPriv (ue))
10876 ; /* any checks here? */
10878 else if (fileloc_isExternal (uentry_whereDefined (ue)))
10880 ; /* no errors for externals */
10886 if (uentry_isExpandedMacro (ue))
10892 if (uentry_isExpandedMacro (ue))
10896 else if (uentry_isVariable (ue))
10898 sRef sr = uentry_getSref (ue);
10900 if (sRef_isValid (sr))
10902 scope = sRef_getScope (sr);
10909 else if (uentry_isFunction (ue)
10910 || uentry_isIter (ue)
10911 || uentry_isEndIter (ue)
10912 || uentry_isConstant (ue))
10914 scope = uentry_isStatic (ue) ? fileScope : globScope;
10916 else /* datatypes, etc. must be global */
10921 usymtab_checkDistinctName (ue, scope);
10924 if (context_getFlag (FLG_CPPNAMES))
10929 if (scope == globScope)
10931 checkExternalName (ue);
10933 else if (scope == fileScope)
10935 checkFileScopeName (ue);
10939 checkLocalName (ue);
10943 checkAnsiName (ue);
10948 /*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@only@*/ fileloc loc)
10954 ** Can't but unrecognized ids in macros in global scope, because srefs will break!
10957 if (!context_inMacro ())
10959 sRef_setGlobalScopeSafe ();
10962 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
10963 uentry_setUsed (ue, loc);
10965 tloc = fileloc_createExternal ();
10966 uentry_setDefined (ue, tloc);
10967 fileloc_free (tloc);
10968 uentry_setHasNameError (ue);
10970 if (context_getFlag (FLG_REPEATUNRECOG))
10972 uentry_markOwned (ue);
10976 ue = usymtab_supReturnFileEntry (ue);
10979 if (!context_inMacro ())
10981 sRef_clearGlobalScopeSafe ();
10987 uentry uentry_makeGlobalMarker ()
10992 llassert (sRef_inGlobalScope ());
10994 ue = uentry_makeVariableAux
10995 (GLOBAL_MARKER_NAME, ctype_unknown, fileloc_undefined,
10996 sRef_makeGlobalMarker (),
10999 tloc = fileloc_createExternal ();
11000 uentry_setUsed (ue, tloc);
11001 uentry_setDefined (ue, tloc);
11002 fileloc_free (tloc);
11003 uentry_setHasNameError (ue);
11009 bool uentry_isGlobalMarker (uentry ue)
11011 return (uentry_isValid (ue)
11012 && (cstring_equal (uentry_rawName (ue), GLOBAL_MARKER_NAME)));
11015 /* new start modifications */
11017 /* start modifications */
11019 requires: p_e is defined, is a ptr/array variable
11021 effects: sets the state of the variable
11025 void uentry_setPossiblyNullTerminatedState (uentry p_e) {
11026 /*@access sRef@*/ /*i523 shouldn't do this! */
11027 if( uentry_isValid(p_e) ) {
11028 if( p_e->info != NULL) {
11029 if( p_e->info->var != NULL) {
11030 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
11031 p_e->sref->bufinfo.bufstate = BB_POSSIBLYNULLTERMINATED;
11036 /*@noaccess sRef@*/
11038 fprintf(stderr, "uentry:Error in setPossiblyNullTerminatedState\n");
11042 requires: p_e is defined, is a ptr/array variable
11044 effects: sets the size of the buffer
11047 void uentry_setNullTerminatedState (uentry p_e) {
11048 if( uentry_isValid(p_e) ) {
11049 if( p_e->info != NULL) {
11050 if( p_e->info->var != NULL) {
11051 p_e->info->var->bufinfo->bufstate = BB_NULLTERMINATED;
11052 /*@access sRef@*/ /*@i523 bad!*/
11053 p_e->sref->bufinfo.bufstate = BB_NULLTERMINATED;
11054 /*@noaccess sRef@*/
11060 fprintf(stderr, "uentry:Error in setNullTerminatedState\n");
11064 requires: p_e is defined, is a ptr/array variable
11066 effects: sets the size of the buffer
11069 void uentry_setSize (uentry p_e, int size) {
11070 if( uentry_isValid(p_e) ) {
11071 if( p_e->info != NULL) {
11072 if( p_e->info->var != NULL) {
11073 p_e->info->var->bufinfo->size = size;
11074 /*@access sRef@*/ /*@i523 bad!*/
11075 p_e->sref->bufinfo.size = size;
11076 /*@noaccess sRef@*/
11082 fprintf(stderr, "uentry:Error in setSize\n");
11087 requires: p_e is defined, is a ptr/array variable
11089 effects: sets the length of the buffer
11092 void uentry_setLen (uentry p_e, int len) {
11093 if( uentry_isValid(p_e) ) {
11094 if( p_e->info != NULL) {
11095 if( p_e->info->var != NULL) {
11096 p_e->info->var->bufinfo->len = len;
11097 /*@access sRef@*/ /*@i523 bad!*/
11098 p_e->sref->bufinfo.len = len;
11099 /*@noaccess sRef@*/
11105 fprintf(stderr, "uentry:Error in setLen\n");
11110 bool uentry_hasMetaStateEnsures (uentry e)
11112 if (uentry_isValid (e) && uentry_isFunction (e))
11114 return functionConstraint_hasMetaStateConstraint (e->info->fcn->postconditions);
11122 metaStateConstraintList uentry_getMetaStateEnsures (uentry e)
11124 llassert (uentry_isValid (e) && uentry_isFunction (e));
11125 return functionConstraint_getMetaStateConstraints (e->info->fcn->postconditions);