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"
34 # include "usymtab_interface.h"
36 # include "structNames.h"
37 # include "nameChecks.h"
40 # include "sgrammar_tokens.h"
42 # include "cgrammar_tokens.h"
46 ** Lots of variables are needed because of interactions with the
47 ** parser. This is easier than restructuring the grammar so the
48 ** right values are available in the right place.
52 static /*@only@*/ constraintList implicitFcnConstraints = NULL;
54 static void clabstract_prepareFunction (uentry p_e) /*@modifies p_e@*/ ;
55 static bool fcnNoGlobals = FALSE;
56 static void processVariable (/*@temp@*/ idDecl p_t) /*@modifies internalState@*/ ;
58 static bool s_processingVars = FALSE;
59 static bool s_processingParams = FALSE;
60 static bool s_processingGlobals = FALSE;
61 static bool s_processingTypedef = FALSE;
62 static bool s_processingIterVars = FALSE;
63 static /*@only@*/ qtype processingType = qtype_undefined;
64 static uentry currentIter = uentry_undefined;
65 static /*@dependent@*/ uentryList saveParamList; /* for old style functions */
66 static /*@owned@*/ uentry saveFunction = uentry_undefined;
67 static int saveIterParamNo;
68 static idDecl fixStructDecl (/*@returned@*/ idDecl p_d);
69 static void checkTypeDecl (uentry p_e, ctype p_rep);
70 static /*@dependent@*/ fileloc saveStoreLoc = fileloc_undefined;
71 static storageClassCode storageClass = SCNONE;
72 static void declareEnumList (/*@temp@*/ enumNameList p_el, ctype p_c, fileloc p_loc);
73 static void resetGlobals (void);
74 static /*@null@*/ qual specialFunctionCode;
75 static bool argsUsed = FALSE;
77 extern void clabstract_initMod ()
79 specialFunctionCode = qual_createUnknown ();
80 DPRINTF (("Initialized: %s", qual_unparse (specialFunctionCode)));
83 static bool hasSpecialCode (void)
85 return (!qual_isUnknown (specialFunctionCode));
88 extern void setArgsUsed (void)
94 cstring_makeLiteral ("Multiple ARGSUSED comments for one function"),
101 static void reflectArgsUsed (uentry ue)
105 if (uentry_isFunction (ue))
107 uentryList params = uentry_getParams (ue);
109 uentryList_elements (params, el)
111 uentry_setUsed (el, fileloc_undefined);
112 } end_uentryList_elements ;
119 extern void setSpecialFunction (qual qu)
121 if (!qual_isUnknown (specialFunctionCode))
123 voptgenerror (FLG_SYNTAX,
124 message ("Multiple special function codes: %s, %s "
125 "(first code is ignored)",
126 qual_unparse (specialFunctionCode),
131 specialFunctionCode = qu;
134 static void reflectSpecialCode (uentry ue)
136 if (qual_isUnknown (specialFunctionCode)) {
138 } else if (qual_isPrintfLike (specialFunctionCode)) {
139 uentry_setPrintfLike (ue);
140 } else if (qual_isScanfLike (specialFunctionCode)) {
141 uentry_setScanfLike (ue);
142 } else if (qual_isMessageLike (specialFunctionCode)) {
143 uentry_setMessageLike (ue);
148 specialFunctionCode = qual_createUnknown ();
151 static void resetStorageClass (void)
153 qtype_free (processingType);
154 processingType = qtype_undefined;
155 storageClass = SCNONE;
158 static void reflectStorageClass (uentry u)
160 if (storageClass == SCSTATIC)
162 uentry_setStatic (u);
164 else if (storageClass == SCEXTERN)
166 uentry_setExtern (u);
170 ; /* no storage class */
177 saveStoreLoc = g_currentloc;
180 void setFunctionNoGlobals (void)
185 static void reflectGlobalQualifiers (sRef sr, qualList quals)
187 DPRINTF (("Reflect global qualifiers: %s / %s",
188 sRef_unparseFull (sr), qualList_unparse (quals)));
190 qualList_elements (quals, qel)
192 if (qual_isGlobalQual (qel)) /* undef, killed */
194 sstate oldstate = sRef_getDefState (sr);
195 sstate defstate = sstate_fromQual (qel);
197 if ((oldstate == SS_UNDEFGLOB && defstate == SS_KILLED)
198 || (oldstate == SS_KILLED && defstate == SS_UNDEFGLOB))
200 defstate = SS_UNDEFKILLED;
207 sRef_setDefState (sr, defstate, fileloc_undefined);
208 DPRINTF (("State: %s", sRef_unparseFull (sr)));
210 else if (qual_isAllocQual (qel)) /* out, partial, reldef, etc. */
212 ctype realType = sRef_getType (sr);
213 sstate defstate = sstate_fromQual (qel);
215 if (qual_isRelDef (qel))
217 ; /* okay anywhere */
221 if (!ctype_isAP (realType)
222 && !ctype_isSU (realType)
223 && !ctype_isUnknown (realType)
224 && !ctype_isAbstract (sRef_getType (sr)))
228 message ("Qualifier %s used on non-pointer or struct: %q",
229 qual_unparse (qel), sRef_unparse (sr)));
234 sRef_setDefState (sr, defstate, fileloc_undefined);
236 else if (qual_isNull (qel))
238 sRef_setNullState (sr, NS_POSNULL, fileloc_undefined);
240 else if (qual_isRelNull (qel))
242 sRef_setNullState (sr, NS_RELNULL, fileloc_undefined);
244 else if (qual_isNotNull (qel))
246 sRef_setNullState (sr, NS_MNOTNULL, fileloc_undefined);
250 if (qual_isCQual (qel))
257 message ("Qualifier %s cannot be used in a globals list",
258 qual_unparse (qel)));
261 } end_qualList_elements;
264 sRef clabstract_createGlobal (sRef sr, qualList quals)
268 if (sRef_isValid (sr))
270 res = sRef_copy (sr);
271 DPRINTF (("Reflecting quals: %s / %s", sRef_unparse (sr), qualList_unparse (quals)));
272 reflectGlobalQualifiers (res, quals);
273 DPRINTF (("==> %s", sRef_unparseFull (res)));
277 res = sRef_undefined;
280 qualList_free (quals);
284 extern void declareCIter (cstring name, /*@owned@*/ uentryList params)
288 ue = uentry_makeIter (name,
289 ctype_makeFunction (ctype_void, params),
290 fileloc_copy (g_currentloc));
292 usymtab_supEntry (uentry_makeEndIter (name, fileloc_copy (g_currentloc)));
293 ue = usymtab_supGlobalEntryReturn (ue);
296 extern void nextIterParam (void)
298 llassert (s_processingIterVars);
302 extern int iterParamNo (void)
304 llassert (s_processingIterVars);
305 return saveIterParamNo;
309 ** yucky hacks to put it in the right place
313 makeCurrentParam (idDecl t)
317 saveStoreLoc = fileloc_undefined;
319 /* param number unknown */
321 ue = uentry_makeParam (t, 0);
326 declareUnnamedEnum (enumNameList el)
328 ctype ret = usymtab_enumEnumNameListType (el);
332 if (ctype_isDefined (ret))
335 e = uentry_makeEnumTagLoc (ctype_enumTag (rt), ret);
337 reflectStorageClass (e);
338 usymtab_supGlobalEntry (e);
340 declareEnumList (el, ret, g_currentloc);
341 enumNameList_free (el);
345 ctype ct = ctype_createEnum (fakeTag (), el);
347 e = uentry_makeEnumTagLoc (ctype_enumTag (ctype_realType (ct)), ct);
348 reflectStorageClass (e);
350 e = usymtab_supGlobalEntryReturn (e);
351 rt = uentry_getAbstractType (e);
352 declareEnumList (el, ct, g_currentloc);
359 declareEnum (cstring ename, enumNameList el)
364 llassert (cstring_isDefined (ename));
366 cet = ctype_createEnum (ename, el);
367 e = uentry_makeEnumTagLoc (ename, cet);
368 reflectStorageClass (e);
369 e = usymtab_supGlobalEntryReturn (e);
370 cet = uentry_getType (e);
371 declareEnumList (el, cet, uentry_whereLast (e));
372 return (uentry_getAbstractType (e));
376 declareEnumList (enumNameList el, ctype c, fileloc loc)
378 bool boolnames = FALSE;
379 bool othernames = FALSE;
381 (void) context_getSaveLocation (); /* undefine it */
383 if (context_maybeSet (FLG_NUMENUMMEMBERS))
385 int maxnum = context_getValue (FLG_NUMENUMMEMBERS);
386 int num = enumNameList_size (el);
392 message ("Enumerator %s declared with %d members (limit is set to %d)",
393 ctype_unparse (c), num, maxnum),
398 enumNameList_elements (el, e)
400 uentry ue = usymtab_lookupExposeGlob (e);
401 ctype ct = uentry_getType (ue);
403 llassert (uentry_isEnumConstant (ue));
405 if (ctype_isUnknown (ct))
407 uentry_setType (ue, c);
411 if (cstring_equal (e, context_getFalseName ())
412 || cstring_equal (e, context_getTrueName ()))
418 message ("Enumerator mixes boolean name (%s) with "
421 uentry_whereLast (ue)))
428 uentry_setType (ue, ctype_bool);
429 DPRINTF (("Set type: %s / %s",
430 uentry_unparse (ue), ctype_unparse (ctype_bool)));
438 message ("Enumerator mixes boolean names (%s, %s) with "
439 "non-boolean name: %s",
440 context_getTrueName (),
441 context_getFalseName (),
443 uentry_whereLast (ue)))
452 if (!ctype_match (c, ct))
454 if (ctype_isDirectBool (ct))
456 if (cstring_equal (e, context_getFalseName ())
457 || cstring_equal (e, context_getTrueName ()))
459 DPRINTF (("Here we are!"));
465 message ("Enumerator member %s declared with "
466 "inconsistent type: %s",
467 e, ctype_unparse (c)),
468 uentry_whereLast (ue)))
470 uentry_showWhereSpecifiedExtra
471 (ue, cstring_copy (ctype_unparse (ct)));
479 message ("Enumerator member %s declared with "
480 "inconsistent type: %s",
481 e, ctype_unparse (c)),
482 uentry_whereLast (ue)))
484 uentry_showWhereSpecifiedExtra
485 (ue, cstring_copy (ctype_unparse (ct)));
490 } end_enumNameList_elements;
493 static /*@dependent@*/ uentryList currentParamList;
495 /*drl added 3-28-2002*/
496 /* this function takes a list of paramentar and generates a list
500 /* drl modified 10/23/2002
502 The current semantics are generated constraints of the form MaxSet(p) >= 0 and MaxRead(p) >= 0 for all pointers
503 unless the @out@ annotation has been applied to a parameter, then we only want to generate maxSet(p) > = 0
506 void setImplictfcnConstraints (void)
511 params = currentParamList;
513 if (constraintList_isDefined(implicitFcnConstraints) )
514 constraintList_free(implicitFcnConstraints);
516 implicitFcnConstraints = constraintList_makeNew();
518 uentryList_elements (params, el)
520 DPRINTF((message("setImplictfcnConstraints doing: %s", uentry_unparse(el) ) ));
522 s = uentry_getSref(el);
523 if (sRef_isReference (s) )
525 DPRINTF((message ("%s is a pointer", sRef_unparse(s) ) ));
529 DPRINTF((message ("%s is NOT a pointer", sRef_unparse(s) ) ));
532 chagned this from MaxSet(s) == 0 to MaxSet(s) >= 0 */
533 c = constraint_makeSRefWriteSafeInt (s, 0);
535 implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c);
537 /*drl 10/23/2002 added support for out*/
538 if (!uentry_isOut(el) )
540 c = constraint_makeSRefReadSafeInt (s, 0);
542 implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c);
547 end_uentryList_elements;
548 DPRINTF((message("implicitFcnConstraints has been set to %s\n",
549 constraintList_print(implicitFcnConstraints) ) ));
553 /*@observer@*/ constraintList getImplicitFcnConstraints (void)
555 return implicitFcnConstraints;
558 void setCurrentParams (/*@dependent@*/ uentryList ue)
560 currentParamList = ue;
563 void clearCurrentParams (void)
565 currentParamList = uentryList_undefined;
569 ** requires: uentry_isFunction (e)
570 ** parameter names for current function are in currentParamList
573 static void enterFunctionParams (uentryList params)
577 uentryList_elements (params, current)
579 if (uentry_hasName (current))
581 uentry_setParamNo (current, paramno);
582 usymtab_supEntry (uentry_copy (current));
586 } end_uentryList_elements;
590 extern void enterParamsTemp (void)
592 usymtab_enterScope ();
593 enterFunctionParams (currentParamList);
596 extern void exitParamsTemp (void)
598 usymtab_quietPlainExitScope ();
601 static /*@exposed@*/ uentry clabstract_globalDeclareFunction (idDecl tid)
603 ctype deftype = idDecl_getCtype (tid);
607 DPRINTF (("Global function: %s", idDecl_unparse (tid)));
609 if (ctype_isFunction (deftype))
611 rettype = ctype_getReturnType (deftype);
615 rettype = ctype_unknown;
619 ** check has been moved here...
622 if (ctype_isFunction (idDecl_getCtype (tid)))
624 ue = uentry_makeIdFunction (tid);
625 reflectSpecialCode (ue);
626 reflectArgsUsed (ue);
627 reflectStorageClass (ue);
628 uentry_checkParams (ue);
630 DPRINTF (("Supercede function: %s", uentry_unparseFull (ue)));
632 ue = usymtab_supGlobalEntryReturn (ue);
633 DPRINTF (("After supercede function: %s", uentry_unparseFull (ue)));
635 DPRINTF (("Enter function: %s", uentry_unparseFull (ue)));
636 context_enterFunction (ue);
637 enterFunctionParams (uentry_getParams (ue));
639 resetStorageClass ();
640 DPRINTF (("Function: %s", uentry_unparseFull (ue)));
645 llparseerror (message ("Non-function declaration: %q",
646 idDecl_unparse (tid)));
647 return (uentry_undefined);
652 ** for now, no type checking
653 ** (must check later though!)
656 static /*@only@*/ uentry globalDeclareOldStyleFunction (idDecl tid)
661 ** check has been moved here...
664 if (cstring_equalLit (idDecl_observeId (tid), "main"))
666 context_setFlagTemp (FLG_MAINTYPE, FALSE);
669 ue = uentry_makeIdFunction (tid);
670 reflectStorageClass (ue);
671 reflectSpecialCode (ue);
672 reflectArgsUsed (ue);
673 uentry_setDefined (ue, g_currentloc);
674 uentry_checkParams (ue);
675 resetStorageClass ();
677 /* context_enterOldStyleScope (); */
682 static void oldStyleDeclareFunction (/*@only@*/ uentry e)
684 uentryList params = saveParamList;
685 ctype rt = uentry_getType (e);
687 llassert (ctype_isFunction (rt));
689 if (uentry_hasStateClauseList (e)
690 || uentry_hasConditions (e))
692 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
693 fileloc_unparse (g_currentloc), uentry_unparse (e)));
696 e = usymtab_supGlobalEntryReturn (e);
698 context_enterFunction (e);
699 enterFunctionParams (params);
700 saveParamList = uentryList_undefined;
701 resetStorageClass ();
704 static void oldStyleCompleteFunction (/*@only@*/ uentry e)
706 uentryList params = saveParamList;
707 ctype rt = uentry_getType (e);
709 llassert (ctype_isFunction (rt));
711 if (uentry_hasStateClauseList (e)
712 || uentry_hasConditions (e))
714 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
715 fileloc_unparse (g_currentloc), uentry_unparse (e)));
718 e = usymtab_supGlobalEntryReturn (e);
720 context_completeOldStyleFunction (e);
721 enterFunctionParams (params);
722 saveParamList = uentryList_undefined;
723 resetStorageClass ();
726 void clabstract_declareFunction (idDecl tid) /*@globals undef saveFunction; @*/
730 DPRINTF (("Declare function: %s", idDecl_unparse (tid)));
732 if (ctype_isUnknown (idDecl_getCtype (tid)))
735 ** No type, its really a plain name (int) declaration
738 voptgenerror (FLG_IMPTYPE,
739 message ("No type before declaration name (implicit int type): %q",
740 idDecl_unparse (tid)),
742 tid = idDecl_replaceCtype (tid, ctype_int);
743 processVariable (tid);
744 saveFunction = uentry_undefined;
748 if (s_processingParams)
750 ue = globalDeclareOldStyleFunction (tid);
752 DPRINTF (("Set save function: %s", uentry_unparseFull (ue)));
756 saveFunction = uentry_undefined;
758 if (context_inRealFunction ())
760 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
762 llparseerror (message ("Function declared inside function: %q",
763 idDecl_unparse (tid)));
765 context_quietExitFunction ();
766 ue = usymtab_supEntryReturn (ue);
770 if (context_inInnerScope ())
772 llparseerror (message ("Declaration in inner context: %q",
773 idDecl_unparse (tid)));
775 sRef_setGlobalScope ();
776 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
778 ue = usymtab_supGlobalEntryReturn (ue);
779 sRef_clearGlobalScope ();
783 ue = clabstract_globalDeclareFunction (tid);
790 resetStorageClass ();
796 void declareStaticFunction (idDecl tid) /*@globals undef saveFunction; @*/
800 DPRINTF (("Declare static funciton: %s", idDecl_unparse (tid)));
802 if (s_processingParams)
804 ue = globalDeclareOldStyleFunction (tid);
809 saveFunction = uentry_undefined;
811 if (context_inRealFunction ())
813 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
815 llparseerror (message ("Function declared inside function: %q",
816 idDecl_unparse (tid)));
818 context_quietExitFunction ();
819 ue = usymtab_supEntryReturn (ue);
823 if (context_inInnerScope ())
825 llparseerror (message ("Declaration in inner context: %q",
826 idDecl_unparse (tid)));
828 sRef_setGlobalScope ();
829 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
831 ue = usymtab_supGlobalEntryReturn (ue);
832 sRef_clearGlobalScope ();
836 ctype deftype = idDecl_getCtype (tid);
839 if (ctype_isFunction (deftype))
841 rettype = ctype_getReturnType (deftype);
845 rettype = ctype_unknown;
849 ** check has been moved here...
852 if (ctype_isFunction (idDecl_getCtype (tid)))
854 ue = uentry_makeIdFunction (tid);
855 reflectSpecialCode (ue);
856 reflectArgsUsed (ue);
860 DPRINTF (("Here we are!"));
861 llparseerror (message ("Inconsistent function declaration: %q",
862 idDecl_unparse (tid)));
864 tid = idDecl_replaceCtype
865 (tid, ctype_makeFunction (ctype_unknown, uentryList_undefined));
866 ue = uentry_makeIdFunction (tid);
869 reflectStorageClass (ue);
870 uentry_setStatic (ue);
872 uentry_checkParams (ue);
874 DPRINTF (("Sub global entry: %s", uentry_unparse (ue)));
875 ue = usymtab_supGlobalEntryReturn (ue);
877 context_enterFunction (ue);
878 enterFunctionParams (uentry_getParams (ue));
879 resetStorageClass ();
886 resetStorageClass ();
891 checkTypeDecl (uentry e, ctype rep)
893 cstring n = uentry_getName (e);
895 DPRINTF (("Check type decl: %s", uentry_unparseFull (e)));
897 if (cstring_equal (context_getBoolName (), n))
899 ctype rrep = ctype_realType (rep);
902 ** for abstract enum types, we need to fix the enum members:
903 ** they should have the abstract type, not the rep type.
906 if (ctype_isEnum (ctype_realType (rrep)))
908 enumNameList el = ctype_elist (rrep);
910 enumNameList_elements (el, ye)
912 if (usymtab_existsGlob (ye))
914 uentry ue = usymtab_lookupSafe (ye);
915 uentry_setType (ue, ctype_bool);
918 if (cstring_equal (context_getTrueName (), ye)
919 || cstring_equal (context_getFalseName (), ye))
927 message ("Member of boolean enumerated type definition "
928 "does not match name set to represent TRUE "
931 message ("Use -boolfalse and -booltrue to set the "
932 "name of false and true boolean values."),
933 uentry_whereDefined (e));
935 } end_enumNameList_elements;
939 if (usymtab_exists (n))
941 usymId llm = usymtab_getId (n);
942 uentry le = usymtab_getTypeEntry (llm);
944 uentry_setDeclared (e, g_currentloc);
945 uentry_setSref (e, sRef_makeGlobal (llm, uentry_getType (le), stateInfo_currentLoc ()));
947 DPRINTF (("Here we are: %s / %s",
948 n, context_getBoolName ()));
950 if (uentry_isAbstractDatatype (le))
952 ctype rrep = ctype_realType (rep);
954 DPRINTF (("Abstract type: %s", uentry_unparseFull (le)));
957 ** for abstract enum types, we need to fix the enum members:
958 ** they should have the abstract type, not the rep type.
961 if (ctype_isEnum (ctype_realType (rrep)))
963 ctype at = uentry_getAbstractType (le);
964 enumNameList el = ctype_elist (rrep);
966 enumNameList_elements (el, ye)
968 if (usymtab_existsGlob (ye))
970 uentry ue = usymtab_lookupSafe (ye);
972 llassert (uentry_isEitherConstant (ue));
974 /* evans 2002-04-22 */
975 if (ctype_isBool (uentry_getType (ue)))
978 ** If set using -booltrue or -boolfalse, don't change the type.
983 llassertprint (ctype_match (uentry_getType (ue), rrep),
984 ("Bad enum: %s / %s",
986 ctype_unparse (rrep)));
988 uentry_setType (ue, at);
991 } end_enumNameList_elements;
994 if (uentry_isMutableDatatype (le))
996 /* maybe more complicated if abstract and immutable ? */
998 if (!ctype_isRealPointer (rep) && !ctype_isRealAbstract (rep))
1002 message ("Mutable abstract type %s declared without pointer "
1003 "indirection: %s (violates assignment semantics)",
1004 n, ctype_unparse (rep)),
1005 uentry_whereDefined (e));
1007 uentry_setMutable (e);
1014 fileloc fl = uentry_whereDeclared (e);
1016 if (context_getFlag (FLG_LIKELYBOOL)
1017 && !context_getFlag (FLG_BOOLINT))
1019 if ((cstring_equalLit (n, "BOOL")
1020 || cstring_equalLit (n, "Bool")
1021 || cstring_equalLit (n, "bool")
1022 || cstring_equalLit (n, "boolean")
1023 || cstring_equalLit (n, "Boolean")
1024 || cstring_equalLit (n, "BOOLEAN"))
1025 && !(cstring_equal (n, context_getBoolName ())))
1027 if (context_setBoolName ()) {
1030 message ("Type %s is probably meant as a boolean type, but does "
1031 "not match the boolean type name \"%s\".",
1033 context_getBoolName ()),
1038 message ("Type %s is probably meant as a boolean type, "
1039 "but the boolean type name is not set. "
1040 "Use -booltype %s to set it.",
1047 if (!uentry_isStatic (e)
1048 && !ctype_isFunction (uentry_getType (e))
1049 && !fileloc_isLib (fl)
1050 && !fileloc_isImport (fl)
1051 && fileloc_isHeader (fl))
1053 voptgenerror (FLG_EXPORTTYPE,
1054 message ("Type exported, but not specified: %s\n", n),
1063 fixUentryList (idDeclList tl, qtype q)
1065 uentryList f = uentryList_new ();
1067 idDeclList_elements (tl, i)
1069 if (idDecl_isDefined (i))
1075 (void) idDecl_fixBase (i, q);
1078 ** implicit annotations
1081 (void) fixStructDecl (i);
1083 ue = uentry_makeIdVariable (i);
1084 rt = ctype_realType (uentry_getType (ue));
1087 ** where is this here???
1089 if (ctype_isArray (rt) || ctype_isSU (rt))
1091 sRef_setAllocated (uentry_getSref (ue), uentry_whereDefined (ue));
1097 if (uentry_isValid (old = uentryList_lookupField (f, uentry_rawName (ue))))
1099 if (optgenerror (FLG_SYNTAX,
1100 message ("Field name reused: %s", uentry_rawName (ue)),
1101 uentry_whereDefined (ue)))
1103 llgenmsg (message ("Previous use of %s", uentry_rawName (ue)),
1104 uentry_whereDefined (old));
1108 f = uentryList_add (f, ue);
1110 } end_idDeclList_elements;
1112 idDeclList_free (tl);
1117 ** This is a hack to support unnamed struct/union fields as done by
1118 ** Microsoft VC++. It is not supported by the ANSI standard.
1120 ** The inner fields are added to the outer structure. This is meaningful
1121 ** for nesting structs inside unions, but Splint does no related
1126 fixUnnamedDecl (qtype q)
1128 ctype ct = ctype_realType (qtype_getType (q));
1130 if (ctype_isStruct (ct) || ctype_isUnion (ct))
1132 return uentryList_single (uentry_makeUnnamedVariable (ct));
1134 else if (ctype_isEnum (ct))
1136 /* evans 2002-02-05: nothing to do for unnamed enum lists */
1137 return uentryList_undefined;
1143 message ("Type name in field declarations: %s", qtype_unparse (q)),
1147 return uentryList_undefined;
1150 void setStorageClass (storageClassCode sc)
1156 setProcessingIterVars (uentry iter)
1158 s_processingIterVars = TRUE;
1160 saveIterParamNo = 0;
1164 setProcessingGlobalsList ()
1166 s_processingGlobals = TRUE;
1167 fcnNoGlobals = FALSE;
1170 static bool ProcessingGlobMods = FALSE;
1173 setProcessingGlobMods ()
1175 ProcessingGlobMods = TRUE;
1179 clearProcessingGlobMods ()
1181 ProcessingGlobMods = FALSE;
1185 isProcessingGlobMods ()
1187 return (ProcessingGlobMods);
1190 static void resetGlobals (void)
1192 s_processingGlobals = FALSE;
1193 fcnNoGlobals = FALSE;
1197 unsetProcessingGlobals ()
1199 s_processingGlobals = FALSE;
1203 setProcessingVars (/*@only@*/ qtype q)
1205 s_processingVars = TRUE;
1206 qtype_free (processingType);
1211 setGenericParamList (/*@dependent@*/ uentryList pm)
1213 s_processingParams = TRUE;
1218 setProcessingTypedef (qtype q)
1220 s_processingTypedef = TRUE;
1222 qtype_free (processingType);
1227 unsetProcessingVars ()
1229 resetStorageClass ();
1230 s_processingVars = FALSE;
1234 oldStyleDoneParams ()
1236 if (s_processingParams)
1238 if (uentry_isInvalid (saveFunction))
1240 llbuglit ("unsetProcessingVars: no saved function\n");
1244 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1245 uentryList params = uentryList_copy (saveParamList);
1246 ctype ct2 = ctype_makeFunction (ct, params);
1248 uentry_setType (saveFunction, ct2);
1249 s_processingParams = FALSE;
1251 oldStyleCompleteFunction (saveFunction);
1252 saveFunction = uentry_undefined;
1259 ** If the paramlist used a type name, we could be here.
1262 llfatalerror (message ("%q: Old-style function parameter list uses a "
1263 "type name.", fileloc_unparse (g_currentloc)));
1270 if (uentry_isValid (saveFunction))
1273 ** old style declaration
1276 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1279 DPRINTF (("save function: %s", uentry_unparseFull (saveFunction)));
1281 uentryList_elements (saveParamList, current)
1283 uentry_setType (current, ctype_int); /* all params are ints */
1284 } end_uentryList_elements;
1286 ct2 = ctype_makeParamsFunction (ct, uentryList_copy (saveParamList));
1288 uentry_setType (saveFunction, ct2);
1289 s_processingParams = FALSE;
1291 oldStyleDeclareFunction (saveFunction);
1292 saveFunction = uentry_undefined;
1296 void clabstract_declareType (/*@only@*/ exprNodeList decls, /*@only@*/ warnClause warn)
1298 llassert (s_processingTypedef);
1300 DPRINTF (("Declare type: %s", exprNodeList_unparse (decls)));
1302 if (warnClause_isDefined (warn))
1304 DPRINTF (("Has a warn clause!"));
1305 DPRINTF (("Warn: %s", warnClause_unparse (warn)));
1307 exprNodeList_elements (decls, el)
1309 uentry ue = exprNode_getUentry (el);
1310 cstring uname = uentry_getName (ue);
1312 DPRINTF (("Entry: %s", exprNode_unparse (el)));
1315 ** Need to lookup again to make sure we have the right one...
1318 ue = usymtab_lookupExposeGlob (uname);
1320 llassert (uentry_isValid (ue));
1321 llassert (uentry_isDatatype (ue));
1323 DPRINTF (("Warning for %s: %s",
1324 uentry_unparse (ue), warnClause_unparse (warn)));
1326 uentry_addWarning (ue, warnClause_copy (warn));
1327 DPRINTF (("After add warning: %s", uentry_unparseFull (ue)));
1328 cstring_free (uname);
1329 } end_exprNodeList_elements;
1332 warnClause_free (warn);
1333 exprNodeList_free (decls);
1334 unsetProcessingTypedef ();
1338 unsetProcessingTypedef ()
1340 s_processingTypedef = FALSE;
1343 void checkConstant (qtype t, idDecl id)
1347 id = idDecl_fixBase (id, t);
1348 e = uentry_makeIdConstant (id);
1350 reflectStorageClass (e);
1351 resetStorageClass ();
1353 DPRINTF (("Constant: %s", uentry_unparseFull (e)));
1354 usymtab_supGlobalEntry (e);
1357 void checkValueConstant (qtype t, idDecl id, exprNode e)
1361 id = idDecl_fixBase (id, t);
1362 ue = uentry_makeIdConstant (id);
1363 reflectStorageClass (ue);
1364 resetStorageClass ();
1366 if (exprNode_isDefined (e))
1368 if (!exprNode_matchType (uentry_getType (ue), e))
1371 (exprNode_getType (e), e,
1372 uentry_getType (ue), exprNode_undefined,
1373 message ("Constant %q initialized to type %t, expects %t: %s",
1374 uentry_getName (ue),
1375 exprNode_getType (e),
1376 uentry_getType (ue),
1377 exprNode_unparse (e)),
1382 if (exprNode_hasValue (e))
1384 uentry_mergeConstantValue (ue, multiVal_copy (exprNode_getValue (e)));
1388 DPRINTF (("No value: %s", exprNode_unparse (e)));
1393 DPRINTF (("Constant value: %s", uentry_unparseFull (ue)));
1394 usymtab_supGlobalEntry (ue);
1397 static void processVariable (idDecl t)
1402 ct = ctype_realType (idDecl_getCtype (t));
1404 if (s_processingParams)
1406 cstring id = idDecl_getName (t);
1407 int paramno = uentryList_lookupRealName (saveParamList, id);
1411 uentry cparam = uentryList_getN (saveParamList, paramno);
1413 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1414 uentry_setType (cparam, idDecl_getCtype (t));
1415 uentry_reflectQualifiers (cparam, idDecl_getQuals (t));
1416 uentry_setDeclaredOnly (cparam, context_getSaveLocation ());
1417 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1422 (message ("Old style declaration uses unlisted parameter: %s",
1430 if (context_inIterDef ())
1432 cstring pname = makeParam (idDecl_observeId (t));
1433 uentry p = usymtab_lookupSafe (pname);
1435 cstring_free (pname);
1437 if (uentry_isYield (p))
1439 e = uentry_makeParam (t, sRef_getParam (uentry_getSref (p)));
1440 uentry_checkYieldParam (p, e);
1441 usymtab_supEntrySref (e);
1446 if ((hasSpecialCode () || argsUsed)
1447 && ctype_isFunction (idDecl_getCtype (t)))
1449 e = uentry_makeIdFunction (t);
1450 reflectSpecialCode (e);
1451 reflectArgsUsed (e);
1455 e = uentry_makeIdVariable (t);
1458 loc = uentry_whereDeclared (e);
1461 if (context_inGlobalScope ())
1463 uentry_checkParams was here!
1467 if (ctype_isFunction (uentry_getType (e)))
1469 clabstract_prepareFunction (e);
1472 DPRINTF (("Superceding... %s", uentry_unparseFull (e)));
1473 e = usymtab_supEntrySrefReturn (e);
1474 DPRINTF (("After superceding... %s", uentry_unparseFull (e)));
1476 if (uentry_isExtern (e) && !context_inGlobalScope ())
1480 message ("Declaration using extern inside function scope: %q",
1481 uentry_unparse (e)),
1484 uentry_setDefined (e, fileloc_getExternal ());
1485 sRef_setDefined (uentry_getSref (e), fileloc_getExternal ());
1488 if (uentry_isFunction (e))
1490 if (!context_inXHFile ())
1492 checkParamNames (e);
1496 if (uentry_isVar (e) && uentry_isCheckedUnknown (e))
1498 sRef sr = uentry_getSref (e);
1500 if (sRef_isLocalVar (sr))
1502 if (context_getFlag (FLG_IMPCHECKMODINTERNALS))
1504 uentry_setCheckMod (e);
1508 uentry_setUnchecked (e);
1511 else if (sRef_isFileStatic (sr))
1513 if (context_getFlag (FLG_IMPCHECKEDSTRICTSTATICS))
1515 uentry_setCheckedStrict (e);
1517 else if (context_getFlag (FLG_IMPCHECKEDSTATICS))
1519 uentry_setChecked (e);
1521 else if (context_getFlag (FLG_IMPCHECKMODSTATICS))
1523 uentry_setCheckMod (e);
1530 else /* real global */
1532 llassert (sRef_isRealGlobal (sr));
1534 if (context_getFlag (FLG_IMPCHECKEDSTRICTGLOBALS))
1536 uentry_setCheckedStrict (e);
1538 else if (context_getFlag (FLG_IMPCHECKEDGLOBALS))
1540 uentry_setChecked (e);
1542 else if (context_getFlag (FLG_IMPCHECKMODGLOBALS))
1544 uentry_setCheckMod (e);
1555 void processNamedDecl (idDecl t)
1557 if (qtype_isUndefined (processingType))
1559 processingType = qtype_create (ctype_int);
1560 t = idDecl_fixBase (t, processingType);
1562 voptgenerror (FLG_IMPTYPE,
1563 message ("No type before declaration name (implicit int type): %q",
1564 idDecl_unparse (t)),
1569 t = idDecl_fixBase (t, processingType);
1572 DPRINTF (("Declare: %s", idDecl_unparse (t)));
1574 if (s_processingGlobals)
1576 cstring id = idDecl_getName (t);
1577 uentry ue = usymtab_lookupSafe (id);
1579 if (!uentry_isValid (ue))
1581 llerror (FLG_UNRECOG,
1582 message ("Variable used in globals list is undeclared: %s", id));
1586 if (!ctype_match (uentry_getType (ue), idDecl_getCtype (t)))
1590 message ("Variable %s used in globals list declared %s, "
1592 id, ctype_unparse (uentry_getType (ue)),
1593 ctype_unparse (idDecl_getCtype (t))),
1598 sRef sr = sRef_copy (uentry_getSref (ue));
1599 reflectGlobalQualifiers (sr, idDecl_getQuals (t));
1603 else if (s_processingVars)
1605 processVariable (t);
1607 else if (s_processingTypedef)
1609 ctype ct = idDecl_getCtype (t);
1612 DPRINTF (("Processing typedef: %s", ctype_unparse (ct)));
1614 e = uentry_makeIdDatatype (t);
1616 if (cstring_equal (idDecl_getName (t), context_getBoolName ())) {
1617 ctype rt = ctype_realType (ct);
1619 if (ctype_isEnum (rt)) {
1622 if (!(ctype_isInt (rt)
1623 || ctype_isUnknown (rt)
1624 || ctype_isChar (rt))) {
1627 message ("Boolean type %s defined using non-standard type %s (integral, char or enum type expected)",
1628 context_getBoolName (),
1629 ctype_unparse (ct)),
1630 uentry_whereLast (e));
1634 uentry_setType (e, ct);
1638 reflectStorageClass (e);
1639 checkTypeDecl (e, ct);
1641 e = usymtab_supReturnTypeEntry (e);
1645 llparseerror (message ("Suspect missing struct or union keyword: %q",
1646 idDecl_unparse (t)));
1652 ** moved from grammar
1655 static idDecl fixStructDecl (/*@returned@*/ idDecl d)
1657 if (ctype_isVisiblySharable (idDecl_getCtype (d))
1658 && context_getFlag (FLG_STRUCTIMPONLY))
1660 if (!qualList_hasAliasQualifier (idDecl_getQuals (d)))
1662 if (qualList_hasExposureQualifier (idDecl_getQuals (d)))
1664 idDecl_addQual (d, qual_createDependent ());
1668 idDecl_addQual (d, qual_createImpOnly ());
1677 declareUnnamedStruct (/*@only@*/ uentryList f)
1679 DPRINTF (("Unnamed struct: %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 ("Structure declared with %d fields "
1691 "(limit is set to %d)",
1697 return (ctype_createUnnamedStruct (f));
1701 declareUnnamedUnion (/*@only@*/ uentryList f)
1703 DPRINTF (("Unnamed union: %s", uentryList_unparse (f)));
1705 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1707 int num = uentryList_size (f);
1708 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1713 (FLG_NUMSTRUCTFIELDS,
1714 message ("Union declared with %d fields "
1715 "(limit is set to %d)",
1721 return (ctype_createUnnamedUnion (f));
1724 ctype declareStruct (cstring id, /*@only@*/ uentryList f)
1728 int num = uentryList_size (f);
1730 DPRINTF (("Declare struct: %s / %s [%d]", id, uentryList_unparse (f),
1731 uentryList_size (f)));
1733 ct = ctype_createStruct (cstring_copy (id), f);
1735 DPRINTF (("Ctype: %s", ctype_unparse (ct)));
1737 ue = uentry_makeStructTagLoc (id, ct);
1739 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
1741 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1743 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1748 (FLG_NUMSTRUCTFIELDS,
1749 message ("Structure %q declared with %d fields "
1750 "(limit is set to %d)",
1751 uentry_getName (ue), num, max),
1752 uentry_whereLast (ue));
1756 return (usymtab_supTypeEntry (ue));
1759 ctype declareUnion (cstring id, uentryList f)
1763 int num = uentryList_size (f);
1765 ct = ctype_createUnion (cstring_copy (id), f);
1766 ue = uentry_makeUnionTagLoc (id, ct);
1768 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1770 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1775 (FLG_NUMSTRUCTFIELDS,
1776 message ("Union %q declared with %d fields "
1777 "(limit is set to %d)",
1778 uentry_getName (ue), num, max),
1779 uentry_whereLast (ue));
1783 return (usymtab_supTypeEntry (ue));
1786 ctype handleStruct (/*@only@*/ cstring id)
1788 if (usymtab_existsStructTag (id))
1790 ctype ct = uentry_getAbstractType (usymtab_lookupStructTag (id));
1797 return (ctype_createForwardStruct (id));
1801 ctype handleUnion (/*@only@*/ cstring id)
1803 if (usymtab_existsUnionTag (id))
1805 ctype ret = uentry_getAbstractType (usymtab_lookupUnionTag (id));
1811 return (ctype_createForwardUnion (id));
1816 handleEnum (cstring id)
1818 if (usymtab_existsEnumTag (id))
1820 ctype ret = uentry_getAbstractType (usymtab_lookupEnumTag (id));
1826 return (ctype_createForwardEnum (id));
1830 bool processingIterVars (void)
1832 return s_processingIterVars;
1835 uentry getCurrentIter (void)
1840 static bool flipOldStyle = FALSE;
1841 static bool flipNewStyle = TRUE;
1843 void setFlipOldStyle () { flipOldStyle = TRUE; }
1844 bool isFlipOldStyle () { return flipOldStyle; }
1845 bool isNewStyle () { return flipNewStyle; }
1846 void setNewStyle () { flipNewStyle = TRUE; }
1848 /*@dependent@*/ uentryList handleParamIdList (/*@dependent@*/ uentryList params)
1853 ** this is a really YUCKY hack to handle old style
1857 voptgenerror (FLG_OLDSTYLE,
1858 cstring_makeLiteral ("Old style function declaration"),
1861 DPRINTF (("Handle old style params: %s", uentryList_unparseFull (params)));
1863 uentryList_elements (params, current)
1865 uentry_setParam (current);
1866 uentry_setSref (current, sRef_makeParam (paramno, ctype_unknown, stateInfo_makeLoc (uentry_whereLast (current))));
1868 } end_uentryList_elements;
1870 setGenericParamList (params);
1871 g_expectingTypeName = TRUE;
1876 /*@dependent@*/ uentryList handleParamTypeList (/*@returned@*/ uentryList params)
1880 uentryList_fixMissingNames (params);
1882 voptgenerror (FLG_OLDSTYLE,
1883 cstring_makeLiteral ("Old style function declaration."),
1886 setGenericParamList (params);
1887 flipOldStyle = FALSE;
1888 g_expectingTypeName = TRUE;
1897 ctype c = ctype_unknown;
1898 cstring id = cstring_makeLiteral ("va_alist");
1901 if (s_processingParams)
1903 int i = uentryList_lookupRealName (saveParamList, id);
1907 fileloc loc = context_getSaveLocation ();
1908 e = uentry_makeVariableSrefParam (id, c, loc, sRef_makeParam (i, c, stateInfo_makeLoc (loc)));
1912 e = uentry_undefined; /* suppress gcc message */
1913 llfatalerrorLoc (cstring_makeLiteral ("va_dcl used without va_alist"));
1918 llerror (FLG_SYNTAX, cstring_makeLiteral ("va_dcl used outside of function declaration"));
1919 e = uentry_makeVariableLoc (id, c);
1923 uentry_setUsed (e, g_currentloc);
1924 usymtab_supEntrySref (e);
1927 /*@exposed@*/ sRef modListPointer (/*@exposed@*/ sRef s)
1929 ctype ct = sRef_getType (s);
1930 ctype rt = ctype_realType (ct);
1932 if (ctype_isAP (rt))
1934 if (context_inHeader () && ctype_isAbstract (ct))
1939 ("Modifies clause in header file dereferences abstract "
1940 "type %s (interface modifies clause should not depend "
1941 "on or expose type representation): %q",
1947 return (sRef_constructPointer (s));
1951 if (ctype_isKnown (rt))
1955 message ("Implementation modifies clause dereferences non-pointer (type %s): %q",
1965 /*@exposed@*/ sRef modListFieldAccess (sRef s, cstring f)
1967 ctype ct = sRef_getType (s);
1968 ctype rt = ctype_realType (ct);
1970 if (ctype_isStructorUnion (rt))
1972 uentry tf = uentryList_lookupField (ctype_getFields (rt), f);
1974 if (uentry_isUndefined (tf))
1976 voptgenerror (FLG_TYPE,
1977 message ("Modifies list accesses non-existent "
1978 "field %s of %t: %q", f, ct,
1983 return sRef_undefined;
1987 if (ctype_isAbstract (ct) && context_inHeader ())
1992 ("Modifies clause in header file accesses abstract "
1993 "type %s (interface modifies clause should not depend "
1994 "on or expose type representation): %q",
2001 cstring_markOwned (f);
2002 return (sRef_makeField (s, f));
2008 message ("Modifies clause dereferences non-pointer (type %s): %q",
2018 /*@dependent@*/ sRef clabstract_unrecognizedGlobal (cstring s)
2020 if (cstring_equalLit (s, "nothing"))
2022 return sRef_makeNothing ();
2024 else if (cstring_equalLit (s, "internalState"))
2026 return sRef_makeInternalState ();
2028 else if (cstring_equalLit (s, "fileSystem")
2029 || cstring_equalLit (s, "systemState"))
2031 return sRef_makeSystemState ();
2037 message ("Unrecognized identifier in globals list: %s", s),
2040 return sRef_undefined;
2044 /*@exposed@*/ sRef modListArrowAccess (sRef s, cstring f)
2046 ctype ct = sRef_getType (s);
2047 ctype rt = ctype_realType (ct);
2049 if (ctype_isRealPointer (rt))
2051 ctype b = ctype_baseArrayPtr (rt);
2052 ctype rb = ctype_realType (b);
2054 if (ctype_isStructorUnion (rb))
2056 uentry tf = uentryList_lookupField (ctype_getFields (rb), f);
2058 if (uentry_isUndefined (tf))
2060 voptgenerror (FLG_TYPE,
2061 message ("Modifies list arrow accesses non-existent "
2062 "field %s of %t: %q", f, b,
2067 return sRef_undefined;
2071 if (context_inHeader ())
2073 if (ctype_isAbstract (b))
2078 ("Modifies clause in header file arrow accesses abstract "
2079 "type %s (interface modifies clause should not depend "
2080 "on or expose type representation): %q",
2088 if (ctype_isAbstract (rt))
2093 ("Modifies clause arrow accesses inaccessible abstract "
2094 "type %s (interface modifies clause should not depend "
2095 "on or expose type representation): %q",
2103 cstring_markOwned (f);
2104 return (sRef_makeArrow (s, f));
2110 message ("Modifies clause arrow accesses pointer to "
2111 "non-structure (type %s): %q",
2121 message ("Modifies clause arrow accesses non-pointer (type %s): %q",
2131 sRef checkStateClausesId (uentry ue)
2133 cstring s = uentry_rawName (ue);
2135 if (sRef_isFileOrGlobalScope (uentry_getSref (ue)))
2139 message ("Global variable %s used state clause. (Global variables "
2140 "are not recognized in state clauses. If there is "
2141 "sufficient interest in support for this, it may be "
2142 "added to a future release. Send mail to "
2143 "info@splint.org.)",
2147 return sRef_undefined;
2151 if (cstring_equalLit (s, "result"))
2155 message ("Special clause list uses %s which is a variable and has special "
2156 "meaning in a modifies list. (Special meaning assumed.)", s),
2159 uentry_showWhereDeclared (ue);
2163 return uentry_getSref (ue);
2169 don;t know what the real date is...
2175 based on checkSpecClausesId
2179 sRef checkbufferConstraintClausesId (uentry ue)
2182 cstring s = uentry_rawName (ue);
2184 if (cstring_equalLit (s, "result"))
2188 message ("Function clause list uses %s which is a variable and has special "
2189 "meaning in a modifies list. (Special meaning assumed.)", s),
2192 uentry_showWhereDeclared (ue);
2196 DPRINTF (("constraint id: %s", uentry_unparseFull (ue)));
2197 sr = uentry_getSref (ue);
2199 if (sRef_isInvalid (sr) )
2201 llfatalerrorLoc (cstring_makeLiteral("Macro defined constants can not be used in function constraints unless they are specifed with the constant annotation. To use a macro defined constant include an annotation of the form /*@constant <type> <name>=<value>@*/ somewhere before the function constraint. This restriction may be removed in future releases if it is determined to be excessively burdensome." ));
2203 return sRef_saveCopy (sr); /*@i523 why the saveCopy? */
2206 void checkModifiesId (uentry ue)
2208 cstring s = uentry_rawName (ue);
2210 if (cstring_equalLit (s, "nothing")
2211 || cstring_equalLit (s, "internalState")
2212 || cstring_equalLit (s, "systemState")
2213 || (cstring_equalLit (s, "fileSystem")))
2217 message ("Modifies list uses %s which is a variable and has special "
2218 "meaning in a modifies list. (Special meaning assumed.)", s),
2221 uentry_showWhereDeclared (ue);
2226 /*@exposed@*/ sRef fixModifiesId (cstring s)
2229 cstring pname = makeParam (s);
2230 uentry ue = usymtab_lookupSafe (pname);
2232 cstring_free (pname);
2234 if (cstring_equalLit (s, "nothing"))
2236 ret = sRef_makeNothing ();
2238 else if (cstring_equalLit (s, "internalState"))
2240 ret = sRef_makeInternalState ();
2242 else if (cstring_equalLit (s, "fileSystem")
2243 || cstring_equalLit (s, "systemState"))
2245 ret = sRef_makeSystemState ();
2249 ret = sRef_undefined;
2252 if (sRef_isValid (ret))
2254 if (uentry_isValid (ue))
2258 message ("Modifies list uses %s which is a parameter and has special "
2259 "meaning in a modifies list. (Special meaning assumed.)", s),
2265 if (uentry_isValid (ue))
2267 ret = uentry_getSref (ue);
2271 fileloc loc = fileloc_decColumn (g_currentloc, size_toInt (cstring_length (s)));
2272 ret = sRef_undefined;
2276 message ("Unrecognized identifier in modifies comment: %s", s),
2286 sRef fixStateClausesId (cstring s)
2289 cstring pname = makeParam (s);
2290 uentry ue = usymtab_lookupSafe (pname);
2292 cstring_free (pname);
2294 if (cstring_equalLit (s, "result"))
2296 ret = sRef_makeResult (ctype_unknown);
2300 ret = sRef_undefined;
2303 if (sRef_isValid (ret))
2305 if (uentry_isValid (ue))
2309 message ("Function clause uses %s which is a parameter and has special "
2310 "meaning in a function clause. (Special meaning assumed.)", s),
2316 if (uentry_isValid (ue))
2318 ret = uentry_getSref (ue);
2320 if (sRef_isFileOrGlobalScope (ret))
2324 message ("Global variable %s used in function clause. (Global variables "
2325 "are not recognized in function clauses. If there is "
2326 "sufficient interest in support for this, it may be "
2327 "added to a future release. Send mail to "
2328 "info@splint.org.)",
2332 ret = sRef_undefined;
2338 /*drl handle structure invariant */
2341 /*check that we're in a structure */
2343 /*@unused@*/ uentryList ueL;
2344 /*@unused@*/ uentry ue2;
2345 /*@unused@*/ ctype ct;
\r
2347 fileloc loc = fileloc_decColumn (g_currentloc, size_toInt (cstring_length (s)));
2348 ret = sRef_undefined;
2350 /*drl commenting this out for now
2351 ct = context_getLastStruct ( ct );
2353 llassert( ctype_isStruct(ct) );
2355 ueL = ctype_getFields (ct);
2357 ue2 = uentryList_lookupField (ueL, s);
2359 if (!uentry_isUndefined(ue2) )
2361 ret = uentry_getSref(ue2);
2364 message("Got field in structure in the annotation constraint: %s (or sref: %s)", s, sRef_unparse(ret) )
2374 message ("Unrecognized identifier in function clause: %s", s),
2384 sRef modListArrayFetch (/*@exposed@*/ sRef s, /*@unused@*/ sRef mexp)
2386 ctype ct = sRef_getType (s);
2387 ctype rt = ctype_realType (ct);
2389 if (ctype_isAP (rt))
2391 if (context_inHeader () && ctype_isAbstract (ct))
2396 ("Modifies clause in header file indexes abstract "
2397 "type %s (interface modifies clause should not depend "
2398 "on or expose type representation): %q",
2404 return (sRef_makeAnyArrayFetch (s));
2411 ("Implementation modifies clause uses array fetch on non-array (type %s): %q",
2412 ctype_unparse (ct), sRef_unparse (s)),
2418 static void clabstract_prepareFunction (uentry e)
2420 uentry_checkParams (e);
2421 DPRINTF (("After prepare: %s", uentry_unparseFull (e)));
2424 sRef clabstract_checkGlobal (exprNode e)
2427 llassert (exprNode_isInitializer (e));
2429 s = exprNode_getSref (e);
2430 DPRINTF (("Initializer: %s -> %s", exprNode_unparse (e), sRef_unparse (s)));
2433 return sRef_copy (s);