2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 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 splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
31 # include "splintMacros.nf"
33 # include "cgrammar.h"
36 # include "usymtab_interface.h"
39 # include "structNames.h"
40 # include "nameChecks.h"
43 # include "sgrammar_tokens.h"
45 # include "cgrammar_tokens.h"
49 ** Lots of variables are needed because of interactions with the
50 ** parser. This is easier than restructuring the grammar so the
51 ** right values are available in the right place.
55 static /*@only@*/ constraintList implicitFcnConstraints = NULL;
57 static void clabstract_prepareFunction (uentry p_e) /*@modifies p_e@*/ ;
58 static bool fcnNoGlobals = FALSE;
59 static void processVariable (/*@temp@*/ idDecl p_t) /*@modifies internalState@*/ ;
61 static bool s_processingVars = FALSE;
62 static bool s_processingParams = FALSE;
63 static bool s_processingGlobals = FALSE;
64 static bool s_processingTypedef = FALSE;
65 static bool s_processingIterVars = FALSE;
66 static /*@only@*/ qtype processingType = qtype_undefined;
67 static uentry currentIter = uentry_undefined;
68 static /*@dependent@*/ uentryList saveParamList; /* for old style functions */
69 static /*@owned@*/ uentry saveFunction = uentry_undefined;
70 static int saveIterParamNo;
71 static idDecl fixStructDecl (/*@returned@*/ idDecl p_d);
72 static void checkTypeDecl (uentry p_e, ctype p_rep);
73 static /*@dependent@*/ fileloc saveStoreLoc = fileloc_undefined;
74 static storageClassCode storageClass = SCNONE;
75 static void declareEnumList (/*@temp@*/ enumNameList p_el, ctype p_c, fileloc p_loc);
76 static void resetGlobals (void);
77 static /*@null@*/ qual specialFunctionCode;
78 static bool argsUsed = FALSE;
80 extern void clabstract_initMod ()
82 specialFunctionCode = qual_createUnknown ();
83 DPRINTF (("Initialized: %s", qual_unparse (specialFunctionCode)));
86 static bool hasSpecialCode (void)
88 return (!qual_isUnknown (specialFunctionCode));
91 extern void setArgsUsed (void)
97 cstring_makeLiteral ("Multiple ARGSUSED comments for one function"),
104 static void reflectArgsUsed (uentry ue)
108 if (uentry_isFunction (ue))
110 uentryList params = uentry_getParams (ue);
112 uentryList_elements (params, el)
114 uentry_setUsed (el, fileloc_undefined);
115 } end_uentryList_elements ;
122 extern void setSpecialFunction (qual qu)
124 if (!qual_isUnknown (specialFunctionCode))
126 voptgenerror (FLG_SYNTAX,
127 message ("Multiple special function codes: %s, %s "
128 "(first code is ignored)",
129 qual_unparse (specialFunctionCode),
134 specialFunctionCode = qu;
137 static void reflectSpecialCode (uentry ue)
139 if (qual_isUnknown (specialFunctionCode)) {
141 } else if (qual_isPrintfLike (specialFunctionCode)) {
142 uentry_setPrintfLike (ue);
143 } else if (qual_isScanfLike (specialFunctionCode)) {
144 uentry_setScanfLike (ue);
145 } else if (qual_isMessageLike (specialFunctionCode)) {
146 uentry_setMessageLike (ue);
151 specialFunctionCode = qual_createUnknown ();
154 static void resetStorageClass (void)
156 qtype_free (processingType);
157 processingType = qtype_undefined;
158 storageClass = SCNONE;
161 static void reflectStorageClass (uentry u)
163 if (storageClass == SCSTATIC)
165 uentry_setStatic (u);
167 else if (storageClass == SCEXTERN)
169 uentry_setExtern (u);
173 ; /* no storage class */
180 saveStoreLoc = g_currentloc;
183 void setFunctionNoGlobals (void)
188 static void reflectGlobalQualifiers (sRef sr, qualList quals)
190 DPRINTF (("Reflect global qualifiers: %s / %s",
191 sRef_unparseFull (sr), qualList_unparse (quals)));
193 qualList_elements (quals, qel)
195 if (qual_isGlobalQual (qel)) /* undef, killed */
197 sstate oldstate = sRef_getDefState (sr);
198 sstate defstate = sstate_fromQual (qel);
200 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
201 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
203 defstate = SS_UNDEFKILLED;
210 sRef_setDefState (sr, defstate, fileloc_undefined);
211 DPRINTF (("State: %s", sRef_unparseFull (sr)));
213 else if (qual_isAllocQual (qel)) /* out, partial, reldef, etc. */
215 ctype realType = sRef_getType (sr);
216 sstate defstate = sstate_fromQual (qel);
218 if (qual_isRelDef (qel))
220 ; /* okay anywhere */
224 if (!ctype_isAP (realType)
225 && !ctype_isSU (realType)
226 && !ctype_isUnknown (realType)
227 && !ctype_isAbstract (sRef_getType (sr)))
231 message ("Qualifier %s used on non-pointer or struct: %q",
232 qual_unparse (qel), sRef_unparse (sr)));
237 sRef_setDefState (sr, defstate, fileloc_undefined);
239 else if (qual_isNull (qel))
241 sRef_setNullState (sr, NS_POSNULL, fileloc_undefined);
243 else if (qual_isRelNull (qel))
245 sRef_setNullState (sr, NS_RELNULL, fileloc_undefined);
247 else if (qual_isNotNull (qel))
249 sRef_setNullState (sr, NS_MNOTNULL, fileloc_undefined);
253 if (qual_isCQual (qel))
260 message ("Qualifier %s cannot be used in a globals list",
261 qual_unparse (qel)));
264 } end_qualList_elements;
267 sRef clabstract_createGlobal (sRef sr, qualList quals)
271 if (sRef_isValid (sr))
273 res = sRef_copy (sr);
274 DPRINTF (("Reflecting quals: %s / %s", sRef_unparse (sr), qualList_unparse (quals)));
275 reflectGlobalQualifiers (res, quals);
276 DPRINTF (("==> %s", sRef_unparseFull (res)));
280 res = sRef_undefined;
283 qualList_free (quals);
287 extern void declareCIter (cstring name, /*@owned@*/ uentryList params)
291 ue = uentry_makeIter (name,
292 ctype_makeFunction (ctype_void, params),
293 fileloc_copy (g_currentloc));
295 usymtab_supEntry (uentry_makeEndIter (name, fileloc_copy (g_currentloc)));
296 ue = usymtab_supGlobalEntryReturn (ue);
299 extern void nextIterParam (void)
301 llassert (s_processingIterVars);
305 extern int iterParamNo (void)
307 llassert (s_processingIterVars);
308 return saveIterParamNo;
312 ** yucky hacks to put it in the right place
316 makeCurrentParam (idDecl t)
320 saveStoreLoc = fileloc_undefined;
322 /* param number unknown */
324 ue = uentry_makeParam (t, 0);
329 declareUnnamedEnum (enumNameList el)
331 ctype ret = usymtab_enumEnumNameListType (el);
335 if (ctype_isDefined (ret))
338 e = uentry_makeEnumTagLoc (ctype_enumTag (rt), ret);
340 reflectStorageClass (e);
341 usymtab_supGlobalEntry (e);
343 declareEnumList (el, ret, g_currentloc);
344 enumNameList_free (el);
348 ctype ct = ctype_createEnum (fakeTag (), el);
350 e = uentry_makeEnumTagLoc (ctype_enumTag (ctype_realType (ct)), ct);
351 reflectStorageClass (e);
353 e = usymtab_supGlobalEntryReturn (e);
354 rt = uentry_getAbstractType (e);
355 declareEnumList (el, ct, g_currentloc);
362 declareEnum (cstring ename, enumNameList el)
367 llassert (cstring_isDefined (ename));
369 cet = ctype_createEnum (ename, el);
370 e = uentry_makeEnumTagLoc (ename, cet);
371 reflectStorageClass (e);
372 e = usymtab_supGlobalEntryReturn (e);
373 cet = uentry_getType (e);
374 declareEnumList (el, cet, uentry_whereLast (e));
375 return (uentry_getAbstractType (e));
379 declareEnumList (enumNameList el, ctype c, fileloc loc)
381 bool boolnames = FALSE;
382 bool othernames = FALSE;
384 (void) context_getSaveLocation (); /* undefine it */
386 if (context_maybeSet (FLG_NUMENUMMEMBERS))
388 int maxnum = context_getValue (FLG_NUMENUMMEMBERS);
389 int num = enumNameList_size (el);
395 message ("Enumerator %s declared with %d members (limit is set to %d)",
396 ctype_unparse (c), num, maxnum),
401 enumNameList_elements (el, e)
403 uentry ue = usymtab_lookupExposeGlob (e);
404 ctype ct = uentry_getType (ue);
406 llassert (uentry_isEnumConstant (ue));
408 if (ctype_isUnknown (ct))
410 uentry_setType (ue, c);
414 if (cstring_equal (e, context_getFalseName ())
415 || cstring_equal (e, context_getTrueName ()))
421 message ("Enumerator mixes boolean name (%s) with "
424 uentry_whereLast (ue)))
431 uentry_setType (ue, ctype_bool);
432 DPRINTF (("Set type: %s / %s",
433 uentry_unparse (ue), ctype_unparse (ctype_bool)));
441 message ("Enumerator mixes boolean names (%s, %s) with "
442 "non-boolean name: %s",
443 context_getTrueName (),
444 context_getFalseName (),
446 uentry_whereLast (ue)))
455 if (!ctype_match (c, ct))
457 if (ctype_isDirectBool (ct))
459 if (cstring_equal (e, context_getFalseName ())
460 || cstring_equal (e, context_getTrueName ()))
462 DPRINTF (("Here we are!"));
468 message ("Enumerator member %s declared with "
469 "inconsistent type: %s",
470 e, ctype_unparse (c)),
471 uentry_whereLast (ue)))
473 uentry_showWhereSpecifiedExtra
474 (ue, cstring_copy (ctype_unparse (ct)));
482 message ("Enumerator member %s declared with "
483 "inconsistent type: %s",
484 e, ctype_unparse (c)),
485 uentry_whereLast (ue)))
487 uentry_showWhereSpecifiedExtra
488 (ue, cstring_copy (ctype_unparse (ct)));
493 } end_enumNameList_elements;
496 static /*@dependent@*/ uentryList currentParamList;
498 /*drl added 3-28-2002*/
499 /* this function takes a list of paramentar and generates a list
501 Currently the only constraints gnerated are MaxSet(p) >= 0 for all pointers
504 void setImplictfcnConstraints (void)
509 params = currentParamList;
511 if (constraintList_isDefined(implicitFcnConstraints) )
512 constraintList_free(implicitFcnConstraints);
514 implicitFcnConstraints = constraintList_makeNew();
516 uentryList_elements (params, el)
518 DPRINTF((message("setImplictfcnConstraints doing: %s", uentry_unparse(el) ) ));
520 s = uentry_getSref(el);
521 if (sRef_isReference (s) )
523 DPRINTF((message ("%s is a pointer", sRef_unparse(s) ) ));
527 DPRINTF((message ("%s is NOT a pointer", sRef_unparse(s) ) ));
530 chagned this is MaxSet(s) == 0 to MaxSet(s) >= 0 */
532 c = constraint_makeSRefWriteSafeInt (s, 0);
533 /* constraint_makeSRefSetBufferSize (s, 0); */
534 implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c);
536 end_uentryList_elements;
540 /*@observer@*/ constraintList getImplicitFcnConstraints (void)
542 return implicitFcnConstraints;
545 void setCurrentParams (/*@dependent@*/ uentryList ue)
547 currentParamList = ue;
550 void clearCurrentParams (void)
552 currentParamList = uentryList_undefined;
556 ** requires: uentry_isFunction (e)
557 ** parameter names for current function are in currentParamList
560 static void enterFunctionParams (uentryList params)
564 uentryList_elements (params, current)
566 if (uentry_hasName (current))
568 uentry_setParamNo (current, paramno);
569 usymtab_supEntry (uentry_copy (current));
573 } end_uentryList_elements;
577 extern void enterParamsTemp (void)
579 usymtab_enterScope ();
580 enterFunctionParams (currentParamList);
583 extern void exitParamsTemp (void)
585 usymtab_quietPlainExitScope ();
588 static /*@exposed@*/ uentry clabstract_globalDeclareFunction (idDecl tid)
590 ctype deftype = idDecl_getCtype (tid);
594 DPRINTF (("Global function: %s", idDecl_unparse (tid)));
596 if (ctype_isFunction (deftype))
598 rettype = ctype_getReturnType (deftype);
602 rettype = ctype_unknown;
606 ** check has been moved here...
609 if (ctype_isFunction (idDecl_getCtype (tid)))
611 ue = uentry_makeIdFunction (tid);
612 reflectSpecialCode (ue);
613 reflectArgsUsed (ue);
614 reflectStorageClass (ue);
615 uentry_checkParams (ue);
617 DPRINTF (("Supercede function: %s", uentry_unparseFull (ue)));
619 ue = usymtab_supGlobalEntryReturn (ue);
620 DPRINTF (("After supercede function: %s", uentry_unparseFull (ue)));
622 DPRINTF (("Enter function: %s", uentry_unparseFull (ue)));
623 context_enterFunction (ue);
624 enterFunctionParams (uentry_getParams (ue));
626 resetStorageClass ();
627 DPRINTF (("Function: %s", uentry_unparseFull (ue)));
632 llparseerror (message ("Non-function declaration: %q",
633 idDecl_unparse (tid)));
634 return (uentry_undefined);
639 ** for now, no type checking
640 ** (must check later though!)
643 static /*@only@*/ uentry globalDeclareOldStyleFunction (idDecl tid)
648 ** check has been moved here...
651 if (cstring_equalLit (idDecl_observeId (tid), "main"))
653 context_setFlagTemp (FLG_MAINTYPE, FALSE);
656 ue = uentry_makeIdFunction (tid);
657 reflectStorageClass (ue);
658 reflectSpecialCode (ue);
659 reflectArgsUsed (ue);
660 uentry_setDefined (ue, g_currentloc);
661 uentry_checkParams (ue);
662 resetStorageClass ();
664 /* context_enterOldStyleScope (); */
669 static void oldStyleDeclareFunction (/*@only@*/ uentry e)
671 uentryList params = saveParamList;
672 ctype rt = uentry_getType (e);
674 llassert (ctype_isFunction (rt));
676 if (uentry_hasStateClauseList (e)
677 || uentry_hasConditions (e))
679 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
680 fileloc_unparse (g_currentloc), uentry_unparse (e)));
683 e = usymtab_supGlobalEntryReturn (e);
685 context_enterFunction (e);
686 enterFunctionParams (params);
687 saveParamList = uentryList_undefined;
688 resetStorageClass ();
691 static void oldStyleCompleteFunction (/*@only@*/ uentry e)
693 uentryList params = saveParamList;
694 ctype rt = uentry_getType (e);
696 llassert (ctype_isFunction (rt));
698 if (uentry_hasStateClauseList (e)
699 || uentry_hasConditions (e))
701 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
702 fileloc_unparse (g_currentloc), uentry_unparse (e)));
705 e = usymtab_supGlobalEntryReturn (e);
707 context_completeOldStyleFunction (e);
708 enterFunctionParams (params);
709 saveParamList = uentryList_undefined;
710 resetStorageClass ();
713 void clabstract_declareFunction (idDecl tid) /*@globals undef saveFunction; @*/
717 DPRINTF (("Declare function: %s", idDecl_unparse (tid)));
719 if (ctype_isUnknown (idDecl_getCtype (tid)))
722 ** No type, its really a plain name (int) declaration
725 voptgenerror (FLG_IMPTYPE,
726 message ("No type before declaration name (implicit int type): %q",
727 idDecl_unparse (tid)),
729 tid = idDecl_replaceCtype (tid, ctype_int);
730 processVariable (tid);
731 saveFunction = uentry_undefined;
735 if (s_processingParams)
737 ue = globalDeclareOldStyleFunction (tid);
739 DPRINTF (("Set save function: %s", uentry_unparseFull (ue)));
743 saveFunction = uentry_undefined;
745 if (context_inRealFunction ())
747 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
749 llparseerror (message ("Function declared inside function: %q",
750 idDecl_unparse (tid)));
752 context_quietExitFunction ();
753 ue = usymtab_supEntryReturn (ue);
757 if (context_inInnerScope ())
759 llparseerror (message ("Declaration in inner context: %q",
760 idDecl_unparse (tid)));
762 sRef_setGlobalScope ();
763 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
765 ue = usymtab_supGlobalEntryReturn (ue);
766 sRef_clearGlobalScope ();
770 ue = clabstract_globalDeclareFunction (tid);
777 resetStorageClass ();
783 void declareStaticFunction (idDecl tid) /*@globals undef saveFunction; @*/
787 DPRINTF (("Declare static funciton: %s", idDecl_unparse (tid)));
789 if (s_processingParams)
791 ue = globalDeclareOldStyleFunction (tid);
796 saveFunction = uentry_undefined;
798 if (context_inRealFunction ())
800 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
802 llparseerror (message ("Function declared inside function: %q",
803 idDecl_unparse (tid)));
805 context_quietExitFunction ();
806 ue = usymtab_supEntryReturn (ue);
810 if (context_inInnerScope ())
812 llparseerror (message ("Declaration in inner context: %q",
813 idDecl_unparse (tid)));
815 sRef_setGlobalScope ();
816 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
818 ue = usymtab_supGlobalEntryReturn (ue);
819 sRef_clearGlobalScope ();
823 ctype deftype = idDecl_getCtype (tid);
826 if (ctype_isFunction (deftype))
828 rettype = ctype_getReturnType (deftype);
832 rettype = ctype_unknown;
836 ** check has been moved here...
839 if (ctype_isFunction (idDecl_getCtype (tid)))
841 ue = uentry_makeIdFunction (tid);
842 reflectSpecialCode (ue);
843 reflectArgsUsed (ue);
847 DPRINTF (("Here we are!"));
848 llparseerror (message ("Inconsistent function declaration: %q",
849 idDecl_unparse (tid)));
851 tid = idDecl_replaceCtype
852 (tid, ctype_makeFunction (ctype_unknown, uentryList_undefined));
853 ue = uentry_makeIdFunction (tid);
856 reflectStorageClass (ue);
857 uentry_setStatic (ue);
859 uentry_checkParams (ue);
861 DPRINTF (("Sub global entry: %s", uentry_unparse (ue)));
862 ue = usymtab_supGlobalEntryReturn (ue);
864 context_enterFunction (ue);
865 enterFunctionParams (uentry_getParams (ue));
866 resetStorageClass ();
873 resetStorageClass ();
878 checkTypeDecl (uentry e, ctype rep)
880 cstring n = uentry_getName (e);
882 DPRINTF (("Check type decl: %s", uentry_unparseFull (e)));
884 if (cstring_equal (context_getBoolName (), n))
886 ctype rrep = ctype_realType (rep);
889 ** for abstract enum types, we need to fix the enum members:
890 ** they should have the abstract type, not the rep type.
893 if (ctype_isEnum (ctype_realType (rrep)))
895 enumNameList el = ctype_elist (rrep);
897 enumNameList_elements (el, ye)
899 if (usymtab_existsGlob (ye))
901 uentry ue = usymtab_lookupSafe (ye);
902 uentry_setType (ue, ctype_bool);
905 if (cstring_equal (context_getTrueName (), ye)
906 || cstring_equal (context_getFalseName (), ye))
914 message ("Member of boolean enumerated type definition "
915 "does not match name set to represent TRUE "
918 message ("Use -boolfalse and -booltrue to set the "
919 "name of false and true boolean values."),
920 uentry_whereDefined (e));
922 } end_enumNameList_elements;
926 if (usymtab_exists (n))
928 usymId llm = usymtab_getId (n);
929 uentry le = usymtab_getTypeEntry (llm);
931 uentry_setDeclared (e, g_currentloc);
932 uentry_setSref (e, sRef_makeGlobal (llm, uentry_getType (le), stateInfo_currentLoc ()));
934 DPRINTF (("Here we are: %s / %s",
935 n, context_getBoolName ()));
937 if (uentry_isAbstractDatatype (le))
939 ctype rrep = ctype_realType (rep);
941 DPRINTF (("Abstract type: %s", uentry_unparseFull (le)));
944 ** for abstract enum types, we need to fix the enum members:
945 ** they should have the abstract type, not the rep type.
948 if (ctype_isEnum (ctype_realType (rrep)))
950 ctype at = uentry_getAbstractType (le);
951 enumNameList el = ctype_elist (rrep);
953 enumNameList_elements (el, ye)
955 if (usymtab_existsGlob (ye))
957 uentry ue = usymtab_lookupSafe (ye);
959 llassert (uentry_isEitherConstant (ue));
960 llassertprint (ctype_match (uentry_getType (ue), rrep),
961 ("Bad enum: %s / %s",
963 ctype_unparse (rrep)));
965 uentry_setType (ue, at);
967 } end_enumNameList_elements;
970 if (uentry_isMutableDatatype (le))
972 /* maybe more complicated if abstract and immutable ? */
974 if (!ctype_isRealPointer (rep) && !ctype_isRealAbstract (rep))
978 message ("Mutable abstract type %s declared without pointer "
979 "indirection: %s (violates assignment semantics)",
980 n, ctype_unparse (rep)),
981 uentry_whereDefined (e));
983 uentry_setMutable (e);
990 fileloc fl = uentry_whereDeclared (e);
992 if (context_getFlag (FLG_LIKELYBOOL)
993 && !context_getFlag (FLG_BOOLINT))
995 if ((cstring_equalLit (n, "BOOL")
996 || cstring_equalLit (n, "Bool")
997 || cstring_equalLit (n, "bool")
998 || cstring_equalLit (n, "boolean")
999 || cstring_equalLit (n, "Boolean")
1000 || cstring_equalLit (n, "BOOLEAN"))
1001 && !(cstring_equal (n, context_getBoolName ())))
1003 if (context_setBoolName ()) {
1006 message ("Type %s is probably meant as a boolean type, but does "
1007 "not match the boolean type name \"%s\".",
1009 context_getBoolName ()),
1014 message ("Type %s is probably meant as a boolean type, "
1015 "but the boolean type name is not set. "
1016 "Use -booltype %s to set it.",
1023 if (!uentry_isStatic (e)
1024 && !ctype_isFunction (uentry_getType (e))
1025 && !fileloc_isLib (fl)
1026 && !fileloc_isImport (fl)
1027 && fileloc_isHeader (fl))
1029 voptgenerror (FLG_EXPORTTYPE,
1030 message ("Type exported, but not specified: %s\n", n),
1039 fixUentryList (idDeclList tl, qtype q)
1041 uentryList f = uentryList_new ();
1043 idDeclList_elements (tl, i)
1045 if (idDecl_isDefined (i))
1051 (void) idDecl_fixBase (i, q);
1054 ** implicit annotations
1057 (void) fixStructDecl (i);
1059 ue = uentry_makeIdVariable (i);
1060 rt = ctype_realType (uentry_getType (ue));
1063 ** where is this here???
1065 if (ctype_isArray (rt) || ctype_isSU (rt))
1067 sRef_setAllocated (uentry_getSref (ue), uentry_whereDefined (ue));
1073 if (uentry_isValid (old = uentryList_lookupField (f, uentry_rawName (ue))))
1075 if (optgenerror (FLG_SYNTAX,
1076 message ("Field name reused: %s", uentry_rawName (ue)),
1077 uentry_whereDefined (ue)))
1079 llgenmsg (message ("Previous use of %s", uentry_rawName (ue)),
1080 uentry_whereDefined (old));
1084 f = uentryList_add (f, ue);
1086 } end_idDeclList_elements;
1088 idDeclList_free (tl);
1093 ** This is a hack to support unnamed struct/union fields as done by
1094 ** Microsoft VC++. It is not supported by the ANSI standard.
1096 ** The inner fields are added to the outer structure. This is meaningful
1097 ** for nesting structs inside unions, but Splint does no related
1102 fixUnnamedDecl (qtype q)
1104 ctype ct = ctype_realType (qtype_getType (q));
1106 if (ctype_isStruct (ct) || ctype_isUnion (ct))
1108 return uentryList_single (uentry_makeUnnamedVariable (ct));
1110 else if (ctype_isEnum (ct))
1112 /* evans 2002-02-05: nothing to do for unnamed enum lists */
1113 return uentryList_undefined;
1119 message ("Type name in field declarations: %s", qtype_unparse (q)),
1123 return uentryList_undefined;
1126 void setStorageClass (storageClassCode sc)
1132 setProcessingIterVars (uentry iter)
1134 s_processingIterVars = TRUE;
1136 saveIterParamNo = 0;
1140 setProcessingGlobalsList ()
1142 s_processingGlobals = TRUE;
1143 fcnNoGlobals = FALSE;
1146 static bool ProcessingGlobMods = FALSE;
1149 setProcessingGlobMods ()
1151 ProcessingGlobMods = TRUE;
1155 clearProcessingGlobMods ()
1157 ProcessingGlobMods = FALSE;
1161 isProcessingGlobMods ()
1163 return (ProcessingGlobMods);
1166 static void resetGlobals (void)
1168 s_processingGlobals = FALSE;
1169 fcnNoGlobals = FALSE;
1173 unsetProcessingGlobals ()
1175 s_processingGlobals = FALSE;
1179 setProcessingVars (/*@only@*/ qtype q)
1181 s_processingVars = TRUE;
1182 qtype_free (processingType);
1187 setGenericParamList (/*@dependent@*/ uentryList pm)
1189 s_processingParams = TRUE;
1194 setProcessingTypedef (qtype q)
1196 s_processingTypedef = TRUE;
1198 qtype_free (processingType);
1203 unsetProcessingVars ()
1205 resetStorageClass ();
1206 s_processingVars = FALSE;
1210 oldStyleDoneParams ()
1212 if (s_processingParams)
1214 if (uentry_isInvalid (saveFunction))
1216 llbuglit ("unsetProcessingVars: no saved function\n");
1220 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1221 uentryList params = uentryList_copy (saveParamList);
1222 ctype ct2 = ctype_makeFunction (ct, params);
1224 uentry_setType (saveFunction, ct2);
1225 s_processingParams = FALSE;
1227 oldStyleCompleteFunction (saveFunction);
1228 saveFunction = uentry_undefined;
1235 ** If the paramlist used a type name, we could be here.
1238 llfatalerror (message ("%q: Old-style function parameter list uses a "
1239 "type name.", fileloc_unparse (g_currentloc)));
1246 if (uentry_isValid (saveFunction))
1249 ** old style declaration
1252 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1255 DPRINTF (("save function: %s", uentry_unparseFull (saveFunction)));
1257 uentryList_elements (saveParamList, current)
1259 uentry_setType (current, ctype_int); /* all params are ints */
1260 } end_uentryList_elements;
1262 ct2 = ctype_makeParamsFunction (ct, uentryList_copy (saveParamList));
1264 uentry_setType (saveFunction, ct2);
1265 s_processingParams = FALSE;
1267 oldStyleDeclareFunction (saveFunction);
1268 saveFunction = uentry_undefined;
1272 void clabstract_declareType (/*@only@*/ exprNodeList decls, /*@only@*/ warnClause warn)
1274 llassert (s_processingTypedef);
1276 DPRINTF (("Declare type: %s", exprNodeList_unparse (decls)));
1278 if (warnClause_isDefined (warn))
1280 DPRINTF (("Has a warn clause!"));
1281 DPRINTF (("Warn: %s", warnClause_unparse (warn)));
1283 exprNodeList_elements (decls, el)
1285 uentry ue = exprNode_getUentry (el);
1286 cstring uname = uentry_getName (ue);
1288 DPRINTF (("Entry: %s", exprNode_unparse (el)));
1291 ** Need to lookup again to make sure we have the right one...
1294 ue = usymtab_lookupExposeGlob (uname);
1296 llassert (uentry_isValid (ue));
1297 llassert (uentry_isDatatype (ue));
1299 DPRINTF (("Warning for %s: %s",
1300 uentry_unparse (ue), warnClause_unparse (warn)));
1302 uentry_addWarning (ue, warnClause_copy (warn));
1303 DPRINTF (("After add warning: %s", uentry_unparseFull (ue)));
1304 cstring_free (uname);
1305 } end_exprNodeList_elements;
1308 warnClause_free (warn);
1309 exprNodeList_free (decls);
1310 unsetProcessingTypedef ();
1314 unsetProcessingTypedef ()
1316 s_processingTypedef = FALSE;
1319 void checkConstant (qtype t, idDecl id)
1323 id = idDecl_fixBase (id, t);
1324 e = uentry_makeIdConstant (id);
1326 reflectStorageClass (e);
1327 resetStorageClass ();
1329 DPRINTF (("Constant: %s", uentry_unparseFull (e)));
1330 usymtab_supGlobalEntry (e);
1333 void checkValueConstant (qtype t, idDecl id, exprNode e)
1337 id = idDecl_fixBase (id, t);
1338 ue = uentry_makeIdConstant (id);
1339 reflectStorageClass (ue);
1340 resetStorageClass ();
1342 if (exprNode_isDefined (e))
1344 if (!exprNode_matchType (uentry_getType (ue), e))
1347 (exprNode_getType (e), e,
1348 uentry_getType (ue), exprNode_undefined,
1349 message ("Constant %q initialized to type %t, expects %t: %s",
1350 uentry_getName (ue),
1351 exprNode_getType (e),
1352 uentry_getType (ue),
1353 exprNode_unparse (e)),
1358 if (exprNode_hasValue (e))
1360 uentry_mergeConstantValue (ue, multiVal_copy (exprNode_getValue (e)));
1364 DPRINTF (("No value: %s", exprNode_unparse (e)));
1369 DPRINTF (("Constant value: %s", uentry_unparseFull (ue)));
1370 usymtab_supGlobalEntry (ue);
1373 static void processVariable (idDecl t)
1378 ct = ctype_realType (idDecl_getCtype (t));
1380 if (s_processingParams)
1382 cstring id = idDecl_getName (t);
1383 int paramno = uentryList_lookupRealName (saveParamList, id);
1387 uentry cparam = uentryList_getN (saveParamList, paramno);
1389 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1390 uentry_setType (cparam, idDecl_getCtype (t));
1391 uentry_reflectQualifiers (cparam, idDecl_getQuals (t));
1392 uentry_setDeclaredOnly (cparam, context_getSaveLocation ());
1393 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1398 (message ("Old style declaration uses unlisted parameter: %s",
1406 if (context_inIterDef ())
1408 cstring pname = makeParam (idDecl_observeId (t));
1409 uentry p = usymtab_lookupSafe (pname);
1411 cstring_free (pname);
1413 if (uentry_isYield (p))
1415 e = uentry_makeParam (t, sRef_getParam (uentry_getSref (p)));
1416 uentry_checkYieldParam (p, e);
1417 usymtab_supEntrySref (e);
1422 if ((hasSpecialCode () || argsUsed)
1423 && ctype_isFunction (idDecl_getCtype (t)))
1425 e = uentry_makeIdFunction (t);
1426 reflectSpecialCode (e);
1427 reflectArgsUsed (e);
1431 e = uentry_makeIdVariable (t);
1434 loc = uentry_whereDeclared (e);
1437 if (context_inGlobalScope ())
1439 uentry_checkParams was here!
1443 if (ctype_isFunction (uentry_getType (e)))
1445 clabstract_prepareFunction (e);
1448 DPRINTF (("Superceding... %s", uentry_unparseFull (e)));
1449 e = usymtab_supEntrySrefReturn (e);
1450 DPRINTF (("After superceding... %s", uentry_unparseFull (e)));
1452 if (uentry_isExtern (e) && !context_inGlobalScope ())
1456 message ("Declaration using extern inside function scope: %q",
1457 uentry_unparse (e)),
1460 uentry_setDefined (e, fileloc_getExternal ());
1461 sRef_setDefined (uentry_getSref (e), fileloc_getExternal ());
1464 if (uentry_isFunction (e))
1466 if (!context_inXHFile ())
1468 checkParamNames (e);
1472 if (uentry_isVar (e) && uentry_isCheckedUnknown (e))
1474 sRef sr = uentry_getSref (e);
1476 if (sRef_isLocalVar (sr))
1478 if (context_getFlag (FLG_IMPCHECKMODINTERNALS))
1480 uentry_setCheckMod (e);
1484 uentry_setUnchecked (e);
1487 else if (sRef_isFileStatic (sr))
1489 if (context_getFlag (FLG_IMPCHECKEDSTRICTSTATICS))
1491 uentry_setCheckedStrict (e);
1493 else if (context_getFlag (FLG_IMPCHECKEDSTATICS))
1495 uentry_setChecked (e);
1497 else if (context_getFlag (FLG_IMPCHECKMODSTATICS))
1499 uentry_setCheckMod (e);
1506 else /* real global */
1508 llassert (sRef_isRealGlobal (sr));
1510 if (context_getFlag (FLG_IMPCHECKEDSTRICTGLOBALS))
1512 uentry_setCheckedStrict (e);
1514 else if (context_getFlag (FLG_IMPCHECKEDGLOBALS))
1516 uentry_setChecked (e);
1518 else if (context_getFlag (FLG_IMPCHECKMODGLOBALS))
1520 uentry_setCheckMod (e);
1531 void processNamedDecl (idDecl t)
1533 if (qtype_isUndefined (processingType))
1535 processingType = qtype_create (ctype_int);
1536 t = idDecl_fixBase (t, processingType);
1538 voptgenerror (FLG_IMPTYPE,
1539 message ("No type before declaration name (implicit int type): %q",
1540 idDecl_unparse (t)),
1545 t = idDecl_fixBase (t, processingType);
1548 DPRINTF (("Declare: %s", idDecl_unparse (t)));
1550 if (s_processingGlobals)
1552 cstring id = idDecl_getName (t);
1553 uentry ue = usymtab_lookupSafe (id);
1555 if (!uentry_isValid (ue))
1557 llerror (FLG_UNRECOG,
1558 message ("Variable used in globals list is undeclared: %s", id));
1562 if (!ctype_match (uentry_getType (ue), idDecl_getCtype (t)))
1566 message ("Variable %s used in globals list declared %s, "
1568 id, ctype_unparse (uentry_getType (ue)),
1569 ctype_unparse (idDecl_getCtype (t))),
1574 sRef sr = sRef_copy (uentry_getSref (ue));
1575 reflectGlobalQualifiers (sr, idDecl_getQuals (t));
1579 else if (s_processingVars)
1581 processVariable (t);
1583 else if (s_processingTypedef)
1585 ctype ct = idDecl_getCtype (t);
1588 DPRINTF (("Processing typedef: %s", ctype_unparse (ct)));
1590 e = uentry_makeIdDatatype (t);
1592 if (cstring_equal (idDecl_getName (t), context_getBoolName ())) {
1593 ctype rt = ctype_realType (ct);
1595 if (ctype_isEnum (rt)) {
1598 if (!(ctype_isInt (rt)
1599 || ctype_isUnknown (rt)
1600 || ctype_isChar (rt))) {
1603 message ("Boolean type %s defined using non-standard type %s (integral, char or enum type expected)",
1604 context_getBoolName (),
1605 ctype_unparse (ct)),
1606 uentry_whereLast (e));
1610 uentry_setType (e, ct);
1614 reflectStorageClass (e);
1615 checkTypeDecl (e, ct);
1617 e = usymtab_supReturnTypeEntry (e);
1621 llparseerror (message ("Suspect missing struct or union keyword: %q",
1622 idDecl_unparse (t)));
1628 ** moved from grammar
1631 static idDecl fixStructDecl (/*@returned@*/ idDecl d)
1633 if (ctype_isVisiblySharable (idDecl_getCtype (d))
1634 && context_getFlag (FLG_STRUCTIMPONLY))
1636 if (!qualList_hasAliasQualifier (idDecl_getQuals (d)))
1638 if (qualList_hasExposureQualifier (idDecl_getQuals (d)))
1640 idDecl_addQual (d, qual_createDependent ());
1644 idDecl_addQual (d, qual_createImpOnly ());
1653 declareUnnamedStruct (/*@only@*/ uentryList f)
1655 DPRINTF (("Unnamed struct: %s", uentryList_unparse (f)));
1657 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1659 int num = uentryList_size (f);
1660 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1665 (FLG_NUMSTRUCTFIELDS,
1666 message ("Structure declared with %d fields "
1667 "(limit is set to %d)",
1673 return (ctype_createUnnamedStruct (f));
1677 declareUnnamedUnion (/*@only@*/ uentryList f)
1679 DPRINTF (("Unnamed union: %s", uentryList_unparse (f)));
1681 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1683 int num = uentryList_size (f);
1684 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1689 (FLG_NUMSTRUCTFIELDS,
1690 message ("Union declared with %d fields "
1691 "(limit is set to %d)",
1697 return (ctype_createUnnamedUnion (f));
1700 ctype declareStruct (cstring id, /*@only@*/ uentryList f)
1704 int num = uentryList_size (f);
1706 DPRINTF (("Declare struct: %s / %s [%d]", id, uentryList_unparse (f),
1707 uentryList_size (f)));
1709 ct = ctype_createStruct (cstring_copy (id), f);
1711 DPRINTF (("Ctype: %s", ctype_unparse (ct)));
1713 ue = uentry_makeStructTagLoc (id, ct);
1715 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
1717 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1719 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1724 (FLG_NUMSTRUCTFIELDS,
1725 message ("Structure %q declared with %d fields "
1726 "(limit is set to %d)",
1727 uentry_getName (ue), num, max),
1728 uentry_whereLast (ue));
1732 return (usymtab_supTypeEntry (ue));
1735 ctype declareUnion (cstring id, uentryList f)
1739 int num = uentryList_size (f);
1741 ct = ctype_createUnion (cstring_copy (id), f);
1742 ue = uentry_makeUnionTagLoc (id, ct);
1744 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1746 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1751 (FLG_NUMSTRUCTFIELDS,
1752 message ("Union %q declared with %d fields "
1753 "(limit is set to %d)",
1754 uentry_getName (ue), num, max),
1755 uentry_whereLast (ue));
1759 return (usymtab_supTypeEntry (ue));
1762 ctype handleStruct (/*@only@*/ cstring id)
1764 if (usymtab_existsStructTag (id))
1766 ctype ct = uentry_getAbstractType (usymtab_lookupStructTag (id));
1773 return (ctype_createForwardStruct (id));
1777 ctype handleUnion (/*@only@*/ cstring id)
1779 if (usymtab_existsUnionTag (id))
1781 ctype ret = uentry_getAbstractType (usymtab_lookupUnionTag (id));
1787 return (ctype_createForwardUnion (id));
1792 handleEnum (cstring id)
1794 if (usymtab_existsEnumTag (id))
1796 ctype ret = uentry_getAbstractType (usymtab_lookupEnumTag (id));
1802 return (declareEnum (id, enumNameList_new ()));
1806 bool processingIterVars (void)
1808 return s_processingIterVars;
1811 uentry getCurrentIter (void)
1816 static bool flipOldStyle = FALSE;
1817 static bool flipNewStyle = TRUE;
1819 void setFlipOldStyle () { flipOldStyle = TRUE; }
1820 bool isFlipOldStyle () { return flipOldStyle; }
1821 bool isNewStyle () { return flipNewStyle; }
1822 void setNewStyle () { flipNewStyle = TRUE; }
1824 /*@dependent@*/ uentryList handleParamIdList (/*@dependent@*/ uentryList params)
1829 ** this is a really YUCKY hack to handle old style
1833 voptgenerror (FLG_OLDSTYLE,
1834 cstring_makeLiteral ("Old style function declaration"),
1837 DPRINTF (("Handle old style params: %s", uentryList_unparseFull (params)));
1839 uentryList_elements (params, current)
1841 uentry_setParam (current);
1842 uentry_setSref (current, sRef_makeParam (paramno, ctype_unknown, stateInfo_makeLoc (uentry_whereLast (current))));
1844 } end_uentryList_elements;
1846 setGenericParamList (params);
1847 g_expectingTypeName = TRUE;
1852 /*@dependent@*/ uentryList handleParamTypeList (/*@returned@*/ uentryList params)
1856 uentryList_fixMissingNames (params);
1858 voptgenerror (FLG_OLDSTYLE,
1859 cstring_makeLiteral ("Old style function declaration."),
1862 setGenericParamList (params);
1863 flipOldStyle = FALSE;
1864 g_expectingTypeName = TRUE;
1873 ctype c = ctype_unknown;
1874 cstring id = cstring_makeLiteral ("va_alist");
1877 if (s_processingParams)
1879 int i = uentryList_lookupRealName (saveParamList, id);
1883 fileloc loc = context_getSaveLocation ();
1884 e = uentry_makeVariableSrefParam (id, c, loc, sRef_makeParam (i, c, stateInfo_makeLoc (loc)));
1888 e = uentry_undefined; /* suppress gcc message */
1889 llfatalerrorLoc (cstring_makeLiteral ("va_dcl used without va_alist"));
1894 llerror (FLG_SYNTAX, cstring_makeLiteral ("va_dcl used outside of function declaration"));
1895 e = uentry_makeVariableLoc (id, c);
1899 uentry_setUsed (e, g_currentloc);
1900 usymtab_supEntrySref (e);
1903 /*@exposed@*/ sRef modListPointer (/*@exposed@*/ sRef s)
1905 ctype ct = sRef_getType (s);
1906 ctype rt = ctype_realType (ct);
1908 if (ctype_isAP (rt))
1910 if (context_inHeader () && ctype_isAbstract (ct))
1915 ("Modifies clause in header file dereferences abstract "
1916 "type %s (interface modifies clause should not depend "
1917 "on or expose type representation): %q",
1923 return (sRef_constructPointer (s));
1927 if (ctype_isKnown (rt))
1931 message ("Implementation modifies clause dereferences non-pointer (type %s): %q",
1941 /*@exposed@*/ sRef modListFieldAccess (sRef s, cstring f)
1943 ctype ct = sRef_getType (s);
1944 ctype rt = ctype_realType (ct);
1946 if (ctype_isStructorUnion (rt))
1948 uentry tf = uentryList_lookupField (ctype_getFields (rt), f);
1950 if (uentry_isUndefined (tf))
1952 voptgenerror (FLG_TYPE,
1953 message ("Modifies list accesses non-existent "
1954 "field %s of %t: %q", f, ct,
1959 return sRef_undefined;
1963 if (ctype_isAbstract (ct) && context_inHeader ())
1968 ("Modifies clause in header file accesses abstract "
1969 "type %s (interface modifies clause should not depend "
1970 "on or expose type representation): %q",
1977 cstring_markOwned (f);
1978 return (sRef_makeField (s, f));
1984 message ("Modifies clause dereferences non-pointer (type %s): %q",
1994 /*@dependent@*/ sRef clabstract_unrecognizedGlobal (cstring s)
1996 if (cstring_equalLit (s, "nothing"))
1998 return sRef_makeNothing ();
2000 else if (cstring_equalLit (s, "internalState"))
2002 return sRef_makeInternalState ();
2004 else if (cstring_equalLit (s, "fileSystem")
2005 || cstring_equalLit (s, "systemState"))
2007 return sRef_makeSystemState ();
2013 message ("Unrecognized identifier in globals list: %s", s),
2016 return sRef_undefined;
2020 /*@exposed@*/ sRef modListArrowAccess (sRef s, cstring f)
2022 ctype ct = sRef_getType (s);
2023 ctype rt = ctype_realType (ct);
2025 if (ctype_isRealPointer (rt))
2027 ctype b = ctype_baseArrayPtr (rt);
2028 ctype rb = ctype_realType (b);
2030 if (ctype_isStructorUnion (rb))
2032 uentry tf = uentryList_lookupField (ctype_getFields (rb), f);
2034 if (uentry_isUndefined (tf))
2036 voptgenerror (FLG_TYPE,
2037 message ("Modifies list arrow accesses non-existent "
2038 "field %s of %t: %q", f, b,
2043 return sRef_undefined;
2047 if (context_inHeader ())
2049 if (ctype_isAbstract (b))
2054 ("Modifies clause in header file arrow accesses abstract "
2055 "type %s (interface modifies clause should not depend "
2056 "on or expose type representation): %q",
2064 if (ctype_isAbstract (rt))
2069 ("Modifies clause arrow accesses inaccessible abstract "
2070 "type %s (interface modifies clause should not depend "
2071 "on or expose type representation): %q",
2079 cstring_markOwned (f);
2080 return (sRef_makeArrow (s, f));
2086 message ("Modifies clause arrow accesses pointer to "
2087 "non-structure (type %s): %q",
2097 message ("Modifies clause arrow accesses non-pointer (type %s): %q",
2107 sRef checkStateClausesId (uentry ue)
2109 cstring s = uentry_rawName (ue);
2111 if (sRef_isFileOrGlobalScope (uentry_getSref (ue)))
2115 message ("Global variable %s used state clause. (Global variables "
2116 "are not recognized in state clauses. If there is "
2117 "sufficient interest in support for this, it may be "
2118 "added to a future release. Send mail to "
2119 "info@splint.org.)",
2123 return sRef_undefined;
2127 if (cstring_equalLit (s, "result"))
2131 message ("Special clause list uses %s which is a variable and has special "
2132 "meaning in a modifies list. (Special meaning assumed.)", s),
2135 uentry_showWhereDeclared (ue);
2139 return uentry_getSref (ue);
2145 don;t know what the real date is...
2151 based on checkSpecClausesId
2155 sRef checkbufferConstraintClausesId (uentry ue)
2157 cstring s = uentry_rawName (ue);
2159 if (cstring_equalLit (s, "result"))
2163 message ("Function clause list uses %s which is a variable and has special "
2164 "meaning in a modifies list. (Special meaning assumed.)", s),
2167 uentry_showWhereDeclared (ue);
2171 DPRINTF (("constrant id: %s", uentry_unparseFull (ue)));
2172 return sRef_saveCopy (uentry_getSref (ue)); /*@i523 why the saveCopy? */
2175 void checkModifiesId (uentry ue)
2177 cstring s = uentry_rawName (ue);
2179 if (cstring_equalLit (s, "nothing")
2180 || cstring_equalLit (s, "internalState")
2181 || cstring_equalLit (s, "systemState")
2182 || (cstring_equalLit (s, "fileSystem")))
2186 message ("Modifies list uses %s which is a variable and has special "
2187 "meaning in a modifies list. (Special meaning assumed.)", s),
2190 uentry_showWhereDeclared (ue);
2195 /*@exposed@*/ sRef fixModifiesId (cstring s)
2198 cstring pname = makeParam (s);
2199 uentry ue = usymtab_lookupSafe (pname);
2201 cstring_free (pname);
2203 if (cstring_equalLit (s, "nothing"))
2205 ret = sRef_makeNothing ();
2207 else if (cstring_equalLit (s, "internalState"))
2209 ret = sRef_makeInternalState ();
2211 else if (cstring_equalLit (s, "fileSystem")
2212 || cstring_equalLit (s, "systemState"))
2214 ret = sRef_makeSystemState ();
2218 ret = sRef_undefined;
2221 if (sRef_isValid (ret))
2223 if (uentry_isValid (ue))
2227 message ("Modifies list uses %s which is a parameter and has special "
2228 "meaning in a modifies list. (Special meaning assumed.)", s),
2234 if (uentry_isValid (ue))
2236 ret = uentry_getSref (ue);
2240 fileloc loc = fileloc_decColumn (g_currentloc, size_toInt (cstring_length (s)));
2241 ret = sRef_undefined;
2245 message ("Unrecognized identifier in modifies comment: %s", s),
2255 sRef fixStateClausesId (cstring s)
2258 cstring pname = makeParam (s);
2259 uentry ue = usymtab_lookupSafe (pname);
2261 cstring_free (pname);
2263 if (cstring_equalLit (s, "result"))
2265 ret = sRef_makeResult (ctype_unknown);
2269 ret = sRef_undefined;
2272 if (sRef_isValid (ret))
2274 if (uentry_isValid (ue))
2278 message ("Function clause uses %s which is a parameter and has special "
2279 "meaning in a function clause. (Special meaning assumed.)", s),
2285 if (uentry_isValid (ue))
2287 ret = uentry_getSref (ue);
2289 if (sRef_isFileOrGlobalScope (ret))
2293 message ("Global variable %s used in function clause. (Global variables "
2294 "are not recognized in function clauses. If there is "
2295 "sufficient interest in support for this, it may be "
2296 "added to a future release. Send mail to "
2297 "info@splint.org.)",
2301 ret = sRef_undefined;
2307 /*drl handle structure invariant */
2310 /*check that we're in a structure */
2312 /*@unused@*/ uentryList ueL;
2313 /*@unused@*/ uentry ue2;
2314 /*@unused@*/ ctype ct;
\r
2316 fileloc loc = fileloc_decColumn (g_currentloc, size_toInt (cstring_length (s)));
2317 ret = sRef_undefined;
2319 /*drl commenting this out for now
2320 ct = context_getLastStruct ( ct );
2322 llassert( ctype_isStruct(ct) );
2324 ueL = ctype_getFields (ct);
2326 ue2 = uentryList_lookupField (ueL, s);
2328 if (!uentry_isUndefined(ue2) )
2330 ret = uentry_getSref(ue2);
2333 message("Got field in structure in the annotation constraint: %s (or sref: %s)", s, sRef_unparse(ret) )
2343 message ("Unrecognized identifier in function clause: %s", s),
2353 sRef modListArrayFetch (/*@exposed@*/ sRef s, /*@unused@*/ sRef mexp)
2355 ctype ct = sRef_getType (s);
2356 ctype rt = ctype_realType (ct);
2358 if (ctype_isAP (rt))
2360 if (context_inHeader () && ctype_isAbstract (ct))
2365 ("Modifies clause in header file indexes abstract "
2366 "type %s (interface modifies clause should not depend "
2367 "on or expose type representation): %q",
2373 return (sRef_makeAnyArrayFetch (s));
2380 ("Implementation modifies clause uses array fetch on non-array (type %s): %q",
2381 ctype_unparse (ct), sRef_unparse (s)),
2387 static void clabstract_prepareFunction (uentry e)
2389 uentry_checkParams (e);
2390 DPRINTF (("After prepare: %s", uentry_unparseFull (e)));
2393 sRef clabstract_checkGlobal (exprNode e)
2396 llassert (exprNode_isInitializer (e));
2398 s = exprNode_getSref (e);
2399 DPRINTF (("Initializer: %s -> %s", exprNode_unparse (e), sRef_unparse (s)));
2402 return sRef_copy (s);