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 /*@out@*/ /*@notnull@*/ uentry uentry_alloc (void) /*@*/
95 uentry ue = (uentry) dmalloc (sizeof (*ue));
96 ue->warn = warnClause_undefined; /*@i32@*/
103 static cstring uentry_getOptName (uentry p_e) /*@*/ ;
104 static void uentry_copyInto (/*@out@*/ /*@unique@*/ uentry p_unew, uentry p_old);
105 static void uentry_setNullState (/*@notnull@*/ uentry p_ue, nstate p_ns);
106 static void uentry_setAliasKind (/*@notnull@*/ uentry p_ue, alkind p_ak);
107 static /*@only@*/ /*@null@*/ uinfo uinfo_copy (uinfo p_u, ekind p_kind);
108 static void uinfo_free (/*@only@*/ uinfo p_u, ekind p_kind);
109 static void uvinfo_free (/*@only@*/ uvinfo p_u);
113 static /*@only@*/ cstring ancontext_unparse (ancontext an)
117 case AN_UNKNOWN: return cstring_makeLiteral ("unknown");
118 case AN_FCNRETURN: return cstring_makeLiteral ("return value");
119 case AN_FCNPARAM: return cstring_makeLiteral ("function param");
120 case AN_SUFIELD: return cstring_makeLiteral ("su field");
121 case AN_TDEFN: return cstring_makeLiteral ("type definition");
122 case AN_GSVAR: return cstring_makeLiteral ("global/static var");
123 case AN_CONST: return cstring_makeLiteral ("constant");
129 static int annots[AN_LAST][QU_LAST];
130 static int decls[AN_LAST];
131 static int shdecls[AN_LAST];
132 static int idecls[AN_LAST];
138 for (i = AN_UNKNOWN; i < AN_LAST; i++)
144 for (j = QU_UNKNOWN; j < QU_LAST; j++)
151 static void tallyAnnot (ancontext ac, qual q)
165 for (j = QU_UNKNOWN; j < QU_LAST; j++)
170 for (i = AN_UNKNOWN; i < AN_LAST; i++)
176 printf ("Context: %s (%d declarations, %d sharable, %d indirect)\n",
177 ancontext_unparse (i),
178 decls[i], shdecls[i], idecls[i]);
180 totdecls += decls[i];
181 totshdecls += shdecls[i];
182 totidecls += idecls[i];
184 for (j = QU_UNKNOWN; j < QU_LAST; j++)
186 total[j] += annots[i][j];
187 alltotals += annots[i][j];
190 printf (" Allocation:\n");
194 for (j = QU_UNKNOWN; j < QU_LAST; j++)
196 if (qual_isAliasQual (j) && !qual_isUnique (j))
198 if (annots[i][j] > 0)
200 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
201 100.0 * (double)annots[i][j] / (double)decls[i]);
202 tmptot += annots[i][j];
207 printf (" Exposure:\n");
211 for (j = QU_UNKNOWN; j < QU_LAST; j++)
213 if (qual_isExQual (j))
215 if (annots[i][j] > 0)
217 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
218 100.0 * (double)annots[i][j] / (double)decls[i]);
219 tmptot += annots[i][j];
224 printf (" Definition:\n");
226 for (j = QU_UNKNOWN; j < QU_LAST; j++)
228 if (qual_isAllocQual (j))
230 if (annots[i][j] > 0)
232 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
233 100.0 * (double)annots[i][j] / (double)decls[i]);
240 for (j = QU_UNKNOWN; j < QU_LAST; j++)
242 if (qual_isNull (j) || qual_isNotNull (j) || qual_isRelNull (j))
244 if (annots[i][j] > 0)
246 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
247 100.0 * (double)annots[i][j] / (double)decls[i]);
256 for (j = QU_UNKNOWN; j < QU_LAST; j++)
260 for (i = AN_UNKNOWN; i < AN_LAST; i++)
262 if (annots[i][j] > 0)
271 printf ("Annotation: %s\n", qual_unparse (j));
273 for (i = AN_UNKNOWN; i < AN_LAST; i++)
275 if (annots[i][j] > 0)
277 printf ("%25s: %5d\n", ancontext_unparse (i), annots[i][j]);
284 printf ("All Contexts\n");
286 for (j = QU_UNKNOWN; j < QU_LAST; j++)
290 printf ("%10s: %5d (%3.2f%%)\n", qual_unparse (j), total[j],
291 100.0 * (double)total[j] / (double)(totdecls));
296 printf ("Total Annotations: %d (%d decls, %d sharable, %d indirect)\n", alltotals, totdecls, totshdecls, totidecls); }
298 extern void uentry_tallyAnnots (uentry u, ancontext kind)
300 alkind ak = sRef_getAliasKind (u->sref);
301 exkind ek = sRef_getExKind (u->sref);
302 nstate ns = sRef_getNullState (u->sref);
303 sstate ss = sRef_getDefState (u->sref);
304 bool recordUnknown = FALSE;
306 if (kind == AN_UNKNOWN)
314 else if (e == KCONST || e == KENUMCONST)
318 else if (e == KFCN || e == KITER)
320 uentryList params = uentry_getParams (u);
323 uentryList_elements (params, current)
325 if (uentry_isReturned (current))
329 if (!uentry_isElipsisMarker (current))
331 uentry_tallyAnnots (current, AN_FCNPARAM);
333 } end_uentryList_elements;
337 if (ctype_isFunction (u->utype)
339 && ctype_isVisiblySharable (ctype_realType (ctype_getReturnType (u->utype))))
341 recordUnknown = TRUE;
344 else if (e == KDATATYPE || e == KSTRUCTTAG || e == KUNIONTAG || e == KENUMTAG)
346 ctype t = ctype_realType (u->utype);
350 uentryList fields = ctype_getFields (t);
352 uentryList_elements (fields, current)
354 uentry_tallyAnnots (current, AN_SUFIELD);
356 } end_uentryList_elements;
360 if (ctype_isVisiblySharable (u->utype))
362 recordUnknown = TRUE;
370 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
372 recordUnknown = TRUE;
379 if (kind == AN_FCNRETURN)
393 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
398 if (ctype_isRealPointer (ctype_realType (u->utype)))
406 case SS_ALLOCATED: tallyAnnot (kind, QU_OUT); break;
407 case SS_PARTIAL: tallyAnnot (kind, QU_PARTIAL); break;
408 case SS_RELDEF: tallyAnnot (kind, QU_RELDEF); break;
409 case SS_SPECIAL: tallyAnnot (kind, QU_SPECIAL); break;
413 if (uentry_isReturned (u))
415 tallyAnnot (kind, QU_RETURNED);
421 if (ctype_isRefCounted (ctype_realType (u->utype))
422 || (ctype_isFunction (u->utype) &&
423 ctype_isRefCounted (ctype_realType (ctype_getReturnType (u->utype)))))
429 if (kind == AN_FCNPARAM)
431 tallyAnnot (kind, QU_TEMP);
433 else if (recordUnknown)
435 if (kind == AN_FCNRETURN)
438 tallyAnnot (kind, QU_UNKNOWN);
442 case AK_ONLY: tallyAnnot (kind, QU_ONLY); break;
443 case AK_IMPONLY: tallyAnnot (kind, QU_ONLY); break;
444 case AK_KEEP: tallyAnnot (kind, QU_KEEP); break;
445 case AK_KEPT: tallyAnnot (kind, QU_KEPT); break;
447 case AK_TEMP: tallyAnnot (kind, QU_TEMP); break;
448 case AK_SHARED: tallyAnnot (kind, QU_SHARED); break;
449 case AK_UNIQUE: tallyAnnot (kind, QU_UNIQUE); break;
450 case AK_RETURNED: tallyAnnot (kind, QU_RETURNED); break;
451 case AK_REFCOUNTED: tallyAnnot (kind, QU_UNKNOWN); break;
452 case AK_REFS: tallyAnnot (kind, QU_REFS); break;
453 case AK_KILLREF: tallyAnnot (kind, QU_KILLREF); break;
454 case AK_NEWREF: tallyAnnot (kind, QU_NEWREF); break;
455 case AK_OWNED: tallyAnnot (kind, QU_OWNED); break;
456 case AK_IMPDEPENDENT:
457 case AK_DEPENDENT: tallyAnnot (kind, QU_DEPENDENT); break;
467 case XO_EXPOSED: tallyAnnot (kind, QU_EXPOSED); break;
468 case XO_OBSERVER: tallyAnnot (kind, QU_OBSERVER); break;
474 case NS_ERROR: break;
475 case NS_UNKNOWN: break;
476 case NS_NOTNULL: break;
477 case NS_MNOTNULL: tallyAnnot (kind, QU_NOTNULL); break;
478 case NS_RELNULL: tallyAnnot (kind, QU_RELNULL); break;
479 case NS_CONSTNULL: tallyAnnot (kind, QU_NULL); break;
480 case NS_POSNULL: tallyAnnot (kind, QU_NULL); break;
482 case NS_ABSNULL: break;
488 static /*@observer@*/ cstring specCode_unparse (specCode s) /*@*/
492 case SPC_NONE: return cstring_makeLiteralTemp ("normal");
493 case SPC_PRINTFLIKE: return cstring_makeLiteralTemp ("printflike");
494 case SPC_SCANFLIKE: return cstring_makeLiteralTemp ("scanflike");
495 case SPC_MESSAGELIKE: return cstring_makeLiteralTemp ("messagelike");
496 case SPC_LAST: return cstring_makeLiteralTemp ("<error>");
502 static specCode specCode_fromInt (int i)
505 llassert (i >= SPC_NONE && i < SPC_LAST);
507 return ((specCode) i);
511 /*@observer@*/ cstring uentry_specOrDefName (uentry u)
513 if (uentry_isDeclared (u))
515 return cstring_makeLiteralTemp ("previously declared");
519 return cstring_makeLiteralTemp ("specified");
523 /*@observer@*/ cstring uentry_specDeclName (uentry u)
525 if (uentry_isDeclared (u))
527 return cstring_makeLiteralTemp ("previous declaration");
531 return cstring_makeLiteralTemp ("specification");
535 static /*@observer@*/ cstring uentry_reDefDecl (uentry old, uentry unew) /*@*/
537 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
539 return cstring_makeLiteralTemp ("redefined");
541 else if (uentry_isCodeDefined (unew))
543 return cstring_makeLiteralTemp ("defined");
545 else if (uentry_isDeclared (old) && uentry_isDeclared (unew))
547 return cstring_makeLiteralTemp ("redeclared");
551 return cstring_makeLiteralTemp ("declared");
557 /*@only@*/ constraintList uentry_getFcnPreconditions (uentry ue)
559 if (uentry_isValid (ue))
562 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
564 DPRINTF(( (message( "Function pointer %s not doing uentry_getFcnPreconditions", uentry_unparse(ue) )) ));
565 // uentry_makeVarFunction (ue);
568 //llassert (uentry_isFunction (ue));
569 //llassert ((ue->info->fcn->preconditions));
570 //llassert ((ue->info->fcn->preconditions));
572 if (!uentry_isFunction (ue))
574 DPRINTF( (message ("called uentry_getFcnPreconditions on nonfunction %s",
575 uentry_unparse (ue) ) ) );
576 if (!uentry_isSpecified (ue) )
578 DPRINTF((message ("called uentry_getFcnPreconditions on nonfunction %s",
579 uentry_unparse (ue) ) ));
580 return constraintList_undefined;
584 return constraintList_undefined;
587 if (functionConstraint_hasBufferConstraint (ue->info->fcn->preconditions))
589 return constraintList_copy (functionConstraint_getBufferConstraint (ue->info->fcn->preconditions));
598 return constraintList_undefined;
607 constraintList uentry_getFcnPostconditions (uentry ue)
609 if (uentry_isValid (ue))
611 DPRINTF( (message ("called uentry_getFcnPostconditions on %s",
612 uentry_unparse (ue) ) ) );
614 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
616 DPRINTF( (message ("called uentry_getFcnPostconditions on nonfunction %s",
617 uentry_unparse (ue) ) ) );
618 if (!uentry_isFunction (ue) )
620 DPRINTF((message ("called uentry_getFcnPostconditions on nonfunction %s",
621 uentry_unparse (ue) ) ));
622 return constraintList_undefined;
626 return constraintList_undefined;
629 // llassert (uentry_isFunction (ue));
630 if (!uentry_isFunction(ue) )
633 DPRINTF( (message ("called uentry_getFcnPostconditions on non function %s",
634 uentry_unparse (ue) ) ) );
635 return constraintList_undefined;
639 if (functionConstraint_hasBufferConstraint (ue->info->fcn->postconditions))
641 DPRINTF((message ("called uentry_getFcnPostconditions on %s and returned %q",
643 constraintList_unparse (functionConstraint_getBufferConstraint (ue->info->fcn->postconditions)))));
645 return constraintList_copy (functionConstraint_getBufferConstraint (ue->info->fcn->postconditions));
655 return constraintList_undefined;
660 static /*@only@*/ fileloc setLocation (void)
662 fileloc fl = context_getSaveLocation ();
664 if (fileloc_isDefined (fl))
670 return fileloc_copy (g_currentloc);
674 /*@notnull@*/ uentry uentry_makeEnumConstant (cstring n, ctype t)
676 fileloc loc = setLocation ();
677 uentry ue = uentry_makeConstant (n, t, loc);
679 ue->ukind = KENUMCONST;
680 uentry_setDefined (ue, loc);
684 /*@notnull@*/ uentry uentry_makeEnumInitializedConstant (cstring n, ctype t, exprNode expr)
686 fileloc loc = setLocation ();
687 uentry ue = uentry_makeConstant (n, t, loc);
688 ctype etype = exprNode_getType (expr);
690 if (!ctype_isRealInt (etype)) {
694 ("Value of enum member is not an integeral type (type %s): %s",
695 ctype_unparse (etype), exprNode_unparse (expr)),
696 exprNode_loc (expr));
699 ue->ukind = KENUMCONST;
700 uentry_setDefined (ue, loc);
705 /*@notnull@*/ uentry uentry_makeSpecEnumConstant (cstring n, ctype t, fileloc loc)
707 uentry ue = uentry_makeConstant (n, t, loc);
709 ue->ukind = KENUMCONST;
714 /*@notnull@*/ uentry uentry_makeVariableLoc (cstring n, ctype t)
716 return uentry_makeVariable (n, t, setLocation (), FALSE);
720 /*@notnull@*/ /*@only@*/ uentry uentry_makeUnnamedVariable (ctype t)
722 return uentry_makeVariable (cstring_undefined, t, setLocation (), FALSE);
726 /*@notnull@*/ uentry uentry_makeIdDatatype (idDecl id)
728 ctype ct = idDecl_getCtype (id);
729 uentry ue = uentry_makeDatatype (idDecl_observeId (id), ct,
730 MAYBE, MAYBE, setLocation ());
732 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
734 if (!ynm_isOn (ue->info->datatype->abs))
736 if (ctype_isUnknown (ct))
738 ue->info->datatype->mut = MAYBE;
742 ue->info->datatype->mut = ynm_fromBool (ctype_isMutable (ct));
749 void uentry_checkParams (uentry ue)
751 if (uentry_isValid (ue))
753 bool isExt = uentry_isExtern (ue);
755 if (uentry_isRealFunction (ue))
757 uentryList params = uentry_getParams (ue);
759 uentryList_elements (params, current)
761 if (uentry_isValid (current))
763 ctype ct = current->utype;
765 if (ctype_isFixedArray (ct))
767 if (ctype_isArray (ctype_baseArrayPtr (ct))
768 && !ctype_isFixedArray (ctype_baseArrayPtr (ct)))
775 (FLG_FIXEDFORMALARRAY,
776 message ("Function parameter %q declared as "
777 "manifest array (size constant is meaningless)",
778 uentry_getName (current)),
779 uentry_whereDeclared (current));
784 if (ctype_isArray (ct))
788 message ("Function parameter %q declared as "
789 "array (treated as pointer)",
790 uentry_getName (current)),
791 uentry_whereDeclared (current));
795 if (sRef_getNullState (uentry_getSref (current)) == NS_MNOTNULL)
797 if (ctype_isAbstract (ct) &&
798 (isExt || (ctype_isAbstract (ctype_realType (ct))
799 && !context_hasFileAccess (ctype_typeId (ct)))))
804 ("Function %q declared with notnull parameter %q of abstract "
807 uentry_getName (current),
810 ("Since %s is an abstract type, notnull can only be "
811 "used for parameters if the function is static to a "
812 "module where %s is accessible.",
815 uentry_whereDeclared (current));
819 } end_uentryList_elements;
821 if (sRef_getNullState (uentry_getSref (ue)) == NS_MNOTNULL)
823 ctype ct = ue->utype;
825 if (ctype_isAbstract (ct)
826 && (isExt || (ctype_isAbstract (ctype_realType (ct))
827 && !context_hasFileAccess (ctype_typeId (ct)))))
832 ("%s %q declared %s notnull storage of abstract type %s",
833 ekind_capName (uentry_getKind (ue)),
838 ("Since %s is an abstract type, notnull can only be used "
839 "if it is static to a module where %s is accessible.",
842 uentry_whereDeclared (ue));
849 static void reflectImplicitFunctionQualifiers (/*@notnull@*/ uentry ue, bool spec)
851 alkind ak = sRef_getAliasKind (ue->sref);
853 if (alkind_isRefCounted (ak))
855 sRef_setAliasKind (ue->sref, AK_NEWREF, fileloc_undefined);
859 if (alkind_isUnknown (ak))
861 exkind ek = sRef_getExKind (ue->sref);
863 if (exkind_isKnown (ek))
865 DPRINTF (("Setting imp dependent: %s",
866 uentry_unparseFull (ue)));
867 sRef_setAliasKind (ue->sref, AK_IMPDEPENDENT, fileloc_undefined);
871 if (context_getFlag (spec ? FLG_SPECRETIMPONLY : FLG_RETIMPONLY))
873 /* evans 2000-12-22 removed ctype_realType so it will
874 not apply to immutable abstract types. */
876 if (ctype_isVisiblySharable
877 (ctype_realType (ctype_getReturnType (ue->utype))))
879 if (uentryList_hasReturned (uentry_getParams (ue)))
885 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
887 ; /* Immutable objects are not shared. */
891 sRef_setAliasKind (ue->sref, AK_IMPONLY,
893 DPRINTF (("Ret imp only: %s",
894 ctype_unparse (ctype_getReturnType (ue->utype))));
904 static /*@notnull@*/ uentry
905 uentry_makeFunctionAux (cstring n, ctype t,
907 /*@only@*/ globSet globs,
908 /*@only@*/ sRefSet mods,
909 /*@only@*/ warnClause warn,
910 /*@keep@*/ fileloc f, bool priv,
911 /*@unused@*/ bool isForward)
913 uentry e = uentry_alloc ();
916 llassert (warnClause_isUndefined (warn)); /*@i325 remove parameter! */
918 if (ctype_isFunction (t))
920 ret = ctype_getReturnType (t);
924 if (ctype_isKnown (t))
926 llbug (message ("not function: %s", ctype_unparse (t)));
933 if (fileloc_isSpec (f) || fileloc_isImport (f))
935 e->whereSpecified = f;
936 e->whereDeclared = fileloc_undefined;
940 e->whereSpecified = fileloc_undefined;
941 e->whereDeclared = f;
944 /* e->shallowCopy = FALSE; */
945 e->uname = cstring_copy (n);
947 e->storageclass = SCNONE;
949 e->sref = sRef_makeType (ret);
951 if (ctype_isUA (ret))
953 sRef_setStateFromType (e->sref, ret);
958 e->uses = filelocList_new ();
960 e->hasNameError = FALSE;
964 e->info = (uinfo) dmalloc (sizeof (*e->info));
965 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
967 e->info->fcn->hasMods = sRefSet_isDefined (mods);
968 e->info->fcn->hasGlobs = globSet_isDefined (globs);
970 e->info->fcn->exitCode = XK_UNKNOWN;
971 e->info->fcn->nullPred = qual_createUnknown ();
972 e->info->fcn->specialCode = SPC_NONE;
974 e->info->fcn->access = access;
975 e->info->fcn->globs = globs;
976 e->info->fcn->defparams = uentryList_undefined;
978 sRef_setDefined (e->sref, f);
979 e->whereDefined = fileloc_undefined;
981 e->info->fcn->mods = sRefSet_undefined;
982 e->info->fcn->specclauses = NULL;
985 e->info->fcn->preconditions = NULL;
989 e->info->fcn->postconditions = NULL;
992 checkGlobalsModifies (e, mods);
993 e->info->fcn->mods = mods;
998 static void uentry_reflectClauses (uentry ue, functionClauseList clauses)
1000 functionClauseList_elements (clauses, el)
1002 DPRINTF (("Reflect clause: %s on %s",
1003 functionClause_unparse (el), uentry_getName (ue)));
1005 if (functionClause_isNoMods (el))
1007 modifiesClause mel = functionClause_getModifies (el);
1009 if (uentry_hasGlobs (ue))
1014 ("No globals and modifies inconsistent to globals clause for %q: %q",
1015 uentry_getName (ue),
1016 globSet_unparse (uentry_getGlobs (ue))),
1017 modifiesClause_getLoc (mel));
1021 if (uentry_hasMods (ue))
1026 ("No globals and modifies inconsistent to modifies clause for %q: %q",
1027 uentry_getName (ue),
1028 sRefSet_unparse (uentry_getMods (ue))),
1029 modifiesClause_getLoc (mel));
1032 uentry_setGlobals (ue, globSet_undefined);
1033 uentry_setModifies (ue, sRefSet_undefined);
1035 else if (functionClause_isGlobals (el))
1037 globalsClause glc = functionClause_getGlobals (el);
1039 DPRINTF (("Globals: %s / %s", uentry_unparse (ue),
1040 globalsClause_unparse (glc)));
1042 if (uentry_hasGlobs (ue))
1047 ("Multiple globals clauses for %q: %q",
1048 uentry_getName (ue),
1049 globalsClause_unparse (glc)),
1050 globalsClause_getLoc (glc));
1051 uentry_setGlobals (ue, globalsClause_takeGlobs (glc)); /*@i32@*/
1055 uentry_setGlobals (ue, globalsClause_takeGlobs (glc));
1058 else if (functionClause_isModifies (el))
1060 modifiesClause mlc = functionClause_getModifies (el);
1062 DPRINTF (("Has modifies: %s", uentry_unparseFull (ue)));
1064 if (uentry_hasMods (ue))
1072 ("Multiple modifies clauses for %s: %s",
1073 uentry_getName (ue),
1074 modifiesClause_unparse (mlc)),
1075 modifiesClause_getLoc (mlc)))
1077 llhint (message ("Previous modifies clause: ",
1078 sRefSet_unparse (uentry_getMods (ue))));
1084 uentry_combineModifies (ue, modifiesClause_takeMods (mlc)); /*@i32@*/
1088 uentry_setModifies (ue, modifiesClause_takeMods (mlc));
1091 else if (functionClause_isEnsures (el))
1093 functionConstraint cl = functionClause_takeEnsures (el);
1094 DPRINTF (("Setting post: %s / %s",
1095 uentry_unparse (ue), functionConstraint_unparse (cl)));
1096 uentry_setPostconditions (ue, cl);
1098 else if (functionClause_isRequires (el))
1100 functionConstraint cl = functionClause_takeRequires (el);
1101 uentry_setPreconditions (ue, cl);
1103 else if (functionClause_isState (el))
1105 stateClause sc = functionClause_takeState (el);
1106 uentry_addStateClause (ue, sc);
1108 else if (functionClause_isWarn (el))
1110 warnClause wc = functionClause_takeWarn (el);
1111 uentry_addWarning (ue, wc);
1115 DPRINTF (("Unhandled clause: %s", functionClause_unparse (el)));
1117 } end_functionClauseList_elements ;
1119 stateClauseList_checkAll (ue);
1122 /*@notnull@*/ uentry uentry_makeIdFunction (idDecl id)
1124 bool leaveFunc = FALSE;
1126 uentry_makeFunction (idDecl_observeId (id), idDecl_getCtype (id),
1127 typeId_invalid, globSet_undefined,
1128 sRefSet_undefined, warnClause_undefined,
1132 ** This makes parameters names print out correctly.
1133 ** (But we might be a local variable declaration for a function type...)
1136 if (context_inFunctionLike ())
1138 DPRINTF (("Header: %s / %s",
1139 uentry_unparse (context_getHeader ()),
1140 idDecl_unparse (id)));
1144 context_enterFunctionDeclaration (ue);
1148 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
1149 reflectImplicitFunctionQualifiers (ue, FALSE);
1151 uentry_reflectClauses (ue, idDecl_getClauses (id));
1153 if (!uentry_isStatic (ue)
1154 && cstring_equalLit (ue->uname, "main"))
1156 ctype typ = ue->utype;
1160 llassert (ctype_isFunction (typ));
1162 retval = ctype_getReturnType (typ);
1164 if (!ctype_isInt (retval))
1168 message ("Function main declared to return %s, should return int",
1169 ctype_unparse (retval)),
1170 uentry_whereDeclared (ue));
1173 args = ctype_argsFunction (typ);
1175 if (uentryList_isMissingParams (args)
1176 || uentryList_size (args) == 0)
1182 if (uentryList_size (args) != 2)
1186 message ("Function main declared with %d arg%&, "
1187 "should have 2 (int argc, char *argv[])",
1188 uentryList_size (args)),
1189 uentry_whereLast (ue));
1193 uentry arg = uentryList_getN (args, 0);
1194 ctype ct = uentry_getType (arg);
1196 if (!ctype_isInt (ct))
1200 message ("Parameter 1, %q, of function main declared "
1201 "with type %t, should have type int",
1202 uentry_getName (arg), ct),
1203 uentry_whereDeclared (arg));
1206 arg = uentryList_getN (args, 1);
1207 ct = uentry_getType (arg);
1209 if (ctype_isArrayPtr (ct)
1210 && ctype_isArrayPtr (ctype_baseArrayPtr (ct))
1211 && ctype_isChar (ctype_baseArrayPtr (ctype_baseArrayPtr (ct))))
1219 message ("Parameter 2, %q, of function main declared "
1220 "with type %t, should have type char **",
1221 uentry_getName (arg), ct),
1222 uentry_whereDeclared (arg));
1230 context_exitFunctionDeclaration ();
1236 static void uentry_implicitParamAnnots (/*@notnull@*/ uentry e)
1238 alkind ak = sRef_getAliasKind (e->sref);
1240 if ((alkind_isUnknown (ak) || alkind_isImplicit (ak))
1241 && context_getFlag (FLG_PARAMIMPTEMP))
1243 exkind ek = sRef_getExKind (e->sref);
1245 if (exkind_isKnown (ek))
1247 DPRINTF (("imp dep: %s", uentry_unparseFull (e)));
1248 sRef_setAliasKind (e->sref, AK_IMPDEPENDENT, fileloc_undefined);
1249 sRef_setOrigAliasKind (e->sref, AK_IMPDEPENDENT);
1253 sRef_setAliasKind (e->sref, AK_IMPTEMP, fileloc_undefined);
1254 sRef_setOrigAliasKind (e->sref, AK_IMPTEMP);
1259 static /*@only@*/ /*@notnull@*/ uentry
1260 uentry_makeVariableParamAux (cstring n, ctype t, /*@dependent@*/ sRef s, sstate defstate) /*@i32 exposed*/
1262 cstring pname = makeParam (n);
1265 DPRINTF (("Sref: %s", sRef_unparseFull (s)));
1266 e = uentry_makeVariableAux (pname, t, setLocation (), s, FALSE, VKPARAM);
1268 cstring_free (pname);
1269 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1270 uentry_implicitParamAnnots (e);
1271 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1273 if (!sRef_isAllocated (e->sref) && !sRef_isPartial (e->sref))
1275 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1276 sRef_setDefState (e->sref, defstate, uentry_whereDeclared (e));
1277 e->info->var->defstate = defstate;
1280 DPRINTF (("Param: %s", uentry_unparseFull (e)));
1286 uentry_setRefCounted (uentry e)
1288 if (uentry_isValid (e))
1290 uentry_setAliasKind (e, AK_REFCOUNTED);
1291 sRef_storeState (e->sref);
1297 uentry_setStatic (uentry c)
1299 if (uentry_isValid (c))
1301 alkind ak = sRef_getAliasKind (c->sref);
1302 c->storageclass = SCSTATIC;
1304 if (uentry_isVariable (c) && !ctype_isFunction (uentry_getType (c)))
1306 if (!alkind_isUnknown (ak)
1307 && !alkind_isStatic (ak))
1309 if (!(ctype_isRealPointer (uentry_getType (c)))
1310 && !(ctype_isAbstract (ctype_realType (uentry_getType (c))))
1311 && !alkind_isRefCounted (ak))
1313 if (alkind_isImplicit (ak)
1314 && alkind_isDependent (ak)
1315 && ctype_isArray (uentry_getType (c)))
1317 ; /* no error for observer arrays */
1323 message ("Static storage %q declared as %s",
1325 alkind_unparse (ak)),
1326 uentry_whereDeclared (c));
1332 if (alkind_isUnknown (ak)
1333 || (alkind_isImplicit (sRef_getAliasKind (c->sref))
1334 && !alkind_isDependent (sRef_getAliasKind (c->sref))))
1336 sRef_setAliasKind (c->sref, AK_STATIC, fileloc_undefined);
1337 sRef_setOrigAliasKind (c->sref, AK_STATIC);
1345 uentry_setExtern (uentry c)
1347 if (uentry_isValid (c))
1348 c->storageclass = SCEXTERN;
1352 uentry_setParamNo (uentry ue, int pno)
1354 llassert (uentry_isAnyParam (ue) && sRef_isParam (ue->sref));
1355 sRef_setParamNo (ue->sref, pno);
1359 void checkGlobalsModifies (/*@notnull@*/ uentry ue, sRefSet sr)
1361 sRefSet_allElements (sr, el)
1363 sRef base = sRef_getRootBase (el);
1365 if (sRef_isFileOrGlobalScope (base) || sRef_isInternalState (base)
1366 || (sRef_isKindSpecial (base) && !sRef_isNothing (base)))
1368 if (!globSet_member (ue->info->fcn->globs, base))
1370 if (uentry_hasGlobs (ue)
1371 || context_getFlag (FLG_WARNMISSINGGLOBALSNOGLOBS))
1374 (FLG_WARNMISSINGGLOBALS,
1376 ("Modifies list for %q uses global %q, "
1377 "not included in globals list.",
1378 uentry_getName (ue),
1379 sRef_unparse (base)),
1380 uentry_whereLast (ue)))
1382 uentry_showWhereSpecified (ue);
1386 ue->info->fcn->globs = globSet_insert (ue->info->fcn->globs,
1388 if (sRef_isFileStatic (base))
1390 context_recordFileGlobals (ue->info->fcn->globs);
1394 } end_sRefSet_allElements;
1398 uentry_makeVariableSrefParam (cstring n, ctype t, /*@exposed@*/ sRef s)
1400 return (uentry_makeVariableParamAux (n, t, s, SS_UNKNOWN));
1404 uentry_fixupSref (uentry ue)
1408 if (uentry_isUndefined (ue) || uentry_isElipsisMarker (ue))
1413 sr = uentry_getSref (ue);
1415 sRef_resetState (sr);
1416 sRef_clearDerived (sr);
1418 llassertprint (uentry_isVariable (ue), ("fixing: %s", uentry_unparseFull (ue)));
1419 llassert (sRef_isValid (sr));
1421 if (uentry_isVariable (ue))
1423 sRef_setDefState (sr, ue->info->var->defstate, fileloc_undefined);
1424 sRef_setNullState (sr, ue->info->var->nullstate, fileloc_undefined);
1428 static void uentry_addStateClause (uentry ue, stateClause sc)
1431 ** Okay to allow multiple clauses of the same kind.
1432 */ /*@i834 is this true?@*/
1434 ue->info->fcn->specclauses =
1435 stateClauseList_add (ue->info->fcn->specclauses, sc);
1437 /* Will call checkAll to check later... */
1440 void uentry_setStateClauseList (uentry ue, stateClauseList clauses)
1442 llassert (uentry_isFunction (ue));
1443 llassert (!stateClauseList_isDefined (ue->info->fcn->specclauses));
1445 DPRINTF (("checked clauses: %s", stateClauseList_unparse (clauses)));
1446 ue->info->fcn->specclauses = clauses;
1447 stateClauseList_checkAll (ue);
1448 DPRINTF (("checked clauses: %s", uentry_unparseFull (ue)));
1452 ** Used for @modifies@ @endmodifies@ syntax.
1454 ** If ue is specified, sr must contain *only*:
1456 ** o file static globals
1457 ** o sRef's derived from modifies spec (i.e., more specific than
1458 ** what was specified)
1460 ** Otherwise, if sr has modifies it must match sr.
1462 ** If it doesn't have modifies, set them to sr.
1466 uentry_checkModifiesContext (void)
1468 if (sRef_modInFunction ())
1472 ("Modifies list not in function context. "
1473 "A modifies list can only appear following the parameter list "
1474 "in a function declaration or header."));
1483 uentry_setModifies (uentry ue, /*@owned@*/ sRefSet sr)
1485 if (!uentry_checkModifiesContext ())
1491 if (uentry_isValid (ue))
1493 if (uentry_isIter (ue))
1495 llassert (sRefSet_isUndefined (ue->info->iter->mods));
1496 ue->info->iter->mods = sr;
1500 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
1502 uentry_makeVarFunction (ue);
1505 llassertfatal (uentry_isFunction (ue));
1506 llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1508 ue->info->fcn->mods = sr;
1509 ue->info->fcn->hasMods = TRUE;
1511 checkGlobalsModifies (ue, sr);
1514 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1516 ue->info->fcn->hasGlobs = TRUE;
1519 if (sRefSet_hasStatic (ue->info->fcn->mods))
1521 context_recordFileModifies (ue->info->fcn->mods);
1531 uentry_combineModifies (uentry ue, /*@owned@*/ sRefSet sr)
1534 ** Function already has one modifies clause (possibly from
1535 ** a specification).
1538 if (!uentry_checkModifiesContext ())
1543 llassert (uentry_isValid (ue));
1545 if (uentry_isIter (ue))
1547 ue->info->iter->mods = sRefSet_unionFree (ue->info->iter->mods, sr);
1551 llassertfatal (uentry_isFunction (ue));
1552 llassert (ue->info->fcn->hasMods);
1554 checkGlobalsModifies (ue, sr);
1555 ue->info->fcn->mods = sRefSet_unionFree (ue->info->fcn->mods, sr);
1557 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1559 ue->info->fcn->hasGlobs = TRUE;
1563 if (sRefSet_hasStatic (ue->info->fcn->mods))
1565 context_recordFileModifies (ue->info->fcn->mods);
1569 bool uentry_hasWarning (uentry ue)
1571 return (uentry_isValid (ue)
1572 && warnClause_isDefined (ue->warn));
1575 void uentry_addWarning (uentry ue, /*@only@*/ warnClause warn)
1577 llassert (warnClause_isUndefined (ue->warn));
1582 uentry_setPreconditions (uentry ue, /*@only@*/ functionConstraint preconditions)
1584 if (sRef_modInFunction ())
1587 (message ("Precondition list not in function context. "
1588 "A precondition list can only appear following the parameter list "
1589 "in a function declaration or header."));
1591 /*@-mustfree@*/ return; /*@=mustfree@*/
1594 if (uentry_isValid (ue))
1597 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
1599 uentry_makeVarFunction (ue);
1602 llassertfatal (uentry_isFunction (ue));
1604 if (functionConstraint_isDefined (ue->info->fcn->preconditions))
1606 BADBRANCH; /* should conjoin constraints? */
1607 ue->info->fcn->preconditions = functionConstraint_conjoin (ue->info->fcn->preconditions, preconditions);
1611 ue->info->fcn->preconditions = preconditions;
1618 llfatalbug ( (message("uentry_setPreconditions called with invalid uentry") ));
1627 uentry_setPostconditions (uentry ue, /*@only@*/ functionConstraint postconditions)
1629 if (sRef_modInFunction ())
1632 (message ("Postcondition list not in function context. "
1633 "A postcondition list can only appear following the parameter list "
1634 "in a function declaration or header."));
1636 /*@-mustfree@*/ return; /*@=mustfree@*/
1639 if (uentry_isValid (ue))
1642 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
1644 uentry_makeVarFunction (ue);
1647 llassertfatal (uentry_isFunction (ue));
1649 if (functionConstraint_isUndefined (ue->info->fcn->postconditions))
1651 ue->info->fcn->postconditions = postconditions;
1655 BADBRANCH; /* should conjoin */
1656 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 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2349 uentry_makeVarFunction (ue);
2352 if (uentry_isFunction (ue))
2354 ctype typ = uentry_getType (ue);
2355 ctype rtype = ctype_getReturnType (uentry_getType (ue));
2357 if (ctype_isRealBool (rtype))
2359 uentryList pl = ctype_argsFunction (typ);
2361 if (uentryList_size (pl) == 1)
2363 ue->info->fcn->nullPred = qel;
2367 voptgenerror (FLG_ANNOTATIONERROR,
2368 message ("Qualifier %s used with function having %d "
2369 "arguments (should have 1)",
2371 uentryList_size (pl)),
2372 uentry_whereLast (ue));
2377 voptgenerror (FLG_ANNOTATIONERROR,
2378 message ("Qualifier %s used with function returning %s "
2379 "(should return bool)",
2381 ctype_unparse (rtype)),
2382 uentry_whereLast (ue));
2387 voptgenerror (FLG_ANNOTATIONERROR,
2388 message ("Qualifier %s used with non-function",
2389 qual_unparse (qel)),
2390 uentry_whereLast (ue));
2393 else if (qual_isExitQual (qel))
2395 exitkind exk = exitkind_fromQual (qel);
2397 if (uentry_isFunction (ue))
2399 if (exitkind_isKnown (ue->info->fcn->exitCode))
2401 voptgenerror (FLG_ANNOTATIONERROR,
2402 message ("Multiple exit qualifiers used on function %q: %s, %s",
2403 uentry_getName (ue),
2404 exitkind_unparse (ue->info->fcn->exitCode),
2405 exitkind_unparse (exk)),
2406 uentry_whereLast (ue));
2409 ue->info->fcn->exitCode = exk;
2413 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2415 uentry_makeVarFunction (ue);
2416 ue->info->fcn->exitCode = exk;
2420 voptgenerror (FLG_ANNOTATIONERROR,
2421 message ("Exit qualifier %s used with non-function (type %s)",
2423 ctype_unparse (uentry_getType (ue))),
2424 uentry_whereLast (ue));
2428 else if (qual_isMetaState (qel))
2430 annotationInfo ainfo = qual_getAnnotationInfo (qel);
2432 if (annotationInfo_matchesContext (ainfo, ue))
2434 DPRINTF (("Reflecting %s on %s",
2435 annotationInfo_unparse (ainfo),
2436 uentry_unparseFull (ue)));
2438 sRef_reflectAnnotation (ue->sref, ainfo, g_currentloc);
2439 DPRINTF (("==> %s", sRef_unparseFull (ue->sref)));
2440 DPRINTF (("==> %s", uentry_unparseFull (ue)));
2445 (FLG_ANNOTATIONERROR,
2446 message ("Meta state anntation %s used in inconsistent context: %q",
2448 uentry_unparse (ue)),
2449 uentry_whereLast (ue)))
2451 /*@i! annotationInfo_showContextError (ainfo, ue); */
2457 if (qual_isCQual (qel))
2463 llbug (message ("Unhandled qualifier: %s", qual_unparse (qel)));
2469 uentry_reflectQualifiers (uentry ue, qualList q)
2471 llassert (uentry_isValid (ue));
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;
2796 uentry_isOnly (uentry ue)
2798 return (!uentry_isUndefined (ue)
2799 && uentry_isVariable (ue)
2800 && alkind_isOnly (sRef_getOrigAliasKind (ue->sref)));
2804 uentry_setAliasKind (/*@notnull@*/ uentry ue, alkind ak)
2806 sRef_setAliasKind (ue->sref, ak, uentry_whereDeclared (ue));
2807 sRef_setOrigAliasKind (ue->sref, ak);
2811 uentry_setNullState (/*@notnull@*/ uentry ue, nstate ns)
2813 if (uentry_isVariable (ue))
2815 ue->info->var->nullstate = ns;
2818 sRef_setNullState (ue->sref, ns, uentry_whereDeclared (ue));
2822 uentry_isUnique (uentry ue)
2824 return (!uentry_isUndefined (ue)
2825 && uentry_isVariable (ue)
2826 && alkind_isUnique (sRef_getOrigAliasKind (ue->sref)));
2830 uentry_isFileStatic (uentry ue)
2832 return (uentry_isStatic (ue)
2833 && (!uentry_isVariable (ue)
2834 || sRef_isFileStatic (uentry_getSref (ue))));
2838 uentry_isExported (uentry ue)
2840 if (uentry_isValid (ue))
2842 if (uentry_isVariable (ue))
2844 return (sRef_isRealGlobal (uentry_getSref (ue)));
2848 return !uentry_isStatic (ue);
2856 uentry_isNonLocal (uentry ue)
2858 return (uentry_isValid (ue) && uentry_isVariable (ue)
2859 && (sRef_isFileOrGlobalScope (ue->sref) || uentry_isStatic (ue)));
2863 uentry_isGlobalVariable (uentry ue)
2865 return (uentry_isValid (ue) && uentry_isVariable (ue)
2866 && sRef_isFileOrGlobalScope (ue->sref));
2870 uentry_isVisibleExternally (uentry ue)
2872 return (uentry_isValid (ue)
2873 && ((uentry_isVariable (ue) && sRef_isRealGlobal (ue->sref))
2874 || (!uentry_isStatic (ue)
2875 && (uentry_isFunction (ue)
2876 || uentry_isIter (ue)
2877 || uentry_isEndIter (ue)
2878 || uentry_isConstant (ue)
2879 || uentry_isDatatype (ue)
2880 || uentry_isAnyTag (ue)))));
2884 uentry_isPrintfLike (uentry ue)
2886 return (uentry_isFunction (ue)
2887 && (ue->info->fcn->specialCode == SPC_PRINTFLIKE));
2891 uentry_isScanfLike (uentry ue)
2893 return (uentry_isFunction (ue)
2894 && (ue->info->fcn->specialCode == SPC_SCANFLIKE));
2898 uentry_isMessageLike (uentry ue)
2900 return (uentry_isFunction (ue)
2901 && (ue->info->fcn->specialCode == SPC_MESSAGELIKE));
2904 static void checkSpecialFunction (/*@notnull@*/ uentry ue)
2906 uentryList args = uentry_getParams (ue);
2908 if (!uentryList_isMissingParams (args))
2910 uentry last = uentry_undefined;
2912 uentryList_elements (args, current)
2914 if (uentry_isElipsisMarker (current))
2916 if (uentry_isUndefined (last))
2920 message ("Function %q is marked %s, but has no format "
2921 "string argument before elipsis",
2922 uentry_getName (ue),
2923 specCode_unparse (ue->info->fcn->specialCode)),
2924 uentry_whereLast (ue));
2925 ue->info->fcn->specialCode = SPC_NONE;
2929 ctype rt = ctype_realType (uentry_getType (last));
2931 if (!ctype_match (rt, ctype_string))
2935 /* wchar_t * is okay too */
2936 if (ctype_isAP (rt))
2938 ctype base = ctype_baseArrayPtr (rt);
2940 if (ctype_isArbitraryIntegral (base))
2950 message ("Function %q is marked %s, but the argument "
2951 "before the elipsis has type %s (should be char *)",
2952 uentry_getName (ue),
2953 specCode_unparse (ue->info->fcn->specialCode),
2954 ctype_unparse (uentry_getType (last))),
2955 uentry_whereLast (ue));
2957 ue->info->fcn->specialCode = SPC_NONE;
2964 } end_uentryList_elements ;
2968 message ("Function %q is marked %s, but has no elipsis parameter",
2969 uentry_getName (ue),
2970 specCode_unparse (ue->info->fcn->specialCode)),
2971 uentry_whereLast (ue));
2973 ue->info->fcn->specialCode = SPC_NONE;
2978 uentry_setPrintfLike (uentry ue)
2980 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2982 uentry_makeVarFunction (ue);
2985 llassertfatal (uentry_isFunction (ue));
2986 ue->info->fcn->specialCode = SPC_PRINTFLIKE;
2987 checkSpecialFunction (ue);
2991 uentry_setScanfLike (uentry ue)
2993 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2995 uentry_makeVarFunction (ue);
2998 llassertfatal (uentry_isFunction (ue));
2999 ue->info->fcn->specialCode = SPC_SCANFLIKE;
3000 checkSpecialFunction (ue);
3004 uentry_setMessageLike (uentry ue)
3006 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
3008 uentry_makeVarFunction (ue);
3011 llassertfatal (uentry_isFunction (ue));
3012 ue->info->fcn->specialCode = SPC_MESSAGELIKE;
3013 checkSpecialFunction (ue);
3017 uentry_isSpecialFunction (uentry ue)
3019 return (uentry_isFunction (ue)
3020 && (ue->info->fcn->specialCode != SPC_NONE));
3023 /*@notnull@*/ uentry uentry_makeParam (idDecl t, int i)
3025 ctype ct = idDecl_getCtype (t);
3027 sRef pref = sRef_makeParam (i, ct);
3028 uentry ue = uentry_makeVariableSrefParam (idDecl_observeId (t), ct, pref);
3030 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3031 uentry_implicitParamAnnots (ue);
3033 /* Parameter type [][] or [x][] is invalid */
3035 while (ctype_isFixedArray (base)) {
3036 base = ctype_baseArrayPtr (base);
3039 if (ctype_isIncompleteArray (base)) {
3040 base = ctype_baseArrayPtr (base);
3042 if (ctype_isArray (base)) {
3043 if (!uentry_hasName (ue)) {
3044 (void) optgenerror (FLG_INCOMPLETETYPE,
3045 message ("Unnamed function parameter %d is incomplete type (inner array must have bounds): %s",
3047 ctype_unparse (ct)),
3048 uentry_whereLast (ue));
3050 (void) optgenerror (FLG_INCOMPLETETYPE,
3051 message ("Function parameter %q is incomplete type (inner array must have bounds): %s",
3052 uentry_getName (ue),
3053 ctype_unparse (ct)),
3054 uentry_whereLast (ue));
3059 DPRINTF (("Param: %s", uentry_unparseFull (ue)));
3063 /*@only@*/ /*@notnull@*/ uentry uentry_makeIdVariable (idDecl t)
3065 ctype ct = idDecl_getCtype (t);
3067 if (ctype_isFunction (ct))
3069 return (uentry_makeIdFunction (t));
3073 fileloc loc = setLocation ();
3074 uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
3076 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3078 if (!uentry_isExtern (ue))
3080 uentry_setDefined (ue, loc);
3088 /*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t)
3090 return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), SS_DEFINED));
3098 /*@only@*/ /*@notnull@*/
3099 uentry uentry_makeConstantAux (cstring n, ctype t,
3100 /*@keep@*/ fileloc f, bool priv,
3101 /*@only@*/ multiVal m)
3103 uentry e = uentry_alloc ();
3106 e->uname = cstring_copy (n);
3108 e->storageclass = SCNONE;
3110 e->warn = warnClause_undefined; /*@i32 warnings for constants? */
3112 e->sref = sRef_makeConst (t);
3117 e->uses = filelocList_new ();
3118 e->isPrivate = priv;
3119 e->hasNameError = FALSE;
3121 e->info = (uinfo) dmalloc (sizeof (*e->info));
3122 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
3123 e->info->uconst->val = m;
3124 e->info->uconst->access = typeIdSet_undefined;
3126 uentry_setSpecDef (e, f);
3128 if (multiVal_isInt (m) && (multiVal_forceInt (m) == 0))
3130 sRef_setDefNull (e->sref, uentry_whereDeclared (e));
3136 /*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
3138 return (uentry_makeConstantAux (n, t, f, FALSE, multiVal_unknown ()));
3141 /*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
3143 uentry ue = uentry_makeConstant (idDecl_observeId (t),
3144 idDecl_getCtype (t),
3147 llassert (fileloc_isUndefined (ue->whereDeclared));
3148 ue->whereDeclared = setLocation ();
3150 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
3159 void uentry_setDefState (uentry ue, sstate defstate)
3161 if (uentry_isValid (ue))
3163 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
3165 if (uentry_isVariable (ue))
3167 ue->info->var->defstate = defstate; /* evs 2000-05-17: fixed bug, was SS_DEFINED! */
3172 bool uentry_isCheckedUnknown (uentry ue)
3174 return (uentry_isVar (ue)
3175 && (ue->info->var->checked == CH_UNKNOWN));
3178 bool uentry_isCheckMod (uentry ue)
3180 return (uentry_isVar (ue)
3181 && (ue->info->var->checked == CH_CHECKMOD));
3184 bool uentry_isUnchecked (uentry ue)
3186 return (uentry_isVar (ue)
3187 && (ue->info->var->checked == CH_UNCHECKED));
3190 bool uentry_isChecked (uentry ue)
3192 return (uentry_isVar (ue)
3193 && (ue->info->var->checked == CH_CHECKED));
3196 bool uentry_isCheckedModify (uentry ue)
3198 return (uentry_isVar (ue)
3199 && (ue->info->var->checked == CH_CHECKED
3200 || ue->info->var->checked == CH_CHECKMOD
3201 || ue->info->var->checked == CH_CHECKEDSTRICT));
3204 bool uentry_isCheckedStrict (uentry ue)
3206 return (uentry_isVar (ue)
3207 && (ue->info->var->checked == CH_CHECKEDSTRICT));
3210 void uentry_setUnchecked (uentry ue)
3212 llassert (uentry_isVar (ue));
3214 ue->info->var->checked = CH_UNCHECKED;
3217 void uentry_setChecked (uentry ue)
3219 llassert (uentry_isVar (ue));
3221 ue->info->var->checked = CH_CHECKED;
3224 void uentry_setCheckMod (uentry ue)
3226 llassert (uentry_isVar (ue));
3228 ue->info->var->checked = CH_CHECKMOD;
3231 void uentry_setCheckedStrict (uentry ue)
3233 llassert (uentry_isVar (ue));
3235 ue->info->var->checked = CH_CHECKEDSTRICT;
3238 static /*@only@*/ /*@notnull@*/
3239 uentry uentry_makeVariableAux (cstring n, ctype t,
3241 /*@exposed@*/ sRef s,
3242 bool priv, vkind kind)
3244 uentry e = uentry_alloc ();
3247 DPRINTF (("Make variable: %s %s %s", n, ctype_unparse (t), sRef_unparse (s)));
3250 e->uname = cstring_copy (n);
3253 e->storageclass = SCNONE;
3255 e->warn = warnClause_undefined; /*@i32 warnings for variable @*/
3262 e->uses = filelocList_new ();
3263 e->isPrivate = priv;
3264 e->hasNameError = FALSE;
3266 e->info = (uinfo) dmalloc (sizeof (*e->info));
3267 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
3268 e->info->var->kind = kind;
3270 e->info->var->checked = CH_UNKNOWN;
3272 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3273 uentry_setSpecDef (e, f);
3274 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3276 if (ctype_isFunction (rt))
3278 rt = ctype_getReturnType (rt);
3281 if (ctype_isUA (rt))
3283 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3284 sRef_setStateFromType (e->sref, rt);
3287 DPRINTF (("Here we are: %s", sRef_unparseFull (e->sref)));
3288 e->info->var->defstate = sRef_getDefState (e->sref);
3289 e->info->var->nullstate = sRef_getNullState (e->sref);
3291 /* start modifications */
3292 /* This function sets the uentry for a pointer or array variable declaration,
3293 it allocates memory and sets the fields. We check if the type of the variable
3294 is a pointer or array and allocate a `bbufinfo' struct accordingly */
3296 if( ctype_isArray (t) || ctype_isPointer(t)) {
3297 /*@i222@*/e->info->var->bufinfo = dmalloc( sizeof(*e->info->var->bufinfo) );
3298 e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
3299 /*@access sRef@*/ /*i@222*/
3300 /* It probably isn't necessary to violate the abstraction here
3303 s->bufinfo.bufstate = BB_NOTNULLTERMINATED;
3306 e->info->var->bufinfo = NULL;
3308 /* end modification */
3314 uentry_isYield (uentry ue)
3316 return (uentry_isVariable (ue)
3317 && (ue->info->var->kind == VKYIELDPARAM
3318 || ue->info->var->kind == VKREFYIELDPARAM));
3322 uentry_isRefsField (uentry ue)
3324 return (uentry_isVariable (ue) && sRef_isRefsField (ue->sref));
3327 /*@only@*/ /*@notnull@*/
3328 uentry uentry_makeVariable (cstring n, ctype t, fileloc f, bool isPriv)
3330 return (uentry_makeVariableAux (n, t, f, sRef_makeType (t), isPriv,
3331 fileloc_isSpec (f) ? VKSPEC : VKNORMAL));
3338 void uentry_makeVarFunction (uentry ue)
3345 llassert (uentry_isValid (ue));
3346 llassert (!sRef_modInFunction ());
3348 ak = sRef_getOrigAliasKind (ue->sref);
3349 ek = sRef_getOrigExKind (ue->sref);
3351 oldInfo = ue->info->var;
3353 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
3356 ** expanded macro is marked used (until I write a pre-processor)
3359 ue->used |= (oldInfo->kind == VKEXPMACRO);
3362 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3363 ue->info->fcn->exitCode = XK_UNKNOWN;
3364 ue->info->fcn->nullPred = qual_createUnknown ();
3365 ue->info->fcn->specialCode = SPC_NONE;
3366 ue->info->fcn->access = typeIdSet_undefined;
3367 ue->info->fcn->hasGlobs = FALSE;
3368 ue->info->fcn->globs = globSet_undefined;
3369 ue->info->fcn->hasMods = FALSE;
3370 ue->info->fcn->mods = sRefSet_undefined;
3371 ue->info->fcn->specclauses = NULL;
3372 ue->info->fcn->defparams = uentryList_undefined;
3375 ue->info->fcn->preconditions = functionConstraint_undefined;
3379 ue->info->fcn->postconditions = functionConstraint_undefined;
3383 if (ctype_isFunction (ue->utype))
3385 ue->sref = sRef_makeType (ctype_getReturnType (ue->utype));
3389 ue->sref = sRef_makeType (ctype_unknown);
3392 if (sRef_isRefCounted (ue->sref))
3398 if (alkind_isUnknown (ak))
3400 if (exkind_isKnown (ek))
3402 DPRINTF (("imp dep: %s", uentry_unparseFull (ue)));
3403 ak = AK_IMPDEPENDENT;
3407 if (context_getFlag (FLG_RETIMPONLY))
3409 if (ctype_isFunction (ue->utype)
3410 && ctype_isVisiblySharable
3411 (ctype_realType (ctype_getReturnType (ue->utype))))
3413 if (uentryList_hasReturned (uentry_getParams (ue)))
3419 if (ctype_isImmutableAbstract (ctype_getReturnType (ue->utype)))
3434 loc = ue->whereDeclared;
3436 sRef_setAliasKind (ue->sref, ak, loc);
3437 sRef_setNullState (ue->sref, oldInfo->nullstate, loc);
3438 sRef_setDefState (ue->sref, oldInfo->defstate, loc);
3439 sRef_setExKind (ue->sref, ek, loc);
3441 if (oldInfo->kind == VKEXPMACRO)
3444 ue->whereDeclared = fileloc_undefined;
3448 fileloc_free (ue->whereDefined);
3449 ue->whereDefined = fileloc_undefined;
3452 uvinfo_free (oldInfo);
3456 uentry_setGlobals (uentry ue, /*@owned@*/ globSet globs)
3458 llassert (uentry_isValid (ue));
3460 if (uentry_isIter (ue))
3462 llassert (globSet_isUndefined (ue->info->iter->globs));
3463 ue->info->iter->globs = globs;
3467 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
3469 uentry_makeVarFunction (ue);
3472 llassert (uentry_isFunction (ue));
3473 llassert (!ue->info->fcn->hasGlobs
3474 && globSet_isUndefined (ue->info->fcn->globs));
3476 ue->info->fcn->hasGlobs = TRUE;
3477 globSet_markImmutable (globs);
3478 /*@-mustfree@*/ ue->info->fcn->globs = globs;
3483 if (globSet_hasStatic (globs))
3485 context_recordFileGlobals (globs);
3489 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3491 ue->info->fcn->hasMods = TRUE;
3495 void uentry_addAccessType (uentry ue, typeId tid)
3497 if (uentry_isFunction (ue))
3499 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3501 else if (uentry_isEitherConstant (ue))
3503 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3505 else if (uentry_isIter (ue))
3507 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3509 else if (uentry_isEndIter (ue))
3511 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3515 llbug (message ("no access for: %q", uentry_unparse (ue)));
3519 /*@only@*/ /*@notnull@*/ uentry
3520 uentry_makeFunction (cstring n, ctype t,
3522 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
3523 /*@only@*/ warnClause warn,
3526 llassert (warnClause_isUndefined (warn)); /*@i325 remove parameter! */
3527 return (uentry_makeFunctionAux (n, t,
3528 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3529 : typeIdSet_single (access)),
3536 /*@notnull@*/ uentry
3537 uentry_makePrivFunction2 (cstring n, ctype t,
3539 globSet globs, sRefSet mods,
3542 return (uentry_makeFunctionAux (n, t, access, globs, mods, warnClause_undefined,
3547 /*@notnull@*/ uentry
3548 uentry_makeSpecFunction (cstring n, ctype t,
3550 /*@only@*/ globSet globs,
3551 /*@only@*/ sRefSet mods,
3554 uentry ue = uentry_makeFunctionAux (n, t, access,
3555 globs, mods, warnClause_undefined,
3558 uentry_setHasGlobs (ue);
3559 uentry_setHasMods (ue);
3561 reflectImplicitFunctionQualifiers (ue, TRUE);
3566 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3568 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3569 sRef_undefined, FALSE, VKEXPMACRO);
3571 uentry_setDefined (ue, f);
3575 /*@notnull@*/ /*@notnull@*/ uentry
3576 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3578 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3579 typeIdSet_singleOpt (access),
3580 globSet_undefined, sRefSet_undefined,
3581 warnClause_undefined,
3585 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3589 bool uentry_isForward (uentry e)
3591 if (uentry_isValid (e))
3593 ctype ct = uentry_getType (e);
3595 return (ctype_isUnknown (ct)
3596 || (ctype_isFunction (ct)
3597 && ctype_isUnknown (ctype_getReturnType (ct))));
3604 /*@notnull@*/ uentry
3605 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3607 return (uentry_makeFunctionAux (n, ctype_unknown, access,
3608 globSet_undefined, sRefSet_undefined, warnClause_undefined,
3612 /*@notnull@*/ uentry
3613 uentry_makeUnspecFunction (cstring n, ctype t,
3617 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_undefined,
3618 sRefSet_undefined, warnClause_undefined,
3621 reflectImplicitFunctionQualifiers (ue, TRUE);
3630 /* is exported for use by usymtab_interface */
3632 /*@notnull@*/ uentry
3633 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, ynm abstract,
3634 fileloc f, bool priv)
3636 uentry e = uentry_alloc ();
3638 DPRINTF (("Make datatype: %s / %s",
3639 n, ctype_unparse (t)));
3641 /* e->shallowCopy = FALSE; */
3642 e->ukind = KDATATYPE;
3643 e->uname = cstring_copy (n);
3645 e->storageclass = SCNONE;
3646 e->sref = sRef_makeUnknown ();
3650 sRef_setStateFromType (e->sref, t);
3653 uentry_setSpecDef (e, f);
3655 e->warn = warnClause_undefined; /*@i634@*/
3656 e->uses = filelocList_new ();
3657 e->isPrivate = priv;
3658 e->hasNameError = FALSE;
3663 e->info = (uinfo) dmalloc (sizeof (*e->info));
3664 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3665 e->info->datatype->abs = abstract;
3666 e->info->datatype->mut = mut;
3667 e->info->datatype->type = ctype_undefined;
3669 if (uentry_isDeclared (e))
3671 uentry_setDefined (e, f);
3674 if (ynm_isOn (abstract) && !(uentry_isCodeDefined (e)))
3676 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3682 /*@notnull@*/ uentry
3683 uentry_makeDatatype (cstring n, ctype t, ynm mut, ynm abstract, fileloc f)
3685 return (uentry_makeDatatypeAux (n, t, mut, abstract, f, FALSE));
3688 /*@notnull@*/ uentry uentry_makeBoolDatatype (ynm abstract)
3690 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
3691 ctype_bool, NO, abstract,
3692 fileloc_getBuiltin (),
3695 ret->info->datatype->type = ctype_bool;
3703 static /*@only@*/ /*@notnull@*/ uentry
3704 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3705 /*@only@*/ fileloc f)
3707 uentry e = uentry_alloc ();
3710 e->uname = cstring_copy (n);
3712 e->sref = sRef_makeUnknown ();
3713 e->storageclass = SCNONE;
3717 uentry_setSpecDef (e, f);
3719 e->warn = warnClause_undefined; /*@i452@*/
3720 e->uses = filelocList_new ();
3721 e->isPrivate = FALSE;
3722 e->hasNameError = FALSE;
3724 e->info = (uinfo) dmalloc (sizeof (*e->info));
3725 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3726 e->info->iter->access = access;
3727 e->info->iter->mods = sRefSet_undefined;
3728 e->info->iter->globs = globSet_undefined;
3730 uentry_checkIterArgs (e);
3734 /*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3736 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3739 static /*@notnull@*/ uentry
3740 uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3742 uentry e = uentry_alloc ();
3744 /* e->shallowCopy = FALSE; */
3745 e->ukind = KENDITER;
3746 e->storageclass = SCNONE;
3747 e->uname = message ("end_%s", n);
3748 e->utype = ctype_unknown;
3749 e->sref = sRef_makeUnknown ();
3751 uentry_setSpecDef (e, f);
3756 e->uses = filelocList_new ();
3757 e->isPrivate = FALSE;
3758 e->hasNameError = FALSE;
3760 e->info = (uinfo) dmalloc (sizeof (*e->info));
3761 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3763 e->info->enditer->access = access;
3765 e->warn = warnClause_undefined; /*@i452@*/
3769 /*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3771 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3778 static /*@only@*/ /*@notnull@*/ uentry
3779 uentry_makeTagAux (cstring n, ctype t,
3780 /*@only@*/ fileloc fl,
3781 bool priv, ekind kind)
3783 uentry e = uentry_alloc ();
3785 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3787 llbuglit ("uentry_makeTagAux: not a tag type");
3791 /* e->shallowCopy = FALSE; */
3792 e->uname = cstring_copy (n);
3795 e->sref = sRef_makeUnknown ();
3796 e->storageclass = SCNONE;
3798 uentry_setSpecDef (e, fl);
3803 e->uses = filelocList_new ();
3804 e->isPrivate = priv;
3805 e->hasNameError = FALSE;
3807 e->info = (uinfo) dmalloc (sizeof (*e->info));
3808 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3809 e->info->datatype->abs = NO;
3810 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3811 e->info->datatype->type = t;
3812 e->warn = warnClause_undefined; /*@i452@*/
3814 if (uentry_isDeclared (e))
3816 uentry_setDefined (e, fl);
3822 uentry uentry_makeStructTagLoc (cstring n, ctype t)
3824 cstring sname = makeStruct (n);
3825 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3827 cstring_free (sname);
3832 uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3834 cstring sname = makeStruct (n);
3835 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3837 cstring_free (sname);
3842 uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
3844 cstring uname = makeUnion (n);
3845 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
3847 cstring_free (uname);
3853 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
3855 cstring ename = makeEnum (n);
3856 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
3858 cstring_free (ename);
3864 uentry_makeUnionTagLoc (cstring n, ctype t)
3866 cstring uname = makeUnion (n);
3867 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
3869 cstring_free (uname);
3874 uentry_makeEnumTagLoc (cstring n, ctype t)
3876 cstring ename = makeEnum (n);
3877 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
3879 cstring_free (ename);
3884 uentry_isStructTag (uentry ue)
3886 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
3890 uentry_isUnionTag (uentry ue)
3892 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
3896 uentry_isEnumTag (uentry ue)
3898 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
3902 uentry_isAnyTag (uentry ue)
3904 return (uentry_isStructTag (ue)
3905 || uentry_isUnionTag (ue)
3906 || uentry_isEnumTag (ue));
3909 static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
3911 extern void uentry_destroyMod (void)
3912 /*@globals killed emarker@*/ /*@modifies emarker@*/
3914 static bool wasDestroyed = FALSE;
3916 llassert (!wasDestroyed);
3918 if (emarker != NULL)
3920 uentry_reallyFree (emarker);
3923 wasDestroyed = TRUE;
3927 uentry_makeElipsisMarker (void)
3929 if (emarker == NULL)
3931 emarker = uentry_alloc ();
3933 emarker->ukind = KELIPSMARKER;
3934 emarker->uname = cstring_makeLiteral ("...");
3935 emarker->utype = ctype_elipsMarker;
3936 emarker->sref = sRef_undefined;
3937 emarker->storageclass = SCNONE;
3938 emarker->used = FALSE;
3939 emarker->lset = FALSE;
3940 emarker->info = NULL;
3942 uentry_setSpecDef (emarker, fileloc_undefined);
3943 emarker->uses = filelocList_new ();
3944 emarker->isPrivate = FALSE;
3945 emarker->hasNameError = FALSE;
3948 /*@ignore@*/ return (emarker); /*@end@*/
3956 uentry_equiv (uentry p1, uentry p2)
3958 if (uentry_compare (p1, p2) != 0)
3969 uentry_xcomparealpha (uentry *p1, uentry *p2)
3973 if ((res = uentry_compare (*p1, *p2)) == 0) {
3974 if ((*p1 != NULL) && (*p2 != NULL)) {
3975 res = cstring_compare ((*p1)->uname,
3984 uentry_xcompareuses (uentry *p1, uentry *p2)
3989 if (uentry_isValid (u1))
3991 if (uentry_isValid (u2))
3993 return (-1 * int_compare (filelocList_size (u1->uses),
3994 filelocList_size (u2->uses)));
4003 if (uentry_isValid (u2))
4015 uentry_compareStrict (uentry v1, uentry v2)
4017 COMPARERETURN (uentry_compare (v1, v2));
4019 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
4021 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
4022 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
4023 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
4030 uentry_compare (uentry u1, uentry u2)
4032 if (u1 == u2) return 0;
4034 if (uentry_isInvalid (u1)) return -1;
4035 if (uentry_isInvalid (u2)) return 1;
4037 INTCOMPARERETURN (u1->ukind, u2->ukind);
4038 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
4039 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
4040 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
4046 /* bug detected by lclint:
4047 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
4052 return (multiVal_compare (u1->info->uconst->val,
4053 u2->info->uconst->val));
4057 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
4059 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
4060 uentry_accessType (u2)));
4061 return (uentryList_compareParams (uentry_getParams (u1),
4062 uentry_getParams (u2)));
4064 return (typeIdSet_compare (uentry_accessType (u1),
4065 uentry_accessType (u2)));
4068 ** Functions are never equivalent
4071 if ((int) u1 < (int) u2)
4081 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
4082 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
4083 sRef_getOrigAliasKind (u2->sref)));
4084 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
4085 sRef_getOrigExKind (u2->sref)));
4086 COMPARERETURN (generic_compare (u1->info->var->checked,
4087 u2->info->var->checked));
4088 COMPARERETURN (generic_compare (u1->info->var->defstate,
4089 u2->info->var->defstate));
4090 return (generic_compare (u1->info->var->nullstate,
4091 u2->info->var->nullstate));
4093 COMPARERETURN (ctype_compare (u1->info->datatype->type,
4094 u2->info->datatype->type));
4095 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
4096 u2->info->datatype->mut));
4097 return (ynm_compare (u1->info->datatype->abs, u2->info->datatype->abs));
4106 ** all entries are: <type>[@<info>]*#<name>
4108 ** info depends on kind:
4112 advanceField (char **s)
4114 reader_checkChar (s, '@');
4118 advanceName (char **s)
4120 reader_checkChar (s, '#');
4124 vkind_fromInt (int i)
4126 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
4128 llbuglit ("vkind_fromInt: out of range");
4135 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
4136 typeIdSet access, nstate nullstate,
4137 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
4139 uentry e = uentry_alloc ();
4144 e->sref = sRef_makeConst (ct);
4146 sRef_setNullState (e->sref, nullstate, loc);
4147 e->storageclass = SCNONE;
4149 if (fileloc_isSpec (loc))
4151 e->whereSpecified = loc;
4152 e->whereDeclared = fileloc_undefined;
4156 e->whereSpecified = fileloc_undefined;
4157 e->whereDeclared = loc;
4160 e->whereDefined = fileloc_undefined;
4161 e->uses = filelocList_new ();
4162 e->isPrivate = FALSE;
4163 e->hasNameError = FALSE;
4168 e->warn = warnClause_undefined; /*@i452@*/
4170 e->info = (uinfo) dmalloc (sizeof (*e->info));
4171 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
4172 e->info->uconst->val = m;
4173 e->info->uconst->access = access;
4175 sRef_storeState (e->sref);
4180 static /*@only@*/ uentry
4181 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
4182 sstate defstate, nstate isnull, alkind aliased,
4183 exkind exp, chkind checked,
4184 /*@only@*/ fileloc loc)
4186 uentry e = uentry_alloc ();
4191 e->storageclass = SCNONE;
4193 e->sref = sRef_makeType (ct);
4194 sRef_setNullState (e->sref, isnull, loc);
4196 e->whereDefined = fileloc_undefined;
4198 if (fileloc_isSpec (loc))
4200 e->whereSpecified = loc;
4201 e->whereDeclared = fileloc_undefined;
4205 e->whereSpecified = fileloc_undefined;
4206 e->whereDeclared = loc;
4209 e->isPrivate = FALSE;
4210 e->hasNameError = FALSE;
4215 e->uses = filelocList_new ();
4216 e->warn = warnClause_undefined; /*@i452@*/
4218 e->info = (uinfo) dmalloc (sizeof (*e->info));
4219 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
4220 e->info->var->kind = kind;
4221 e->info->var->checked = checked;
4222 e->info->var->defstate = defstate;
4224 sRef_setDefState (e->sref, defstate, loc);
4226 e->info->var->nullstate = sRef_getNullState (e->sref);
4228 sRef_setExKind (e->sref, exp, loc);
4229 sRef_setAliasKind (e->sref, aliased, loc);
4231 sRef_storeState (e->sref);
4233 /*DRL ADDED 9-1-2000 */
4234 e->info->var->bufinfo = NULL;
4239 static /*@only@*/ uentry
4240 uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, ynm abstract,
4241 ynm mut, ctype rtype, alkind ak, exkind exp,
4242 sstate defstate, nstate isnull,
4243 /*@only@*/ fileloc loc)
4245 uentry e = uentry_alloc ();
4247 e->ukind = KDATATYPE;
4248 /* e->shallowCopy = FALSE; */
4251 e->storageclass = SCNONE;
4252 e->sref = sRef_makeUnknown ();
4253 DPRINTF (("Merge null 1: %s", sRef_unparseFull (e->sref)));
4256 ** This is only setting null state. (I think?)
4259 if (ctype_isUA (ct))
4261 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
4263 if (uentry_isValid (te))
4265 sRef_setStateFromUentry (e->sref, te);
4269 /* problem for recursive type definitions */
4273 sRef_setAliasKind (e->sref, ak, loc);
4274 sRef_setExKind (e->sref, exp, loc);
4276 sRef_setDefState (e->sref, defstate, loc);
4278 if (ynm_isOn (abstract) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
4280 isnull = NS_ABSNULL;
4283 DPRINTF (("Merge null: %s", sRef_unparseFull (e->sref)));
4284 sRef_mergeNullState (e->sref, isnull);
4286 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
4288 if (fileloc_isSpec (loc))
4290 e->whereSpecified = loc;
4291 e->whereDeclared = fileloc_undefined;
4295 e->whereSpecified = fileloc_undefined;
4296 e->whereDeclared = loc;
4299 e->isPrivate = FALSE;
4300 e->hasNameError = FALSE;
4302 e->warn = warnClause_undefined; /*@i452@*/
4306 e->uses = filelocList_new ();
4308 e->info = (uinfo) dmalloc (sizeof (*e->info));
4309 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4310 e->info->datatype->abs = abstract;
4311 e->info->datatype->mut = mut;
4312 e->info->datatype->type = rtype;
4314 DPRINTF (("About to store: %s", sRef_unparseFull (e->sref)));
4315 sRef_storeState (e->sref);
4316 DPRINTF (("After store: %s", sRef_unparseFull (e->sref)));
4322 static void uentry_setHasGlobs (uentry ue)
4324 llassert (uentry_isFunction (ue));
4326 ue->info->fcn->hasGlobs = TRUE;
4329 static void uentry_setHasMods (uentry ue)
4331 llassert (uentry_isFunction (ue));
4333 ue->info->fcn->hasMods = TRUE;
4337 bool uentry_hasGlobs (uentry ue)
4339 if (uentry_isFunction (ue))
4341 return (ue->info->fcn->hasGlobs);
4347 bool uentry_hasStateClauseList (uentry ue)
4349 return (uentry_isFunction (ue) && stateClauseList_isDefined (ue->info->fcn->specclauses));
4352 stateClauseList uentry_getStateClauseList (uentry ue)
4354 if (!uentry_isFunction (ue))
4356 llassert (uentry_isFunction (ue));
4357 return stateClauseList_undefined;
4360 DPRINTF (("Get state clause list: %s", uentry_unparse (ue)));
4361 return ue->info->fcn->specclauses;
4364 bool uentry_hasMods (uentry ue)
4366 if (uentry_isFunction (ue))
4368 return (ue->info->fcn->hasMods);
4375 uentry_makeFunctionBase (/*@only@*/ cstring name, ctype ct,
4377 bool hasGlobs, /*@only@*/ globSet globs,
4378 bool hasMods, /*@only@*/ sRefSet mods,
4379 alkind ak, exkind exp,
4380 sstate defstate, nstate isnull,
4384 /*@only@*/ stateClauseList specclauses,
4385 /*@only@*/ warnClause warnclause,
4386 /*@only@*/ fileloc loc)
4388 uentry e = uentry_alloc ();
4391 /* e->shallowCopy = FALSE; */
4395 e->storageclass = SCNONE;
4397 if (ctype_isFunction (ct))
4399 ret = ctype_getReturnType (ct);
4403 if (ctype_isKnown (ct))
4405 llbug (message ("not function: %s", ctype_unparse (ct)));
4408 ret = ctype_unknown;
4411 e->sref = sRef_makeType (ret);
4413 if (ctype_isUA (ret))
4415 sRef_setStateFromType (e->sref, ret);
4418 sRef_setDefined (e->sref, loc);
4419 sRef_setNullState (e->sref, isnull, loc);
4421 sRef_setAliasKind (e->sref, ak, loc);
4422 sRef_setExKind (e->sref, exp, loc);
4423 sRef_setDefState (e->sref, defstate, loc);
4425 e->whereSpecified = loc;
4426 e->whereDefined = fileloc_undefined;
4428 e->isPrivate = FALSE;
4429 e->hasNameError = FALSE;
4433 e->uses = filelocList_new ();
4434 e->warn = warnclause;
4436 e->info = (uinfo) dmalloc (sizeof (*e->info));
4437 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
4439 e->info->fcn->exitCode = exitCode;
4440 e->info->fcn->specialCode = sCode;
4441 e->info->fcn->nullPred = nullPred;
4442 e->info->fcn->access = access;
4444 e->info->fcn->specclauses = specclauses;
4445 e->info->fcn->hasGlobs = hasGlobs;
4446 e->info->fcn->globs = globs;
4448 e->info->fcn->hasMods = hasMods;
4449 e->info->fcn->mods = mods;
4451 e->info->fcn->defparams = uentryList_undefined;
4452 e->whereDeclared = fileloc_undefined;
4454 sRef_storeState (e->sref);
4457 e->info->fcn->preconditions = NULL;
4461 e->info->fcn->postconditions = NULL;
4467 static /*@only@*/ uentry
4468 uentry_makeTagBase (/*@only@*/ cstring name, ekind tagkind,
4469 ctype ct, ctype rtype, /*@only@*/ fileloc loc)
4471 uentry e = uentry_alloc ();
4473 if (tagkind != KSTRUCTTAG && tagkind != KUNIONTAG && tagkind != KENUMTAG)
4475 llbuglit ("uentry_makeTagBase: not a tag type");
4478 /* e->shallowCopy = FALSE; */
4482 e->sref = sRef_makeUnknown ();
4483 e->storageclass = SCNONE;
4485 if (fileloc_isSpec (loc))
4487 e->whereSpecified = loc;
4488 e->whereDeclared = fileloc_undefined;
4492 e->whereDeclared = loc;
4493 e->whereSpecified = fileloc_undefined;
4496 e->whereDefined = fileloc_undefined;
4498 e->isPrivate = FALSE;
4499 e->hasNameError = FALSE;
4503 e->uses = filelocList_new ();
4504 e->warn = warnClause_undefined; /*@i452@*/
4506 e->info = (uinfo) dmalloc (sizeof (*e->info));
4507 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4508 e->info->datatype->abs = NO;
4509 e->info->datatype->mut = MAYBE;
4510 e->info->datatype->type = rtype;
4512 sRef_storeState (e->sref);
4518 uentry_makeIterBase (/*@only@*/ cstring name, typeIdSet access,
4519 ctype ct, /*@only@*/ fileloc loc)
4521 uentry e = uentry_alloc ();
4523 /* e->shallowCopy = FALSE; */
4527 e->sref = sRef_makeUnknown ();
4528 e->storageclass = SCNONE;
4530 if (fileloc_isSpec (loc))
4532 e->whereSpecified = loc;
4533 e->whereDeclared = fileloc_undefined;
4537 e->whereDeclared = loc;
4538 e->whereSpecified = fileloc_undefined;
4541 e->whereDefined = fileloc_undefined;
4543 e->isPrivate = FALSE;
4544 e->hasNameError = FALSE;
4548 e->uses = filelocList_new ();
4549 e->warn = warnClause_undefined; /*@i452@*/
4551 e->info = (uinfo) dmalloc (sizeof (*e->info));
4552 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
4553 e->info->iter->access = access;
4554 e->info->iter->mods = sRefSet_undefined;
4555 e->info->iter->globs = globSet_undefined;
4557 sRef_storeState (e->sref);
4562 uentry_makeEndIterBase (/*@only@*/ cstring name, typeIdSet access,
4563 /*@only@*/ fileloc loc)
4565 uentry e = uentry_alloc ();
4567 /* e->shallowCopy = FALSE; */
4568 e->ukind = KENDITER;
4569 e->storageclass = SCNONE;
4571 e->utype = ctype_unknown;
4572 e->sref = sRef_makeUnknown ();
4574 if (fileloc_isSpec (loc))
4576 e->whereSpecified = loc;
4577 e->whereDeclared = fileloc_undefined;
4581 e->whereDeclared = loc;
4582 e->whereSpecified = fileloc_undefined;
4585 e->whereDefined = fileloc_undefined;
4587 e->isPrivate = FALSE;
4588 e->hasNameError = FALSE;
4592 e->uses = filelocList_new ();
4593 e->warn = warnClause_undefined; /*@i452@*/
4595 e->info = (uinfo) dmalloc (sizeof (*e->info));
4596 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
4597 e->info->enditer->access = access;
4598 sRef_storeState (e->sref);
4603 void uentry_markFree (/*@unused@*/ /*@owned@*/ uentry u)
4611 uentry_undump (ekind kind, fileloc loc, char **s)
4615 DPRINTF (("Uentry undump: %s", *s));
4619 reader_checkChar (s, '!');
4620 reader_checkChar (s, '.');
4621 ue = uentry_makeElipsisMarker ();
4625 ctype ct = ctype_undump (s);
4639 reader_checkChar (s, '|');
4641 if (reader_optCheckChar (s, '@'))
4643 tkind = vkind_fromInt (reader_getInt (s));
4644 reader_checkChar (s, '|');
4651 if (reader_optCheckChar (s, '$'))
4653 defstate = SS_UNKNOWN;
4654 isnull = NS_UNKNOWN;
4655 aliased = AK_IMPTEMP;
4657 checked = CH_UNKNOWN;
4659 else if (reader_optCheckChar (s, '&'))
4661 defstate = SS_DEFINED;
4662 isnull = NS_UNKNOWN;
4663 aliased = AK_IMPTEMP;
4665 checked = CH_UNKNOWN;
4667 else if (reader_optCheckChar (s, '^'))
4669 defstate = SS_UNKNOWN;
4670 isnull = NS_UNKNOWN;
4671 aliased = AK_IMPTEMP;
4673 checked = CH_UNKNOWN;
4677 defstate = sstate_fromInt (reader_getInt (s));
4678 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4679 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4681 if (reader_optCheckChar (s, '&'))
4684 checked = CH_UNKNOWN;
4688 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4689 advanceField (s); checked = (chkind) (reader_getInt (s));
4694 name = reader_getStringWord (s);
4696 llassert (!cstring_equal (name, GLOBAL_MARKER_NAME));
4698 ue = uentry_makeVariableBase (name, ct, tkind, defstate,
4699 isnull, aliased, exp,
4700 checked, fileloc_copy (loc));
4713 advanceField (s); abstract = ynm_fromCodeChar (reader_loadChar (s));
4714 advanceField (s); mut = ynm_fromCodeChar (reader_loadChar (s));
4715 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4716 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4717 advanceField (s); aliased = alkind_fromInt (reader_getInt (s));
4718 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4719 advanceField (s); rtype = ctype_undump (s);
4721 name = reader_getStringWord (s);
4722 DPRINTF (("Datatype %s, Exp = %s", name, exkind_unparse (exp)));
4723 ue = uentry_makeDatatypeBase (name, ct, abstract, mut, rtype,
4724 aliased, exp, defstate, isnull,
4725 fileloc_copy (loc));
4742 stateClauseList specclauses = stateClauseList_undefined;
4743 warnClause warnclause = warnClause_undefined;
4745 if (reader_optCheckChar (s, '$'))
4747 defstate = SS_DEFINED;
4748 isnull = NS_UNKNOWN;
4749 exitCode = XK_UNKNOWN;
4751 nullPred = qual_createUnknown ();
4755 advanceField (s); defstate = sstate_fromInt (reader_getInt (s));
4756 advanceField (s); isnull = nstate_fromInt (reader_getInt (s));
4757 advanceField (s); exitCode = exitkind_fromInt (reader_getInt (s));
4758 advanceField (s); specc = specCode_fromInt (reader_getInt (s));
4759 advanceField (s); nullPred = qual_undump (s);
4762 if (reader_optCheckChar (s, '$'))
4765 globs = globSet_undefined;
4767 mods = sRefSet_undefined;
4769 else if (reader_optCheckChar (s, '^'))
4772 globs = globSet_undefined;
4774 mods = sRefSet_undefined;
4778 advanceField (s); hasGlobs = bool_fromInt (reader_getInt (s));
4779 advanceField (s); globs = globSet_undump (s);
4780 advanceField (s); hasMods = bool_fromInt (reader_getInt (s));
4781 advanceField (s); mods = sRefSet_undump (s);
4784 if (reader_optCheckChar (s, '$'))
4791 advanceField (s); ak = alkind_fromInt (reader_getInt (s));
4792 advanceField (s); exp = exkind_fromInt (reader_getInt (s));
4795 advanceField (s); access = typeIdSet_undump (s);
4798 ** Optional clauses: Start with @<code>:
4801 while (reader_optCheckChar (s, '@'))
4803 if (reader_optCheckChar (s, 'W')) /* Warn clause */
4805 reader_checkChar (s, ':');
4806 warnclause = warnClause_undump (s);
4808 else if (reader_optCheckChar (s, 'S')) /* stateClause List */
4810 reader_checkChar (s, ':');
4811 specclauses = stateClauseList_undump (s);
4819 advanceName (s); name = reader_getStringWord (s);
4821 ue = uentry_makeFunctionBase (name, ct, access,
4824 ak, exp, defstate, isnull,
4825 exitCode, specc, nullPred,
4828 fileloc_copy (loc));
4829 DPRINTF (("Undump: %s", uentry_unparse (ue)));
4836 advanceField (s); access = typeIdSet_undump (s);
4837 advanceName (s); name = reader_getStringWord (s);
4839 ue = uentry_makeIterBase (name, access, ct,
4840 fileloc_copy (loc));
4847 advanceField (s); access = typeIdSet_undump (s);
4848 advanceName (s); name = reader_getStringWord (s);
4850 ue = uentry_makeEndIterBase (name, access, fileloc_copy (loc));
4860 if (reader_optCheckChar (s, '$'))
4862 val = multiVal_undefined;
4863 access = typeIdSet_undefined;
4864 nullstate = NS_UNKNOWN;
4868 advanceField (s); val = multiVal_undump (s);
4869 advanceField (s); access = typeIdSet_undump (s);
4870 advanceField (s); nullstate = nstate_fromInt (reader_getInt (s));
4873 advanceName (s); name = reader_getStringWord (s);
4875 ue = uentry_makeConstantBase (name, ct, access,
4876 nullstate, fileloc_copy (loc), val);
4885 advanceField (s); rtype = ctype_undump (s);
4886 advanceName (s); name = reader_getStringWord (s);
4887 ue = uentry_makeTagBase (name, kind, ct, rtype, fileloc_copy (loc));
4891 llcontbuglit ("uentry_undump: invalid");
4892 ue = uentry_undefined;
4895 llcontbuglit ("uentry_undump: elips marker");
4896 ue = uentry_undefined;
4905 uentry_dump (uentry v)
4907 return (uentry_dumpAux (v, FALSE));
4911 uentry_dumpParam (uentry v)
4913 llassertprint (uentry_isVariable (v) || uentry_isElipsisMarker (v),
4914 ("dump: %s", uentry_unparseFull (v)));
4916 return (uentry_dumpAux (v, TRUE));
4920 uentry_dumpAux (uentry v, bool isParam)
4922 llassert (uentry_isValid (v));
4923 llassert (!uentry_isGlobalMarker (v));
4925 DPRINTF (("Dump uentry: [%p]", v));
4926 DPRINTF (("Dumping entry: %s", uentry_unparseFull (v)));
4931 llcontbuglit ("uentry_dump: invalid entry");
4932 return cstring_undefined;
4934 return (message ("!."));
4938 vkind vk = v->info->var->kind;
4939 sstate dss = sRef_getDefState (v->sref);
4940 nstate nst = sRef_getNullState (v->sref);
4941 alkind alk = sRef_getAliasKind (v->sref);
4942 exkind exk = sRef_getExKind (v->sref);
4943 chkind chk = v->info->var->checked;
4945 DPRINTF (("Dumping var"));
4947 if (dss == SS_UNKNOWN
4948 && nst == NS_UNKNOWN
4949 && alk == AK_IMPTEMP
4950 && exk == XO_UNKNOWN
4951 && chk == CH_UNKNOWN)
4953 sdump = cstring_makeLiteral ("$");
4955 else if (dss == SS_DEFINED
4956 && nst == NS_UNKNOWN
4957 && alk == AK_IMPTEMP
4958 && exk == XO_UNKNOWN
4959 && chk == CH_UNKNOWN)
4961 sdump = cstring_makeLiteral ("&");
4963 else if (dss == SS_UNKNOWN
4964 && nst == NS_UNKNOWN
4965 && alk == AK_UNKNOWN
4966 && exk == XO_UNKNOWN
4967 && chk == CH_UNKNOWN)
4969 sdump = cstring_makeLiteral ("^");
4971 else if (exk == XO_UNKNOWN
4972 && chk == CH_UNKNOWN)
4974 sdump = message ("%d@%d@%d&",
4981 sdump = message ("%d@%d@%d@%d@%d",
4992 return (message ("%q|@%d|%q#%s",
4993 ctype_dump (v->utype),
4996 isParam ? cstring_undefined : v->uname));
5000 return (message ("%q|%q#%s",
5001 ctype_dump (v->utype),
5003 isParam ? cstring_undefined : v->uname));
5009 DPRINTF (("Dumping datatype: %s -> %s type: %s [%d]",
5011 exkind_unparse (sRef_getExKind (v->sref)),
5012 ctype_unparse (v->utype), (int) v->utype));
5015 return (message ("%q@%s@%s@%d@%d@%d@%d@%q#%s",
5016 ctype_dump (v->utype),
5017 ynm_unparseCode (v->info->datatype->abs),
5018 ynm_unparseCode (v->info->datatype->mut),
5019 (int) sRef_getDefState (v->sref),
5020 (int) sRef_getNullState (v->sref),
5021 (int) sRef_getAliasKind (v->sref),
5022 (int) sRef_getExKind (v->sref),
5023 ctype_dump (v->info->datatype->type),
5027 cstring sdump, gdump, adump, xdump;
5028 alkind alk = sRef_getAliasKind (v->sref);
5029 exkind exk = sRef_getExKind (v->sref);
5031 if (sRef_getDefState (v->sref) == SS_DEFINED
5032 && !nstate_isKnown (sRef_getNullState (v->sref))
5033 && !exitkind_isKnown (v->info->fcn->exitCode)
5034 && v->info->fcn->specialCode == SPC_NONE
5035 && qual_isUnknown (v->info->fcn->nullPred))
5037 sdump = cstring_makeLiteral ("$");
5041 sdump = message ("@%d@%d@%d@%d@%x",
5042 (int) sRef_getDefState (v->sref),
5043 (int) sRef_getNullState (v->sref),
5044 (int) v->info->fcn->exitCode,
5045 (int) v->info->fcn->specialCode,
5046 qual_dump (v->info->fcn->nullPred));
5049 if (!uentry_hasGlobs(v) && !uentry_hasMods (v))
5051 gdump = cstring_makeLiteral ("$");
5053 else if (uentry_hasGlobs (v) && globSet_isEmpty (uentry_getGlobs (v))
5054 && uentry_hasMods (v) && sRefSet_isEmpty (uentry_getMods (v)))
5056 gdump = cstring_makeLiteral ("^");
5060 gdump = message ("@%s@%q@%s@%q",
5061 bool_dump (uentry_hasGlobs (v)),
5062 globSet_dump (uentry_getGlobs (v)),
5063 bool_dump (uentry_hasMods (v)),
5064 sRefSet_dump (uentry_getMods (v)));
5067 if (alk == AK_UNKNOWN && exk == XO_UNKNOWN)
5069 adump = cstring_makeLiteral ("$");
5073 adump = message ("@%d@%d", (int) alk, (int) exk);
5076 xdump = cstring_undefined;
5078 if (uentry_hasWarning (v))
5080 xdump = message ("%q@W:%q", xdump, warnClause_dump (v->warn));
5083 if (uentry_hasStateClauseList (v))
5085 xdump = message ("%q@S:%q", xdump, stateClauseList_dump (v->info->fcn->specclauses));
5088 return (message ("%q%q%q%q@%q%q#%s",
5089 ctype_dump (v->utype),
5093 typeIdSet_dump (uentry_accessType (v)),
5098 return (message ("%q@%q#%s",
5099 ctype_dump (v->utype),
5100 typeIdSet_dump (v->info->iter->access),
5103 return (message ("%q@%q#%s",
5104 ctype_dump (v->utype),
5105 typeIdSet_dump (uentry_accessType (v)),
5112 if (multiVal_isUnknown (v->info->uconst->val)
5113 && typeIdSet_isEmpty (uentry_accessType (v))
5114 && (sRef_getNullState (v->sref) == NS_UNKNOWN))
5116 sdump = cstring_makeLiteral ("$");
5120 sdump = message ("@%q@%q@%d",
5121 multiVal_dump (v->info->uconst->val),
5122 typeIdSet_dump (uentry_accessType (v)),
5123 (int) sRef_getNullState (v->sref));
5126 return (message ("%q%q#%s",
5127 ctype_dump (v->utype),
5134 return (message ("%q@%q#%s",
5135 ctype_dump (v->utype),
5136 ctype_dump (v->info->datatype->type), v->uname));
5143 uentry_unparseAbbrev (uentry v)
5145 if (!uentry_isVariable (v))
5147 llcontbuglit ("uentry_unparseAbbrev: not variable");
5148 return uentry_unparse (v);
5151 return (message ("%s %q", ctype_unparseDeep (v->utype), uentry_getName (v)));
5155 uentry_unparse (uentry v)
5159 if (uentry_isUndefined (v)) return (cstring_makeLiteral ("<undefined>"));
5160 if (uentry_isElipsisMarker (v)) return (cstring_makeLiteral ("..."));
5162 st = uentry_getName (v);
5164 if (cstring_isDefined (st))
5166 return (ctype_unparseDeclaration (v->utype, st));
5171 return (cstring_copy (ctype_unparse (v->utype)));
5176 uentry_unparseFull (uentry v)
5178 if (uentry_isUndefined (v))
5180 return (cstring_makeLiteral ("<undefined>"));
5186 res = message ("[%w] %s %s: %s [spec: %q; decl: %q; def: %q]",
5187 (unsigned long) v, ekind_unparse (v->ukind), v->uname,
5188 ctype_unparse (v->utype),
5189 fileloc_unparse (uentry_whereSpecified (v)),
5190 fileloc_unparse (uentry_whereDeclared (v)),
5191 fileloc_unparse (uentry_whereDefined (v)));
5193 DPRINTF (("uentry: %s", res));
5195 if (uentry_isDatatype (v))
5197 res = message ("%q / type: %s mut: %s abs: %s state: %q",
5200 (ctype_isDefined (v->info->datatype->type)
5201 ? v->info->datatype->type : ctype_unknown),
5202 ynm_unparse (v->info->datatype->mut),
5203 ynm_unparse (v->info->datatype->abs),
5204 sRef_unparseState (v->sref));
5206 else if (uentry_isFunction (v))
5208 res = message ("%q / sref: %q / mods: %q / "
5209 "globs: %q / clauses: %q / pre: %q / post: %q",
5211 sRef_unparseFull (v->sref),
5212 sRefSet_unparse (v->info->fcn->mods),
5213 globSet_unparse (v->info->fcn->globs),
5214 stateClauseList_unparse (v->info->fcn->specclauses),
5215 functionConstraint_unparse (v->info->fcn->preconditions),
5216 functionConstraint_unparse (v->info->fcn->postconditions));
5218 else if (uentry_isIter (v))
5220 res = message ("%q / sref: %q",
5222 sRef_unparseFull (v->sref));
5224 else if (uentry_isVariable (v))
5226 res = message ("%q / sref: %q / kind <%d> isout <%d> null <%d> used <%d>",
5228 sRef_unparseFull (v->sref),
5229 (int) v->info->var->kind,
5230 (int) v->info->var->defstate,
5231 (int) v->info->var->nullstate,
5233 DPRINTF (("sref: [%p]", v->sref));
5234 DPRINTF (("sref: %s", sRef_unparseDebug (v->sref)));
5235 /* DPRINTF (("sref: %s", sRef_unparseDeep (v->sref))); */
5239 res = message ("%q :: %q", res, uentry_unparse (v));
5246 bool uentry_hasAccessType (uentry e)
5248 if (uentry_isValid (e))
5253 return (!typeIdSet_isEmpty (e->info->iter->access));
5255 return (!typeIdSet_isEmpty (e->info->enditer->access));
5257 return (!typeIdSet_isEmpty (e->info->fcn->access));
5260 return (!typeIdSet_isEmpty (e->info->uconst->access));
5269 typeIdSet uentry_accessType (uentry e)
5271 if (uentry_isValid (e))
5276 return (e->info->iter->access);
5278 return (e->info->enditer->access);
5280 return (e->info->fcn->access);
5283 return (e->info->uconst->access);
5289 return typeIdSet_undefined;
5293 uentry_isVariable (uentry e)
5295 return (uentry_isVar (e));
5299 uentry_isSpecified (uentry e)
5301 return (uentry_isValid (e) && !fileloc_isUndefined (e->whereSpecified));
5305 uentry_isReallySpecified (uentry e)
5307 return (uentry_isValid (e)
5308 && fileloc_isRealSpec (e->whereSpecified));
5312 uentry_isVar (uentry e)
5314 return (!uentry_isUndefined (e) && e->ukind == KVAR);
5318 uentry_isFakeTag (uentry e)
5320 return (uentry_isValid (e) && strchr (cstring_toCharsSafe (e->uname), '!') != 0);
5324 uentry_isDatatype (uentry e)
5326 return (!uentry_isUndefined (e) &&
5327 (e->ukind == KDATATYPE || e->ukind == KSTRUCTTAG ||
5328 e->ukind == KUNIONTAG || e->ukind == KENUMTAG));
5332 uentry_setAbstract (uentry e)
5336 llassert (uentry_isDatatype (e)
5337 && (ynm_isMaybe (e->info->datatype->abs)));
5339 oldid = ctype_typeId (e->info->datatype->type);
5340 e->info->datatype->abs = YES;
5341 e->info->datatype->type = ctype_createAbstract (oldid);
5345 uentry_setConcrete (uentry e)
5347 llassert (uentry_isDatatype (e)
5348 && (ynm_isMaybe (e->info->datatype->abs)));
5350 e->info->datatype->abs = NO;
5354 uentry_isAbstractDatatype (uentry e)
5356 return (uentry_isDatatype (e)
5357 && (ynm_isOn (e->info->datatype->abs)));
5361 uentry_isMaybeAbstract (uentry e)
5363 return (uentry_isDatatype (e)
5364 && (ynm_isMaybe (e->info->datatype->abs)));
5368 uentry_isMutableDatatype (uentry e)
5370 bool res = uentry_isDatatype (e)
5371 && (ynm_toBoolRelaxed (e->info->datatype->mut));
5377 uentry_isRefCountedDatatype (uentry e)
5379 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
5383 uentry_isParam (uentry u)
5385 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
5386 || u->info->var->kind == VKYIELDPARAM));
5390 uentry_isExpandedMacro (uentry u)
5392 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
5396 uentry_isSefParam (uentry u)
5398 return (uentry_isVariable (u)
5399 && (u->info->var->kind == VKSEFPARAM
5400 || u->info->var->kind == VKREFSEFPARAM
5401 || u->info->var->kind == VKSEFRETPARAM
5402 || u->info->var->kind == VKREFSEFRETPARAM));
5406 uentry_isRefParam (uentry u)
5408 return (uentry_isVariable (u)
5409 && (u->info->var->kind == VKREFPARAM
5410 || u->info->var->kind == VKREFYIELDPARAM
5411 || u->info->var->kind == VKREFSEFPARAM
5412 || u->info->var->kind == VKREFSEFRETPARAM));
5416 uentry_isAnyParam (uentry u)
5418 return (uentry_isVariable (u)
5419 && ((u->info->var->kind == VKPARAM)
5420 || (u->info->var->kind == VKSEFPARAM)
5421 || (u->info->var->kind == VKYIELDPARAM)
5422 || (u->info->var->kind == VKRETPARAM)
5423 || (u->info->var->kind == VKSEFRETPARAM)));
5427 uentry_getDefState (uentry u)
5429 if (uentry_isValid (u))
5431 return (sRef_getDefState (u->sref));
5435 return (SS_UNKNOWN);
5440 uentry_isOut (uentry u)
5442 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5443 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5447 uentry_isPartial (uentry u)
5449 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5450 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5454 uentry_isStateSpecial (uentry u)
5456 return ((uentry_isVariable (u)
5457 && (u->info->var->defstate == SS_SPECIAL))
5458 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5461 exitkind uentry_getExitCode (uentry ue)
5463 if (uentry_isFunction (ue))
5465 return ue->info->fcn->exitCode;
5473 qual uentry_nullPred (uentry u)
5475 llassert (uentry_isRealFunction (u));
5477 if (uentry_isFunction (u))
5479 return (u->info->fcn->nullPred);
5483 return qual_createUnknown ();
5488 ** Note for variables, this is checking the declared state, not the current state.
5492 uentry_possiblyNull (uentry u)
5494 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5495 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5499 uentry_getAliasKind (uentry u)
5501 if (uentry_isValid (u))
5503 return (sRef_getAliasKind (uentry_getSref (u)));
5512 uentry_getExpKind (uentry u)
5514 if (uentry_isValid (u))
5516 return (sRef_getExKind (uentry_getSref (u)));
5525 uentry_isIter (uentry e)
5527 return (!uentry_isUndefined (e) && e->ukind == KITER);
5531 uentry_isEndIter (uentry e)
5533 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5537 uentry_isRealFunction (uentry e)
5539 return (uentry_isFunction (e) ||
5540 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5544 uentry_hasName (uentry e)
5546 if (uentry_isValid (e))
5548 cstring s = e->uname;
5550 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")
5551 || uentry_isFakeTag (e)));
5560 ** Returns true for fake tags.
5561 ** This is used for dumping the library
5564 bool uentry_hasRealName (uentry e)
5566 return (uentry_isValid (e)
5567 && cstring_isNonEmpty (e->uname)
5568 && !uentry_isGlobalMarker (e));
5572 /*@observer@*/ globSet
5573 uentry_getGlobs (uentry l)
5575 if (uentry_isInvalid (l))
5577 return globSet_undefined;
5580 if (l->ukind != KFCN)
5582 if (l->ukind != KITER && l->ukind != KENDITER)
5584 if (l->ukind == KVAR)
5586 llbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
5588 ekind_unparse (l->ukind)));
5592 llbug (message ("Bad call to uentry_getGlobs: %q (%s)",
5594 ekind_unparse (l->ukind)));
5597 return globSet_undefined;
5600 return l->info->fcn->globs;
5603 /*@observer@*/ sRefSet
5604 uentry_getMods (uentry l)
5606 llassert (uentry_isValid (l));
5608 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5610 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5611 return sRefSet_undefined;
5614 return l->info->fcn->mods;
5618 uentry_getKind (uentry e)
5620 llassert (uentry_isValid (e));
5625 /*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5627 llassert (uentry_isEitherConstant (e));
5629 return (e->info->uconst->val);
5632 /*@observer@*/ uentryList
5633 uentry_getParams (uentry l)
5635 if (uentry_isInvalid (l)) return uentryList_undefined;
5642 ctype ct = l->utype;
5644 if (ctype_isFunction (ct))
5646 return (ctype_argsFunction (ct));
5650 return uentryList_undefined;
5655 ctype ct = l->utype;
5657 llassert (ctype_isFunction (ct));
5658 return (ctype_argsFunction (ct));
5665 /*@observer@*/ cstring
5666 uentry_rawName (uentry e)
5668 if (uentry_isValid (e))
5674 return cstring_undefined;
5679 uentry_getOptName (uentry e)
5681 cstring s = uentry_getName (e);
5683 if (cstring_isDefined (s))
5685 s = cstring_appendChar (s, ' ');
5692 uentry_getName (uentry e)
5694 cstring ret = cstring_undefined;
5696 if (uentry_isValid (e))
5698 if (uentry_isAnyTag (e))
5700 ret = fixTagName (e->uname);
5702 else if (uentry_isAnyParam (e))
5704 ret = cstring_copy (fixParamName (e->uname));
5708 ret = cstring_copy (e->uname);
5715 cstring uentry_observeRealName (uentry e)
5717 cstring ret = cstring_undefined;
5719 if (uentry_isValid (e))
5721 if (uentry_isAnyTag (e))
5723 if (isFakeTag (e->uname))
5725 ret = cstring_undefined;
5729 ret = plainTagName (e->uname);
5732 else if (uentry_isAnyParam (e))
5734 ret = fixParamName (e->uname);
5745 cstring uentry_getRealName (uentry e)
5747 if (uentry_isValid (e))
5749 if (uentry_isAnyTag (e))
5751 return (cstring_undefined);
5758 return cstring_undefined;
5761 ctype uentry_getType (uentry e)
5763 if (uentry_isValid (e))
5769 return ctype_unknown;
5773 fileloc uentry_whereLast (uentry e)
5777 if (uentry_isInvalid (e))
5779 return fileloc_undefined;
5782 loc = e->whereDefined;
5784 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5789 loc = uentry_whereDeclared (e);
5791 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5796 loc = uentry_whereSpecified (e);
5800 fileloc uentry_whereEither (uentry e)
5802 if (uentry_isInvalid (e)) return fileloc_undefined;
5804 if (fileloc_isDefined (e->whereDefined)
5805 && !fileloc_isExternal (e->whereDefined))
5807 return e->whereDefined;
5809 else if (fileloc_isDefined (e->whereDeclared))
5811 return e->whereDeclared;
5815 return e->whereSpecified;
5819 fileloc uentry_whereSpecified (uentry e)
5821 if (uentry_isInvalid (e)) return fileloc_undefined;
5823 return (e->whereSpecified);
5826 fileloc uentry_whereDefined (uentry e)
5828 if (uentry_isInvalid (e)) return fileloc_undefined;
5830 return (e->whereDefined);
5833 fileloc uentry_whereDeclared (uentry e)
5835 if (uentry_isInvalid (e)) return fileloc_undefined;
5837 return (e->whereDeclared);
5840 /*@observer@*/ fileloc
5841 uentry_whereEarliest (uentry e)
5843 if (uentry_isInvalid (e)) return fileloc_undefined;
5845 if (fileloc_isDefined (e->whereSpecified))
5847 return (e->whereSpecified);
5849 else if (fileloc_isDefined (e->whereDeclared))
5851 return (e->whereDeclared);
5855 return e->whereDefined;
5860 uentry_setFunctionDefined (uentry e, fileloc loc)
5862 if (uentry_isValid (e))
5864 llassert (uentry_isFunction (e));
5866 if (fileloc_isUndefined (e->whereDeclared))
5868 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
5871 if (!fileloc_isDefined (e->whereDefined))
5873 e->whereDefined = fileloc_update (e->whereDefined, loc);
5879 uentry_setDeclDef (uentry e, fileloc f)
5881 uentry_setDeclared (e, f);
5883 if (!uentry_isFunction (e)
5884 && !(uentry_isVariable (e) && uentry_isExtern (e)))
5886 uentry_setDefined (e, f);
5891 uentry_setDeclaredForce (uentry e, fileloc f)
5893 llassert (uentry_isValid (e));
5894 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5898 uentry_setDeclaredForceOnly (uentry e, fileloc f)
5900 llassert (uentry_isValid (e));
5901 fileloc_free (e->whereDeclared);
5902 e->whereDeclared = f;
5906 uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
5910 llassert (uentry_isValid (e));
5911 oldloc = e->whereDeclared;
5913 if (fileloc_isDefined (oldloc))
5915 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
5917 e->whereDeclared = f;
5918 fileloc_free (oldloc);
5927 e->whereDeclared = f;
5928 fileloc_free (oldloc);
5933 uentry_setDeclared (uentry e, fileloc f)
5937 llassert (uentry_isValid (e));
5938 oldloc = e->whereDeclared;
5940 if (fileloc_isDefined (oldloc))
5942 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
5944 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5953 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5958 uentry_clearDefined (uentry e)
5960 if (uentry_isValid (e))
5962 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
5967 uentry_setDefined (uentry e, fileloc f)
5971 llassert (uentry_isValid (e));
5972 oldloc = e->whereDefined;
5974 if (fileloc_isDefined (oldloc))
5976 if (fileloc_isLib (oldloc)
5977 || fileloc_isImport (oldloc)
5978 || fileloc_isBuiltin (oldloc)
5979 || fileloc_isPreproc (oldloc))
5981 e->whereDefined = fileloc_update (e->whereDefined, f);
5985 if (fileloc_equal (oldloc, f) || context_processingMacros ())
5991 if (optgenerror (FLG_REDEF,
5992 message ("%s %q redefined",
5993 ekind_capName (e->ukind),
5994 uentry_getName (e)),
5997 llgenindentmsg (message ("Previous definition of %q",
5998 uentry_getName (e)),
6006 e->whereDefined = fileloc_update (e->whereDefined, f);
6011 uentry_isCodeDefined (uentry e)
6013 return (uentry_isValid (e) && fileloc_isDefined (e->whereDefined));
6017 uentry_isDeclared (uentry e)
6019 if (uentry_isValid (e))
6021 return (fileloc_isDefined (e->whereDeclared));
6027 sRef uentry_getSref (uentry e)
6029 /* not true, used for functions too (but shouldn't be? */
6030 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
6032 if (uentry_isInvalid (e)) return sRef_undefined;
6037 sRef uentry_getOrigSref (uentry e)
6039 if (uentry_isValid (e))
6041 sRef sr = sRef_copy (uentry_getSref (e));
6043 sRef_resetState (sr);
6044 sRef_clearDerived (sr);
6046 if (uentry_isVariable (e))
6048 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
6049 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
6056 return sRef_undefined;
6061 ** requires: uentry e is not in a hashed symbol table
6065 uentry_setName (uentry e, /*@only@*/ cstring n)
6067 llassert (uentry_isValid (e));
6069 cstring_free (e->uname);
6074 uentry_setType (uentry e, ctype t)
6076 if (uentry_isValid (e))
6079 sRef_setType (e->sref, t);
6084 uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
6087 ctype rettype = ctype_unknown;
6089 llassert (uentry_isValid (ue));
6091 rct = ctype_realType (ue->utype);
6093 if (uentry_isVariable (ue) && (ctype_isFunction (rct) || ctype_isUnknown (rct)))
6095 uentry_makeVarFunction (ue);
6098 llassert (uentry_isFunction (ue));
6100 if (ctype_isFunction (rct))
6102 rettype = ctype_getReturnType (rct);
6105 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
6109 uentry_setRefParam (uentry e)
6112 if (!uentry_isVar (e))
6114 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6118 if (e->info->var->kind == VKSEFPARAM)
6120 e->info->var->kind = VKREFSEFPARAM;
6122 else if (e->info->var->kind == VKSEFRETPARAM)
6124 e->info->var->kind = VKREFSEFRETPARAM;
6126 else if (e->info->var->kind == VKYIELDPARAM)
6128 e->info->var->kind = VKREFYIELDPARAM;
6132 e->info->var->kind = VKREFPARAM;
6138 uentry_setParam (uentry e)
6140 if (!uentry_isVar (e))
6142 if (uentry_isElipsisMarker (e))
6148 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
6155 if (e->info->var->kind == VKYIELDPARAM
6156 || e->info->var->kind == VKSEFPARAM
6157 || e->info->var->kind == VKSEFRETPARAM)
6163 e->info->var->kind = VKPARAM;
6167 e->uname = makeParam (e->uname);
6168 cstring_free (oldname);
6173 uentry_setSref (uentry e, sRef s)
6175 if (uentry_isValid (e))
6177 if (sRef_isValid (e->sref))
6179 sRef_mergeStateQuietReverse (e->sref, s);
6183 e->sref = sRef_saveCopy (s);
6189 uentry_getAbstractType (uentry e)
6191 llassert (uentry_isDatatype (e));
6194 ** This assertion removed.
6195 ** Okay to have undefined type, for system types
6197 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
6198 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
6203 if (ctype_isUndefined (e->info->datatype->type))
6205 return ctype_unknown;
6209 ** Sadly, a kludge...
6212 if (ctype_isUserBool (e->info->datatype->type)) {
6216 return e->info->datatype->type;
6219 ctype uentry_getRealType (uentry e)
6222 typeId uid = USYMIDINVALID;
6224 if (uentry_isInvalid (e))
6226 return ctype_unknown;
6229 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6231 if (uentry_isAnyTag (e))
6236 if (uentry_isAbstractType (e))
6238 ct = uentry_getAbstractType (e);
6240 if (ctype_isManifestBool (ct)) {
6244 llassert (ctype_isUA (ct));
6246 uid = ctype_typeId (ct);
6248 if (!context_hasAccess (uid))
6254 ct = uentry_getType (e);
6256 /* if (ctype_isUserBool (ct)) return ct; */
6258 if (ctype_isManifestBool (ct)) {
6262 if (ctype_isUA (ct))
6264 usymId iid = ctype_typeId (ct);
6266 if (usymId_equal (iid, uid))
6268 llcontbug (message ("uentry_getRealType: recursive type! %s",
6269 ctype_unparse (ct)));
6274 /* evs 2000-07-25: possible infinite recursion ? */
6275 uentry ue2 = usymtab_getTypeEntry (iid);
6279 llcontbug (message ("Bad recursion: %q", uentry_unparseFull (e)));
6280 return ctype_unknown;
6283 return uentry_getRealType (ue2);
6292 ctype uentry_getForceRealType (uentry e)
6295 typeId uid = USYMIDINVALID;
6297 if (uentry_isInvalid (e))
6299 return ctype_unknown;
6302 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
6304 if (uentry_isAnyTag (e))
6309 if (uentry_isAbstractType (e))
6311 ct = uentry_getAbstractType (e);
6312 llassert (ctype_isUA (ct));
6314 uid = ctype_typeId (ct);
6315 /* no check for access! */
6318 ct = uentry_getType (e);
6320 /* evs 2000-07-25 */
6321 /* if (ctype_isUserBool (ct)) return ct; */
6323 if (ctype_isManifestBool (ct)) {
6327 if (ctype_isUA (ct))
6329 usymId iid = ctype_typeId (ct);
6331 if (usymId_equal (iid, uid))
6333 llcontbug (message ("uentry_getRealType: recursive type! %s",
6334 ctype_unparse (ct)));
6339 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
6348 uentry uentry_nameCopy (cstring name, uentry e)
6350 uentry enew = uentry_alloc ();
6352 llassert (uentry_isValid (e));
6354 /* enew->shallowCopy = FALSE; */
6355 enew->ukind = e->ukind;
6357 enew->utype = e->utype;
6358 enew->whereSpecified = fileloc_copy (e->whereSpecified);
6359 enew->whereDefined = fileloc_copy (e->whereDefined);
6360 enew->whereDeclared = fileloc_copy (e->whereDeclared);
6361 enew->sref = sRef_copy (e->sref);
6362 enew->used = e->used;
6364 enew->isPrivate = e->isPrivate;
6365 enew->hasNameError = FALSE;
6367 enew->uses = filelocList_new ();
6368 enew->warn = warnClause_undefined;
6370 enew->storageclass = e->storageclass;
6371 enew->info = uinfo_copy (e->info, e->ukind);
6377 uentry_setDatatype (uentry e, usymId uid)
6379 llassert (uentry_isDatatype (e));
6381 if (uentry_isAbstractType (e))
6383 e->info->datatype->type = ctype_createAbstract (uid);
6387 e->info->datatype->type = ctype_createUser (uid);
6392 uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
6393 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
6396 llassert (uentry_isValid (e));
6398 if (fileloc_isSpec (f) || fileloc_isImport (f))
6400 e->whereSpecified = f;
6401 e->whereDeclared = fileloc_undefined;
6402 e->whereDefined = fileloc_undefined;
6406 e->whereSpecified = fileloc_undefined;
6407 e->whereDeclared = f;
6408 e->whereDefined = fileloc_undefined;
6413 ucinfo_free (/*@only@*/ ucinfo u)
6415 multiVal_free (u->val);
6420 uvinfo_free (/*@only@*/ uvinfo u)
6422 /*drl7x added 6/29/01 */
6423 /*free null terminated stuff */
6425 // free(u->bufinfo);
6430 udinfo_free (/*@only@*/ udinfo u)
6436 ufinfo_free (/*@only@*/ ufinfo u)
6438 globSet_free (u->globs);
6439 sRefSet_free (u->mods);
6440 stateClauseList_free (u->specclauses);
6445 uiinfo_free (/*@only@*/ uiinfo u)
6451 ueinfo_free (/*@only@*/ ueinfo u)
6456 static /*@only@*/ ucinfo
6457 ucinfo_copy (ucinfo u)
6459 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
6461 ret->val = multiVal_copy (u->val);
6462 ret->access = u->access;
6467 static /*@only@*/ uvinfo
6468 uvinfo_copy (uvinfo u)
6470 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
6472 ret->kind = u->kind;
6473 ret->nullstate = u->nullstate;
6474 ret->defstate = u->defstate;
6475 ret->checked = u->checked;
6477 /* drl added 07-02-001 */
6478 /* copy null terminated information */
6480 if (u->bufinfo != NULL)
6482 ret->bufinfo = (bbufinfo) dmalloc (sizeof( * u->bufinfo ) );
6483 ret->bufinfo->bufstate = u->bufinfo->bufstate;
6484 ret->bufinfo->size = u->bufinfo->size;
6485 ret->bufinfo->len = u->bufinfo->len;
6490 ret->bufinfo = NULL;
6496 static /*@only@*/ udinfo
6497 udinfo_copy (udinfo u)
6499 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6503 ret->type = u->type;
6508 static /*@only@*/ ufinfo
6509 ufinfo_copy (ufinfo u)
6511 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6513 ret->hasGlobs = u->hasGlobs;
6514 ret->hasMods = u->hasMods;
6515 ret->exitCode = u->exitCode;
6516 ret->specialCode = u->specialCode;
6517 ret->nullPred = u->nullPred;
6518 ret->access = u->access;
6519 ret->globs = globSet_newCopy (u->globs);
6520 ret->mods = sRefSet_newCopy (u->mods);
6521 ret->defparams = u->defparams;
6522 ret->specclauses = stateClauseList_copy (u->specclauses);
6524 ret->preconditions = functionConstraint_copy (u->preconditions);
6525 ret->postconditions = functionConstraint_copy (u->postconditions);
6530 static /*@only@*/ uiinfo
6531 uiinfo_copy (uiinfo u)
6533 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6535 ret->access = u->access;
6536 ret->globs = globSet_newCopy (u->globs);
6537 ret->mods = sRefSet_newCopy (u->mods);
6542 static /*@only@*/ ueinfo
6543 ueinfo_copy (ueinfo u)
6545 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6547 ret->access = u->access;
6552 uinfo_free (uinfo u, ekind kind)
6557 case KCONST: ucinfo_free (u->uconst); break;
6558 case KVAR: uvinfo_free (u->var); break;
6562 case KDATATYPE: udinfo_free (u->datatype); break;
6563 case KFCN: ufinfo_free (u->fcn); break;
6564 case KITER: uiinfo_free (u->iter); break;
6565 case KENDITER: ueinfo_free (u->enditer); break;
6566 case KELIPSMARKER: break;
6567 case KINVALID: break;
6573 static /*@only@*/ /*@null@*/ uinfo
6574 uinfo_copy (uinfo u, ekind kind)
6576 if (kind == KELIPSMARKER || kind == KINVALID)
6582 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6587 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6588 case KVAR: ret->var = uvinfo_copy (u->var); break;
6592 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6593 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6594 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6595 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6603 uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6605 filelocList_free (e->uses);
6606 cstring_free (e->uname);
6608 uinfo_free (e->info, e->ukind);
6610 fileloc_free (e->whereSpecified);
6611 fileloc_free (e->whereDefined);
6612 fileloc_free (e->whereDeclared);
6614 warnClause_free (e->warn);
6620 extern void uentry_markOwned (/*@owned@*/ uentry u)
6622 sfreeEventually (u);
6626 uentry_free (/*@only@*/ uentry e)
6628 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6630 uentry_reallyFree (e);
6635 ** For uentry's in the global or file scope
6639 uentry_freeComplete (/*@only@*/ uentry e)
6641 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6643 DPRINTF (("Free complete: %s", sRef_unparseFull (e->sref)));
6644 /*@i@*/ sRef_free (e->sref);
6645 e->sref = sRef_undefined;
6646 uentry_reallyFree (e);
6651 ** requires old->kind != new->kind, old->uname = new->uname
6655 KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6657 llassert (uentry_isValid (old));
6658 llassert (uentry_isValid (unew));
6660 if (uentry_isEitherConstant (unew)
6661 && (fileloc_isPreproc (uentry_whereDeclared (old))
6662 || ctype_isUnknown (old->utype))
6663 && !uentry_isSpecified (old))
6671 if (!uentry_isDeclared (old))
6673 if (uentry_isSpecified (old))
6675 if (uentry_isSpecified (unew))
6677 llbuglit ("Respecification!");
6679 else if (uentry_isDeclared (unew))
6683 message ("%s %q inconsistently declared as %s: %t",
6684 ekind_capName (old->ukind),
6685 uentry_getName (unew),
6686 ekind_unparseLong (unew->ukind),
6688 uentry_whereDeclared (unew)))
6690 uentry_showWhereLast (old);
6702 message ("%s %q inconsistently declared as %s: %t",
6703 ekind_capName (old->ukind),
6704 uentry_getName (unew),
6705 ekind_unparseLong (unew->ukind),
6707 uentry_whereDeclared (unew)))
6709 uentry_showWhereLast (old);
6715 llassert (uentry_isDeclared (unew));
6719 message ("%s %q inconsistently redeclared as %s",
6720 ekind_capName (old->ukind),
6721 uentry_getName (unew),
6722 ekind_unparseLong (unew->ukind)),
6723 uentry_whereDeclared (unew)))
6725 uentry_showWhereLast (old);
6731 uentry_copyInto (old, unew);
6735 ** def is the definition of spec, modifies spec
6737 ** reports any inconsistencies
6738 ** returns the summary of all available information
6739 ** if spec and def are inconsistent, def is returned
6743 uentry_showWhereLast (uentry spec)
6745 if (uentry_isValid (spec))
6747 if (fileloc_isDefined (spec->whereDefined)
6748 && !fileloc_isLib (spec->whereDefined)
6749 && !fileloc_isPreproc (spec->whereDefined))
6751 llgenindentmsg (message ("Previous definition of %q: %t",
6752 uentry_getName (spec),
6753 uentry_getType (spec)),
6754 uentry_whereDefined (spec));
6756 else if (uentry_isDeclared (spec))
6758 llgenindentmsg (message ("Previous declaration of %q: %t",
6759 uentry_getName (spec),
6760 uentry_getType (spec)),
6761 uentry_whereDeclared (spec));
6763 else if (uentry_isSpecified (spec))
6765 if (uentry_hasName (spec))
6767 llgenindentmsg (message ("Specification of %q: %t",
6768 uentry_getName (spec),
6769 uentry_getType (spec)),
6770 uentry_whereSpecified (spec));
6774 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
6775 uentry_whereSpecified (spec));
6780 /* nothing to show */
6786 uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
6788 fileloc loc = uentry_whereDefined (ce);
6790 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6792 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
6796 loc = uentry_whereSpecified (ce);
6798 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6800 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
6805 void uentry_showWhereLastExtra (uentry spec, cstring extra)
6807 if (uentry_isDeclared (spec))
6809 llgenindentmsg (message ("Previous declaration of %q: %q",
6810 uentry_getName (spec), extra),
6811 uentry_whereDeclared (spec));
6813 else if (uentry_isSpecified (spec))
6815 llgenindentmsg (message ("Specification of %q: %q",
6816 uentry_getName (spec), extra),
6817 uentry_whereSpecified (spec));
6821 cstring_free (extra);
6826 uentry_showWhereDeclared (uentry spec)
6828 if (uentry_isDeclared (spec))
6830 if (uentry_hasName (spec))
6832 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6833 uentry_whereDeclared (spec));
6837 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6840 else if (uentry_isSpecified (spec))
6842 if (uentry_hasName (spec))
6844 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6845 uentry_whereSpecified (spec));
6849 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
6854 /* nothing to show */
6860 uentry_showWhereAny (uentry spec)
6862 if (uentry_isDeclared (spec))
6864 if (uentry_hasName (spec))
6866 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6867 uentry_whereDeclared (spec));
6871 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6874 else if (uentry_isSpecified (spec))
6876 if (uentry_hasName (spec))
6878 llgenindentmsg (message ("Specification of %q",
6879 uentry_getName (spec)),
6880 uentry_whereSpecified (spec));
6884 llgenindentmsg (cstring_makeLiteral ("Specification"),
6885 uentry_whereSpecified (spec));
6888 else if (fileloc_isDefined (uentry_whereDefined (spec)))
6890 if (uentry_hasName (spec))
6892 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
6893 uentry_whereDefined (spec));
6897 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
6902 /* nothing to show */
6907 uentry_showWhereDefined (uentry spec)
6909 if (uentry_isCodeDefined (spec))
6911 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
6912 uentry_whereDefined (spec));
6917 uentry_showWhereLastPlain (uentry spec)
6919 if (uentry_isDeclared (spec))
6921 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
6922 uentry_whereDeclared (spec));
6924 else if (uentry_isSpecified (spec))
6926 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6927 uentry_whereSpecified (spec));
6935 uentry_showWhereLastVal (uentry spec, cstring val)
6937 if (uentry_isDeclared (spec))
6939 llgenindentmsg (message ("Previous declaration of %q: %s",
6940 uentry_getName (spec), val),
6941 uentry_whereDeclared (spec));
6943 else if (uentry_isSpecified (spec))
6945 llgenindentmsg (message ("Specification of %q: %s",
6946 uentry_getName (spec), val),
6947 uentry_whereSpecified (spec));
6955 uentry_showWhereSpecified (uentry spec)
6957 if (uentry_isSpecified (spec))
6959 if (uentry_hasName (spec))
6961 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6962 uentry_whereSpecified (spec));
6966 llgenindentmsg (cstring_makeLiteral ("Specification"),
6967 uentry_whereSpecified (spec));
6970 else if (uentry_isDeclared (spec))
6972 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6973 uentry_whereDeclared (spec));
6977 /* nothing to show */
6982 uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
6984 if (uentry_isSpecified (spec))
6986 if (uentry_hasName (spec))
6988 llgenindentmsg (message ("Specification of %q: %q",
6989 uentry_getName (spec), s),
6990 uentry_whereSpecified (spec));
6994 llgenindentmsg (message ("Specification: %q", s),
6995 uentry_whereSpecified (spec));
6998 else if (uentry_isDeclared (spec))
7000 llgenindentmsg (message ("Declaration of %q: %q",
7001 uentry_getName (spec), s),
7002 uentry_whereDeclared (spec));
7006 llgenindentmsg (message ("Previous: %q", s),
7007 uentry_whereLast (spec));
7016 checkStructConformance (uentry old, uentry unew)
7019 uentryList fold, fnew;
7022 ** requires: types of old and new are structs or unions
7025 llassert (uentry_isValid (old));
7026 llassert (uentry_isValid (unew));
7028 oldr = ctype_realType (old->utype);
7029 fold = ctype_getFields (oldr);
7031 newr = ctype_realType (unew->utype);
7032 fnew = ctype_getFields (newr);
7034 if (!uentryList_matchFields (fold, fnew))
7036 if (fileloc_equal (uentry_whereLast (old),
7037 uentry_whereLast (unew)))
7045 message ("%q %q %rdeclared with fields { %q }, %s "
7046 "with fields { %q }",
7047 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
7048 uentry_getName (old),
7049 uentry_isDeclared (old),
7050 uentryList_unparseAbbrev (fnew),
7051 uentry_specOrDefName (old),
7052 uentryList_unparseAbbrev (fold)),
7053 uentry_whereDeclared (unew)))
7055 uentry_showWhereLastPlain (old);
7056 uentryList_showFieldDifference (fold, fnew);
7060 old->utype = unew->utype;
7065 checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7068 ** requires old and new are enums
7071 ctype rold = ctype_realType (old->utype);
7072 ctype rnew = ctype_realType (unew->utype);
7073 enumNameList eold = ctype_elist (rold);
7074 enumNameList enew = ctype_elist (rnew);
7076 if (!enumNameList_match (eold, enew))
7080 message ("Enum %q declared with members { %q } but "
7081 "specified with members { %q }",
7082 uentry_getName (old),
7083 enumNameList_unparse (enew),
7084 enumNameList_unparse (eold)),
7085 uentry_whereDeclared (unew)))
7087 uentry_showWhereSpecified (old);
7088 old->utype = unew->utype;
7094 ** either oldCurrent or newCurrent may be undefined!
7098 paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
7099 uentry unew, uentry newCurrent, ctype newType,
7102 bool hasError = FALSE;
7104 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
7106 if (uentry_hasName (newCurrent))
7108 hasError = optgenerror
7110 message ("Parameter %d, %q, of function %q has inconsistent type: "
7111 "declared %t, %s %t",
7112 paramno + 1, uentry_getName (newCurrent),
7113 uentry_getName (unew),
7114 newType, uentry_specOrDefName (old), oldType),
7115 uentry_whereDeclared (newCurrent));
7119 hasError = optgenerror
7121 message ("Parameter %d of function %q has inconsistent type: "
7122 "declared %t, %s %t",
7123 paramno + 1, uentry_getName (unew),
7124 newType, uentry_specOrDefName (old), oldType),
7125 uentry_whereDeclared (newCurrent));
7127 DPRINTF (("type: %s / %s",
7128 ctype_unparse (newType),
7129 ctype_unparse (ctype_realType (newType))));
7134 if (uentry_isDeclared (unew))
7136 hasError = optgenerror
7138 message ("Parameter %d of function %s has inconsistent type: "
7139 "declared %t, %s %t",
7140 paramno + 1, unew->uname,
7141 newType, uentry_specOrDefName (old), oldType),
7142 uentry_whereDeclared (unew));
7146 hasError = optgenerror
7148 message ("Parameter %d of function %s has inconsistent type: "
7149 "declared %t, %s %t",
7150 paramno + 1, unew->uname,
7151 newType, uentry_specOrDefName (old), oldType),
7152 uentry_whereDeclared (unew));
7158 if (!uentry_isUndefined (oldCurrent))
7160 if (!uentry_isUndefined (newCurrent)
7161 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
7163 uentry_showWhereLast (oldCurrent);
7167 uentry_showWhereLastPlain (old);
7170 uentry_setType (oldCurrent, newType);
7174 uentry_showWhereLastPlain (old);
7180 nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7184 message ("Function %s %rdeclared with %d arg%&, %s with %d",
7186 uentry_isDeclared (old),
7187 uentryList_size (uentry_getParams (unew)),
7188 uentry_specOrDefName (old),
7189 uentryList_size (uentry_getParams (old))),
7190 uentry_whereDeclared (unew)))
7192 uentry_showWhereLastPlain (old);
7197 returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
7201 message ("Function %s inconsistently %rdeclared to return %t",
7203 uentry_isDeclared (old),
7204 ctype_getReturnType (unew->utype)),
7205 uentry_whereDeclared (unew)))
7207 uentry_showWhereLastVal (old, ctype_unparse (ctype_getReturnType (old->utype)));
7211 static cstring paramStorageName (uentry ue)
7213 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
7216 static cstring fcnErrName (uentry ue)
7218 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
7221 extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
7223 if (uentry_isVar (ue))
7225 return (checkedName (ue->info->var->checked));
7229 return (cstring_makeLiteralTemp ("<checked invalid>"));
7233 static cstring checkedName (chkind checked)
7237 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
7238 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
7239 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
7240 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
7241 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
7247 void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
7252 if (uentry_isVar (unew))
7254 llassert (uentry_isVar (old));
7256 oldState = old->info->var->nullstate;
7257 newState = unew->info->var->nullstate;
7261 oldState = sRef_getNullState (old->sref);
7262 newState = sRef_getNullState (unew->sref);
7265 if (oldState == NS_ABSNULL)
7267 if (uentry_isVar (old))
7269 old->info->var->nullstate = newState;
7272 sRef_mergeNullState (old->sref, newState);
7274 else if (newState == NS_UNKNOWN)
7276 if (completeConform && newState != oldState
7277 && uentry_isReallySpecified (old))
7281 message ("%s %q specified as %s, but declared without %s qualifier",
7282 ekind_capName (unew->ukind),
7283 uentry_getName (unew),
7284 nstate_unparse (oldState),
7285 nstate_unparse (oldState)),
7286 uentry_whereDeclared (unew)))
7288 uentry_showWhereSpecified (old);
7292 if (uentry_isVar (unew))
7294 unew->info->var->nullstate = oldState;
7297 sRef_mergeNullState (unew->sref, oldState);
7299 else if (newState == NS_POSNULL)
7301 if (oldState == NS_MNOTNULL
7302 && (ctype_isUA (unew->utype)
7303 || (uentry_isFunction (unew)
7304 && ctype_isUA (ctype_getReturnType (unew->utype)))))
7306 if (uentry_isVar (unew))
7308 unew->info->var->nullstate = oldState;
7311 sRef_mergeNullState (unew->sref, oldState);
7315 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
7316 || oldState == NS_UNKNOWN)
7323 ("%s %q inconsistently %rdeclared %s possibly null storage, "
7325 uentry_ekindName (unew),
7326 uentry_getName (unew),
7327 uentry_isDeclared (old),
7329 uentry_specOrDefName (old),
7330 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
7331 uentry_whereDeclared (unew)))
7333 uentry_showWhereSpecified (old);
7338 if (uentry_isVar (old))
7340 old->info->var->nullstate = newState;
7343 sRef_mergeNullState (old->sref, newState);
7346 else if (newState == NS_MNOTNULL)
7348 if (oldState != NS_MNOTNULL)
7354 message ("%s %q inconsistently %rdeclared %s notnull storage, "
7355 "%s without notnull qualifier",
7356 uentry_ekindName (unew),
7357 uentry_getName (unew),
7358 uentry_isDeclared (old),
7360 uentry_specOrDefName (old)),
7361 uentry_whereDeclared (unew)))
7363 uentry_showWhereSpecified (old);
7367 if (uentry_isVar (old))
7369 old->info->var->nullstate = newState;
7372 sRef_mergeNullState (old->sref, newState);
7377 if (uentry_isVar (unew))
7379 unew->info->var->nullstate = oldState;
7382 sRef_mergeNullState (unew->sref, oldState);
7387 void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7388 bool mustConform, bool completeConform)
7394 if (uentry_isVar (old) && uentry_isVar (unew))
7396 oldState = old->info->var->defstate;
7397 newState = unew->info->var->defstate;
7402 oldState = sRef_getDefState (old->sref);
7403 newState = sRef_getDefState (unew->sref);
7406 if (newState != oldState
7407 && newState != SS_UNKNOWN
7408 && newState != SS_DEFINED)
7410 DPRINTF (("Where declared: %s / %s",
7411 fileloc_unparse (uentry_whereDeclared (unew)),
7412 bool_unparse (fileloc_isXHFile (uentry_whereDeclared (unew)))));
7418 message ("%s %q inconsistently %rdeclared %s %s %s, "
7420 uentry_ekindName (unew),
7421 uentry_getName (unew),
7422 uentry_isDeclared (old),
7424 sstate_unparse (newState),
7425 paramStorageName (unew),
7426 uentry_specOrDefName (old),
7428 sstate_unparse (oldState),
7429 paramStorageName (unew)),
7430 uentry_whereDeclared (unew)))
7432 uentry_showWhereSpecified (old);
7436 if (vars) old->info->var->defstate = newState;
7437 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
7442 && (newState != oldState) && (oldState != SS_DEFINED)
7443 && uentry_isReallySpecified (old))
7447 message ("%s %q specified as %s, but declared without %s qualifier",
7448 ekind_capName (unew->ukind),
7449 uentry_getName (unew),
7450 sstate_unparse (oldState),
7451 sstate_unparse (oldState)),
7452 uentry_whereDeclared (unew)))
7454 uentry_showWhereSpecified (old);
7458 if (vars) unew->info->var->defstate = oldState;
7459 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
7464 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7465 bool mustConform, bool completeConform)
7470 oldKind = sRef_getAliasKind (old->sref);
7471 newKind = sRef_getAliasKind (unew->sref);
7473 if (alkind_isImplicit (newKind)
7474 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
7476 if (completeConform && !alkind_equal (newKind, oldKind)
7477 && uentry_isReallySpecified (old))
7481 message ("%s %q specified as %s, but declared without "
7482 "explicit alias qualifier",
7483 ekind_capName (unew->ukind),
7484 uentry_getName (unew),
7485 alkind_unparse (oldKind)),
7486 uentry_whereDeclared (unew)))
7488 uentry_showWhereSpecified (old);
7493 ** This really shouldn't be necessary, but it is!
7494 ** Function params (?) use new here.
7497 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7501 if (alkind_isKnown (newKind))
7503 if (!alkind_equal (oldKind, newKind))
7505 if (alkind_isKnown (oldKind))
7510 message ("%s %q inconsistently %rdeclared %s %s storage, "
7512 uentry_ekindName (unew),
7513 uentry_getName (unew),
7514 uentry_isDeclared (old),
7516 alkind_unparse (newKind),
7517 uentry_specOrDefName (old),
7518 alkind_unparse (oldKind)),
7519 uentry_whereDeclared (unew)))
7521 uentry_showWhereSpecified (old);
7523 DPRINTF (("Old: %s", sRef_unparseFull (old->sref)));
7524 DPRINTF (("New: %s", sRef_unparseFull (unew->sref)));
7525 sRef_setAliasKind (old->sref, AK_ERROR,
7526 uentry_whereDeclared (unew));
7530 sRef_setAliasKind (old->sref, newKind,
7531 uentry_whereDeclared (unew));
7536 if (!(alkind_isImplicit (newKind)))
7539 !uentry_isFunction (unew) &&
7542 message ("%s %q inconsistently %rdeclared %s %s storage, "
7543 "implicitly %s as temp storage",
7544 uentry_ekindName (unew),
7545 uentry_getName (unew),
7546 uentry_isDeclared (old),
7548 alkind_unparse (newKind),
7549 uentry_specOrDefName (old)),
7550 uentry_whereDeclared (unew)))
7552 uentry_showWhereSpecified (old);
7556 sRef_setAliasKind (old->sref, newKind,
7557 uentry_whereDeclared (unew));
7559 else /* newKind is temp or refcounted */
7566 else /* newKind unknown */
7573 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7574 bool mustConform, bool completeConform)
7579 oldKind = sRef_getExKind (old->sref);
7580 newKind = sRef_getExKind (unew->sref);
7582 if (exkind_isKnown (newKind))
7584 if (oldKind != newKind)
7586 if (exkind_isKnown (oldKind))
7591 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7592 uentry_ekindName (unew),
7593 uentry_getName (unew),
7594 uentry_isDeclared (old),
7596 exkind_unparse (newKind),
7597 uentry_specOrDefName (old),
7598 exkind_unparse (oldKind)),
7599 uentry_whereDeclared (unew)))
7601 uentry_showWhereSpecified (old);
7604 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7611 message ("%s %q inconsistently %rdeclared %s %s, "
7612 "implicitly %s without exposure qualifier",
7613 uentry_ekindName (unew),
7614 uentry_getName (unew),
7615 uentry_isDeclared (old),
7617 exkind_unparse (newKind),
7618 uentry_specOrDefName (old)),
7619 uentry_whereDeclared (unew)))
7621 uentry_showWhereSpecified (old);
7624 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7630 if (completeConform && exkind_isKnown (oldKind)
7631 && uentry_isReallySpecified (old))
7635 message ("%s %q specified as %s, but declared without "
7636 "exposure qualifier",
7637 ekind_capName (unew->ukind),
7638 uentry_getName (unew),
7639 exkind_unparse (oldKind)),
7640 uentry_whereDeclared (unew)))
7642 uentry_showWhereSpecified (old);
7646 /* yes, this is necessary! (if its a param) */
7647 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7652 checkMetaState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7653 bool mustConform, /*@unused@*/ bool completeConform)
7655 valueTable newvals = sRef_getValueTable (unew->sref);
7657 if (valueTable_isDefined (newvals))
7659 DPRINTF (("Check meta state: %s -> %s",
7660 uentry_unparseFull (old),
7661 uentry_unparseFull (unew)));
7663 DPRINTF (("Check meta state refs: %s -> %s",
7664 sRef_unparseFull (old->sref),
7665 sRef_unparseFull (unew->sref)));
7667 DPRINTF (("Value table: %s", valueTable_unparse (newvals)));
7670 ** Copy the new values into the old ref
7673 valueTable_elements (newvals, key, newval)
7675 metaStateInfo msinfo = context_lookupMetaStateInfo (key);
7676 stateValue oldval = sRef_getMetaStateValue (old->sref, key);
7678 llassert (metaStateInfo_isDefined (msinfo));
7680 if (stateValue_isUndefined (oldval))
7682 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7686 if (stateValue_isError (oldval))
7688 if (!stateValue_isError (newval))
7690 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7694 ; /* No change necessary. */
7699 if (stateValue_getValue (newval) != stateValue_getValue (oldval))
7701 if (fileloc_isXHFile (uentry_whereDeclared (unew)))
7707 if (!stateValue_isError (newval))
7712 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7713 uentry_ekindName (unew),
7714 uentry_getName (unew),
7715 uentry_isDeclared (old),
7717 metaStateInfo_unparseValue (msinfo,
7718 stateValue_getValue (newval)),
7719 uentry_specOrDefName (old),
7720 metaStateInfo_unparseValue (msinfo,
7721 stateValue_getValue (oldval))),
7722 uentry_whereDeclared (unew)))
7724 uentry_showWhereSpecified (old);
7729 DPRINTF (("Updating!"));
7730 sRef_setMetaStateValue (old->sref, key, stateValue_getValue (newval), uentry_whereLast (unew));
7734 DPRINTF (("Values match"));
7738 } end_valueTable_elements ;
7743 uentry_checkStateConformance (/*@notnull@*/ uentry old,
7744 /*@notnull@*/ uentry unew,
7745 bool mustConform, bool completeConform)
7747 checkDefState (old, unew, mustConform, completeConform);
7748 checkNullState (old, unew, mustConform, completeConform);
7749 checkAliasState (old, unew, mustConform, completeConform);
7750 checkExpState (old, unew, mustConform, completeConform);
7751 checkMetaState (old, unew, mustConform, completeConform);
7753 sRef_storeState (old->sref);
7754 sRef_storeState (unew->sref);
7758 checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
7760 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
7765 llassert (uentry_isVar (old));
7766 llassert (uentry_isVar (unew));
7768 if (cstring_isEmpty (old->uname))
7770 cstring_free (old->uname);
7771 old->uname = cstring_copy (unew->uname);
7774 if (unew->info->var->kind == VKRETPARAM
7775 || unew->info->var->kind == VKSEFRETPARAM)
7777 if (old->info->var->kind != VKRETPARAM
7778 && old->info->var->kind != VKSEFRETPARAM)
7782 message ("Parameter %q inconsistently %rdeclared as "
7783 "returned parameter",
7784 uentry_getName (unew),
7785 uentry_isDeclared (old)),
7786 uentry_whereDeclared (unew)))
7788 uentry_showWhereSpecified (old);
7789 old->info->var->kind = unew->info->var->kind;
7795 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
7797 if (old->info->var->kind != VKSEFPARAM
7798 && old->info->var->kind != VKSEFRETPARAM)
7802 message ("Parameter %qinconsistently %rdeclared as "
7804 uentry_getOptName (unew),
7805 uentry_isDeclared (old)),
7806 uentry_whereDeclared (unew)))
7808 uentry_showWhereSpecified (old);
7809 old->info->var->kind = unew->info->var->kind;
7814 if (old->info->var->kind == VKSPEC)
7816 old->info->var->kind = unew->info->var->kind;
7820 unew->info->var->kind = old->info->var->kind;
7823 if (unew->info->var->checked != CH_UNKNOWN
7824 && unew->info->var->checked != old->info->var->checked)
7826 if (old->info->var->checked == CH_UNKNOWN
7827 && !fileloc_isUser (uentry_whereLast (old)))
7835 message ("Variable %q inconsistently %rdeclared as "
7836 "%s parameter (was %s)",
7837 uentry_getName (unew),
7838 uentry_isDeclared (old),
7839 checkedName (unew->info->var->checked),
7840 checkedName (old->info->var->checked)),
7841 uentry_whereDeclared (unew)))
7843 uentry_showWhereSpecified (old);
7847 old->info->var->checked = unew->info->var->checked;
7852 && (old->info->var->checked != CH_UNKNOWN)
7853 && uentry_isReallySpecified (old))
7857 message ("%s %q specified as %s, but declared without %s qualifier",
7858 ekind_capName (unew->ukind),
7859 uentry_getName (unew),
7860 checkedName (old->info->var->checked),
7861 checkedName (old->info->var->checked)),
7862 uentry_whereDeclared (unew)))
7864 uentry_showWhereSpecified (old);
7868 unew->info->var->checked = old->info->var->checked;
7871 uentry_checkStateConformance (old, unew, mustConform, completeConform);
7874 void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
7876 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
7881 llassert (uentry_isVar (u1));
7882 llassert (uentry_isVar (u2));
7884 if (u1->info->var->kind != u2->info->var->kind) {
7885 if (u1->info->var->kind == VKSEFRETPARAM) {
7886 if (u2->info->var->kind == VKRETPARAM) {
7889 message ("Function types are inconsistent. Parameter %d is "
7890 "sef parameter, but non-sef parameter in "
7891 "assigned function: %s",
7892 paramno, exprNode_unparse (e)),
7894 } else if (u2->info->var->kind == VKSEFPARAM) {
7897 message ("Function types are inconsistent. Parameter %d is "
7898 "returns parameter, but non-returns parameter in "
7899 "assigned function: %s",
7900 paramno, exprNode_unparse (e)),
7905 message ("Function types are inconsistent. Parameter %d is "
7906 "sef returns parameter, but non-sef returns parameter in "
7907 "assigned function: %s",
7908 paramno, exprNode_unparse (e)),
7911 } else if (u1->info->var->kind == VKRETPARAM) {
7914 message ("Function types are inconsistent. Parameter %d is "
7915 "returns parameter, but non-returns parameter in "
7916 "assigned function: %s",
7917 paramno, exprNode_unparse (e)),
7919 } else if (u1->info->var->kind == VKSEFPARAM) {
7922 message ("Function types are inconsistent. Parameter %d is "
7923 "sef parameter, but non-sef parameter in "
7924 "assigned function: %s",
7925 paramno, exprNode_unparse (e)),
7928 if (u2->info->var->kind == VKSEFRETPARAM) {
7931 message ("Function types are inconsistent. Parameter %d is "
7932 "normal parameter, but sef returns parameter in "
7933 "assigned function: %s",
7934 paramno, exprNode_unparse (e)),
7936 } else if (u2->info->var->kind == VKSEFPARAM) {
7939 message ("Function types are inconsistent. Parameter %d is "
7940 "normal parameter, but sef parameter in "
7941 "assigned function: %s",
7942 paramno, exprNode_unparse (e)),
7944 } else if (u2->info->var->kind == VKRETPARAM) {
7947 message ("Function types are inconsistent. Parameter %d is "
7948 "normal parameter, but returns parameter in "
7949 "assigned function: %s",
7950 paramno, exprNode_unparse (e)),
7958 if (u1->info->var->defstate != u2->info->var->defstate)
7962 message ("Function types are inconsistent. Parameter %d is "
7963 "%s, but %s in assigned function: %s",
7965 sstate_unparse (u1->info->var->defstate),
7966 sstate_unparse (u2->info->var->defstate),
7967 exprNode_unparse (e)),
7971 if (u1->info->var->nullstate != u2->info->var->nullstate)
7975 message ("Function types are inconsistent. Parameter %d is "
7976 "%s, but %s in assigned function: %s",
7978 nstate_unparse (u1->info->var->nullstate),
7979 nstate_unparse (u2->info->var->nullstate),
7980 exprNode_unparse (e)),
7984 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
7988 message ("Function types are inconsistent. Parameter %d is "
7989 "%s, but %s in assigned function: %s",
7991 alkind_unparse (sRef_getAliasKind (u1->sref)),
7992 alkind_unparse (sRef_getAliasKind (u2->sref)),
7993 exprNode_unparse (e)),
7997 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
8001 message ("Function types are inconsistent. Parameter %d is "
8002 "%s, but %s in assigned function: %s",
8004 exkind_unparse (sRef_getExKind (u1->sref)),
8005 exkind_unparse (sRef_getExKind (u2->sref)),
8006 exprNode_unparse (e)),
8012 checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8013 /*@notnull@*/ uentry unew,
8014 bool mustConform, /*@unused@*/ bool completeConform)
8016 uentryList oldParams = uentry_getParams (old);
8017 uentryList newParams = uentry_getParams (unew);
8018 ctype newType = unew->utype;
8019 ctype oldType = old->utype;
8020 ctype oldRetType = ctype_unknown;
8021 ctype newRetType = ctype_unknown;
8023 DPRINTF (("Function conform: %s ==> %s",
8024 uentry_unparseFull (old),
8025 uentry_unparseFull (unew)));
8027 if (uentry_isForward (old))
8029 mustConform = FALSE;
8030 uentry_copyInto (old, unew);
8035 ** check return values
8038 if (ctype_isKnown (oldType))
8040 llassert (ctype_isFunction (oldType));
8042 oldRetType = ctype_getReturnType (oldType);
8045 if (ctype_isKnown (newType))
8047 llassert (ctype_isFunction (newType));
8049 newRetType = ctype_getReturnType (newType);
8052 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
8053 && !ctype_matchDef (newRetType, oldRetType))
8055 if (mustConform) returnValueError (old, unew);
8059 if (ctype_isConj (newRetType))
8061 if (ctype_isConj (oldRetType))
8063 if (!ctype_sameAltTypes (newRetType, oldRetType))
8067 message ("Function %q inconsistently %rdeclared to "
8068 "return alternate types %s "
8069 "(types match, but alternates are not identical, "
8070 "so checking may not be correct)",
8071 uentry_getName (unew),
8072 uentry_isDeclared (old),
8073 ctype_unparse (newRetType)),
8074 uentry_whereDeclared (unew)))
8076 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
8082 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
8087 DPRINTF (("Before state: %s",
8088 uentry_unparseFull (old)));
8089 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8090 DPRINTF (("After state: %s",
8091 uentry_unparseFull (old)));
8093 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
8095 if (exitkind_isKnown (unew->info->fcn->exitCode))
8099 message ("Function %q inconsistently %rdeclared using %s",
8100 uentry_getName (unew),
8101 uentry_isDeclared (old),
8102 exitkind_unparse (unew->info->fcn->exitCode)),
8103 uentry_whereDeclared (unew)))
8105 uentry_showWhereSpecified (old);
8110 unew->info->fcn->exitCode = old->info->fcn->exitCode;
8114 if (!qual_isUnknown (unew->info->fcn->nullPred))
8116 if (!qual_match (old->info->fcn->nullPred, unew->info->fcn->nullPred))
8120 message ("Function %q inconsistently %rdeclared using %s",
8121 uentry_getName (unew),
8122 uentry_isDeclared (old),
8123 qual_unparse (unew->info->fcn->nullPred)),
8124 uentry_whereDeclared (unew)))
8126 uentry_showWhereSpecified (old);
8132 unew->info->fcn->nullPred = old->info->fcn->nullPred;
8135 if (unew->info->fcn->specialCode != SPC_NONE)
8137 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
8141 message ("Function %q inconsistently %rdeclared using %s",
8142 uentry_getName (unew),
8143 uentry_isDeclared (old),
8144 specCode_unparse (unew->info->fcn->specialCode)),
8145 uentry_whereDeclared (unew)))
8147 uentry_showWhereSpecified (old);
8153 unew->info->fcn->specialCode = old->info->fcn->specialCode;
8160 if (!uentryList_sameObject (oldParams, newParams)
8161 && (!uentryList_isMissingParams (oldParams)))
8163 if (!uentryList_isMissingParams (newParams))
8166 int nparams = uentryList_size (oldParams);
8167 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
8169 if (nparams != uentryList_size (newParams))
8171 nargsError (old, unew);
8174 if (uentryList_size (newParams) < nparams)
8176 nparams = uentryList_size (newParams);
8179 while (paramno < nparams)
8181 uentry oldCurrent = uentryList_getN (oldParams, paramno);
8182 uentry newCurrent = uentryList_getN (newParams, paramno);
8183 ctype oldCurrentType = uentry_getType (oldCurrent);
8184 ctype newCurrentType = uentry_getType (newCurrent);
8186 llassert (uentry_isValid (oldCurrent)
8187 && uentry_isValid (newCurrent));
8189 if (!uentry_isElipsisMarker (oldCurrent)
8190 && !uentry_isElipsisMarker (newCurrent))
8192 checkVarConformance (oldCurrent, newCurrent,
8193 mustConform, completeConform);
8198 if (uentry_hasName (oldCurrent)
8199 && uentry_hasName (newCurrent))
8201 cstring oldname = uentry_getName (oldCurrent);
8202 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
8204 cstring nname = uentry_getName (newCurrent);
8207 if (cstring_isDefined (pfx)
8208 && cstring_equalPrefix (oldname, cstring_toCharsSafe (pfx)))
8210 oname = cstring_suffix (oldname, cstring_length (pfx));
8215 /*@-branchstate@*/ } /*@=branchstate@*/
8217 if (cstring_isDefined (pfx)
8218 && cstring_equalPrefix (nname, cstring_toCharsSafe (pfx)))
8220 nnamefix = cstring_suffix (nname, cstring_length (pfx));
8225 /*@-branchstate@*/ } /*@=branchstate@*/
8227 if (!cstring_equal (oname, nnamefix))
8230 (FLG_DECLPARAMMATCH,
8231 message ("Definition parameter name %s does not match "
8232 "name of corresponding parameter in "
8235 uentry_whereLast (newCurrent)))
8237 uentry_showWhereLastPlain (oldCurrent);
8241 cstring_free (oldname);
8242 cstring_free (nname);
8246 if (!ctype_match (oldCurrentType, newCurrentType))
8248 paramTypeError (old, oldCurrent, oldCurrentType,
8249 unew, newCurrent, newCurrentType, paramno);
8253 if (ctype_isMissingParamsMarker (newCurrentType)
8254 || ctype_isElips (newCurrentType)
8255 || ctype_isMissingParamsMarker (oldCurrentType)
8256 || ctype_isElips (oldCurrentType))
8262 if (ctype_isConj (newCurrentType))
8264 if (ctype_isConj (oldCurrentType))
8266 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
8270 message ("Parameter %q inconsistently %rdeclared with "
8271 "alternate types %s "
8272 "(types match, but alternates are not identical, "
8273 "so checking may not be correct)",
8274 uentry_getName (newCurrent),
8275 uentry_isDeclared (oldCurrent),
8276 ctype_unparse (newCurrentType)),
8277 uentry_whereDeclared (unew)))
8279 uentry_showWhereLastVal (oldCurrent,
8280 ctype_unparse (oldCurrentType));
8288 message ("Parameter %q inconsistently %rdeclared with "
8289 "alternate types %s",
8290 uentry_getName (newCurrent),
8291 uentry_isDeclared (oldCurrent),
8292 ctype_unparse (newCurrentType)),
8293 uentry_whereDeclared (unew)))
8295 uentry_showWhereLastVal (oldCurrent,
8296 ctype_unparse (oldCurrentType));
8303 if (ctype_isConj (oldCurrentType))
8305 uentry_setType (newCurrent, oldCurrentType);
8313 ** Forgot this! detected by lclint:
8314 ** uentry.c:1257,15: Suspected infinite loop
8320 if (!uentryList_isMissingParams (newParams))
8322 if (ctype_isConj (oldRetType))
8324 old->utype = ctype_makeFunction (oldRetType,
8325 uentryList_copy (newParams));
8329 old->utype = unew->utype;
8333 checkGlobalsConformance (old, unew, mustConform, completeConform);
8334 checkModifiesConformance (old, unew, mustConform, completeConform);
8336 DPRINTF (("Before list: %s",
8337 uentry_unparseFull (old)));
8339 if (stateClauseList_isDefined (unew->info->fcn->specclauses))
8341 if (!stateClauseList_isDefined (old->info->fcn->specclauses))
8346 message ("Function %q redeclared using special clauses (can only "
8347 "be used in first declaration)",
8348 uentry_getName (unew)),
8349 uentry_whereDeclared (unew)))
8351 uentry_showWhereLast (old);
8355 /*@i23 need checking @*/
8357 old->info->fcn->specclauses = unew->info->fcn->specclauses;
8361 /*@i43 should be able to append? @*/
8363 stateClauseList_checkEqual (old, unew);
8364 stateClauseList_free (unew->info->fcn->specclauses);
8365 unew->info->fcn->specclauses = stateClauseList_undefined;
8368 /*@=branchstate@*/ /*@i23 shouldn't need this@*/
8371 DPRINTF (("After state: %s",
8372 uentry_unparseFull (old)));
8374 if (fileloc_isUndefined (old->whereDeclared))
8376 old->whereDeclared = fileloc_copy (unew->whereDeclared);
8378 else if (fileloc_isUndefined (unew->whereDeclared))
8380 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8389 uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
8393 llassert (uentry_isValid (ue));
8394 llassert (uentry_isEitherConstant (ue));
8396 uval = ue->info->uconst->val;
8398 if (multiVal_isDefined (uval))
8400 if (multiVal_isDefined (m))
8402 if (!multiVal_equiv (uval, m))
8406 message ("%s %q defined with inconsistent value: %q",
8407 ekind_capName (ue->ukind),
8408 uentry_getName (ue),
8409 multiVal_unparse (m)),
8412 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
8420 ue->info->uconst->val = m;
8421 multiVal_free (uval);
8426 bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
8429 bool typeError = FALSE;
8431 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
8433 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
8437 DPRINTF (("Check struct conformance: %s / %s",
8438 uentry_unparseFull (old),
8439 uentry_unparseFull (unew)));
8440 checkStructConformance (old, unew);
8445 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8447 llbug (message ("struct tags: bad types: %t / %t",
8448 old->utype, unew->utype));
8452 else if (uentry_isEnumTag (old))
8454 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
8456 if (mustConform) checkEnumConformance (old, unew);
8460 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
8462 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
8463 ctype_unparse (unew->utype)));
8467 else if (!ctype_match (old->utype, unew->utype))
8469 DPRINTF (("Type mismatch: %s / %s",
8470 ctype_unparse (old->utype),
8471 ctype_unparse (unew->utype)));
8473 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
8475 ctype realt = ctype_realType (unew->utype);
8477 if (ctype_isRealInt (realt) || ctype_isChar (realt))
8479 unew->utype = ctype_bool;
8485 typeError = optgenerror
8487 message ("%q defined as %s", uentry_getName (old),
8488 ctype_unparse (realt)),
8489 uentry_whereDeclared (unew));
8497 ctype oldr = ctype_realType (old->utype);
8498 ctype newr = ctype_realType (unew->utype);
8500 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
8502 checkStructConformance (old, unew);
8504 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
8506 checkStructConformance (old, unew);
8508 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
8510 checkEnumConformance (old, unew);
8512 else if (uentry_isConstant (old)
8513 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
8515 /* okay...for now! (should check the type is reset later... */
8519 DPRINTF (("YABA!"));
8522 message ("%s %q %rdeclared with inconsistent type: %t",
8523 ekind_capName (unew->ukind),
8524 uentry_getName (unew),
8525 uentry_isDeclared (old),
8527 uentry_whereDeclared (unew)))
8529 uentry_showWhereLast (old);
8545 uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
8546 /*@notnull@*/ uentry unew,
8547 bool mustConform, bool completeConform)
8549 if (ctype_isDefined (unew->info->datatype->type))
8552 ** bool is hard coded here, since it is built into LCL.
8553 ** For now, we're stuck with LCL's types.
8556 if (ctype_isDirectBool (old->utype) &&
8557 cstring_equalLit (unew->uname, "bool"))
8559 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
8560 evs 2000-07-25: removed
8562 unew->utype = ctype_bool;
8565 if (ctype_isUnknown (old->info->datatype->type))
8567 old->info->datatype->type = unew->info->datatype->type;
8571 DPRINTF (("Old: %s / New: %s",
8572 uentry_unparseFull (old),
8573 uentry_unparseFull (unew)));
8574 DPRINTF (("Types: %s / %s",
8575 ctype_unparse (old->info->datatype->type),
8576 ctype_unparse (unew->info->datatype->type)));
8578 if (ctype_matchDef (old->info->datatype->type,
8579 unew->info->datatype->type))
8588 ("Type %q %s with inconsistent type: %t",
8589 uentry_getName (unew),
8590 uentry_reDefDecl (old, unew),
8591 unew->info->datatype->type),
8592 uentry_whereDeclared (unew)))
8594 uentry_showWhereLastExtra
8595 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
8598 old->info->datatype->type = unew->info->datatype->type;
8603 if (unew->info->datatype->abs != MAYBE)
8605 if (ynm_isOff (old->info->datatype->abs)
8606 && ynm_isOn (unew->info->datatype->abs))
8608 if (!ctype_isDirectBool (old->utype))
8613 ("Datatype %q inconsistently %rdeclared as abstract type",
8614 uentry_getName (unew),
8615 uentry_isDeclared (old)),
8616 uentry_whereDeclared (unew)))
8618 uentry_showWhereLastPlain (old);
8622 else if (ynm_isOn (old->info->datatype->abs)
8623 && ynm_isOff (unew->info->datatype->abs))
8625 if (!ctype_isDirectBool (old->utype))
8630 ("Datatype %q inconsistently %rdeclared as concrete type",
8631 uentry_getName (unew),
8632 uentry_isDeclared (old)),
8633 uentry_whereDeclared (unew)))
8635 uentry_showWhereLastPlain (old);
8646 if (ynm_isOn (old->info->datatype->abs))
8648 old->sref = unew->sref;
8649 unew->info->datatype->mut = old->info->datatype->mut;
8652 && uentry_isReallySpecified (old))
8657 ("Datatype %q specified as abstract, "
8658 "but abstract annotation not used in declaration",
8659 uentry_getName (unew)),
8660 uentry_whereDeclared (unew)))
8662 uentry_showWhereLastPlain (old);
8668 unew->info->datatype->abs = old->info->datatype->abs;
8670 if (ynm_isMaybe (unew->info->datatype->mut))
8672 if (completeConform && ynm_isOff (old->info->datatype->mut)
8673 && uentry_isReallySpecified (old))
8678 ("Datatype %q specified as immutable, "
8679 "but immutable annotation not used in declaration",
8680 uentry_getName (unew)),
8681 uentry_whereDeclared (unew)))
8683 uentry_showWhereLastPlain (old);
8687 unew->info->datatype->mut = old->info->datatype->mut;
8689 else if (ynm_isMaybe (old->info->datatype->mut))
8691 old->info->datatype->mut = unew->info->datatype->mut;
8695 if (ynm_isOn (old->info->datatype->abs))
8697 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
8701 message ("Datatype %q inconsistently %rdeclared as immutable",
8702 uentry_getName (unew),
8703 uentry_isDeclared (old)),
8704 uentry_whereDeclared (unew)))
8706 uentry_showWhereLastPlain (old);
8711 if (ynm_isOff (old->info->datatype->mut)
8712 && ynm_isOn (unew->info->datatype->mut))
8716 message ("Datatype %q inconsistently %rdeclared as mutable",
8717 uentry_getName (unew),
8718 uentry_isDeclared (old)),
8719 uentry_whereDeclared (unew)))
8721 uentry_showWhereLastPlain (old);
8726 old->info->datatype->mut = unew->info->datatype->mut;
8729 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8733 uentry_checkConstantConformance (/*@notnull@*/ uentry old,
8734 /*@notnull@*/ uentry unew,
8736 /*@unused@*/ bool completeConform)
8738 multiVal oldVal = old->info->uconst->val;
8739 multiVal newVal = unew->info->uconst->val;
8741 if (multiVal_isDefined (oldVal))
8743 if (multiVal_isDefined (newVal))
8745 if (!multiVal_equiv (oldVal, newVal))
8750 message ("%s %q %rdeclared with inconsistent value: %q",
8751 ekind_capName (unew->ukind),
8752 uentry_getName (unew),
8753 uentry_isDeclared (old),
8754 multiVal_unparse (newVal)),
8755 uentry_whereDeclared (unew)))
8757 uentry_showWhereLastExtra (old, multiVal_unparse (oldVal));
8761 unew->info->uconst->val = multiVal_copy (oldVal);
8762 multiVal_free (newVal);
8771 old->info->uconst->val = multiVal_copy (newVal);
8776 uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8777 /*@notnull@*/ uentry unew, bool mustConform,
8778 bool completeConform)
8780 bool typeError = FALSE;
8781 bool fcnConformance = FALSE;
8783 if (!ekind_equal (unew->ukind, old->ukind))
8786 ** okay, only if one is a function and the other is
8787 ** a variable of type function.
8790 if (unew->ukind == KENUMCONST
8791 && old->ukind == KCONST)
8793 old->ukind = KENUMCONST;
8797 if (unew->ukind == KFCN
8798 && old->ukind == KCONST
8799 && ctype_isUnknown (old->utype))
8802 ** When a function is defined with an unparam macro
8805 uentry_copyInto (old, unew);
8809 if (uentry_isExpandedMacro (old)
8810 && uentry_isEitherConstant (unew))
8812 uentry_copyInto (old, unew);
8816 if (uentry_isEndIter (unew))
8818 if (ctype_isUnknown (old->utype))
8820 if (!uentry_isSpecified (old)
8821 && uentry_isCodeDefined (unew))
8823 if (!fileloc_withinLines (uentry_whereDefined (old),
8824 uentry_whereDeclared (unew), 2))
8825 { /* bogus! will give errors if there is too much whitespace */
8829 ("Iterator finalized name %q does not match name in "
8830 "previous iter declaration (should be end_%q). This iter "
8831 "is declared at %q",
8832 uentry_getName (unew),
8833 uentry_getName (old),
8834 fileloc_unparse (uentry_whereDefined (old))),
8835 uentry_whereDeclared (old));
8839 uentry_copyInto (old, unew);
8844 KindConformanceError (old, unew, mustConform);
8848 if (uentry_isFunction (unew))
8850 if (uentry_isVariable (old))
8852 if (!ctype_isUnknown (old->utype))
8854 if (ctype_isFunction (old->utype))
8856 uentry_makeVarFunction (old);
8857 checkFunctionConformance (old, unew, mustConform,
8859 fcnConformance = TRUE;
8863 KindConformanceError (old, unew, mustConform);
8868 if (uentry_isExpandedMacro (old))
8870 if (fileloc_isUndefined (unew->whereDefined))
8872 unew->whereDefined = fileloc_update (unew->whereDefined,
8876 uentry_copyInto (old, unew);
8877 old->used = unew->used = TRUE;
8882 /* undeclared identifier */
8883 old->utype = unew->utype;
8884 uentry_makeVarFunction (old);
8885 checkFunctionConformance (old, unew, FALSE, FALSE);
8886 fcnConformance = TRUE;
8892 KindConformanceError (old, unew, mustConform);
8895 else if (uentry_isFunction (old) && uentry_isVariable (unew))
8897 if (!ctype_isUnknown (unew->utype))
8899 if (ctype_isFunction (unew->utype))
8901 uentry_makeVarFunction (unew);
8902 checkFunctionConformance (old, unew, mustConform, completeConform);
8903 fcnConformance = TRUE;
8907 KindConformanceError (old, unew, mustConform);
8912 KindConformanceError (old, unew, mustConform);
8917 KindConformanceError (old, unew, mustConform);
8923 ** check parameter lists for functions
8924 ** (before type errors, to get better messages
8927 if (uentry_isFunction (old))
8929 checkFunctionConformance (old, unew, mustConform, completeConform);
8930 fcnConformance = TRUE;
8934 if (!ctype_isUndefined (old->utype))
8936 typeError = checkTypeConformance (old, unew, mustConform);
8943 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
8945 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
8948 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
8950 DPRINTF (("Check datatype: %s / %s",
8951 uentry_unparseFull (old),
8952 uentry_unparseFull (unew)));
8954 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
8957 if (uentry_isVariable (old) && uentry_isVariable (unew))
8960 !ctype_matchDef (old->utype, unew->utype))
8965 ("Variable %q %s with inconsistent type (arrays and pointers are "
8966 "not identical in variable declarations): %t",
8967 uentry_getName (unew),
8968 uentry_reDefDecl (old, unew),
8970 uentry_whereDeclared (unew)))
8972 uentry_showWhereLast (old);
8975 ** Avoid repeated errors.
8978 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
8980 old->whereDefined = fileloc_update (old->whereDefined,
8988 checkVarConformance (old, unew, mustConform, completeConform);
8993 /* old->utype = unew->utype; */
8997 if (ctype_isConj (old->utype))
8999 if (ctype_isConj (unew->utype))
9001 if (!ctype_sameAltTypes (old->utype, unew->utype))
9005 message ("%s %q inconsistently %rdeclared with "
9006 "alternate types %s "
9007 "(types match, but alternates are not identical, "
9008 "so checking may not be correct)",
9009 ekind_capName (uentry_getKind (old)),
9010 uentry_getName (unew),
9011 uentry_isDeclared (old),
9012 ctype_unparse (unew->utype)),
9013 uentry_whereDeclared (unew)))
9015 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
9019 old->utype = unew->utype;
9026 if (ctype_isUnknown (old->utype))
9028 old->utype = unew->utype;
9033 if (unew->ukind == old->ukind)
9036 unew->info = uinfo_copy (old->info, old->ukind);
9039 sRef_storeState (old->sref);
9040 sRef_storeState (unew->sref);
9043 static void uentry_mergeConstraints (uentry spec, uentry def)
9045 if (uentry_isFunction (def))
9047 DPRINTF (("Here: %s / %s",
9048 uentry_unparseFull (spec),
9049 uentry_unparseFull (def)));
9051 if (functionConstraint_isDefined (def->info->fcn->preconditions))
9053 if (fileloc_isXHFile (uentry_whereLast (def)))
9055 llassert (uentry_isFunction (spec));
9056 spec->info->fcn->preconditions = functionConstraint_conjoin (spec->info->fcn->preconditions,
9057 def->info->fcn->preconditions);
9058 def->info->fcn->preconditions = functionConstraint_undefined;
9067 if (functionConstraint_isDefined (def->info->fcn->postconditions))
9069 if (fileloc_isXHFile (uentry_whereLast (def)))
9071 llassert (uentry_isFunction (spec));
9072 DPRINTF (("Post: %s /++/ %s",
9073 functionConstraint_unparse (spec->info->fcn->postconditions),
9074 functionConstraint_unparse (def->info->fcn->postconditions)));
9075 spec->info->fcn->postconditions = functionConstraint_conjoin (spec->info->fcn->postconditions,
9076 def->info->fcn->postconditions);
9077 def->info->fcn->postconditions = functionConstraint_undefined;
9078 DPRINTF (("Conjoined post: %s", functionConstraint_unparse (spec->info->fcn->postconditions)));
9089 ** modifies spec to reflect def, reports any inconsistencies
9093 uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
9095 llassert (uentry_isValid (spec));
9096 llassert (uentry_isValid (def));
9097 llassert (cstring_equal (spec->uname, def->uname));
9099 DPRINTF (("Merge entries: %s / %s",
9100 uentry_unparseFull (spec),
9101 uentry_unparseFull (def)));
9103 uentry_mergeConstraints (spec, def);
9105 uentry_checkConformance (spec, def, TRUE,
9106 context_getFlag (FLG_NEEDSPEC));
9108 DPRINTF (("Merge entries after conform: %s / %s",
9109 uentry_unparseFull (spec),
9110 uentry_unparseFull (def)));
9112 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
9115 ** okay, declarations conform. Propagate extra information.
9118 uentry_setDefined (spec, uentry_whereDefined (def));
9119 uentry_setDeclared (spec, uentry_whereDeclared (def));
9121 if (uentry_isStatic (def))
9125 message ("%s %q specified, but declared as static",
9126 ekind_capName (def->ukind),
9127 uentry_getName (def)),
9128 uentry_whereDeclared (def)))
9130 uentry_showWhereSpecified (spec);
9135 spec->storageclass = def->storageclass;
9138 sRef_storeState (spec->sref);
9140 spec->used = def->used || spec->used;
9141 spec->hasNameError |= def->hasNameError;
9145 if (!spec->hasNameError)
9147 uentry_checkName (spec);
9156 ** Can't generate function redeclaration errors when the
9157 ** entries are merged, since we don't yet know if its the
9158 ** definition of the function.
9162 uentry_clearDecl (void)
9164 posRedeclared = uentry_undefined;
9165 fileloc_free (posLoc);
9166 posLoc = fileloc_undefined;
9170 uentry_checkDecl (void)
9172 if (uentry_isValid (posRedeclared) && !fileloc_isXHFile (posLoc))
9174 llassert (fileloc_isDefined (posLoc));
9176 if (uentry_isCodeDefined (posRedeclared))
9178 if (optgenerror (FLG_REDECL,
9179 message ("%s %q declared after definition",
9180 ekind_capName (posRedeclared->ukind),
9181 uentry_getName (posRedeclared)),
9184 llgenindentmsg (message ("Definition of %q",
9185 uentry_getName (posRedeclared)),
9186 posRedeclared->whereDeclared);
9191 if (optgenerror (FLG_REDECL,
9192 message ("%s %q declared more than once",
9193 ekind_capName (posRedeclared->ukind),
9194 uentry_getName (posRedeclared)),
9197 llgenindentmsg (message ("Previous declaration of %q",
9198 uentry_getName (posRedeclared)),
9199 posRedeclared->whereDeclared);
9204 fileloc_free (posLoc);
9205 posLoc = fileloc_undefined;
9206 posRedeclared = uentry_undefined;
9210 ** Redefinition of old as unew.
9211 ** modifies old to reflect unew, reports any inconsistencies
9215 uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
9217 fileloc olddef = uentry_whereDeclared (old);
9218 fileloc unewdef = uentry_whereDeclared (unew);
9222 DPRINTF (("uentry merge: %s / %s",
9223 uentry_unparseFull (old),
9224 uentry_unparseFull (unew)));
9226 if (uentry_isExtern (unew))
9228 uentry_setUsed (old, unewdef);
9232 fileloc_isUndefined (olddef)
9233 && fileloc_isDefined (uentry_whereDefined (old))
9234 && !uentry_isExpandedMacro (old);
9236 if (!context_getFlag (FLG_INCONDEFSLIB)
9237 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9239 mustConform = FALSE;
9246 llassert (uentry_isValid (old));
9247 llassert (uentry_isValid (unew));
9248 llassert (cstring_equal (old->uname, unew->uname));
9251 ** should check old one was extern!
9254 if (uentry_isStatic (old))
9256 if (!(uentry_isStatic (unew)))
9260 message ("%s %q shadows static declaration",
9261 ekind_capName (unew->ukind),
9262 uentry_getName (unew)),
9265 uentry_showWhereLast (old);
9270 uentry_setDeclDef (old, unewdef);
9273 else if (uentry_isStatic (unew))
9275 uentry_setDeclDef (old, unewdef);
9277 else if (uentry_isExtern (old))
9279 uentry_setDeclared (old, unewdef);
9283 if (!uentry_isExtern (unew) && !uentry_isForward (old)
9284 && !fileloc_equal (olddef, unewdef)
9285 && !fileloc_isUndefined (olddef)
9286 && !fileloc_isUndefined (unewdef)
9287 && !fileloc_isBuiltin (olddef)
9288 && !fileloc_isBuiltin (unewdef)
9289 && !uentry_isYield (old)
9290 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
9292 if (uentry_isVariable (old) || uentry_isVariable (unew))
9294 ; /* will report redeclaration error later */
9298 if (fileloc_isDefined (uentry_whereDefined (old)))
9302 message ("%s %q defined more than once",
9303 ekind_capName (unew->ukind),
9304 uentry_getName (unew)),
9305 uentry_whereLast (unew)))
9308 (message ("Previous definition of %q",
9309 uentry_getName (old)),
9310 uentry_whereLast (old));
9313 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
9315 uentry_copyInto (old, unew);
9316 old->sref = sRef_saveCopy (old->sref);
9324 if (fileloc_isLib (olddef)
9325 || fileloc_isUndefined (olddef)
9326 || fileloc_isImport (olddef))
9328 if (uentry_isExtern (unew))
9330 if (uentry_isExtern (old)
9331 || (fileloc_isDefined (uentry_whereDeclared (old))
9332 && (!fileloc_equal (uentry_whereDeclared (old),
9333 uentry_whereDefined (old)))))
9337 message ("%s %q declared more than once",
9338 ekind_capName (unew->ukind),
9339 uentry_getName (unew)),
9340 unew->whereDeclared))
9343 (message ("Previous declaration of %q",
9344 uentry_getName (old)),
9345 old->whereDeclared);
9349 uentry_setExtern (old);
9353 uentry_setDefined (old, unewdef);
9359 uentry_mergeConstraints (old, unew);
9361 uentry_checkConformance (old, unew, mustConform, FALSE);
9363 old->used = old->used || unew->used;
9364 old->uses = filelocList_append (old->uses, unew->uses);
9365 unew->uses = filelocList_undefined;
9367 sRef_storeState (old->sref);
9368 sRef_storeState (unew->sref);
9372 old->whereDefined = fileloc_update (old->whereDefined,
9377 ** No redeclaration errors for functions here, since we
9378 ** don't know if this is the definition of the function.
9381 if (fileloc_isUser (old->whereDeclared)
9382 && fileloc_isUser (unew->whereDeclared)
9383 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
9384 && !fileloc_isDefined (unew->whereDefined))
9386 if (uentry_isFunction (old))
9388 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
9389 posLoc = fileloc_update (posLoc, unew->whereDeclared);
9393 if (optgenerror (FLG_REDECL,
9394 message ("%s %q declared more than once",
9395 ekind_capName (unew->ukind),
9396 uentry_getName (unew)),
9397 unew->whereDeclared))
9399 llgenindentmsg (message ("Previous declaration of %q",
9400 uentry_getName (old)),
9401 old->whereDeclared);
9406 if (fileloc_isUndefined (old->whereDefined))
9408 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
9412 if (!context_processingMacros ()
9413 && fileloc_isUser (old->whereDefined)
9414 && fileloc_isUser (unew->whereDefined)
9415 && !fileloc_equal (old->whereDefined, unew->whereDefined))
9417 if (uentry_isVariable (unew) || uentry_isFunction (unew))
9419 if (uentry_isVariable (unew)
9420 && uentry_isExtern (unew))
9422 if (optgenerror (FLG_REDECL,
9423 message ("%s %q declared after definition",
9424 ekind_capName (unew->ukind),
9425 uentry_getName (unew)),
9426 unew->whereDeclared))
9428 llgenindentmsg (message ("Definition of %q",
9429 uentry_getName (old)),
9435 if (optgenerror (FLG_REDEF,
9436 message ("%s %q redefined",
9437 ekind_capName (unew->ukind),
9438 uentry_getName (unew)),
9439 unew->whereDefined))
9441 llgenindentmsg (message ("Previous definition of %q",
9442 uentry_getName (old)),
9450 if (uentry_isExternal (unew))
9452 old->whereDefined = fileloc_createExternal ();
9455 if (unew->hasNameError)
9457 old->hasNameError = TRUE;
9462 if (!old->hasNameError)
9464 uentry_checkName (old);
9467 llassert (!ctype_isUndefined (old->utype));
9471 uentry_copyState (uentry res, uentry other)
9473 llassert (uentry_isValid (res));
9474 llassert (uentry_isValid (other));
9476 res->used = other->used;
9478 res->info->var->kind = other->info->var->kind;
9479 res->info->var->defstate = other->info->var->defstate;
9480 res->info->var->nullstate = other->info->var->nullstate;
9481 res->info->var->checked = other->info->var->checked;
9483 sRef_copyState (res->sref, other->sref);
9487 uentry_sameKind (uentry u1, uentry u2)
9489 if (uentry_isValid (u1) && uentry_isValid (u2))
9491 if (uentry_isVar (u1) && uentry_isVar (u2))
9493 ctype c1 = u1->utype;
9494 ctype c2 = u2->utype;
9496 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
9499 ** both functions, or both not functions
9502 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
9506 return ((u1->ukind == u2->ukind));
9513 static void uentry_copyInto (/*@unique@*/ uentry unew, uentry old)
9515 llassert (uentry_isValid (unew));
9516 llassert (uentry_isValid (old));
9518 unew->ukind = old->ukind;
9519 unew->uname = cstring_copy (old->uname);
9520 unew->utype = old->utype;
9522 unew->whereSpecified = fileloc_copy (old->whereSpecified);
9523 unew->whereDefined = fileloc_copy (old->whereDefined);
9524 unew->whereDeclared = fileloc_copy (old->whereDeclared);
9526 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
9527 unew->used = old->used;
9529 unew->isPrivate = old->isPrivate;
9530 unew->hasNameError = old->hasNameError;
9531 unew->uses = filelocList_undefined;
9533 unew->storageclass = old->storageclass;
9534 unew->info = uinfo_copy (old->info, old->ukind);
9539 uentry_copy (uentry e)
9541 if (uentry_isValid (e))
9543 uentry enew = uentry_alloc ();
9544 DPRINTF (("copy: %s", uentry_unparseFull (e)));
9545 uentry_copyInto (enew, e);
9546 DPRINTF (("Here we are..."));
9547 DPRINTF (("original: %s", uentry_unparseFull (e)));
9548 DPRINTF (("copy: %s", uentry_unparse (enew)));
9549 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
9554 return uentry_undefined;
9559 uentry_setState (uentry res, uentry other)
9561 llassert (uentry_isValid (res));
9562 llassert (uentry_isValid (other));
9564 llassert (res->ukind == other->ukind);
9565 llassert (res->ukind == KVAR);
9567 res->sref = sRef_saveCopy (other->sref);
9568 res->used = other->used;
9569 filelocList_free (res->uses);
9570 res->uses = other->uses;
9571 other->uses = filelocList_undefined;
9572 res->lset = other->lset;
9576 uentry_mergeUses (uentry res, uentry other)
9578 llassert (uentry_isValid (res));
9579 llassert (uentry_isValid (other));
9581 res->used = other->used || res->used;
9582 res->lset = other->lset || res->lset;
9583 res->uses = filelocList_append (res->uses, other->uses);
9584 other->uses = filelocList_undefined;
9589 ** This is a really ugly routine.
9591 ** gack...fix this one day.
9596 ** >> res is the false branch, other is the true branch (or continuation)
9598 ** >> res is the true branch, other is the false branch (or continutation)
9605 ** References not effected by res are propagated from other.
9609 branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
9610 bool flip, clause cl, fileloc loc)
9614 message ("%s %q is %s %s, but %s %s.",
9615 ekind_capName (res->ukind), uentry_getName (res),
9616 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
9617 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
9620 if (sRef_isDead (res->sref))
9622 sRef_showStateInfo (res->sref);
9624 else if (sRef_isKept (res->sref))
9626 sRef_showAliasInfo (res->sref);
9628 else /* dependent */
9630 sRef_showAliasInfo (res->sref);
9631 sRef_showAliasInfo (other->sref);
9634 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
9638 static bool incompatibleStates (sRef rs, sRef os)
9640 alkind rk = sRef_getAliasKind (rs);
9641 alkind ok = sRef_getAliasKind (os);
9643 if (alkind_isError (rk) || alkind_isError (ok))
9649 return ((sRef_isDead (rs)
9650 || (alkind_isKept (rk) && !alkind_isKept (ok))
9651 || (alkind_isDependent (rk)
9652 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
9653 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
9658 branchStateAltError (/*@notnull@*/ uentry res,
9659 /*@notnull@*/ uentry other, bool flip,
9660 clause cl, fileloc loc)
9664 message ("%s %q is %s %s, but %s %s.",
9665 ekind_capName (res->ukind), uentry_getName (res),
9666 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
9667 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
9670 if (sRef_isDead (other->sref))
9672 sRef_showStateInfo (other->sref);
9676 sRef_showAliasInfo (other->sref);
9679 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
9680 sRef_setDefinedComplete (res->sref, fileloc_undefined);
9682 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
9683 sRef_setDefinedComplete (other->sref, fileloc_undefined);
9688 ** A reference is relevant for certain checks, only if it
9689 ** is not definitely null on this path (but not declared
9690 ** to always be null.)
9693 static bool uentry_relevantReference (sRef sr, bool flip)
9695 if (sRef_isKept (sr) || sRef_isDependent (sr))
9703 return !sRef_definitelyNullContext (sr);
9707 return !sRef_definitelyNullAltContext (sr);
9713 uentry_mergeAliasStates (uentry res, uentry other, fileloc loc,
9714 bool mustReturn, bool flip, bool opt,
9717 DPRINTF (("Merge alias states: %s / %s",
9718 uentry_unparseFull (res),
9719 uentry_unparseFull (other)));
9721 if (sRef_isValid (res->sref))
9726 if (incompatibleStates (res->sref, other->sref))
9730 if (sRef_isThroughArrayFetch (res->sref)
9731 && !context_getFlag (FLG_STRICTBRANCHSTATE))
9733 if (sRef_isKept (res->sref) || sRef_isKept (other->sref))
9735 sRef_maybeKill (res->sref, loc);
9737 else if (sRef_isPossiblyDead (other->sref))
9739 sRef_maybeKill (res->sref, loc);
9748 if (uentry_relevantReference (other->sref, flip))
9751 if (sRef_isLocalParamVar (res->sref)
9752 && (sRef_isLocalState (other->sref)
9753 || sRef_isDependent (other->sref)))
9755 if (sRef_isDependent (res->sref))
9757 sRef_setDependent (other->sref, loc);
9761 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
9766 branchStateError (res, other, flip, cl, loc);
9771 if (sRef_isKept (res->sref))
9773 sRef_setKept (other->sref, loc);
9778 if (incompatibleStates (other->sref, res->sref))
9780 if (uentry_relevantReference (res->sref, !flip))
9782 if (sRef_isLocalParamVar (res->sref)
9783 && (sRef_isDependent (res->sref)
9784 || sRef_isLocalState (res->sref)))
9786 if (sRef_isDependent (other->sref))
9788 sRef_setDependent (res->sref, loc);
9792 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
9797 if (sRef_isParam (other->sref))
9800 ** If the local variable associated
9801 ** with the param has the correct state,
9803 ** (e.g., free (s); s = new(); ...
9806 uentry uvar = usymtab_lookupSafe (other->uname);
9808 if (uentry_isValid (uvar)
9809 && ((sRef_isDead (other->sref)
9810 && sRef_isOnly (uvar->sref))
9811 || (sRef_isDependent (other->sref)
9812 && sRef_isOwned (uvar->sref))))
9818 branchStateAltError (res, other,
9824 DPRINTF (("Here: %s / %s",
9825 uentry_unparseFull (res),
9826 uentry_unparseFull (other)));
9828 branchStateAltError (res, other,
9835 if (sRef_isKept (other->sref))
9837 sRef_setKept (res->sref, loc);
9843 DPRINTF (("Merge opt..."));
9844 sRef_mergeOptState (res->sref, other->sref, cl, loc);
9845 DPRINTF (("Done!"));
9849 sRef_mergeState (res->sref, other->sref, cl, loc);
9854 if (sRef_isModified (other->sref))
9856 sRef_setModified (res->sref);
9863 uentry_mergeValueStates (uentry res, uentry other, fileloc loc)
9868 DPRINTF (("Merge values: %s / %s", sRef_unparseFull (res->sref), sRef_unparseFull (other->sref)));
9870 rvalues = sRef_getValueTable (res->sref);
9871 ovalues = sRef_getValueTable (other->sref);
9873 if (valueTable_isUndefined (ovalues))
9875 DPRINTF (("No value table: %s", sRef_unparseFull (other->sref)));
9878 else if (valueTable_isUndefined (rvalues))
9881 ** Copy values from other
9885 DPRINTF (("Has value table: %s", sRef_unparseFull (other->sref)));
9886 DPRINTF (("No value table: %s", sRef_unparseFull (res->sref)));
9891 valueTable_elements (ovalues, fkey, fval) {
9893 metaStateInfo minfo;
9894 stateCombinationTable sctable;
9898 tval = valueTable_lookup (rvalues, fkey);
9900 DPRINTF (("Merge value: %s / %s X %s", fkey,
9901 stateValue_unparse (fval), stateValue_unparse (tval)));
9903 minfo = context_lookupMetaStateInfo (fkey);
9904 llassert (stateValue_isDefined (tval));
9906 if (metaStateInfo_isUndefined (minfo) || !stateValue_isDefined (tval))
9908 DPRINTF (("Cannot find meta state for: %s", fkey));
9913 llassert (metaStateInfo_isDefined (minfo));
9915 if (stateValue_isError (fval)
9916 || sRef_definitelyNullContext (res->sref))
9918 sRef_setMetaStateValueComplete (res->sref,
9919 fkey, stateValue_getValue (fval),
9921 DPRINTF (("Setting res: %s", sRef_unparseFull (res->sref)));
9923 else if (stateValue_isError (tval)
9924 || sRef_definitelyNullAltContext (other->sref))
9926 DPRINTF (("Other branch is definitely null!"));
9930 DPRINTF (("Check: %s / %s / %s / %s", fkey,
9931 metaStateInfo_unparse (minfo),
9932 stateValue_unparse (fval),
9933 stateValue_unparse (tval)));
9935 DPRINTF (("state values: %d / %d",
9936 stateValue_getValue (fval), stateValue_getValue (tval)));
9938 sctable = metaStateInfo_getMergeTable (minfo);
9940 DPRINTF (("Merge table: %s",
9941 stateCombinationTable_unparse (sctable)));
9943 msg = cstring_undefined;
9945 nval = stateCombinationTable_lookup (sctable,
9946 stateValue_getValue (fval),
9947 stateValue_getValue (tval),
9950 DPRINTF (("nval: %d / %d / %d", nval,
9951 stateValue_getValue (fval), stateValue_getValue (tval)));
9953 if (cstring_isDefined (msg))
9955 /*@i32 print extra info for assignments@*/
9957 if (uentry_isGlobalMarker (res))
9962 ("Control branches merge with incompatible global states (%s and %s): %s",
9963 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
9964 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
9968 sRef_showMetaStateInfo (res->sref, fkey);
9969 sRef_showMetaStateInfo (other->sref, fkey);
9977 ("Control branches merge with incompatible states for %q (%s and %s): %s",
9978 uentry_getName (res),
9979 metaStateInfo_unparseValue (minfo, stateValue_getValue (fval)),
9980 metaStateInfo_unparseValue (minfo, stateValue_getValue (tval)),
9984 sRef_showMetaStateInfo (res->sref, fkey);
9985 sRef_showMetaStateInfo (other->sref, fkey);
9986 DPRINTF (("Res: %s", sRef_unparseFull (res->sref)));
9987 DPRINTF (("Other: %s", sRef_unparseFull (other->sref)));
9988 DPRINTF (("Null: %s / %s",
9989 bool_unparse (usymtab_isDefinitelyNull (res->sref)),
9990 bool_unparse (usymtab_isDefinitelyNull (other->sref))));
9996 if (nval == stateValue_getValue (fval)
9997 && nval != stateValue_getValue (tval))
9999 loc = stateValue_getLoc (fval);
10001 else if (nval == stateValue_getValue (tval)
10002 && nval != stateValue_getValue (fval))
10004 loc = stateValue_getLoc (tval);
10011 if (stateValue_getValue (sRef_getMetaStateValue (res->sref, fkey)) == nval
10012 && nval == stateValue_getValue (fval)
10013 && nval == stateValue_getValue (tval))
10019 sRef_setMetaStateValueComplete (res->sref, fkey, nval, loc);
10023 } end_valueTable_elements ;
10029 uentry_mergeSetStates (uentry res, uentry other, /*@unused@*/ fileloc loc,
10030 bool flip, clause cl)
10032 if (cl == DOWHILECLAUSE)
10034 res->used = other->used || res->used;
10035 res->lset = other->lset || res->lset;
10036 res->uses = filelocList_append (res->uses, other->uses);
10037 other->uses = filelocList_undefined;
10041 if (sRef_isMacroParamRef (res->sref)
10042 && !uentry_isSefParam (other)
10043 && !uentry_isSefParam (res))
10045 bool hasError = FALSE;
10047 if (bool_equal (res->used, other->used))
10049 res->used = other->used;
10053 if (other->used && !flip)
10058 message ("Macro parameter %q used in true clause, "
10059 "but not in false clause",
10060 uentry_getName (res)),
10061 uentry_whereDeclared (res));
10068 message ("Macro parameter %q used in false clause, "
10069 "but not in true clause",
10070 uentry_getName (res)),
10071 uentry_whereDeclared (res));
10077 /* make it sef now, prevent more errors */
10078 res->info->var->kind = VKREFSEFPARAM;
10084 res->used = other->used || res->used;
10085 res->lset = other->lset || res->lset;
10086 res->uses = filelocList_append (res->uses, other->uses);
10087 other->uses = filelocList_undefined;
10093 uentry_mergeState (uentry res, uentry other, fileloc loc,
10094 bool mustReturn, bool flip, bool opt,
10097 llassert (uentry_isValid (res));
10098 llassert (uentry_isValid (other));
10100 llassert (res->ukind == other->ukind);
10101 llassert (res->ukind == KVAR);
10103 DPRINTF (("Merge state: %s / %s", uentry_unparseFull (res),
10104 uentry_unparseFull (other)));
10106 uentry_mergeAliasStates (res, other, loc, mustReturn, flip, opt, cl);
10107 uentry_mergeValueStates (res, other, loc);
10108 uentry_mergeSetStates (res, other, loc, flip, cl);
10111 void uentry_setUsed (uentry e, fileloc loc)
10113 static bool firstTime = TRUE;
10114 static bool showUses = FALSE;
10115 static bool exportLocal = FALSE;
10117 DPRINTF (("Used: %s / %s", uentry_unparse (e), fileloc_unparse (loc)));
10121 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
10123 showUses = context_getFlag (FLG_SHOWUSES);
10124 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
10129 if (uentry_isValid (e))
10133 if (warnClause_isDefined (e->warn))
10135 flagSpec flg = warnClause_getFlag (e->warn);
10138 if (warnClause_hasMessage (e->warn))
10140 msg = cstring_copy (warnClause_getMessage (e->warn));
10144 msg = message ("Use of possibly dangerous %s",
10145 uentry_ekindNameLC (e));
10149 message ("%q: %q", msg, uentry_getName (e)),
10153 if (sRef_isMacroParamRef (e->sref))
10155 if (uentry_isYield (e) || uentry_isSefParam (e))
10161 if (context_inConditional ())
10165 message ("Macro parameter %q used in conditionally "
10166 "executed code (may or may not be "
10167 "evaluated exactly once)",
10168 uentry_getName (e)),
10171 e->info->var->kind = VKREFSEFPARAM;
10180 message ("Macro parameter %q used more than once",
10181 uentry_getName (e)),
10182 uentry_whereDeclared (e)))
10184 e->info->var->kind = VKREFSEFPARAM;
10191 if ((dp = uentry_directParamNo (e)) >= 0)
10193 uentry_setUsed (usymtab_getParam (dp), loc);
10198 if (!sRef_isLocalVar (e->sref))
10202 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
10208 if (context_inMacro ())
10210 e->uses = filelocList_addUndefined (e->uses);
10214 e->uses = filelocList_addDifferentFile
10216 uentry_whereDeclared (e),
10225 bool uentry_isReturned (uentry u)
10227 return (uentry_isValid (u) && uentry_isVar (u)
10228 && (u->info->var->kind == VKRETPARAM
10229 || u->info->var->kind == VKSEFRETPARAM));
10232 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args)
10234 llassert (uentry_isRealFunction (u));
10236 if (ctype_isFunction (u->utype) && sRef_isStateSpecial (uentry_getSref (u)))
10238 stateClauseList clauses = uentry_getStateClauseList (u);
10239 sRef res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10241 DPRINTF (("Returned: %s", sRef_unparseFull (res)));
10242 sRef_setAllocated (res, g_currentloc);
10244 DPRINTF (("ensures clause: %s / %s", uentry_unparse (u),
10245 stateClauseList_unparse (clauses)));
10247 stateClauseList_postElements (clauses, cl)
10249 if (!stateClause_isGlobal (cl))
10251 sRefSet refs = stateClause_getRefs (cl);
10252 sRefMod modf = stateClause_getEffectFunction (cl);
10254 sRefSet_elements (refs, el)
10256 sRef base = sRef_getRootBase (el);
10258 if (sRef_isResult (base))
10262 sRef sr = sRef_fixBase (el, res);
10263 modf (sr, g_currentloc);
10270 } end_sRefSet_elements ;
10272 } end_stateClauseList_postElements ;
10280 sRefSet prefs = sRefSet_new ();
10281 sRef res = sRef_undefined;
10284 params = uentry_getParams (u);
10286 uentryList_elements (params, current)
10288 if (uentry_isReturned (current))
10290 if (exprNodeList_size (args) >= paramno)
10292 exprNode ecur = exprNodeList_nth (args, paramno);
10293 sRef tref = exprNode_getSref (ecur);
10295 DPRINTF (("Returned reference: %s", sRef_unparseFull (tref)));
10297 if (sRef_isValid (tref))
10299 sRef tcref = sRef_copy (tref);
10301 usymtab_addForceMustAlias (tcref, tref); /* evans 2001-05-27 */
10303 if (sRef_isDead (tcref))
10305 sRef_setDefined (tcref, g_currentloc);
10306 sRef_setOnly (tcref, g_currentloc);
10309 if (sRef_isRefCounted (tcref))
10311 /* could be a new ref now (but only if its returned) */
10312 sRef_setAliasKindComplete (tcref, AK_ERROR, g_currentloc);
10315 sRef_makeSafe (tcref);
10316 prefs = sRefSet_insert (prefs, tcref);
10322 } end_uentryList_elements ;
10324 if (sRefSet_size (prefs) > 0)
10326 nstate n = sRef_getNullState (u->sref);
10328 if (sRefSet_size (prefs) == 1)
10330 res = sRefSet_choose (prefs);
10334 /* should this ever happen? */ /*@i534 evans 2001-05-27 */
10335 res = sRefSet_mergeIntoOne (prefs);
10338 if (nstate_isKnown (n))
10340 sRef_setNullState (res, n, g_currentloc);
10345 if (ctype_isFunction (u->utype))
10347 DPRINTF (("Making new from %s -->", uentry_unparseFull (u)));
10348 res = sRef_makeNew (ctype_getReturnType (u->utype), u->sref, u->uname);
10352 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
10355 if (sRef_isRefCounted (res))
10357 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10362 if (sRef_getNullState (res) == NS_ABSNULL)
10364 ctype ct = ctype_realType (u->utype);
10366 if (ctype_isAbstract (ct))
10368 sRef_setNotNull (res, g_currentloc);
10372 if (ctype_isUser (ct))
10374 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
10378 sRef_setNotNull (res, g_currentloc);
10383 if (sRef_isRefCounted (res))
10385 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
10387 else if (sRef_isKillRef (res))
10389 sRef_setAliasKind (res, AK_REFCOUNTED, g_currentloc);
10396 ak = sRef_getAliasKind (res);
10398 if (alkind_isImplicit (ak))
10400 sRef_setAliasKind (res,
10401 alkind_fixImplicit (ak),
10405 sRefSet_free (prefs);
10407 DPRINTF (("Returns ref: %s", sRef_unparseFull (res)));
10412 static bool uentry_isRefCounted (uentry ue)
10414 ctype ct = uentry_getType (ue);
10416 if (ctype_isFunction (ct))
10418 return (ctype_isRefCounted (ctype_getReturnType (ct)));
10422 return (ctype_isRefCounted (ct));
10427 ** old was declared yield in the specification.
10428 ** new is declared in the iter implementation.
10431 void uentry_checkYieldParam (uentry old, uentry unew)
10435 llassert (uentry_isVariable (old));
10436 llassert (uentry_isVariable (unew));
10438 unew->info->var->kind = VKYIELDPARAM;
10439 (void) checkTypeConformance (old, unew, TRUE);
10440 checkVarConformance (old, unew, TRUE, FALSE);
10442 /* get rid of param marker */
10444 name = uentry_getName (unew);
10445 cstring_free (unew->uname);
10446 unew->uname = name;
10447 unew->info->var->kind = VKREFYIELDPARAM;
10449 uentry_setUsed (old, fileloc_undefined);
10450 uentry_setUsed (unew, fileloc_undefined);
10453 /*@observer@*/ cstring
10454 uentry_ekindName (uentry ue)
10456 if (uentry_isValid (ue))
10461 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
10463 return cstring_makeLiteralTemp ("Datatype");
10465 return cstring_makeLiteralTemp ("Enum member");
10467 return cstring_makeLiteralTemp ("Constant");
10469 if (uentry_isParam (ue))
10471 return cstring_makeLiteralTemp ("Parameter");
10473 else if (uentry_isExpandedMacro (ue))
10475 return cstring_makeLiteralTemp ("Expanded macro");
10479 return cstring_makeLiteralTemp ("Variable");
10482 return cstring_makeLiteralTemp ("Function");
10484 return cstring_makeLiteralTemp ("Iterator");
10486 return cstring_makeLiteralTemp ("Iterator finalizer");
10488 return cstring_makeLiteralTemp ("Struct tag");
10490 return cstring_makeLiteralTemp ("Union tag");
10492 return cstring_makeLiteralTemp ("Enum tag");
10494 return cstring_makeLiteralTemp ("Optional parameters");
10499 return cstring_makeLiteralTemp ("<Undefined>");
10505 /*@observer@*/ cstring
10506 uentry_ekindNameLC (uentry ue)
10508 if (uentry_isValid (ue))
10513 return cstring_makeLiteralTemp ("<error: invalid uentry>");
10515 return cstring_makeLiteralTemp ("datatype");
10517 return cstring_makeLiteralTemp ("enum member");
10519 return cstring_makeLiteralTemp ("constant");
10521 if (uentry_isParam (ue))
10523 return cstring_makeLiteralTemp ("parameter");
10525 else if (uentry_isExpandedMacro (ue))
10527 return cstring_makeLiteralTemp ("expanded macro");
10531 return cstring_makeLiteralTemp ("variable");
10534 return cstring_makeLiteralTemp ("function");
10536 return cstring_makeLiteralTemp ("iterator");
10538 return cstring_makeLiteralTemp ("iterator finalizer");
10540 return cstring_makeLiteralTemp ("struct tag");
10542 return cstring_makeLiteralTemp ("union tag");
10544 return cstring_makeLiteralTemp ("enum tag");
10546 return cstring_makeLiteralTemp ("optional parameters");
10551 return cstring_makeLiteralTemp ("<Undefined>");
10557 void uentry_setHasNameError (uentry ue)
10559 llassert (uentry_isValid (ue));
10561 ue->hasNameError = TRUE;
10564 void uentry_checkName (uentry ue)
10566 DPRINTF (("Checking name: %s / %s / %s", uentry_unparse (ue),
10567 uentry_observeRealName (ue),
10568 bool_unparse (uentry_isVisibleExternally (ue))));
10570 if (uentry_isValid (ue)
10571 && !context_inXHFile ()
10572 && uentry_hasName (ue)
10573 && !uentry_isElipsisMarker (ue)
10574 && context_getFlag (FLG_NAMECHECKS)
10575 && !ue->hasNameError
10576 && !uentry_isEndIter (ue)
10577 && !fileloc_isBuiltin (uentry_whereLast (ue))
10578 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
10580 DPRINTF (("Here..."));
10582 if (uentry_isPriv (ue))
10584 ; /* any checks here? */
10586 else if (fileloc_isExternal (uentry_whereDefined (ue)))
10588 ; /* no errors for externals */
10594 if (uentry_isExpandedMacro (ue))
10600 if (uentry_isExpandedMacro (ue))
10604 else if (uentry_isVariable (ue))
10606 sRef sr = uentry_getSref (ue);
10608 if (sRef_isValid (sr))
10610 scope = sRef_getScope (sr);
10617 else if (uentry_isFunction (ue)
10618 || uentry_isIter (ue)
10619 || uentry_isEndIter (ue)
10620 || uentry_isConstant (ue))
10622 scope = uentry_isStatic (ue) ? fileScope : globScope;
10624 else /* datatypes, etc. must be global */
10629 usymtab_checkDistinctName (ue, scope);
10632 if (context_getFlag (FLG_CPPNAMES))
10637 if (scope == globScope)
10639 checkExternalName (ue);
10641 else if (scope == fileScope)
10643 checkFileScopeName (ue);
10647 checkLocalName (ue);
10651 checkAnsiName (ue);
10656 /*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@keep@*/ fileloc loc)
10662 ** Can't but unrecognized ids in macros in global scope, because srefs will break! */
10663 if (!context_inMacro ())
10665 sRef_setGlobalScopeSafe ();
10668 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
10669 uentry_setUsed (ue, loc);
10671 tloc = fileloc_createExternal ();
10672 uentry_setDefined (ue, tloc);
10673 fileloc_free (tloc);
10674 uentry_setHasNameError (ue);
10676 if (context_getFlag (FLG_REPEATUNRECOG))
10678 uentry_markOwned (ue);
10682 ue = usymtab_supReturnFileEntry (ue);
10685 if (!context_inMacro ())
10687 sRef_clearGlobalScopeSafe ();
10693 uentry uentry_makeGlobalMarker ()
10698 llassert (sRef_inGlobalScope ());
10700 ue = uentry_makeVariableAux
10701 (GLOBAL_MARKER_NAME, ctype_unknown, fileloc_undefined,
10702 sRef_makeGlobalMarker (),
10705 tloc = fileloc_createExternal ();
10706 uentry_setUsed (ue, tloc);
10707 uentry_setDefined (ue, tloc);
10708 fileloc_free (tloc);
10709 uentry_setHasNameError (ue);
10715 bool uentry_isGlobalMarker (uentry ue)
10717 return (uentry_isValid (ue)
10718 && (cstring_equal (uentry_rawName (ue), GLOBAL_MARKER_NAME)));
10723 /* new start modifications */
10730 static void uentry_testInRange (uentry p_e, uentry cconstant) {
10731 if (uentry_isValid(p_e)) {
10732 if (sRef_isValid (p_e->sref)) {
10733 /* char * t = cstring_toCharsSafe (uentry_unparse(cconstant) );
10734 int index = atoi( t );
10737 long index = multiVal_forceInt (uentry_getConstantValue (cconstant));
10738 // usymtab_testInRange (p_e->sref, index);
10744 /* void uentry_setStringLength (uentry p_e, uentry cconstant) { */
10745 /* if( uentry_isValid(p_e) ) { */
10746 /* if( p_e->info != NULL) { */
10747 /* if( p_e->info->var != NULL) { */
10748 /* char *t = cstring_toCharsSafe (uentry_unparse(cconstant)); */
10749 /* int length = atoi( t ); */
10751 /* p_e->info->var->bufinfo->len = length; */
10752 /* p_e->sref->bufinfo.len = length; */
10753 /* printf("Set string length of buff to %d \n", p_e->sref->bufinfo.size); */
10760 static void uentry_setBufferSize (uentry p_e, exprNode cconstant) {
10761 if( uentry_isValid(p_e) ) {
10762 if( p_e->info != NULL) {
10763 if( p_e->info->var != NULL) {
10764 int size = atoi(cstring_toCharsSafe(exprNode_unparse(cconstant) ) );
10765 p_e->info->var->bufinfo->size = size;
10766 p_e->sref->bufinfo.size = size;
10767 printf("Set buffer size to %d \n", p_e->sref->bufinfo.size);
10768 // fprintf(stderr, "For %s and %s\n", uentry_unparse(p_e) );
10769 // fprintf(stderr, "and %d\n", size );
10779 /* start modifications */
10781 requires: p_e is defined, is a ptr/array variable
10783 effects: sets the state of the variable
10787 void uentry_setPossiblyNullTerminatedState (uentry p_e) {
10788 if( uentry_isValid(p_e) ) {
10789 if( p_e->info != NULL) {
10790 if( p_e->info->var != NULL) {
10791 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
10792 p_e->sref->bufinfo.bufstate = BB_POSSIBLYNULLTERMINATED;
10798 fprintf(stderr, "uentry:Error in setPossiblyNullTerminatedState\n");
10802 requires: p_e is defined, is a ptr/array variable
10804 effects: sets the size of the buffer
10807 void uentry_setNullTerminatedState (uentry p_e) {
10808 if( uentry_isValid(p_e) ) {
10809 if( p_e->info != NULL) {
10810 if( p_e->info->var != NULL) {
10811 p_e->info->var->bufinfo->bufstate = BB_NULLTERMINATED;
10812 p_e->sref->bufinfo.bufstate = BB_NULLTERMINATED;
10818 fprintf(stderr, "uentry:Error in setNullTerminatedState\n");
10823 requires: p_e is defined, is a ptr/array variable
10825 effects: sets the state of the variable
10828 /* void uentry_setNotNullTerminatedState (uentry p_e) { */
10829 /* if( uentry_isValid(p_e) ) { */
10830 /* if( p_e->info != NULL) { */
10831 /* if( p_e->info->var != NULL) { */
10832 /* p_e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED; */
10833 /* p_e->sref->bufinfo.bufstate = BB_NOTNULLTERMINATED; */
10839 /* fprintf(stderr, "uentry:Error in setNotNullTerminatedState\n"); */
10844 requires: p_e is defined, is a ptr/array variable
10846 effects: sets the size of the buffer
10849 void uentry_setSize (uentry p_e, int size) {
10850 if( uentry_isValid(p_e) ) {
10851 if( p_e->info != NULL) {
10852 if( p_e->info->var != NULL) {
10853 p_e->info->var->bufinfo->size = size;
10854 p_e->sref->bufinfo.size = size;
10860 fprintf(stderr, "uentry:Error in setSize\n");
10865 requires: p_e is defined, is a ptr/array variable
10867 effects: sets the length of the buffer
10870 void uentry_setLen (uentry p_e, int len) {
10871 if( uentry_isValid(p_e) ) {
10872 if( p_e->info != NULL) {
10873 if( p_e->info->var != NULL) {
10874 p_e->info->var->bufinfo->len = len;
10875 p_e->sref->bufinfo.len = len;
10881 fprintf(stderr, "uentry:Error in setLen\n");
10886 bool uentry_hasMetaStateEnsures (uentry e)
10888 if (uentry_isValid (e) && uentry_isFunction (e))
10890 return functionConstraint_hasMetaStateConstraint (e->info->fcn->postconditions);
10898 metaStateConstraint uentry_getMetaStateEnsures (uentry e)
10900 llassert (uentry_hasMetaStateEnsures (e));
10901 return functionConstraint_getMetaStateConstraint (e->info->fcn->postconditions);