2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 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"
35 static /*@dependent@*/ uentry posRedeclared = uentry_undefined;
36 static /*@only@*/ fileloc posLoc = fileloc_undefined;
37 static int nuentries = 0;
38 static int totuentries = 0;
40 static void checkGlobalsModifies (/*@notnull@*/ uentry p_ue, sRefSet p_sr) ;
41 static void uentry_setDeclDef (uentry p_e, fileloc p_f) /*@modifies p_e@*/ ;
42 static bool uentry_isRefCounted (uentry p_ue) /*@*/ ;
43 static bool uentry_isRefsField (uentry p_ue) /*@*/ ;
44 static bool uentry_isReallySpecified (uentry p_e) /*@*/ ;
45 static void uentry_checkIterArgs (uentry p_ue);
46 static cstring uentry_dumpAux (uentry p_v, bool p_isParam);
49 static void checkAliasState (/*@notnull@*/ uentry p_old,
50 /*@notnull@*/ uentry p_unew,
51 bool p_mustConform, bool p_completeConform)
52 /*@modifies p_old, p_unew@*/ ;
53 static void checkNullState (/*@notnull@*/ uentry p_old,
54 /*@notnull@*/ uentry p_unew,
55 bool p_mustConform, bool p_completeConform)
56 /*@modifies p_old, p_unew@*/ ;
58 static void checkVarConformance (/*@notnull@*/ uentry p_old,
59 /*@notnull@*/ uentry p_unew,
60 bool p_mustConform, bool p_completeConform)
61 /*@modifies p_old, p_unew@*/;
64 static void uentry_setHasMods (uentry p_ue) /*@modifies p_ue@*/;
65 static void uentry_setHasGlobs (uentry p_ue) /*@modifies p_ue@*/;
68 static void uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry p_e);
70 static void uentry_setSpecDef (/*@special@*/ uentry p_e, /*@keep@*/ fileloc p_f)
71 /*@defines p_e->whereSpecified, p_e->whereDeclared, p_e->whereDefined@*/
74 static void returnValueError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_unew);
75 static void nargsError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_unew);
76 static /*@observer@*/ cstring paramStorageName (uentry p_ue) /*@*/ ;
77 static /*@observer@*/ cstring fcnErrName (uentry p_ue) /*@*/ ;
78 static /*@observer@*/ cstring checkedName (chkind p_checked) /*@*/ ;
80 paramTypeError (/*@notnull@*/ uentry p_old, /*@notnull@*/ uentry p_oldCurrent,
81 ctype p_oldType, /*@notnull@*/ uentry p_unew,
82 /*@notnull@*/ uentry p_newCurrent,
83 ctype p_newType, int p_paramno) /*@modifies g_msgstream@*/ ;
85 static /*@only@*/ /*@notnull@*/ uentry
86 uentry_makeVariableAux (cstring p_n, ctype p_t, /*@keep@*/ fileloc p_f,
87 /*@exposed@*/ sRef p_s, bool p_priv, vkind p_kind);
89 static /*@out@*/ /*@notnull@*/ uentry uentry_alloc (void) /*@*/
91 uentry ue = (uentry) dmalloc (sizeof (*ue));
98 static cstring uentry_getOptName (uentry p_e) /*@*/ ;
99 static void uentry_copyInto (/*@out@*/ /*@unique@*/ uentry p_unew, uentry p_old);
100 static void uentry_setNullState (/*@notnull@*/ uentry p_ue, nstate p_ns);
101 static void uentry_setAliasKind (/*@notnull@*/ uentry p_ue, alkind p_ak);
102 static /*@only@*/ /*@null@*/ uinfo uinfo_copy (uinfo p_u, ekind p_kind);
103 static void uinfo_free (/*@only@*/ uinfo p_u, ekind p_kind);
104 static void uvinfo_free (/*@only@*/ uvinfo p_u);
108 static /*@only@*/ cstring ancontext_unparse (ancontext an)
112 case AN_UNKNOWN: return cstring_makeLiteral ("unknown");
113 case AN_FCNRETURN: return cstring_makeLiteral ("return value");
114 case AN_FCNPARAM: return cstring_makeLiteral ("function param");
115 case AN_SUFIELD: return cstring_makeLiteral ("su field");
116 case AN_TDEFN: return cstring_makeLiteral ("type definition");
117 case AN_GSVAR: return cstring_makeLiteral ("global/static var");
118 case AN_CONST: return cstring_makeLiteral ("constant");
124 static int annots[AN_LAST][QU_LAST];
125 static int decls[AN_LAST];
126 static int shdecls[AN_LAST];
127 static int idecls[AN_LAST];
133 for (i = AN_UNKNOWN; i < AN_LAST; i++)
139 for (j = QU_UNKNOWN; j < QU_LAST; j++)
146 static void tallyAnnot (ancontext ac, qual q)
160 for (j = QU_UNKNOWN; j < QU_LAST; j++)
165 for (i = AN_UNKNOWN; i < AN_LAST; i++)
171 printf ("Context: %s (%d declarations, %d sharable, %d indirect)\n",
172 ancontext_unparse (i),
173 decls[i], shdecls[i], idecls[i]);
175 totdecls += decls[i];
176 totshdecls += shdecls[i];
177 totidecls += idecls[i];
179 for (j = QU_UNKNOWN; j < QU_LAST; j++)
181 total[j] += annots[i][j];
182 alltotals += annots[i][j];
185 printf (" Allocation:\n");
189 for (j = QU_UNKNOWN; j < QU_LAST; j++)
191 if (qual_isAliasQual (j) && !qual_isUnique (j))
193 if (annots[i][j] > 0)
195 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
196 100.0 * (double)annots[i][j] / (double)decls[i]);
197 tmptot += annots[i][j];
202 printf (" Exposure:\n");
206 for (j = QU_UNKNOWN; j < QU_LAST; j++)
208 if (qual_isExQual (j))
210 if (annots[i][j] > 0)
212 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
213 100.0 * (double)annots[i][j] / (double)decls[i]);
214 tmptot += annots[i][j];
219 printf (" Definition:\n");
221 for (j = QU_UNKNOWN; j < QU_LAST; j++)
223 if (qual_isAllocQual (j))
225 if (annots[i][j] > 0)
227 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
228 100.0 * (double)annots[i][j] / (double)decls[i]);
235 for (j = QU_UNKNOWN; j < QU_LAST; j++)
237 if (qual_isNull (j) || qual_isNotNull (j) || qual_isRelNull (j))
239 if (annots[i][j] > 0)
241 printf ("\t%10s: %5d (%3.2f%%)\n", qual_unparse (j), annots[i][j],
242 100.0 * (double)annots[i][j] / (double)decls[i]);
251 for (j = QU_UNKNOWN; j < QU_LAST; j++)
255 for (i = AN_UNKNOWN; i < AN_LAST; i++)
257 if (annots[i][j] > 0)
266 printf ("Annotation: %s\n", qual_unparse (j));
268 for (i = AN_UNKNOWN; i < AN_LAST; i++)
270 if (annots[i][j] > 0)
272 printf ("%25s: %5d\n", ancontext_unparse (i), annots[i][j]);
279 printf ("All Contexts\n");
281 for (j = QU_UNKNOWN; j < QU_LAST; j++)
285 printf ("%10s: %5d (%3.2f%%)\n", qual_unparse (j), total[j],
286 100.0 * (double)total[j] / (double)(totdecls));
291 printf ("Total Annotations: %d (%d decls, %d sharable, %d indirect)\n", alltotals, totdecls, totshdecls, totidecls);
294 extern void uentry_tallyAnnots (uentry u, ancontext kind)
296 alkind ak = sRef_getAliasKind (u->sref);
297 exkind ek = sRef_getExKind (u->sref);
298 nstate ns = sRef_getNullState (u->sref);
299 sstate ss = sRef_getDefState (u->sref);
300 bool recordUnknown = FALSE;
303 if (kind == AN_UNKNOWN)
311 else if (e == KCONST || e == KENUMCONST)
315 else if (e == KFCN || e == KITER)
317 uentryList params = uentry_getParams (u);
320 uentryList_elements (params, current)
322 if (uentry_isReturned (current))
326 if (!uentry_isElipsisMarker (current))
328 uentry_tallyAnnots (current, AN_FCNPARAM);
330 } end_uentryList_elements;
334 if (ctype_isFunction (u->utype)
336 && ctype_isVisiblySharable (ctype_realType (ctype_returnValue (u->utype))))
338 recordUnknown = TRUE;
341 else if (e == KDATATYPE || e == KSTRUCTTAG || e == KUNIONTAG || e == KENUMTAG)
343 ctype t = ctype_realType (u->utype);
347 uentryList fields = ctype_getFields (t);
349 uentryList_elements (fields, current)
351 uentry_tallyAnnots (current, AN_SUFIELD);
353 } end_uentryList_elements;
357 if (ctype_isVisiblySharable (u->utype))
359 recordUnknown = TRUE;
367 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
369 recordUnknown = TRUE;
376 if (kind == AN_FCNRETURN)
390 if (ctype_isVisiblySharable (ctype_realType (u->utype)))
395 if (ctype_isRealPointer (ctype_realType (u->utype)))
412 case SS_ALLOCATED: tallyAnnot (kind, QU_OUT); break;
413 case SS_PARTIAL: tallyAnnot (kind, QU_PARTIAL); break;
414 case SS_RELDEF: tallyAnnot (kind, QU_RELDEF); break;
415 case SS_SPECIAL: tallyAnnot (kind, QU_SPECIAL); break;
419 if (uentry_isReturned (u))
421 tallyAnnot (kind, QU_RETURNED);
427 if (ctype_isRefCounted (ctype_realType (u->utype))
428 || (ctype_isFunction (u->utype) &&
429 ctype_isRefCounted (ctype_realType (ctype_returnValue (u->utype)))))
435 if (kind == AN_FCNPARAM)
437 tallyAnnot (kind, QU_TEMP);
439 else if (recordUnknown)
441 if (kind == AN_FCNRETURN)
444 tallyAnnot (kind, QU_UNKNOWN);
448 case AK_ONLY: tallyAnnot (kind, QU_ONLY); break;
449 case AK_IMPONLY: tallyAnnot (kind, QU_ONLY); break;
450 case AK_KEEP: tallyAnnot (kind, QU_KEEP); break;
451 case AK_KEPT: tallyAnnot (kind, QU_KEPT); break;
453 case AK_TEMP: tallyAnnot (kind, QU_TEMP); break;
454 case AK_SHARED: tallyAnnot (kind, QU_SHARED); break;
455 case AK_UNIQUE: tallyAnnot (kind, QU_UNIQUE); break;
456 case AK_RETURNED: tallyAnnot (kind, QU_RETURNED); break;
457 case AK_REFCOUNTED: tallyAnnot (kind, QU_UNKNOWN); break;
458 case AK_REFS: tallyAnnot (kind, QU_REFS); break;
459 case AK_KILLREF: tallyAnnot (kind, QU_KILLREF); break;
460 case AK_NEWREF: tallyAnnot (kind, QU_NEWREF); break;
461 case AK_OWNED: tallyAnnot (kind, QU_OWNED); break;
462 case AK_IMPDEPENDENT:
463 case AK_DEPENDENT: tallyAnnot (kind, QU_DEPENDENT); break;
473 case XO_EXPOSED: tallyAnnot (kind, QU_EXPOSED); break;
474 case XO_OBSERVER: tallyAnnot (kind, QU_OBSERVER); break;
480 case NS_ERROR: break;
481 case NS_UNKNOWN: break;
482 case NS_NOTNULL: break;
483 case NS_MNOTNULL: tallyAnnot (kind, QU_NOTNULL); break;
484 case NS_RELNULL: tallyAnnot (kind, QU_RELNULL); break;
485 case NS_CONSTNULL: tallyAnnot (kind, QU_NULL); break;
486 case NS_POSNULL: tallyAnnot (kind, QU_NULL); break;
488 case NS_ABSNULL: break;
494 static /*@observer@*/ cstring specCode_unparse (specCode s) /*@*/
498 case SPC_NONE: return cstring_makeLiteralTemp ("normal");
499 case SPC_PRINTFLIKE: return cstring_makeLiteralTemp ("printflike");
500 case SPC_SCANFLIKE: return cstring_makeLiteralTemp ("scanflike");
501 case SPC_MESSAGELIKE: return cstring_makeLiteralTemp ("messagelike");
502 case SPC_LAST: return cstring_makeLiteralTemp ("<error>");
508 static specCode specCode_fromInt (int i)
511 llassert (i >= SPC_NONE && i < SPC_LAST);
513 return ((specCode) i);
517 /*@observer@*/ cstring uentry_specOrDefName (uentry u)
519 if (uentry_isDeclared (u))
521 return cstring_makeLiteralTemp ("previously declared");
525 return cstring_makeLiteralTemp ("specified");
529 /*@observer@*/ cstring uentry_specDeclName (uentry u)
531 if (uentry_isDeclared (u))
533 return cstring_makeLiteralTemp ("previous declaration");
537 return cstring_makeLiteralTemp ("specification");
541 static /*@observer@*/ cstring uentry_reDefDecl (uentry old, uentry unew) /*@*/
543 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
545 return cstring_makeLiteralTemp ("redefined");
547 else if (uentry_isCodeDefined (unew))
549 return cstring_makeLiteralTemp ("defined");
551 else if (uentry_isDeclared (old) && uentry_isDeclared (unew))
553 return cstring_makeLiteralTemp ("redeclared");
557 return cstring_makeLiteralTemp ("declared");
563 constraintList uentry_getFcnPreconditions (uentry ue)
565 if (uentry_isValid (ue))
568 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
570 uentry_makeVarFunction (ue);
573 //llassert (uentry_isFunction (ue));
574 //llassert ((ue->info->fcn->preconditions));
575 //llassert ((ue->info->fcn->preconditions));
576 if (!uentry_isFunction (ue))
578 TPRINTF ( (message ("called uentry_getFcnPreconditions on nonfunction %s",
579 uentry_unparse (ue) ) ) );
580 if (!uentry_isSpecified (ue) )
582 TPRINTF((message ("called uentry_getFcnPreconditions on nonfunction %s",
583 uentry_unparse (ue) ) ));
584 return constraintList_undefined;
588 return constraintList_undefined;
591 if (ue->info->fcn->preconditions)
593 return constraintList_copy (ue->info->fcn->preconditions);
603 return constraintList_undefined;
611 constraintList uentry_getFcnPostconditions (uentry ue)
613 if (uentry_isValid (ue))
616 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
618 uentry_makeVarFunction (ue);
621 //llassert (uentry_isFunction (ue));
622 //llassert ((ue->info->fcn->preconditions));
623 /* if (!uentry_isSpecified (ue) )
625 TPRINTF((message ("called uentry_getFcnPostconditions on nonfunction %s",
626 uentry_unparse (ue) ) ));
627 // return constraintList_undefined;
630 if (!uentry_isFunction (ue))
632 /*llcontbug*/ TPRINTF( (message ("called uentry_getFcnPostconditions on nonfunction %s",
633 uentry_unparse (ue) ) ) );
634 return constraintList_undefined;
637 if (ue->info->fcn->postconditions)
639 return constraintList_copy (ue->info->fcn->postconditions);
649 return constraintList_undefined;
654 static /*@only@*/ fileloc setLocation (void)
656 fileloc fl = context_getSaveLocation ();
658 if (fileloc_isDefined (fl))
664 return fileloc_copy (g_currentloc);
668 /*@notnull@*/ uentry uentry_makeEnumConstant (cstring n, ctype t)
670 fileloc loc = setLocation ();
671 uentry ue = uentry_makeConstant (n, t, loc);
673 ue->ukind = KENUMCONST;
674 uentry_setDefined (ue, loc);
678 /*@notnull@*/ uentry uentry_makeEnumInitializedConstant (cstring n, ctype t, exprNode expr)
680 fileloc loc = setLocation ();
681 uentry ue = uentry_makeConstant (n, t, loc);
682 ctype etype = exprNode_getType (expr);
684 if (!ctype_isRealInt (etype)) {
688 ("Value of enum member is not an integeral type (type %s): %s",
689 ctype_unparse (etype), exprNode_unparse (expr)),
690 exprNode_loc (expr));
693 ue->ukind = KENUMCONST;
694 uentry_setDefined (ue, loc);
699 /*@notnull@*/ uentry uentry_makeSpecEnumConstant (cstring n, ctype t, fileloc loc)
701 uentry ue = uentry_makeConstant (n, t, loc);
703 ue->ukind = KENUMCONST;
708 /*@notnull@*/ uentry uentry_makeVariableLoc (cstring n, ctype t)
710 return uentry_makeVariable (n, t, setLocation (), FALSE);
714 /*@notnull@*/ /*@only@*/ uentry uentry_makeUnnamedVariable (ctype t)
716 return uentry_makeVariable (cstring_undefined, t, setLocation (), FALSE);
720 /*@notnull@*/ uentry uentry_makeIdDatatype (idDecl id)
722 ctype ct = idDecl_getCtype (id);
723 uentry ue = uentry_makeDatatype (idDecl_observeId (id), ct,
724 MAYBE, MAYBE, setLocation ());
726 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
728 if (!ynm_isOn (ue->info->datatype->abs))
730 if (ctype_isUnknown (ct))
732 ue->info->datatype->mut = MAYBE;
736 ue->info->datatype->mut = ynm_fromBool (ctype_isMutable (ct));
743 void uentry_checkParams (uentry ue)
745 if (uentry_isValid (ue))
747 bool isExt = uentry_isExtern (ue);
749 if (uentry_isRealFunction (ue))
751 uentryList params = uentry_getParams (ue);
753 uentryList_elements (params, current)
755 if (uentry_isValid (current))
757 ctype ct = current->utype;
759 if (ctype_isFixedArray (ct))
761 if (ctype_isArray (ctype_baseArrayPtr (ct))
762 && !ctype_isFixedArray (ctype_baseArrayPtr (ct)))
769 (FLG_FIXEDFORMALARRAY,
770 message ("Function parameter %q declared as "
771 "manifest array (size constant is meaningless)",
772 uentry_getName (current)),
773 uentry_whereDeclared (current));
778 if (ctype_isArray (ct))
782 message ("Function parameter %q declared as "
783 "array (treated as pointer)",
784 uentry_getName (current)),
785 uentry_whereDeclared (current));
789 if (sRef_getNullState (uentry_getSref (current)) == NS_MNOTNULL)
791 if (ctype_isAbstract (ct) &&
792 (isExt || (ctype_isAbstract (ctype_realType (ct))
793 && !context_hasFileAccess (ctype_typeId (ct)))))
798 ("Function %q declared with notnull parameter %q of abstract "
801 uentry_getName (current),
804 ("Since %s is an abstract type, notnull can only be "
805 "used for parameters if the function is static to a "
806 "module where %s is accessible.",
809 uentry_whereDeclared (current));
813 } end_uentryList_elements;
815 if (sRef_getNullState (uentry_getSref (ue)) == NS_MNOTNULL)
817 ctype ct = ue->utype;
819 if (ctype_isAbstract (ct)
820 && (isExt || (ctype_isAbstract (ctype_realType (ct))
821 && !context_hasFileAccess (ctype_typeId (ct)))))
826 ("%s %q declared %s notnull storage of abstract type %s",
827 ekind_capName (uentry_getKind (ue)),
832 ("Since %s is an abstract type, notnull can only be used "
833 "if it is static to a module where %s is accessible.",
836 uentry_whereDeclared (ue));
843 static void reflectImplicitFunctionQualifiers (/*@notnull@*/ uentry ue, bool spec)
845 alkind ak = sRef_getAliasKind (ue->sref);
847 if (alkind_isRefCounted (ak))
849 sRef_setAliasKind (ue->sref, AK_NEWREF, fileloc_undefined);
853 if (alkind_isUnknown (ak))
855 exkind ek = sRef_getExKind (ue->sref);
857 if (exkind_isKnown (ek))
859 sRef_setAliasKind (ue->sref, AK_IMPDEPENDENT, fileloc_undefined);
863 if (context_getFlag (spec ? FLG_SPECRETIMPONLY : FLG_RETIMPONLY))
865 if (ctype_isVisiblySharable
866 (ctype_realType (ctype_returnValue (ue->utype))))
868 if (uentryList_hasReturned (uentry_getParams (ue)))
874 sRef_setAliasKind (ue->sref, AK_IMPONLY,
884 static /*@notnull@*/ uentry
885 uentry_makeFunctionAux (cstring n, ctype t,
887 /*@only@*/ globSet globs,
888 /*@only@*/ sRefSet mods,
889 /*@keep@*/ fileloc f, bool priv,
890 /*@unused@*/ bool isForward)
892 uentry e = uentry_alloc ();
895 if (ctype_isFunction (t))
897 ret = ctype_returnValue (t);
901 if (ctype_isKnown (t))
903 llbug (message ("not function: %s", ctype_unparse (t)));
910 if (fileloc_isSpec (f) || fileloc_isImport (f))
912 e->whereSpecified = f;
913 e->whereDeclared = fileloc_undefined;
917 e->whereSpecified = fileloc_undefined;
918 e->whereDeclared = f;
921 /* e->shallowCopy = FALSE; */
922 e->uname = cstring_copy (n);
924 e->storageclass = SCNONE;
926 e->sref = sRef_makeType (ret);
928 if (ctype_isUA (ret))
930 sRef_setStateFromType (e->sref, ret);
935 e->uses = filelocList_new ();
937 e->hasNameError = FALSE;
939 e->info = (uinfo) dmalloc (sizeof (*e->info));
940 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
942 e->info->fcn->hasMods = sRefSet_isDefined (mods);
943 e->info->fcn->hasGlobs = globSet_isDefined (globs);
945 e->info->fcn->exitCode = XK_UNKNOWN;
946 e->info->fcn->nullPred = QU_UNKNOWN;
947 e->info->fcn->specialCode = SPC_NONE;
949 e->info->fcn->access = access;
950 e->info->fcn->globs = globs;
951 e->info->fcn->defparams = uentryList_undefined;
953 sRef_setDefined (e->sref, f);
954 e->whereDefined = fileloc_undefined;
956 e->info->fcn->mods = sRefSet_undefined;
957 e->info->fcn->specclauses = NULL;
960 e->info->fcn->preconditions = NULL;
964 e->info->fcn->postconditions = NULL;
967 checkGlobalsModifies (e, mods);
968 e->info->fcn->mods = mods;
973 /*@notnull@*/ uentry uentry_makeIdFunction (idDecl id)
976 uentry_makeFunction (idDecl_observeId (id), idDecl_getCtype (id),
977 typeId_invalid, globSet_undefined,
981 uentry_reflectQualifiers (ue, idDecl_getQuals (id));
982 reflectImplicitFunctionQualifiers (ue, FALSE);
984 if (!uentry_isStatic (ue)
985 && cstring_equalLit (ue->uname, "main"))
987 ctype typ = ue->utype;
991 llassert (ctype_isFunction (typ));
993 retval = ctype_returnValue (typ);
995 if (!ctype_isInt (retval))
999 message ("Function main declared to return %s, should return int",
1000 ctype_unparse (retval)),
1001 uentry_whereDeclared (ue));
1004 args = ctype_argsFunction (typ);
1006 if (uentryList_isMissingParams (args)
1007 || uentryList_size (args) == 0)
1013 if (uentryList_size (args) != 2)
1017 message ("Function main declared with %d arg%p, "
1018 "should have 2 (int argc, char *argv[])",
1019 uentryList_size (args)),
1020 uentry_whereLast (ue));
1024 uentry arg = uentryList_getN (args, 0);
1025 ctype ct = uentry_getType (arg);
1027 if (!ctype_isInt (ct))
1031 message ("Parameter 1, %q, of function main declared "
1032 "with type %t, should have type int",
1033 uentry_getName (arg), ct),
1034 uentry_whereDeclared (arg));
1037 arg = uentryList_getN (args, 1);
1038 ct = uentry_getType (arg);
1040 if (ctype_isArrayPtr (ct)
1041 && ctype_isArrayPtr (ctype_baseArrayPtr (ct))
1042 && ctype_isChar (ctype_baseArrayPtr (ctype_baseArrayPtr (ct))))
1050 message ("Parameter 2, %q, of function main declared "
1051 "with type %t, should have type char **",
1052 uentry_getName (arg), ct),
1053 uentry_whereDeclared (arg));
1062 static void uentry_implicitParamAnnots (/*@notnull@*/ uentry e)
1064 alkind ak = sRef_getAliasKind (e->sref);
1066 if ((alkind_isUnknown (ak) || alkind_isImplicit (ak))
1067 && context_getFlag (FLG_PARAMIMPTEMP))
1069 exkind ek = sRef_getExKind (e->sref);
1071 if (exkind_isKnown (ek))
1073 sRef_setAliasKind (e->sref, AK_IMPDEPENDENT, fileloc_undefined);
1074 sRef_setOrigAliasKind (e->sref, AK_IMPDEPENDENT);
1078 sRef_setAliasKind (e->sref, AK_IMPTEMP, fileloc_undefined);
1079 sRef_setOrigAliasKind (e->sref, AK_IMPTEMP);
1084 static /*@only@*/ /*@notnull@*/ uentry
1085 uentry_makeVariableParamAux (cstring n, ctype t, sRef s, sstate defstate)
1087 cstring pname = makeParam (n);
1088 uentry e = uentry_makeVariableAux (pname, t, setLocation (), s, FALSE, VKPARAM);
1090 cstring_free (pname);
1091 uentry_implicitParamAnnots (e);
1093 if (!sRef_isAllocated (e->sref) && !sRef_isPartial (e->sref))
1095 sRef_setDefState (e->sref, defstate, uentry_whereDeclared (e));
1096 e->info->var->defstate = defstate;
1104 uentry_setRefCounted (uentry e)
1106 if (uentry_isValid (e))
1108 uentry_setAliasKind (e, AK_REFCOUNTED);
1109 sRef_storeState (e->sref);
1115 uentry_setStatic (uentry c)
1117 if (uentry_isValid (c))
1119 alkind ak = sRef_getAliasKind (c->sref);
1120 c->storageclass = SCSTATIC;
1122 if (uentry_isVariable (c) && !ctype_isFunction (uentry_getType (c)))
1124 if (!alkind_isUnknown (ak)
1125 && !alkind_isStatic (ak))
1127 if (!(ctype_isRealPointer (uentry_getType (c)))
1128 && !(ctype_isAbstract (ctype_realType (uentry_getType (c))))
1129 && !alkind_isRefCounted (ak))
1131 if (alkind_isImplicit (ak)
1132 && alkind_isDependent (ak)
1133 && ctype_isArray (uentry_getType (c)))
1135 ; /* no error for observer arrays */
1141 message ("Static storage %q declared as %s",
1143 alkind_unparse (ak)),
1144 uentry_whereDeclared (c));
1150 if (alkind_isUnknown (ak)
1151 || (alkind_isImplicit (sRef_getAliasKind (c->sref))
1152 && !alkind_isDependent (sRef_getAliasKind (c->sref))))
1154 sRef_setAliasKind (c->sref, AK_STATIC, fileloc_undefined);
1155 sRef_setOrigAliasKind (c->sref, AK_STATIC);
1163 uentry_setExtern (uentry c)
1165 if (uentry_isValid (c))
1166 c->storageclass = SCEXTERN;
1170 uentry_setParamNo (uentry ue, int pno)
1172 llassert (uentry_isAnyParam (ue) && sRef_isParam (ue->sref));
1173 sRef_setParamNo (ue->sref, pno);
1177 void checkGlobalsModifies (/*@notnull@*/ uentry ue, sRefSet sr)
1179 sRefSet_allElements (sr, el)
1181 sRef base = sRef_getRootBase (el);
1183 if (sRef_isGlobal (base) || sRef_isInternalState (base)
1184 || (sRef_isKindSpecial (base) && !sRef_isNothing (base)))
1186 if (!globSet_member (ue->info->fcn->globs, base))
1188 if (uentry_hasGlobs (ue)
1189 || context_getFlag (FLG_WARNMISSINGGLOBALSNOGLOBS))
1192 (FLG_WARNMISSINGGLOBALS,
1194 ("Modifies list for %q uses global %q, "
1195 "not included in globals list.",
1196 uentry_getName (ue),
1197 sRef_unparse (base)),
1198 uentry_whereLast (ue)))
1200 uentry_showWhereSpecified (ue);
1204 ue->info->fcn->globs = globSet_insert (ue->info->fcn->globs,
1206 if (sRef_isFileStatic (base))
1208 context_recordFileGlobals (ue->info->fcn->globs);
1212 } end_sRefSet_allElements;
1216 uentry_makeVariableSrefParam (cstring n, ctype t, sRef s)
1218 return (uentry_makeVariableParamAux (n, t, s, SS_UNKNOWN));
1222 uentry_fixupSref (uentry ue)
1226 if (uentry_isUndefined (ue) || uentry_isElipsisMarker (ue))
1231 sr = uentry_getSref (ue);
1233 sRef_resetState (sr);
1234 sRef_clearDerived (sr);
1236 llassertprint (uentry_isVariable (ue), ("fixing: %s", uentry_unparseFull (ue)));
1237 llassert (sRef_isValid (sr));
1239 if (uentry_isVariable (ue))
1241 sRef_setDefState (sr, ue->info->var->defstate, fileloc_undefined);
1242 sRef_setNullState (sr, ue->info->var->nullstate, fileloc_undefined);
1246 void uentry_setSpecialClauses (uentry ue, specialClauses clauses)
1248 llassert (uentry_isFunction (ue));
1249 llassert (!specialClauses_isDefined (ue->info->fcn->specclauses));
1251 ue->info->fcn->specclauses = clauses;
1252 specialClauses_checkAll (ue);
1256 ** Used for @modifies@ @endmodifies@ syntax.
1258 ** If ue is specified, sr must contain *only*:
1260 ** o file static globals
1261 ** o sRef's derived from modifies spec (i.e., more specific than
1262 ** what was specified)
1264 ** Otherwise, if sr has modifies it must match sr.
1266 ** If it doesn't have modifies, set them to sr.
1270 uentry_setModifies (uentry ue, /*@owned@*/ sRefSet sr)
1272 if (sRef_modInFunction ())
1275 (message ("Modifies list not in function context. "
1276 "A modifies list can only appear following the parameter list "
1277 "in a function declaration or header."));
1279 /*@-mustfree@*/ return; /*@=mustfree@*/
1282 if (sRefSet_hasStatic (sr))
1284 context_recordFileModifies (sr);
1287 if (uentry_isValid (ue))
1289 if (uentry_isIter (ue))
1291 llassert (sRefSet_isUndefined (ue->info->iter->mods));
1292 ue->info->iter->mods = sr;
1296 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
1298 uentry_makeVarFunction (ue);
1301 llassertfatal (uentry_isFunction (ue));
1302 llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1304 ue->info->fcn->mods = sr;
1305 ue->info->fcn->hasMods = TRUE;
1307 checkGlobalsModifies (ue, sr);
1310 if (context_getFlag (FLG_MODIFIESIMPNOGLOBALS))
1312 ue->info->fcn->hasGlobs = TRUE;
1322 uentry_setPreconditions (uentry ue, /*@owned@*/ constraintList preconditions)
1324 if (sRef_modInFunction ())
1327 (message ("Precondition list not in function context. "
1328 "A precondition list can only appear following the parameter list "
1329 "in a function declaration or header."));
1331 /*@-mustfree@*/ return; /*@=mustfree@*/
1334 if (uentry_isValid (ue))
1337 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
1339 uentry_makeVarFunction (ue);
1342 llassertfatal (uentry_isFunction (ue));
1343 // llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1345 ue->info->fcn->preconditions = preconditions;
1360 uentry_setPostconditions (uentry ue, /*@owned@*/ constraintList postconditions)
1362 if (sRef_modInFunction ())
1365 (message ("Postcondition list not in function context. "
1366 "A postcondition list can only appear following the parameter list "
1367 "in a function declaration or header."));
1369 /*@-mustfree@*/ return; /*@=mustfree@*/
1372 if (uentry_isValid (ue))
1375 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
1377 uentry_makeVarFunction (ue);
1380 llassertfatal (uentry_isFunction (ue));
1381 // llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1383 ue->info->fcn->postconditions = postconditions;
1394 ** requires: new and old are functions
1398 checkGlobalsConformance (/*@notnull@*/ uentry old,
1399 /*@notnull@*/ uentry unew,
1400 bool mustConform, bool completeConform)
1402 bool hasInternalState = FALSE;
1404 old->info->fcn->hasGlobs |= unew->info->fcn->hasGlobs;
1406 if (globSet_isDefined (unew->info->fcn->globs))
1408 globSet_allElements (unew->info->fcn->globs, el)
1410 if (sRef_isFileStatic (el))
1412 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1414 if (sRef_isInvalid (sr))
1416 bool hasError = FALSE;
1418 if (!hasInternalState
1419 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1420 sRef_makeInternalState ()))
1421 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1422 sRef_makeSpecState ())))
1425 && !uentry_isStatic (old)
1428 message ("Globals list for %q includes internal state, %q, "
1429 "but %s without globals internalState.",
1430 uentry_getName (old),
1432 uentry_specOrDefName (old)),
1433 uentry_whereLast (unew)))
1435 uentry_showWhereSpecified (old);
1439 old->info->fcn->globs = globSet_insert (old->info->fcn->globs,
1440 sRef_makeInternalState ());
1441 hasInternalState = TRUE;
1445 && fileloc_sameFile (uentry_whereDeclared (unew),
1446 uentry_whereDeclared (old)))
1451 message ("Function %q inconsistently %rdeclared (in "
1452 "same file) with file static global %q in "
1454 uentry_getName (unew),
1455 uentry_isDeclared (old),
1457 uentry_whereDeclared (unew)))
1459 uentry_showWhereSpecified (old);
1464 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1465 context_recordFileGlobals (old->info->fcn->globs);
1469 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1471 if (sRef_isInvalid (sr))
1476 message ("Function %q inconsistently %rdeclared with "
1477 "%q in globals list",
1478 uentry_getName (unew),
1479 uentry_isDeclared (old),
1481 uentry_whereDeclared (unew)))
1483 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1484 uentry_showWhereSpecified (old);
1489 if (!bool_equal (sRef_isAllocated (el), sRef_isAllocated (sr)))
1495 ("Function %q global %q inconsistently "
1496 "%rdeclared as %qout global",
1497 uentry_getName (unew),
1499 uentry_isDeclared (old),
1500 cstring_makeLiteral (sRef_isAllocated (el) ? "" : "non-")),
1501 uentry_whereDeclared (unew)))
1503 uentry_showWhereSpecified (old);
1508 } end_globSet_allElements ;
1510 if (completeConform)
1512 globSet_allElements (old->info->fcn->globs, el)
1514 sRef sr = globSet_lookup (unew->info->fcn->globs, el);
1516 if (sRef_isInvalid (sr))
1519 && uentry_isReallySpecified (old)
1522 message ("Function %q specified with %q in globals list, "
1523 "but declared without %q",
1524 uentry_getName (unew),
1527 uentry_whereDeclared (unew)))
1529 uentry_showWhereSpecified (old);
1532 } end_globSet_allElements;
1537 if (completeConform && !globSet_isEmpty (old->info->fcn->globs))
1539 if (uentry_isReallySpecified (old)
1542 message ("%s %q specified with globals list, but "
1543 "declared with no globals",
1544 ekind_capName (unew->ukind),
1545 uentry_getName (unew)),
1546 uentry_whereDeclared (unew)))
1549 (message ("Specification globals: %q",
1550 globSet_unparse (old->info->fcn->globs)),
1551 uentry_whereSpecified (old));
1555 unew->info->fcn->globs = globSet_copy (unew->info->fcn->globs,
1556 old->info->fcn->globs);
1561 ** new modifies list must be included by old modifies list.
1563 ** file static state may be added to new, if old has internal.
1567 checkModifiesConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
1568 bool mustConform, bool completeConform)
1571 bool changedMods = FALSE;
1572 bool modInternal = FALSE;
1574 llassert (uentry_isFunction (old) && uentry_isFunction (unew));
1576 old->info->fcn->hasMods |= unew->info->fcn->hasMods;
1577 newMods = unew->info->fcn->mods;
1579 if (sRefSet_isEmpty (newMods))
1581 if (completeConform && !sRefSet_isEmpty (old->info->fcn->mods)
1582 && uentry_isReallySpecified (old))
1586 message ("%s %q specified with modifies clause, "
1587 "but declared with no modifies clause",
1588 ekind_capName (unew->ukind),
1589 uentry_getName (unew)),
1590 uentry_whereDeclared (unew)))
1592 llgenindentmsg (message ("Specification has modifies %q",
1593 sRefSet_unparse (old->info->fcn->mods)),
1594 uentry_whereSpecified (old));
1601 sRefSet_allElements (newMods, current)
1603 if (sRef_isValid (current))
1605 sRef rb = sRef_getRootBase (current);
1607 if (sRef_isFileStatic (rb))
1611 if (!sRefSet_isSameMember (old->info->fcn->mods,
1612 sRef_makeInternalState ())
1613 && !sRefSet_isSameMember (old->info->fcn->mods,
1614 sRef_makeSpecState ()))
1617 && !uentry_isStatic (old)
1621 ("Modifies list for %q includes internal state, "
1622 "but %s without modifies internal.",
1623 uentry_getName (old),
1624 uentry_specOrDefName (old)),
1625 uentry_whereLast (unew)))
1627 uentry_showWhereSpecified (old);
1630 old->info->fcn->mods =
1631 sRefSet_insert (old->info->fcn->mods,
1632 sRef_makeInternalState ());
1637 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1643 if (sRef_canModifyVal (current, old->info->fcn->mods))
1645 int size = sRefSet_size (old->info->fcn->mods);
1647 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1650 if (sRefSet_size (old->info->fcn->mods) != size)
1661 ("Modifies list for %q contains %q, not modifiable "
1663 uentry_getName (old),
1664 sRef_unparse (current),
1665 uentry_specDeclName (old)),
1666 uentry_whereLast (unew)))
1668 uentry_showWhereSpecified (old);
1673 } end_sRefSet_allElements;
1675 if (completeConform && uentry_isReallySpecified (old))
1677 sRefSet_allElements (old->info->fcn->mods, el)
1679 if (sRef_canModify (el, newMods))
1688 ("Specification modifies clause for %q contains %q, "
1689 "not included in declaration modifies clause",
1690 uentry_getName (old),
1692 uentry_whereLast (unew)))
1694 uentry_showWhereSpecified (old);
1697 } end_sRefSet_allElements ;
1701 ** Make sure file static elements will be removed.
1706 context_recordFileModifies (old->info->fcn->mods);
1711 uentry_checkMutableType (uentry ue)
1713 ctype ct = uentry_getType (ue);
1715 if (!ctype_isRealPointer (ct) && !ctype_isRealAbstract (ct))
1717 voptgenerror (FLG_MUTREP,
1718 message ("Mutable abstract type %q declared without pointer "
1719 "indirection: %t (violates assignment semantics)",
1720 uentry_getName (ue), ct),
1721 uentry_whereDeclared (ue));
1726 uentry_setMutable (uentry e)
1728 llassert (uentry_isDatatype (e));
1729 e->info->datatype->mut = YES;
1733 uentry_checkIterArgs (uentry ue)
1735 bool hasYield = FALSE;
1738 llassert (uentry_isIter (ue));
1740 args = uentry_getParams (ue);
1742 uentryList_elements (args, el)
1744 sstate ds = uentry_getDefState (el);
1746 if (uentry_isYield (el))
1751 if (sstate_isUnknown (ds))
1753 uentry_setDefState (el, SS_DEFINED);
1759 } end_uentryList_elements;
1763 voptgenerror (FLG_HASYIELD,
1764 message ("Iterator %q declared with no yield parameters",
1765 uentry_getName (ue)),
1766 uentry_whereDeclared (ue));
1771 chkind_fromQual (qual qel)
1773 if (qual_isChecked (qel))
1777 else if (qual_isCheckMod (qel))
1781 else if (qual_isCheckedStrict (qel))
1783 return CH_CHECKEDSTRICT;
1785 else if (qual_isUnchecked (qel))
1787 return CH_UNCHECKED;
1792 /*@notreached@*/ return CH_UNKNOWN;
1797 uentry_reflectOtherQualifier (/*@notnull@*/ uentry ue, qual qel)
1799 if (qual_isKillRef (qel) || qual_isNewRef (qel) || qual_isTempRef (qel))
1801 if (!uentry_isRefCounted (ue))
1805 message ("Reference counting qualifier %s used on non-reference "
1806 "counted storage: %q",
1808 uentry_unparse (ue)));
1812 alkind ak = alkind_fromQual (qel);
1814 uentry_setAliasKind (ue, ak);
1817 else if (qual_isRefCounted (qel))
1819 ctype ct = ctype_realType (uentry_getType (ue));
1822 if (ctype_isPointer (ct)
1823 && (ctype_isStruct (rt = ctype_realType (ctype_baseArrayPtr (ct)))))
1825 /* check there is a refs field */
1826 uentryList fields = ctype_getFields (rt);
1827 uentry refs = uentry_undefined;
1829 uentryList_elements (fields, field)
1831 if (uentry_isRefsField (field))
1833 if (uentry_isValid (refs))
1837 message ("Reference counted structure type %s has "
1838 "multiple refs fields: %q and %q",
1840 uentry_getName (refs),
1841 uentry_getName (field)));
1846 } end_uentryList_elements;
1848 if (uentry_isInvalid (refs))
1852 message ("Reference counted structure type %s has "
1854 ctype_unparse (ct)),
1856 ("To count reference, the structure must have a field named "
1857 "refs of type int."),
1860 else if (!ctype_isInt (uentry_getType (refs)))
1864 message ("Reference counted structure type %s refs field has "
1865 "type %s (should be int)", ctype_unparse (ct),
1866 ctype_unparse (uentry_getType (refs))));
1870 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
1871 uentry_whereDeclared (ue));
1876 if ((ctype_isPointer (ct)
1877 && ctype_isUnknown (ctype_realType (ctype_baseArrayPtr (ct))))
1878 ||ctype_isAbstract (ct) || ctype_isUnknown (ct))
1880 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
1881 uentry_whereDeclared (ue));
1887 message ("Non-pointer to structure type %s declared with "
1888 "refcounted qualifier",
1889 ctype_unparse (ct)));
1893 else if (qual_isRefs (qel))
1895 if (uentry_isVariable (ue) && !uentry_isParam (ue))
1897 uentry_setAliasKind (ue, AK_REFS);
1903 message ("Refs qualifier used on non-structure field: %q",
1904 uentry_unparse (ue)));
1907 else if (qual_isAliasQual (qel))
1909 alkind ak = alkind_fromQual (qel);
1911 alkind oldak = uentry_getAliasKind (ue);
1912 ctype ut = uentry_getType (ue);
1914 if (alkind_isImplicit (ak)
1915 && (alkind_isKnown (oldak) && !alkind_isImplicit (oldak)))
1917 /* ignore the implied qualifier */
1921 if (uentry_isEitherConstant (ue))
1925 message ("Alias qualifier %s used on constant: %q",
1926 alkind_unparse (ak), uentry_unparse (ue)));
1930 if (ctype_isFunction (ut))
1932 ut = ctype_returnValue (ut);
1935 if (!(ctype_isVisiblySharable (ut)
1936 || ctype_isRealArray (ut)
1937 || ctype_isRealSU (ut)))
1939 if (!qual_isImplied (qel))
1943 message ("Alias qualifier %s used on unsharable storage type %t: %q",
1944 alkind_unparse (ak), ut, uentry_getName (ue)));
1951 if (uentry_isRefCounted (ue))
1953 if (!(qual_isRefQual (qel) || qual_isOnly (qel)
1954 || qual_isExposed (qel)
1955 || qual_isObserver (qel)))
1957 if (!qual_isImplied (qel))
1962 ("Alias qualifier %s used on reference counted storage: %q",
1963 alkind_unparse (ak),
1964 uentry_unparse (ue)));
1972 if (qual_isRefQual (qel))
1976 message ("Qualifier %s used on non-reference counted storage: %q",
1977 alkind_unparse (ak), uentry_unparse (ue)));
1986 uentry_setAliasKind (ue, ak);
1989 else if (qual_isNull (qel))
1991 if (uentry_isConstant (ue))
1995 ctype_isAbstract (ue->utype) ? NS_CONSTNULL : NS_DEFNULL,
1996 uentry_whereDeclared (ue));
2000 uentry_setNullState (ue, NS_POSNULL);
2003 else if (qual_isRelNull (qel))
2005 uentry_setNullState (ue, NS_RELNULL);
2007 else if (qual_isNotNull (qel))
2009 uentry_setNullState (ue, NS_MNOTNULL);
2011 else if (qual_isAbstract (qel)
2012 || qual_isConcrete (qel))
2014 if (!uentry_isDatatype (ue))
2018 message ("Qualifier %s used with non-datatype",
2019 qual_unparse (qel)));
2023 ue->info->datatype->abs = ynm_fromBool (qual_isAbstract (qel));
2026 else if (qual_isMutable (qel))
2028 if (!uentry_isDatatype (ue))
2030 llerror (FLG_SYNTAX,
2031 message ("Qualifier %s used with non-datatype", qual_unparse (qel)));
2035 if (!ynm_isOn (ue->info->datatype->mut))
2037 uentry_checkMutableType (ue);
2040 ue->info->datatype->mut = YES;
2043 else if (qual_isImmutable (qel))
2045 if (!uentry_isDatatype (ue))
2047 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-datatype",
2048 qual_unparse (qel)));
2052 ue->info->datatype->mut = NO;
2055 else if (qual_isNullPred (qel))
2057 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2059 uentry_makeVarFunction (ue);
2062 if (uentry_isFunction (ue))
2064 ctype typ = uentry_getType (ue);
2065 ctype rtype = ctype_returnValue (uentry_getType (ue));
2067 if (ctype_isRealBool (rtype))
2069 uentryList pl = ctype_argsFunction (typ);
2071 if (uentryList_size (pl) == 1)
2073 ue->info->fcn->nullPred = qel;
2077 llerror (FLG_SYNTAX,
2078 message ("Qualifier %s used with function having %d "
2079 "arguments (should have 1)",
2081 uentryList_size (pl)));
2086 llerror (FLG_SYNTAX,
2087 message ("Qualifier %s used with function returning %s "
2088 "(should return bool)",
2090 ctype_unparse (rtype)));
2095 llerror (FLG_SYNTAX,
2096 message ("Qualifier %s used with non-function",
2097 qual_unparse (qel)));
2100 else if (qual_isExitQual (qel))
2102 exitkind exk = exitkind_fromQual (qel);
2104 if (uentry_isFunction (ue))
2106 if (exitkind_isKnown (ue->info->fcn->exitCode))
2108 llerror (FLG_SYNTAX,
2109 message ("Multiple exit qualifiers used on function %q: %s, %s",
2110 uentry_getName (ue),
2111 exitkind_unparse (ue->info->fcn->exitCode),
2112 exitkind_unparse (exk)));
2115 ue->info->fcn->exitCode = exk;
2119 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2121 uentry_makeVarFunction (ue);
2122 ue->info->fcn->exitCode = exk;
2126 llerror (FLG_SYNTAX,
2127 message ("Exit qualifier %s used with non-function (type %s)",
2129 ctype_unparse (uentry_getType (ue))));
2135 if (qual_isCQual (qel))
2141 llbug (message ("unhandled qualifier: %s", qual_unparse (qel)));
2147 uentry_reflectQualifiers (uentry ue, qualList q)
2149 llassert (uentry_isValid (ue));
2151 qualList_elements (q, qel)
2153 if (qual_isStatic (qel))
2155 uentry_setStatic (ue);
2157 else if (qual_isUnused (qel))
2159 uentry_setUsed (ue, fileloc_undefined);
2161 else if (qual_isExternal (qel))
2163 fileloc_free (ue->whereDefined);
2164 ue->whereDefined = fileloc_createExternal ();
2166 else if (qual_isSef (qel))
2168 if (uentry_isVariable (ue))
2170 vkind vk = ue->info->var->kind;
2172 llassert (vk != VKREFPARAM);
2174 if (vk == VKYIELDPARAM)
2178 message ("Qualifier sef cannot be used with %s: %q",
2179 cstring_makeLiteralTemp (vk == VKYIELDPARAM ? "yield" : "returned"),
2180 uentry_unparse (ue)));
2182 else if (vk == VKRETPARAM)
2184 ue->info->var->kind = VKSEFRETPARAM;
2188 ue->info->var->kind = VKSEFPARAM;
2195 message ("Qualifier sef is meaningful only on parameters: %q",
2196 uentry_unparse (ue)));
2199 else if (qual_isExtern (qel))
2201 ue->storageclass = SCEXTERN;
2203 else if (qual_isGlobalQual (qel)) /* undef, killed */
2205 if (uentry_isVariable (ue))
2207 sstate oldstate = ue->info->var->defstate;
2208 sstate defstate = sstate_fromQual (qel);
2211 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
2212 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
2214 defstate = SS_UNDEFKILLED;
2221 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2222 ue->info->var->defstate = defstate;
2228 message ("Qualifier %s used on non-variable: %q",
2229 qual_unparse (qel), uentry_unparse (ue)));
2232 /* start modifications */
2234 else if( qual_isBufQualifier(qel) ) {
2235 ctype ct = ctype_realType(uentry_getType(ue));
2237 if( ctype_isArray(ct) || ctype_isPointer(ct) ) {
2239 if( uentry_hasBufStateInfo(ue) ) {
2241 if( qual_isNullTerminated(qel) ) { /* handle Nullterm */
2243 if (uentry_isAnyParam(ue) || uentry_isReturned (ue)) {
2244 /* If formal func param */
2245 uentry_setNullTerminatedState(ue);
2246 uentry_setLen (ue, 1);
2247 uentry_setSize (ue, 1);
2249 sRef_setNullTerminatedState(uentry_getSref(ue));
2250 sRef_setLen (uentry_getSref(ue), 1);
2251 sRef_setSize (uentry_getSref(ue), 1);
2253 uentry_setPossiblyNullTerminatedState(ue);
2255 sRef_setPossiblyNullTerminatedState(uentry_getSref(ue));
2259 /* put other BufState Qualifiers here */
2261 cstring s = uentry_getName(ue);
2262 llfatalbug(message("INTERNAL Error: we have a NULL BufState \
2263 struct for identifier %s\n", s) );
2265 } else if (ctype_isFunction (ct)) { /* We have to handle function */
2267 sRef retSref = uentry_getSref (ue);
2268 ctype retType = sRef_getType (retSref);
2270 if (ctype_isPointer (retType) || ctype_isArray (retType)) {
2271 sRef_setNullTerminatedState (retSref);
2277 message ("Qualifier %s used on non-pointer on \
2278 function return: %q", qual_unparse (qel),
2279 uentry_unparse (ue)));
2286 message ("Qualifier %s used on non-pointer: %q",
2287 qual_unparse (qel), uentry_unparse (ue)));
2290 else if (qual_isAllocQual (qel)) /* out, partial, reldef, special, etc. */
2292 ctype realType = ctype_realType (ue->utype);
2293 sstate defstate = sstate_fromQual (qel);
2295 if (ctype_isFunction (realType))
2297 realType = ctype_realType (ctype_returnValue (realType));
2300 if (qual_isRelDef (qel))
2302 ; /* okay anywhere */
2306 if (!ctype_isAP (realType)
2307 && !ctype_isSU (realType)
2308 && !ctype_isUnknown (realType)
2309 && !ctype_isAbstract (ue->utype))
2313 message ("Qualifier %s used on non-pointer or struct: %q",
2314 qual_unparse (qel), uentry_unparse (ue)));
2318 uentry_setDefState (ue, defstate);
2320 if (sRef_isStateSpecial (ue->sref)
2321 && alkind_isImplicit (sRef_getAliasKind (ue->sref)))
2323 sRef_setAliasKind (ue->sref, AK_ERROR, fileloc_undefined);
2326 else if (qual_isYield (qel))
2328 if (uentry_isVariable (ue))
2330 ue->info->var->kind = VKYIELDPARAM;
2336 message ("Qualifier %s used on non-iterator parameter: %q",
2337 qual_unparse (qel), uentry_unparse (ue)));
2340 else if (qual_isExQual (qel))
2342 exkind ek = exkind_fromQual (qel);
2343 ctype ut = uentry_getType (ue);
2345 if (ctype_isFunction (ut))
2347 ut = ctype_returnValue (ut);
2350 if (!(ctype_isVisiblySharable (ut))
2351 && !(ctype_isArray (ut)) /* can apply to arrays also! */
2352 && !(ctype_isStruct (ctype_realType (ut)))) /* applies to structure fields! */
2354 if (!qual_isImplied (qel))
2358 message ("Qualifier %s used on unsharable storage type %t: %q",
2359 exkind_unparse (ek), ut, uentry_getName (ue)));
2364 alkind ak = sRef_getAliasKind (ue->sref);
2366 sRef_setExKind (ue->sref, ek, uentry_whereDeclared (ue));
2368 if (alkind_isUnknown (ak) || alkind_isImplicit (ak) || alkind_isStatic (ak))
2370 if (!alkind_isTemp (ak))
2372 uentry_setAliasKind (ue, AK_IMPDEPENDENT);
2375 else if (alkind_isDependent (ak) || alkind_isTemp (ak)
2376 || alkind_isOwned (ak))
2384 message ("Exposure qualifier %s used on %s storage (should "
2385 "be dependent): %q",
2387 alkind_unparse (ak),
2388 uentry_unparse (ue)));
2392 else if (qual_isGlobCheck (qel))
2394 if (uentry_isVariable (ue))
2396 chkind ch = chkind_fromQual (qel);
2398 if (ue->info->var->checked != CH_UNKNOWN)
2400 if (ch == ue->info->var->checked)
2402 llerror (FLG_SYNTAX,
2403 message ("Redundant %s qualifier on %q",
2405 uentry_getName (ue)));
2409 llerror (FLG_SYNTAX,
2411 ("Contradictory %s and %s qualifiers on %q",
2413 checkedName (ue->info->var->checked),
2414 uentry_getName (ue)));
2418 ue->info->var->checked = ch;
2424 message ("Qualifier %s used with non-variable",
2425 qual_unparse (qel)));
2428 else if (qual_isReturned (qel))
2430 if (uentry_isVariable (ue))
2432 ue->info->var->kind = VKRETPARAM;
2436 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-variable",
2437 qual_unparse (qel)));
2442 uentry_reflectOtherQualifier (ue, qel);
2445 sRef_storeState (ue->sref);
2446 } end_qualList_elements;
2452 uentry_isOnly (uentry ue)
2454 return (!uentry_isUndefined (ue)
2455 && uentry_isVariable (ue)
2456 && alkind_isOnly (sRef_getOrigAliasKind (ue->sref)));
2460 uentry_setAliasKind (/*@notnull@*/ uentry ue, alkind ak)
2462 sRef_setAliasKind (ue->sref, ak, uentry_whereDeclared (ue));
2463 sRef_setOrigAliasKind (ue->sref, ak);
2467 uentry_setNullState (/*@notnull@*/ uentry ue, nstate ns)
2469 if (uentry_isVariable (ue))
2471 ue->info->var->nullstate = ns;
2474 sRef_setNullState (ue->sref, ns, uentry_whereDeclared (ue));
2478 uentry_isUnique (uentry ue)
2480 return (!uentry_isUndefined (ue)
2481 && uentry_isVariable (ue)
2482 && alkind_isUnique (sRef_getOrigAliasKind (ue->sref)));
2486 uentry_isFileStatic (uentry ue)
2488 return (uentry_isStatic (ue)
2489 && (!uentry_isVariable (ue)
2490 || sRef_isFileStatic (uentry_getSref (ue))));
2494 uentry_isExported (uentry ue)
2496 if (uentry_isValid (ue))
2498 if (uentry_isVariable (ue))
2500 return (sRef_isRealGlobal (uentry_getSref (ue)));
2504 return !uentry_isStatic (ue);
2512 uentry_isNonLocal (uentry ue)
2514 return (uentry_isValid (ue) && uentry_isVariable (ue)
2515 && (sRef_isGlobal (ue->sref) || uentry_isStatic (ue)));
2519 uentry_isGlobal (uentry ue)
2521 return (uentry_isValid (ue) && uentry_isVariable (ue) &&
2522 sRef_isGlobal (ue->sref));
2526 uentry_isPrintfLike (uentry ue)
2528 return (uentry_isFunction (ue)
2529 && (ue->info->fcn->specialCode == SPC_PRINTFLIKE));
2533 uentry_isScanfLike (uentry ue)
2535 return (uentry_isFunction (ue)
2536 && (ue->info->fcn->specialCode == SPC_SCANFLIKE));
2540 uentry_isMessageLike (uentry ue)
2542 return (uentry_isFunction (ue)
2543 && (ue->info->fcn->specialCode == SPC_MESSAGELIKE));
2546 static void checkSpecialFunction (/*@notnull@*/ uentry ue)
2548 uentryList args = uentry_getParams (ue);
2550 if (!uentryList_isMissingParams (args))
2552 uentry last = uentry_undefined;
2554 uentryList_elements (args, current)
2556 if (uentry_isElipsisMarker (current))
2558 if (uentry_isUndefined (last))
2562 message ("Function %q is marked %s, but has no format "
2563 "string argument before elipsis",
2564 uentry_getName (ue),
2565 specCode_unparse (ue->info->fcn->specialCode)),
2566 uentry_whereLast (ue));
2567 ue->info->fcn->specialCode = SPC_NONE;
2571 ctype rt = ctype_realType (uentry_getType (last));
2573 if (!ctype_match (rt, ctype_string))
2577 /* wchar_t * is okay too */
2578 if (ctype_isAP (rt))
2580 ctype base = ctype_baseArrayPtr (rt);
2582 if (ctype_isArbitraryIntegral (base))
2592 message ("Function %q is marked %s, but the argument "
2593 "before the elipsis has type %s (should be char *)",
2594 uentry_getName (ue),
2595 specCode_unparse (ue->info->fcn->specialCode),
2596 ctype_unparse (uentry_getType (last))),
2597 uentry_whereLast (ue));
2599 ue->info->fcn->specialCode = SPC_NONE;
2606 } end_uentryList_elements ;
2610 message ("Function %q is marked %s, but has no elipsis parameter",
2611 uentry_getName (ue),
2612 specCode_unparse (ue->info->fcn->specialCode)),
2613 uentry_whereLast (ue));
2615 ue->info->fcn->specialCode = SPC_NONE;
2620 uentry_setPrintfLike (uentry ue)
2622 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2624 uentry_makeVarFunction (ue);
2627 llassertfatal (uentry_isFunction (ue));
2628 ue->info->fcn->specialCode = SPC_PRINTFLIKE;
2629 checkSpecialFunction (ue);
2633 uentry_setScanfLike (uentry ue)
2635 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2637 uentry_makeVarFunction (ue);
2640 llassertfatal (uentry_isFunction (ue));
2641 ue->info->fcn->specialCode = SPC_SCANFLIKE;
2642 checkSpecialFunction (ue);
2646 uentry_setMessageLike (uentry ue)
2648 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2650 uentry_makeVarFunction (ue);
2653 llassertfatal (uentry_isFunction (ue));
2654 ue->info->fcn->specialCode = SPC_MESSAGELIKE;
2655 checkSpecialFunction (ue);
2659 uentry_isSpecialFunction (uentry ue)
2661 return (uentry_isFunction (ue)
2662 && (ue->info->fcn->specialCode != SPC_NONE));
2665 /*@notnull@*/ uentry uentry_makeParam (idDecl t, int i)
2667 ctype ct = idDecl_getCtype (t);
2669 sRef pref = sRef_makeParam (i, ct);
2670 uentry ue = uentry_makeVariableSrefParam (idDecl_observeId (t), ct, pref);
2672 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
2673 uentry_implicitParamAnnots (ue);
2675 /* Parameter type [][] or [x][] is invalid */
2677 while (ctype_isFixedArray (base)) {
2678 base = ctype_baseArrayPtr (base);
2681 if (ctype_isIncompleteArray (base)) {
2682 base = ctype_baseArrayPtr (base);
2684 if (ctype_isArray (base)) {
2685 if (!uentry_hasName (ue)) {
2686 (void) optgenerror (FLG_INCOMPLETETYPE,
2687 message ("Unnamed function parameter %d is incomplete type (inner array must have bounds): %s",
2689 ctype_unparse (ct)),
2690 uentry_whereLast (ue));
2692 (void) optgenerror (FLG_INCOMPLETETYPE,
2693 message ("Function parameter %q is incomplete type (inner array must have bounds): %s",
2694 uentry_getName (ue),
2695 ctype_unparse (ct)),
2696 uentry_whereLast (ue));
2704 /*@only@*/ /*@notnull@*/ uentry uentry_makeIdVariable (idDecl t)
2706 ctype ct = idDecl_getCtype (t);
2708 if (ctype_isFunction (ct))
2710 return (uentry_makeIdFunction (t));
2714 fileloc loc = setLocation ();
2715 uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
2717 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
2719 if (!uentry_isExtern (ue))
2721 uentry_setDefined (ue, loc);
2729 /*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t)
2731 return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), SS_DEFINED));
2739 /*@only@*/ /*@notnull@*/
2740 uentry uentry_makeConstantAux (cstring n, ctype t,
2741 /*@keep@*/ fileloc f, bool priv,
2742 /*@only@*/ multiVal m)
2744 uentry e = uentry_alloc ();
2747 e->uname = cstring_copy (n);
2749 e->storageclass = SCNONE;
2751 e->sref = sRef_makeConst (t);
2756 e->uses = filelocList_new ();
2757 e->isPrivate = priv;
2758 e->hasNameError = FALSE;
2760 e->info = (uinfo) dmalloc (sizeof (*e->info));
2761 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
2762 e->info->uconst->val = m;
2763 e->info->uconst->access = typeIdSet_undefined;
2765 uentry_setSpecDef (e, f);
2767 if (multiVal_isInt (m) && (multiVal_forceInt (m) == 0))
2769 sRef_setDefNull (e->sref, uentry_whereDeclared (e));
2775 /*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
2777 return (uentry_makeConstantAux (n, t, f, FALSE, multiVal_unknown ()));
2780 /*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
2782 uentry ue = uentry_makeConstant (idDecl_observeId (t),
2783 idDecl_getCtype (t),
2786 llassert (fileloc_isUndefined (ue->whereDeclared));
2787 ue->whereDeclared = setLocation ();
2789 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
2798 void uentry_setDefState (uentry ue, sstate defstate)
2800 if (uentry_isValid (ue))
2802 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2804 if (uentry_isVariable (ue))
2806 ue->info->var->defstate = defstate; /* evs 2000-05-17: fixed bug, was SS_DEFINED! */
2811 bool uentry_isCheckedUnknown (uentry ue)
2813 return (uentry_isVar (ue)
2814 && (ue->info->var->checked == CH_UNKNOWN));
2817 bool uentry_isCheckMod (uentry ue)
2819 return (uentry_isVar (ue)
2820 && (ue->info->var->checked == CH_CHECKMOD));
2823 bool uentry_isUnchecked (uentry ue)
2825 return (uentry_isVar (ue)
2826 && (ue->info->var->checked == CH_UNCHECKED));
2829 bool uentry_isChecked (uentry ue)
2831 return (uentry_isVar (ue)
2832 && (ue->info->var->checked == CH_CHECKED));
2835 bool uentry_isCheckedModify (uentry ue)
2837 return (uentry_isVar (ue)
2838 && (ue->info->var->checked == CH_CHECKED
2839 || ue->info->var->checked == CH_CHECKMOD
2840 || ue->info->var->checked == CH_CHECKEDSTRICT));
2843 bool uentry_isCheckedStrict (uentry ue)
2845 return (uentry_isVar (ue)
2846 && (ue->info->var->checked == CH_CHECKEDSTRICT));
2849 void uentry_setUnchecked (uentry ue)
2851 llassert (uentry_isVar (ue));
2853 ue->info->var->checked = CH_UNCHECKED;
2856 void uentry_setChecked (uentry ue)
2858 llassert (uentry_isVar (ue));
2860 ue->info->var->checked = CH_CHECKED;
2863 void uentry_setCheckMod (uentry ue)
2865 llassert (uentry_isVar (ue));
2867 ue->info->var->checked = CH_CHECKMOD;
2870 void uentry_setCheckedStrict (uentry ue)
2872 llassert (uentry_isVar (ue));
2874 ue->info->var->checked = CH_CHECKEDSTRICT;
2877 static /*@only@*/ /*@notnull@*/
2878 uentry uentry_makeVariableAux (cstring n, ctype t,
2880 /*@exposed@*/ sRef s,
2881 bool priv, vkind kind)
2883 uentry e = uentry_alloc ();
2886 DPRINTF (("Make variable: %s %s %s", n, ctype_unparse (t), sRef_unparse (s)));
2889 e->uname = cstring_copy (n);
2892 e->storageclass = SCNONE;
2899 e->uses = filelocList_new ();
2900 e->isPrivate = priv;
2901 e->hasNameError = FALSE;
2903 e->info = (uinfo) dmalloc (sizeof (*e->info));
2904 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
2905 e->info->var->kind = kind;
2907 e->info->var->checked = CH_UNKNOWN;
2909 uentry_setSpecDef (e, f);
2911 if (ctype_isFunction (rt))
2913 rt = ctype_returnValue (rt);
2916 if (ctype_isUA (rt))
2918 sRef_setStateFromType (e->sref, rt);
2921 e->info->var->defstate = sRef_getDefState (e->sref);
2922 e->info->var->nullstate = sRef_getNullState (e->sref);
2924 /* start modifications */
2925 /* This function sets the uentry for a pointer or array variable declaration,
2926 it allocates memory and sets the fields. We check if the type of the variable
2927 is a pointer or array and allocate a `bbufinfo' struct accordingly */
2929 if( ctype_isArray (t) || ctype_isPointer(t)) {
2930 /*@i222@*/e->info->var->bufinfo = dmalloc( sizeof(*e->info->var->bufinfo) );
2931 e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
2932 s->bufinfo.bufstate = BB_NOTNULLTERMINATED;
2934 e->info->var->bufinfo = NULL;
2936 /* end modification */
2942 uentry_isYield (uentry ue)
2944 return (uentry_isVariable (ue)
2945 && (ue->info->var->kind == VKYIELDPARAM
2946 || ue->info->var->kind == VKREFYIELDPARAM));
2950 uentry_isRefsField (uentry ue)
2952 return (uentry_isVariable (ue) && sRef_isRefsField (ue->sref));
2955 /*@only@*/ /*@notnull@*/
2956 uentry uentry_makeVariable (cstring n, ctype t, fileloc f, bool isPriv)
2958 return (uentry_makeVariableAux (n, t, f, sRef_makeType (t), isPriv,
2959 fileloc_isSpec (f) ? VKSPEC : VKNORMAL));
2966 void uentry_makeVarFunction (uentry ue)
2973 llassert (uentry_isValid (ue));
2974 llassert (!sRef_modInFunction ());
2976 ak = sRef_getOrigAliasKind (ue->sref);
2977 ek = sRef_getOrigExKind (ue->sref);
2979 oldInfo = ue->info->var;
2981 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
2984 ** expanded macro is marked used (until I write a pre-processor)
2987 ue->used |= (oldInfo->kind == VKEXPMACRO);
2990 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
2991 ue->info->fcn->exitCode = XK_UNKNOWN;
2992 ue->info->fcn->nullPred = QU_UNKNOWN;
2993 ue->info->fcn->specialCode = SPC_NONE;
2994 ue->info->fcn->access = typeIdSet_undefined;
2995 ue->info->fcn->hasGlobs = FALSE;
2996 ue->info->fcn->globs = globSet_undefined;
2997 ue->info->fcn->hasMods = FALSE;
2998 ue->info->fcn->mods = sRefSet_undefined;
2999 ue->info->fcn->specclauses = NULL;
3000 ue->info->fcn->defparams = uentryList_undefined;
3003 ue->info->fcn->preconditions = constraintList_undefined;
3007 ue->info->fcn->postconditions = constraintList_undefined;
3011 if (ctype_isFunction (ue->utype))
3013 ue->sref = sRef_makeType (ctype_returnValue (ue->utype));
3017 ue->sref = sRef_makeType (ctype_unknown);
3020 if (sRef_isRefCounted (ue->sref))
3026 if (alkind_isUnknown (ak))
3028 if (exkind_isKnown (ek))
3030 ak = AK_IMPDEPENDENT;
3034 if (context_getFlag (FLG_RETIMPONLY))
3036 if (ctype_isFunction (ue->utype)
3037 && ctype_isVisiblySharable
3038 (ctype_realType (ctype_returnValue (ue->utype))))
3040 if (uentryList_hasReturned (uentry_getParams (ue)))
3054 loc = ue->whereDeclared;
3056 sRef_setAliasKind (ue->sref, ak, loc);
3057 sRef_setNullState (ue->sref, oldInfo->nullstate, loc);
3058 sRef_setDefState (ue->sref, oldInfo->defstate, loc);
3059 sRef_setExKind (ue->sref, ek, loc);
3061 if (oldInfo->kind == VKEXPMACRO)
3064 ue->whereDeclared = fileloc_undefined;
3068 fileloc_free (ue->whereDefined);
3069 ue->whereDefined = fileloc_undefined;
3072 uvinfo_free (oldInfo);
3076 uentry_setGlobals (uentry ue, /*@owned@*/ globSet globs)
3078 llassert (uentry_isValid (ue));
3080 if (uentry_isIter (ue))
3082 llassert (globSet_isUndefined (ue->info->iter->globs));
3083 ue->info->iter->globs = globs;
3087 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
3089 uentry_makeVarFunction (ue);
3092 llassert (uentry_isFunction (ue));
3093 llassert (!ue->info->fcn->hasGlobs
3094 && globSet_isUndefined (ue->info->fcn->globs));
3096 ue->info->fcn->hasGlobs = TRUE;
3097 /*@-mustfree@*/ ue->info->fcn->globs = globs;
3101 if (globSet_hasStatic (globs))
3103 context_recordFileGlobals (globs);
3106 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3108 ue->info->fcn->hasMods = TRUE;
3112 void uentry_addAccessType (uentry ue, typeId tid)
3114 if (uentry_isFunction (ue))
3116 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3118 else if (uentry_isEitherConstant (ue))
3120 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3122 else if (uentry_isIter (ue))
3124 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3126 else if (uentry_isEndIter (ue))
3128 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3132 llbug (message ("no access for: %q", uentry_unparse (ue)));
3136 /*@only@*/ /*@notnull@*/ uentry
3137 uentry_makeFunction (cstring n, ctype t,
3139 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
3142 return (uentry_makeFunctionAux (n, t,
3143 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3144 : typeIdSet_single (access)),
3150 /*@notnull@*/ uentry
3151 uentry_makePrivFunction2 (cstring n, ctype t,
3153 globSet globs, sRefSet mods,
3156 return (uentry_makeFunctionAux (n, t, access, globs, mods, f, TRUE, FALSE));
3160 /*@notnull@*/ uentry
3161 uentry_makeSpecFunction (cstring n, ctype t,
3163 /*@only@*/ globSet globs,
3164 /*@only@*/ sRefSet mods,
3167 uentry ue = uentry_makeFunctionAux (n, t, access,
3171 uentry_setHasGlobs (ue);
3172 uentry_setHasMods (ue);
3174 reflectImplicitFunctionQualifiers (ue, TRUE);
3179 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3181 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3182 sRef_undefined, FALSE, VKEXPMACRO);
3184 uentry_setDefined (ue, f);
3188 /*@notnull@*/ /*@notnull@*/ uentry
3189 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3191 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3192 typeIdSet_singleOpt (access),
3193 globSet_undefined, sRefSet_undefined,
3197 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3201 bool uentry_isForward (uentry e)
3203 if (uentry_isValid (e))
3205 ctype ct = uentry_getType (e);
3207 return (ctype_isUnknown (ct)
3208 || (ctype_isFunction (ct)
3209 && ctype_isUnknown (ctype_returnValue (ct))));
3216 /*@notnull@*/ uentry
3217 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3219 return (uentry_makeFunctionAux (n, ctype_unknown, access,
3225 /*@notnull@*/ uentry
3226 uentry_makeUnspecFunction (cstring n, ctype t,
3230 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_new (),
3231 sRefSet_new (), f, FALSE, TRUE);
3233 reflectImplicitFunctionQualifiers (ue, TRUE);
3242 /* is exported for use by usymtab_interface */
3244 /*@notnull@*/ uentry
3245 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, ynm abs,
3246 fileloc f, bool priv)
3248 uentry e = uentry_alloc ();
3250 DPRINTF (("Make datatype: %s / %s",
3251 n, ctype_unparse (t)));
3253 /* e->shallowCopy = FALSE; */
3254 e->ukind = KDATATYPE;
3255 e->uname = cstring_copy (n);
3257 e->storageclass = SCNONE;
3258 e->sref = sRef_makeUnknown ();
3262 sRef_setStateFromType (e->sref, t);
3265 uentry_setSpecDef (e, f);
3267 e->uses = filelocList_new ();
3268 e->isPrivate = priv;
3269 e->hasNameError = FALSE;
3274 e->info = (uinfo) dmalloc (sizeof (*e->info));
3275 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3276 e->info->datatype->abs = abs;
3277 e->info->datatype->mut = mut;
3278 e->info->datatype->type = ctype_undefined;
3280 if (uentry_isDeclared (e))
3282 uentry_setDefined (e, f);
3285 if (ynm_isOn (abs) && !(uentry_isCodeDefined (e)))
3287 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3293 /*@notnull@*/ uentry
3294 uentry_makeDatatype (cstring n, ctype t, ynm mut, ynm abs,
3297 return (uentry_makeDatatypeAux (n, t, mut, abs, f, FALSE));
3300 /*@notnull@*/ uentry uentry_makeBoolDatatype (ynm abs)
3302 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
3303 ctype_bool, NO, abs,
3304 fileloc_getBuiltin (),
3307 ret->info->datatype->type = ctype_bool;
3315 static /*@only@*/ /*@notnull@*/ uentry
3316 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3317 /*@only@*/ fileloc f)
3319 uentry e = uentry_alloc ();
3322 e->uname = cstring_copy (n);
3324 e->sref = sRef_makeUnknown ();
3325 e->storageclass = SCNONE;
3329 uentry_setSpecDef (e, f);
3331 e->uses = filelocList_new ();
3332 e->isPrivate = FALSE;
3333 e->hasNameError = FALSE;
3335 e->info = (uinfo) dmalloc (sizeof (*e->info));
3336 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3337 e->info->iter->access = access;
3338 e->info->iter->mods = sRefSet_undefined;
3339 e->info->iter->globs = globSet_undefined;
3341 uentry_checkIterArgs (e);
3345 /*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3347 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3350 static /*@notnull@*/ uentry
3351 uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3353 uentry e = uentry_alloc ();
3355 /* e->shallowCopy = FALSE; */
3356 e->ukind = KENDITER;
3357 e->storageclass = SCNONE;
3358 e->uname = message ("end_%s", n);
3359 e->utype = ctype_unknown;
3360 e->sref = sRef_makeUnknown ();
3362 uentry_setSpecDef (e, f);
3367 e->uses = filelocList_new ();
3368 e->isPrivate = FALSE;
3369 e->hasNameError = FALSE;
3371 e->info = (uinfo) dmalloc (sizeof (*e->info));
3372 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3374 e->info->enditer->access = access;
3379 /*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3381 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3388 static /*@only@*/ /*@notnull@*/ uentry
3389 uentry_makeTagAux (cstring n, ctype t,
3390 /*@only@*/ fileloc fl,
3391 bool priv, ekind kind)
3393 uentry e = uentry_alloc ();
3395 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3397 llbuglit ("uentry_makeTagAux: not a tag type");
3401 /* e->shallowCopy = FALSE; */
3402 e->uname = cstring_copy (n);
3405 e->sref = sRef_makeUnknown ();
3406 e->storageclass = SCNONE;
3408 uentry_setSpecDef (e, fl);
3413 e->uses = filelocList_new ();
3414 e->isPrivate = priv;
3415 e->hasNameError = FALSE;
3417 e->info = (uinfo) dmalloc (sizeof (*e->info));
3418 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3419 e->info->datatype->abs = NO;
3420 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3421 e->info->datatype->type = t;
3423 if (uentry_isDeclared (e))
3425 uentry_setDefined (e, fl);
3431 uentry uentry_makeStructTagLoc (cstring n, ctype t)
3433 cstring sname = makeStruct (n);
3434 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3436 cstring_free (sname);
3441 uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3443 cstring sname = makeStruct (n);
3444 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3446 cstring_free (sname);
3451 uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
3453 cstring uname = makeUnion (n);
3454 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
3456 cstring_free (uname);
3462 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
3464 cstring ename = makeEnum (n);
3465 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
3467 cstring_free (ename);
3473 uentry_makeUnionTagLoc (cstring n, ctype t)
3475 cstring uname = makeUnion (n);
3476 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
3478 cstring_free (uname);
3483 uentry_makeEnumTagLoc (cstring n, ctype t)
3485 cstring ename = makeEnum (n);
3486 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
3488 cstring_free (ename);
3493 uentry_isStructTag (uentry ue)
3495 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
3499 uentry_isUnionTag (uentry ue)
3501 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
3505 uentry_isEnumTag (uentry ue)
3507 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
3511 uentry_isAnyTag (uentry ue)
3513 return (uentry_isStructTag (ue)
3514 || uentry_isUnionTag (ue)
3515 || uentry_isEnumTag (ue));
3518 static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
3520 extern void uentry_destroyMod (void)
3521 /*@globals killed emarker@*/ /*@modifies emarker@*/
3523 static bool wasDestroyed = FALSE;
3525 llassert (!wasDestroyed);
3527 if (emarker != NULL)
3529 uentry_reallyFree (emarker);
3532 wasDestroyed = TRUE;
3536 uentry_makeElipsisMarker (void)
3538 if (emarker == NULL)
3540 emarker = uentry_alloc ();
3542 emarker->ukind = KELIPSMARKER;
3543 emarker->uname = cstring_makeLiteral ("...");
3544 emarker->utype = ctype_elipsMarker;
3545 emarker->sref = sRef_undefined;
3546 emarker->storageclass = SCNONE;
3547 emarker->used = FALSE;
3548 emarker->lset = FALSE;
3549 emarker->info = NULL;
3551 uentry_setSpecDef (emarker, fileloc_undefined);
3552 emarker->uses = filelocList_new ();
3553 emarker->isPrivate = FALSE;
3554 emarker->hasNameError = FALSE;
3557 /*@ignore@*/ return (emarker); /*@end@*/
3565 uentry_equiv (uentry p1, uentry p2)
3567 if (uentry_compare (p1, p2) != 0)
3578 uentry_xcomparealpha (uentry *p1, uentry *p2)
3582 if ((res = uentry_compare (*p1, *p2)) == 0) {
3583 if ((*p1 != NULL) && (*p2 != NULL)) {
3584 res = cstring_compare ((*p1)->uname,
3593 uentry_xcompareuses (uentry *p1, uentry *p2)
3598 if (uentry_isValid (u1))
3600 if (uentry_isValid (u2))
3602 return (-1 * int_compare (filelocList_size (u1->uses),
3603 filelocList_size (u2->uses)));
3612 if (uentry_isValid (u2))
3624 uentry_compareStrict (uentry v1, uentry v2)
3626 COMPARERETURN (uentry_compare (v1, v2));
3628 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
3630 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
3631 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
3632 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
3639 uentry_compare (uentry u1, uentry u2)
3641 if (u1 == u2) return 0;
3643 if (uentry_isInvalid (u1)) return -1;
3644 if (uentry_isInvalid (u2)) return 1;
3646 INTCOMPARERETURN (u1->ukind, u2->ukind);
3647 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
3648 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
3650 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
3656 /* bug detected by lclint:
3657 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
3662 return (multiVal_compare (u1->info->uconst->val,
3663 u2->info->uconst->val));
3667 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
3669 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
3670 uentry_accessType (u2)));
3671 return (uentryList_compareParams (uentry_getParams (u1),
3672 uentry_getParams (u2)));
3674 return (typeIdSet_compare (uentry_accessType (u1),
3675 uentry_accessType (u2)));
3677 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
3678 uentry_accessType (u2)));
3679 COMPARERETURN (globSet_compare (uentry_getGlobs (u1),
3680 uentry_getGlobs (u2)));
3681 COMPARERETURN (uentryList_compareParams (uentry_getParams (u1),
3682 uentry_getParams (u2)));
3683 COMPARERETURN (generic_compare (u1->info->fcn->specialCode,
3684 u2->info->fcn->specialCode));
3685 COMPARERETURN (generic_compare (u1->info->fcn->nullPred,
3686 u2->info->fcn->nullPred));
3688 return (sRefSet_compare (uentry_getMods (u1), uentry_getMods (u2)));
3690 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
3691 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
3692 sRef_getOrigAliasKind (u2->sref)));
3693 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
3694 sRef_getOrigExKind (u2->sref)));
3695 COMPARERETURN (generic_compare (u1->info->var->checked,
3696 u2->info->var->checked));
3697 COMPARERETURN (generic_compare (u1->info->var->defstate,
3698 u2->info->var->defstate));
3699 return (generic_compare (u1->info->var->nullstate,
3700 u2->info->var->nullstate));
3702 COMPARERETURN (ctype_compare (u1->info->datatype->type,
3703 u2->info->datatype->type));
3704 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
3705 u2->info->datatype->mut));
3706 return (ynm_compare (u1->info->datatype->abs, u2->info->datatype->abs));
3715 ** all entries are: <type>[@<info>]*#<name>
3717 ** info depends on kind:
3721 advanceField (char **s)
3727 advanceName (char **s)
3733 vkind_fromInt (int i)
3735 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
3737 llbuglit ("vkind_fromInt: out of range");
3744 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
3745 typeIdSet access, nstate nullstate,
3746 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
3748 uentry e = uentry_alloc ();
3753 e->sref = sRef_makeConst (ct);
3755 sRef_setNullState (e->sref, nullstate, loc);
3756 e->storageclass = SCNONE;
3758 if (fileloc_isSpec (loc))
3760 e->whereSpecified = loc;
3761 e->whereDeclared = fileloc_undefined;
3765 e->whereSpecified = fileloc_undefined;
3766 e->whereDeclared = loc;
3769 e->whereDefined = fileloc_undefined;
3770 e->uses = filelocList_new ();
3771 e->isPrivate = FALSE;
3772 e->hasNameError = FALSE;
3777 e->info = (uinfo) dmalloc (sizeof (*e->info));
3778 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
3779 e->info->uconst->val = m;
3780 e->info->uconst->access = access;
3782 sRef_storeState (e->sref);
3787 static /*@only@*/ uentry
3788 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
3789 sstate defstate, nstate isnull, alkind aliased,
3790 exkind exp, chkind checked,
3791 /*@only@*/ fileloc loc)
3793 uentry e = uentry_alloc ();
3798 e->storageclass = SCNONE;
3800 e->sref = sRef_makeType (ct);
3801 sRef_setNullState (e->sref, isnull, loc);
3803 e->whereDefined = fileloc_undefined;
3805 if (fileloc_isSpec (loc))
3807 e->whereSpecified = loc;
3808 e->whereDeclared = fileloc_undefined;
3812 e->whereSpecified = fileloc_undefined;
3813 e->whereDeclared = loc;
3816 e->isPrivate = FALSE;
3817 e->hasNameError = FALSE;
3822 e->uses = filelocList_new ();
3824 e->info = (uinfo) dmalloc (sizeof (*e->info));
3825 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
3826 e->info->var->kind = kind;
3827 e->info->var->checked = checked;
3828 e->info->var->defstate = defstate;
3830 sRef_setDefState (e->sref, defstate, loc);
3832 e->info->var->nullstate = sRef_getNullState (e->sref);
3834 sRef_setExKind (e->sref, exp, loc);
3835 sRef_setAliasKind (e->sref, aliased, loc);
3837 sRef_storeState (e->sref);
3839 /*DRL ADDED 9-1-2000 */
3840 e->info->var->bufinfo = NULL;
3845 static /*@only@*/ uentry
3846 uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, ynm abs,
3847 ynm mut, ctype rtype, alkind ak, exkind exp,
3848 sstate defstate, nstate isnull,
3849 /*@only@*/ fileloc loc)
3851 uentry e = uentry_alloc ();
3853 e->ukind = KDATATYPE;
3854 /* e->shallowCopy = FALSE; */
3857 e->storageclass = SCNONE;
3858 e->sref = sRef_makeUnknown ();
3861 ** This is only setting null state. (I think?)
3864 if (ctype_isUA (ct))
3866 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
3868 if (uentry_isValid (te))
3870 sRef_setStateFromUentry (e->sref, te);
3874 /* problem for recursive type definitions */
3878 sRef_setAliasKind (e->sref, ak, loc);
3879 sRef_setExKind (e->sref, exp, loc);
3881 sRef_setDefState (e->sref, defstate, loc);
3883 if (ynm_isOn (abs) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
3885 isnull = NS_ABSNULL;
3888 sRef_mergeNullState (e->sref, isnull);
3890 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
3892 if (fileloc_isSpec (loc))
3894 e->whereSpecified = loc;
3895 e->whereDeclared = fileloc_undefined;
3899 e->whereSpecified = fileloc_undefined;
3900 e->whereDeclared = loc;
3903 e->isPrivate = FALSE;
3904 e->hasNameError = FALSE;
3908 e->uses = filelocList_new ();
3910 e->info = (uinfo) dmalloc (sizeof (*e->info));
3911 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3912 e->info->datatype->abs = abs;
3913 e->info->datatype->mut = mut;
3914 e->info->datatype->type = rtype;
3916 sRef_storeState (e->sref);
3922 static void uentry_setHasGlobs (uentry ue)
3924 llassert (uentry_isFunction (ue));
3926 ue->info->fcn->hasGlobs = TRUE;
3929 static void uentry_setHasMods (uentry ue)
3931 llassert (uentry_isFunction (ue));
3933 ue->info->fcn->hasMods = TRUE;
3937 bool uentry_hasGlobs (uentry ue)
3939 if (uentry_isFunction (ue))
3941 return (ue->info->fcn->hasGlobs);
3947 bool uentry_hasSpecialClauses (uentry ue)
3949 return (uentry_isFunction (ue) && specialClauses_isDefined (ue->info->fcn->specclauses));
3952 specialClauses uentry_getSpecialClauses (uentry ue)
3954 llassert (uentry_isFunction (ue));
3955 return ue->info->fcn->specclauses;
3958 bool uentry_hasMods (uentry ue)
3960 if (uentry_isFunction (ue))
3962 return (ue->info->fcn->hasMods);
3969 uentry_makeFunctionBase (/*@only@*/ cstring name, ctype ct,
3971 bool hasGlobs, /*@only@*/ globSet globs,
3972 bool hasMods, /*@only@*/ sRefSet mods,
3973 alkind ak, exkind exp,
3974 sstate defstate, nstate isnull,
3978 /*@only@*/ specialClauses specclauses,
3979 /*@only@*/ fileloc loc)
3981 uentry e = uentry_alloc ();
3984 /* e->shallowCopy = FALSE; */
3988 e->storageclass = SCNONE;
3990 if (ctype_isFunction (ct))
3992 ret = ctype_returnValue (ct);
3996 if (ctype_isKnown (ct))
3998 llbug (message ("not function: %s", ctype_unparse (ct)));
4001 ret = ctype_unknown;
4004 e->sref = sRef_makeType (ret);
4006 if (ctype_isUA (ret))
4008 sRef_setStateFromType (e->sref, ret);
4011 sRef_setDefined (e->sref, loc);
4012 sRef_setNullState (e->sref, isnull, loc);
4014 sRef_setAliasKind (e->sref, ak, loc);
4015 sRef_setExKind (e->sref, exp, loc);
4016 sRef_setDefState (e->sref, defstate, loc);
4018 e->whereSpecified = loc;
4019 e->whereDefined = fileloc_undefined;
4021 e->isPrivate = FALSE;
4022 e->hasNameError = FALSE;
4026 e->uses = filelocList_new ();
4028 e->info = (uinfo) dmalloc (sizeof (*e->info));
4029 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
4031 e->info->fcn->exitCode = exitCode;
4032 e->info->fcn->specialCode = sCode;
4033 e->info->fcn->nullPred = nullPred;
4034 e->info->fcn->access = access;
4036 e->info->fcn->specclauses = specclauses;
4037 e->info->fcn->hasGlobs = hasGlobs;
4038 e->info->fcn->globs = globs;
4040 e->info->fcn->hasMods = hasMods;
4041 e->info->fcn->mods = mods;
4043 e->info->fcn->defparams = uentryList_undefined;
4044 e->whereDeclared = fileloc_undefined;
4046 sRef_storeState (e->sref);
4049 e->info->fcn->preconditions = NULL;
4053 e->info->fcn->postconditions = NULL;
4059 static /*@only@*/ uentry
4060 uentry_makeTagBase (/*@only@*/ cstring name, ekind tagkind,
4061 ctype ct, ctype rtype, /*@only@*/ fileloc loc)
4063 uentry e = uentry_alloc ();
4065 if (tagkind != KSTRUCTTAG && tagkind != KUNIONTAG && tagkind != KENUMTAG)
4067 llbuglit ("uentry_makeTagBase: not a tag type");
4070 /* e->shallowCopy = FALSE; */
4074 e->sref = sRef_makeUnknown ();
4075 e->storageclass = SCNONE;
4077 if (fileloc_isSpec (loc))
4079 e->whereSpecified = loc;
4080 e->whereDeclared = fileloc_undefined;
4084 e->whereDeclared = loc;
4085 e->whereSpecified = fileloc_undefined;
4088 e->whereDefined = fileloc_undefined;
4090 e->isPrivate = FALSE;
4091 e->hasNameError = FALSE;
4095 e->uses = filelocList_new ();
4097 e->info = (uinfo) dmalloc (sizeof (*e->info));
4098 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4099 e->info->datatype->abs = NO;
4100 e->info->datatype->mut = MAYBE;
4101 e->info->datatype->type = rtype;
4103 sRef_storeState (e->sref);
4109 uentry_makeIterBase (/*@only@*/ cstring name, typeIdSet access,
4110 ctype ct, /*@only@*/ fileloc loc)
4112 uentry e = uentry_alloc ();
4114 /* e->shallowCopy = FALSE; */
4118 e->sref = sRef_makeUnknown ();
4119 e->storageclass = SCNONE;
4121 if (fileloc_isSpec (loc))
4123 e->whereSpecified = loc;
4124 e->whereDeclared = fileloc_undefined;
4128 e->whereDeclared = loc;
4129 e->whereSpecified = fileloc_undefined;
4132 e->whereDefined = fileloc_undefined;
4134 e->isPrivate = FALSE;
4135 e->hasNameError = FALSE;
4139 e->uses = filelocList_new ();
4141 e->info = (uinfo) dmalloc (sizeof (*e->info));
4142 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
4143 e->info->iter->access = access;
4144 e->info->iter->mods = sRefSet_undefined;
4145 e->info->iter->globs = globSet_undefined;
4147 sRef_storeState (e->sref);
4152 uentry_makeEndIterBase (/*@only@*/ cstring name, typeIdSet access,
4153 /*@only@*/ fileloc loc)
4155 uentry e = uentry_alloc ();
4157 /* e->shallowCopy = FALSE; */
4158 e->ukind = KENDITER;
4159 e->storageclass = SCNONE;
4161 e->utype = ctype_unknown;
4162 e->sref = sRef_makeUnknown ();
4164 if (fileloc_isSpec (loc))
4166 e->whereSpecified = loc;
4167 e->whereDeclared = fileloc_undefined;
4171 e->whereDeclared = loc;
4172 e->whereSpecified = fileloc_undefined;
4175 e->whereDefined = fileloc_undefined;
4177 e->isPrivate = FALSE;
4178 e->hasNameError = FALSE;
4182 e->uses = filelocList_new ();
4184 e->info = (uinfo) dmalloc (sizeof (*e->info));
4185 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
4186 e->info->enditer->access = access;
4187 sRef_storeState (e->sref);
4192 void uentry_markFree (/*@unused@*/ /*@owned@*/ uentry u)
4200 uentry_undump (ekind kind, fileloc loc, char **s)
4208 ue = uentry_makeElipsisMarker ();
4212 ctype ct = ctype_undump (s);
4228 if (optCheckChar (s, '@'))
4230 tkind = vkind_fromInt (getInt (s));
4238 if (optCheckChar (s, '$'))
4240 defstate = SS_UNKNOWN;
4241 isnull = NS_UNKNOWN;
4242 aliased = AK_IMPTEMP;
4244 checked = CH_UNKNOWN;
4246 else if (optCheckChar (s, '&'))
4248 defstate = SS_DEFINED;
4249 isnull = NS_UNKNOWN;
4250 aliased = AK_IMPTEMP;
4252 checked = CH_UNKNOWN;
4254 else if (optCheckChar (s, '^'))
4256 defstate = SS_UNKNOWN;
4257 isnull = NS_UNKNOWN;
4258 aliased = AK_IMPTEMP;
4260 checked = CH_UNKNOWN;
4264 defstate = sstate_fromInt (getInt (s));
4265 advanceField (s); isnull = nstate_fromInt (getInt (s));
4266 advanceField (s); aliased = alkind_fromInt (getInt (s));
4268 if (optCheckChar (s, '&'))
4271 checked = CH_UNKNOWN;
4275 advanceField (s); exp = exkind_fromInt (getInt (s));
4276 advanceField (s); checked = (chkind) (getInt (s));
4281 name = getStringWord (s);
4283 ue = uentry_makeVariableBase (name, ct, tkind, defstate,
4284 isnull, aliased, exp,
4285 checked, fileloc_copy (loc));
4298 advanceField (s); abs = ynm_fromCodeChar (loadChar (s));
4299 advanceField (s); mut = ynm_fromCodeChar (loadChar (s));
4300 advanceField (s); defstate = sstate_fromInt (getInt (s));
4301 advanceField (s); isnull = nstate_fromInt (getInt (s));
4302 advanceField (s); aliased = alkind_fromInt (getInt (s));
4303 advanceField (s); exp = exkind_fromInt (getInt (s));
4304 advanceField (s); rtype = ctype_undump (s);
4306 name = getStringWord (s);
4308 ue = uentry_makeDatatypeBase (name, ct, abs, mut, rtype,
4309 aliased, exp, defstate, isnull,
4310 fileloc_copy (loc));
4327 specialClauses specclauses;
4329 if (optCheckChar (s, '$'))
4331 defstate = SS_DEFINED;
4332 isnull = NS_UNKNOWN;
4333 exitCode = XK_UNKNOWN;
4335 nullPred = QU_UNKNOWN;
4339 advanceField (s); defstate = sstate_fromInt (getInt (s));
4340 advanceField (s); isnull = nstate_fromInt (getInt (s));
4341 advanceField (s); exitCode = exitkind_fromInt (getInt (s));
4342 advanceField (s); specc = specCode_fromInt (getInt (s));
4343 advanceField (s); nullPred = qual_fromInt (getInt (s));
4346 if (optCheckChar (s, '$'))
4349 globs = globSet_undefined;
4351 mods = sRefSet_undefined;
4353 else if (optCheckChar (s, '^'))
4356 globs = globSet_undefined;
4358 mods = sRefSet_undefined;
4362 advanceField (s); hasGlobs = bool_fromInt (getInt (s));
4363 advanceField (s); globs = globSet_undump (s);
4364 advanceField (s); hasMods = bool_fromInt (getInt (s));
4365 advanceField (s); mods = sRefSet_undump (s);
4368 if (optCheckChar (s, '$'))
4375 advanceField (s); ak = alkind_fromInt (getInt (s));
4376 advanceField (s); exp = exkind_fromInt (getInt (s));
4379 advanceField (s); access = typeIdSet_undump (s);
4381 if (optCheckChar (s, '@'))
4383 specclauses = specialClauses_undump (s);
4387 specclauses = specialClauses_undefined;
4390 advanceName (s); name = getStringWord (s);
4392 ue = uentry_makeFunctionBase (name, ct, access,
4395 ak, exp, defstate, isnull,
4396 exitCode, specc, nullPred,
4398 fileloc_copy (loc));
4399 DPRINTF (("Undump: %s", uentry_unparse (ue)));
4406 advanceField (s); access = typeIdSet_undump (s);
4407 advanceName (s); name = getStringWord (s);
4409 ue = uentry_makeIterBase (name, access, ct,
4410 fileloc_copy (loc));
4417 advanceField (s); access = typeIdSet_undump (s);
4418 advanceName (s); name = getStringWord (s);
4420 ue = uentry_makeEndIterBase (name, access, fileloc_copy (loc));
4430 if (optCheckChar (s, '$'))
4432 val = multiVal_undefined;
4433 access = typeIdSet_undefined;
4434 nullstate = NS_UNKNOWN;
4438 advanceField (s); val = multiVal_undump (s);
4439 advanceField (s); access = typeIdSet_undump (s);
4440 advanceField (s); nullstate = nstate_fromInt (getInt (s));
4443 advanceName (s); name = getStringWord (s);
4445 ue = uentry_makeConstantBase (name, ct, access,
4446 nullstate, fileloc_copy (loc), val);
4455 advanceField (s); rtype = ctype_undump (s);
4456 advanceName (s); name = getStringWord (s);
4457 ue = uentry_makeTagBase (name, kind, ct, rtype, fileloc_copy (loc));
4461 llcontbuglit ("uentry_undump: invalid");
4462 ue = uentry_undefined;
4465 llcontbuglit ("uentry_undump: elips marker");
4466 ue = uentry_undefined;
4475 uentry_dump (uentry v)
4477 return (uentry_dumpAux (v, FALSE));
4481 uentry_dumpParam (uentry v)
4483 llassertprint (uentry_isVariable (v) || uentry_isElipsisMarker (v),
4484 ("dump: %s", uentry_unparseFull (v)));
4486 return (uentry_dumpAux (v, TRUE));
4490 uentry_dumpAux (uentry v, bool isParam)
4492 llassert (uentry_isValid (v));
4494 DPRINTF (("Dumping entry: %s", uentry_unparseFull (v)));
4499 llcontbuglit ("uentry_dump: invalid entry");
4500 return cstring_undefined;
4502 return (message ("!."));
4506 vkind vk = v->info->var->kind;
4507 sstate dss = sRef_getDefState (v->sref);
4508 nstate nst = sRef_getNullState (v->sref);
4509 alkind alk = sRef_getAliasKind (v->sref);
4510 exkind exk = sRef_getExKind (v->sref);
4511 chkind chk = v->info->var->checked;
4513 DPRINTF (("Dumping var"));
4515 if (dss == SS_UNKNOWN
4516 && nst == NS_UNKNOWN
4517 && alk == AK_IMPTEMP
4518 && exk == XO_UNKNOWN
4519 && chk == CH_UNKNOWN)
4521 sdump = cstring_makeLiteral ("$");
4523 else if (dss == SS_DEFINED
4524 && nst == NS_UNKNOWN
4525 && alk == AK_IMPTEMP
4526 && exk == XO_UNKNOWN
4527 && chk == CH_UNKNOWN)
4529 sdump = cstring_makeLiteral ("&");
4531 else if (dss == SS_UNKNOWN
4532 && nst == NS_UNKNOWN
4533 && alk == AK_UNKNOWN
4534 && exk == XO_UNKNOWN
4535 && chk == CH_UNKNOWN)
4537 sdump = cstring_makeLiteral ("^");
4539 else if (exk == XO_UNKNOWN
4540 && chk == CH_UNKNOWN)
4542 sdump = message ("%d@%d@%d&",
4549 sdump = message ("%d@%d@%d@%d@%d",
4560 return (message ("%q|@%d|%q#%s",
4561 ctype_dump (v->utype),
4564 isParam ? cstring_undefined : v->uname));
4568 return (message ("%q|%q#%s",
4569 ctype_dump (v->utype),
4571 isParam ? cstring_undefined : v->uname));
4576 return (message ("%q@%s@%s@%d@%d@%d@%d@%q#%s",
4577 ctype_dump (v->utype),
4578 ynm_unparseCode (v->info->datatype->abs),
4579 ynm_unparseCode (v->info->datatype->mut),
4580 (int) sRef_getDefState (v->sref),
4581 (int) sRef_getNullState (v->sref),
4582 (int) sRef_getAliasKind (v->sref),
4583 (int) sRef_getExKind (v->sref),
4584 ctype_dump (v->info->datatype->type),
4588 cstring sdump, gdump, adump;
4589 alkind alk = sRef_getAliasKind (v->sref);
4590 exkind exk = sRef_getExKind (v->sref);
4592 if (sRef_getDefState (v->sref) == SS_DEFINED
4593 && !nstate_isKnown (sRef_getNullState (v->sref))
4594 && !exitkind_isKnown (v->info->fcn->exitCode)
4595 && v->info->fcn->specialCode == SPC_NONE
4596 && v->info->fcn->nullPred == QU_UNKNOWN)
4598 sdump = cstring_makeLiteral ("$");
4602 sdump = message ("@%d@%d@%d@%d@%d",
4603 (int) sRef_getDefState (v->sref),
4604 (int) sRef_getNullState (v->sref),
4605 (int) v->info->fcn->exitCode,
4606 (int) v->info->fcn->specialCode,
4607 (int) v->info->fcn->nullPred);
4610 if (!uentry_hasGlobs(v) && !uentry_hasMods (v))
4612 gdump = cstring_makeLiteral ("$");
4614 else if (uentry_hasGlobs (v) && globSet_isEmpty (uentry_getGlobs (v))
4615 && uentry_hasMods (v) && sRefSet_isEmpty (uentry_getMods (v)))
4617 gdump = cstring_makeLiteral ("^");
4621 gdump = message ("@%s@%q@%s@%q",
4622 bool_dump (uentry_hasGlobs (v)),
4623 globSet_dump (uentry_getGlobs (v)),
4624 bool_dump (uentry_hasMods (v)),
4625 sRefSet_dump (uentry_getMods (v)));
4628 if (alk == AK_UNKNOWN && exk == XO_UNKNOWN)
4630 adump = cstring_makeLiteral ("$");
4634 adump = message ("@%d@%d", (int) alk, (int) exk);
4637 if (uentry_hasSpecialClauses (v))
4639 return (message ("%q%q%q%q@%q@%q#%s",
4640 ctype_dump (v->utype),
4644 typeIdSet_dump (uentry_accessType (v)),
4645 specialClauses_dump (v->info->fcn->specclauses),
4650 return (message ("%q%q%q%q@%q#%s",
4651 ctype_dump (v->utype),
4655 typeIdSet_dump (uentry_accessType (v)),
4660 return (message ("%q@%q#%s",
4661 ctype_dump (v->utype),
4662 typeIdSet_dump (v->info->iter->access),
4665 return (message ("%q@%q#%s",
4666 ctype_dump (v->utype),
4667 typeIdSet_dump (uentry_accessType (v)),
4674 if (multiVal_isUnknown (v->info->uconst->val)
4675 && typeIdSet_isEmpty (uentry_accessType (v))
4676 && (sRef_getNullState (v->sref) == NS_UNKNOWN))
4678 sdump = cstring_makeLiteral ("$");
4682 sdump = message ("@%q@%q@%d",
4683 multiVal_dump (v->info->uconst->val),
4684 typeIdSet_dump (uentry_accessType (v)),
4685 (int) sRef_getNullState (v->sref));
4688 return (message ("%q%q#%s",
4689 ctype_dump (v->utype),
4696 return (message ("%q@%q#%s",
4697 ctype_dump (v->utype),
4698 ctype_dump (v->info->datatype->type), v->uname));
4705 uentry_unparseAbbrev (uentry v)
4707 if (!uentry_isVariable (v))
4709 llcontbuglit ("uentry_unparseAbbrev: not variable");
4710 return uentry_unparse (v);
4713 return (message ("%s %q", ctype_unparseDeep (v->utype), uentry_getName (v)));
4717 uentry_unparse (uentry v)
4721 if (uentry_isUndefined (v)) return (cstring_makeLiteral ("<undefined>"));
4722 if (uentry_isElipsisMarker (v)) return (cstring_makeLiteral ("..."));
4724 st = uentry_getName (v);
4726 if (cstring_isDefined (st))
4728 return (ctype_unparseDeclaration (v->utype, st));
4733 return (cstring_copy (ctype_unparse (v->utype)));
4738 uentry_unparseFull (uentry v)
4740 if (uentry_isUndefined (v))
4742 return (cstring_makeLiteral ("<undefined>"));
4744 else if (uentry_isDatatype (v))
4746 return (message ("[%d] [%s] %s %q : %t [%t] %s %s // %q [s: %q; d: %q]",
4748 ekind_unparse (v->ukind),
4752 ctype_isDefined (v->info->datatype->type)
4753 ? v->info->datatype->type : ctype_unknown,
4754 ynm_unparse (v->info->datatype->mut),
4755 ynm_unparse (v->info->datatype->abs),
4756 sRef_unparseState (v->sref),
4757 fileloc_unparse (v->whereSpecified),
4758 fileloc_unparse (v->whereDefined)));
4760 else if (uentry_isFunction (v))
4762 return (message ("[%w] = [%s] %q : %t / sref: %q / mods: %q / "
4763 "globs: %q / [s: %q; decl: %q; def: %q]",
4765 ekind_unparse (v->ukind),
4768 sRef_unparseFull (v->sref),
4769 sRefSet_unparse (v->info->fcn->mods),
4770 globSet_unparse (v->info->fcn->globs),
4771 fileloc_unparse (v->whereSpecified),
4772 fileloc_unparse (v->whereDeclared),
4773 fileloc_unparse (v->whereDefined)));
4775 else if (uentry_isIter (v))
4777 return (message ("[%s] %q: %t / %q [s: %q; d: %q]",
4778 ekind_unparse (v->ukind),
4781 sRef_unparseFull (v->sref),
4782 fileloc_unparse (v->whereSpecified),
4783 fileloc_unparse (v->whereDefined)));
4785 else if (uentry_isVariable (v))
4788 (message ("[check: %s] / [%w] = [%s] %s : %t %q [s: %q; def: %q; dec: %q] "
4789 "kind <%d> isout <%d> used <%d>",
4790 checkedName (v->info->var->checked),
4792 ekind_unparse (v->ukind),
4795 sRef_unparseDeep (v->sref),
4796 fileloc_unparse (v->whereSpecified),
4797 fileloc_unparse (v->whereDefined),
4798 fileloc_unparse (v->whereDeclared),
4799 (int) v->info->var->kind,
4800 (int) v->info->var->defstate,
4805 return (message ("[%s] %s : %t %q at [s: %q; d: %q]",
4806 ekind_unparse (v->ukind),
4809 sRef_unparseFull (v->sref),
4810 fileloc_unparse (v->whereSpecified),
4811 fileloc_unparse (v->whereDefined)));
4816 bool uentry_hasAccessType (uentry e)
4818 if (uentry_isValid (e))
4823 return (!typeIdSet_isEmpty (e->info->iter->access));
4825 return (!typeIdSet_isEmpty (e->info->enditer->access));
4827 return (!typeIdSet_isEmpty (e->info->fcn->access));
4830 return (!typeIdSet_isEmpty (e->info->uconst->access));
4839 typeIdSet uentry_accessType (uentry e)
4841 if (uentry_isValid (e))
4846 return (e->info->iter->access);
4848 return (e->info->enditer->access);
4850 return (e->info->fcn->access);
4853 return (e->info->uconst->access);
4859 return typeIdSet_undefined;
4863 uentry_isVariable (uentry e)
4865 return (uentry_isVar (e));
4869 uentry_isSpecified (uentry e)
4871 return (uentry_isValid (e) && !fileloc_isUndefined (e->whereSpecified));
4875 uentry_isReallySpecified (uentry e)
4877 return (uentry_isValid (e)
4878 && fileloc_isRealSpec (e->whereSpecified));
4882 uentry_isVar (uentry e)
4884 return (!uentry_isUndefined (e) && e->ukind == KVAR);
4888 uentry_isFakeTag (uentry e)
4890 return (uentry_isValid (e) && strchr (cstring_toCharsSafe (e->uname), '!') != 0);
4894 uentry_isDatatype (uentry e)
4896 return (!uentry_isUndefined (e) &&
4897 (e->ukind == KDATATYPE || e->ukind == KSTRUCTTAG ||
4898 e->ukind == KUNIONTAG || e->ukind == KENUMTAG));
4902 uentry_setAbstract (uentry e)
4906 llassert (uentry_isDatatype (e)
4907 && (ynm_isMaybe (e->info->datatype->abs)));
4909 oldid = ctype_typeId (e->info->datatype->type);
4910 e->info->datatype->abs = YES;
4911 e->info->datatype->type = ctype_createAbstract (oldid);
4915 uentry_setConcrete (uentry e)
4917 llassert (uentry_isDatatype (e)
4918 && (ynm_isMaybe (e->info->datatype->abs)));
4920 e->info->datatype->abs = NO;
4924 uentry_isAbstractDatatype (uentry e)
4926 return (uentry_isDatatype (e)
4927 && (ynm_isOn (e->info->datatype->abs)));
4931 uentry_isMaybeAbstract (uentry e)
4933 return (uentry_isDatatype (e)
4934 && (ynm_isMaybe (e->info->datatype->abs)));
4938 uentry_isMutableDatatype (uentry e)
4940 bool res = uentry_isDatatype (e)
4941 && (ynm_toBoolRelaxed (e->info->datatype->mut));
4947 uentry_isRefCountedDatatype (uentry e)
4949 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
4953 uentry_isParam (uentry u)
4955 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
4956 || u->info->var->kind == VKYIELDPARAM));
4960 uentry_isExpandedMacro (uentry u)
4962 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
4966 uentry_isSefParam (uentry u)
4968 return (uentry_isVariable (u)
4969 && (u->info->var->kind == VKSEFPARAM
4970 || u->info->var->kind == VKREFSEFPARAM
4971 || u->info->var->kind == VKSEFRETPARAM
4972 || u->info->var->kind == VKREFSEFRETPARAM));
4976 uentry_isRefParam (uentry u)
4978 return (uentry_isVariable (u)
4979 && (u->info->var->kind == VKREFPARAM
4980 || u->info->var->kind == VKREFYIELDPARAM
4981 || u->info->var->kind == VKREFSEFPARAM
4982 || u->info->var->kind == VKREFSEFRETPARAM));
4986 uentry_isAnyParam (uentry u)
4988 return (uentry_isVariable (u)
4989 && ((u->info->var->kind == VKPARAM)
4990 || (u->info->var->kind == VKSEFPARAM)
4991 || (u->info->var->kind == VKYIELDPARAM)
4992 || (u->info->var->kind == VKRETPARAM)
4993 || (u->info->var->kind == VKSEFRETPARAM)));
4997 uentry_getDefState (uentry u)
4999 if (uentry_isValid (u))
5001 return (sRef_getDefState (u->sref));
5005 return (SS_UNKNOWN);
5010 uentry_isOut (uentry u)
5012 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5013 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5017 uentry_isPartial (uentry u)
5019 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5020 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5024 uentry_isStateSpecial (uentry u)
5026 return ((uentry_isVariable (u)
5027 && (u->info->var->defstate == SS_SPECIAL))
5028 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5031 exitkind uentry_getExitCode (uentry ue)
5033 if (uentry_isFunction (ue))
5035 return ue->info->fcn->exitCode;
5044 uentry_nullPred (uentry u)
5046 llassert (uentry_isRealFunction (u));
5048 if (uentry_isFunction (u))
5050 return (u->info->fcn->nullPred);
5059 uentry_possiblyNull (uentry u)
5061 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5062 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5066 uentry_getAliasKind (uentry u)
5068 if (uentry_isValid (u))
5070 return (sRef_getAliasKind (uentry_getSref (u)));
5079 uentry_getExpKind (uentry u)
5081 if (uentry_isValid (u))
5083 return (sRef_getExKind (uentry_getSref (u)));
5092 uentry_isIter (uentry e)
5094 return (!uentry_isUndefined (e) && e->ukind == KITER);
5098 uentry_isEndIter (uentry e)
5100 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5104 uentry_isRealFunction (uentry e)
5106 return (uentry_isFunction (e) ||
5107 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5111 uentry_hasName (uentry e)
5113 if (uentry_isValid (e))
5115 cstring s = e->uname;
5117 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")));
5125 bool uentry_hasRealName (uentry e)
5127 return (uentry_isValid (e) && cstring_isNonEmpty (e->uname));
5131 /*@observer@*/ globSet
5132 uentry_getGlobs (uentry l)
5134 if (uentry_isInvalid (l))
5136 return globSet_undefined;
5139 if (l->ukind != KFCN)
5141 if (l->ukind != KITER && l->ukind != KENDITER)
5143 if (l->ukind == KVAR)
5145 llbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
5147 ekind_unparse (l->ukind)));
5151 llbug (message ("Bad call to uentry_getGlobs: %q (%s)",
5153 ekind_unparse (l->ukind)));
5156 return globSet_undefined;
5159 return l->info->fcn->globs;
5162 /*@observer@*/ sRefSet
5163 uentry_getMods (uentry l)
5165 llassert (uentry_isValid (l));
5167 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5169 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5170 return sRefSet_undefined;
5173 return l->info->fcn->mods;
5177 uentry_getKind (uentry e)
5179 llassert (uentry_isValid (e));
5184 /*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5186 llassert (uentry_isEitherConstant (e));
5188 return (e->info->uconst->val);
5191 /*@observer@*/ uentryList
5192 uentry_getParams (uentry l)
5194 if (uentry_isInvalid (l)) return uentryList_undefined;
5201 ctype ct = l->utype;
5203 if (ctype_isFunction (ct))
5205 return (ctype_argsFunction (ct));
5209 return uentryList_undefined;
5214 ctype ct = l->utype;
5216 llassert (ctype_isFunction (ct));
5217 return (ctype_argsFunction (ct));
5224 /*@observer@*/ cstring
5225 uentry_rawName (uentry e)
5227 if (uentry_isValid (e))
5233 return cstring_undefined;
5238 uentry_getOptName (uentry e)
5240 cstring s = uentry_getName (e);
5242 if (cstring_isDefined (s))
5244 s = cstring_appendChar (s, ' ');
5251 uentry_getName (uentry e)
5253 cstring ret = cstring_undefined;
5255 if (uentry_isValid (e))
5258 if (uentry_isAnyTag (e))
5260 ret = fixTagName (e->uname);
5262 else if (uentry_isAnyParam (e))
5264 ret = cstring_copy (fixParamName (e->uname));
5268 ret = cstring_copy (e->uname);
5275 cstring uentry_getRealName (uentry e)
5277 if (uentry_isValid (e))
5279 if (uentry_isAnyTag (e))
5281 return (cstring_undefined);
5288 return cstring_undefined;
5291 ctype uentry_getType (uentry e)
5293 if (uentry_isValid (e))
5299 return ctype_unknown;
5303 fileloc uentry_whereLast (uentry e)
5307 if (uentry_isInvalid (e))
5309 return fileloc_undefined;
5312 loc = e->whereDefined;
5314 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5319 loc = uentry_whereDeclared (e);
5321 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5326 loc = uentry_whereSpecified (e);
5330 fileloc uentry_whereEither (uentry e)
5332 if (uentry_isInvalid (e)) return fileloc_undefined;
5334 if (fileloc_isDefined (e->whereDefined)
5335 && !fileloc_isExternal (e->whereDefined))
5337 return e->whereDefined;
5339 else if (fileloc_isDefined (e->whereDeclared))
5341 return e->whereDeclared;
5345 return e->whereSpecified;
5349 fileloc uentry_whereSpecified (uentry e)
5351 if (uentry_isInvalid (e)) return fileloc_undefined;
5353 return (e->whereSpecified);
5356 fileloc uentry_whereDefined (uentry e)
5358 if (uentry_isInvalid (e)) return fileloc_undefined;
5360 return (e->whereDefined);
5363 fileloc uentry_whereDeclared (uentry e)
5365 if (uentry_isInvalid (e)) return fileloc_undefined;
5367 return (e->whereDeclared);
5370 /*@observer@*/ fileloc
5371 uentry_whereEarliest (uentry e)
5373 if (uentry_isInvalid (e)) return fileloc_undefined;
5375 if (fileloc_isDefined (e->whereSpecified))
5377 return (e->whereSpecified);
5379 else if (fileloc_isDefined (e->whereDeclared))
5381 return (e->whereDeclared);
5385 return e->whereDefined;
5390 uentry_setFunctionDefined (uentry e, fileloc loc)
5392 if (uentry_isValid (e))
5394 llassert (uentry_isFunction (e));
5396 if (fileloc_isUndefined (e->whereDeclared))
5398 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
5401 if (!fileloc_isDefined (e->whereDefined))
5403 e->whereDefined = fileloc_update (e->whereDefined, loc);
5409 uentry_setDeclDef (uentry e, fileloc f)
5411 uentry_setDeclared (e, f);
5413 if (!uentry_isFunction (e)
5414 && !(uentry_isVariable (e) && uentry_isExtern (e)))
5416 uentry_setDefined (e, f);
5421 uentry_setDeclaredForce (uentry e, fileloc f)
5423 llassert (uentry_isValid (e));
5424 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5428 uentry_setDeclaredForceOnly (uentry e, fileloc f)
5430 llassert (uentry_isValid (e));
5431 fileloc_free (e->whereDeclared);
5432 e->whereDeclared = f;
5436 uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
5440 llassert (uentry_isValid (e));
5441 oldloc = e->whereDeclared;
5443 if (fileloc_isDefined (oldloc))
5445 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
5447 e->whereDeclared = f;
5448 fileloc_free (oldloc);
5457 e->whereDeclared = f;
5458 fileloc_free (oldloc);
5463 uentry_setDeclared (uentry e, fileloc f)
5467 llassert (uentry_isValid (e));
5468 oldloc = e->whereDeclared;
5470 if (fileloc_isDefined (oldloc))
5472 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
5474 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5483 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5488 uentry_clearDefined (uentry e)
5490 if (uentry_isValid (e))
5492 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
5497 uentry_setDefined (uentry e, fileloc f)
5501 llassert (uentry_isValid (e));
5502 oldloc = e->whereDefined;
5504 if (fileloc_isDefined (oldloc))
5506 if (fileloc_isLib (oldloc)
5507 || fileloc_isImport (oldloc)
5508 || fileloc_isBuiltin (oldloc)
5509 || fileloc_isPreproc (oldloc))
5511 e->whereDefined = fileloc_update (e->whereDefined, f);
5515 if (fileloc_equal (oldloc, f) || context_processingMacros ())
5521 if (optgenerror (FLG_REDEF,
5522 message ("%s %q redefined",
5523 ekind_capName (e->ukind),
5524 uentry_getName (e)),
5527 llgenindentmsg (message ("Previous definition of %q",
5528 uentry_getName (e)),
5536 e->whereDefined = fileloc_update (e->whereDefined, f);
5541 uentry_isCodeDefined (uentry e)
5543 return (uentry_isValid (e) && fileloc_isDefined (e->whereDefined));
5547 uentry_isDeclared (uentry e)
5549 if (uentry_isValid (e))
5551 return (fileloc_isDefined (e->whereDeclared));
5557 sRef uentry_getSref (uentry e)
5559 /* not true, used for functions too (but shouldn't be? */
5560 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
5562 if (uentry_isInvalid (e)) return sRef_undefined;
5567 sRef uentry_getOrigSref (uentry e)
5569 if (uentry_isValid (e))
5571 sRef sr = sRef_copy (uentry_getSref (e));
5573 sRef_resetState (sr);
5574 sRef_clearDerived (sr);
5576 if (uentry_isVariable (e))
5578 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
5579 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
5586 return sRef_undefined;
5591 ** requires: uentry e is not in a hashed symbol table
5595 uentry_setName (uentry e, /*@only@*/ cstring n)
5597 llassert (uentry_isValid (e));
5599 cstring_free (e->uname);
5604 uentry_setType (uentry e, ctype t)
5606 if (uentry_isValid (e))
5609 sRef_setType (e->sref, t);
5614 uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
5617 ctype rettype = ctype_unknown;
5619 llassert (uentry_isValid (ue));
5621 rct = ctype_realType (ue->utype);
5623 if (uentry_isVariable (ue) && (ctype_isFunction (rct) || ctype_isUnknown (rct)))
5625 uentry_makeVarFunction (ue);
5628 llassert (uentry_isFunction (ue));
5630 if (ctype_isFunction (rct))
5632 rettype = ctype_returnValue (rct);
5635 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
5639 uentry_setRefParam (uentry e)
5642 if (!uentry_isVar (e))
5644 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
5648 if (e->info->var->kind == VKSEFPARAM)
5650 e->info->var->kind = VKREFSEFPARAM;
5652 else if (e->info->var->kind == VKSEFRETPARAM)
5654 e->info->var->kind = VKREFSEFRETPARAM;
5656 else if (e->info->var->kind == VKYIELDPARAM)
5658 e->info->var->kind = VKREFYIELDPARAM;
5662 e->info->var->kind = VKREFPARAM;
5668 uentry_setParam (uentry e)
5670 if (!uentry_isVar (e))
5672 if (uentry_isElipsisMarker (e))
5678 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
5685 if (e->info->var->kind == VKYIELDPARAM
5686 || e->info->var->kind == VKSEFPARAM
5687 || e->info->var->kind == VKSEFRETPARAM)
5693 e->info->var->kind = VKPARAM;
5697 e->uname = makeParam (e->uname);
5698 cstring_free (oldname);
5703 uentry_setSref (uentry e, sRef s)
5705 if (uentry_isValid (e))
5707 if (sRef_isValid (e->sref))
5709 sRef_mergeStateQuietReverse (e->sref, s);
5713 e->sref = sRef_saveCopy (s);
5719 uentry_getAbstractType (uentry e)
5721 llassert (uentry_isDatatype (e));
5724 ** This assertion removed.
5725 ** Okay to have undefined type, for system types
5727 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
5728 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
5733 if (ctype_isUndefined (e->info->datatype->type))
5735 return ctype_unknown;
5739 ** Sadly, a kludge...
5742 if (ctype_isUserBool (e->info->datatype->type)) {
5746 return e->info->datatype->type;
5749 ctype uentry_getRealType (uentry e)
5752 typeId uid = USYMIDINVALID;
5754 if (uentry_isInvalid (e))
5756 return ctype_unknown;
5759 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
5761 if (uentry_isAnyTag (e))
5766 if (uentry_isAbstractType (e))
5768 ct = uentry_getAbstractType (e);
5770 if (ctype_isManifestBool (ct)) {
5774 llassert (ctype_isUA (ct));
5776 uid = ctype_typeId (ct);
5778 if (!context_hasAccess (uid))
5784 ct = uentry_getType (e);
5786 /* if (ctype_isUserBool (ct)) return ct; */
5788 if (ctype_isManifestBool (ct)) {
5792 if (ctype_isUA (ct))
5794 usymId iid = ctype_typeId (ct);
5796 if /*@access usymId@*/ (iid == uid) /*@noaccess usymId@*/
5798 llcontbug (message ("uentry_getRealType: recursive type! %s",
5799 ctype_unparse (ct)));
5804 /* evs 2000-07-25: possible infinite recursion ? */
5805 uentry ue2 = usymtab_getTypeEntry (iid);
5806 llassertprint (ue2 != e, ("Bad recursion: %s", uentry_unparseFull (e)));
5808 return uentry_getRealType (ue2);
5817 ctype uentry_getForceRealType (uentry e)
5820 typeId uid = USYMIDINVALID;
5822 if (uentry_isInvalid (e))
5824 return ctype_unknown;
5827 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
5829 if (uentry_isAnyTag (e))
5834 if (uentry_isAbstractType (e))
5836 ct = uentry_getAbstractType (e);
5837 llassert (ctype_isUA (ct));
5839 uid = ctype_typeId (ct);
5840 /* no check for access! */
5843 ct = uentry_getType (e);
5845 /* evs 2000-07-25 */
5846 /* if (ctype_isUserBool (ct)) return ct; */
5848 if (ctype_isManifestBool (ct)) {
5852 if (ctype_isUA (ct))
5854 usymId iid = ctype_typeId (ct);
5856 if /*@access usymId@*/ (iid == uid) /*@noaccess usymId@*/
5858 llcontbug (message ("uentry_getRealType: recursive type! %s",
5859 ctype_unparse (ct)));
5864 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
5873 uentry uentry_nameCopy (cstring name, uentry e)
5875 uentry enew = uentry_alloc ();
5877 llassert (uentry_isValid (e));
5879 /* enew->shallowCopy = FALSE; */
5880 enew->ukind = e->ukind;
5882 enew->utype = e->utype;
5883 enew->whereSpecified = fileloc_copy (e->whereSpecified);
5884 enew->whereDefined = fileloc_copy (e->whereDefined);
5885 enew->whereDeclared = fileloc_copy (e->whereDeclared);
5886 enew->sref = sRef_copy (e->sref);
5887 enew->used = e->used;
5889 enew->isPrivate = e->isPrivate;
5890 enew->hasNameError = FALSE;
5892 enew->uses = filelocList_new ();
5894 enew->storageclass = e->storageclass;
5895 enew->info = uinfo_copy (e->info, e->ukind);
5901 uentry_setDatatype (uentry e, usymId uid)
5903 llassert (uentry_isDatatype (e));
5905 if (uentry_isAbstractType (e))
5907 e->info->datatype->type = ctype_createAbstract (uid);
5911 e->info->datatype->type = ctype_createUser (uid);
5916 uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
5917 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
5920 llassert (uentry_isValid (e));
5922 if (fileloc_isSpec (f) || fileloc_isImport (f))
5924 e->whereSpecified = f;
5925 e->whereDeclared = fileloc_undefined;
5926 e->whereDefined = fileloc_undefined;
5930 e->whereSpecified = fileloc_undefined;
5931 e->whereDeclared = f;
5932 e->whereDefined = fileloc_undefined;
5937 ucinfo_free (/*@only@*/ ucinfo u)
5939 multiVal_free (u->val);
5944 uvinfo_free (/*@only@*/ uvinfo u)
5950 udinfo_free (/*@only@*/ udinfo u)
5956 ufinfo_free (/*@only@*/ ufinfo u)
5958 globSet_free (u->globs);
5959 sRefSet_free (u->mods);
5960 specialClauses_free (u->specclauses);
5966 uiinfo_free (/*@only@*/ uiinfo u)
5972 ueinfo_free (/*@only@*/ ueinfo u)
5977 static /*@only@*/ ucinfo
5978 ucinfo_copy (ucinfo u)
5980 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
5982 ret->val = multiVal_copy (u->val);
5983 ret->access = u->access;
5988 static /*@only@*/ uvinfo
5989 uvinfo_copy (uvinfo u)
5991 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
5993 ret->kind = u->kind;
5994 ret->nullstate = u->nullstate;
5995 ret->defstate = u->defstate;
5996 ret->checked = u->checked;
5998 //ret->bufinfo = u->bufinfo;
5999 /*@i334@*/ return ret;
6002 static /*@only@*/ udinfo
6003 udinfo_copy (udinfo u)
6005 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6009 ret->type = u->type;
6014 static /*@only@*/ ufinfo
6015 ufinfo_copy (ufinfo u)
6017 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6019 ret->hasGlobs = u->hasGlobs;
6020 ret->hasMods = u->hasMods;
6021 ret->exitCode = u->exitCode;
6022 ret->specialCode = u->specialCode;
6023 ret->nullPred = u->nullPred;
6024 ret->access = u->access;
6025 ret->globs = globSet_newCopy (u->globs);
6026 ret->mods = sRefSet_newCopy (u->mods);
6027 ret->defparams = u->defparams;
6028 ret->specclauses = specialClauses_copy (u->specclauses);
6031 ret->preconditions = u->preconditions? constraintList_copy(u->preconditions): NULL;
6036 ret->postconditions = u->postconditions? constraintList_copy(u->postconditions): NULL;
6042 static /*@only@*/ uiinfo
6043 uiinfo_copy (uiinfo u)
6045 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6047 ret->access = u->access;
6048 ret->globs = globSet_newCopy (u->globs);
6049 ret->mods = sRefSet_newCopy (u->mods);
6054 static /*@only@*/ ueinfo
6055 ueinfo_copy (ueinfo u)
6057 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6059 ret->access = u->access;
6064 uinfo_free (uinfo u, ekind kind)
6069 case KCONST: ucinfo_free (u->uconst); break;
6070 case KVAR: uvinfo_free (u->var); break;
6074 case KDATATYPE: udinfo_free (u->datatype); break;
6075 case KFCN: ufinfo_free (u->fcn); break;
6076 case KITER: uiinfo_free (u->iter); break;
6077 case KENDITER: ueinfo_free (u->enditer); break;
6078 case KELIPSMARKER: break;
6079 case KINVALID: break;
6085 static /*@only@*/ /*@null@*/ uinfo
6086 uinfo_copy (uinfo u, ekind kind)
6088 if (kind == KELIPSMARKER || kind == KINVALID)
6094 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6099 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6100 case KVAR: ret->var = uvinfo_copy (u->var); break;
6104 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6105 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6106 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6107 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6115 uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6117 filelocList_free (e->uses);
6118 cstring_free (e->uname);
6120 uinfo_free (e->info, e->ukind);
6122 fileloc_free (e->whereSpecified);
6123 fileloc_free (e->whereDefined);
6124 fileloc_free (e->whereDeclared);
6130 extern void uentry_markOwned (/*@owned@*/ uentry u)
6132 sfreeEventually (u);
6136 uentry_free (/*@only@*/ uentry e)
6138 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6140 uentry_reallyFree (e);
6145 ** For uentry's in the global or file scope
6149 uentry_freeComplete (/*@only@*/ uentry e)
6151 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6153 /*@i@*/ sRef_free (e->sref);
6154 e->sref = sRef_undefined;
6155 uentry_reallyFree (e);
6160 ** requires old->kind != new->kind, old->uname = new->uname
6164 KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6166 llassert (uentry_isValid (old));
6167 llassert (uentry_isValid (unew));
6169 if (uentry_isEitherConstant (unew)
6170 && (fileloc_isPreproc (uentry_whereDeclared (old))
6171 || ctype_isUnknown (old->utype))
6172 && !uentry_isSpecified (old))
6180 if (!uentry_isDeclared (old))
6182 if (uentry_isSpecified (old))
6184 if (uentry_isSpecified (unew))
6186 llbuglit ("Respecification!");
6188 else if (uentry_isDeclared (unew))
6192 message ("%s %q inconsistently declared as %s: %t",
6193 ekind_capName (old->ukind),
6194 uentry_getName (unew),
6195 ekind_unparseLong (unew->ukind),
6197 uentry_whereDeclared (unew)))
6199 uentry_showWhereLast (old);
6211 message ("%s %q inconsistently declared as %s: %t",
6212 ekind_capName (old->ukind),
6213 uentry_getName (unew),
6214 ekind_unparseLong (unew->ukind),
6216 uentry_whereDeclared (unew)))
6218 uentry_showWhereLast (old);
6224 llassert (uentry_isDeclared (unew));
6228 message ("%s %q inconsistently redeclared as %s",
6229 ekind_capName (old->ukind),
6230 uentry_getName (unew),
6231 ekind_unparseLong (unew->ukind)),
6232 uentry_whereDeclared (unew)))
6234 uentry_showWhereLast (old);
6240 uentry_copyInto (old, unew);
6244 ** def is the definition of spec, modifies spec
6246 ** reports any inconsistencies
6247 ** returns the summary of all available information
6248 ** if spec and def are inconsistent, def is returned
6252 uentry_showWhereLast (uentry spec)
6254 if (uentry_isValid (spec))
6256 if (fileloc_isDefined (spec->whereDefined)
6257 && !fileloc_isLib (spec->whereDefined)
6258 && !fileloc_isPreproc (spec->whereDefined))
6260 llgenindentmsg (message ("Previous definition of %q: %t",
6261 uentry_getName (spec),
6262 uentry_getType (spec)),
6263 uentry_whereDefined (spec));
6265 else if (uentry_isDeclared (spec))
6267 llgenindentmsg (message ("Previous declaration of %q: %t",
6268 uentry_getName (spec),
6269 uentry_getType (spec)),
6270 uentry_whereDeclared (spec));
6272 else if (uentry_isSpecified (spec))
6274 if (uentry_hasName (spec))
6276 llgenindentmsg (message ("Specification of %q: %t",
6277 uentry_getName (spec),
6278 uentry_getType (spec)),
6279 uentry_whereSpecified (spec));
6283 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
6284 uentry_whereSpecified (spec));
6289 /* nothing to show */
6295 uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
6297 fileloc loc = uentry_whereDefined (ce);
6299 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6301 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
6305 loc = uentry_whereSpecified (ce);
6307 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6309 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
6314 void uentry_showWhereLastExtra (uentry spec, cstring extra)
6316 if (uentry_isDeclared (spec))
6318 llgenindentmsg (message ("Previous declaration of %q: %q",
6319 uentry_getName (spec), extra),
6320 uentry_whereDeclared (spec));
6322 else if (uentry_isSpecified (spec))
6324 llgenindentmsg (message ("Specification of %q: %q",
6325 uentry_getName (spec), extra),
6326 uentry_whereSpecified (spec));
6330 cstring_free (extra);
6335 uentry_showWhereDeclared (uentry spec)
6337 if (uentry_isDeclared (spec))
6339 if (uentry_hasName (spec))
6341 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6342 uentry_whereDeclared (spec));
6346 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6349 else if (uentry_isSpecified (spec))
6351 if (uentry_hasName (spec))
6353 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6354 uentry_whereSpecified (spec));
6358 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
6363 /* nothing to show */
6369 uentry_showWhereAny (uentry spec)
6371 if (uentry_isDeclared (spec))
6373 if (uentry_hasName (spec))
6375 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6376 uentry_whereDeclared (spec));
6380 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6383 else if (uentry_isSpecified (spec))
6385 if (uentry_hasName (spec))
6387 llgenindentmsg (message ("Specification of %q",
6388 uentry_getName (spec)),
6389 uentry_whereSpecified (spec));
6393 llgenindentmsg (cstring_makeLiteral ("Specification"),
6394 uentry_whereSpecified (spec));
6397 else if (fileloc_isDefined (uentry_whereDefined (spec)))
6399 if (uentry_hasName (spec))
6401 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
6402 uentry_whereDefined (spec));
6406 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
6411 /* nothing to show */
6416 uentry_showWhereDefined (uentry spec)
6418 if (uentry_isCodeDefined (spec))
6420 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
6421 uentry_whereDefined (spec));
6426 uentry_showWhereLastPlain (uentry spec)
6428 if (uentry_isDeclared (spec))
6430 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
6431 uentry_whereDeclared (spec));
6433 else if (uentry_isSpecified (spec))
6435 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6436 uentry_whereSpecified (spec));
6444 uentry_showWhereLastVal (uentry spec, cstring val)
6446 if (uentry_isDeclared (spec))
6448 llgenindentmsg (message ("Previous declaration of %q: %s",
6449 uentry_getName (spec), val),
6450 uentry_whereDeclared (spec));
6452 else if (uentry_isSpecified (spec))
6454 llgenindentmsg (message ("Specification of %q: %s",
6455 uentry_getName (spec), val),
6456 uentry_whereSpecified (spec));
6464 uentry_showWhereSpecified (uentry spec)
6466 if (uentry_isSpecified (spec))
6468 if (uentry_hasName (spec))
6470 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6471 uentry_whereSpecified (spec));
6475 llgenindentmsg (cstring_makeLiteral ("Specification"),
6476 uentry_whereSpecified (spec));
6479 else if (uentry_isDeclared (spec))
6481 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6482 uentry_whereDeclared (spec));
6486 /* nothing to show */
6491 uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
6493 if (uentry_isSpecified (spec))
6495 if (uentry_hasName (spec))
6497 llgenindentmsg (message ("Specification of %q: %q",
6498 uentry_getName (spec), s),
6499 uentry_whereSpecified (spec));
6503 llgenindentmsg (message ("Specification: %q", s),
6504 uentry_whereSpecified (spec));
6507 else if (uentry_isDeclared (spec))
6509 llgenindentmsg (message ("Declaration of %q: %q",
6510 uentry_getName (spec), s),
6511 uentry_whereDeclared (spec));
6515 llgenindentmsg (message ("Previous: %q", s),
6516 uentry_whereLast (spec));
6525 checkStructConformance (uentry old, uentry unew)
6528 uentryList fold, fnew;
6531 ** requires: types of old and new are structs or unions
6534 llassert (uentry_isValid (old));
6535 llassert (uentry_isValid (unew));
6537 oldr = ctype_realType (old->utype);
6538 fold = ctype_getFields (oldr);
6540 newr = ctype_realType (unew->utype);
6541 fnew = ctype_getFields (newr);
6543 if (!uentryList_matchFields (fold, fnew))
6545 if (fileloc_equal (uentry_whereLast (old),
6546 uentry_whereLast (unew)))
6554 message ("%q %q %rdeclared with fields { %q }, %s "
6555 "with fields { %q }",
6556 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
6557 uentry_getName (old),
6558 uentry_isDeclared (old),
6559 uentryList_unparseAbbrev (fnew),
6560 uentry_specOrDefName (old),
6561 uentryList_unparseAbbrev (fold)),
6562 uentry_whereDeclared (unew)))
6564 uentry_showWhereLastPlain (old);
6565 uentryList_showFieldDifference (fold, fnew);
6569 old->utype = unew->utype;
6574 checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
6577 ** requires old and new are enums
6580 ctype rold = ctype_realType (old->utype);
6581 ctype rnew = ctype_realType (unew->utype);
6582 enumNameList eold = ctype_elist (rold);
6583 enumNameList enew = ctype_elist (rnew);
6585 if (!enumNameList_match (eold, enew))
6589 message ("Enum %q declared with members { %q } but "
6590 "specified with members { %q }",
6591 uentry_getName (old),
6592 enumNameList_unparse (enew),
6593 enumNameList_unparse (eold)),
6594 uentry_whereDeclared (unew)))
6596 uentry_showWhereSpecified (old);
6597 old->utype = unew->utype;
6603 ** either oldCurrent or newCurrent may be undefined!
6607 paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
6608 uentry unew, uentry newCurrent, ctype newType,
6611 bool hasError = FALSE;
6613 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
6615 if (uentry_hasName (newCurrent))
6617 hasError = optgenerror
6619 message ("Parameter %d, %q, of function %q has inconsistent type: "
6620 "declared %t, %s %t",
6621 paramno + 1, uentry_getName (newCurrent),
6622 uentry_getName (unew),
6623 newType, uentry_specOrDefName (old), oldType),
6624 uentry_whereDeclared (newCurrent));
6628 hasError = optgenerror
6630 message ("Parameter %d of function %q has inconsistent type: "
6631 "declared %t, %s %t",
6632 paramno + 1, uentry_getName (unew),
6633 newType, uentry_specOrDefName (old), oldType),
6634 uentry_whereDeclared (newCurrent));
6636 DPRINTF (("type: %s / %s",
6637 ctype_unparse (newType),
6638 ctype_unparse (ctype_realType (newType))));
6643 if (uentry_isDeclared (unew))
6645 hasError = optgenerror
6647 message ("Parameter %d of function %s has inconsistent type: "
6648 "declared %t, %s %t",
6649 paramno + 1, unew->uname,
6650 newType, uentry_specOrDefName (old), oldType),
6651 uentry_whereDeclared (unew));
6655 hasError = optgenerror
6657 message ("Parameter %d of function %s has inconsistent type: "
6658 "declared %t, %s %t",
6659 paramno + 1, unew->uname,
6660 newType, uentry_specOrDefName (old), oldType),
6661 uentry_whereDeclared (unew));
6667 if (!uentry_isUndefined (oldCurrent))
6669 if (!uentry_isUndefined (newCurrent)
6670 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
6672 uentry_showWhereLast (oldCurrent);
6676 uentry_showWhereLastPlain (old);
6679 uentry_setType (oldCurrent, newType);
6683 uentry_showWhereLastPlain (old);
6689 nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
6693 message ("Function %s %rdeclared with %d arg%p, %s with %d",
6695 uentry_isDeclared (old),
6696 uentryList_size (uentry_getParams (unew)),
6697 uentry_specOrDefName (old),
6698 uentryList_size (uentry_getParams (old))),
6699 uentry_whereDeclared (unew)))
6701 uentry_showWhereLastPlain (old);
6706 returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
6710 message ("Function %s inconsistently %rdeclared to return %t",
6712 uentry_isDeclared (old),
6713 ctype_returnValue (unew->utype)),
6714 uentry_whereDeclared (unew)))
6716 uentry_showWhereLastVal (old, ctype_unparse (ctype_returnValue (old->utype)));
6720 static cstring paramStorageName (uentry ue)
6722 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
6725 static cstring fcnErrName (uentry ue)
6727 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
6730 extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
6732 if (uentry_isVar (ue))
6734 return (checkedName (ue->info->var->checked));
6738 return (cstring_makeLiteralTemp ("<checked invalid>"));
6742 static cstring checkedName (chkind checked)
6746 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
6747 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
6748 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
6749 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
6750 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
6756 void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
6761 if (uentry_isVar (unew))
6763 llassert (uentry_isVar (old));
6765 oldState = old->info->var->nullstate;
6766 newState = unew->info->var->nullstate;
6770 oldState = sRef_getNullState (old->sref);
6771 newState = sRef_getNullState (unew->sref);
6774 if (oldState == NS_ABSNULL)
6776 if (uentry_isVar (old))
6778 old->info->var->nullstate = newState;
6781 sRef_mergeNullState (old->sref, newState);
6783 else if (newState == NS_UNKNOWN)
6785 if (completeConform && newState != oldState
6786 && uentry_isReallySpecified (old))
6790 message ("%s %q specified as %s, but declared without %s qualifier",
6791 ekind_capName (unew->ukind),
6792 uentry_getName (unew),
6793 nstate_unparse (oldState),
6794 nstate_unparse (oldState)),
6795 uentry_whereDeclared (unew)))
6797 uentry_showWhereSpecified (old);
6801 if (uentry_isVar (unew))
6803 unew->info->var->nullstate = oldState;
6806 sRef_mergeNullState (unew->sref, oldState);
6808 else if (newState == NS_POSNULL)
6810 if (oldState == NS_MNOTNULL
6811 && (ctype_isUA (unew->utype)
6812 || (uentry_isFunction (unew)
6813 && ctype_isUA (ctype_returnValue (unew->utype)))))
6815 if (uentry_isVar (unew))
6817 unew->info->var->nullstate = oldState;
6820 sRef_mergeNullState (unew->sref, oldState);
6824 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
6825 || oldState == NS_UNKNOWN)
6832 ("%s %q inconsistently %rdeclared %s possibly null storage, "
6834 uentry_ekindName (unew),
6835 uentry_getName (unew),
6836 uentry_isDeclared (old),
6838 uentry_specOrDefName (old),
6839 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
6840 uentry_whereDeclared (unew)))
6842 uentry_showWhereSpecified (old);
6847 if (uentry_isVar (old))
6849 old->info->var->nullstate = newState;
6852 sRef_mergeNullState (old->sref, newState);
6855 else if (newState == NS_MNOTNULL)
6857 if (oldState != NS_MNOTNULL)
6863 message ("%s %q inconsistently %rdeclared %s notnull storage, "
6864 "%s without notnull qualifier",
6865 uentry_ekindName (unew),
6866 uentry_getName (unew),
6867 uentry_isDeclared (old),
6869 uentry_specOrDefName (old)),
6870 uentry_whereDeclared (unew)))
6872 uentry_showWhereSpecified (old);
6876 if (uentry_isVar (old))
6878 old->info->var->nullstate = newState;
6881 sRef_mergeNullState (old->sref, newState);
6886 if (uentry_isVar (unew))
6888 unew->info->var->nullstate = oldState;
6891 sRef_mergeNullState (unew->sref, oldState);
6896 void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
6897 bool mustConform, bool completeConform)
6903 if (uentry_isVar (old) && uentry_isVar (unew))
6905 oldState = old->info->var->defstate;
6906 newState = unew->info->var->defstate;
6911 oldState = sRef_getDefState (old->sref);
6912 newState = sRef_getDefState (unew->sref);
6915 if (newState != oldState && newState != SS_UNKNOWN && newState != SS_DEFINED)
6921 message ("%s %q inconsistently %rdeclared %s %s %s, "
6923 uentry_ekindName (unew),
6924 uentry_getName (unew),
6925 uentry_isDeclared (old),
6927 sstate_unparse (newState),
6928 paramStorageName (unew),
6929 uentry_specOrDefName (old),
6931 sstate_unparse (oldState),
6932 paramStorageName (unew)),
6933 uentry_whereDeclared (unew)))
6935 uentry_showWhereSpecified (old);
6939 if (vars) old->info->var->defstate = newState;
6940 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
6945 && (newState != oldState) && (oldState != SS_DEFINED)
6946 && uentry_isReallySpecified (old))
6950 message ("%s %q specified as %s, but declared without %s qualifier",
6951 ekind_capName (unew->ukind),
6952 uentry_getName (unew),
6953 sstate_unparse (oldState),
6954 sstate_unparse (oldState)),
6955 uentry_whereDeclared (unew)))
6957 uentry_showWhereSpecified (old);
6961 if (vars) unew->info->var->defstate = oldState;
6962 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
6967 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
6968 bool mustConform, bool completeConform)
6973 oldKind = sRef_getAliasKind (old->sref);
6974 newKind = sRef_getAliasKind (unew->sref);
6976 if (alkind_isImplicit (newKind)
6977 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
6979 if (completeConform && !alkind_equal (newKind, oldKind)
6980 && uentry_isReallySpecified (old))
6984 message ("%s %q specified as %s, but declared without "
6985 "explicit alias qualifier",
6986 ekind_capName (unew->ukind),
6987 uentry_getName (unew),
6988 alkind_unparse (oldKind)),
6989 uentry_whereDeclared (unew)))
6991 uentry_showWhereSpecified (old);
6996 ** This really shouldn't be necessary, but it is!
6997 ** Function params (?) use new here.
7000 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7004 if (alkind_isKnown (newKind))
7006 if (!alkind_equal (oldKind, newKind))
7008 if (alkind_isKnown (oldKind))
7013 message ("%s %q inconsistently %rdeclared %s %s storage, "
7015 uentry_ekindName (unew),
7016 uentry_getName (unew),
7017 uentry_isDeclared (old),
7019 alkind_unparse (newKind),
7020 uentry_specOrDefName (old),
7021 alkind_unparse (oldKind)),
7022 uentry_whereDeclared (unew)))
7024 uentry_showWhereSpecified (old);
7026 sRef_setAliasKind (old->sref, AK_ERROR,
7027 uentry_whereDeclared (unew));
7031 sRef_setAliasKind (old->sref, newKind,
7032 uentry_whereDeclared (unew));
7037 if (!(alkind_isImplicit (newKind)))
7040 !uentry_isFunction (unew) &&
7043 message ("%s %q inconsistently %rdeclared %s %s storage, "
7044 "implicitly %s as temp storage",
7045 uentry_ekindName (unew),
7046 uentry_getName (unew),
7047 uentry_isDeclared (old),
7049 alkind_unparse (newKind),
7050 uentry_specOrDefName (old)),
7051 uentry_whereDeclared (unew)))
7053 uentry_showWhereSpecified (old);
7057 sRef_setAliasKind (old->sref, newKind,
7058 uentry_whereDeclared (unew));
7060 else /* newKind is temp or refcounted */
7067 else /* newKind unknown */
7074 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7075 bool mustConform, bool completeConform)
7080 oldKind = sRef_getExKind (old->sref);
7081 newKind = sRef_getExKind (unew->sref);
7083 if (exkind_isKnown (newKind))
7085 if (oldKind != newKind)
7087 if (exkind_isKnown (oldKind))
7092 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7093 uentry_ekindName (unew),
7094 uentry_getName (unew),
7095 uentry_isDeclared (old),
7097 exkind_unparse (newKind),
7098 uentry_specOrDefName (old),
7099 exkind_unparse (oldKind)),
7100 uentry_whereDeclared (unew)))
7102 uentry_showWhereSpecified (old);
7105 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7112 message ("%s %q inconsistently %rdeclared %s %s, "
7113 "implicitly %s without exposure qualifier",
7114 uentry_ekindName (unew),
7115 uentry_getName (unew),
7116 uentry_isDeclared (old),
7118 exkind_unparse (newKind),
7119 uentry_specOrDefName (old)),
7120 uentry_whereDeclared (unew)))
7122 uentry_showWhereSpecified (old);
7125 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7131 if (completeConform && exkind_isKnown (oldKind)
7132 && uentry_isReallySpecified (old))
7136 message ("%s %q specified as %s, but declared without "
7137 "exposure qualifier",
7138 ekind_capName (unew->ukind),
7139 uentry_getName (unew),
7140 exkind_unparse (oldKind)),
7141 uentry_whereDeclared (unew)))
7143 uentry_showWhereSpecified (old);
7147 /* yes, this is necessary! (if its a param) */
7148 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7153 uentry_checkStateConformance (/*@notnull@*/ uentry old,
7154 /*@notnull@*/ uentry unew,
7155 bool mustConform, bool completeConform)
7157 checkDefState (old, unew, mustConform, completeConform);
7158 checkNullState (old, unew, mustConform, completeConform);
7159 checkAliasState (old, unew, mustConform, completeConform);
7160 checkExpState (old, unew, mustConform, completeConform);
7162 sRef_storeState (old->sref);
7163 sRef_storeState (unew->sref);
7167 checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
7169 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
7174 llassert (uentry_isVar (old));
7175 llassert (uentry_isVar (unew));
7177 if (cstring_isEmpty (old->uname))
7179 cstring_free (old->uname);
7180 old->uname = cstring_copy (unew->uname);
7183 if (unew->info->var->kind == VKRETPARAM
7184 || unew->info->var->kind == VKSEFRETPARAM)
7186 if (old->info->var->kind != VKRETPARAM
7187 && old->info->var->kind != VKSEFRETPARAM)
7191 message ("Parameter %q inconsistently %rdeclared as "
7192 "returned parameter",
7193 uentry_getName (unew),
7194 uentry_isDeclared (old)),
7195 uentry_whereDeclared (unew)))
7197 uentry_showWhereSpecified (old);
7198 old->info->var->kind = unew->info->var->kind;
7204 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
7206 if (old->info->var->kind != VKSEFPARAM
7207 && old->info->var->kind != VKSEFRETPARAM)
7211 message ("Parameter %qinconsistently %rdeclared as "
7213 uentry_getOptName (unew),
7214 uentry_isDeclared (old)),
7215 uentry_whereDeclared (unew)))
7217 uentry_showWhereSpecified (old);
7218 old->info->var->kind = unew->info->var->kind;
7223 if (old->info->var->kind == VKSPEC)
7225 old->info->var->kind = unew->info->var->kind;
7229 unew->info->var->kind = old->info->var->kind;
7232 if (unew->info->var->checked != CH_UNKNOWN
7233 && unew->info->var->checked != old->info->var->checked)
7235 if (old->info->var->checked == CH_UNKNOWN
7236 && !fileloc_isUser (uentry_whereLast (old)))
7244 message ("Variable %q inconsistently %rdeclared as "
7245 "%s parameter (was %s)",
7246 uentry_getName (unew),
7247 uentry_isDeclared (old),
7248 checkedName (unew->info->var->checked),
7249 checkedName (old->info->var->checked)),
7250 uentry_whereDeclared (unew)))
7252 uentry_showWhereSpecified (old);
7256 old->info->var->checked = unew->info->var->checked;
7261 && (old->info->var->checked != CH_UNKNOWN)
7262 && uentry_isReallySpecified (old))
7266 message ("%s %q specified as %s, but declared without %s qualifier",
7267 ekind_capName (unew->ukind),
7268 uentry_getName (unew),
7269 checkedName (old->info->var->checked),
7270 checkedName (old->info->var->checked)),
7271 uentry_whereDeclared (unew)))
7273 uentry_showWhereSpecified (old);
7277 unew->info->var->checked = old->info->var->checked;
7280 uentry_checkStateConformance (old, unew, mustConform, completeConform);
7283 void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
7285 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
7290 llassert (uentry_isVar (u1));
7291 llassert (uentry_isVar (u2));
7293 if (u1->info->var->kind != u2->info->var->kind) {
7294 if (u1->info->var->kind == VKSEFRETPARAM) {
7295 if (u2->info->var->kind == VKRETPARAM) {
7298 message ("Function types are inconsistent. Parameter %d is "
7299 "sef parameter, but non-sef parameter in "
7300 "assigned function: %s",
7301 paramno, exprNode_unparse (e)),
7303 } else if (u2->info->var->kind == VKSEFPARAM) {
7306 message ("Function types are inconsistent. Parameter %d is "
7307 "returns parameter, but non-returns parameter in "
7308 "assigned function: %s",
7309 paramno, exprNode_unparse (e)),
7314 message ("Function types are inconsistent. Parameter %d is "
7315 "sef returns parameter, but non-sef returns parameter in "
7316 "assigned function: %s",
7317 paramno, exprNode_unparse (e)),
7320 } else if (u1->info->var->kind == VKRETPARAM) {
7323 message ("Function types are inconsistent. Parameter %d is "
7324 "returns parameter, but non-returns parameter in "
7325 "assigned function: %s",
7326 paramno, exprNode_unparse (e)),
7328 } else if (u1->info->var->kind == VKSEFPARAM) {
7331 message ("Function types are inconsistent. Parameter %d is "
7332 "sef parameter, but non-sef parameter in "
7333 "assigned function: %s",
7334 paramno, exprNode_unparse (e)),
7337 if (u2->info->var->kind == VKSEFRETPARAM) {
7340 message ("Function types are inconsistent. Parameter %d is "
7341 "normal parameter, but sef returns parameter in "
7342 "assigned function: %s",
7343 paramno, exprNode_unparse (e)),
7345 } else if (u2->info->var->kind == VKSEFPARAM) {
7348 message ("Function types are inconsistent. Parameter %d is "
7349 "normal parameter, but sef parameter in "
7350 "assigned function: %s",
7351 paramno, exprNode_unparse (e)),
7353 } else if (u2->info->var->kind == VKRETPARAM) {
7356 message ("Function types are inconsistent. Parameter %d is "
7357 "normal parameter, but returns parameter in "
7358 "assigned function: %s",
7359 paramno, exprNode_unparse (e)),
7367 if (u1->info->var->defstate != u2->info->var->defstate)
7371 message ("Function types are inconsistent. Parameter %d is "
7372 "%s, but %s in assigned function: %s",
7374 sstate_unparse (u1->info->var->defstate),
7375 sstate_unparse (u2->info->var->defstate),
7376 exprNode_unparse (e)),
7380 if (u1->info->var->nullstate != u2->info->var->nullstate)
7384 message ("Function types are inconsistent. Parameter %d is "
7385 "%s, but %s in assigned function: %s",
7387 nstate_unparse (u1->info->var->nullstate),
7388 nstate_unparse (u2->info->var->nullstate),
7389 exprNode_unparse (e)),
7393 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
7397 message ("Function types are inconsistent. Parameter %d is "
7398 "%s, but %s in assigned function: %s",
7400 alkind_unparse (sRef_getAliasKind (u1->sref)),
7401 alkind_unparse (sRef_getAliasKind (u2->sref)),
7402 exprNode_unparse (e)),
7406 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
7410 message ("Function types are inconsistent. Parameter %d is "
7411 "%s, but %s in assigned function: %s",
7413 exkind_unparse (sRef_getExKind (u1->sref)),
7414 exkind_unparse (sRef_getExKind (u2->sref)),
7415 exprNode_unparse (e)),
7421 checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
7422 /*@notnull@*/ uentry unew,
7423 bool mustConform, /*@unused@*/ bool completeConform)
7425 uentryList oldParams = uentry_getParams (old);
7426 uentryList newParams = uentry_getParams (unew);
7427 ctype newType = unew->utype;
7428 ctype oldType = old->utype;
7429 ctype oldRetType = ctype_unknown;
7430 ctype newRetType = ctype_unknown;
7432 if (uentry_isForward (old))
7434 mustConform = FALSE;
7435 uentry_copyInto (old, unew);
7440 ** check return values
7443 if (ctype_isKnown (oldType))
7445 llassert (ctype_isFunction (oldType));
7447 oldRetType = ctype_returnValue (oldType);
7450 if (ctype_isKnown (newType))
7452 llassert (ctype_isFunction (newType));
7454 newRetType = ctype_returnValue (newType);
7457 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
7458 && !ctype_matchDef (newRetType, oldRetType))
7460 if (mustConform) returnValueError (old, unew);
7464 if (ctype_isConj (newRetType))
7466 if (ctype_isConj (oldRetType))
7468 if (!ctype_sameAltTypes (newRetType, oldRetType))
7472 message ("Function %q inconsistently %rdeclared to "
7473 "return alternate types %s "
7474 "(types match, but alternates are not identical, "
7475 "so checking may not be correct)",
7476 uentry_getName (unew),
7477 uentry_isDeclared (old),
7478 ctype_unparse (newRetType)),
7479 uentry_whereDeclared (unew)))
7481 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
7487 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
7492 uentry_checkStateConformance (old, unew, mustConform, completeConform);
7494 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
7496 if (exitkind_isKnown (unew->info->fcn->exitCode))
7500 message ("Function %q inconsistently %rdeclared using %s",
7501 uentry_getName (unew),
7502 uentry_isDeclared (old),
7503 exitkind_unparse (unew->info->fcn->exitCode)),
7504 uentry_whereDeclared (unew)))
7506 uentry_showWhereSpecified (old);
7511 unew->info->fcn->exitCode = old->info->fcn->exitCode;
7515 if (!qual_isUnknown (unew->info->fcn->nullPred))
7517 if (!qual_equal (old->info->fcn->nullPred, unew->info->fcn->nullPred))
7521 message ("Function %q inconsistently %rdeclared using %s",
7522 uentry_getName (unew),
7523 uentry_isDeclared (old),
7524 qual_unparse (unew->info->fcn->nullPred)),
7525 uentry_whereDeclared (unew)))
7527 uentry_showWhereSpecified (old);
7533 unew->info->fcn->nullPred = old->info->fcn->nullPred;
7536 if (unew->info->fcn->specialCode != SPC_NONE)
7538 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
7542 message ("Function %q inconsistently %rdeclared using %s",
7543 uentry_getName (unew),
7544 uentry_isDeclared (old),
7545 specCode_unparse (unew->info->fcn->specialCode)),
7546 uentry_whereDeclared (unew)))
7548 uentry_showWhereSpecified (old);
7554 unew->info->fcn->specialCode = old->info->fcn->specialCode;
7561 if (!uentryList_sameObject (oldParams, newParams)
7562 && (!uentryList_isMissingParams (oldParams)))
7564 if (!uentryList_isMissingParams (newParams))
7567 int nparams = uentryList_size (oldParams);
7568 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
7570 if (nparams != uentryList_size (newParams))
7572 nargsError (old, unew);
7575 if (uentryList_size (newParams) < nparams)
7577 nparams = uentryList_size (newParams);
7580 while (paramno < nparams)
7582 uentry oldCurrent = uentryList_getN (oldParams, paramno);
7583 uentry newCurrent = uentryList_getN (newParams, paramno);
7584 ctype oldCurrentType = uentry_getType (oldCurrent);
7585 ctype newCurrentType = uentry_getType (newCurrent);
7587 llassert (uentry_isValid (oldCurrent)
7588 && uentry_isValid (newCurrent));
7590 if (!uentry_isElipsisMarker (oldCurrent)
7591 && !uentry_isElipsisMarker (newCurrent))
7593 checkVarConformance (oldCurrent, newCurrent,
7594 mustConform, completeConform);
7599 if (uentry_hasName (oldCurrent)
7600 && uentry_hasName (newCurrent))
7602 cstring oldname = uentry_getName (oldCurrent);
7603 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
7605 cstring nname = uentry_getName (newCurrent);
7608 if (cstring_isDefined (pfx)
7609 && cstring_equalPrefix (oldname, cstring_toCharsSafe (pfx)))
7611 oname = cstring_suffix (oldname, cstring_length (pfx));
7616 /*@-branchstate@*/ } /*@=branchstate@*/
7618 if (cstring_isDefined (pfx)
7619 && cstring_equalPrefix (nname, cstring_toCharsSafe (pfx)))
7621 nnamefix = cstring_suffix (nname, cstring_length (pfx));
7626 /*@-branchstate@*/ } /*@=branchstate@*/
7628 if (!cstring_equal (oname, nnamefix))
7631 (FLG_DECLPARAMMATCH,
7632 message ("Definition parameter name %s does not match "
7633 "name of corresponding parameter in "
7636 uentry_whereLast (newCurrent)))
7638 uentry_showWhereLastPlain (oldCurrent);
7642 cstring_free (oldname);
7643 cstring_free (nname);
7647 if (!ctype_match (oldCurrentType, newCurrentType))
7649 paramTypeError (old, oldCurrent, oldCurrentType,
7650 unew, newCurrent, newCurrentType, paramno);
7654 if (ctype_isMissingParamsMarker (newCurrentType)
7655 || ctype_isElips (newCurrentType)
7656 || ctype_isMissingParamsMarker (oldCurrentType)
7657 || ctype_isElips (oldCurrentType))
7663 if (ctype_isConj (newCurrentType))
7665 if (ctype_isConj (oldCurrentType))
7667 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
7671 message ("Parameter %q inconsistently %rdeclared with "
7672 "alternate types %s "
7673 "(types match, but alternates are not identical, "
7674 "so checking may not be correct)",
7675 uentry_getName (newCurrent),
7676 uentry_isDeclared (oldCurrent),
7677 ctype_unparse (newCurrentType)),
7678 uentry_whereDeclared (unew)))
7680 uentry_showWhereLastVal (oldCurrent,
7681 ctype_unparse (oldCurrentType));
7689 message ("Parameter %q inconsistently %rdeclared with "
7690 "alternate types %s",
7691 uentry_getName (newCurrent),
7692 uentry_isDeclared (oldCurrent),
7693 ctype_unparse (newCurrentType)),
7694 uentry_whereDeclared (unew)))
7696 uentry_showWhereLastVal (oldCurrent,
7697 ctype_unparse (oldCurrentType));
7704 if (ctype_isConj (oldCurrentType))
7706 uentry_setType (newCurrent, oldCurrentType);
7714 ** Forgot this! detected by lclint:
7715 ** uentry.c:1257,15: Suspected infinite loop
7721 if (!uentryList_isMissingParams (newParams))
7723 if (ctype_isConj (oldRetType))
7725 old->utype = ctype_makeFunction (oldRetType,
7726 uentryList_copy (newParams));
7730 old->utype = unew->utype;
7734 checkGlobalsConformance (old, unew, mustConform, completeConform);
7735 checkModifiesConformance (old, unew, mustConform, completeConform);
7737 if (specialClauses_isDefined (unew->info->fcn->specclauses))
7739 if (!specialClauses_isDefined (old->info->fcn->specclauses))
7743 message ("Function %q redeclared using special clauses (can only "
7744 "be used in first declaration)",
7745 uentry_getName (unew)),
7746 uentry_whereDeclared (unew)))
7748 uentry_showWhereLast (old);
7753 specialClauses_checkEqual (old, unew);
7757 if (fileloc_isUndefined (old->whereDeclared))
7759 old->whereDeclared = fileloc_copy (unew->whereDeclared);
7761 else if (fileloc_isUndefined (unew->whereDeclared))
7763 unew->whereDeclared = fileloc_copy (old->whereDeclared);
7772 uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
7776 llassert (uentry_isValid (ue));
7777 llassert (uentry_isEitherConstant (ue));
7779 uval = ue->info->uconst->val;
7781 if (multiVal_isDefined (uval))
7783 if (multiVal_isDefined (m))
7785 if (!multiVal_equiv (uval, m))
7789 message ("%s %q defined with inconsistent value: %q",
7790 ekind_capName (ue->ukind),
7791 uentry_getName (ue),
7792 multiVal_unparse (m)),
7795 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
7803 ue->info->uconst->val = m;
7804 multiVal_free (uval);
7809 bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7812 bool typeError = FALSE;
7814 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
7816 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
7820 checkStructConformance (old, unew);
7825 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
7827 llbug (message ("struct tags: bad types: %t / %t",
7828 old->utype, unew->utype));
7832 else if (uentry_isEnumTag (old))
7834 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
7836 if (mustConform) checkEnumConformance (old, unew);
7840 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
7842 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
7843 ctype_unparse (unew->utype)));
7847 else if (!ctype_match (old->utype, unew->utype))
7849 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
7851 ctype realt = ctype_realType (unew->utype);
7853 if (ctype_isRealInt (realt) || ctype_isChar (realt))
7855 unew->utype = ctype_bool;
7861 typeError = optgenerror
7863 message ("%q defined as %s", uentry_getName (old),
7864 ctype_unparse (realt)),
7865 uentry_whereDeclared (unew));
7873 ctype oldr = ctype_realType (old->utype);
7874 ctype newr = ctype_realType (unew->utype);
7876 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
7878 checkStructConformance (old, unew);
7880 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
7882 checkStructConformance (old, unew);
7884 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
7886 checkEnumConformance (old, unew);
7888 else if (uentry_isConstant (old)
7889 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
7891 /* okay...for now! (should check the type is reset later... */
7895 DPRINTF (("YABA!"));
7898 message ("%s %q %rdeclared with inconsistent type: %t",
7899 ekind_capName (unew->ukind),
7900 uentry_getName (unew),
7901 uentry_isDeclared (old),
7903 uentry_whereDeclared (unew)))
7905 uentry_showWhereLast (old);
7921 uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
7922 /*@notnull@*/ uentry unew,
7923 bool mustConform, bool completeConform)
7925 if (ctype_isDefined (unew->info->datatype->type))
7928 ** bool is hard coded here, since it is built into LCL.
7929 ** For now, we're stuck with LCL's types.
7932 if (ctype_isDirectBool (old->utype) &&
7933 cstring_equalLit (unew->uname, "bool"))
7935 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
7936 evs 2000-07-25: removed
7938 unew->utype = ctype_bool;
7941 if (ctype_isUnknown (old->info->datatype->type))
7943 old->info->datatype->type = unew->info->datatype->type;
7947 DPRINTF (("Old: %s / New: %s",
7948 uentry_unparseFull (old),
7949 uentry_unparseFull (unew)));
7950 DPRINTF (("Types: %s / %s",
7951 ctype_unparse (old->info->datatype->type),
7952 ctype_unparse (unew->info->datatype->type)));
7954 if (ctype_matchDef (old->info->datatype->type,
7955 unew->info->datatype->type))
7964 ("Type %q %s with inconsistent type: %t",
7965 uentry_getName (unew),
7966 uentry_reDefDecl (old, unew),
7967 unew->info->datatype->type),
7968 uentry_whereDeclared (unew)))
7970 uentry_showWhereLastExtra
7971 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
7974 old->info->datatype->type = unew->info->datatype->type;
7979 if (unew->info->datatype->abs != MAYBE)
7981 if (ynm_isOff (old->info->datatype->abs)
7982 && ynm_isOn (unew->info->datatype->abs))
7984 if (!ctype_isDirectBool (old->utype))
7989 ("Datatype %q inconsistently %rdeclared as abstract type",
7990 uentry_getName (unew),
7991 uentry_isDeclared (old)),
7992 uentry_whereDeclared (unew)))
7994 uentry_showWhereLastPlain (old);
7998 else if (ynm_isOn (old->info->datatype->abs)
7999 && ynm_isOff (unew->info->datatype->abs))
8001 if (!ctype_isDirectBool (old->utype))
8006 ("Datatype %q inconsistently %rdeclared as concrete type",
8007 uentry_getName (unew),
8008 uentry_isDeclared (old)),
8009 uentry_whereDeclared (unew)))
8011 uentry_showWhereLastPlain (old);
8022 if (ynm_isOn (old->info->datatype->abs))
8024 old->sref = unew->sref;
8025 unew->info->datatype->mut = old->info->datatype->mut;
8028 && uentry_isReallySpecified (old))
8033 ("Datatype %q specified as abstract, "
8034 "but abstract annotation not used in declaration",
8035 uentry_getName (unew)),
8036 uentry_whereDeclared (unew)))
8038 uentry_showWhereLastPlain (old);
8044 unew->info->datatype->abs = old->info->datatype->abs;
8046 if (ynm_isMaybe (unew->info->datatype->mut))
8048 if (completeConform && ynm_isOff (old->info->datatype->mut)
8049 && uentry_isReallySpecified (old))
8054 ("Datatype %q specified as immutable, "
8055 "but immutable annotation not used in declaration",
8056 uentry_getName (unew)),
8057 uentry_whereDeclared (unew)))
8059 uentry_showWhereLastPlain (old);
8063 unew->info->datatype->mut = old->info->datatype->mut;
8065 else if (ynm_isMaybe (old->info->datatype->mut))
8067 old->info->datatype->mut = unew->info->datatype->mut;
8071 if (ynm_isOn (old->info->datatype->abs))
8073 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
8077 message ("Datatype %q inconsistently %rdeclared as immutable",
8078 uentry_getName (unew),
8079 uentry_isDeclared (old)),
8080 uentry_whereDeclared (unew)))
8082 uentry_showWhereLastPlain (old);
8087 if (ynm_isOff (old->info->datatype->mut)
8088 && ynm_isOn (unew->info->datatype->mut))
8092 message ("Datatype %q inconsistently %rdeclared as mutable",
8093 uentry_getName (unew),
8094 uentry_isDeclared (old)),
8095 uentry_whereDeclared (unew)))
8097 uentry_showWhereLastPlain (old);
8102 old->info->datatype->mut = unew->info->datatype->mut;
8105 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8109 uentry_checkConstantConformance (/*@notnull@*/ uentry old,
8110 /*@notnull@*/ uentry unew,
8112 /*@unused@*/ bool completeConform)
8114 multiVal oldVal = old->info->uconst->val;
8115 multiVal newVal = unew->info->uconst->val;
8117 if (multiVal_isDefined (oldVal))
8119 if (multiVal_isDefined (newVal))
8121 if (!multiVal_equiv (oldVal, newVal))
8126 message ("%s %q %rdeclared with inconsistent value: %q",
8127 ekind_capName (unew->ukind),
8128 uentry_getName (unew),
8129 uentry_isDeclared (old),
8130 multiVal_unparse (newVal)),
8131 uentry_whereDeclared (unew)))
8133 uentry_showWhereLastExtra (old, multiVal_unparse (oldVal));
8137 unew->info->uconst->val = multiVal_copy (oldVal);
8138 multiVal_free (newVal);
8147 old->info->uconst->val = multiVal_copy (newVal);
8152 uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8153 /*@notnull@*/ uentry unew, bool mustConform,
8154 bool completeConform)
8156 bool typeError = FALSE;
8157 bool fcnConformance = FALSE;
8159 if (!ekind_equal (unew->ukind, old->ukind))
8162 ** okay, only if one is a function and the other is
8163 ** a variable of type function.
8166 if (unew->ukind == KENUMCONST
8167 && old->ukind == KCONST)
8169 old->ukind = KENUMCONST;
8173 if (unew->ukind == KFCN
8174 && old->ukind == KCONST
8175 && ctype_isUnknown (old->utype))
8178 ** When a function is defined with an unparam macro
8181 uentry_copyInto (old, unew);
8185 if (uentry_isExpandedMacro (old)
8186 && uentry_isEitherConstant (unew))
8188 uentry_copyInto (old, unew);
8192 if (uentry_isEndIter (unew))
8194 if (ctype_isUnknown (old->utype))
8196 if (!uentry_isSpecified (old)
8197 && uentry_isCodeDefined (unew))
8199 if (!fileloc_withinLines (uentry_whereDefined (old),
8200 uentry_whereDeclared (unew), 2))
8201 { /* bogus! will give errors if there is too much whitespace */
8205 ("Iterator finalized name %q does not match name in "
8206 "previous iter declaration (should be end_%q). This iter "
8207 "is declared at %q",
8208 uentry_getName (unew),
8209 uentry_getName (old),
8210 fileloc_unparse (uentry_whereDefined (old))),
8211 uentry_whereDeclared (old));
8215 uentry_copyInto (old, unew);
8220 KindConformanceError (old, unew, mustConform);
8224 if (uentry_isFunction (unew))
8226 if (uentry_isVariable (old))
8228 if (!ctype_isUnknown (old->utype))
8230 if (ctype_isFunction (old->utype))
8232 uentry_makeVarFunction (old);
8233 checkFunctionConformance (old, unew, mustConform,
8235 fcnConformance = TRUE;
8239 KindConformanceError (old, unew, mustConform);
8244 if (uentry_isExpandedMacro (old))
8246 if (fileloc_isUndefined (unew->whereDefined))
8248 unew->whereDefined = fileloc_update (unew->whereDefined,
8252 uentry_copyInto (old, unew);
8253 old->used = unew->used = TRUE;
8258 /* undeclared identifier */
8259 old->utype = unew->utype;
8260 uentry_makeVarFunction (old);
8261 checkFunctionConformance (old, unew, FALSE, FALSE);
8262 fcnConformance = TRUE;
8268 KindConformanceError (old, unew, mustConform);
8271 else if (uentry_isFunction (old) && uentry_isVariable (unew))
8273 if (!ctype_isUnknown (unew->utype))
8275 if (ctype_isFunction (unew->utype))
8277 uentry_makeVarFunction (unew);
8278 checkFunctionConformance (old, unew, mustConform, completeConform);
8279 fcnConformance = TRUE;
8283 KindConformanceError (old, unew, mustConform);
8288 KindConformanceError (old, unew, mustConform);
8293 KindConformanceError (old, unew, mustConform);
8299 ** check parameter lists for functions
8300 ** (before type errors, to get better messages
8303 if (uentry_isFunction (old))
8305 checkFunctionConformance (old, unew, mustConform, completeConform);
8306 fcnConformance = TRUE;
8310 if (!ctype_isUndefined (old->utype))
8312 typeError = checkTypeConformance (old, unew, mustConform);
8319 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
8321 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
8324 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
8326 DPRINTF (("Check datatype: %s / %s",
8327 uentry_unparseFull (old),
8328 uentry_unparseFull (unew)));
8330 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
8333 if (uentry_isVariable (old) && uentry_isVariable (unew))
8336 !ctype_matchDef (old->utype, unew->utype))
8341 ("Variable %q %s with inconsistent type (arrays and pointers are "
8342 "not identical in variable declarations): %t",
8343 uentry_getName (unew),
8344 uentry_reDefDecl (old, unew),
8346 uentry_whereDeclared (unew)))
8348 uentry_showWhereLast (old);
8351 ** Avoid repeated errors.
8354 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
8356 old->whereDefined = fileloc_update (old->whereDefined,
8364 checkVarConformance (old, unew, mustConform, completeConform);
8369 /* old->utype = unew->utype; */
8373 if (ctype_isConj (old->utype))
8375 if (ctype_isConj (unew->utype))
8377 if (!ctype_sameAltTypes (old->utype, unew->utype))
8381 message ("%s %q inconsistently %rdeclared with "
8382 "alternate types %s "
8383 "(types match, but alternates are not identical, "
8384 "so checking may not be correct)",
8385 ekind_capName (uentry_getKind (old)),
8386 uentry_getName (unew),
8387 uentry_isDeclared (old),
8388 ctype_unparse (unew->utype)),
8389 uentry_whereDeclared (unew)))
8391 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
8395 old->utype = unew->utype;
8402 if (ctype_isUnknown (old->utype))
8404 old->utype = unew->utype;
8409 if (unew->ukind == old->ukind)
8412 unew->info = uinfo_copy (old->info, old->ukind);
8415 sRef_storeState (old->sref);
8416 sRef_storeState (unew->sref);
8420 ** modifies spec to reflect def, reports any inconsistencies
8424 uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
8426 llassert (uentry_isValid (spec));
8427 llassert (uentry_isValid (def));
8428 llassert (cstring_equal (spec->uname, def->uname));
8430 uentry_checkConformance (spec, def, TRUE,
8431 context_getFlag (FLG_NEEDSPEC));
8433 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
8436 ** okay, declarations conform. Propagate extra information.
8439 uentry_setDefined (spec, uentry_whereDefined (def));
8440 uentry_setDeclared (spec, uentry_whereDeclared (def));
8442 if (uentry_isStatic (def))
8446 message ("%s %q specified, but declared as static",
8447 ekind_capName (def->ukind),
8448 uentry_getName (def)),
8449 uentry_whereDeclared (def)))
8451 uentry_showWhereSpecified (spec);
8456 spec->storageclass = def->storageclass;
8459 sRef_storeState (spec->sref);
8461 spec->used = def->used || spec->used;
8462 spec->hasNameError |= def->hasNameError;
8466 if (!spec->hasNameError)
8468 uentry_checkName (spec);
8477 ** Can't generate function redeclaration errors when the
8478 ** entries are merged, since we don't yet know if its the
8479 ** definition of the function.
8483 uentry_clearDecl (void)
8485 posRedeclared = uentry_undefined;
8486 fileloc_free (posLoc);
8487 posLoc = fileloc_undefined;
8491 uentry_checkDecl (void)
8493 if (uentry_isValid (posRedeclared))
8495 llassert (fileloc_isDefined (posLoc));
8497 if (uentry_isCodeDefined (posRedeclared))
8499 if (optgenerror (FLG_REDECL,
8500 message ("%s %q declared after definition",
8501 ekind_capName (posRedeclared->ukind),
8502 uentry_getName (posRedeclared)),
8505 llgenindentmsg (message ("Definition of %q",
8506 uentry_getName (posRedeclared)),
8507 posRedeclared->whereDeclared);
8512 if (optgenerror (FLG_REDECL,
8513 message ("%s %q declared more than once",
8514 ekind_capName (posRedeclared->ukind),
8515 uentry_getName (posRedeclared)),
8518 llgenindentmsg (message ("Previous declaration of %q",
8519 uentry_getName (posRedeclared)),
8520 posRedeclared->whereDeclared);
8525 fileloc_free (posLoc);
8526 posLoc = fileloc_undefined;
8527 posRedeclared = uentry_undefined;
8531 ** Redefinition of old as unew.
8532 ** modifies old to reflect unew, reports any inconsistencies
8536 uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
8538 fileloc olddef = uentry_whereDeclared (old);
8539 fileloc unewdef = uentry_whereDeclared (unew);
8543 if (uentry_isExtern (unew))
8545 uentry_setUsed (old, unewdef);
8549 fileloc_isUndefined (olddef)
8550 && fileloc_isDefined (uentry_whereDefined (old))
8551 && !uentry_isExpandedMacro (old);
8553 if (!context_getFlag (FLG_INCONDEFSLIB)
8554 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
8556 mustConform = FALSE;
8563 llassert (uentry_isValid (old));
8564 llassert (uentry_isValid (unew));
8565 llassert (cstring_equal (old->uname, unew->uname));
8568 ** should check old one was extern!
8571 if (uentry_isStatic (old))
8573 if (!(uentry_isStatic (unew)))
8577 message ("%s %q shadows static declaration",
8578 ekind_capName (unew->ukind),
8579 uentry_getName (unew)),
8582 uentry_showWhereLast (old);
8587 uentry_setDeclDef (old, unewdef);
8590 else if (uentry_isStatic (unew))
8592 uentry_setDeclDef (old, unewdef);
8594 else if (uentry_isExtern (old))
8596 uentry_setDeclared (old, unewdef);
8600 if (!uentry_isExtern (unew) && !uentry_isForward (old)
8601 && !fileloc_equal (olddef, unewdef)
8602 && !fileloc_isUndefined (olddef)
8603 && !fileloc_isUndefined (unewdef)
8604 && !fileloc_isBuiltin (olddef)
8605 && !fileloc_isBuiltin (unewdef)
8606 && !uentry_isYield (old)
8607 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
8609 if (uentry_isVariable (old) || uentry_isVariable (unew))
8611 ; /* will report redeclaration error later */
8615 if (fileloc_isDefined (uentry_whereDefined (old)))
8619 message ("%s %q defined more than once",
8620 ekind_capName (unew->ukind),
8621 uentry_getName (unew)),
8622 uentry_whereLast (unew)))
8625 (message ("Previous definition of %q",
8626 uentry_getName (old)),
8627 uentry_whereLast (old));
8630 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
8632 uentry_copyInto (old, unew);
8633 old->sref = sRef_saveCopy (old->sref);
8641 if (fileloc_isLib (olddef)
8642 || fileloc_isUndefined (olddef)
8643 || fileloc_isImport (olddef))
8645 if (uentry_isExtern (unew))
8647 if (uentry_isExtern (old)
8648 || (fileloc_isDefined (uentry_whereDeclared (old))
8649 && (!fileloc_equal (uentry_whereDeclared (old),
8650 uentry_whereDefined (old)))))
8654 message ("%s %q declared more than once",
8655 ekind_capName (unew->ukind),
8656 uentry_getName (unew)),
8657 unew->whereDeclared))
8660 (message ("Previous declaration of %q",
8661 uentry_getName (old)),
8662 old->whereDeclared);
8666 uentry_setExtern (old);
8670 uentry_setDefined (old, unewdef);
8676 uentry_checkConformance (old, unew, mustConform, FALSE);
8678 old->used = old->used || unew->used;
8679 old->uses = filelocList_append (old->uses, unew->uses);
8680 unew->uses = filelocList_undefined;
8682 sRef_storeState (old->sref);
8683 sRef_storeState (unew->sref);
8687 old->whereDefined = fileloc_update (old->whereDefined,
8692 ** No redeclaration errors for functions here, since we
8693 ** don't know if this is the definition of the function.
8696 if (fileloc_isUser (old->whereDeclared)
8697 && fileloc_isUser (unew->whereDeclared)
8698 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
8699 && !fileloc_isDefined (unew->whereDefined))
8701 if (uentry_isFunction (old))
8703 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
8704 posLoc = fileloc_update (posLoc, unew->whereDeclared);
8708 if (optgenerror (FLG_REDECL,
8709 message ("%s %q declared more than once",
8710 ekind_capName (unew->ukind),
8711 uentry_getName (unew)),
8712 unew->whereDeclared))
8714 llgenindentmsg (message ("Previous declaration of %q",
8715 uentry_getName (old)),
8716 old->whereDeclared);
8721 if (fileloc_isUndefined (old->whereDefined))
8723 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
8727 if (!context_processingMacros ()
8728 && fileloc_isUser (old->whereDefined)
8729 && fileloc_isUser (unew->whereDefined)
8730 && !fileloc_equal (old->whereDefined, unew->whereDefined))
8732 if (uentry_isVariable (unew) || uentry_isFunction (unew))
8734 if (uentry_isVariable (unew)
8735 && uentry_isExtern (unew))
8737 if (optgenerror (FLG_REDECL,
8738 message ("%s %q declared after definition",
8739 ekind_capName (unew->ukind),
8740 uentry_getName (unew)),
8741 unew->whereDeclared))
8743 llgenindentmsg (message ("Definition of %q",
8744 uentry_getName (old)),
8750 if (optgenerror (FLG_REDEF,
8751 message ("%s %q redefined",
8752 ekind_capName (unew->ukind),
8753 uentry_getName (unew)),
8754 unew->whereDefined))
8756 llgenindentmsg (message ("Previous definition of %q",
8757 uentry_getName (old)),
8765 if (uentry_isExternal (unew))
8767 old->whereDefined = fileloc_createExternal ();
8770 if (unew->hasNameError)
8772 old->hasNameError = TRUE;
8777 if (!old->hasNameError)
8779 uentry_checkName (old);
8782 llassert (!ctype_isUndefined (old->utype));
8786 uentry_copyState (uentry res, uentry other)
8788 llassert (uentry_isValid (res));
8789 llassert (uentry_isValid (other));
8791 res->used = other->used;
8793 res->info->var->kind = other->info->var->kind;
8794 res->info->var->defstate = other->info->var->defstate;
8795 res->info->var->nullstate = other->info->var->nullstate;
8796 res->info->var->checked = other->info->var->checked;
8798 sRef_copyState (res->sref, other->sref);
8802 uentry_sameKind (uentry u1, uentry u2)
8804 if (uentry_isValid (u1) && uentry_isValid (u2))
8806 if (uentry_isVar (u1) && uentry_isVar (u2))
8808 ctype c1 = u1->utype;
8809 ctype c2 = u2->utype;
8811 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
8814 ** both functions, or both not functions
8817 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
8821 return ((u1->ukind == u2->ukind));
8828 static void uentry_copyInto (/*@unique@*/ uentry unew, uentry old)
8830 llassert (uentry_isValid (unew));
8831 llassert (uentry_isValid (old));
8833 unew->ukind = old->ukind;
8834 unew->uname = cstring_copy (old->uname);
8835 unew->utype = old->utype;
8837 unew->whereSpecified = fileloc_copy (old->whereSpecified);
8838 unew->whereDefined = fileloc_copy (old->whereDefined);
8839 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8841 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
8842 unew->used = old->used;
8844 unew->isPrivate = old->isPrivate;
8845 unew->hasNameError = old->hasNameError;
8846 unew->uses = filelocList_undefined;
8848 unew->storageclass = old->storageclass;
8849 unew->info = uinfo_copy (old->info, old->ukind);
8854 uentry_copy (uentry e)
8856 if (uentry_isValid (e))
8858 uentry enew = uentry_alloc ();
8859 DPRINTF (("copy: %s", uentry_unparseFull (e)));
8860 uentry_copyInto (enew, e);
8861 DPRINTF (("Here we are..."));
8862 DPRINTF (("original: %s", uentry_unparseFull (e)));
8863 DPRINTF (("copy: %s", uentry_unparse (enew)));
8864 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
8869 return uentry_undefined;
8874 uentry_setState (uentry res, uentry other)
8876 llassert (uentry_isValid (res));
8877 llassert (uentry_isValid (other));
8879 llassert (res->ukind == other->ukind);
8880 llassert (res->ukind == KVAR);
8882 res->sref = sRef_saveCopy (other->sref);
8883 res->used = other->used;
8884 filelocList_free (res->uses);
8885 res->uses = other->uses;
8886 other->uses = filelocList_undefined;
8887 res->lset = other->lset;
8891 uentry_mergeUses (uentry res, uentry other)
8893 llassert (uentry_isValid (res));
8894 llassert (uentry_isValid (other));
8896 res->used = other->used || res->used;
8897 res->lset = other->lset || res->lset;
8898 res->uses = filelocList_append (res->uses, other->uses);
8899 other->uses = filelocList_undefined;
8904 ** This is a really ugly routine.
8906 ** gack...fix this one day.
8911 ** >> res is the false branch, other is the true branch (or continuation)
8913 ** >> res is the true branch, other is the false branch (or continutation)
8920 ** References not effected by res are propagated from other.
8924 branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
8925 bool flip, clause cl, fileloc loc)
8929 message ("%s %q is %s %s, but %s %s.",
8930 ekind_capName (res->ukind), uentry_getName (res),
8931 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
8932 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
8935 if (sRef_isDead (res->sref))
8937 sRef_showStateInfo (res->sref);
8939 else if (sRef_isKept (res->sref))
8941 sRef_showAliasInfo (res->sref);
8943 else /* dependent */
8945 sRef_showAliasInfo (res->sref);
8946 sRef_showAliasInfo (other->sref);
8949 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
8953 static bool incompatibleStates (sRef rs, sRef os)
8955 alkind rk = sRef_getAliasKind (rs);
8956 alkind ok = sRef_getAliasKind (os);
8958 if (alkind_isError (rk) || alkind_isError (ok))
8964 return ((sRef_isDead (rs)
8965 || (alkind_isKept (rk) && !alkind_isKept (ok))
8966 || (alkind_isDependent (rk)
8967 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
8968 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
8973 branchStateAltError (/*@notnull@*/ uentry res,
8974 /*@notnull@*/ uentry other, bool flip,
8975 clause cl, fileloc loc)
8979 message ("%s %q is %s %s, but %s %s.",
8980 ekind_capName (res->ukind), uentry_getName (res),
8981 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
8982 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
8985 if (sRef_isDead (other->sref))
8987 sRef_showStateInfo (other->sref);
8991 sRef_showAliasInfo (other->sref);
8994 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
8995 sRef_setDefinedComplete (res->sref, fileloc_undefined);
8997 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
8998 sRef_setDefinedComplete (other->sref, fileloc_undefined);
9002 static bool notNull (sRef sr, bool flip)
9004 return (!sRef_definitelyNull (sr)
9005 && !(sRef_isKept (sr))
9006 && !(sRef_isDependent (sr))
9007 && !(flip ? usymtab_isProbableDeepNull (sr)
9008 : usymtab_isAltProbablyDeepNull (sr)));
9012 uentry_mergeState (uentry res, uentry other, fileloc loc,
9013 bool mustReturn, bool flip, bool opt,
9016 llassert (uentry_isValid (res));
9017 llassert (uentry_isValid (other));
9019 llassert (res->ukind == other->ukind);
9020 llassert (res->ukind == KVAR);
9022 DPRINTF (("Merge state: %s / %s",
9023 uentry_unparse (res),
9024 uentry_unparse (other)));
9026 if (sRef_isValid (res->sref))
9030 if (incompatibleStates (res->sref, other->sref))
9032 if (sRef_isThroughArrayFetch (res->sref)
9033 && !context_getFlag (FLG_STRICTBRANCHSTATE))
9035 if (sRef_isKept (res->sref) || sRef_isKept (other->sref))
9037 sRef_maybeKill (res->sref, loc);
9039 else if (sRef_isPossiblyDead (other->sref))
9041 sRef_maybeKill (res->sref, loc);
9050 if (notNull (other->sref, flip))
9052 if (sRef_isLocalParamVar (res->sref)
9053 && (sRef_isLocalState (other->sref)
9054 || sRef_isDependent (other->sref)))
9056 if (sRef_isDependent (res->sref))
9058 sRef_setDependent (other->sref, loc);
9062 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
9067 branchStateError (res, other, flip, cl, loc);
9072 if (sRef_isKept (res->sref))
9074 sRef_setKept (other->sref, loc);
9079 if (incompatibleStates (other->sref, res->sref))
9081 if (notNull (res->sref, !flip))
9083 if (sRef_isLocalParamVar (res->sref)
9084 && (sRef_isDependent (res->sref)
9085 || sRef_isLocalState (res->sref)))
9087 if (sRef_isDependent (other->sref))
9089 sRef_setDependent (res->sref, loc);
9093 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
9098 if (sRef_isParam (other->sref))
9101 ** If the local variable associated
9102 ** with the param has the correct state,
9104 ** (e.g., free (s); s = new(); ...
9107 uentry uvar = usymtab_lookupSafe (other->uname);
9109 if (uentry_isValid (uvar)
9110 && ((sRef_isDead (other->sref)
9111 && sRef_isOnly (uvar->sref))
9112 || (sRef_isDependent (other->sref)
9113 && sRef_isOwned (uvar->sref))))
9119 branchStateAltError (res, other,
9125 branchStateAltError (res, other,
9132 if (sRef_isKept (other->sref))
9134 sRef_setKept (res->sref, loc);
9140 DPRINTF (("Merge opt..."));
9141 sRef_mergeOptState (res->sref, other->sref, cl, loc);
9142 DPRINTF (("Done!"));
9146 sRef_mergeState (res->sref, other->sref, cl, loc);
9151 if (sRef_isModified (other->sref))
9153 sRef_setModified (res->sref);
9157 if (cl == DOWHILECLAUSE)
9159 res->used = other->used || res->used;
9160 res->lset = other->lset || res->lset;
9161 res->uses = filelocList_append (res->uses, other->uses);
9162 other->uses = filelocList_undefined;
9166 if (sRef_isMacroParamRef (res->sref)
9167 && !uentry_isSefParam (other)
9168 && !uentry_isSefParam (res))
9170 bool hasError = FALSE;
9172 if (bool_equal (res->used, other->used))
9174 res->used = other->used;
9178 if (other->used && !flip)
9183 message ("Macro parameter %q used in true clause, "
9184 "but not in false clause",
9185 uentry_getName (res)),
9186 uentry_whereDeclared (res));
9193 message ("Macro parameter %q used in false clause, "
9194 "but not in true clause",
9195 uentry_getName (res)),
9196 uentry_whereDeclared (res));
9202 /* make it sef now, prevent more errors */
9203 res->info->var->kind = VKREFSEFPARAM;
9209 res->used = other->used || res->used;
9210 res->lset = other->lset || res->lset;
9211 res->uses = filelocList_append (res->uses, other->uses);
9212 other->uses = filelocList_undefined;
9218 void uentry_setUsed (uentry e, fileloc loc)
9220 static bool firstTime = TRUE;
9221 static bool showUses = FALSE;
9222 static bool exportLocal = FALSE;
9226 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
9228 showUses = context_getFlag (FLG_SHOWUSES);
9229 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
9234 if (uentry_isValid (e))
9238 if (sRef_isMacroParamRef (e->sref))
9240 if (uentry_isYield (e) || uentry_isSefParam (e))
9246 if (context_inConditional ())
9250 message ("Macro parameter %q used in conditionally "
9251 "executed code (may or may not be "
9252 "evaluated exactly once)",
9253 uentry_getName (e)),
9256 e->info->var->kind = VKREFSEFPARAM;
9265 message ("Macro parameter %q used more than once",
9266 uentry_getName (e)),
9267 uentry_whereDeclared (e)))
9269 e->info->var->kind = VKREFSEFPARAM;
9276 if ((dp = uentry_directParamNo (e)) >= 0)
9278 uentry_setUsed (usymtab_getParam (dp), loc);
9283 if (!sRef_isLocalVar (e->sref))
9287 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
9293 if (context_inMacro ())
9295 e->uses = filelocList_addUndefined (e->uses);
9299 e->uses = filelocList_addDifferentFile
9301 uentry_whereDeclared (e),
9310 bool uentry_isReturned (uentry u)
9312 return (uentry_isValid (u) && uentry_isVar (u)
9313 && (u->info->var->kind == VKRETPARAM
9314 || u->info->var->kind == VKSEFRETPARAM));
9317 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args)
9319 llassert (uentry_isRealFunction (u));
9321 if (ctype_isFunction (u->utype)
9322 && sRef_isStateSpecial (uentry_getSref (u)))
9324 specialClauses clauses = uentry_getSpecialClauses (u);
9325 sRef res = sRef_makeNew (ctype_returnValue (u->utype), u->sref, u->uname);
9327 sRef_setAllocated (res, g_currentloc);
9329 specialClauses_postElements (clauses, cl)
9331 sRefSet refs = specialClause_getRefs (cl);
9332 sRefMod modf = specialClause_getEffectFunction (cl);
9334 sRefSet_elements (refs, el)
9336 sRef base = sRef_getRootBase (el);
9338 if (sRef_isResult (base))
9342 sRef sr = sRef_fixBase (el, res);
9343 modf (sr, g_currentloc);
9350 } end_sRefSet_elements ;
9352 } end_specialClauses_postElements ;
9360 sRefSet prefs = sRefSet_new ();
9361 sRef res = sRef_undefined;
9364 params = uentry_getParams (u);
9366 uentryList_elements (params, current)
9368 if (uentry_isReturned (current))
9370 if (exprNodeList_size (args) >= paramno)
9372 exprNode ecur = exprNodeList_nth (args, paramno);
9373 sRef tref = exprNode_getSref (ecur);
9375 if (sRef_isValid (tref))
9377 sRef tcref = sRef_copy (tref);
9379 if (sRef_isDead (tcref))
9381 sRef_setDefined (tcref, g_currentloc);
9382 sRef_setOnly (tcref, g_currentloc);
9385 if (sRef_isRefCounted (tcref))
9387 /* could be a new ref now (but only if its returned) */
9388 sRef_setAliasKindComplete (tcref, AK_ERROR, g_currentloc);
9391 sRef_makeSafe (tcref);
9393 prefs = sRefSet_insert (prefs, tcref);
9399 } end_uentryList_elements ;
9401 if (sRefSet_size (prefs) > 0)
9403 nstate n = sRef_getNullState (u->sref);
9405 if (sRefSet_size (prefs) == 1)
9407 res = sRefSet_choose (prefs);
9411 res = sRefSet_mergeIntoOne (prefs);
9414 if (nstate_isKnown (n))
9416 sRef_setNullState (res, n, g_currentloc);
9421 if (ctype_isFunction (u->utype))
9423 res = sRef_makeNew (ctype_returnValue (u->utype), u->sref, u->uname);
9427 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
9430 if (sRef_isRefCounted (res))
9432 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
9436 if (sRef_getNullState (res) == NS_ABSNULL)
9438 ctype ct = ctype_realType (u->utype);
9440 if (ctype_isAbstract (ct))
9442 sRef_setNotNull (res, g_currentloc);
9446 if (ctype_isUser (ct))
9448 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
9452 sRef_setNotNull (res, g_currentloc);
9457 if (sRef_isRefCounted (res))
9459 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
9461 else if (sRef_isKillRef (res))
9463 sRef_setAliasKind (res, AK_REFCOUNTED, g_currentloc);
9470 ak = sRef_getAliasKind (res);
9472 if (alkind_isImplicit (ak))
9474 sRef_setAliasKind (res,
9475 alkind_fixImplicit (ak),
9479 sRefSet_free (prefs);
9485 static bool uentry_isRefCounted (uentry ue)
9487 ctype ct = uentry_getType (ue);
9489 if (ctype_isFunction (ct))
9491 return (ctype_isRefCounted (ctype_returnValue (ct)));
9495 return (ctype_isRefCounted (ct));
9500 ** old was declared yield in the specification.
9501 ** new is declared in the iter implementation.
9504 void uentry_checkYieldParam (uentry old, uentry unew)
9508 llassert (uentry_isVariable (old));
9509 llassert (uentry_isVariable (unew));
9511 unew->info->var->kind = VKYIELDPARAM;
9512 (void) checkTypeConformance (old, unew, TRUE);
9513 checkVarConformance (old, unew, TRUE, FALSE);
9515 /* get rid of param marker */
9517 name = uentry_getName (unew);
9518 cstring_free (unew->uname);
9520 unew->info->var->kind = VKREFYIELDPARAM;
9522 uentry_setUsed (old, fileloc_undefined);
9523 uentry_setUsed (unew, fileloc_undefined);
9526 /*@observer@*/ cstring
9527 uentry_ekindName (uentry ue)
9529 if (uentry_isValid (ue))
9534 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
9536 return cstring_makeLiteralTemp ("Datatype");
9538 return cstring_makeLiteralTemp ("Enum member");
9540 return cstring_makeLiteralTemp ("Constant");
9542 if (uentry_isParam (ue))
9544 return cstring_makeLiteralTemp ("Parameter");
9546 else if (uentry_isExpandedMacro (ue))
9548 return cstring_makeLiteralTemp ("Expanded macro");
9552 return cstring_makeLiteralTemp ("Variable");
9555 return cstring_makeLiteralTemp ("Function");
9557 return cstring_makeLiteralTemp ("Iterator");
9559 return cstring_makeLiteralTemp ("Iterator finalizer");
9561 return cstring_makeLiteralTemp ("Struct tag");
9563 return cstring_makeLiteralTemp ("Union tag");
9565 return cstring_makeLiteralTemp ("Enum tag");
9567 return cstring_makeLiteralTemp ("Optional parameters");
9572 return cstring_makeLiteralTemp ("<Undefined>");
9578 void uentry_setHasNameError (uentry ue)
9580 llassert (uentry_isValid (ue));
9582 ue->hasNameError = TRUE;
9585 void uentry_checkName (uentry ue)
9587 if (uentry_isValid (ue)
9588 && !uentry_isElipsisMarker (ue)
9589 && context_getFlag (FLG_NAMECHECKS)
9590 && !ue->hasNameError
9591 && !uentry_isEndIter (ue)
9592 && !fileloc_isBuiltin (uentry_whereLast (ue))
9593 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
9596 if (uentry_isPriv (ue))
9598 ; /* any checks here? */
9600 else if (fileloc_isExternal (uentry_whereDefined (ue)))
9602 ; /* no errors for externals */
9608 if (uentry_isExpandedMacro (ue))
9614 if (uentry_isExpandedMacro (ue))
9618 else if (uentry_isVariable (ue))
9620 sRef sr = uentry_getSref (ue);
9622 if (sRef_isValid (sr))
9624 scope = sRef_getScope (sr);
9631 else if (uentry_isFunction (ue)
9632 || uentry_isIter (ue)
9633 || uentry_isEndIter (ue)
9634 || uentry_isConstant (ue))
9636 scope = uentry_isStatic (ue) ? fileScope : globScope;
9638 else /* datatypes, etc. must be global */
9643 usymtab_checkDistinctName (ue, scope);
9646 if (context_getFlag (FLG_CPPNAMES))
9648 if (checkCppName (uentry_rawName (ue), uentry_whereLast (ue)))
9650 uentry_setHasNameError (ue);
9654 if (scope == globScope)
9656 checkGlobalName (ue);
9658 if (context_getFlag (FLG_ANSIRESERVED))
9660 if (uentry_hasName (ue)
9661 && !uentry_isAnyTag (ue))
9663 if (checkAnsiName (uentry_rawName (ue),
9664 uentry_whereLast (ue)))
9666 uentry_setHasNameError (ue);
9673 checkLocalName (ue);
9675 if (context_getFlag (FLG_ANSIRESERVEDLOCAL))
9677 if (uentry_hasName (ue)
9678 && !uentry_isAnyTag (ue))
9680 if (checkAnsiName (uentry_rawName (ue),
9681 uentry_whereLast (ue)))
9683 uentry_setHasNameError (ue);
9689 DPRINTF (("Check prefix: %s", uentry_unparse (ue)));
9695 /*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@keep@*/ fileloc loc)
9701 ** Can't but unrecognized ids in macros in global scope, because srefs will break! */
9702 if (!context_inMacro ())
9704 sRef_setGlobalScopeSafe ();
9707 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
9708 uentry_setUsed (ue, loc);
9710 tloc = fileloc_createExternal ();
9711 uentry_setDefined (ue, tloc);
9712 fileloc_free (tloc);
9713 uentry_setHasNameError (ue);
9715 if (context_getFlag (FLG_REPEATUNRECOG))
9717 uentry_markOwned (ue);
9721 ue = usymtab_supReturnFileEntry (ue);
9724 if (!context_inMacro ())
9726 sRef_clearGlobalScopeSafe ();
9732 /* new start modifications */
9734 void uentry_testInRange (uentry p_e, uentry cconstant) {
9735 if( uentry_isValid(p_e) ) {
9736 if( sRef_isValid (p_e->sref) ) {
9737 char * t = cstring_toCharsSafe (uentry_unparse(cconstant) );
9738 int index = atoi( t );
9740 usymtab_testInRange (p_e->sref, index);
9745 void uentry_setStringLength (uentry p_e, uentry cconstant) {
9746 if( uentry_isValid(p_e) ) {
9747 if( p_e->info != NULL) {
9748 if( p_e->info->var != NULL) {
9749 char *t = cstring_toCharsSafe (uentry_unparse(cconstant));
9750 int length = atoi( t );
9752 p_e->info->var->bufinfo->len = length;
9753 p_e->sref->bufinfo.len = length;
9754 printf("Set string length of buff to %d \n", p_e->sref->bufinfo.size);
9761 void uentry_setBufferSize (uentry p_e, exprNode cconstant) {
9762 if( uentry_isValid(p_e) ) {
9763 if( p_e->info != NULL) {
9764 if( p_e->info->var != NULL) {
9765 int size = atoi(cstring_toCharsSafe(exprNode_unparse(cconstant) ) );
9766 p_e->info->var->bufinfo->size = size;
9767 p_e->sref->bufinfo.size = size;
9768 printf("Set buffer size to %d \n", p_e->sref->bufinfo.size);
9769 // fprintf(stderr, "For %s and %s\n", uentry_unparse(p_e) );
9770 // fprintf(stderr, "and %d\n", size );
9778 /* start modifications */
9780 requires: p_e is defined, is a ptr/array variable
9782 effects: sets the state of the variable
9785 void uentry_setPossiblyNullTerminatedState (uentry p_e) {
9786 if( uentry_isValid(p_e) ) {
9787 if( p_e->info != NULL) {
9788 if( p_e->info->var != NULL) {
9789 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
9790 p_e->sref->bufinfo.bufstate = BB_POSSIBLYNULLTERMINATED;
9796 fprintf(stderr, "uentry:Error in setPossiblyNullTerminatedState\n");
9800 requires: p_e is defined, is a ptr/array variable
9802 effects: sets the size of the buffer
9805 void uentry_setNullTerminatedState (uentry p_e) {
9806 if( uentry_isValid(p_e) ) {
9807 if( p_e->info != NULL) {
9808 if( p_e->info->var != NULL) {
9809 p_e->info->var->bufinfo->bufstate = BB_NULLTERMINATED;
9810 p_e->sref->bufinfo.bufstate = BB_NULLTERMINATED;
9816 fprintf(stderr, "uentry:Error in setNullTerminatedState\n");
9821 requires: p_e is defined, is a ptr/array variable
9823 effects: sets the state of the variable
9826 void uentry_setNotNullTerminatedState (uentry p_e) {
9827 if( uentry_isValid(p_e) ) {
9828 if( p_e->info != NULL) {
9829 if( p_e->info->var != NULL) {
9830 p_e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
9831 p_e->sref->bufinfo.bufstate = BB_NOTNULLTERMINATED;
9837 fprintf(stderr, "uentry:Error in setNotNullTerminatedState\n");
9842 requires: p_e is defined, is a ptr/array variable
9844 effects: sets the size of the buffer
9847 void uentry_setSize (uentry p_e, int size) {
9848 if( uentry_isValid(p_e) ) {
9849 if( p_e->info != NULL) {
9850 if( p_e->info->var != NULL) {
9851 p_e->info->var->bufinfo->size = size;
9852 p_e->sref->bufinfo.size = size;
9858 fprintf(stderr, "uentry:Error in setSize\n");
9863 requires: p_e is defined, is a ptr/array variable
9865 effects: sets the length of the buffer
9868 void uentry_setLen (uentry p_e, int len) {
9869 if( uentry_isValid(p_e) ) {
9870 if( p_e->info != NULL) {
9871 if( p_e->info->var != NULL) {
9872 p_e->info->var->bufinfo->len = len;
9873 p_e->sref->bufinfo.len = len;
9879 fprintf(stderr, "uentry:Error in setLen\n");