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 /*@only@*/ 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 DPRINTF ( (message ("called uentry_getFcnPreconditions on nonfunction %s",
579 uentry_unparse (ue) ) ) );
580 if (!uentry_isSpecified (ue) )
582 DPRINTF((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*/ DPRINTF( (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 if ((ue->info->fcn->preconditions) != NULL )
1347 constraintList_free(ue->info->fcn->preconditions);
1348 ue->info->fcn->preconditions = preconditions;
1351 ue->info->fcn->preconditions = preconditions;
1366 uentry_setPostconditions (uentry ue, /*@owned@*/ constraintList postconditions)
1368 if (sRef_modInFunction ())
1371 (message ("Postcondition list not in function context. "
1372 "A postcondition list can only appear following the parameter list "
1373 "in a function declaration or header."));
1375 /*@-mustfree@*/ return; /*@=mustfree@*/
1378 if (uentry_isValid (ue))
1381 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
1383 uentry_makeVarFunction (ue);
1386 llassertfatal (uentry_isFunction (ue));
1387 // llassert (sRefSet_isUndefined (ue->info->fcn->mods));
1389 if ((ue->info->fcn->postconditions ) == NULL)
1390 ue->info->fcn->postconditions = postconditions;
1393 constraintList_free(ue->info->fcn->postconditions);
1394 ue->info->fcn->postconditions = postconditions;
1407 ** requires: new and old are functions
1411 checkGlobalsConformance (/*@notnull@*/ uentry old,
1412 /*@notnull@*/ uentry unew,
1413 bool mustConform, bool completeConform)
1415 bool hasInternalState = FALSE;
1417 old->info->fcn->hasGlobs |= unew->info->fcn->hasGlobs;
1419 if (globSet_isDefined (unew->info->fcn->globs))
1421 globSet_allElements (unew->info->fcn->globs, el)
1423 if (sRef_isFileStatic (el))
1425 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1427 if (sRef_isInvalid (sr))
1429 bool hasError = FALSE;
1431 if (!hasInternalState
1432 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1433 sRef_makeInternalState ()))
1434 && sRef_isInvalid (globSet_lookup (old->info->fcn->globs,
1435 sRef_makeSpecState ())))
1438 && !uentry_isStatic (old)
1441 message ("Globals list for %q includes internal state, %q, "
1442 "but %s without globals internalState.",
1443 uentry_getName (old),
1445 uentry_specOrDefName (old)),
1446 uentry_whereLast (unew)))
1448 uentry_showWhereSpecified (old);
1452 old->info->fcn->globs = globSet_insert (old->info->fcn->globs,
1453 sRef_makeInternalState ());
1454 hasInternalState = TRUE;
1458 && fileloc_sameFile (uentry_whereDeclared (unew),
1459 uentry_whereDeclared (old)))
1464 message ("Function %q inconsistently %rdeclared (in "
1465 "same file) with file static global %q in "
1467 uentry_getName (unew),
1468 uentry_isDeclared (old),
1470 uentry_whereDeclared (unew)))
1472 uentry_showWhereSpecified (old);
1477 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1478 context_recordFileGlobals (old->info->fcn->globs);
1482 sRef sr = globSet_lookup (old->info->fcn->globs, el);
1484 if (sRef_isInvalid (sr))
1489 message ("Function %q inconsistently %rdeclared with "
1490 "%q in globals list",
1491 uentry_getName (unew),
1492 uentry_isDeclared (old),
1494 uentry_whereDeclared (unew)))
1496 old->info->fcn->globs = globSet_insert (old->info->fcn->globs, el);
1497 uentry_showWhereSpecified (old);
1502 if (!bool_equal (sRef_isAllocated (el), sRef_isAllocated (sr)))
1508 ("Function %q global %q inconsistently "
1509 "%rdeclared as %qout global",
1510 uentry_getName (unew),
1512 uentry_isDeclared (old),
1513 cstring_makeLiteral (sRef_isAllocated (el) ? "" : "non-")),
1514 uentry_whereDeclared (unew)))
1516 uentry_showWhereSpecified (old);
1521 } end_globSet_allElements ;
1523 if (completeConform)
1525 globSet_allElements (old->info->fcn->globs, el)
1527 sRef sr = globSet_lookup (unew->info->fcn->globs, el);
1529 if (sRef_isInvalid (sr))
1532 && uentry_isReallySpecified (old)
1535 message ("Function %q specified with %q in globals list, "
1536 "but declared without %q",
1537 uentry_getName (unew),
1540 uentry_whereDeclared (unew)))
1542 uentry_showWhereSpecified (old);
1545 } end_globSet_allElements;
1550 if (completeConform && !globSet_isEmpty (old->info->fcn->globs))
1552 if (uentry_isReallySpecified (old)
1555 message ("%s %q specified with globals list, but "
1556 "declared with no globals",
1557 ekind_capName (unew->ukind),
1558 uentry_getName (unew)),
1559 uentry_whereDeclared (unew)))
1562 (message ("Specification globals: %q",
1563 globSet_unparse (old->info->fcn->globs)),
1564 uentry_whereSpecified (old));
1568 unew->info->fcn->globs = globSet_copy (unew->info->fcn->globs,
1569 old->info->fcn->globs);
1574 ** new modifies list must be included by old modifies list.
1576 ** file static state may be added to new, if old has internal.
1580 checkModifiesConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
1581 bool mustConform, bool completeConform)
1584 bool changedMods = FALSE;
1585 bool modInternal = FALSE;
1587 llassert (uentry_isFunction (old) && uentry_isFunction (unew));
1589 old->info->fcn->hasMods |= unew->info->fcn->hasMods;
1590 newMods = unew->info->fcn->mods;
1592 if (sRefSet_isEmpty (newMods))
1594 if (completeConform && !sRefSet_isEmpty (old->info->fcn->mods)
1595 && uentry_isReallySpecified (old))
1599 message ("%s %q specified with modifies clause, "
1600 "but declared with no modifies clause",
1601 ekind_capName (unew->ukind),
1602 uentry_getName (unew)),
1603 uentry_whereDeclared (unew)))
1605 llgenindentmsg (message ("Specification has modifies %q",
1606 sRefSet_unparse (old->info->fcn->mods)),
1607 uentry_whereSpecified (old));
1614 sRefSet_allElements (newMods, current)
1616 if (sRef_isValid (current))
1618 sRef rb = sRef_getRootBase (current);
1620 if (sRef_isFileStatic (rb))
1624 if (!sRefSet_isSameMember (old->info->fcn->mods,
1625 sRef_makeInternalState ())
1626 && !sRefSet_isSameMember (old->info->fcn->mods,
1627 sRef_makeSpecState ()))
1630 && !uentry_isStatic (old)
1634 ("Modifies list for %q includes internal state, "
1635 "but %s without modifies internal.",
1636 uentry_getName (old),
1637 uentry_specOrDefName (old)),
1638 uentry_whereLast (unew)))
1640 uentry_showWhereSpecified (old);
1643 old->info->fcn->mods =
1644 sRefSet_insert (old->info->fcn->mods,
1645 sRef_makeInternalState ());
1650 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1656 if (sRef_canModifyVal (current, old->info->fcn->mods))
1658 int size = sRefSet_size (old->info->fcn->mods);
1660 old->info->fcn->mods = sRefSet_insert (old->info->fcn->mods,
1663 if (sRefSet_size (old->info->fcn->mods) != size)
1674 ("Modifies list for %q contains %q, not modifiable "
1676 uentry_getName (old),
1677 sRef_unparse (current),
1678 uentry_specDeclName (old)),
1679 uentry_whereLast (unew)))
1681 uentry_showWhereSpecified (old);
1686 } end_sRefSet_allElements;
1688 if (completeConform && uentry_isReallySpecified (old))
1690 sRefSet_allElements (old->info->fcn->mods, el)
1692 if (sRef_canModify (el, newMods))
1701 ("Specification modifies clause for %q contains %q, "
1702 "not included in declaration modifies clause",
1703 uentry_getName (old),
1705 uentry_whereLast (unew)))
1707 uentry_showWhereSpecified (old);
1710 } end_sRefSet_allElements ;
1714 ** Make sure file static elements will be removed.
1719 context_recordFileModifies (old->info->fcn->mods);
1724 uentry_checkMutableType (uentry ue)
1726 ctype ct = uentry_getType (ue);
1728 if (!ctype_isRealPointer (ct) && !ctype_isRealAbstract (ct))
1730 voptgenerror (FLG_MUTREP,
1731 message ("Mutable abstract type %q declared without pointer "
1732 "indirection: %t (violates assignment semantics)",
1733 uentry_getName (ue), ct),
1734 uentry_whereDeclared (ue));
1739 uentry_setMutable (uentry e)
1741 llassert (uentry_isDatatype (e));
1742 e->info->datatype->mut = YES;
1746 uentry_checkIterArgs (uentry ue)
1748 bool hasYield = FALSE;
1751 llassert (uentry_isIter (ue));
1753 args = uentry_getParams (ue);
1755 uentryList_elements (args, el)
1757 sstate ds = uentry_getDefState (el);
1759 if (uentry_isYield (el))
1764 if (sstate_isUnknown (ds))
1766 uentry_setDefState (el, SS_DEFINED);
1772 } end_uentryList_elements;
1776 voptgenerror (FLG_HASYIELD,
1777 message ("Iterator %q declared with no yield parameters",
1778 uentry_getName (ue)),
1779 uentry_whereDeclared (ue));
1784 chkind_fromQual (qual qel)
1786 if (qual_isChecked (qel))
1790 else if (qual_isCheckMod (qel))
1794 else if (qual_isCheckedStrict (qel))
1796 return CH_CHECKEDSTRICT;
1798 else if (qual_isUnchecked (qel))
1800 return CH_UNCHECKED;
1805 /*@notreached@*/ return CH_UNKNOWN;
1810 uentry_reflectOtherQualifier (/*@notnull@*/ uentry ue, qual qel)
1812 if (qual_isKillRef (qel) || qual_isNewRef (qel) || qual_isTempRef (qel))
1814 if (!uentry_isRefCounted (ue))
1818 message ("Reference counting qualifier %s used on non-reference "
1819 "counted storage: %q",
1821 uentry_unparse (ue)));
1825 alkind ak = alkind_fromQual (qel);
1827 uentry_setAliasKind (ue, ak);
1830 else if (qual_isRefCounted (qel))
1832 ctype ct = ctype_realType (uentry_getType (ue));
1835 if (ctype_isPointer (ct)
1836 && (ctype_isStruct (rt = ctype_realType (ctype_baseArrayPtr (ct)))))
1838 /* check there is a refs field */
1839 uentryList fields = ctype_getFields (rt);
1840 uentry refs = uentry_undefined;
1842 uentryList_elements (fields, field)
1844 if (uentry_isRefsField (field))
1846 if (uentry_isValid (refs))
1850 message ("Reference counted structure type %s has "
1851 "multiple refs fields: %q and %q",
1853 uentry_getName (refs),
1854 uentry_getName (field)));
1859 } end_uentryList_elements;
1861 if (uentry_isInvalid (refs))
1865 message ("Reference counted structure type %s has "
1867 ctype_unparse (ct)),
1869 ("To count reference, the structure must have a field named "
1870 "refs of type int."),
1873 else if (!ctype_isInt (uentry_getType (refs)))
1877 message ("Reference counted structure type %s refs field has "
1878 "type %s (should be int)", ctype_unparse (ct),
1879 ctype_unparse (uentry_getType (refs))));
1883 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
1884 uentry_whereDeclared (ue));
1889 if ((ctype_isPointer (ct)
1890 && ctype_isUnknown (ctype_realType (ctype_baseArrayPtr (ct))))
1891 ||ctype_isAbstract (ct) || ctype_isUnknown (ct))
1893 sRef_setAliasKind (ue->sref, alkind_fromQual (qel),
1894 uentry_whereDeclared (ue));
1900 message ("Non-pointer to structure type %s declared with "
1901 "refcounted qualifier",
1902 ctype_unparse (ct)));
1906 else if (qual_isRefs (qel))
1908 if (uentry_isVariable (ue) && !uentry_isParam (ue))
1910 uentry_setAliasKind (ue, AK_REFS);
1916 message ("Refs qualifier used on non-structure field: %q",
1917 uentry_unparse (ue)));
1920 else if (qual_isAliasQual (qel))
1922 alkind ak = alkind_fromQual (qel);
1924 alkind oldak = uentry_getAliasKind (ue);
1925 ctype ut = uentry_getType (ue);
1927 if (alkind_isImplicit (ak)
1928 && (alkind_isKnown (oldak) && !alkind_isImplicit (oldak)))
1930 /* ignore the implied qualifier */
1934 if (uentry_isEitherConstant (ue))
1938 message ("Alias qualifier %s used on constant: %q",
1939 alkind_unparse (ak), uentry_unparse (ue)));
1943 if (ctype_isFunction (ut))
1945 ut = ctype_returnValue (ut);
1948 if (!(ctype_isVisiblySharable (ut)
1949 || ctype_isRealArray (ut)
1950 || ctype_isRealSU (ut)))
1952 if (!qual_isImplied (qel))
1956 message ("Alias qualifier %s used on unsharable storage type %t: %q",
1957 alkind_unparse (ak), ut, uentry_getName (ue)));
1964 if (uentry_isRefCounted (ue))
1966 if (!(qual_isRefQual (qel) || qual_isOnly (qel)
1967 || qual_isExposed (qel)
1968 || qual_isObserver (qel)))
1970 if (!qual_isImplied (qel))
1975 ("Alias qualifier %s used on reference counted storage: %q",
1976 alkind_unparse (ak),
1977 uentry_unparse (ue)));
1985 if (qual_isRefQual (qel))
1989 message ("Qualifier %s used on non-reference counted storage: %q",
1990 alkind_unparse (ak), uentry_unparse (ue)));
1999 uentry_setAliasKind (ue, ak);
2002 else if (qual_isNull (qel))
2004 if (uentry_isConstant (ue))
2008 ctype_isAbstract (ue->utype) ? NS_CONSTNULL : NS_DEFNULL,
2009 uentry_whereDeclared (ue));
2013 uentry_setNullState (ue, NS_POSNULL);
2016 else if (qual_isRelNull (qel))
2018 uentry_setNullState (ue, NS_RELNULL);
2020 else if (qual_isNotNull (qel))
2022 uentry_setNullState (ue, NS_MNOTNULL);
2024 else if (qual_isAbstract (qel)
2025 || qual_isConcrete (qel))
2027 if (!uentry_isDatatype (ue))
2031 message ("Qualifier %s used with non-datatype",
2032 qual_unparse (qel)));
2036 ue->info->datatype->abs = ynm_fromBool (qual_isAbstract (qel));
2039 else if (qual_isMutable (qel))
2041 if (!uentry_isDatatype (ue))
2043 llerror (FLG_SYNTAX,
2044 message ("Qualifier %s used with non-datatype", qual_unparse (qel)));
2048 if (!ynm_isOn (ue->info->datatype->mut))
2050 uentry_checkMutableType (ue);
2053 ue->info->datatype->mut = YES;
2056 else if (qual_isImmutable (qel))
2058 if (!uentry_isDatatype (ue))
2060 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-datatype",
2061 qual_unparse (qel)));
2065 ue->info->datatype->mut = NO;
2068 else if (qual_isNullPred (qel))
2070 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2072 uentry_makeVarFunction (ue);
2075 if (uentry_isFunction (ue))
2077 ctype typ = uentry_getType (ue);
2078 ctype rtype = ctype_returnValue (uentry_getType (ue));
2080 if (ctype_isRealBool (rtype))
2082 uentryList pl = ctype_argsFunction (typ);
2084 if (uentryList_size (pl) == 1)
2086 ue->info->fcn->nullPred = qel;
2090 llerror (FLG_SYNTAX,
2091 message ("Qualifier %s used with function having %d "
2092 "arguments (should have 1)",
2094 uentryList_size (pl)));
2099 llerror (FLG_SYNTAX,
2100 message ("Qualifier %s used with function returning %s "
2101 "(should return bool)",
2103 ctype_unparse (rtype)));
2108 llerror (FLG_SYNTAX,
2109 message ("Qualifier %s used with non-function",
2110 qual_unparse (qel)));
2113 else if (qual_isExitQual (qel))
2115 exitkind exk = exitkind_fromQual (qel);
2117 if (uentry_isFunction (ue))
2119 if (exitkind_isKnown (ue->info->fcn->exitCode))
2121 llerror (FLG_SYNTAX,
2122 message ("Multiple exit qualifiers used on function %q: %s, %s",
2123 uentry_getName (ue),
2124 exitkind_unparse (ue->info->fcn->exitCode),
2125 exitkind_unparse (exk)));
2128 ue->info->fcn->exitCode = exk;
2132 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2134 uentry_makeVarFunction (ue);
2135 ue->info->fcn->exitCode = exk;
2139 llerror (FLG_SYNTAX,
2140 message ("Exit qualifier %s used with non-function (type %s)",
2142 ctype_unparse (uentry_getType (ue))));
2148 if (qual_isCQual (qel))
2154 llbug (message ("unhandled qualifier: %s", qual_unparse (qel)));
2160 uentry_reflectQualifiers (uentry ue, qualList q)
2162 llassert (uentry_isValid (ue));
2164 qualList_elements (q, qel)
2166 if (qual_isStatic (qel))
2168 uentry_setStatic (ue);
2170 else if (qual_isUnused (qel))
2172 uentry_setUsed (ue, fileloc_undefined);
2174 else if (qual_isExternal (qel))
2176 fileloc_free (ue->whereDefined);
2177 ue->whereDefined = fileloc_createExternal ();
2179 else if (qual_isSef (qel))
2181 if (uentry_isVariable (ue))
2183 vkind vk = ue->info->var->kind;
2185 llassert (vk != VKREFPARAM);
2187 if (vk == VKYIELDPARAM)
2191 message ("Qualifier sef cannot be used with %s: %q",
2192 cstring_makeLiteralTemp (vk == VKYIELDPARAM ? "yield" : "returned"),
2193 uentry_unparse (ue)));
2195 else if (vk == VKRETPARAM)
2197 ue->info->var->kind = VKSEFRETPARAM;
2201 ue->info->var->kind = VKSEFPARAM;
2208 message ("Qualifier sef is meaningful only on parameters: %q",
2209 uentry_unparse (ue)));
2212 else if (qual_isExtern (qel))
2214 ue->storageclass = SCEXTERN;
2216 else if (qual_isGlobalQual (qel)) /* undef, killed */
2218 if (uentry_isVariable (ue))
2220 sstate oldstate = ue->info->var->defstate;
2221 sstate defstate = sstate_fromQual (qel);
2224 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
2225 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
2227 defstate = SS_UNDEFKILLED;
2234 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2235 ue->info->var->defstate = defstate;
2241 message ("Qualifier %s used on non-variable: %q",
2242 qual_unparse (qel), uentry_unparse (ue)));
2245 /* start modifications */
2247 else if( qual_isBufQualifier(qel) ) {
2248 ctype ct = ctype_realType(uentry_getType(ue));
2250 if( ctype_isArray(ct) || ctype_isPointer(ct) ) {
2252 if( uentry_hasBufStateInfo(ue) ) {
2254 if( qual_isNullTerminated(qel) ) { /* handle Nullterm */
2256 if (uentry_isAnyParam(ue) || uentry_isReturned (ue)) {
2257 /* If formal func param */
2258 uentry_setNullTerminatedState(ue);
2259 uentry_setLen (ue, 1);
2260 uentry_setSize (ue, 1);
2262 sRef_setNullTerminatedState(uentry_getSref(ue));
2263 sRef_setLen (uentry_getSref(ue), 1);
2264 sRef_setSize (uentry_getSref(ue), 1);
2266 uentry_setPossiblyNullTerminatedState(ue);
2268 sRef_setPossiblyNullTerminatedState(uentry_getSref(ue));
2272 /* put other BufState Qualifiers here */
2274 cstring s = uentry_getName(ue);
2275 llfatalbug(message("INTERNAL Error: we have a NULL BufState \
2276 struct for identifier %s\n", s) );
2278 } else if (ctype_isFunction (ct)) { /* We have to handle function */
2280 sRef retSref = uentry_getSref (ue);
2281 ctype retType = sRef_getType (retSref);
2283 if (ctype_isPointer (retType) || ctype_isArray (retType)) {
2284 sRef_setNullTerminatedState (retSref);
2290 message ("Qualifier %s used on non-pointer on \
2291 function return: %q", qual_unparse (qel),
2292 uentry_unparse (ue)));
2299 message ("Qualifier %s used on non-pointer: %q",
2300 qual_unparse (qel), uentry_unparse (ue)));
2303 else if (qual_isAllocQual (qel)) /* out, partial, reldef, special, etc. */
2305 ctype realType = ctype_realType (ue->utype);
2306 sstate defstate = sstate_fromQual (qel);
2308 if (ctype_isFunction (realType))
2310 realType = ctype_realType (ctype_returnValue (realType));
2313 if (qual_isRelDef (qel))
2315 ; /* okay anywhere */
2319 if (!ctype_isAP (realType)
2320 && !ctype_isSU (realType)
2321 && !ctype_isUnknown (realType)
2322 && !ctype_isAbstract (ue->utype))
2326 message ("Qualifier %s used on non-pointer or struct: %q",
2327 qual_unparse (qel), uentry_unparse (ue)));
2331 uentry_setDefState (ue, defstate);
2333 if (sRef_isStateSpecial (ue->sref)
2334 && alkind_isImplicit (sRef_getAliasKind (ue->sref)))
2336 sRef_setAliasKind (ue->sref, AK_ERROR, fileloc_undefined);
2339 else if (qual_isYield (qel))
2341 if (uentry_isVariable (ue))
2343 ue->info->var->kind = VKYIELDPARAM;
2349 message ("Qualifier %s used on non-iterator parameter: %q",
2350 qual_unparse (qel), uentry_unparse (ue)));
2353 else if (qual_isExQual (qel))
2355 exkind ek = exkind_fromQual (qel);
2356 ctype ut = uentry_getType (ue);
2358 if (ctype_isFunction (ut))
2360 ut = ctype_returnValue (ut);
2363 if (!(ctype_isVisiblySharable (ut))
2364 && !(ctype_isArray (ut)) /* can apply to arrays also! */
2365 && !(ctype_isStruct (ctype_realType (ut)))) /* applies to structure fields! */
2367 if (!qual_isImplied (qel))
2371 message ("Qualifier %s used on unsharable storage type %t: %q",
2372 exkind_unparse (ek), ut, uentry_getName (ue)));
2377 alkind ak = sRef_getAliasKind (ue->sref);
2379 sRef_setExKind (ue->sref, ek, uentry_whereDeclared (ue));
2381 if (alkind_isUnknown (ak) || alkind_isImplicit (ak) || alkind_isStatic (ak))
2383 if (!alkind_isTemp (ak))
2385 uentry_setAliasKind (ue, AK_IMPDEPENDENT);
2388 else if (alkind_isDependent (ak) || alkind_isTemp (ak)
2389 || alkind_isOwned (ak))
2397 message ("Exposure qualifier %s used on %s storage (should "
2398 "be dependent): %q",
2400 alkind_unparse (ak),
2401 uentry_unparse (ue)));
2405 else if (qual_isGlobCheck (qel))
2407 if (uentry_isVariable (ue))
2409 chkind ch = chkind_fromQual (qel);
2411 if (ue->info->var->checked != CH_UNKNOWN)
2413 if (ch == ue->info->var->checked)
2415 llerror (FLG_SYNTAX,
2416 message ("Redundant %s qualifier on %q",
2418 uentry_getName (ue)));
2422 llerror (FLG_SYNTAX,
2424 ("Contradictory %s and %s qualifiers on %q",
2426 checkedName (ue->info->var->checked),
2427 uentry_getName (ue)));
2431 ue->info->var->checked = ch;
2437 message ("Qualifier %s used with non-variable",
2438 qual_unparse (qel)));
2441 else if (qual_isReturned (qel))
2443 if (uentry_isVariable (ue))
2445 ue->info->var->kind = VKRETPARAM;
2449 llerror (FLG_SYNTAX, message ("Qualifier %s used with non-variable",
2450 qual_unparse (qel)));
2455 uentry_reflectOtherQualifier (ue, qel);
2458 sRef_storeState (ue->sref);
2459 } end_qualList_elements;
2465 uentry_isOnly (uentry ue)
2467 return (!uentry_isUndefined (ue)
2468 && uentry_isVariable (ue)
2469 && alkind_isOnly (sRef_getOrigAliasKind (ue->sref)));
2473 uentry_setAliasKind (/*@notnull@*/ uentry ue, alkind ak)
2475 sRef_setAliasKind (ue->sref, ak, uentry_whereDeclared (ue));
2476 sRef_setOrigAliasKind (ue->sref, ak);
2480 uentry_setNullState (/*@notnull@*/ uentry ue, nstate ns)
2482 if (uentry_isVariable (ue))
2484 ue->info->var->nullstate = ns;
2487 sRef_setNullState (ue->sref, ns, uentry_whereDeclared (ue));
2491 uentry_isUnique (uentry ue)
2493 return (!uentry_isUndefined (ue)
2494 && uentry_isVariable (ue)
2495 && alkind_isUnique (sRef_getOrigAliasKind (ue->sref)));
2499 uentry_isFileStatic (uentry ue)
2501 return (uentry_isStatic (ue)
2502 && (!uentry_isVariable (ue)
2503 || sRef_isFileStatic (uentry_getSref (ue))));
2507 uentry_isExported (uentry ue)
2509 if (uentry_isValid (ue))
2511 if (uentry_isVariable (ue))
2513 return (sRef_isRealGlobal (uentry_getSref (ue)));
2517 return !uentry_isStatic (ue);
2525 uentry_isNonLocal (uentry ue)
2527 return (uentry_isValid (ue) && uentry_isVariable (ue)
2528 && (sRef_isGlobal (ue->sref) || uentry_isStatic (ue)));
2532 uentry_isGlobal (uentry ue)
2534 return (uentry_isValid (ue) && uentry_isVariable (ue) &&
2535 sRef_isGlobal (ue->sref));
2539 uentry_isPrintfLike (uentry ue)
2541 return (uentry_isFunction (ue)
2542 && (ue->info->fcn->specialCode == SPC_PRINTFLIKE));
2546 uentry_isScanfLike (uentry ue)
2548 return (uentry_isFunction (ue)
2549 && (ue->info->fcn->specialCode == SPC_SCANFLIKE));
2553 uentry_isMessageLike (uentry ue)
2555 return (uentry_isFunction (ue)
2556 && (ue->info->fcn->specialCode == SPC_MESSAGELIKE));
2559 static void checkSpecialFunction (/*@notnull@*/ uentry ue)
2561 uentryList args = uentry_getParams (ue);
2563 if (!uentryList_isMissingParams (args))
2565 uentry last = uentry_undefined;
2567 uentryList_elements (args, current)
2569 if (uentry_isElipsisMarker (current))
2571 if (uentry_isUndefined (last))
2575 message ("Function %q is marked %s, but has no format "
2576 "string argument before elipsis",
2577 uentry_getName (ue),
2578 specCode_unparse (ue->info->fcn->specialCode)),
2579 uentry_whereLast (ue));
2580 ue->info->fcn->specialCode = SPC_NONE;
2584 ctype rt = ctype_realType (uentry_getType (last));
2586 if (!ctype_match (rt, ctype_string))
2590 /* wchar_t * is okay too */
2591 if (ctype_isAP (rt))
2593 ctype base = ctype_baseArrayPtr (rt);
2595 if (ctype_isArbitraryIntegral (base))
2605 message ("Function %q is marked %s, but the argument "
2606 "before the elipsis has type %s (should be char *)",
2607 uentry_getName (ue),
2608 specCode_unparse (ue->info->fcn->specialCode),
2609 ctype_unparse (uentry_getType (last))),
2610 uentry_whereLast (ue));
2612 ue->info->fcn->specialCode = SPC_NONE;
2619 } end_uentryList_elements ;
2623 message ("Function %q is marked %s, but has no elipsis parameter",
2624 uentry_getName (ue),
2625 specCode_unparse (ue->info->fcn->specialCode)),
2626 uentry_whereLast (ue));
2628 ue->info->fcn->specialCode = SPC_NONE;
2633 uentry_setPrintfLike (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_PRINTFLIKE;
2642 checkSpecialFunction (ue);
2646 uentry_setScanfLike (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_SCANFLIKE;
2655 checkSpecialFunction (ue);
2659 uentry_setMessageLike (uentry ue)
2661 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
2663 uentry_makeVarFunction (ue);
2666 llassertfatal (uentry_isFunction (ue));
2667 ue->info->fcn->specialCode = SPC_MESSAGELIKE;
2668 checkSpecialFunction (ue);
2672 uentry_isSpecialFunction (uentry ue)
2674 return (uentry_isFunction (ue)
2675 && (ue->info->fcn->specialCode != SPC_NONE));
2678 /*@notnull@*/ uentry uentry_makeParam (idDecl t, int i)
2680 ctype ct = idDecl_getCtype (t);
2682 sRef pref = sRef_makeParam (i, ct);
2683 uentry ue = uentry_makeVariableSrefParam (idDecl_observeId (t), ct, pref);
2685 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
2686 uentry_implicitParamAnnots (ue);
2688 /* Parameter type [][] or [x][] is invalid */
2690 while (ctype_isFixedArray (base)) {
2691 base = ctype_baseArrayPtr (base);
2694 if (ctype_isIncompleteArray (base)) {
2695 base = ctype_baseArrayPtr (base);
2697 if (ctype_isArray (base)) {
2698 if (!uentry_hasName (ue)) {
2699 (void) optgenerror (FLG_INCOMPLETETYPE,
2700 message ("Unnamed function parameter %d is incomplete type (inner array must have bounds): %s",
2702 ctype_unparse (ct)),
2703 uentry_whereLast (ue));
2705 (void) optgenerror (FLG_INCOMPLETETYPE,
2706 message ("Function parameter %q is incomplete type (inner array must have bounds): %s",
2707 uentry_getName (ue),
2708 ctype_unparse (ct)),
2709 uentry_whereLast (ue));
2717 /*@only@*/ /*@notnull@*/ uentry uentry_makeIdVariable (idDecl t)
2719 ctype ct = idDecl_getCtype (t);
2721 if (ctype_isFunction (ct))
2723 return (uentry_makeIdFunction (t));
2727 fileloc loc = setLocation ();
2728 uentry ue = uentry_makeVariable (idDecl_observeId (t), ct, loc, FALSE);
2730 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
2732 if (!uentry_isExtern (ue))
2734 uentry_setDefined (ue, loc);
2742 /*@notnull@*/ uentry uentry_makeVariableParam (cstring n, ctype t)
2744 return (uentry_makeVariableParamAux (n, t, sRef_makeType (t), SS_DEFINED));
2752 /*@only@*/ /*@notnull@*/
2753 uentry uentry_makeConstantAux (cstring n, ctype t,
2754 /*@keep@*/ fileloc f, bool priv,
2755 /*@only@*/ multiVal m)
2757 uentry e = uentry_alloc ();
2760 e->uname = cstring_copy (n);
2762 e->storageclass = SCNONE;
2764 e->sref = sRef_makeConst (t);
2769 e->uses = filelocList_new ();
2770 e->isPrivate = priv;
2771 e->hasNameError = FALSE;
2773 e->info = (uinfo) dmalloc (sizeof (*e->info));
2774 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
2775 e->info->uconst->val = m;
2776 e->info->uconst->access = typeIdSet_undefined;
2778 uentry_setSpecDef (e, f);
2780 if (multiVal_isInt (m) && (multiVal_forceInt (m) == 0))
2782 sRef_setDefNull (e->sref, uentry_whereDeclared (e));
2788 /*@notnull@*/ uentry uentry_makeConstant (cstring n, ctype t, fileloc f)
2790 return (uentry_makeConstantAux (n, t, f, FALSE, multiVal_unknown ()));
2793 /*@notnull@*/ uentry uentry_makeIdConstant (idDecl t)
2795 uentry ue = uentry_makeConstant (idDecl_observeId (t),
2796 idDecl_getCtype (t),
2799 llassert (fileloc_isUndefined (ue->whereDeclared));
2800 ue->whereDeclared = setLocation ();
2802 uentry_reflectQualifiers (ue, idDecl_getQuals (t));
2811 void uentry_setDefState (uentry ue, sstate defstate)
2813 if (uentry_isValid (ue))
2815 sRef_setDefState (ue->sref, defstate, fileloc_undefined);
2817 if (uentry_isVariable (ue))
2819 ue->info->var->defstate = defstate; /* evs 2000-05-17: fixed bug, was SS_DEFINED! */
2824 bool uentry_isCheckedUnknown (uentry ue)
2826 return (uentry_isVar (ue)
2827 && (ue->info->var->checked == CH_UNKNOWN));
2830 bool uentry_isCheckMod (uentry ue)
2832 return (uentry_isVar (ue)
2833 && (ue->info->var->checked == CH_CHECKMOD));
2836 bool uentry_isUnchecked (uentry ue)
2838 return (uentry_isVar (ue)
2839 && (ue->info->var->checked == CH_UNCHECKED));
2842 bool uentry_isChecked (uentry ue)
2844 return (uentry_isVar (ue)
2845 && (ue->info->var->checked == CH_CHECKED));
2848 bool uentry_isCheckedModify (uentry ue)
2850 return (uentry_isVar (ue)
2851 && (ue->info->var->checked == CH_CHECKED
2852 || ue->info->var->checked == CH_CHECKMOD
2853 || ue->info->var->checked == CH_CHECKEDSTRICT));
2856 bool uentry_isCheckedStrict (uentry ue)
2858 return (uentry_isVar (ue)
2859 && (ue->info->var->checked == CH_CHECKEDSTRICT));
2862 void uentry_setUnchecked (uentry ue)
2864 llassert (uentry_isVar (ue));
2866 ue->info->var->checked = CH_UNCHECKED;
2869 void uentry_setChecked (uentry ue)
2871 llassert (uentry_isVar (ue));
2873 ue->info->var->checked = CH_CHECKED;
2876 void uentry_setCheckMod (uentry ue)
2878 llassert (uentry_isVar (ue));
2880 ue->info->var->checked = CH_CHECKMOD;
2883 void uentry_setCheckedStrict (uentry ue)
2885 llassert (uentry_isVar (ue));
2887 ue->info->var->checked = CH_CHECKEDSTRICT;
2890 static /*@only@*/ /*@notnull@*/
2891 uentry uentry_makeVariableAux (cstring n, ctype t,
2893 /*@exposed@*/ sRef s,
2894 bool priv, vkind kind)
2896 uentry e = uentry_alloc ();
2899 DPRINTF (("Make variable: %s %s %s", n, ctype_unparse (t), sRef_unparse (s)));
2902 e->uname = cstring_copy (n);
2905 e->storageclass = SCNONE;
2912 e->uses = filelocList_new ();
2913 e->isPrivate = priv;
2914 e->hasNameError = FALSE;
2916 e->info = (uinfo) dmalloc (sizeof (*e->info));
2917 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
2918 e->info->var->kind = kind;
2920 e->info->var->checked = CH_UNKNOWN;
2922 uentry_setSpecDef (e, f);
2924 if (ctype_isFunction (rt))
2926 rt = ctype_returnValue (rt);
2929 if (ctype_isUA (rt))
2931 sRef_setStateFromType (e->sref, rt);
2934 e->info->var->defstate = sRef_getDefState (e->sref);
2935 e->info->var->nullstate = sRef_getNullState (e->sref);
2937 /* start modifications */
2938 /* This function sets the uentry for a pointer or array variable declaration,
2939 it allocates memory and sets the fields. We check if the type of the variable
2940 is a pointer or array and allocate a `bbufinfo' struct accordingly */
2942 if( ctype_isArray (t) || ctype_isPointer(t)) {
2943 /*@i222@*/e->info->var->bufinfo = dmalloc( sizeof(*e->info->var->bufinfo) );
2944 e->info->var->bufinfo->bufstate = BB_NOTNULLTERMINATED;
2945 s->bufinfo.bufstate = BB_NOTNULLTERMINATED;
2947 e->info->var->bufinfo = NULL;
2949 /* end modification */
2955 uentry_isYield (uentry ue)
2957 return (uentry_isVariable (ue)
2958 && (ue->info->var->kind == VKYIELDPARAM
2959 || ue->info->var->kind == VKREFYIELDPARAM));
2963 uentry_isRefsField (uentry ue)
2965 return (uentry_isVariable (ue) && sRef_isRefsField (ue->sref));
2968 /*@only@*/ /*@notnull@*/
2969 uentry uentry_makeVariable (cstring n, ctype t, fileloc f, bool isPriv)
2971 return (uentry_makeVariableAux (n, t, f, sRef_makeType (t), isPriv,
2972 fileloc_isSpec (f) ? VKSPEC : VKNORMAL));
2979 void uentry_makeVarFunction (uentry ue)
2986 llassert (uentry_isValid (ue));
2987 llassert (!sRef_modInFunction ());
2989 ak = sRef_getOrigAliasKind (ue->sref);
2990 ek = sRef_getOrigExKind (ue->sref);
2992 oldInfo = ue->info->var;
2994 llassert (ctype_isUnknown (ue->utype) || ctype_isFunction (ue->utype));
2997 ** expanded macro is marked used (until I write a pre-processor)
3000 ue->used |= (oldInfo->kind == VKEXPMACRO);
3003 ue->info->fcn = (ufinfo) dmalloc (sizeof (*ue->info->fcn));
3004 ue->info->fcn->exitCode = XK_UNKNOWN;
3005 ue->info->fcn->nullPred = QU_UNKNOWN;
3006 ue->info->fcn->specialCode = SPC_NONE;
3007 ue->info->fcn->access = typeIdSet_undefined;
3008 ue->info->fcn->hasGlobs = FALSE;
3009 ue->info->fcn->globs = globSet_undefined;
3010 ue->info->fcn->hasMods = FALSE;
3011 ue->info->fcn->mods = sRefSet_undefined;
3012 ue->info->fcn->specclauses = NULL;
3013 ue->info->fcn->defparams = uentryList_undefined;
3016 ue->info->fcn->preconditions = constraintList_undefined;
3020 ue->info->fcn->postconditions = constraintList_undefined;
3024 if (ctype_isFunction (ue->utype))
3026 ue->sref = sRef_makeType (ctype_returnValue (ue->utype));
3030 ue->sref = sRef_makeType (ctype_unknown);
3033 if (sRef_isRefCounted (ue->sref))
3039 if (alkind_isUnknown (ak))
3041 if (exkind_isKnown (ek))
3043 ak = AK_IMPDEPENDENT;
3047 if (context_getFlag (FLG_RETIMPONLY))
3049 if (ctype_isFunction (ue->utype)
3050 && ctype_isVisiblySharable
3051 (ctype_realType (ctype_returnValue (ue->utype))))
3053 if (uentryList_hasReturned (uentry_getParams (ue)))
3067 loc = ue->whereDeclared;
3069 sRef_setAliasKind (ue->sref, ak, loc);
3070 sRef_setNullState (ue->sref, oldInfo->nullstate, loc);
3071 sRef_setDefState (ue->sref, oldInfo->defstate, loc);
3072 sRef_setExKind (ue->sref, ek, loc);
3074 if (oldInfo->kind == VKEXPMACRO)
3077 ue->whereDeclared = fileloc_undefined;
3081 fileloc_free (ue->whereDefined);
3082 ue->whereDefined = fileloc_undefined;
3085 uvinfo_free (oldInfo);
3089 uentry_setGlobals (uentry ue, /*@owned@*/ globSet globs)
3091 llassert (uentry_isValid (ue));
3093 if (uentry_isIter (ue))
3095 llassert (globSet_isUndefined (ue->info->iter->globs));
3096 ue->info->iter->globs = globs;
3100 if (uentry_isVariable (ue) && ctype_isFunction (uentry_getType (ue)))
3102 uentry_makeVarFunction (ue);
3105 llassert (uentry_isFunction (ue));
3106 llassert (!ue->info->fcn->hasGlobs
3107 && globSet_isUndefined (ue->info->fcn->globs));
3109 ue->info->fcn->hasGlobs = TRUE;
3110 /*@-mustfree@*/ ue->info->fcn->globs = globs;
3114 if (globSet_hasStatic (globs))
3116 context_recordFileGlobals (globs);
3119 if (context_getFlag (FLG_GLOBALSIMPMODIFIESNOTHING))
3121 ue->info->fcn->hasMods = TRUE;
3125 void uentry_addAccessType (uentry ue, typeId tid)
3127 if (uentry_isFunction (ue))
3129 ue->info->fcn->access = typeIdSet_insert (ue->info->fcn->access, tid);
3131 else if (uentry_isEitherConstant (ue))
3133 ue->info->uconst->access = typeIdSet_insert (ue->info->uconst->access, tid);
3135 else if (uentry_isIter (ue))
3137 ue->info->iter->access = typeIdSet_insert (ue->info->iter->access, tid);
3139 else if (uentry_isEndIter (ue))
3141 ue->info->enditer->access = typeIdSet_insert (ue->info->enditer->access, tid);
3145 llbug (message ("no access for: %q", uentry_unparse (ue)));
3149 /*@only@*/ /*@notnull@*/ uentry
3150 uentry_makeFunction (cstring n, ctype t,
3152 /*@only@*/ globSet globs, /*@only@*/ sRefSet mods,
3155 return (uentry_makeFunctionAux (n, t,
3156 ((typeId_isInvalid (access)) ? typeIdSet_emptySet ()
3157 : typeIdSet_single (access)),
3163 /*@notnull@*/ uentry
3164 uentry_makePrivFunction2 (cstring n, ctype t,
3166 globSet globs, sRefSet mods,
3169 return (uentry_makeFunctionAux (n, t, access, globs, mods, f, TRUE, FALSE));
3173 /*@notnull@*/ uentry
3174 uentry_makeSpecFunction (cstring n, ctype t,
3176 /*@only@*/ globSet globs,
3177 /*@only@*/ sRefSet mods,
3180 uentry ue = uentry_makeFunctionAux (n, t, access,
3184 uentry_setHasGlobs (ue);
3185 uentry_setHasMods (ue);
3187 reflectImplicitFunctionQualifiers (ue, TRUE);
3192 uentry uentry_makeExpandedMacro (cstring s, fileloc f)
3194 uentry ue = uentry_makeVariableAux (s, ctype_unknown, fileloc_undefined,
3195 sRef_undefined, FALSE, VKEXPMACRO);
3197 uentry_setDefined (ue, f);
3201 /*@notnull@*/ /*@notnull@*/ uentry
3202 uentry_makeForwardFunction (cstring n, typeId access, fileloc f)
3204 uentry ue = uentry_makeFunctionAux (n, ctype_unknown,
3205 typeIdSet_singleOpt (access),
3206 globSet_undefined, sRefSet_undefined,
3210 ue->whereDeclared = fileloc_update (ue->whereDeclared, f);
3214 bool uentry_isForward (uentry e)
3216 if (uentry_isValid (e))
3218 ctype ct = uentry_getType (e);
3220 return (ctype_isUnknown (ct)
3221 || (ctype_isFunction (ct)
3222 && ctype_isUnknown (ctype_returnValue (ct))));
3229 /*@notnull@*/ uentry
3230 uentry_makeTypeListFunction (cstring n, typeIdSet access, fileloc f)
3232 return (uentry_makeFunctionAux (n, ctype_unknown, access,
3238 /*@notnull@*/ uentry
3239 uentry_makeUnspecFunction (cstring n, ctype t,
3243 uentry ue = uentry_makeFunctionAux (n, t, access, globSet_new (),
3244 sRefSet_new (), f, FALSE, TRUE);
3246 reflectImplicitFunctionQualifiers (ue, TRUE);
3255 /* is exported for use by usymtab_interface */
3257 /*@notnull@*/ uentry
3258 uentry_makeDatatypeAux (cstring n, ctype t, ynm mut, ynm abs,
3259 fileloc f, bool priv)
3261 uentry e = uentry_alloc ();
3263 DPRINTF (("Make datatype: %s / %s",
3264 n, ctype_unparse (t)));
3266 /* e->shallowCopy = FALSE; */
3267 e->ukind = KDATATYPE;
3268 e->uname = cstring_copy (n);
3270 e->storageclass = SCNONE;
3271 e->sref = sRef_makeUnknown ();
3275 sRef_setStateFromType (e->sref, t);
3278 uentry_setSpecDef (e, f);
3280 e->uses = filelocList_new ();
3281 e->isPrivate = priv;
3282 e->hasNameError = FALSE;
3287 e->info = (uinfo) dmalloc (sizeof (*e->info));
3288 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3289 e->info->datatype->abs = abs;
3290 e->info->datatype->mut = mut;
3291 e->info->datatype->type = ctype_undefined;
3293 if (uentry_isDeclared (e))
3295 uentry_setDefined (e, f);
3298 if (ynm_isOn (abs) && !(uentry_isCodeDefined (e)))
3300 sRef_setNullState (e->sref, NS_ABSNULL, uentry_whereDeclared (e));
3306 /*@notnull@*/ uentry
3307 uentry_makeDatatype (cstring n, ctype t, ynm mut, ynm abs,
3310 return (uentry_makeDatatypeAux (n, t, mut, abs, f, FALSE));
3313 /*@notnull@*/ uentry uentry_makeBoolDatatype (ynm abs)
3315 uentry ret = uentry_makeDatatypeAux (context_getBoolName (),
3316 ctype_bool, NO, abs,
3317 fileloc_getBuiltin (),
3320 ret->info->datatype->type = ctype_bool;
3328 static /*@only@*/ /*@notnull@*/ uentry
3329 uentry_makeIterAux (cstring n, typeIdSet access, ctype ct,
3330 /*@only@*/ fileloc f)
3332 uentry e = uentry_alloc ();
3335 e->uname = cstring_copy (n);
3337 e->sref = sRef_makeUnknown ();
3338 e->storageclass = SCNONE;
3342 uentry_setSpecDef (e, f);
3344 e->uses = filelocList_new ();
3345 e->isPrivate = FALSE;
3346 e->hasNameError = FALSE;
3348 e->info = (uinfo) dmalloc (sizeof (*e->info));
3349 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
3350 e->info->iter->access = access;
3351 e->info->iter->mods = sRefSet_undefined;
3352 e->info->iter->globs = globSet_undefined;
3354 uentry_checkIterArgs (e);
3358 /*@notnull@*/ uentry uentry_makeIter (cstring n, ctype ct, fileloc f)
3360 return (uentry_makeIterAux (n, context_fileAccessTypes (), ct, f));
3363 static /*@notnull@*/ uentry
3364 uentry_makeEndIterAux (cstring n, typeIdSet access, /*@only@*/ fileloc f)
3366 uentry e = uentry_alloc ();
3368 /* e->shallowCopy = FALSE; */
3369 e->ukind = KENDITER;
3370 e->storageclass = SCNONE;
3371 e->uname = message ("end_%s", n);
3372 e->utype = ctype_unknown;
3373 e->sref = sRef_makeUnknown ();
3375 uentry_setSpecDef (e, f);
3380 e->uses = filelocList_new ();
3381 e->isPrivate = FALSE;
3382 e->hasNameError = FALSE;
3384 e->info = (uinfo) dmalloc (sizeof (*e->info));
3385 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
3387 e->info->enditer->access = access;
3392 /*@notnull@*/ /*@only@*/ uentry uentry_makeEndIter (cstring n, fileloc f)
3394 return (uentry_makeEndIterAux (n, context_fileAccessTypes (), f));
3401 static /*@only@*/ /*@notnull@*/ uentry
3402 uentry_makeTagAux (cstring n, ctype t,
3403 /*@only@*/ fileloc fl,
3404 bool priv, ekind kind)
3406 uentry e = uentry_alloc ();
3408 if (kind != KSTRUCTTAG && kind != KUNIONTAG && kind != KENUMTAG)
3410 llbuglit ("uentry_makeTagAux: not a tag type");
3414 /* e->shallowCopy = FALSE; */
3415 e->uname = cstring_copy (n);
3418 e->sref = sRef_makeUnknown ();
3419 e->storageclass = SCNONE;
3421 uentry_setSpecDef (e, fl);
3426 e->uses = filelocList_new ();
3427 e->isPrivate = priv;
3428 e->hasNameError = FALSE;
3430 e->info = (uinfo) dmalloc (sizeof (*e->info));
3431 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3432 e->info->datatype->abs = NO;
3433 e->info->datatype->mut = (kind == KENUMTAG) ? NO : MAYBE;
3434 e->info->datatype->type = t;
3436 if (uentry_isDeclared (e))
3438 uentry_setDefined (e, fl);
3444 uentry uentry_makeStructTagLoc (cstring n, ctype t)
3446 cstring sname = makeStruct (n);
3447 uentry ret = uentry_makeTagAux (sname, t, setLocation (), FALSE, KSTRUCTTAG);
3449 cstring_free (sname);
3454 uentry_makeStructTag (cstring n, ctype t, fileloc loc)
3456 cstring sname = makeStruct (n);
3457 uentry ret = uentry_makeTagAux (sname, t, loc, FALSE, KSTRUCTTAG);
3459 cstring_free (sname);
3464 uentry_makeUnionTag (cstring n, ctype t, fileloc loc)
3466 cstring uname = makeUnion (n);
3467 uentry ret = uentry_makeTagAux (uname, t, loc, FALSE, KUNIONTAG);
3469 cstring_free (uname);
3475 uentry_makeEnumTag (cstring n, ctype t, fileloc loc)
3477 cstring ename = makeEnum (n);
3478 uentry ret = uentry_makeTagAux (ename, t, loc, FALSE, KENUMTAG);
3480 cstring_free (ename);
3486 uentry_makeUnionTagLoc (cstring n, ctype t)
3488 cstring uname = makeUnion (n);
3489 uentry ret = uentry_makeTagAux (uname, t, setLocation (), FALSE, KUNIONTAG);
3491 cstring_free (uname);
3496 uentry_makeEnumTagLoc (cstring n, ctype t)
3498 cstring ename = makeEnum (n);
3499 uentry ret = uentry_makeTagAux (ename, t, setLocation (), FALSE, KENUMTAG);
3501 cstring_free (ename);
3506 uentry_isStructTag (uentry ue)
3508 return (uentry_isValid (ue) && ue->ukind == KSTRUCTTAG);
3512 uentry_isUnionTag (uentry ue)
3514 return (uentry_isValid (ue) && ue->ukind == KUNIONTAG);
3518 uentry_isEnumTag (uentry ue)
3520 return (uentry_isValid (ue) && ue->ukind == KENUMTAG);
3524 uentry_isAnyTag (uentry ue)
3526 return (uentry_isStructTag (ue)
3527 || uentry_isUnionTag (ue)
3528 || uentry_isEnumTag (ue));
3531 static /*@unchecked@*/ /*@only@*/ uentry emarker = NULL;
3533 extern void uentry_destroyMod (void)
3534 /*@globals killed emarker@*/ /*@modifies emarker@*/
3536 static bool wasDestroyed = FALSE;
3538 llassert (!wasDestroyed);
3540 if (emarker != NULL)
3542 uentry_reallyFree (emarker);
3545 wasDestroyed = TRUE;
3549 uentry_makeElipsisMarker (void)
3551 if (emarker == NULL)
3553 emarker = uentry_alloc ();
3555 emarker->ukind = KELIPSMARKER;
3556 emarker->uname = cstring_makeLiteral ("...");
3557 emarker->utype = ctype_elipsMarker;
3558 emarker->sref = sRef_undefined;
3559 emarker->storageclass = SCNONE;
3560 emarker->used = FALSE;
3561 emarker->lset = FALSE;
3562 emarker->info = NULL;
3564 uentry_setSpecDef (emarker, fileloc_undefined);
3565 emarker->uses = filelocList_new ();
3566 emarker->isPrivate = FALSE;
3567 emarker->hasNameError = FALSE;
3570 /*@ignore@*/ return (emarker); /*@end@*/
3578 uentry_equiv (uentry p1, uentry p2)
3580 if (uentry_compare (p1, p2) != 0)
3591 uentry_xcomparealpha (uentry *p1, uentry *p2)
3595 if ((res = uentry_compare (*p1, *p2)) == 0) {
3596 if ((*p1 != NULL) && (*p2 != NULL)) {
3597 res = cstring_compare ((*p1)->uname,
3606 uentry_xcompareuses (uentry *p1, uentry *p2)
3611 if (uentry_isValid (u1))
3613 if (uentry_isValid (u2))
3615 return (-1 * int_compare (filelocList_size (u1->uses),
3616 filelocList_size (u2->uses)));
3625 if (uentry_isValid (u2))
3637 uentry_compareStrict (uentry v1, uentry v2)
3639 COMPARERETURN (uentry_compare (v1, v2));
3641 if (v1 != v2 && uentry_isValid (v1) && uentry_isValid (v2))
3643 COMPARERETURN (fileloc_compare (v1->whereDeclared, v2->whereDeclared));
3644 COMPARERETURN (fileloc_compare (v1->whereDefined, v2->whereDefined));
3645 COMPARERETURN (fileloc_compare (v1->whereSpecified, v2->whereSpecified));
3652 uentry_compare (uentry u1, uentry u2)
3654 if (u1 == u2) return 0;
3656 if (uentry_isInvalid (u1)) return -1;
3657 if (uentry_isInvalid (u2)) return 1;
3659 INTCOMPARERETURN (u1->ukind, u2->ukind);
3660 COMPARERETURN (ctype_compare (u1->utype, u2->utype));
3661 COMPARERETURN (bool_compare (uentry_isPriv (u1), uentry_isPriv (u2)));
3663 COMPARERETURN (sRef_compare (u1->sref, u2->sref));
3669 /* bug detected by lclint:
3670 ** uentry.c:753,14: Return value type bool does not match declared type int: TRUE
3675 return (multiVal_compare (u1->info->uconst->val,
3676 u2->info->uconst->val));
3680 return (ctype_compare (u1->info->datatype->type, u2->info->datatype->type));
3682 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
3683 uentry_accessType (u2)));
3684 return (uentryList_compareParams (uentry_getParams (u1),
3685 uentry_getParams (u2)));
3687 return (typeIdSet_compare (uentry_accessType (u1),
3688 uentry_accessType (u2)));
3690 COMPARERETURN (typeIdSet_compare (uentry_accessType (u1),
3691 uentry_accessType (u2)));
3692 COMPARERETURN (globSet_compare (uentry_getGlobs (u1),
3693 uentry_getGlobs (u2)));
3694 COMPARERETURN (uentryList_compareParams (uentry_getParams (u1),
3695 uentry_getParams (u2)));
3696 COMPARERETURN (generic_compare (u1->info->fcn->specialCode,
3697 u2->info->fcn->specialCode));
3698 COMPARERETURN (generic_compare (u1->info->fcn->nullPred,
3699 u2->info->fcn->nullPred));
3701 return (sRefSet_compare (uentry_getMods (u1), uentry_getMods (u2)));
3703 COMPARERETURN (generic_compare (u1->info->var->kind, u2->info->var->kind));
3704 COMPARERETURN (generic_compare (sRef_getOrigAliasKind (u1->sref),
3705 sRef_getOrigAliasKind (u2->sref)));
3706 COMPARERETURN (generic_compare (sRef_getOrigExKind (u1->sref),
3707 sRef_getOrigExKind (u2->sref)));
3708 COMPARERETURN (generic_compare (u1->info->var->checked,
3709 u2->info->var->checked));
3710 COMPARERETURN (generic_compare (u1->info->var->defstate,
3711 u2->info->var->defstate));
3712 return (generic_compare (u1->info->var->nullstate,
3713 u2->info->var->nullstate));
3715 COMPARERETURN (ctype_compare (u1->info->datatype->type,
3716 u2->info->datatype->type));
3717 COMPARERETURN (ynm_compare (u1->info->datatype->mut,
3718 u2->info->datatype->mut));
3719 return (ynm_compare (u1->info->datatype->abs, u2->info->datatype->abs));
3728 ** all entries are: <type>[@<info>]*#<name>
3730 ** info depends on kind:
3734 advanceField (char **s)
3740 advanceName (char **s)
3746 vkind_fromInt (int i)
3748 if /*@+enumint@*/ (i < VKFIRST || i > VKLAST) /*@=enumint@*/
3750 llbuglit ("vkind_fromInt: out of range");
3757 uentry_makeConstantBase (/*@only@*/ cstring name, ctype ct,
3758 typeIdSet access, nstate nullstate,
3759 /*@keep@*/ fileloc loc, /*@only@*/ multiVal m)
3761 uentry e = uentry_alloc ();
3766 e->sref = sRef_makeConst (ct);
3768 sRef_setNullState (e->sref, nullstate, loc);
3769 e->storageclass = SCNONE;
3771 if (fileloc_isSpec (loc))
3773 e->whereSpecified = loc;
3774 e->whereDeclared = fileloc_undefined;
3778 e->whereSpecified = fileloc_undefined;
3779 e->whereDeclared = loc;
3782 e->whereDefined = fileloc_undefined;
3783 e->uses = filelocList_new ();
3784 e->isPrivate = FALSE;
3785 e->hasNameError = FALSE;
3790 e->info = (uinfo) dmalloc (sizeof (*e->info));
3791 e->info->uconst = (ucinfo) dmalloc (sizeof (*e->info->uconst));
3792 e->info->uconst->val = m;
3793 e->info->uconst->access = access;
3795 sRef_storeState (e->sref);
3800 static /*@only@*/ uentry
3801 uentry_makeVariableBase (/*@only@*/ cstring name, ctype ct, vkind kind,
3802 sstate defstate, nstate isnull, alkind aliased,
3803 exkind exp, chkind checked,
3804 /*@only@*/ fileloc loc)
3806 uentry e = uentry_alloc ();
3811 e->storageclass = SCNONE;
3813 e->sref = sRef_makeType (ct);
3814 sRef_setNullState (e->sref, isnull, loc);
3816 e->whereDefined = fileloc_undefined;
3818 if (fileloc_isSpec (loc))
3820 e->whereSpecified = loc;
3821 e->whereDeclared = fileloc_undefined;
3825 e->whereSpecified = fileloc_undefined;
3826 e->whereDeclared = loc;
3829 e->isPrivate = FALSE;
3830 e->hasNameError = FALSE;
3835 e->uses = filelocList_new ();
3837 e->info = (uinfo) dmalloc (sizeof (*e->info));
3838 e->info->var = (uvinfo) dmalloc (sizeof (*e->info->var));
3839 e->info->var->kind = kind;
3840 e->info->var->checked = checked;
3841 e->info->var->defstate = defstate;
3843 sRef_setDefState (e->sref, defstate, loc);
3845 e->info->var->nullstate = sRef_getNullState (e->sref);
3847 sRef_setExKind (e->sref, exp, loc);
3848 sRef_setAliasKind (e->sref, aliased, loc);
3850 sRef_storeState (e->sref);
3852 /*DRL ADDED 9-1-2000 */
3853 e->info->var->bufinfo = NULL;
3858 static /*@only@*/ uentry
3859 uentry_makeDatatypeBase (/*@only@*/ cstring name, ctype ct, ynm abs,
3860 ynm mut, ctype rtype, alkind ak, exkind exp,
3861 sstate defstate, nstate isnull,
3862 /*@only@*/ fileloc loc)
3864 uentry e = uentry_alloc ();
3866 e->ukind = KDATATYPE;
3867 /* e->shallowCopy = FALSE; */
3870 e->storageclass = SCNONE;
3871 e->sref = sRef_makeUnknown ();
3874 ** This is only setting null state. (I think?)
3877 if (ctype_isUA (ct))
3879 uentry te = usymtab_getTypeEntrySafe (ctype_typeId (ct));
3881 if (uentry_isValid (te))
3883 sRef_setStateFromUentry (e->sref, te);
3887 /* problem for recursive type definitions */
3891 sRef_setAliasKind (e->sref, ak, loc);
3892 sRef_setExKind (e->sref, exp, loc);
3894 sRef_setDefState (e->sref, defstate, loc);
3896 if (ynm_isOn (abs) && ctype_isUnknown (ct) && isnull == NS_UNKNOWN)
3898 isnull = NS_ABSNULL;
3901 sRef_mergeNullState (e->sref, isnull);
3903 e->whereDefined = fileloc_copy (loc); /*< bogus! (but necessary for lexer) >*/
3905 if (fileloc_isSpec (loc))
3907 e->whereSpecified = loc;
3908 e->whereDeclared = fileloc_undefined;
3912 e->whereSpecified = fileloc_undefined;
3913 e->whereDeclared = loc;
3916 e->isPrivate = FALSE;
3917 e->hasNameError = FALSE;
3921 e->uses = filelocList_new ();
3923 e->info = (uinfo) dmalloc (sizeof (*e->info));
3924 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
3925 e->info->datatype->abs = abs;
3926 e->info->datatype->mut = mut;
3927 e->info->datatype->type = rtype;
3929 sRef_storeState (e->sref);
3935 static void uentry_setHasGlobs (uentry ue)
3937 llassert (uentry_isFunction (ue));
3939 ue->info->fcn->hasGlobs = TRUE;
3942 static void uentry_setHasMods (uentry ue)
3944 llassert (uentry_isFunction (ue));
3946 ue->info->fcn->hasMods = TRUE;
3950 bool uentry_hasGlobs (uentry ue)
3952 if (uentry_isFunction (ue))
3954 return (ue->info->fcn->hasGlobs);
3960 bool uentry_hasSpecialClauses (uentry ue)
3962 return (uentry_isFunction (ue) && specialClauses_isDefined (ue->info->fcn->specclauses));
3965 specialClauses uentry_getSpecialClauses (uentry ue)
3967 llassert (uentry_isFunction (ue));
3968 return ue->info->fcn->specclauses;
3971 bool uentry_hasMods (uentry ue)
3973 if (uentry_isFunction (ue))
3975 return (ue->info->fcn->hasMods);
3982 uentry_makeFunctionBase (/*@only@*/ cstring name, ctype ct,
3984 bool hasGlobs, /*@only@*/ globSet globs,
3985 bool hasMods, /*@only@*/ sRefSet mods,
3986 alkind ak, exkind exp,
3987 sstate defstate, nstate isnull,
3991 /*@only@*/ specialClauses specclauses,
3992 /*@only@*/ fileloc loc)
3994 uentry e = uentry_alloc ();
3997 /* e->shallowCopy = FALSE; */
4001 e->storageclass = SCNONE;
4003 if (ctype_isFunction (ct))
4005 ret = ctype_returnValue (ct);
4009 if (ctype_isKnown (ct))
4011 llbug (message ("not function: %s", ctype_unparse (ct)));
4014 ret = ctype_unknown;
4017 e->sref = sRef_makeType (ret);
4019 if (ctype_isUA (ret))
4021 sRef_setStateFromType (e->sref, ret);
4024 sRef_setDefined (e->sref, loc);
4025 sRef_setNullState (e->sref, isnull, loc);
4027 sRef_setAliasKind (e->sref, ak, loc);
4028 sRef_setExKind (e->sref, exp, loc);
4029 sRef_setDefState (e->sref, defstate, loc);
4031 e->whereSpecified = loc;
4032 e->whereDefined = fileloc_undefined;
4034 e->isPrivate = FALSE;
4035 e->hasNameError = FALSE;
4039 e->uses = filelocList_new ();
4041 e->info = (uinfo) dmalloc (sizeof (*e->info));
4042 e->info->fcn = (ufinfo) dmalloc (sizeof (*e->info->fcn));
4044 e->info->fcn->exitCode = exitCode;
4045 e->info->fcn->specialCode = sCode;
4046 e->info->fcn->nullPred = nullPred;
4047 e->info->fcn->access = access;
4049 e->info->fcn->specclauses = specclauses;
4050 e->info->fcn->hasGlobs = hasGlobs;
4051 e->info->fcn->globs = globs;
4053 e->info->fcn->hasMods = hasMods;
4054 e->info->fcn->mods = mods;
4056 e->info->fcn->defparams = uentryList_undefined;
4057 e->whereDeclared = fileloc_undefined;
4059 sRef_storeState (e->sref);
4062 e->info->fcn->preconditions = NULL;
4066 e->info->fcn->postconditions = NULL;
4072 static /*@only@*/ uentry
4073 uentry_makeTagBase (/*@only@*/ cstring name, ekind tagkind,
4074 ctype ct, ctype rtype, /*@only@*/ fileloc loc)
4076 uentry e = uentry_alloc ();
4078 if (tagkind != KSTRUCTTAG && tagkind != KUNIONTAG && tagkind != KENUMTAG)
4080 llbuglit ("uentry_makeTagBase: not a tag type");
4083 /* e->shallowCopy = FALSE; */
4087 e->sref = sRef_makeUnknown ();
4088 e->storageclass = SCNONE;
4090 if (fileloc_isSpec (loc))
4092 e->whereSpecified = loc;
4093 e->whereDeclared = fileloc_undefined;
4097 e->whereDeclared = loc;
4098 e->whereSpecified = fileloc_undefined;
4101 e->whereDefined = fileloc_undefined;
4103 e->isPrivate = FALSE;
4104 e->hasNameError = FALSE;
4108 e->uses = filelocList_new ();
4110 e->info = (uinfo) dmalloc (sizeof (*e->info));
4111 e->info->datatype = (udinfo) dmalloc (sizeof (*e->info->datatype));
4112 e->info->datatype->abs = NO;
4113 e->info->datatype->mut = MAYBE;
4114 e->info->datatype->type = rtype;
4116 sRef_storeState (e->sref);
4122 uentry_makeIterBase (/*@only@*/ cstring name, typeIdSet access,
4123 ctype ct, /*@only@*/ fileloc loc)
4125 uentry e = uentry_alloc ();
4127 /* e->shallowCopy = FALSE; */
4131 e->sref = sRef_makeUnknown ();
4132 e->storageclass = SCNONE;
4134 if (fileloc_isSpec (loc))
4136 e->whereSpecified = loc;
4137 e->whereDeclared = fileloc_undefined;
4141 e->whereDeclared = loc;
4142 e->whereSpecified = fileloc_undefined;
4145 e->whereDefined = fileloc_undefined;
4147 e->isPrivate = FALSE;
4148 e->hasNameError = FALSE;
4152 e->uses = filelocList_new ();
4154 e->info = (uinfo) dmalloc (sizeof (*e->info));
4155 e->info->iter = (uiinfo) dmalloc (sizeof (*e->info->iter));
4156 e->info->iter->access = access;
4157 e->info->iter->mods = sRefSet_undefined;
4158 e->info->iter->globs = globSet_undefined;
4160 sRef_storeState (e->sref);
4165 uentry_makeEndIterBase (/*@only@*/ cstring name, typeIdSet access,
4166 /*@only@*/ fileloc loc)
4168 uentry e = uentry_alloc ();
4170 /* e->shallowCopy = FALSE; */
4171 e->ukind = KENDITER;
4172 e->storageclass = SCNONE;
4174 e->utype = ctype_unknown;
4175 e->sref = sRef_makeUnknown ();
4177 if (fileloc_isSpec (loc))
4179 e->whereSpecified = loc;
4180 e->whereDeclared = fileloc_undefined;
4184 e->whereDeclared = loc;
4185 e->whereSpecified = fileloc_undefined;
4188 e->whereDefined = fileloc_undefined;
4190 e->isPrivate = FALSE;
4191 e->hasNameError = FALSE;
4195 e->uses = filelocList_new ();
4197 e->info = (uinfo) dmalloc (sizeof (*e->info));
4198 e->info->enditer = (ueinfo) dmalloc (sizeof (*e->info->enditer));
4199 e->info->enditer->access = access;
4200 sRef_storeState (e->sref);
4205 void uentry_markFree (/*@unused@*/ /*@owned@*/ uentry u)
4213 uentry_undump (ekind kind, fileloc loc, char **s)
4221 ue = uentry_makeElipsisMarker ();
4225 ctype ct = ctype_undump (s);
4241 if (optCheckChar (s, '@'))
4243 tkind = vkind_fromInt (getInt (s));
4251 if (optCheckChar (s, '$'))
4253 defstate = SS_UNKNOWN;
4254 isnull = NS_UNKNOWN;
4255 aliased = AK_IMPTEMP;
4257 checked = CH_UNKNOWN;
4259 else if (optCheckChar (s, '&'))
4261 defstate = SS_DEFINED;
4262 isnull = NS_UNKNOWN;
4263 aliased = AK_IMPTEMP;
4265 checked = CH_UNKNOWN;
4267 else if (optCheckChar (s, '^'))
4269 defstate = SS_UNKNOWN;
4270 isnull = NS_UNKNOWN;
4271 aliased = AK_IMPTEMP;
4273 checked = CH_UNKNOWN;
4277 defstate = sstate_fromInt (getInt (s));
4278 advanceField (s); isnull = nstate_fromInt (getInt (s));
4279 advanceField (s); aliased = alkind_fromInt (getInt (s));
4281 if (optCheckChar (s, '&'))
4284 checked = CH_UNKNOWN;
4288 advanceField (s); exp = exkind_fromInt (getInt (s));
4289 advanceField (s); checked = (chkind) (getInt (s));
4294 name = getStringWord (s);
4296 ue = uentry_makeVariableBase (name, ct, tkind, defstate,
4297 isnull, aliased, exp,
4298 checked, fileloc_copy (loc));
4311 advanceField (s); abs = ynm_fromCodeChar (loadChar (s));
4312 advanceField (s); mut = ynm_fromCodeChar (loadChar (s));
4313 advanceField (s); defstate = sstate_fromInt (getInt (s));
4314 advanceField (s); isnull = nstate_fromInt (getInt (s));
4315 advanceField (s); aliased = alkind_fromInt (getInt (s));
4316 advanceField (s); exp = exkind_fromInt (getInt (s));
4317 advanceField (s); rtype = ctype_undump (s);
4319 name = getStringWord (s);
4321 ue = uentry_makeDatatypeBase (name, ct, abs, mut, rtype,
4322 aliased, exp, defstate, isnull,
4323 fileloc_copy (loc));
4340 specialClauses specclauses;
4342 if (optCheckChar (s, '$'))
4344 defstate = SS_DEFINED;
4345 isnull = NS_UNKNOWN;
4346 exitCode = XK_UNKNOWN;
4348 nullPred = QU_UNKNOWN;
4352 advanceField (s); defstate = sstate_fromInt (getInt (s));
4353 advanceField (s); isnull = nstate_fromInt (getInt (s));
4354 advanceField (s); exitCode = exitkind_fromInt (getInt (s));
4355 advanceField (s); specc = specCode_fromInt (getInt (s));
4356 advanceField (s); nullPred = qual_fromInt (getInt (s));
4359 if (optCheckChar (s, '$'))
4362 globs = globSet_undefined;
4364 mods = sRefSet_undefined;
4366 else if (optCheckChar (s, '^'))
4369 globs = globSet_undefined;
4371 mods = sRefSet_undefined;
4375 advanceField (s); hasGlobs = bool_fromInt (getInt (s));
4376 advanceField (s); globs = globSet_undump (s);
4377 advanceField (s); hasMods = bool_fromInt (getInt (s));
4378 advanceField (s); mods = sRefSet_undump (s);
4381 if (optCheckChar (s, '$'))
4388 advanceField (s); ak = alkind_fromInt (getInt (s));
4389 advanceField (s); exp = exkind_fromInt (getInt (s));
4392 advanceField (s); access = typeIdSet_undump (s);
4394 if (optCheckChar (s, '@'))
4396 specclauses = specialClauses_undump (s);
4400 specclauses = specialClauses_undefined;
4403 advanceName (s); name = getStringWord (s);
4405 ue = uentry_makeFunctionBase (name, ct, access,
4408 ak, exp, defstate, isnull,
4409 exitCode, specc, nullPred,
4411 fileloc_copy (loc));
4412 DPRINTF (("Undump: %s", uentry_unparse (ue)));
4419 advanceField (s); access = typeIdSet_undump (s);
4420 advanceName (s); name = getStringWord (s);
4422 ue = uentry_makeIterBase (name, access, ct,
4423 fileloc_copy (loc));
4430 advanceField (s); access = typeIdSet_undump (s);
4431 advanceName (s); name = getStringWord (s);
4433 ue = uentry_makeEndIterBase (name, access, fileloc_copy (loc));
4443 if (optCheckChar (s, '$'))
4445 val = multiVal_undefined;
4446 access = typeIdSet_undefined;
4447 nullstate = NS_UNKNOWN;
4451 advanceField (s); val = multiVal_undump (s);
4452 advanceField (s); access = typeIdSet_undump (s);
4453 advanceField (s); nullstate = nstate_fromInt (getInt (s));
4456 advanceName (s); name = getStringWord (s);
4458 ue = uentry_makeConstantBase (name, ct, access,
4459 nullstate, fileloc_copy (loc), val);
4468 advanceField (s); rtype = ctype_undump (s);
4469 advanceName (s); name = getStringWord (s);
4470 ue = uentry_makeTagBase (name, kind, ct, rtype, fileloc_copy (loc));
4474 llcontbuglit ("uentry_undump: invalid");
4475 ue = uentry_undefined;
4478 llcontbuglit ("uentry_undump: elips marker");
4479 ue = uentry_undefined;
4488 uentry_dump (uentry v)
4490 return (uentry_dumpAux (v, FALSE));
4494 uentry_dumpParam (uentry v)
4496 llassertprint (uentry_isVariable (v) || uentry_isElipsisMarker (v),
4497 ("dump: %s", uentry_unparseFull (v)));
4499 return (uentry_dumpAux (v, TRUE));
4503 uentry_dumpAux (uentry v, bool isParam)
4505 llassert (uentry_isValid (v));
4507 DPRINTF (("Dumping entry: %s", uentry_unparseFull (v)));
4512 llcontbuglit ("uentry_dump: invalid entry");
4513 return cstring_undefined;
4515 return (message ("!."));
4519 vkind vk = v->info->var->kind;
4520 sstate dss = sRef_getDefState (v->sref);
4521 nstate nst = sRef_getNullState (v->sref);
4522 alkind alk = sRef_getAliasKind (v->sref);
4523 exkind exk = sRef_getExKind (v->sref);
4524 chkind chk = v->info->var->checked;
4526 DPRINTF (("Dumping var"));
4528 if (dss == SS_UNKNOWN
4529 && nst == NS_UNKNOWN
4530 && alk == AK_IMPTEMP
4531 && exk == XO_UNKNOWN
4532 && chk == CH_UNKNOWN)
4534 sdump = cstring_makeLiteral ("$");
4536 else if (dss == SS_DEFINED
4537 && nst == NS_UNKNOWN
4538 && alk == AK_IMPTEMP
4539 && exk == XO_UNKNOWN
4540 && chk == CH_UNKNOWN)
4542 sdump = cstring_makeLiteral ("&");
4544 else if (dss == SS_UNKNOWN
4545 && nst == NS_UNKNOWN
4546 && alk == AK_UNKNOWN
4547 && exk == XO_UNKNOWN
4548 && chk == CH_UNKNOWN)
4550 sdump = cstring_makeLiteral ("^");
4552 else if (exk == XO_UNKNOWN
4553 && chk == CH_UNKNOWN)
4555 sdump = message ("%d@%d@%d&",
4562 sdump = message ("%d@%d@%d@%d@%d",
4573 return (message ("%q|@%d|%q#%s",
4574 ctype_dump (v->utype),
4577 isParam ? cstring_undefined : v->uname));
4581 return (message ("%q|%q#%s",
4582 ctype_dump (v->utype),
4584 isParam ? cstring_undefined : v->uname));
4589 return (message ("%q@%s@%s@%d@%d@%d@%d@%q#%s",
4590 ctype_dump (v->utype),
4591 ynm_unparseCode (v->info->datatype->abs),
4592 ynm_unparseCode (v->info->datatype->mut),
4593 (int) sRef_getDefState (v->sref),
4594 (int) sRef_getNullState (v->sref),
4595 (int) sRef_getAliasKind (v->sref),
4596 (int) sRef_getExKind (v->sref),
4597 ctype_dump (v->info->datatype->type),
4601 cstring sdump, gdump, adump;
4602 alkind alk = sRef_getAliasKind (v->sref);
4603 exkind exk = sRef_getExKind (v->sref);
4605 if (sRef_getDefState (v->sref) == SS_DEFINED
4606 && !nstate_isKnown (sRef_getNullState (v->sref))
4607 && !exitkind_isKnown (v->info->fcn->exitCode)
4608 && v->info->fcn->specialCode == SPC_NONE
4609 && v->info->fcn->nullPred == QU_UNKNOWN)
4611 sdump = cstring_makeLiteral ("$");
4615 sdump = message ("@%d@%d@%d@%d@%d",
4616 (int) sRef_getDefState (v->sref),
4617 (int) sRef_getNullState (v->sref),
4618 (int) v->info->fcn->exitCode,
4619 (int) v->info->fcn->specialCode,
4620 (int) v->info->fcn->nullPred);
4623 if (!uentry_hasGlobs(v) && !uentry_hasMods (v))
4625 gdump = cstring_makeLiteral ("$");
4627 else if (uentry_hasGlobs (v) && globSet_isEmpty (uentry_getGlobs (v))
4628 && uentry_hasMods (v) && sRefSet_isEmpty (uentry_getMods (v)))
4630 gdump = cstring_makeLiteral ("^");
4634 gdump = message ("@%s@%q@%s@%q",
4635 bool_dump (uentry_hasGlobs (v)),
4636 globSet_dump (uentry_getGlobs (v)),
4637 bool_dump (uentry_hasMods (v)),
4638 sRefSet_dump (uentry_getMods (v)));
4641 if (alk == AK_UNKNOWN && exk == XO_UNKNOWN)
4643 adump = cstring_makeLiteral ("$");
4647 adump = message ("@%d@%d", (int) alk, (int) exk);
4650 if (uentry_hasSpecialClauses (v))
4652 return (message ("%q%q%q%q@%q@%q#%s",
4653 ctype_dump (v->utype),
4657 typeIdSet_dump (uentry_accessType (v)),
4658 specialClauses_dump (v->info->fcn->specclauses),
4663 return (message ("%q%q%q%q@%q#%s",
4664 ctype_dump (v->utype),
4668 typeIdSet_dump (uentry_accessType (v)),
4673 return (message ("%q@%q#%s",
4674 ctype_dump (v->utype),
4675 typeIdSet_dump (v->info->iter->access),
4678 return (message ("%q@%q#%s",
4679 ctype_dump (v->utype),
4680 typeIdSet_dump (uentry_accessType (v)),
4687 if (multiVal_isUnknown (v->info->uconst->val)
4688 && typeIdSet_isEmpty (uentry_accessType (v))
4689 && (sRef_getNullState (v->sref) == NS_UNKNOWN))
4691 sdump = cstring_makeLiteral ("$");
4695 sdump = message ("@%q@%q@%d",
4696 multiVal_dump (v->info->uconst->val),
4697 typeIdSet_dump (uentry_accessType (v)),
4698 (int) sRef_getNullState (v->sref));
4701 return (message ("%q%q#%s",
4702 ctype_dump (v->utype),
4709 return (message ("%q@%q#%s",
4710 ctype_dump (v->utype),
4711 ctype_dump (v->info->datatype->type), v->uname));
4718 uentry_unparseAbbrev (uentry v)
4720 if (!uentry_isVariable (v))
4722 llcontbuglit ("uentry_unparseAbbrev: not variable");
4723 return uentry_unparse (v);
4726 return (message ("%s %q", ctype_unparseDeep (v->utype), uentry_getName (v)));
4730 uentry_unparse (uentry v)
4734 if (uentry_isUndefined (v)) return (cstring_makeLiteral ("<undefined>"));
4735 if (uentry_isElipsisMarker (v)) return (cstring_makeLiteral ("..."));
4737 st = uentry_getName (v);
4739 if (cstring_isDefined (st))
4741 return (ctype_unparseDeclaration (v->utype, st));
4746 return (cstring_copy (ctype_unparse (v->utype)));
4751 uentry_unparseFull (uentry v)
4753 if (uentry_isUndefined (v))
4755 return (cstring_makeLiteral ("<undefined>"));
4757 else if (uentry_isDatatype (v))
4759 return (message ("[%d] [%s] %s %q : %t [%t] %s %s // %q [s: %q; d: %q]",
4761 ekind_unparse (v->ukind),
4765 ctype_isDefined (v->info->datatype->type)
4766 ? v->info->datatype->type : ctype_unknown,
4767 ynm_unparse (v->info->datatype->mut),
4768 ynm_unparse (v->info->datatype->abs),
4769 sRef_unparseState (v->sref),
4770 fileloc_unparse (v->whereSpecified),
4771 fileloc_unparse (v->whereDefined)));
4773 else if (uentry_isFunction (v))
4775 return (message ("[%w] = [%s] %q : %t / sref: %q / mods: %q / "
4776 "globs: %q / [s: %q; decl: %q; def: %q]",
4778 ekind_unparse (v->ukind),
4781 sRef_unparseFull (v->sref),
4782 sRefSet_unparse (v->info->fcn->mods),
4783 globSet_unparse (v->info->fcn->globs),
4784 fileloc_unparse (v->whereSpecified),
4785 fileloc_unparse (v->whereDeclared),
4786 fileloc_unparse (v->whereDefined)));
4788 else if (uentry_isIter (v))
4790 return (message ("[%s] %q: %t / %q [s: %q; d: %q]",
4791 ekind_unparse (v->ukind),
4794 sRef_unparseFull (v->sref),
4795 fileloc_unparse (v->whereSpecified),
4796 fileloc_unparse (v->whereDefined)));
4798 else if (uentry_isVariable (v))
4801 (message ("[check: %s] / [%w] = [%s] %s : %t %q [s: %q; def: %q; dec: %q] "
4802 "kind <%d> isout <%d> used <%d>",
4803 checkedName (v->info->var->checked),
4805 ekind_unparse (v->ukind),
4808 sRef_unparseDeep (v->sref),
4809 fileloc_unparse (v->whereSpecified),
4810 fileloc_unparse (v->whereDefined),
4811 fileloc_unparse (v->whereDeclared),
4812 (int) v->info->var->kind,
4813 (int) v->info->var->defstate,
4818 return (message ("[%s] %s : %t %q at [s: %q; d: %q]",
4819 ekind_unparse (v->ukind),
4822 sRef_unparseFull (v->sref),
4823 fileloc_unparse (v->whereSpecified),
4824 fileloc_unparse (v->whereDefined)));
4829 bool uentry_hasAccessType (uentry e)
4831 if (uentry_isValid (e))
4836 return (!typeIdSet_isEmpty (e->info->iter->access));
4838 return (!typeIdSet_isEmpty (e->info->enditer->access));
4840 return (!typeIdSet_isEmpty (e->info->fcn->access));
4843 return (!typeIdSet_isEmpty (e->info->uconst->access));
4852 typeIdSet uentry_accessType (uentry e)
4854 if (uentry_isValid (e))
4859 return (e->info->iter->access);
4861 return (e->info->enditer->access);
4863 return (e->info->fcn->access);
4866 return (e->info->uconst->access);
4872 return typeIdSet_undefined;
4876 uentry_isVariable (uentry e)
4878 return (uentry_isVar (e));
4882 uentry_isSpecified (uentry e)
4884 return (uentry_isValid (e) && !fileloc_isUndefined (e->whereSpecified));
4888 uentry_isReallySpecified (uentry e)
4890 return (uentry_isValid (e)
4891 && fileloc_isRealSpec (e->whereSpecified));
4895 uentry_isVar (uentry e)
4897 return (!uentry_isUndefined (e) && e->ukind == KVAR);
4901 uentry_isFakeTag (uentry e)
4903 return (uentry_isValid (e) && strchr (cstring_toCharsSafe (e->uname), '!') != 0);
4907 uentry_isDatatype (uentry e)
4909 return (!uentry_isUndefined (e) &&
4910 (e->ukind == KDATATYPE || e->ukind == KSTRUCTTAG ||
4911 e->ukind == KUNIONTAG || e->ukind == KENUMTAG));
4915 uentry_setAbstract (uentry e)
4919 llassert (uentry_isDatatype (e)
4920 && (ynm_isMaybe (e->info->datatype->abs)));
4922 oldid = ctype_typeId (e->info->datatype->type);
4923 e->info->datatype->abs = YES;
4924 e->info->datatype->type = ctype_createAbstract (oldid);
4928 uentry_setConcrete (uentry e)
4930 llassert (uentry_isDatatype (e)
4931 && (ynm_isMaybe (e->info->datatype->abs)));
4933 e->info->datatype->abs = NO;
4937 uentry_isAbstractDatatype (uentry e)
4939 return (uentry_isDatatype (e)
4940 && (ynm_isOn (e->info->datatype->abs)));
4944 uentry_isMaybeAbstract (uentry e)
4946 return (uentry_isDatatype (e)
4947 && (ynm_isMaybe (e->info->datatype->abs)));
4951 uentry_isMutableDatatype (uentry e)
4953 bool res = uentry_isDatatype (e)
4954 && (ynm_toBoolRelaxed (e->info->datatype->mut));
4960 uentry_isRefCountedDatatype (uentry e)
4962 return (uentry_isDatatype (e) && (sRef_isRefCounted (uentry_getSref (e))));
4966 uentry_isParam (uentry u)
4968 return (uentry_isVariable (u) && (u->info->var->kind == VKPARAM
4969 || u->info->var->kind == VKYIELDPARAM));
4973 uentry_isExpandedMacro (uentry u)
4975 return (uentry_isVariable (u) && (u->info->var->kind == VKEXPMACRO));
4979 uentry_isSefParam (uentry u)
4981 return (uentry_isVariable (u)
4982 && (u->info->var->kind == VKSEFPARAM
4983 || u->info->var->kind == VKREFSEFPARAM
4984 || u->info->var->kind == VKSEFRETPARAM
4985 || u->info->var->kind == VKREFSEFRETPARAM));
4989 uentry_isRefParam (uentry u)
4991 return (uentry_isVariable (u)
4992 && (u->info->var->kind == VKREFPARAM
4993 || u->info->var->kind == VKREFYIELDPARAM
4994 || u->info->var->kind == VKREFSEFPARAM
4995 || u->info->var->kind == VKREFSEFRETPARAM));
4999 uentry_isAnyParam (uentry u)
5001 return (uentry_isVariable (u)
5002 && ((u->info->var->kind == VKPARAM)
5003 || (u->info->var->kind == VKSEFPARAM)
5004 || (u->info->var->kind == VKYIELDPARAM)
5005 || (u->info->var->kind == VKRETPARAM)
5006 || (u->info->var->kind == VKSEFRETPARAM)));
5010 uentry_getDefState (uentry u)
5012 if (uentry_isValid (u))
5014 return (sRef_getDefState (u->sref));
5018 return (SS_UNKNOWN);
5023 uentry_isOut (uentry u)
5025 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_ALLOCATED))
5026 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5030 uentry_isPartial (uentry u)
5032 return ((uentry_isVariable (u) && (u->info->var->defstate == SS_PARTIAL))
5033 || (uentry_isDatatype (u) && (sRef_isAllocated (u->sref))));
5037 uentry_isStateSpecial (uentry u)
5039 return ((uentry_isVariable (u)
5040 && (u->info->var->defstate == SS_SPECIAL))
5041 || (uentry_isValid (u) && sRef_isStateSpecial (u->sref)));
5044 exitkind uentry_getExitCode (uentry ue)
5046 if (uentry_isFunction (ue))
5048 return ue->info->fcn->exitCode;
5057 uentry_nullPred (uentry u)
5059 llassert (uentry_isRealFunction (u));
5061 if (uentry_isFunction (u))
5063 return (u->info->fcn->nullPred);
5072 uentry_possiblyNull (uentry u)
5074 return ((uentry_isVariable (u) && (nstate_possiblyNull (u->info->var->nullstate)))
5075 || (uentry_isDatatype (u) && (sRef_possiblyNull (u->sref))));
5079 uentry_getAliasKind (uentry u)
5081 if (uentry_isValid (u))
5083 return (sRef_getAliasKind (uentry_getSref (u)));
5092 uentry_getExpKind (uentry u)
5094 if (uentry_isValid (u))
5096 return (sRef_getExKind (uentry_getSref (u)));
5105 uentry_isIter (uentry e)
5107 return (!uentry_isUndefined (e) && e->ukind == KITER);
5111 uentry_isEndIter (uentry e)
5113 return (!uentry_isUndefined (e) && e->ukind == KENDITER);
5117 uentry_isRealFunction (uentry e)
5119 return (uentry_isFunction (e) ||
5120 (uentry_isVariable (e) && ctype_isFunction (uentry_getType (e))));
5124 uentry_hasName (uentry e)
5126 if (uentry_isValid (e))
5128 cstring s = e->uname;
5130 return (!(cstring_isEmpty (s) || cstring_equalLit (s, "...")));
5138 bool uentry_hasRealName (uentry e)
5140 return (uentry_isValid (e) && cstring_isNonEmpty (e->uname));
5144 /*@observer@*/ globSet
5145 uentry_getGlobs (uentry l)
5147 if (uentry_isInvalid (l))
5149 return globSet_undefined;
5152 if (l->ukind != KFCN)
5154 if (l->ukind != KITER && l->ukind != KENDITER)
5156 if (l->ukind == KVAR)
5158 llbug (message ("Bad call to uentry_getGlobs (var): %q (%s)",
5160 ekind_unparse (l->ukind)));
5164 llbug (message ("Bad call to uentry_getGlobs: %q (%s)",
5166 ekind_unparse (l->ukind)));
5169 return globSet_undefined;
5172 return l->info->fcn->globs;
5175 /*@observer@*/ sRefSet
5176 uentry_getMods (uentry l)
5178 llassert (uentry_isValid (l));
5180 if (l->ukind != KFCN && l->ukind != KITER && l->ukind != KENDITER)
5182 llcontbug (message ("Bad call to uentry_getMods: %q", uentry_unparse (l)));
5183 return sRefSet_undefined;
5186 return l->info->fcn->mods;
5190 uentry_getKind (uentry e)
5192 llassert (uentry_isValid (e));
5197 /*@observer@*/ multiVal uentry_getConstantValue (uentry e)
5199 llassert (uentry_isEitherConstant (e));
5201 return (e->info->uconst->val);
5204 /*@observer@*/ uentryList
5205 uentry_getParams (uentry l)
5207 if (uentry_isInvalid (l)) return uentryList_undefined;
5214 ctype ct = l->utype;
5216 if (ctype_isFunction (ct))
5218 return (ctype_argsFunction (ct));
5222 return uentryList_undefined;
5227 ctype ct = l->utype;
5229 llassert (ctype_isFunction (ct));
5230 return (ctype_argsFunction (ct));
5237 /*@observer@*/ cstring
5238 uentry_rawName (uentry e)
5240 if (uentry_isValid (e))
5246 return cstring_undefined;
5251 uentry_getOptName (uentry e)
5253 cstring s = uentry_getName (e);
5255 if (cstring_isDefined (s))
5257 s = cstring_appendChar (s, ' ');
5264 uentry_getName (uentry e)
5266 cstring ret = cstring_undefined;
5268 if (uentry_isValid (e))
5271 if (uentry_isAnyTag (e))
5273 ret = fixTagName (e->uname);
5275 else if (uentry_isAnyParam (e))
5277 ret = cstring_copy (fixParamName (e->uname));
5281 ret = cstring_copy (e->uname);
5288 cstring uentry_getRealName (uentry e)
5290 if (uentry_isValid (e))
5292 if (uentry_isAnyTag (e))
5294 return (cstring_undefined);
5301 return cstring_undefined;
5304 ctype uentry_getType (uentry e)
5306 if (uentry_isValid (e))
5312 return ctype_unknown;
5316 fileloc uentry_whereLast (uentry e)
5320 if (uentry_isInvalid (e))
5322 return fileloc_undefined;
5325 loc = e->whereDefined;
5327 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5332 loc = uentry_whereDeclared (e);
5334 if (fileloc_isValid (loc) && !fileloc_isExternal (loc))
5339 loc = uentry_whereSpecified (e);
5343 fileloc uentry_whereEither (uentry e)
5345 if (uentry_isInvalid (e)) return fileloc_undefined;
5347 if (fileloc_isDefined (e->whereDefined)
5348 && !fileloc_isExternal (e->whereDefined))
5350 return e->whereDefined;
5352 else if (fileloc_isDefined (e->whereDeclared))
5354 return e->whereDeclared;
5358 return e->whereSpecified;
5362 fileloc uentry_whereSpecified (uentry e)
5364 if (uentry_isInvalid (e)) return fileloc_undefined;
5366 return (e->whereSpecified);
5369 fileloc uentry_whereDefined (uentry e)
5371 if (uentry_isInvalid (e)) return fileloc_undefined;
5373 return (e->whereDefined);
5376 fileloc uentry_whereDeclared (uentry e)
5378 if (uentry_isInvalid (e)) return fileloc_undefined;
5380 return (e->whereDeclared);
5383 /*@observer@*/ fileloc
5384 uentry_whereEarliest (uentry e)
5386 if (uentry_isInvalid (e)) return fileloc_undefined;
5388 if (fileloc_isDefined (e->whereSpecified))
5390 return (e->whereSpecified);
5392 else if (fileloc_isDefined (e->whereDeclared))
5394 return (e->whereDeclared);
5398 return e->whereDefined;
5403 uentry_setFunctionDefined (uentry e, fileloc loc)
5405 if (uentry_isValid (e))
5407 llassert (uentry_isFunction (e));
5409 if (fileloc_isUndefined (e->whereDeclared))
5411 e->whereDeclared = fileloc_update (e->whereDeclared, loc);
5414 if (!fileloc_isDefined (e->whereDefined))
5416 e->whereDefined = fileloc_update (e->whereDefined, loc);
5422 uentry_setDeclDef (uentry e, fileloc f)
5424 uentry_setDeclared (e, f);
5426 if (!uentry_isFunction (e)
5427 && !(uentry_isVariable (e) && uentry_isExtern (e)))
5429 uentry_setDefined (e, f);
5434 uentry_setDeclaredForce (uentry e, fileloc f)
5436 llassert (uentry_isValid (e));
5437 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5441 uentry_setDeclaredForceOnly (uentry e, fileloc f)
5443 llassert (uentry_isValid (e));
5444 fileloc_free (e->whereDeclared);
5445 e->whereDeclared = f;
5449 uentry_setDeclaredOnly (uentry e, /*@only@*/ fileloc f)
5453 llassert (uentry_isValid (e));
5454 oldloc = e->whereDeclared;
5456 if (fileloc_isDefined (oldloc))
5458 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
5460 e->whereDeclared = f;
5461 fileloc_free (oldloc);
5470 e->whereDeclared = f;
5471 fileloc_free (oldloc);
5476 uentry_setDeclared (uentry e, fileloc f)
5480 llassert (uentry_isValid (e));
5481 oldloc = e->whereDeclared;
5483 if (fileloc_isDefined (oldloc))
5485 if (fileloc_isLib (oldloc) || fileloc_isImport (oldloc))
5487 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5496 e->whereDeclared = fileloc_update (e->whereDeclared, f);
5501 uentry_clearDefined (uentry e)
5503 if (uentry_isValid (e))
5505 e->whereDefined = fileloc_update (e->whereDefined, fileloc_undefined);
5510 uentry_setDefined (uentry e, fileloc f)
5514 llassert (uentry_isValid (e));
5515 oldloc = e->whereDefined;
5517 if (fileloc_isDefined (oldloc))
5519 if (fileloc_isLib (oldloc)
5520 || fileloc_isImport (oldloc)
5521 || fileloc_isBuiltin (oldloc)
5522 || fileloc_isPreproc (oldloc))
5524 e->whereDefined = fileloc_update (e->whereDefined, f);
5528 if (fileloc_equal (oldloc, f) || context_processingMacros ())
5534 if (optgenerror (FLG_REDEF,
5535 message ("%s %q redefined",
5536 ekind_capName (e->ukind),
5537 uentry_getName (e)),
5540 llgenindentmsg (message ("Previous definition of %q",
5541 uentry_getName (e)),
5549 e->whereDefined = fileloc_update (e->whereDefined, f);
5554 uentry_isCodeDefined (uentry e)
5556 return (uentry_isValid (e) && fileloc_isDefined (e->whereDefined));
5560 uentry_isDeclared (uentry e)
5562 if (uentry_isValid (e))
5564 return (fileloc_isDefined (e->whereDeclared));
5570 sRef uentry_getSref (uentry e)
5572 /* not true, used for functions too (but shouldn't be? */
5573 /* llassertprint (e->ukind == KVAR, ("uentry_getSref: not variable!")); */
5575 if (uentry_isInvalid (e)) return sRef_undefined;
5580 sRef uentry_getOrigSref (uentry e)
5582 if (uentry_isValid (e))
5584 sRef sr = sRef_copy (uentry_getSref (e));
5586 sRef_resetState (sr);
5587 sRef_clearDerived (sr);
5589 if (uentry_isVariable (e))
5591 sRef_setDefState (sr, e->info->var->defstate, fileloc_undefined);
5592 sRef_setNullState (sr, e->info->var->nullstate, fileloc_undefined);
5599 return sRef_undefined;
5604 ** requires: uentry e is not in a hashed symbol table
5608 uentry_setName (uentry e, /*@only@*/ cstring n)
5610 llassert (uentry_isValid (e));
5612 cstring_free (e->uname);
5617 uentry_setType (uentry e, ctype t)
5619 if (uentry_isValid (e))
5622 sRef_setType (e->sref, t);
5627 uentry_resetParams (uentry ue, /*@only@*/ uentryList pn)
5630 ctype rettype = ctype_unknown;
5632 llassert (uentry_isValid (ue));
5634 rct = ctype_realType (ue->utype);
5636 if (uentry_isVariable (ue) && (ctype_isFunction (rct) || ctype_isUnknown (rct)))
5638 uentry_makeVarFunction (ue);
5641 llassert (uentry_isFunction (ue));
5643 if (ctype_isFunction (rct))
5645 rettype = ctype_returnValue (rct);
5648 ue->utype = ctype_makeNFParamsFunction (rettype, pn);
5652 uentry_setRefParam (uentry e)
5655 if (!uentry_isVar (e))
5657 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
5661 if (e->info->var->kind == VKSEFPARAM)
5663 e->info->var->kind = VKREFSEFPARAM;
5665 else if (e->info->var->kind == VKSEFRETPARAM)
5667 e->info->var->kind = VKREFSEFRETPARAM;
5669 else if (e->info->var->kind == VKYIELDPARAM)
5671 e->info->var->kind = VKREFYIELDPARAM;
5675 e->info->var->kind = VKREFPARAM;
5681 uentry_setParam (uentry e)
5683 if (!uentry_isVar (e))
5685 if (uentry_isElipsisMarker (e))
5691 llbug (message ("uentry_setParam: not variable: %q", uentry_unparse (e)));
5698 if (e->info->var->kind == VKYIELDPARAM
5699 || e->info->var->kind == VKSEFPARAM
5700 || e->info->var->kind == VKSEFRETPARAM)
5706 e->info->var->kind = VKPARAM;
5710 e->uname = makeParam (e->uname);
5711 cstring_free (oldname);
5716 uentry_setSref (uentry e, sRef s)
5718 if (uentry_isValid (e))
5720 if (sRef_isValid (e->sref))
5722 sRef_mergeStateQuietReverse (e->sref, s);
5726 e->sref = sRef_saveCopy (s);
5732 uentry_getAbstractType (uentry e)
5734 llassert (uentry_isDatatype (e));
5737 ** This assertion removed.
5738 ** Okay to have undefined type, for system types
5740 llassertprintret (!ctype_isUndefined (e->info->datatype->type),
5741 ("uentry_getAbstractType %q: undefined", uentry_unparseFull (e)),
5746 if (ctype_isUndefined (e->info->datatype->type))
5748 return ctype_unknown;
5752 ** Sadly, a kludge...
5755 if (ctype_isUserBool (e->info->datatype->type)) {
5759 return e->info->datatype->type;
5762 ctype uentry_getRealType (uentry e)
5765 typeId uid = USYMIDINVALID;
5767 if (uentry_isInvalid (e))
5769 return ctype_unknown;
5772 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
5774 if (uentry_isAnyTag (e))
5779 if (uentry_isAbstractType (e))
5781 ct = uentry_getAbstractType (e);
5783 if (ctype_isManifestBool (ct)) {
5787 llassert (ctype_isUA (ct));
5789 uid = ctype_typeId (ct);
5791 if (!context_hasAccess (uid))
5797 ct = uentry_getType (e);
5799 /* if (ctype_isUserBool (ct)) return ct; */
5801 if (ctype_isManifestBool (ct)) {
5805 if (ctype_isUA (ct))
5807 usymId iid = ctype_typeId (ct);
5809 if /*@access usymId@*/ (iid == uid) /*@noaccess usymId@*/
5811 llcontbug (message ("uentry_getRealType: recursive type! %s",
5812 ctype_unparse (ct)));
5817 /* evs 2000-07-25: possible infinite recursion ? */
5818 uentry ue2 = usymtab_getTypeEntry (iid);
5819 llassertprint (ue2 != e, ("Bad recursion: %s", uentry_unparseFull (e)));
5821 return uentry_getRealType (ue2);
5830 ctype uentry_getForceRealType (uentry e)
5833 typeId uid = USYMIDINVALID;
5835 if (uentry_isInvalid (e))
5837 return ctype_unknown;
5840 llassertprint (uentry_isDatatype (e), ("not datatype: %s", uentry_unparse (e)));
5842 if (uentry_isAnyTag (e))
5847 if (uentry_isAbstractType (e))
5849 ct = uentry_getAbstractType (e);
5850 llassert (ctype_isUA (ct));
5852 uid = ctype_typeId (ct);
5853 /* no check for access! */
5856 ct = uentry_getType (e);
5858 /* evs 2000-07-25 */
5859 /* if (ctype_isUserBool (ct)) return ct; */
5861 if (ctype_isManifestBool (ct)) {
5865 if (ctype_isUA (ct))
5867 usymId iid = ctype_typeId (ct);
5869 if /*@access usymId@*/ (iid == uid) /*@noaccess usymId@*/
5871 llcontbug (message ("uentry_getRealType: recursive type! %s",
5872 ctype_unparse (ct)));
5877 return uentry_getForceRealType (usymtab_getTypeEntry (iid));
5886 uentry uentry_nameCopy (cstring name, uentry e)
5888 uentry enew = uentry_alloc ();
5890 llassert (uentry_isValid (e));
5892 /* enew->shallowCopy = FALSE; */
5893 enew->ukind = e->ukind;
5895 enew->utype = e->utype;
5896 enew->whereSpecified = fileloc_copy (e->whereSpecified);
5897 enew->whereDefined = fileloc_copy (e->whereDefined);
5898 enew->whereDeclared = fileloc_copy (e->whereDeclared);
5899 enew->sref = sRef_copy (e->sref);
5900 enew->used = e->used;
5902 enew->isPrivate = e->isPrivate;
5903 enew->hasNameError = FALSE;
5905 enew->uses = filelocList_new ();
5907 enew->storageclass = e->storageclass;
5908 enew->info = uinfo_copy (e->info, e->ukind);
5914 uentry_setDatatype (uentry e, usymId uid)
5916 llassert (uentry_isDatatype (e));
5918 if (uentry_isAbstractType (e))
5920 e->info->datatype->type = ctype_createAbstract (uid);
5924 e->info->datatype->type = ctype_createUser (uid);
5929 uentry_setSpecDef (/*@special@*/ uentry e, /*@keep@*/ fileloc f)
5930 /*@defines e->whereSpecified, e->whereDeclared, e->whereDefined@*/
5933 llassert (uentry_isValid (e));
5935 if (fileloc_isSpec (f) || fileloc_isImport (f))
5937 e->whereSpecified = f;
5938 e->whereDeclared = fileloc_undefined;
5939 e->whereDefined = fileloc_undefined;
5943 e->whereSpecified = fileloc_undefined;
5944 e->whereDeclared = f;
5945 e->whereDefined = fileloc_undefined;
5950 ucinfo_free (/*@only@*/ ucinfo u)
5952 multiVal_free (u->val);
5957 uvinfo_free (/*@only@*/ uvinfo u)
5963 udinfo_free (/*@only@*/ udinfo u)
5969 ufinfo_free (/*@only@*/ ufinfo u)
5971 globSet_free (u->globs);
5972 sRefSet_free (u->mods);
5973 specialClauses_free (u->specclauses);
5976 /*fix up if this is the right way to handle this --drl*/
5977 if (u->preconditions)
5978 constraintList_free(u->preconditions);
5979 if (u->postconditions)
5980 constraintList_free(u->postconditions);
5986 uiinfo_free (/*@only@*/ uiinfo u)
5992 ueinfo_free (/*@only@*/ ueinfo u)
5997 static /*@only@*/ ucinfo
5998 ucinfo_copy (ucinfo u)
6000 ucinfo ret = (ucinfo) dmalloc (sizeof (*ret));
6002 ret->val = multiVal_copy (u->val);
6003 ret->access = u->access;
6008 static /*@only@*/ uvinfo
6009 uvinfo_copy (uvinfo u)
6011 uvinfo ret = (uvinfo) dmalloc (sizeof (*ret));
6013 ret->kind = u->kind;
6014 ret->nullstate = u->nullstate;
6015 ret->defstate = u->defstate;
6016 ret->checked = u->checked;
6018 //ret->bufinfo = u->bufinfo;
6019 /*@i334@*/ return ret;
6022 static /*@only@*/ udinfo
6023 udinfo_copy (udinfo u)
6025 udinfo ret = (udinfo) dmalloc (sizeof (*ret));
6029 ret->type = u->type;
6034 static /*@only@*/ ufinfo
6035 ufinfo_copy (ufinfo u)
6037 ufinfo ret = (ufinfo) dmalloc (sizeof (*ret));
6039 ret->hasGlobs = u->hasGlobs;
6040 ret->hasMods = u->hasMods;
6041 ret->exitCode = u->exitCode;
6042 ret->specialCode = u->specialCode;
6043 ret->nullPred = u->nullPred;
6044 ret->access = u->access;
6045 ret->globs = globSet_newCopy (u->globs);
6046 ret->mods = sRefSet_newCopy (u->mods);
6047 ret->defparams = u->defparams;
6048 ret->specclauses = specialClauses_copy (u->specclauses);
6051 ret->preconditions = u->preconditions? constraintList_copy(u->preconditions): NULL;
6056 ret->postconditions = u->postconditions? constraintList_copy(u->postconditions): NULL;
6062 static /*@only@*/ uiinfo
6063 uiinfo_copy (uiinfo u)
6065 uiinfo ret = (uiinfo) dmalloc (sizeof (*ret));
6067 ret->access = u->access;
6068 ret->globs = globSet_newCopy (u->globs);
6069 ret->mods = sRefSet_newCopy (u->mods);
6074 static /*@only@*/ ueinfo
6075 ueinfo_copy (ueinfo u)
6077 ueinfo ret = (ueinfo) dmalloc (sizeof (*ret));
6079 ret->access = u->access;
6084 uinfo_free (uinfo u, ekind kind)
6089 case KCONST: ucinfo_free (u->uconst); break;
6090 case KVAR: uvinfo_free (u->var); break;
6094 case KDATATYPE: udinfo_free (u->datatype); break;
6095 case KFCN: ufinfo_free (u->fcn); break;
6096 case KITER: uiinfo_free (u->iter); break;
6097 case KENDITER: ueinfo_free (u->enditer); break;
6098 case KELIPSMARKER: break;
6099 case KINVALID: break;
6105 static /*@only@*/ /*@null@*/ uinfo
6106 uinfo_copy (uinfo u, ekind kind)
6108 if (kind == KELIPSMARKER || kind == KINVALID)
6114 uinfo ret = (uinfo) dmalloc (sizeof (*ret));
6119 case KCONST: ret->uconst = ucinfo_copy (u->uconst); break;
6120 case KVAR: ret->var = uvinfo_copy (u->var); break;
6124 case KDATATYPE: ret->datatype = udinfo_copy (u->datatype); break;
6125 case KFCN: ret->fcn = ufinfo_copy (u->fcn); break;
6126 case KITER: ret->iter = uiinfo_copy (u->iter); break;
6127 case KENDITER: ret->enditer = ueinfo_copy (u->enditer); break;
6135 uentry_reallyFree (/*@notnull@*/ /*@only@*/ uentry e)
6137 filelocList_free (e->uses);
6138 cstring_free (e->uname);
6140 uinfo_free (e->info, e->ukind);
6142 fileloc_free (e->whereSpecified);
6143 fileloc_free (e->whereDefined);
6144 fileloc_free (e->whereDeclared);
6150 extern void uentry_markOwned (/*@owned@*/ uentry u)
6152 sfreeEventually (u);
6156 uentry_free (/*@only@*/ uentry e)
6158 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6160 uentry_reallyFree (e);
6165 ** For uentry's in the global or file scope
6169 uentry_freeComplete (/*@only@*/ uentry e)
6171 if (uentry_isValid (e) && !uentry_isElipsisMarker (e))
6173 /*@i@*/ sRef_free (e->sref);
6174 e->sref = sRef_undefined;
6175 uentry_reallyFree (e);
6180 ** requires old->kind != new->kind, old->uname = new->uname
6184 KindConformanceError (/*@unique@*/ uentry old, uentry unew, bool mustConform)
6186 llassert (uentry_isValid (old));
6187 llassert (uentry_isValid (unew));
6189 if (uentry_isEitherConstant (unew)
6190 && (fileloc_isPreproc (uentry_whereDeclared (old))
6191 || ctype_isUnknown (old->utype))
6192 && !uentry_isSpecified (old))
6200 if (!uentry_isDeclared (old))
6202 if (uentry_isSpecified (old))
6204 if (uentry_isSpecified (unew))
6206 llbuglit ("Respecification!");
6208 else if (uentry_isDeclared (unew))
6212 message ("%s %q inconsistently declared as %s: %t",
6213 ekind_capName (old->ukind),
6214 uentry_getName (unew),
6215 ekind_unparseLong (unew->ukind),
6217 uentry_whereDeclared (unew)))
6219 uentry_showWhereLast (old);
6231 message ("%s %q inconsistently declared as %s: %t",
6232 ekind_capName (old->ukind),
6233 uentry_getName (unew),
6234 ekind_unparseLong (unew->ukind),
6236 uentry_whereDeclared (unew)))
6238 uentry_showWhereLast (old);
6244 llassert (uentry_isDeclared (unew));
6248 message ("%s %q inconsistently redeclared as %s",
6249 ekind_capName (old->ukind),
6250 uentry_getName (unew),
6251 ekind_unparseLong (unew->ukind)),
6252 uentry_whereDeclared (unew)))
6254 uentry_showWhereLast (old);
6260 uentry_copyInto (old, unew);
6264 ** def is the definition of spec, modifies spec
6266 ** reports any inconsistencies
6267 ** returns the summary of all available information
6268 ** if spec and def are inconsistent, def is returned
6272 uentry_showWhereLast (uentry spec)
6274 if (uentry_isValid (spec))
6276 if (fileloc_isDefined (spec->whereDefined)
6277 && !fileloc_isLib (spec->whereDefined)
6278 && !fileloc_isPreproc (spec->whereDefined))
6280 llgenindentmsg (message ("Previous definition of %q: %t",
6281 uentry_getName (spec),
6282 uentry_getType (spec)),
6283 uentry_whereDefined (spec));
6285 else if (uentry_isDeclared (spec))
6287 llgenindentmsg (message ("Previous declaration of %q: %t",
6288 uentry_getName (spec),
6289 uentry_getType (spec)),
6290 uentry_whereDeclared (spec));
6292 else if (uentry_isSpecified (spec))
6294 if (uentry_hasName (spec))
6296 llgenindentmsg (message ("Specification of %q: %t",
6297 uentry_getName (spec),
6298 uentry_getType (spec)),
6299 uentry_whereSpecified (spec));
6303 llgenindentmsg (message ("Specification: %t", uentry_getType (spec)),
6304 uentry_whereSpecified (spec));
6309 /* nothing to show */
6315 uentry_showDefSpecInfo (uentry ce, fileloc fwhere)
6317 fileloc loc = uentry_whereDefined (ce);
6319 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6321 llgenindentmsg (message ("Definition of %q", uentry_getName (ce)),
6325 loc = uentry_whereSpecified (ce);
6327 if (fileloc_isUser (loc) && !fileloc_equal (loc, fwhere))
6329 llgenindentmsg (message ("Specification of %q", uentry_getName (ce)),
6334 void uentry_showWhereLastExtra (uentry spec, cstring extra)
6336 if (uentry_isDeclared (spec))
6338 llgenindentmsg (message ("Previous declaration of %q: %q",
6339 uentry_getName (spec), extra),
6340 uentry_whereDeclared (spec));
6342 else if (uentry_isSpecified (spec))
6344 llgenindentmsg (message ("Specification of %q: %q",
6345 uentry_getName (spec), extra),
6346 uentry_whereSpecified (spec));
6350 cstring_free (extra);
6355 uentry_showWhereDeclared (uentry spec)
6357 if (uentry_isDeclared (spec))
6359 if (uentry_hasName (spec))
6361 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6362 uentry_whereDeclared (spec));
6366 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6369 else if (uentry_isSpecified (spec))
6371 if (uentry_hasName (spec))
6373 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6374 uentry_whereSpecified (spec));
6378 llgenindentmsg (cstring_makeLiteral ("Specification"), uentry_whereSpecified (spec));
6383 /* nothing to show */
6389 uentry_showWhereAny (uentry spec)
6391 if (uentry_isDeclared (spec))
6393 if (uentry_hasName (spec))
6395 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6396 uentry_whereDeclared (spec));
6400 llgenindentmsg (cstring_makeLiteral ("Declaration"), uentry_whereDeclared (spec));
6403 else if (uentry_isSpecified (spec))
6405 if (uentry_hasName (spec))
6407 llgenindentmsg (message ("Specification of %q",
6408 uentry_getName (spec)),
6409 uentry_whereSpecified (spec));
6413 llgenindentmsg (cstring_makeLiteral ("Specification"),
6414 uentry_whereSpecified (spec));
6417 else if (fileloc_isDefined (uentry_whereDefined (spec)))
6419 if (uentry_hasName (spec))
6421 llgenindentmsg (message ("Definition of %q", uentry_getName (spec)),
6422 uentry_whereDefined (spec));
6426 llgenindentmsg (cstring_makeLiteral ("Definition"), uentry_whereDefined (spec));
6431 /* nothing to show */
6436 uentry_showWhereDefined (uentry spec)
6438 if (uentry_isCodeDefined (spec))
6440 llgenindentmsg (message ("Previous definition of %q", uentry_getName (spec)),
6441 uentry_whereDefined (spec));
6446 uentry_showWhereLastPlain (uentry spec)
6448 if (uentry_isDeclared (spec))
6450 llgenindentmsg (message ("Previous declaration of %q", uentry_getName (spec)),
6451 uentry_whereDeclared (spec));
6453 else if (uentry_isSpecified (spec))
6455 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6456 uentry_whereSpecified (spec));
6464 uentry_showWhereLastVal (uentry spec, cstring val)
6466 if (uentry_isDeclared (spec))
6468 llgenindentmsg (message ("Previous declaration of %q: %s",
6469 uentry_getName (spec), val),
6470 uentry_whereDeclared (spec));
6472 else if (uentry_isSpecified (spec))
6474 llgenindentmsg (message ("Specification of %q: %s",
6475 uentry_getName (spec), val),
6476 uentry_whereSpecified (spec));
6484 uentry_showWhereSpecified (uentry spec)
6486 if (uentry_isSpecified (spec))
6488 if (uentry_hasName (spec))
6490 llgenindentmsg (message ("Specification of %q", uentry_getName (spec)),
6491 uentry_whereSpecified (spec));
6495 llgenindentmsg (cstring_makeLiteral ("Specification"),
6496 uentry_whereSpecified (spec));
6499 else if (uentry_isDeclared (spec))
6501 llgenindentmsg (message ("Declaration of %q", uentry_getName (spec)),
6502 uentry_whereDeclared (spec));
6506 /* nothing to show */
6511 uentry_showWhereSpecifiedExtra (uentry spec, cstring s)
6513 if (uentry_isSpecified (spec))
6515 if (uentry_hasName (spec))
6517 llgenindentmsg (message ("Specification of %q: %q",
6518 uentry_getName (spec), s),
6519 uentry_whereSpecified (spec));
6523 llgenindentmsg (message ("Specification: %q", s),
6524 uentry_whereSpecified (spec));
6527 else if (uentry_isDeclared (spec))
6529 llgenindentmsg (message ("Declaration of %q: %q",
6530 uentry_getName (spec), s),
6531 uentry_whereDeclared (spec));
6535 llgenindentmsg (message ("Previous: %q", s),
6536 uentry_whereLast (spec));
6545 checkStructConformance (uentry old, uentry unew)
6548 uentryList fold, fnew;
6551 ** requires: types of old and new are structs or unions
6554 llassert (uentry_isValid (old));
6555 llassert (uentry_isValid (unew));
6557 oldr = ctype_realType (old->utype);
6558 fold = ctype_getFields (oldr);
6560 newr = ctype_realType (unew->utype);
6561 fnew = ctype_getFields (newr);
6563 if (!uentryList_matchFields (fold, fnew))
6565 if (fileloc_equal (uentry_whereLast (old),
6566 uentry_whereLast (unew)))
6574 message ("%q %q %rdeclared with fields { %q }, %s "
6575 "with fields { %q }",
6576 cstring_makeLiteral (ctype_isStruct (newr) ? "Structure": "Union"),
6577 uentry_getName (old),
6578 uentry_isDeclared (old),
6579 uentryList_unparseAbbrev (fnew),
6580 uentry_specOrDefName (old),
6581 uentryList_unparseAbbrev (fold)),
6582 uentry_whereDeclared (unew)))
6584 uentry_showWhereLastPlain (old);
6585 uentryList_showFieldDifference (fold, fnew);
6589 old->utype = unew->utype;
6594 checkEnumConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
6597 ** requires old and new are enums
6600 ctype rold = ctype_realType (old->utype);
6601 ctype rnew = ctype_realType (unew->utype);
6602 enumNameList eold = ctype_elist (rold);
6603 enumNameList enew = ctype_elist (rnew);
6605 if (!enumNameList_match (eold, enew))
6609 message ("Enum %q declared with members { %q } but "
6610 "specified with members { %q }",
6611 uentry_getName (old),
6612 enumNameList_unparse (enew),
6613 enumNameList_unparse (eold)),
6614 uentry_whereDeclared (unew)))
6616 uentry_showWhereSpecified (old);
6617 old->utype = unew->utype;
6623 ** either oldCurrent or newCurrent may be undefined!
6627 paramTypeError (uentry old, uentry oldCurrent, ctype oldType,
6628 uentry unew, uentry newCurrent, ctype newType,
6631 bool hasError = FALSE;
6633 if (uentry_isValid (newCurrent) && uentry_isDeclared (newCurrent))
6635 if (uentry_hasName (newCurrent))
6637 hasError = optgenerror
6639 message ("Parameter %d, %q, of function %q has inconsistent type: "
6640 "declared %t, %s %t",
6641 paramno + 1, uentry_getName (newCurrent),
6642 uentry_getName (unew),
6643 newType, uentry_specOrDefName (old), oldType),
6644 uentry_whereDeclared (newCurrent));
6648 hasError = optgenerror
6650 message ("Parameter %d of function %q has inconsistent type: "
6651 "declared %t, %s %t",
6652 paramno + 1, uentry_getName (unew),
6653 newType, uentry_specOrDefName (old), oldType),
6654 uentry_whereDeclared (newCurrent));
6656 DPRINTF (("type: %s / %s",
6657 ctype_unparse (newType),
6658 ctype_unparse (ctype_realType (newType))));
6663 if (uentry_isDeclared (unew))
6665 hasError = optgenerror
6667 message ("Parameter %d of function %s has inconsistent type: "
6668 "declared %t, %s %t",
6669 paramno + 1, unew->uname,
6670 newType, uentry_specOrDefName (old), oldType),
6671 uentry_whereDeclared (unew));
6675 hasError = optgenerror
6677 message ("Parameter %d of function %s has inconsistent type: "
6678 "declared %t, %s %t",
6679 paramno + 1, unew->uname,
6680 newType, uentry_specOrDefName (old), oldType),
6681 uentry_whereDeclared (unew));
6687 if (!uentry_isUndefined (oldCurrent))
6689 if (!uentry_isUndefined (newCurrent)
6690 && cstring_equal (uentry_rawName (newCurrent), uentry_rawName (oldCurrent)))
6692 uentry_showWhereLast (oldCurrent);
6696 uentry_showWhereLastPlain (old);
6699 uentry_setType (oldCurrent, newType);
6703 uentry_showWhereLastPlain (old);
6709 nargsError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
6713 message ("Function %s %rdeclared with %d arg%p, %s with %d",
6715 uentry_isDeclared (old),
6716 uentryList_size (uentry_getParams (unew)),
6717 uentry_specOrDefName (old),
6718 uentryList_size (uentry_getParams (old))),
6719 uentry_whereDeclared (unew)))
6721 uentry_showWhereLastPlain (old);
6726 returnValueError (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew)
6730 message ("Function %s inconsistently %rdeclared to return %t",
6732 uentry_isDeclared (old),
6733 ctype_returnValue (unew->utype)),
6734 uentry_whereDeclared (unew)))
6736 uentry_showWhereLastVal (old, ctype_unparse (ctype_returnValue (old->utype)));
6740 static cstring paramStorageName (uentry ue)
6742 return (cstring_makeLiteralTemp (uentry_isParam (ue) ? "param" : "storage"));
6745 static cstring fcnErrName (uentry ue)
6747 return (cstring_makeLiteralTemp (uentry_isFunction (ue) ? "to return" : "as"));
6750 extern /*@observer@*/ cstring uentry_checkedName (uentry ue)
6752 if (uentry_isVar (ue))
6754 return (checkedName (ue->info->var->checked));
6758 return (cstring_makeLiteralTemp ("<checked invalid>"));
6762 static cstring checkedName (chkind checked)
6766 case CH_UNKNOWN: return (cstring_makeLiteralTemp ("unknown"));
6767 case CH_UNCHECKED: return (cstring_makeLiteralTemp ("unchecked"));
6768 case CH_CHECKED: return (cstring_makeLiteralTemp ("checked"));
6769 case CH_CHECKMOD: return (cstring_makeLiteralTemp ("checkmod"));
6770 case CH_CHECKEDSTRICT: return (cstring_makeLiteralTemp ("checkedstrict"));
6776 void checkNullState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew, bool mustConform, bool completeConform)
6781 if (uentry_isVar (unew))
6783 llassert (uentry_isVar (old));
6785 oldState = old->info->var->nullstate;
6786 newState = unew->info->var->nullstate;
6790 oldState = sRef_getNullState (old->sref);
6791 newState = sRef_getNullState (unew->sref);
6794 if (oldState == NS_ABSNULL)
6796 if (uentry_isVar (old))
6798 old->info->var->nullstate = newState;
6801 sRef_mergeNullState (old->sref, newState);
6803 else if (newState == NS_UNKNOWN)
6805 if (completeConform && newState != oldState
6806 && uentry_isReallySpecified (old))
6810 message ("%s %q specified as %s, but declared without %s qualifier",
6811 ekind_capName (unew->ukind),
6812 uentry_getName (unew),
6813 nstate_unparse (oldState),
6814 nstate_unparse (oldState)),
6815 uentry_whereDeclared (unew)))
6817 uentry_showWhereSpecified (old);
6821 if (uentry_isVar (unew))
6823 unew->info->var->nullstate = oldState;
6826 sRef_mergeNullState (unew->sref, oldState);
6828 else if (newState == NS_POSNULL)
6830 if (oldState == NS_MNOTNULL
6831 && (ctype_isUA (unew->utype)
6832 || (uentry_isFunction (unew)
6833 && ctype_isUA (ctype_returnValue (unew->utype)))))
6835 if (uentry_isVar (unew))
6837 unew->info->var->nullstate = oldState;
6840 sRef_mergeNullState (unew->sref, oldState);
6844 if (oldState == NS_NOTNULL || oldState == NS_MNOTNULL
6845 || oldState == NS_UNKNOWN)
6852 ("%s %q inconsistently %rdeclared %s possibly null storage, "
6854 uentry_ekindName (unew),
6855 uentry_getName (unew),
6856 uentry_isDeclared (old),
6858 uentry_specOrDefName (old),
6859 cstring_makeLiteral (oldState == NS_MNOTNULL ? "with notnull" : "without null")),
6860 uentry_whereDeclared (unew)))
6862 uentry_showWhereSpecified (old);
6867 if (uentry_isVar (old))
6869 old->info->var->nullstate = newState;
6872 sRef_mergeNullState (old->sref, newState);
6875 else if (newState == NS_MNOTNULL)
6877 if (oldState != NS_MNOTNULL)
6883 message ("%s %q inconsistently %rdeclared %s notnull storage, "
6884 "%s without notnull qualifier",
6885 uentry_ekindName (unew),
6886 uentry_getName (unew),
6887 uentry_isDeclared (old),
6889 uentry_specOrDefName (old)),
6890 uentry_whereDeclared (unew)))
6892 uentry_showWhereSpecified (old);
6896 if (uentry_isVar (old))
6898 old->info->var->nullstate = newState;
6901 sRef_mergeNullState (old->sref, newState);
6906 if (uentry_isVar (unew))
6908 unew->info->var->nullstate = oldState;
6911 sRef_mergeNullState (unew->sref, oldState);
6916 void checkDefState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
6917 bool mustConform, bool completeConform)
6923 if (uentry_isVar (old) && uentry_isVar (unew))
6925 oldState = old->info->var->defstate;
6926 newState = unew->info->var->defstate;
6931 oldState = sRef_getDefState (old->sref);
6932 newState = sRef_getDefState (unew->sref);
6935 if (newState != oldState && newState != SS_UNKNOWN && newState != SS_DEFINED)
6941 message ("%s %q inconsistently %rdeclared %s %s %s, "
6943 uentry_ekindName (unew),
6944 uentry_getName (unew),
6945 uentry_isDeclared (old),
6947 sstate_unparse (newState),
6948 paramStorageName (unew),
6949 uentry_specOrDefName (old),
6951 sstate_unparse (oldState),
6952 paramStorageName (unew)),
6953 uentry_whereDeclared (unew)))
6955 uentry_showWhereSpecified (old);
6959 if (vars) old->info->var->defstate = newState;
6960 sRef_setDefState (old->sref, newState, uentry_whereDeclared (unew));
6965 && (newState != oldState) && (oldState != SS_DEFINED)
6966 && uentry_isReallySpecified (old))
6970 message ("%s %q specified as %s, but declared without %s qualifier",
6971 ekind_capName (unew->ukind),
6972 uentry_getName (unew),
6973 sstate_unparse (oldState),
6974 sstate_unparse (oldState)),
6975 uentry_whereDeclared (unew)))
6977 uentry_showWhereSpecified (old);
6981 if (vars) unew->info->var->defstate = oldState;
6982 sRef_setDefState (unew->sref, oldState, uentry_whereDeclared (unew));
6987 checkAliasState (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
6988 bool mustConform, bool completeConform)
6993 oldKind = sRef_getAliasKind (old->sref);
6994 newKind = sRef_getAliasKind (unew->sref);
6996 if (alkind_isImplicit (newKind)
6997 || (alkind_isRefCounted (newKind) && !uentry_isDatatype (unew)))
6999 if (completeConform && !alkind_equal (newKind, oldKind)
7000 && uentry_isReallySpecified (old))
7004 message ("%s %q specified as %s, but declared without "
7005 "explicit alias qualifier",
7006 ekind_capName (unew->ukind),
7007 uentry_getName (unew),
7008 alkind_unparse (oldKind)),
7009 uentry_whereDeclared (unew)))
7011 uentry_showWhereSpecified (old);
7016 ** This really shouldn't be necessary, but it is!
7017 ** Function params (?) use new here.
7020 sRef_setAliasKind (unew->sref, oldKind, uentry_whereDeclared (unew));
7024 if (alkind_isKnown (newKind))
7026 if (!alkind_equal (oldKind, newKind))
7028 if (alkind_isKnown (oldKind))
7033 message ("%s %q inconsistently %rdeclared %s %s storage, "
7035 uentry_ekindName (unew),
7036 uentry_getName (unew),
7037 uentry_isDeclared (old),
7039 alkind_unparse (newKind),
7040 uentry_specOrDefName (old),
7041 alkind_unparse (oldKind)),
7042 uentry_whereDeclared (unew)))
7044 uentry_showWhereSpecified (old);
7046 sRef_setAliasKind (old->sref, AK_ERROR,
7047 uentry_whereDeclared (unew));
7051 sRef_setAliasKind (old->sref, newKind,
7052 uentry_whereDeclared (unew));
7057 if (!(alkind_isImplicit (newKind)))
7060 !uentry_isFunction (unew) &&
7063 message ("%s %q inconsistently %rdeclared %s %s storage, "
7064 "implicitly %s as temp storage",
7065 uentry_ekindName (unew),
7066 uentry_getName (unew),
7067 uentry_isDeclared (old),
7069 alkind_unparse (newKind),
7070 uentry_specOrDefName (old)),
7071 uentry_whereDeclared (unew)))
7073 uentry_showWhereSpecified (old);
7077 sRef_setAliasKind (old->sref, newKind,
7078 uentry_whereDeclared (unew));
7080 else /* newKind is temp or refcounted */
7087 else /* newKind unknown */
7094 checkExpState(/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7095 bool mustConform, bool completeConform)
7100 oldKind = sRef_getExKind (old->sref);
7101 newKind = sRef_getExKind (unew->sref);
7103 if (exkind_isKnown (newKind))
7105 if (oldKind != newKind)
7107 if (exkind_isKnown (oldKind))
7112 message ("%s %q inconsistently %rdeclared %s %s, %s as %s",
7113 uentry_ekindName (unew),
7114 uentry_getName (unew),
7115 uentry_isDeclared (old),
7117 exkind_unparse (newKind),
7118 uentry_specOrDefName (old),
7119 exkind_unparse (oldKind)),
7120 uentry_whereDeclared (unew)))
7122 uentry_showWhereSpecified (old);
7125 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7132 message ("%s %q inconsistently %rdeclared %s %s, "
7133 "implicitly %s without exposure qualifier",
7134 uentry_ekindName (unew),
7135 uentry_getName (unew),
7136 uentry_isDeclared (old),
7138 exkind_unparse (newKind),
7139 uentry_specOrDefName (old)),
7140 uentry_whereDeclared (unew)))
7142 uentry_showWhereSpecified (old);
7145 sRef_setExKind (old->sref, newKind, uentry_whereDefined (unew));
7151 if (completeConform && exkind_isKnown (oldKind)
7152 && uentry_isReallySpecified (old))
7156 message ("%s %q specified as %s, but declared without "
7157 "exposure qualifier",
7158 ekind_capName (unew->ukind),
7159 uentry_getName (unew),
7160 exkind_unparse (oldKind)),
7161 uentry_whereDeclared (unew)))
7163 uentry_showWhereSpecified (old);
7167 /* yes, this is necessary! (if its a param) */
7168 sRef_setExKind (unew->sref, oldKind, fileloc_undefined);
7173 uentry_checkStateConformance (/*@notnull@*/ uentry old,
7174 /*@notnull@*/ uentry unew,
7175 bool mustConform, bool completeConform)
7177 checkDefState (old, unew, mustConform, completeConform);
7178 checkNullState (old, unew, mustConform, completeConform);
7179 checkAliasState (old, unew, mustConform, completeConform);
7180 checkExpState (old, unew, mustConform, completeConform);
7182 sRef_storeState (old->sref);
7183 sRef_storeState (unew->sref);
7187 checkVarConformance (uentry old, uentry unew, bool mustConform, bool completeConform)
7189 if (uentry_isElipsisMarker (old) || uentry_isElipsisMarker (unew))
7194 llassert (uentry_isVar (old));
7195 llassert (uentry_isVar (unew));
7197 if (cstring_isEmpty (old->uname))
7199 cstring_free (old->uname);
7200 old->uname = cstring_copy (unew->uname);
7203 if (unew->info->var->kind == VKRETPARAM
7204 || unew->info->var->kind == VKSEFRETPARAM)
7206 if (old->info->var->kind != VKRETPARAM
7207 && old->info->var->kind != VKSEFRETPARAM)
7211 message ("Parameter %q inconsistently %rdeclared as "
7212 "returned parameter",
7213 uentry_getName (unew),
7214 uentry_isDeclared (old)),
7215 uentry_whereDeclared (unew)))
7217 uentry_showWhereSpecified (old);
7218 old->info->var->kind = unew->info->var->kind;
7224 if (unew->info->var->kind == VKSEFPARAM || unew->info->var->kind == VKSEFRETPARAM)
7226 if (old->info->var->kind != VKSEFPARAM
7227 && old->info->var->kind != VKSEFRETPARAM)
7231 message ("Parameter %qinconsistently %rdeclared as "
7233 uentry_getOptName (unew),
7234 uentry_isDeclared (old)),
7235 uentry_whereDeclared (unew)))
7237 uentry_showWhereSpecified (old);
7238 old->info->var->kind = unew->info->var->kind;
7243 if (old->info->var->kind == VKSPEC)
7245 old->info->var->kind = unew->info->var->kind;
7249 unew->info->var->kind = old->info->var->kind;
7252 if (unew->info->var->checked != CH_UNKNOWN
7253 && unew->info->var->checked != old->info->var->checked)
7255 if (old->info->var->checked == CH_UNKNOWN
7256 && !fileloc_isUser (uentry_whereLast (old)))
7264 message ("Variable %q inconsistently %rdeclared as "
7265 "%s parameter (was %s)",
7266 uentry_getName (unew),
7267 uentry_isDeclared (old),
7268 checkedName (unew->info->var->checked),
7269 checkedName (old->info->var->checked)),
7270 uentry_whereDeclared (unew)))
7272 uentry_showWhereSpecified (old);
7276 old->info->var->checked = unew->info->var->checked;
7281 && (old->info->var->checked != CH_UNKNOWN)
7282 && uentry_isReallySpecified (old))
7286 message ("%s %q specified as %s, but declared without %s qualifier",
7287 ekind_capName (unew->ukind),
7288 uentry_getName (unew),
7289 checkedName (old->info->var->checked),
7290 checkedName (old->info->var->checked)),
7291 uentry_whereDeclared (unew)))
7293 uentry_showWhereSpecified (old);
7297 unew->info->var->checked = old->info->var->checked;
7300 uentry_checkStateConformance (old, unew, mustConform, completeConform);
7303 void uentry_checkMatchParam (uentry u1, uentry u2, int paramno, exprNode e)
7305 if (uentry_isElipsisMarker (u1) || uentry_isElipsisMarker (u2))
7310 llassert (uentry_isVar (u1));
7311 llassert (uentry_isVar (u2));
7313 if (u1->info->var->kind != u2->info->var->kind) {
7314 if (u1->info->var->kind == VKSEFRETPARAM) {
7315 if (u2->info->var->kind == VKRETPARAM) {
7318 message ("Function types are inconsistent. Parameter %d is "
7319 "sef parameter, but non-sef parameter in "
7320 "assigned function: %s",
7321 paramno, exprNode_unparse (e)),
7323 } else if (u2->info->var->kind == VKSEFPARAM) {
7326 message ("Function types are inconsistent. Parameter %d is "
7327 "returns parameter, but non-returns parameter in "
7328 "assigned function: %s",
7329 paramno, exprNode_unparse (e)),
7334 message ("Function types are inconsistent. Parameter %d is "
7335 "sef returns parameter, but non-sef returns parameter in "
7336 "assigned function: %s",
7337 paramno, exprNode_unparse (e)),
7340 } else if (u1->info->var->kind == VKRETPARAM) {
7343 message ("Function types are inconsistent. Parameter %d is "
7344 "returns parameter, but non-returns parameter in "
7345 "assigned function: %s",
7346 paramno, exprNode_unparse (e)),
7348 } else if (u1->info->var->kind == VKSEFPARAM) {
7351 message ("Function types are inconsistent. Parameter %d is "
7352 "sef parameter, but non-sef parameter in "
7353 "assigned function: %s",
7354 paramno, exprNode_unparse (e)),
7357 if (u2->info->var->kind == VKSEFRETPARAM) {
7360 message ("Function types are inconsistent. Parameter %d is "
7361 "normal parameter, but sef returns parameter in "
7362 "assigned function: %s",
7363 paramno, exprNode_unparse (e)),
7365 } else if (u2->info->var->kind == VKSEFPARAM) {
7368 message ("Function types are inconsistent. Parameter %d is "
7369 "normal parameter, but sef parameter in "
7370 "assigned function: %s",
7371 paramno, exprNode_unparse (e)),
7373 } else if (u2->info->var->kind == VKRETPARAM) {
7376 message ("Function types are inconsistent. Parameter %d is "
7377 "normal parameter, but returns parameter in "
7378 "assigned function: %s",
7379 paramno, exprNode_unparse (e)),
7387 if (u1->info->var->defstate != u2->info->var->defstate)
7391 message ("Function types are inconsistent. Parameter %d is "
7392 "%s, but %s in assigned function: %s",
7394 sstate_unparse (u1->info->var->defstate),
7395 sstate_unparse (u2->info->var->defstate),
7396 exprNode_unparse (e)),
7400 if (u1->info->var->nullstate != u2->info->var->nullstate)
7404 message ("Function types are inconsistent. Parameter %d is "
7405 "%s, but %s in assigned function: %s",
7407 nstate_unparse (u1->info->var->nullstate),
7408 nstate_unparse (u2->info->var->nullstate),
7409 exprNode_unparse (e)),
7413 if (sRef_getAliasKind (u1->sref) != sRef_getAliasKind (u2->sref))
7417 message ("Function types are inconsistent. Parameter %d is "
7418 "%s, but %s in assigned function: %s",
7420 alkind_unparse (sRef_getAliasKind (u1->sref)),
7421 alkind_unparse (sRef_getAliasKind (u2->sref)),
7422 exprNode_unparse (e)),
7426 if (sRef_getExKind (u1->sref) != sRef_getExKind (u2->sref))
7430 message ("Function types are inconsistent. Parameter %d is "
7431 "%s, but %s in assigned function: %s",
7433 exkind_unparse (sRef_getExKind (u1->sref)),
7434 exkind_unparse (sRef_getExKind (u2->sref)),
7435 exprNode_unparse (e)),
7441 checkFunctionConformance (/*@unique@*/ /*@notnull@*/ uentry old,
7442 /*@notnull@*/ uentry unew,
7443 bool mustConform, /*@unused@*/ bool completeConform)
7445 uentryList oldParams = uentry_getParams (old);
7446 uentryList newParams = uentry_getParams (unew);
7447 ctype newType = unew->utype;
7448 ctype oldType = old->utype;
7449 ctype oldRetType = ctype_unknown;
7450 ctype newRetType = ctype_unknown;
7452 if (uentry_isForward (old))
7454 mustConform = FALSE;
7455 uentry_copyInto (old, unew);
7460 ** check return values
7463 if (ctype_isKnown (oldType))
7465 llassert (ctype_isFunction (oldType));
7467 oldRetType = ctype_returnValue (oldType);
7470 if (ctype_isKnown (newType))
7472 llassert (ctype_isFunction (newType));
7474 newRetType = ctype_returnValue (newType);
7477 if (ctype_isKnown (oldRetType) && ctype_isKnown (newRetType)
7478 && !ctype_matchDef (newRetType, oldRetType))
7480 if (mustConform) returnValueError (old, unew);
7484 if (ctype_isConj (newRetType))
7486 if (ctype_isConj (oldRetType))
7488 if (!ctype_sameAltTypes (newRetType, oldRetType))
7492 message ("Function %q inconsistently %rdeclared to "
7493 "return alternate types %s "
7494 "(types match, but alternates are not identical, "
7495 "so checking may not be correct)",
7496 uentry_getName (unew),
7497 uentry_isDeclared (old),
7498 ctype_unparse (newRetType)),
7499 uentry_whereDeclared (unew)))
7501 uentry_showWhereLastVal (old, ctype_unparse (oldRetType));
7507 old->utype = ctype_makeFunction (oldRetType, uentryList_copy (newParams));
7512 uentry_checkStateConformance (old, unew, mustConform, completeConform);
7514 if (!exitkind_equal (unew->info->fcn->exitCode, old->info->fcn->exitCode))
7516 if (exitkind_isKnown (unew->info->fcn->exitCode))
7520 message ("Function %q inconsistently %rdeclared using %s",
7521 uentry_getName (unew),
7522 uentry_isDeclared (old),
7523 exitkind_unparse (unew->info->fcn->exitCode)),
7524 uentry_whereDeclared (unew)))
7526 uentry_showWhereSpecified (old);
7531 unew->info->fcn->exitCode = old->info->fcn->exitCode;
7535 if (!qual_isUnknown (unew->info->fcn->nullPred))
7537 if (!qual_equal (old->info->fcn->nullPred, unew->info->fcn->nullPred))
7541 message ("Function %q inconsistently %rdeclared using %s",
7542 uentry_getName (unew),
7543 uentry_isDeclared (old),
7544 qual_unparse (unew->info->fcn->nullPred)),
7545 uentry_whereDeclared (unew)))
7547 uentry_showWhereSpecified (old);
7553 unew->info->fcn->nullPred = old->info->fcn->nullPred;
7556 if (unew->info->fcn->specialCode != SPC_NONE)
7558 if (old->info->fcn->specialCode != unew->info->fcn->specialCode)
7562 message ("Function %q inconsistently %rdeclared using %s",
7563 uentry_getName (unew),
7564 uentry_isDeclared (old),
7565 specCode_unparse (unew->info->fcn->specialCode)),
7566 uentry_whereDeclared (unew)))
7568 uentry_showWhereSpecified (old);
7574 unew->info->fcn->specialCode = old->info->fcn->specialCode;
7581 if (!uentryList_sameObject (oldParams, newParams)
7582 && (!uentryList_isMissingParams (oldParams)))
7584 if (!uentryList_isMissingParams (newParams))
7587 int nparams = uentryList_size (oldParams);
7588 bool checknames = context_maybeSet (FLG_DECLPARAMMATCH);
7590 if (nparams != uentryList_size (newParams))
7592 nargsError (old, unew);
7595 if (uentryList_size (newParams) < nparams)
7597 nparams = uentryList_size (newParams);
7600 while (paramno < nparams)
7602 uentry oldCurrent = uentryList_getN (oldParams, paramno);
7603 uentry newCurrent = uentryList_getN (newParams, paramno);
7604 ctype oldCurrentType = uentry_getType (oldCurrent);
7605 ctype newCurrentType = uentry_getType (newCurrent);
7607 llassert (uentry_isValid (oldCurrent)
7608 && uentry_isValid (newCurrent));
7610 if (!uentry_isElipsisMarker (oldCurrent)
7611 && !uentry_isElipsisMarker (newCurrent))
7613 checkVarConformance (oldCurrent, newCurrent,
7614 mustConform, completeConform);
7619 if (uentry_hasName (oldCurrent)
7620 && uentry_hasName (newCurrent))
7622 cstring oldname = uentry_getName (oldCurrent);
7623 cstring pfx = context_getString (FLG_DECLPARAMPREFIX);
7625 cstring nname = uentry_getName (newCurrent);
7628 if (cstring_isDefined (pfx)
7629 && cstring_equalPrefix (oldname, cstring_toCharsSafe (pfx)))
7631 oname = cstring_suffix (oldname, cstring_length (pfx));
7636 /*@-branchstate@*/ } /*@=branchstate@*/
7638 if (cstring_isDefined (pfx)
7639 && cstring_equalPrefix (nname, cstring_toCharsSafe (pfx)))
7641 nnamefix = cstring_suffix (nname, cstring_length (pfx));
7646 /*@-branchstate@*/ } /*@=branchstate@*/
7648 if (!cstring_equal (oname, nnamefix))
7651 (FLG_DECLPARAMMATCH,
7652 message ("Definition parameter name %s does not match "
7653 "name of corresponding parameter in "
7656 uentry_whereLast (newCurrent)))
7658 uentry_showWhereLastPlain (oldCurrent);
7662 cstring_free (oldname);
7663 cstring_free (nname);
7667 if (!ctype_match (oldCurrentType, newCurrentType))
7669 paramTypeError (old, oldCurrent, oldCurrentType,
7670 unew, newCurrent, newCurrentType, paramno);
7674 if (ctype_isMissingParamsMarker (newCurrentType)
7675 || ctype_isElips (newCurrentType)
7676 || ctype_isMissingParamsMarker (oldCurrentType)
7677 || ctype_isElips (oldCurrentType))
7683 if (ctype_isConj (newCurrentType))
7685 if (ctype_isConj (oldCurrentType))
7687 if (!ctype_sameAltTypes (newCurrentType, oldCurrentType))
7691 message ("Parameter %q inconsistently %rdeclared with "
7692 "alternate types %s "
7693 "(types match, but alternates are not identical, "
7694 "so checking may not be correct)",
7695 uentry_getName (newCurrent),
7696 uentry_isDeclared (oldCurrent),
7697 ctype_unparse (newCurrentType)),
7698 uentry_whereDeclared (unew)))
7700 uentry_showWhereLastVal (oldCurrent,
7701 ctype_unparse (oldCurrentType));
7709 message ("Parameter %q inconsistently %rdeclared with "
7710 "alternate types %s",
7711 uentry_getName (newCurrent),
7712 uentry_isDeclared (oldCurrent),
7713 ctype_unparse (newCurrentType)),
7714 uentry_whereDeclared (unew)))
7716 uentry_showWhereLastVal (oldCurrent,
7717 ctype_unparse (oldCurrentType));
7724 if (ctype_isConj (oldCurrentType))
7726 uentry_setType (newCurrent, oldCurrentType);
7734 ** Forgot this! detected by lclint:
7735 ** uentry.c:1257,15: Suspected infinite loop
7741 if (!uentryList_isMissingParams (newParams))
7743 if (ctype_isConj (oldRetType))
7745 old->utype = ctype_makeFunction (oldRetType,
7746 uentryList_copy (newParams));
7750 old->utype = unew->utype;
7754 checkGlobalsConformance (old, unew, mustConform, completeConform);
7755 checkModifiesConformance (old, unew, mustConform, completeConform);
7757 if (specialClauses_isDefined (unew->info->fcn->specclauses))
7759 if (!specialClauses_isDefined (old->info->fcn->specclauses))
7763 message ("Function %q redeclared using special clauses (can only "
7764 "be used in first declaration)",
7765 uentry_getName (unew)),
7766 uentry_whereDeclared (unew)))
7768 uentry_showWhereLast (old);
7773 specialClauses_checkEqual (old, unew);
7777 if (fileloc_isUndefined (old->whereDeclared))
7779 old->whereDeclared = fileloc_copy (unew->whereDeclared);
7781 else if (fileloc_isUndefined (unew->whereDeclared))
7783 unew->whereDeclared = fileloc_copy (old->whereDeclared);
7792 uentry_mergeConstantValue (uentry ue, /*@only@*/ multiVal m)
7796 llassert (uentry_isValid (ue));
7797 llassert (uentry_isEitherConstant (ue));
7799 uval = ue->info->uconst->val;
7801 if (multiVal_isDefined (uval))
7803 if (multiVal_isDefined (m))
7805 if (!multiVal_equiv (uval, m))
7809 message ("%s %q defined with inconsistent value: %q",
7810 ekind_capName (ue->ukind),
7811 uentry_getName (ue),
7812 multiVal_unparse (m)),
7815 uentry_showWhereLastExtra (ue, multiVal_unparse (uval));
7823 ue->info->uconst->val = m;
7824 multiVal_free (uval);
7829 bool checkTypeConformance (/*@notnull@*/ uentry old, /*@notnull@*/ uentry unew,
7832 bool typeError = FALSE;
7834 if (uentry_isStructTag (old) || uentry_isUnionTag (old))
7836 if (ctype_isSU (old->utype) && ctype_isSU (unew->utype))
7840 checkStructConformance (old, unew);
7845 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
7847 llbug (message ("struct tags: bad types: %t / %t",
7848 old->utype, unew->utype));
7852 else if (uentry_isEnumTag (old))
7854 if (ctype_isEnum (old->utype) && ctype_isEnum (unew->utype))
7856 if (mustConform) checkEnumConformance (old, unew);
7860 if (!(ctype_isBogus (old->utype) || ctype_isBogus (unew->utype)))
7862 llbug (message ("enum! bad type: %s / %s", ctype_unparse (old->utype),
7863 ctype_unparse (unew->utype)));
7867 else if (!ctype_match (old->utype, unew->utype))
7869 if (cstring_equal (uentry_rawName (old), context_getBoolName ()))
7871 ctype realt = ctype_realType (unew->utype);
7873 if (ctype_isRealInt (realt) || ctype_isChar (realt))
7875 unew->utype = ctype_bool;
7881 typeError = optgenerror
7883 message ("%q defined as %s", uentry_getName (old),
7884 ctype_unparse (realt)),
7885 uentry_whereDeclared (unew));
7893 ctype oldr = ctype_realType (old->utype);
7894 ctype newr = ctype_realType (unew->utype);
7896 if (ctype_isStruct (oldr) && ctype_isStruct (newr))
7898 checkStructConformance (old, unew);
7900 else if (ctype_isUnion (oldr) && ctype_isUnion (newr))
7902 checkStructConformance (old, unew);
7904 else if (ctype_isEnum (oldr) && ctype_isEnum (newr))
7906 checkEnumConformance (old, unew);
7908 else if (uentry_isConstant (old)
7909 && (ctype_isAbstract (oldr) && ctype_isEnum (newr)))
7911 /* okay...for now! (should check the type is reset later... */
7915 DPRINTF (("YABA!"));
7918 message ("%s %q %rdeclared with inconsistent type: %t",
7919 ekind_capName (unew->ukind),
7920 uentry_getName (unew),
7921 uentry_isDeclared (old),
7923 uentry_whereDeclared (unew)))
7925 uentry_showWhereLast (old);
7941 uentry_checkDatatypeConformance (/*@notnull@*/ uentry old,
7942 /*@notnull@*/ uentry unew,
7943 bool mustConform, bool completeConform)
7945 if (ctype_isDefined (unew->info->datatype->type))
7948 ** bool is hard coded here, since it is built into LCL.
7949 ** For now, we're stuck with LCL's types.
7952 if (ctype_isDirectBool (old->utype) &&
7953 cstring_equalLit (unew->uname, "bool"))
7955 /* if (!context_getFlag (FLG_ABSTRACTBOOL))
7956 evs 2000-07-25: removed
7958 unew->utype = ctype_bool;
7961 if (ctype_isUnknown (old->info->datatype->type))
7963 old->info->datatype->type = unew->info->datatype->type;
7967 DPRINTF (("Old: %s / New: %s",
7968 uentry_unparseFull (old),
7969 uentry_unparseFull (unew)));
7970 DPRINTF (("Types: %s / %s",
7971 ctype_unparse (old->info->datatype->type),
7972 ctype_unparse (unew->info->datatype->type)));
7974 if (ctype_matchDef (old->info->datatype->type,
7975 unew->info->datatype->type))
7984 ("Type %q %s with inconsistent type: %t",
7985 uentry_getName (unew),
7986 uentry_reDefDecl (old, unew),
7987 unew->info->datatype->type),
7988 uentry_whereDeclared (unew)))
7990 uentry_showWhereLastExtra
7991 (old, cstring_copy (ctype_unparse (old->info->datatype->type)));
7994 old->info->datatype->type = unew->info->datatype->type;
7999 if (unew->info->datatype->abs != MAYBE)
8001 if (ynm_isOff (old->info->datatype->abs)
8002 && ynm_isOn (unew->info->datatype->abs))
8004 if (!ctype_isDirectBool (old->utype))
8009 ("Datatype %q inconsistently %rdeclared as abstract type",
8010 uentry_getName (unew),
8011 uentry_isDeclared (old)),
8012 uentry_whereDeclared (unew)))
8014 uentry_showWhereLastPlain (old);
8018 else if (ynm_isOn (old->info->datatype->abs)
8019 && ynm_isOff (unew->info->datatype->abs))
8021 if (!ctype_isDirectBool (old->utype))
8026 ("Datatype %q inconsistently %rdeclared as concrete type",
8027 uentry_getName (unew),
8028 uentry_isDeclared (old)),
8029 uentry_whereDeclared (unew)))
8031 uentry_showWhereLastPlain (old);
8042 if (ynm_isOn (old->info->datatype->abs))
8044 old->sref = unew->sref;
8045 unew->info->datatype->mut = old->info->datatype->mut;
8048 && uentry_isReallySpecified (old))
8053 ("Datatype %q specified as abstract, "
8054 "but abstract annotation not used in declaration",
8055 uentry_getName (unew)),
8056 uentry_whereDeclared (unew)))
8058 uentry_showWhereLastPlain (old);
8064 unew->info->datatype->abs = old->info->datatype->abs;
8066 if (ynm_isMaybe (unew->info->datatype->mut))
8068 if (completeConform && ynm_isOff (old->info->datatype->mut)
8069 && uentry_isReallySpecified (old))
8074 ("Datatype %q specified as immutable, "
8075 "but immutable annotation not used in declaration",
8076 uentry_getName (unew)),
8077 uentry_whereDeclared (unew)))
8079 uentry_showWhereLastPlain (old);
8083 unew->info->datatype->mut = old->info->datatype->mut;
8085 else if (ynm_isMaybe (old->info->datatype->mut))
8087 old->info->datatype->mut = unew->info->datatype->mut;
8091 if (ynm_isOn (old->info->datatype->abs))
8093 if (ynm_isOn (old->info->datatype->mut) && ynm_isOff (unew->info->datatype->mut))
8097 message ("Datatype %q inconsistently %rdeclared as immutable",
8098 uentry_getName (unew),
8099 uentry_isDeclared (old)),
8100 uentry_whereDeclared (unew)))
8102 uentry_showWhereLastPlain (old);
8107 if (ynm_isOff (old->info->datatype->mut)
8108 && ynm_isOn (unew->info->datatype->mut))
8112 message ("Datatype %q inconsistently %rdeclared as mutable",
8113 uentry_getName (unew),
8114 uentry_isDeclared (old)),
8115 uentry_whereDeclared (unew)))
8117 uentry_showWhereLastPlain (old);
8122 old->info->datatype->mut = unew->info->datatype->mut;
8125 uentry_checkStateConformance (old, unew, mustConform, completeConform);
8129 uentry_checkConstantConformance (/*@notnull@*/ uentry old,
8130 /*@notnull@*/ uentry unew,
8132 /*@unused@*/ bool completeConform)
8134 multiVal oldVal = old->info->uconst->val;
8135 multiVal newVal = unew->info->uconst->val;
8137 if (multiVal_isDefined (oldVal))
8139 if (multiVal_isDefined (newVal))
8141 if (!multiVal_equiv (oldVal, newVal))
8146 message ("%s %q %rdeclared with inconsistent value: %q",
8147 ekind_capName (unew->ukind),
8148 uentry_getName (unew),
8149 uentry_isDeclared (old),
8150 multiVal_unparse (newVal)),
8151 uentry_whereDeclared (unew)))
8153 uentry_showWhereLastExtra (old, multiVal_unparse (oldVal));
8157 unew->info->uconst->val = multiVal_copy (oldVal);
8158 multiVal_free (newVal);
8167 old->info->uconst->val = multiVal_copy (newVal);
8172 uentry_checkConformance (/*@unique@*/ /*@notnull@*/ uentry old,
8173 /*@notnull@*/ uentry unew, bool mustConform,
8174 bool completeConform)
8176 bool typeError = FALSE;
8177 bool fcnConformance = FALSE;
8179 if (!ekind_equal (unew->ukind, old->ukind))
8182 ** okay, only if one is a function and the other is
8183 ** a variable of type function.
8186 if (unew->ukind == KENUMCONST
8187 && old->ukind == KCONST)
8189 old->ukind = KENUMCONST;
8193 if (unew->ukind == KFCN
8194 && old->ukind == KCONST
8195 && ctype_isUnknown (old->utype))
8198 ** When a function is defined with an unparam macro
8201 uentry_copyInto (old, unew);
8205 if (uentry_isExpandedMacro (old)
8206 && uentry_isEitherConstant (unew))
8208 uentry_copyInto (old, unew);
8212 if (uentry_isEndIter (unew))
8214 if (ctype_isUnknown (old->utype))
8216 if (!uentry_isSpecified (old)
8217 && uentry_isCodeDefined (unew))
8219 if (!fileloc_withinLines (uentry_whereDefined (old),
8220 uentry_whereDeclared (unew), 2))
8221 { /* bogus! will give errors if there is too much whitespace */
8225 ("Iterator finalized name %q does not match name in "
8226 "previous iter declaration (should be end_%q). This iter "
8227 "is declared at %q",
8228 uentry_getName (unew),
8229 uentry_getName (old),
8230 fileloc_unparse (uentry_whereDefined (old))),
8231 uentry_whereDeclared (old));
8235 uentry_copyInto (old, unew);
8240 KindConformanceError (old, unew, mustConform);
8244 if (uentry_isFunction (unew))
8246 if (uentry_isVariable (old))
8248 if (!ctype_isUnknown (old->utype))
8250 if (ctype_isFunction (old->utype))
8252 uentry_makeVarFunction (old);
8253 checkFunctionConformance (old, unew, mustConform,
8255 fcnConformance = TRUE;
8259 KindConformanceError (old, unew, mustConform);
8264 if (uentry_isExpandedMacro (old))
8266 if (fileloc_isUndefined (unew->whereDefined))
8268 unew->whereDefined = fileloc_update (unew->whereDefined,
8272 uentry_copyInto (old, unew);
8273 old->used = unew->used = TRUE;
8278 /* undeclared identifier */
8279 old->utype = unew->utype;
8280 uentry_makeVarFunction (old);
8281 checkFunctionConformance (old, unew, FALSE, FALSE);
8282 fcnConformance = TRUE;
8288 KindConformanceError (old, unew, mustConform);
8291 else if (uentry_isFunction (old) && uentry_isVariable (unew))
8293 if (!ctype_isUnknown (unew->utype))
8295 if (ctype_isFunction (unew->utype))
8297 uentry_makeVarFunction (unew);
8298 checkFunctionConformance (old, unew, mustConform, completeConform);
8299 fcnConformance = TRUE;
8303 KindConformanceError (old, unew, mustConform);
8308 KindConformanceError (old, unew, mustConform);
8313 KindConformanceError (old, unew, mustConform);
8319 ** check parameter lists for functions
8320 ** (before type errors, to get better messages
8323 if (uentry_isFunction (old))
8325 checkFunctionConformance (old, unew, mustConform, completeConform);
8326 fcnConformance = TRUE;
8330 if (!ctype_isUndefined (old->utype))
8332 typeError = checkTypeConformance (old, unew, mustConform);
8339 if (uentry_isEitherConstant (old) && uentry_isEitherConstant (unew))
8341 uentry_checkConstantConformance (old, unew, mustConform, completeConform);
8344 if (uentry_isDatatype (old) && uentry_isDatatype (unew))
8346 DPRINTF (("Check datatype: %s / %s",
8347 uentry_unparseFull (old),
8348 uentry_unparseFull (unew)));
8350 uentry_checkDatatypeConformance (old, unew, mustConform, completeConform);
8353 if (uentry_isVariable (old) && uentry_isVariable (unew))
8356 !ctype_matchDef (old->utype, unew->utype))
8361 ("Variable %q %s with inconsistent type (arrays and pointers are "
8362 "not identical in variable declarations): %t",
8363 uentry_getName (unew),
8364 uentry_reDefDecl (old, unew),
8366 uentry_whereDeclared (unew)))
8368 uentry_showWhereLast (old);
8371 ** Avoid repeated errors.
8374 if (uentry_isCodeDefined (old) && uentry_isCodeDefined (unew))
8376 old->whereDefined = fileloc_update (old->whereDefined,
8384 checkVarConformance (old, unew, mustConform, completeConform);
8389 /* old->utype = unew->utype; */
8393 if (ctype_isConj (old->utype))
8395 if (ctype_isConj (unew->utype))
8397 if (!ctype_sameAltTypes (old->utype, unew->utype))
8401 message ("%s %q inconsistently %rdeclared with "
8402 "alternate types %s "
8403 "(types match, but alternates are not identical, "
8404 "so checking may not be correct)",
8405 ekind_capName (uentry_getKind (old)),
8406 uentry_getName (unew),
8407 uentry_isDeclared (old),
8408 ctype_unparse (unew->utype)),
8409 uentry_whereDeclared (unew)))
8411 uentry_showWhereLastVal (old, ctype_unparse (old->utype));
8415 old->utype = unew->utype;
8422 if (ctype_isUnknown (old->utype))
8424 old->utype = unew->utype;
8429 if (unew->ukind == old->ukind)
8432 unew->info = uinfo_copy (old->info, old->ukind);
8435 sRef_storeState (old->sref);
8436 sRef_storeState (unew->sref);
8440 ** modifies spec to reflect def, reports any inconsistencies
8444 uentry_mergeEntries (uentry spec, /*@only@*/ uentry def)
8446 llassert (uentry_isValid (spec));
8447 llassert (uentry_isValid (def));
8448 llassert (cstring_equal (spec->uname, def->uname));
8450 uentry_checkConformance (spec, def, TRUE,
8451 context_getFlag (FLG_NEEDSPEC));
8453 /* was: !(fileloc_isImport (uentry_whereSpecified (spec)))); */
8456 ** okay, declarations conform. Propagate extra information.
8459 uentry_setDefined (spec, uentry_whereDefined (def));
8460 uentry_setDeclared (spec, uentry_whereDeclared (def));
8462 if (uentry_isStatic (def))
8466 message ("%s %q specified, but declared as static",
8467 ekind_capName (def->ukind),
8468 uentry_getName (def)),
8469 uentry_whereDeclared (def)))
8471 uentry_showWhereSpecified (spec);
8476 spec->storageclass = def->storageclass;
8479 sRef_storeState (spec->sref);
8481 spec->used = def->used || spec->used;
8482 spec->hasNameError |= def->hasNameError;
8486 if (!spec->hasNameError)
8488 uentry_checkName (spec);
8497 ** Can't generate function redeclaration errors when the
8498 ** entries are merged, since we don't yet know if its the
8499 ** definition of the function.
8503 uentry_clearDecl (void)
8505 posRedeclared = uentry_undefined;
8506 fileloc_free (posLoc);
8507 posLoc = fileloc_undefined;
8511 uentry_checkDecl (void)
8513 if (uentry_isValid (posRedeclared))
8515 llassert (fileloc_isDefined (posLoc));
8517 if (uentry_isCodeDefined (posRedeclared))
8519 if (optgenerror (FLG_REDECL,
8520 message ("%s %q declared after definition",
8521 ekind_capName (posRedeclared->ukind),
8522 uentry_getName (posRedeclared)),
8525 llgenindentmsg (message ("Definition of %q",
8526 uentry_getName (posRedeclared)),
8527 posRedeclared->whereDeclared);
8532 if (optgenerror (FLG_REDECL,
8533 message ("%s %q declared more than once",
8534 ekind_capName (posRedeclared->ukind),
8535 uentry_getName (posRedeclared)),
8538 llgenindentmsg (message ("Previous declaration of %q",
8539 uentry_getName (posRedeclared)),
8540 posRedeclared->whereDeclared);
8545 fileloc_free (posLoc);
8546 posLoc = fileloc_undefined;
8547 posRedeclared = uentry_undefined;
8551 ** Redefinition of old as unew.
8552 ** modifies old to reflect unew, reports any inconsistencies
8556 uentry_mergeDefinition (uentry old, /*@only@*/ uentry unew)
8558 fileloc olddef = uentry_whereDeclared (old);
8559 fileloc unewdef = uentry_whereDeclared (unew);
8563 if (uentry_isExtern (unew))
8565 uentry_setUsed (old, unewdef);
8569 fileloc_isUndefined (olddef)
8570 && fileloc_isDefined (uentry_whereDefined (old))
8571 && !uentry_isExpandedMacro (old);
8573 if (!context_getFlag (FLG_INCONDEFSLIB)
8574 && (fileloc_isLib (olddef) || fileloc_isImport (olddef)))
8576 mustConform = FALSE;
8583 llassert (uentry_isValid (old));
8584 llassert (uentry_isValid (unew));
8585 llassert (cstring_equal (old->uname, unew->uname));
8588 ** should check old one was extern!
8591 if (uentry_isStatic (old))
8593 if (!(uentry_isStatic (unew)))
8597 message ("%s %q shadows static declaration",
8598 ekind_capName (unew->ukind),
8599 uentry_getName (unew)),
8602 uentry_showWhereLast (old);
8607 uentry_setDeclDef (old, unewdef);
8610 else if (uentry_isStatic (unew))
8612 uentry_setDeclDef (old, unewdef);
8614 else if (uentry_isExtern (old))
8616 uentry_setDeclared (old, unewdef);
8620 if (!uentry_isExtern (unew) && !uentry_isForward (old)
8621 && !fileloc_equal (olddef, unewdef)
8622 && !fileloc_isUndefined (olddef)
8623 && !fileloc_isUndefined (unewdef)
8624 && !fileloc_isBuiltin (olddef)
8625 && !fileloc_isBuiltin (unewdef)
8626 && !uentry_isYield (old)
8627 && !(fileloc_isLib (olddef) || fileloc_isImport (olddef)))
8629 if (uentry_isVariable (old) || uentry_isVariable (unew))
8631 ; /* will report redeclaration error later */
8635 if (fileloc_isDefined (uentry_whereDefined (old)))
8639 message ("%s %q defined more than once",
8640 ekind_capName (unew->ukind),
8641 uentry_getName (unew)),
8642 uentry_whereLast (unew)))
8645 (message ("Previous definition of %q",
8646 uentry_getName (old)),
8647 uentry_whereLast (old));
8650 if (uentry_isDatatype (old) || uentry_isAnyTag (old))
8652 uentry_copyInto (old, unew);
8653 old->sref = sRef_saveCopy (old->sref);
8661 if (fileloc_isLib (olddef)
8662 || fileloc_isUndefined (olddef)
8663 || fileloc_isImport (olddef))
8665 if (uentry_isExtern (unew))
8667 if (uentry_isExtern (old)
8668 || (fileloc_isDefined (uentry_whereDeclared (old))
8669 && (!fileloc_equal (uentry_whereDeclared (old),
8670 uentry_whereDefined (old)))))
8674 message ("%s %q declared more than once",
8675 ekind_capName (unew->ukind),
8676 uentry_getName (unew)),
8677 unew->whereDeclared))
8680 (message ("Previous declaration of %q",
8681 uentry_getName (old)),
8682 old->whereDeclared);
8686 uentry_setExtern (old);
8690 uentry_setDefined (old, unewdef);
8696 uentry_checkConformance (old, unew, mustConform, FALSE);
8698 old->used = old->used || unew->used;
8699 old->uses = filelocList_append (old->uses, unew->uses);
8700 unew->uses = filelocList_undefined;
8702 sRef_storeState (old->sref);
8703 sRef_storeState (unew->sref);
8707 old->whereDefined = fileloc_update (old->whereDefined,
8712 ** No redeclaration errors for functions here, since we
8713 ** don't know if this is the definition of the function.
8716 if (fileloc_isUser (old->whereDeclared)
8717 && fileloc_isUser (unew->whereDeclared)
8718 && !fileloc_equal (old->whereDeclared, unew->whereDeclared)
8719 && !fileloc_isDefined (unew->whereDefined))
8721 if (uentry_isFunction (old))
8723 /*@-temptrans@*/ posRedeclared = old; /*@=temptrans@*/
8724 posLoc = fileloc_update (posLoc, unew->whereDeclared);
8728 if (optgenerror (FLG_REDECL,
8729 message ("%s %q declared more than once",
8730 ekind_capName (unew->ukind),
8731 uentry_getName (unew)),
8732 unew->whereDeclared))
8734 llgenindentmsg (message ("Previous declaration of %q",
8735 uentry_getName (old)),
8736 old->whereDeclared);
8741 if (fileloc_isUndefined (old->whereDefined))
8743 old->whereDefined = fileloc_update (old->whereDefined, unew->whereDefined);
8747 if (!context_processingMacros ()
8748 && fileloc_isUser (old->whereDefined)
8749 && fileloc_isUser (unew->whereDefined)
8750 && !fileloc_equal (old->whereDefined, unew->whereDefined))
8752 if (uentry_isVariable (unew) || uentry_isFunction (unew))
8754 if (uentry_isVariable (unew)
8755 && uentry_isExtern (unew))
8757 if (optgenerror (FLG_REDECL,
8758 message ("%s %q declared after definition",
8759 ekind_capName (unew->ukind),
8760 uentry_getName (unew)),
8761 unew->whereDeclared))
8763 llgenindentmsg (message ("Definition of %q",
8764 uentry_getName (old)),
8770 if (optgenerror (FLG_REDEF,
8771 message ("%s %q redefined",
8772 ekind_capName (unew->ukind),
8773 uentry_getName (unew)),
8774 unew->whereDefined))
8776 llgenindentmsg (message ("Previous definition of %q",
8777 uentry_getName (old)),
8785 if (uentry_isExternal (unew))
8787 old->whereDefined = fileloc_createExternal ();
8790 if (unew->hasNameError)
8792 old->hasNameError = TRUE;
8797 if (!old->hasNameError)
8799 uentry_checkName (old);
8802 llassert (!ctype_isUndefined (old->utype));
8806 uentry_copyState (uentry res, uentry other)
8808 llassert (uentry_isValid (res));
8809 llassert (uentry_isValid (other));
8811 res->used = other->used;
8813 res->info->var->kind = other->info->var->kind;
8814 res->info->var->defstate = other->info->var->defstate;
8815 res->info->var->nullstate = other->info->var->nullstate;
8816 res->info->var->checked = other->info->var->checked;
8818 sRef_copyState (res->sref, other->sref);
8822 uentry_sameKind (uentry u1, uentry u2)
8824 if (uentry_isValid (u1) && uentry_isValid (u2))
8826 if (uentry_isVar (u1) && uentry_isVar (u2))
8828 ctype c1 = u1->utype;
8829 ctype c2 = u2->utype;
8831 if (ctype_isUnknown (c1) || ctype_isUnknown (c2)) return FALSE;
8834 ** both functions, or both not functions
8837 return (bool_equal (ctype_isFunction (c1), ctype_isFunction (c2)));
8841 return ((u1->ukind == u2->ukind));
8848 static void uentry_copyInto (/*@unique@*/ uentry unew, uentry old)
8850 llassert (uentry_isValid (unew));
8851 llassert (uentry_isValid (old));
8853 unew->ukind = old->ukind;
8854 unew->uname = cstring_copy (old->uname);
8855 unew->utype = old->utype;
8857 unew->whereSpecified = fileloc_copy (old->whereSpecified);
8858 unew->whereDefined = fileloc_copy (old->whereDefined);
8859 unew->whereDeclared = fileloc_copy (old->whereDeclared);
8861 unew->sref = sRef_saveCopy (old->sref); /* Memory leak! */
8862 unew->used = old->used;
8864 unew->isPrivate = old->isPrivate;
8865 unew->hasNameError = old->hasNameError;
8866 unew->uses = filelocList_undefined;
8868 unew->storageclass = old->storageclass;
8869 unew->info = uinfo_copy (old->info, old->ukind);
8874 uentry_copy (uentry e)
8876 if (uentry_isValid (e))
8878 uentry enew = uentry_alloc ();
8879 DPRINTF (("copy: %s", uentry_unparseFull (e)));
8880 uentry_copyInto (enew, e);
8881 DPRINTF (("Here we are..."));
8882 DPRINTF (("original: %s", uentry_unparseFull (e)));
8883 DPRINTF (("copy: %s", uentry_unparse (enew)));
8884 DPRINTF (("copy: %s", uentry_unparseFull (enew)));
8889 return uentry_undefined;
8894 uentry_setState (uentry res, uentry other)
8896 llassert (uentry_isValid (res));
8897 llassert (uentry_isValid (other));
8899 llassert (res->ukind == other->ukind);
8900 llassert (res->ukind == KVAR);
8902 res->sref = sRef_saveCopy (other->sref);
8903 res->used = other->used;
8904 filelocList_free (res->uses);
8905 res->uses = other->uses;
8906 other->uses = filelocList_undefined;
8907 res->lset = other->lset;
8911 uentry_mergeUses (uentry res, uentry other)
8913 llassert (uentry_isValid (res));
8914 llassert (uentry_isValid (other));
8916 res->used = other->used || res->used;
8917 res->lset = other->lset || res->lset;
8918 res->uses = filelocList_append (res->uses, other->uses);
8919 other->uses = filelocList_undefined;
8924 ** This is a really ugly routine.
8926 ** gack...fix this one day.
8931 ** >> res is the false branch, other is the true branch (or continuation)
8933 ** >> res is the true branch, other is the false branch (or continutation)
8940 ** References not effected by res are propagated from other.
8944 branchStateError (/*@notnull@*/ uentry res, /*@notnull@*/ uentry other,
8945 bool flip, clause cl, fileloc loc)
8949 message ("%s %q is %s %s, but %s %s.",
8950 ekind_capName (res->ukind), uentry_getName (res),
8951 sRef_stateVerb (res->sref), clause_nameFlip (cl, flip),
8952 sRef_stateAltVerb (res->sref), clause_nameFlip (cl, !flip)),
8955 if (sRef_isDead (res->sref))
8957 sRef_showStateInfo (res->sref);
8959 else if (sRef_isKept (res->sref))
8961 sRef_showAliasInfo (res->sref);
8963 else /* dependent */
8965 sRef_showAliasInfo (res->sref);
8966 sRef_showAliasInfo (other->sref);
8969 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
8973 static bool incompatibleStates (sRef rs, sRef os)
8975 alkind rk = sRef_getAliasKind (rs);
8976 alkind ok = sRef_getAliasKind (os);
8978 if (alkind_isError (rk) || alkind_isError (ok))
8984 return ((sRef_isDead (rs)
8985 || (alkind_isKept (rk) && !alkind_isKept (ok))
8986 || (alkind_isDependent (rk)
8987 && !alkind_isDependent (ok) && !alkind_isTemp (ok)))
8988 && (sRef_isAllocated (os) || sRef_isStateDefined (os)));
8993 branchStateAltError (/*@notnull@*/ uentry res,
8994 /*@notnull@*/ uentry other, bool flip,
8995 clause cl, fileloc loc)
8999 message ("%s %q is %s %s, but %s %s.",
9000 ekind_capName (res->ukind), uentry_getName (res),
9001 sRef_stateVerb (other->sref), clause_nameFlip (cl, flip),
9002 sRef_stateAltVerb (other->sref), clause_nameFlip (cl, !flip)),
9005 if (sRef_isDead (other->sref))
9007 sRef_showStateInfo (other->sref);
9011 sRef_showAliasInfo (other->sref);
9014 sRef_setAliasKind (res->sref, AK_ERROR, fileloc_undefined);
9015 sRef_setDefinedComplete (res->sref, fileloc_undefined);
9017 sRef_setAliasKind (other->sref, AK_ERROR, fileloc_undefined);
9018 sRef_setDefinedComplete (other->sref, fileloc_undefined);
9022 static bool notNull (sRef sr, bool flip)
9024 return (!sRef_definitelyNull (sr)
9025 && !(sRef_isKept (sr))
9026 && !(sRef_isDependent (sr))
9027 && !(flip ? usymtab_isProbableDeepNull (sr)
9028 : usymtab_isAltProbablyDeepNull (sr)));
9032 uentry_mergeState (uentry res, uentry other, fileloc loc,
9033 bool mustReturn, bool flip, bool opt,
9036 llassert (uentry_isValid (res));
9037 llassert (uentry_isValid (other));
9039 llassert (res->ukind == other->ukind);
9040 llassert (res->ukind == KVAR);
9042 DPRINTF (("Merge state: %s / %s",
9043 uentry_unparse (res),
9044 uentry_unparse (other)));
9046 if (sRef_isValid (res->sref))
9050 if (incompatibleStates (res->sref, other->sref))
9052 if (sRef_isThroughArrayFetch (res->sref)
9053 && !context_getFlag (FLG_STRICTBRANCHSTATE))
9055 if (sRef_isKept (res->sref) || sRef_isKept (other->sref))
9057 sRef_maybeKill (res->sref, loc);
9059 else if (sRef_isPossiblyDead (other->sref))
9061 sRef_maybeKill (res->sref, loc);
9070 if (notNull (other->sref, flip))
9072 if (sRef_isLocalParamVar (res->sref)
9073 && (sRef_isLocalState (other->sref)
9074 || sRef_isDependent (other->sref)))
9076 if (sRef_isDependent (res->sref))
9078 sRef_setDependent (other->sref, loc);
9082 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
9087 branchStateError (res, other, flip, cl, loc);
9092 if (sRef_isKept (res->sref))
9094 sRef_setKept (other->sref, loc);
9099 if (incompatibleStates (other->sref, res->sref))
9101 if (notNull (res->sref, !flip))
9103 if (sRef_isLocalParamVar (res->sref)
9104 && (sRef_isDependent (res->sref)
9105 || sRef_isLocalState (res->sref)))
9107 if (sRef_isDependent (other->sref))
9109 sRef_setDependent (res->sref, loc);
9113 sRef_setDefState (res->sref, SS_UNUSEABLE, loc);
9118 if (sRef_isParam (other->sref))
9121 ** If the local variable associated
9122 ** with the param has the correct state,
9124 ** (e.g., free (s); s = new(); ...
9127 uentry uvar = usymtab_lookupSafe (other->uname);
9129 if (uentry_isValid (uvar)
9130 && ((sRef_isDead (other->sref)
9131 && sRef_isOnly (uvar->sref))
9132 || (sRef_isDependent (other->sref)
9133 && sRef_isOwned (uvar->sref))))
9139 branchStateAltError (res, other,
9145 branchStateAltError (res, other,
9152 if (sRef_isKept (other->sref))
9154 sRef_setKept (res->sref, loc);
9160 DPRINTF (("Merge opt..."));
9161 sRef_mergeOptState (res->sref, other->sref, cl, loc);
9162 DPRINTF (("Done!"));
9166 sRef_mergeState (res->sref, other->sref, cl, loc);
9171 if (sRef_isModified (other->sref))
9173 sRef_setModified (res->sref);
9177 if (cl == DOWHILECLAUSE)
9179 res->used = other->used || res->used;
9180 res->lset = other->lset || res->lset;
9181 res->uses = filelocList_append (res->uses, other->uses);
9182 other->uses = filelocList_undefined;
9186 if (sRef_isMacroParamRef (res->sref)
9187 && !uentry_isSefParam (other)
9188 && !uentry_isSefParam (res))
9190 bool hasError = FALSE;
9192 if (bool_equal (res->used, other->used))
9194 res->used = other->used;
9198 if (other->used && !flip)
9203 message ("Macro parameter %q used in true clause, "
9204 "but not in false clause",
9205 uentry_getName (res)),
9206 uentry_whereDeclared (res));
9213 message ("Macro parameter %q used in false clause, "
9214 "but not in true clause",
9215 uentry_getName (res)),
9216 uentry_whereDeclared (res));
9222 /* make it sef now, prevent more errors */
9223 res->info->var->kind = VKREFSEFPARAM;
9229 res->used = other->used || res->used;
9230 res->lset = other->lset || res->lset;
9231 res->uses = filelocList_append (res->uses, other->uses);
9232 other->uses = filelocList_undefined;
9238 void uentry_setUsed (uentry e, fileloc loc)
9240 static bool firstTime = TRUE;
9241 static bool showUses = FALSE;
9242 static bool exportLocal = FALSE;
9246 /* need to track uses is FLG_SHOWUSES or FLG_EXPORTLOCAL is true */
9248 showUses = context_getFlag (FLG_SHOWUSES);
9249 exportLocal = context_maybeSet (FLG_EXPORTLOCAL);
9254 if (uentry_isValid (e))
9258 if (sRef_isMacroParamRef (e->sref))
9260 if (uentry_isYield (e) || uentry_isSefParam (e))
9266 if (context_inConditional ())
9270 message ("Macro parameter %q used in conditionally "
9271 "executed code (may or may not be "
9272 "evaluated exactly once)",
9273 uentry_getName (e)),
9276 e->info->var->kind = VKREFSEFPARAM;
9285 message ("Macro parameter %q used more than once",
9286 uentry_getName (e)),
9287 uentry_whereDeclared (e)))
9289 e->info->var->kind = VKREFSEFPARAM;
9296 if ((dp = uentry_directParamNo (e)) >= 0)
9298 uentry_setUsed (usymtab_getParam (dp), loc);
9303 if (!sRef_isLocalVar (e->sref))
9307 e->uses = filelocList_add (e->uses, fileloc_copy (loc));
9313 if (context_inMacro ())
9315 e->uses = filelocList_addUndefined (e->uses);
9319 e->uses = filelocList_addDifferentFile
9321 uentry_whereDeclared (e),
9330 bool uentry_isReturned (uentry u)
9332 return (uentry_isValid (u) && uentry_isVar (u)
9333 && (u->info->var->kind == VKRETPARAM
9334 || u->info->var->kind == VKSEFRETPARAM));
9337 /*@exposed@*/ sRef uentry_returnedRef (uentry u, exprNodeList args)
9339 llassert (uentry_isRealFunction (u));
9341 if (ctype_isFunction (u->utype)
9342 && sRef_isStateSpecial (uentry_getSref (u)))
9344 specialClauses clauses = uentry_getSpecialClauses (u);
9345 sRef res = sRef_makeNew (ctype_returnValue (u->utype), u->sref, u->uname);
9347 sRef_setAllocated (res, g_currentloc);
9349 specialClauses_postElements (clauses, cl)
9351 sRefSet refs = specialClause_getRefs (cl);
9352 sRefMod modf = specialClause_getEffectFunction (cl);
9354 sRefSet_elements (refs, el)
9356 sRef base = sRef_getRootBase (el);
9358 if (sRef_isResult (base))
9362 sRef sr = sRef_fixBase (el, res);
9363 modf (sr, g_currentloc);
9370 } end_sRefSet_elements ;
9372 } end_specialClauses_postElements ;
9380 sRefSet prefs = sRefSet_new ();
9381 sRef res = sRef_undefined;
9384 params = uentry_getParams (u);
9386 uentryList_elements (params, current)
9388 if (uentry_isReturned (current))
9390 if (exprNodeList_size (args) >= paramno)
9392 exprNode ecur = exprNodeList_nth (args, paramno);
9393 sRef tref = exprNode_getSref (ecur);
9395 if (sRef_isValid (tref))
9397 sRef tcref = sRef_copy (tref);
9399 if (sRef_isDead (tcref))
9401 sRef_setDefined (tcref, g_currentloc);
9402 sRef_setOnly (tcref, g_currentloc);
9405 if (sRef_isRefCounted (tcref))
9407 /* could be a new ref now (but only if its returned) */
9408 sRef_setAliasKindComplete (tcref, AK_ERROR, g_currentloc);
9411 sRef_makeSafe (tcref);
9413 prefs = sRefSet_insert (prefs, tcref);
9419 } end_uentryList_elements ;
9421 if (sRefSet_size (prefs) > 0)
9423 nstate n = sRef_getNullState (u->sref);
9425 if (sRefSet_size (prefs) == 1)
9427 res = sRefSet_choose (prefs);
9431 res = sRefSet_mergeIntoOne (prefs);
9434 if (nstate_isKnown (n))
9436 sRef_setNullState (res, n, g_currentloc);
9441 if (ctype_isFunction (u->utype))
9443 res = sRef_makeNew (ctype_returnValue (u->utype), u->sref, u->uname);
9447 res = sRef_makeNew (ctype_unknown, u->sref, u->uname);
9450 if (sRef_isRefCounted (res))
9452 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
9456 if (sRef_getNullState (res) == NS_ABSNULL)
9458 ctype ct = ctype_realType (u->utype);
9460 if (ctype_isAbstract (ct))
9462 sRef_setNotNull (res, g_currentloc);
9466 if (ctype_isUser (ct))
9468 sRef_setStateFromUentry (res, usymtab_getTypeEntry (ctype_typeId (ct)));
9472 sRef_setNotNull (res, g_currentloc);
9477 if (sRef_isRefCounted (res))
9479 sRef_setAliasKind (res, AK_NEWREF, g_currentloc);
9481 else if (sRef_isKillRef (res))
9483 sRef_setAliasKind (res, AK_REFCOUNTED, g_currentloc);
9490 ak = sRef_getAliasKind (res);
9492 if (alkind_isImplicit (ak))
9494 sRef_setAliasKind (res,
9495 alkind_fixImplicit (ak),
9499 sRefSet_free (prefs);
9505 static bool uentry_isRefCounted (uentry ue)
9507 ctype ct = uentry_getType (ue);
9509 if (ctype_isFunction (ct))
9511 return (ctype_isRefCounted (ctype_returnValue (ct)));
9515 return (ctype_isRefCounted (ct));
9520 ** old was declared yield in the specification.
9521 ** new is declared in the iter implementation.
9524 void uentry_checkYieldParam (uentry old, uentry unew)
9528 llassert (uentry_isVariable (old));
9529 llassert (uentry_isVariable (unew));
9531 unew->info->var->kind = VKYIELDPARAM;
9532 (void) checkTypeConformance (old, unew, TRUE);
9533 checkVarConformance (old, unew, TRUE, FALSE);
9535 /* get rid of param marker */
9537 name = uentry_getName (unew);
9538 cstring_free (unew->uname);
9540 unew->info->var->kind = VKREFYIELDPARAM;
9542 uentry_setUsed (old, fileloc_undefined);
9543 uentry_setUsed (unew, fileloc_undefined);
9546 /*@observer@*/ cstring
9547 uentry_ekindName (uentry ue)
9549 if (uentry_isValid (ue))
9554 return cstring_makeLiteralTemp ("<Error: invalid uentry>");
9556 return cstring_makeLiteralTemp ("Datatype");
9558 return cstring_makeLiteralTemp ("Enum member");
9560 return cstring_makeLiteralTemp ("Constant");
9562 if (uentry_isParam (ue))
9564 return cstring_makeLiteralTemp ("Parameter");
9566 else if (uentry_isExpandedMacro (ue))
9568 return cstring_makeLiteralTemp ("Expanded macro");
9572 return cstring_makeLiteralTemp ("Variable");
9575 return cstring_makeLiteralTemp ("Function");
9577 return cstring_makeLiteralTemp ("Iterator");
9579 return cstring_makeLiteralTemp ("Iterator finalizer");
9581 return cstring_makeLiteralTemp ("Struct tag");
9583 return cstring_makeLiteralTemp ("Union tag");
9585 return cstring_makeLiteralTemp ("Enum tag");
9587 return cstring_makeLiteralTemp ("Optional parameters");
9592 return cstring_makeLiteralTemp ("<Undefined>");
9598 void uentry_setHasNameError (uentry ue)
9600 llassert (uentry_isValid (ue));
9602 ue->hasNameError = TRUE;
9605 void uentry_checkName (uentry ue)
9607 if (uentry_isValid (ue)
9608 && !uentry_isElipsisMarker (ue)
9609 && context_getFlag (FLG_NAMECHECKS)
9610 && !ue->hasNameError
9611 && !uentry_isEndIter (ue)
9612 && !fileloc_isBuiltin (uentry_whereLast (ue))
9613 && (uentry_isExpandedMacro (ue) || !uentry_isForward (ue)))
9616 if (uentry_isPriv (ue))
9618 ; /* any checks here? */
9620 else if (fileloc_isExternal (uentry_whereDefined (ue)))
9622 ; /* no errors for externals */
9628 if (uentry_isExpandedMacro (ue))
9634 if (uentry_isExpandedMacro (ue))
9638 else if (uentry_isVariable (ue))
9640 sRef sr = uentry_getSref (ue);
9642 if (sRef_isValid (sr))
9644 scope = sRef_getScope (sr);
9651 else if (uentry_isFunction (ue)
9652 || uentry_isIter (ue)
9653 || uentry_isEndIter (ue)
9654 || uentry_isConstant (ue))
9656 scope = uentry_isStatic (ue) ? fileScope : globScope;
9658 else /* datatypes, etc. must be global */
9663 usymtab_checkDistinctName (ue, scope);
9666 if (context_getFlag (FLG_CPPNAMES))
9668 if (checkCppName (uentry_rawName (ue), uentry_whereLast (ue)))
9670 uentry_setHasNameError (ue);
9674 if (scope == globScope)
9676 checkGlobalName (ue);
9678 if (context_getFlag (FLG_ANSIRESERVED))
9680 if (uentry_hasName (ue)
9681 && !uentry_isAnyTag (ue))
9683 if (checkAnsiName (uentry_rawName (ue),
9684 uentry_whereLast (ue)))
9686 uentry_setHasNameError (ue);
9693 checkLocalName (ue);
9695 if (context_getFlag (FLG_ANSIRESERVEDLOCAL))
9697 if (uentry_hasName (ue)
9698 && !uentry_isAnyTag (ue))
9700 if (checkAnsiName (uentry_rawName (ue),
9701 uentry_whereLast (ue)))
9703 uentry_setHasNameError (ue);
9709 DPRINTF (("Check prefix: %s", uentry_unparse (ue)));
9715 /*@exposed@*/ uentry uentry_makeUnrecognized (cstring c, /*@keep@*/ fileloc loc)
9721 ** Can't but unrecognized ids in macros in global scope, because srefs will break! */
9722 if (!context_inMacro ())
9724 sRef_setGlobalScopeSafe ();
9727 ue = uentry_makeVariable (c, ctype_unknown, loc, FALSE);
9728 uentry_setUsed (ue, loc);
9730 tloc = fileloc_createExternal ();
9731 uentry_setDefined (ue, tloc);
9732 fileloc_free (tloc);
9733 uentry_setHasNameError (ue);
9735 if (context_getFlag (FLG_REPEATUNRECOG))
9737 uentry_markOwned (ue);
9741 ue = usymtab_supReturnFileEntry (ue);
9744 if (!context_inMacro ())
9746 sRef_clearGlobalScopeSafe ();
9752 /* new start modifications */
9754 void uentry_testInRange (uentry p_e, uentry cconstant) {
9755 if( uentry_isValid(p_e) ) {
9756 if( sRef_isValid (p_e->sref) ) {
9757 char * t = cstring_toCharsSafe (uentry_unparse(cconstant) );
9758 int index = atoi( t );
9760 usymtab_testInRange (p_e->sref, index);
9766 /* void uentry_setStringLength (uentry p_e, uentry cconstant) { */
9767 /* if( uentry_isValid(p_e) ) { */
9768 /* if( p_e->info != NULL) { */
9769 /* if( p_e->info->var != NULL) { */
9770 /* char *t = cstring_toCharsSafe (uentry_unparse(cconstant)); */
9771 /* int length = atoi( t ); */
9773 /* p_e->info->var->bufinfo->len = length; */
9774 /* p_e->sref->bufinfo.len = length; */
9775 /* printf("Set string length of buff to %d \n", p_e->sref->bufinfo.size); */
9782 static void uentry_setBufferSize (uentry p_e, exprNode cconstant) {
9783 if( uentry_isValid(p_e) ) {
9784 if( p_e->info != NULL) {
9785 if( p_e->info->var != NULL) {
9786 int size = atoi(cstring_toCharsSafe(exprNode_unparse(cconstant) ) );
9787 p_e->info->var->bufinfo->size = size;
9788 p_e->sref->bufinfo.size = size;
9789 printf("Set buffer size to %d \n", p_e->sref->bufinfo.size);
9790 // fprintf(stderr, "For %s and %s\n", uentry_unparse(p_e) );
9791 // fprintf(stderr, "and %d\n", size );
9799 /* start modifications */
9801 requires: p_e is defined, is a ptr/array variable
9803 effects: sets the state of the variable
9806 void uentry_setPossiblyNullTerminatedState (uentry p_e) {
9807 if( uentry_isValid(p_e) ) {
9808 if( p_e->info != NULL) {
9809 if( p_e->info->var != NULL) {
9810 p_e->info->var->bufinfo->bufstate = BB_POSSIBLYNULLTERMINATED;
9811 p_e->sref->bufinfo.bufstate = BB_POSSIBLYNULLTERMINATED;
9817 fprintf(stderr, "uentry:Error in setPossiblyNullTerminatedState\n");
9821 requires: p_e is defined, is a ptr/array variable
9823 effects: sets the size of the buffer
9826 void uentry_setNullTerminatedState (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_NULLTERMINATED;
9831 p_e->sref->bufinfo.bufstate = BB_NULLTERMINATED;
9837 fprintf(stderr, "uentry:Error in setNullTerminatedState\n");
9842 requires: p_e is defined, is a ptr/array variable
9844 effects: sets the state of the variable
9847 /* void uentry_setNotNullTerminatedState (uentry p_e) { */
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->bufstate = BB_NOTNULLTERMINATED; */
9852 /* p_e->sref->bufinfo.bufstate = BB_NOTNULLTERMINATED; */
9858 /* fprintf(stderr, "uentry:Error in setNotNullTerminatedState\n"); */
9863 requires: p_e is defined, is a ptr/array variable
9865 effects: sets the size of the buffer
9868 void uentry_setSize (uentry p_e, int size) {
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->size = size;
9873 p_e->sref->bufinfo.size = size;
9879 fprintf(stderr, "uentry:Error in setSize\n");
9884 requires: p_e is defined, is a ptr/array variable
9886 effects: sets the length of the buffer
9889 void uentry_setLen (uentry p_e, int len) {
9890 if( uentry_isValid(p_e) ) {
9891 if( p_e->info != NULL) {
9892 if( p_e->info->var != NULL) {
9893 p_e->info->var->bufinfo->len = len;
9894 p_e->sref->bufinfo.len = len;
9900 fprintf(stderr, "uentry:Error in setLen\n");