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
498 Currently the only constraints gnerated are MaxSet(p) >= 0 for all pointers
501 void setImplictfcnConstraints (void)
506 params = currentParamList;
508 if (constraintList_isDefined(implicitFcnConstraints) )
509 constraintList_free(implicitFcnConstraints);
511 implicitFcnConstraints = constraintList_makeNew();
513 uentryList_elements (params, el)
515 DPRINTF((message("setImplictfcnConstraints doing: %s", uentry_unparse(el) ) ));
517 s = uentry_getSref(el);
518 if (sRef_isReference (s) )
520 DPRINTF((message ("%s is a pointer", sRef_unparse(s) ) ));
524 DPRINTF((message ("%s is NOT a pointer", sRef_unparse(s) ) ));
527 chagned this is MaxSet(s) == 0 to MaxSet(s) >= 0 */
529 c = constraint_makeSRefWriteSafeInt (s, 0);
530 /* constraint_makeSRefSetBufferSize (s, 0); */
531 implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c);
533 end_uentryList_elements;
537 /*@observer@*/ constraintList getImplicitFcnConstraints (void)
539 return implicitFcnConstraints;
542 void setCurrentParams (/*@dependent@*/ uentryList ue)
544 currentParamList = ue;
547 void clearCurrentParams (void)
549 currentParamList = uentryList_undefined;
553 ** requires: uentry_isFunction (e)
554 ** parameter names for current function are in currentParamList
557 static void enterFunctionParams (uentryList params)
561 uentryList_elements (params, current)
563 if (uentry_hasName (current))
565 uentry_setParamNo (current, paramno);
566 usymtab_supEntry (uentry_copy (current));
570 } end_uentryList_elements;
574 extern void enterParamsTemp (void)
576 usymtab_enterScope ();
577 enterFunctionParams (currentParamList);
580 extern void exitParamsTemp (void)
582 usymtab_quietPlainExitScope ();
585 static /*@exposed@*/ uentry clabstract_globalDeclareFunction (idDecl tid)
587 ctype deftype = idDecl_getCtype (tid);
591 DPRINTF (("Global function: %s", idDecl_unparse (tid)));
593 if (ctype_isFunction (deftype))
595 rettype = ctype_getReturnType (deftype);
599 rettype = ctype_unknown;
603 ** check has been moved here...
606 if (ctype_isFunction (idDecl_getCtype (tid)))
608 ue = uentry_makeIdFunction (tid);
609 reflectSpecialCode (ue);
610 reflectArgsUsed (ue);
611 reflectStorageClass (ue);
612 uentry_checkParams (ue);
614 DPRINTF (("Supercede function: %s", uentry_unparseFull (ue)));
616 ue = usymtab_supGlobalEntryReturn (ue);
617 DPRINTF (("After supercede function: %s", uentry_unparseFull (ue)));
619 DPRINTF (("Enter function: %s", uentry_unparseFull (ue)));
620 context_enterFunction (ue);
621 enterFunctionParams (uentry_getParams (ue));
623 resetStorageClass ();
624 DPRINTF (("Function: %s", uentry_unparseFull (ue)));
629 llparseerror (message ("Non-function declaration: %q",
630 idDecl_unparse (tid)));
631 return (uentry_undefined);
636 ** for now, no type checking
637 ** (must check later though!)
640 static /*@only@*/ uentry globalDeclareOldStyleFunction (idDecl tid)
645 ** check has been moved here...
648 if (cstring_equalLit (idDecl_observeId (tid), "main"))
650 context_setFlagTemp (FLG_MAINTYPE, FALSE);
653 ue = uentry_makeIdFunction (tid);
654 reflectStorageClass (ue);
655 reflectSpecialCode (ue);
656 reflectArgsUsed (ue);
657 uentry_setDefined (ue, g_currentloc);
658 uentry_checkParams (ue);
659 resetStorageClass ();
661 /* context_enterOldStyleScope (); */
666 static void oldStyleDeclareFunction (/*@only@*/ uentry e)
668 uentryList params = saveParamList;
669 ctype rt = uentry_getType (e);
671 llassert (ctype_isFunction (rt));
673 if (uentry_hasStateClauseList (e)
674 || uentry_hasConditions (e))
676 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
677 fileloc_unparse (g_currentloc), uentry_unparse (e)));
680 e = usymtab_supGlobalEntryReturn (e);
682 context_enterFunction (e);
683 enterFunctionParams (params);
684 saveParamList = uentryList_undefined;
685 resetStorageClass ();
688 static void oldStyleCompleteFunction (/*@only@*/ uentry e)
690 uentryList params = saveParamList;
691 ctype rt = uentry_getType (e);
693 llassert (ctype_isFunction (rt));
695 if (uentry_hasStateClauseList (e)
696 || uentry_hasConditions (e))
698 llfatalerror (message ("%q: Old-style function declaration uses a clause (rewrite with function parameters): %q",
699 fileloc_unparse (g_currentloc), uentry_unparse (e)));
702 e = usymtab_supGlobalEntryReturn (e);
704 context_completeOldStyleFunction (e);
705 enterFunctionParams (params);
706 saveParamList = uentryList_undefined;
707 resetStorageClass ();
710 void clabstract_declareFunction (idDecl tid) /*@globals undef saveFunction; @*/
714 DPRINTF (("Declare function: %s", idDecl_unparse (tid)));
716 if (ctype_isUnknown (idDecl_getCtype (tid)))
719 ** No type, its really a plain name (int) declaration
722 voptgenerror (FLG_IMPTYPE,
723 message ("No type before declaration name (implicit int type): %q",
724 idDecl_unparse (tid)),
726 tid = idDecl_replaceCtype (tid, ctype_int);
727 processVariable (tid);
728 saveFunction = uentry_undefined;
732 if (s_processingParams)
734 ue = globalDeclareOldStyleFunction (tid);
736 DPRINTF (("Set save function: %s", uentry_unparseFull (ue)));
740 saveFunction = uentry_undefined;
742 if (context_inRealFunction ())
744 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
746 llparseerror (message ("Function declared inside function: %q",
747 idDecl_unparse (tid)));
749 context_quietExitFunction ();
750 ue = usymtab_supEntryReturn (ue);
754 if (context_inInnerScope ())
756 llparseerror (message ("Declaration in inner context: %q",
757 idDecl_unparse (tid)));
759 sRef_setGlobalScope ();
760 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
762 ue = usymtab_supGlobalEntryReturn (ue);
763 sRef_clearGlobalScope ();
767 ue = clabstract_globalDeclareFunction (tid);
774 resetStorageClass ();
780 void declareStaticFunction (idDecl tid) /*@globals undef saveFunction; @*/
784 DPRINTF (("Declare static funciton: %s", idDecl_unparse (tid)));
786 if (s_processingParams)
788 ue = globalDeclareOldStyleFunction (tid);
793 saveFunction = uentry_undefined;
795 if (context_inRealFunction ())
797 ue = uentry_makeVariableLoc (idDecl_observeId (tid), ctype_unknown);
799 llparseerror (message ("Function declared inside function: %q",
800 idDecl_unparse (tid)));
802 context_quietExitFunction ();
803 ue = usymtab_supEntryReturn (ue);
807 if (context_inInnerScope ())
809 llparseerror (message ("Declaration in inner context: %q",
810 idDecl_unparse (tid)));
812 sRef_setGlobalScope ();
813 ue = uentry_makeVariableLoc (idDecl_observeId (tid),
815 ue = usymtab_supGlobalEntryReturn (ue);
816 sRef_clearGlobalScope ();
820 ctype deftype = idDecl_getCtype (tid);
823 if (ctype_isFunction (deftype))
825 rettype = ctype_getReturnType (deftype);
829 rettype = ctype_unknown;
833 ** check has been moved here...
836 if (ctype_isFunction (idDecl_getCtype (tid)))
838 ue = uentry_makeIdFunction (tid);
839 reflectSpecialCode (ue);
840 reflectArgsUsed (ue);
844 DPRINTF (("Here we are!"));
845 llparseerror (message ("Inconsistent function declaration: %q",
846 idDecl_unparse (tid)));
848 tid = idDecl_replaceCtype
849 (tid, ctype_makeFunction (ctype_unknown, uentryList_undefined));
850 ue = uentry_makeIdFunction (tid);
853 reflectStorageClass (ue);
854 uentry_setStatic (ue);
856 uentry_checkParams (ue);
858 DPRINTF (("Sub global entry: %s", uentry_unparse (ue)));
859 ue = usymtab_supGlobalEntryReturn (ue);
861 context_enterFunction (ue);
862 enterFunctionParams (uentry_getParams (ue));
863 resetStorageClass ();
870 resetStorageClass ();
875 checkTypeDecl (uentry e, ctype rep)
877 cstring n = uentry_getName (e);
879 DPRINTF (("Check type decl: %s", uentry_unparseFull (e)));
881 if (cstring_equal (context_getBoolName (), n))
883 ctype rrep = ctype_realType (rep);
886 ** for abstract enum types, we need to fix the enum members:
887 ** they should have the abstract type, not the rep type.
890 if (ctype_isEnum (ctype_realType (rrep)))
892 enumNameList el = ctype_elist (rrep);
894 enumNameList_elements (el, ye)
896 if (usymtab_existsGlob (ye))
898 uentry ue = usymtab_lookupSafe (ye);
899 uentry_setType (ue, ctype_bool);
902 if (cstring_equal (context_getTrueName (), ye)
903 || cstring_equal (context_getFalseName (), ye))
911 message ("Member of boolean enumerated type definition "
912 "does not match name set to represent TRUE "
915 message ("Use -boolfalse and -booltrue to set the "
916 "name of false and true boolean values."),
917 uentry_whereDefined (e));
919 } end_enumNameList_elements;
923 if (usymtab_exists (n))
925 usymId llm = usymtab_getId (n);
926 uentry le = usymtab_getTypeEntry (llm);
928 uentry_setDeclared (e, g_currentloc);
929 uentry_setSref (e, sRef_makeGlobal (llm, uentry_getType (le), stateInfo_currentLoc ()));
931 DPRINTF (("Here we are: %s / %s",
932 n, context_getBoolName ()));
934 if (uentry_isAbstractDatatype (le))
936 ctype rrep = ctype_realType (rep);
938 DPRINTF (("Abstract type: %s", uentry_unparseFull (le)));
941 ** for abstract enum types, we need to fix the enum members:
942 ** they should have the abstract type, not the rep type.
945 if (ctype_isEnum (ctype_realType (rrep)))
947 ctype at = uentry_getAbstractType (le);
948 enumNameList el = ctype_elist (rrep);
950 enumNameList_elements (el, ye)
952 if (usymtab_existsGlob (ye))
954 uentry ue = usymtab_lookupSafe (ye);
956 llassert (uentry_isEitherConstant (ue));
958 /* evans 2002-04-22 */
959 if (ctype_isBool (uentry_getType (ue)))
962 ** If set using -booltrue or -boolfalse, don't change the type.
967 llassertprint (ctype_match (uentry_getType (ue), rrep),
968 ("Bad enum: %s / %s",
970 ctype_unparse (rrep)));
972 uentry_setType (ue, at);
975 } end_enumNameList_elements;
978 if (uentry_isMutableDatatype (le))
980 /* maybe more complicated if abstract and immutable ? */
982 if (!ctype_isRealPointer (rep) && !ctype_isRealAbstract (rep))
986 message ("Mutable abstract type %s declared without pointer "
987 "indirection: %s (violates assignment semantics)",
988 n, ctype_unparse (rep)),
989 uentry_whereDefined (e));
991 uentry_setMutable (e);
998 fileloc fl = uentry_whereDeclared (e);
1000 if (context_getFlag (FLG_LIKELYBOOL)
1001 && !context_getFlag (FLG_BOOLINT))
1003 if ((cstring_equalLit (n, "BOOL")
1004 || cstring_equalLit (n, "Bool")
1005 || cstring_equalLit (n, "bool")
1006 || cstring_equalLit (n, "boolean")
1007 || cstring_equalLit (n, "Boolean")
1008 || cstring_equalLit (n, "BOOLEAN"))
1009 && !(cstring_equal (n, context_getBoolName ())))
1011 if (context_setBoolName ()) {
1014 message ("Type %s is probably meant as a boolean type, but does "
1015 "not match the boolean type name \"%s\".",
1017 context_getBoolName ()),
1022 message ("Type %s is probably meant as a boolean type, "
1023 "but the boolean type name is not set. "
1024 "Use -booltype %s to set it.",
1031 if (!uentry_isStatic (e)
1032 && !ctype_isFunction (uentry_getType (e))
1033 && !fileloc_isLib (fl)
1034 && !fileloc_isImport (fl)
1035 && fileloc_isHeader (fl))
1037 voptgenerror (FLG_EXPORTTYPE,
1038 message ("Type exported, but not specified: %s\n", n),
1047 fixUentryList (idDeclList tl, qtype q)
1049 uentryList f = uentryList_new ();
1051 idDeclList_elements (tl, i)
1053 if (idDecl_isDefined (i))
1059 (void) idDecl_fixBase (i, q);
1062 ** implicit annotations
1065 (void) fixStructDecl (i);
1067 ue = uentry_makeIdVariable (i);
1068 rt = ctype_realType (uentry_getType (ue));
1071 ** where is this here???
1073 if (ctype_isArray (rt) || ctype_isSU (rt))
1075 sRef_setAllocated (uentry_getSref (ue), uentry_whereDefined (ue));
1081 if (uentry_isValid (old = uentryList_lookupField (f, uentry_rawName (ue))))
1083 if (optgenerror (FLG_SYNTAX,
1084 message ("Field name reused: %s", uentry_rawName (ue)),
1085 uentry_whereDefined (ue)))
1087 llgenmsg (message ("Previous use of %s", uentry_rawName (ue)),
1088 uentry_whereDefined (old));
1092 f = uentryList_add (f, ue);
1094 } end_idDeclList_elements;
1096 idDeclList_free (tl);
1101 ** This is a hack to support unnamed struct/union fields as done by
1102 ** Microsoft VC++. It is not supported by the ANSI standard.
1104 ** The inner fields are added to the outer structure. This is meaningful
1105 ** for nesting structs inside unions, but Splint does no related
1110 fixUnnamedDecl (qtype q)
1112 ctype ct = ctype_realType (qtype_getType (q));
1114 if (ctype_isStruct (ct) || ctype_isUnion (ct))
1116 return uentryList_single (uentry_makeUnnamedVariable (ct));
1118 else if (ctype_isEnum (ct))
1120 /* evans 2002-02-05: nothing to do for unnamed enum lists */
1121 return uentryList_undefined;
1127 message ("Type name in field declarations: %s", qtype_unparse (q)),
1131 return uentryList_undefined;
1134 void setStorageClass (storageClassCode sc)
1140 setProcessingIterVars (uentry iter)
1142 s_processingIterVars = TRUE;
1144 saveIterParamNo = 0;
1148 setProcessingGlobalsList ()
1150 s_processingGlobals = TRUE;
1151 fcnNoGlobals = FALSE;
1154 static bool ProcessingGlobMods = FALSE;
1157 setProcessingGlobMods ()
1159 ProcessingGlobMods = TRUE;
1163 clearProcessingGlobMods ()
1165 ProcessingGlobMods = FALSE;
1169 isProcessingGlobMods ()
1171 return (ProcessingGlobMods);
1174 static void resetGlobals (void)
1176 s_processingGlobals = FALSE;
1177 fcnNoGlobals = FALSE;
1181 unsetProcessingGlobals ()
1183 s_processingGlobals = FALSE;
1187 setProcessingVars (/*@only@*/ qtype q)
1189 s_processingVars = TRUE;
1190 qtype_free (processingType);
1195 setGenericParamList (/*@dependent@*/ uentryList pm)
1197 s_processingParams = TRUE;
1202 setProcessingTypedef (qtype q)
1204 s_processingTypedef = TRUE;
1206 qtype_free (processingType);
1211 unsetProcessingVars ()
1213 resetStorageClass ();
1214 s_processingVars = FALSE;
1218 oldStyleDoneParams ()
1220 if (s_processingParams)
1222 if (uentry_isInvalid (saveFunction))
1224 llbuglit ("unsetProcessingVars: no saved function\n");
1228 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1229 uentryList params = uentryList_copy (saveParamList);
1230 ctype ct2 = ctype_makeFunction (ct, params);
1232 uentry_setType (saveFunction, ct2);
1233 s_processingParams = FALSE;
1235 oldStyleCompleteFunction (saveFunction);
1236 saveFunction = uentry_undefined;
1243 ** If the paramlist used a type name, we could be here.
1246 llfatalerror (message ("%q: Old-style function parameter list uses a "
1247 "type name.", fileloc_unparse (g_currentloc)));
1254 if (uentry_isValid (saveFunction))
1257 ** old style declaration
1260 ctype ct = ctype_getReturnType (uentry_getType (saveFunction));
1263 DPRINTF (("save function: %s", uentry_unparseFull (saveFunction)));
1265 uentryList_elements (saveParamList, current)
1267 uentry_setType (current, ctype_int); /* all params are ints */
1268 } end_uentryList_elements;
1270 ct2 = ctype_makeParamsFunction (ct, uentryList_copy (saveParamList));
1272 uentry_setType (saveFunction, ct2);
1273 s_processingParams = FALSE;
1275 oldStyleDeclareFunction (saveFunction);
1276 saveFunction = uentry_undefined;
1280 void clabstract_declareType (/*@only@*/ exprNodeList decls, /*@only@*/ warnClause warn)
1282 llassert (s_processingTypedef);
1284 DPRINTF (("Declare type: %s", exprNodeList_unparse (decls)));
1286 if (warnClause_isDefined (warn))
1288 DPRINTF (("Has a warn clause!"));
1289 DPRINTF (("Warn: %s", warnClause_unparse (warn)));
1291 exprNodeList_elements (decls, el)
1293 uentry ue = exprNode_getUentry (el);
1294 cstring uname = uentry_getName (ue);
1296 DPRINTF (("Entry: %s", exprNode_unparse (el)));
1299 ** Need to lookup again to make sure we have the right one...
1302 ue = usymtab_lookupExposeGlob (uname);
1304 llassert (uentry_isValid (ue));
1305 llassert (uentry_isDatatype (ue));
1307 DPRINTF (("Warning for %s: %s",
1308 uentry_unparse (ue), warnClause_unparse (warn)));
1310 uentry_addWarning (ue, warnClause_copy (warn));
1311 DPRINTF (("After add warning: %s", uentry_unparseFull (ue)));
1312 cstring_free (uname);
1313 } end_exprNodeList_elements;
1316 warnClause_free (warn);
1317 exprNodeList_free (decls);
1318 unsetProcessingTypedef ();
1322 unsetProcessingTypedef ()
1324 s_processingTypedef = FALSE;
1327 void checkConstant (qtype t, idDecl id)
1331 id = idDecl_fixBase (id, t);
1332 e = uentry_makeIdConstant (id);
1334 reflectStorageClass (e);
1335 resetStorageClass ();
1337 DPRINTF (("Constant: %s", uentry_unparseFull (e)));
1338 usymtab_supGlobalEntry (e);
1341 void checkValueConstant (qtype t, idDecl id, exprNode e)
1345 id = idDecl_fixBase (id, t);
1346 ue = uentry_makeIdConstant (id);
1347 reflectStorageClass (ue);
1348 resetStorageClass ();
1350 if (exprNode_isDefined (e))
1352 if (!exprNode_matchType (uentry_getType (ue), e))
1355 (exprNode_getType (e), e,
1356 uentry_getType (ue), exprNode_undefined,
1357 message ("Constant %q initialized to type %t, expects %t: %s",
1358 uentry_getName (ue),
1359 exprNode_getType (e),
1360 uentry_getType (ue),
1361 exprNode_unparse (e)),
1366 if (exprNode_hasValue (e))
1368 uentry_mergeConstantValue (ue, multiVal_copy (exprNode_getValue (e)));
1372 DPRINTF (("No value: %s", exprNode_unparse (e)));
1377 DPRINTF (("Constant value: %s", uentry_unparseFull (ue)));
1378 usymtab_supGlobalEntry (ue);
1381 static void processVariable (idDecl t)
1386 ct = ctype_realType (idDecl_getCtype (t));
1388 if (s_processingParams)
1390 cstring id = idDecl_getName (t);
1391 int paramno = uentryList_lookupRealName (saveParamList, id);
1395 uentry cparam = uentryList_getN (saveParamList, paramno);
1397 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1398 uentry_setType (cparam, idDecl_getCtype (t));
1399 uentry_reflectQualifiers (cparam, idDecl_getQuals (t));
1400 uentry_setDeclaredOnly (cparam, context_getSaveLocation ());
1401 DPRINTF (("Processing param: %s", uentry_unparseFull (cparam)));
1406 (message ("Old style declaration uses unlisted parameter: %s",
1414 if (context_inIterDef ())
1416 cstring pname = makeParam (idDecl_observeId (t));
1417 uentry p = usymtab_lookupSafe (pname);
1419 cstring_free (pname);
1421 if (uentry_isYield (p))
1423 e = uentry_makeParam (t, sRef_getParam (uentry_getSref (p)));
1424 uentry_checkYieldParam (p, e);
1425 usymtab_supEntrySref (e);
1430 if ((hasSpecialCode () || argsUsed)
1431 && ctype_isFunction (idDecl_getCtype (t)))
1433 e = uentry_makeIdFunction (t);
1434 reflectSpecialCode (e);
1435 reflectArgsUsed (e);
1439 e = uentry_makeIdVariable (t);
1442 loc = uentry_whereDeclared (e);
1445 if (context_inGlobalScope ())
1447 uentry_checkParams was here!
1451 if (ctype_isFunction (uentry_getType (e)))
1453 clabstract_prepareFunction (e);
1456 DPRINTF (("Superceding... %s", uentry_unparseFull (e)));
1457 e = usymtab_supEntrySrefReturn (e);
1458 DPRINTF (("After superceding... %s", uentry_unparseFull (e)));
1460 if (uentry_isExtern (e) && !context_inGlobalScope ())
1464 message ("Declaration using extern inside function scope: %q",
1465 uentry_unparse (e)),
1468 uentry_setDefined (e, fileloc_getExternal ());
1469 sRef_setDefined (uentry_getSref (e), fileloc_getExternal ());
1472 if (uentry_isFunction (e))
1474 if (!context_inXHFile ())
1476 checkParamNames (e);
1480 if (uentry_isVar (e) && uentry_isCheckedUnknown (e))
1482 sRef sr = uentry_getSref (e);
1484 if (sRef_isLocalVar (sr))
1486 if (context_getFlag (FLG_IMPCHECKMODINTERNALS))
1488 uentry_setCheckMod (e);
1492 uentry_setUnchecked (e);
1495 else if (sRef_isFileStatic (sr))
1497 if (context_getFlag (FLG_IMPCHECKEDSTRICTSTATICS))
1499 uentry_setCheckedStrict (e);
1501 else if (context_getFlag (FLG_IMPCHECKEDSTATICS))
1503 uentry_setChecked (e);
1505 else if (context_getFlag (FLG_IMPCHECKMODSTATICS))
1507 uentry_setCheckMod (e);
1514 else /* real global */
1516 llassert (sRef_isRealGlobal (sr));
1518 if (context_getFlag (FLG_IMPCHECKEDSTRICTGLOBALS))
1520 uentry_setCheckedStrict (e);
1522 else if (context_getFlag (FLG_IMPCHECKEDGLOBALS))
1524 uentry_setChecked (e);
1526 else if (context_getFlag (FLG_IMPCHECKMODGLOBALS))
1528 uentry_setCheckMod (e);
1539 void processNamedDecl (idDecl t)
1541 if (qtype_isUndefined (processingType))
1543 processingType = qtype_create (ctype_int);
1544 t = idDecl_fixBase (t, processingType);
1546 voptgenerror (FLG_IMPTYPE,
1547 message ("No type before declaration name (implicit int type): %q",
1548 idDecl_unparse (t)),
1553 t = idDecl_fixBase (t, processingType);
1556 DPRINTF (("Declare: %s", idDecl_unparse (t)));
1558 if (s_processingGlobals)
1560 cstring id = idDecl_getName (t);
1561 uentry ue = usymtab_lookupSafe (id);
1563 if (!uentry_isValid (ue))
1565 llerror (FLG_UNRECOG,
1566 message ("Variable used in globals list is undeclared: %s", id));
1570 if (!ctype_match (uentry_getType (ue), idDecl_getCtype (t)))
1574 message ("Variable %s used in globals list declared %s, "
1576 id, ctype_unparse (uentry_getType (ue)),
1577 ctype_unparse (idDecl_getCtype (t))),
1582 sRef sr = sRef_copy (uentry_getSref (ue));
1583 reflectGlobalQualifiers (sr, idDecl_getQuals (t));
1587 else if (s_processingVars)
1589 processVariable (t);
1591 else if (s_processingTypedef)
1593 ctype ct = idDecl_getCtype (t);
1596 DPRINTF (("Processing typedef: %s", ctype_unparse (ct)));
1598 e = uentry_makeIdDatatype (t);
1600 if (cstring_equal (idDecl_getName (t), context_getBoolName ())) {
1601 ctype rt = ctype_realType (ct);
1603 if (ctype_isEnum (rt)) {
1606 if (!(ctype_isInt (rt)
1607 || ctype_isUnknown (rt)
1608 || ctype_isChar (rt))) {
1611 message ("Boolean type %s defined using non-standard type %s (integral, char or enum type expected)",
1612 context_getBoolName (),
1613 ctype_unparse (ct)),
1614 uentry_whereLast (e));
1618 uentry_setType (e, ct);
1622 reflectStorageClass (e);
1623 checkTypeDecl (e, ct);
1625 e = usymtab_supReturnTypeEntry (e);
1629 llparseerror (message ("Suspect missing struct or union keyword: %q",
1630 idDecl_unparse (t)));
1636 ** moved from grammar
1639 static idDecl fixStructDecl (/*@returned@*/ idDecl d)
1641 if (ctype_isVisiblySharable (idDecl_getCtype (d))
1642 && context_getFlag (FLG_STRUCTIMPONLY))
1644 if (!qualList_hasAliasQualifier (idDecl_getQuals (d)))
1646 if (qualList_hasExposureQualifier (idDecl_getQuals (d)))
1648 idDecl_addQual (d, qual_createDependent ());
1652 idDecl_addQual (d, qual_createImpOnly ());
1661 declareUnnamedStruct (/*@only@*/ uentryList f)
1663 DPRINTF (("Unnamed struct: %s", uentryList_unparse (f)));
1665 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1667 int num = uentryList_size (f);
1668 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1673 (FLG_NUMSTRUCTFIELDS,
1674 message ("Structure declared with %d fields "
1675 "(limit is set to %d)",
1681 return (ctype_createUnnamedStruct (f));
1685 declareUnnamedUnion (/*@only@*/ uentryList f)
1687 DPRINTF (("Unnamed union: %s", uentryList_unparse (f)));
1689 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1691 int num = uentryList_size (f);
1692 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1697 (FLG_NUMSTRUCTFIELDS,
1698 message ("Union declared with %d fields "
1699 "(limit is set to %d)",
1705 return (ctype_createUnnamedUnion (f));
1708 ctype declareStruct (cstring id, /*@only@*/ uentryList f)
1712 int num = uentryList_size (f);
1714 DPRINTF (("Declare struct: %s / %s [%d]", id, uentryList_unparse (f),
1715 uentryList_size (f)));
1717 ct = ctype_createStruct (cstring_copy (id), f);
1719 DPRINTF (("Ctype: %s", ctype_unparse (ct)));
1721 ue = uentry_makeStructTagLoc (id, ct);
1723 DPRINTF (("ue: %s", uentry_unparseFull (ue)));
1725 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1727 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1732 (FLG_NUMSTRUCTFIELDS,
1733 message ("Structure %q declared with %d fields "
1734 "(limit is set to %d)",
1735 uentry_getName (ue), num, max),
1736 uentry_whereLast (ue));
1740 return (usymtab_supTypeEntry (ue));
1743 ctype declareUnion (cstring id, uentryList f)
1747 int num = uentryList_size (f);
1749 ct = ctype_createUnion (cstring_copy (id), f);
1750 ue = uentry_makeUnionTagLoc (id, ct);
1752 if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
1754 int max = context_getValue (FLG_NUMSTRUCTFIELDS);
1759 (FLG_NUMSTRUCTFIELDS,
1760 message ("Union %q declared with %d fields "
1761 "(limit is set to %d)",
1762 uentry_getName (ue), num, max),
1763 uentry_whereLast (ue));
1767 return (usymtab_supTypeEntry (ue));
1770 ctype handleStruct (/*@only@*/ cstring id)
1772 if (usymtab_existsStructTag (id))
1774 ctype ct = uentry_getAbstractType (usymtab_lookupStructTag (id));
1781 return (ctype_createForwardStruct (id));
1785 ctype handleUnion (/*@only@*/ cstring id)
1787 if (usymtab_existsUnionTag (id))
1789 ctype ret = uentry_getAbstractType (usymtab_lookupUnionTag (id));
1795 return (ctype_createForwardUnion (id));
1800 handleEnum (cstring id)
1802 if (usymtab_existsEnumTag (id))
1804 ctype ret = uentry_getAbstractType (usymtab_lookupEnumTag (id));
1810 return (ctype_createForwardEnum (id));
1814 bool processingIterVars (void)
1816 return s_processingIterVars;
1819 uentry getCurrentIter (void)
1824 static bool flipOldStyle = FALSE;
1825 static bool flipNewStyle = TRUE;
1827 void setFlipOldStyle () { flipOldStyle = TRUE; }
1828 bool isFlipOldStyle () { return flipOldStyle; }
1829 bool isNewStyle () { return flipNewStyle; }
1830 void setNewStyle () { flipNewStyle = TRUE; }
1832 /*@dependent@*/ uentryList handleParamIdList (/*@dependent@*/ uentryList params)
1837 ** this is a really YUCKY hack to handle old style
1841 voptgenerror (FLG_OLDSTYLE,
1842 cstring_makeLiteral ("Old style function declaration"),
1845 DPRINTF (("Handle old style params: %s", uentryList_unparseFull (params)));
1847 uentryList_elements (params, current)
1849 uentry_setParam (current);
1850 uentry_setSref (current, sRef_makeParam (paramno, ctype_unknown, stateInfo_makeLoc (uentry_whereLast (current))));
1852 } end_uentryList_elements;
1854 setGenericParamList (params);
1855 g_expectingTypeName = TRUE;
1860 /*@dependent@*/ uentryList handleParamTypeList (/*@returned@*/ uentryList params)
1864 uentryList_fixMissingNames (params);
1866 voptgenerror (FLG_OLDSTYLE,
1867 cstring_makeLiteral ("Old style function declaration."),
1870 setGenericParamList (params);
1871 flipOldStyle = FALSE;
1872 g_expectingTypeName = TRUE;
1881 ctype c = ctype_unknown;
1882 cstring id = cstring_makeLiteral ("va_alist");
1885 if (s_processingParams)
1887 int i = uentryList_lookupRealName (saveParamList, id);
1891 fileloc loc = context_getSaveLocation ();
1892 e = uentry_makeVariableSrefParam (id, c, loc, sRef_makeParam (i, c, stateInfo_makeLoc (loc)));
1896 e = uentry_undefined; /* suppress gcc message */
1897 llfatalerrorLoc (cstring_makeLiteral ("va_dcl used without va_alist"));
1902 llerror (FLG_SYNTAX, cstring_makeLiteral ("va_dcl used outside of function declaration"));
1903 e = uentry_makeVariableLoc (id, c);
1907 uentry_setUsed (e, g_currentloc);
1908 usymtab_supEntrySref (e);
1911 /*@exposed@*/ sRef modListPointer (/*@exposed@*/ sRef s)
1913 ctype ct = sRef_getType (s);
1914 ctype rt = ctype_realType (ct);
1916 if (ctype_isAP (rt))
1918 if (context_inHeader () && ctype_isAbstract (ct))
1923 ("Modifies clause in header file dereferences abstract "
1924 "type %s (interface modifies clause should not depend "
1925 "on or expose type representation): %q",
1931 return (sRef_constructPointer (s));
1935 if (ctype_isKnown (rt))
1939 message ("Implementation modifies clause dereferences non-pointer (type %s): %q",
1949 /*@exposed@*/ sRef modListFieldAccess (sRef s, cstring f)
1951 ctype ct = sRef_getType (s);
1952 ctype rt = ctype_realType (ct);
1954 if (ctype_isStructorUnion (rt))
1956 uentry tf = uentryList_lookupField (ctype_getFields (rt), f);
1958 if (uentry_isUndefined (tf))
1960 voptgenerror (FLG_TYPE,
1961 message ("Modifies list accesses non-existent "
1962 "field %s of %t: %q", f, ct,
1967 return sRef_undefined;
1971 if (ctype_isAbstract (ct) && context_inHeader ())
1976 ("Modifies clause in header file accesses abstract "
1977 "type %s (interface modifies clause should not depend "
1978 "on or expose type representation): %q",
1985 cstring_markOwned (f);
1986 return (sRef_makeField (s, f));
1992 message ("Modifies clause dereferences non-pointer (type %s): %q",
2002 /*@dependent@*/ sRef clabstract_unrecognizedGlobal (cstring s)
2004 if (cstring_equalLit (s, "nothing"))
2006 return sRef_makeNothing ();
2008 else if (cstring_equalLit (s, "internalState"))
2010 return sRef_makeInternalState ();
2012 else if (cstring_equalLit (s, "fileSystem")
2013 || cstring_equalLit (s, "systemState"))
2015 return sRef_makeSystemState ();
2021 message ("Unrecognized identifier in globals list: %s", s),
2024 return sRef_undefined;
2028 /*@exposed@*/ sRef modListArrowAccess (sRef s, cstring f)
2030 ctype ct = sRef_getType (s);
2031 ctype rt = ctype_realType (ct);
2033 if (ctype_isRealPointer (rt))
2035 ctype b = ctype_baseArrayPtr (rt);
2036 ctype rb = ctype_realType (b);
2038 if (ctype_isStructorUnion (rb))
2040 uentry tf = uentryList_lookupField (ctype_getFields (rb), f);
2042 if (uentry_isUndefined (tf))
2044 voptgenerror (FLG_TYPE,
2045 message ("Modifies list arrow accesses non-existent "
2046 "field %s of %t: %q", f, b,
2051 return sRef_undefined;
2055 if (context_inHeader ())
2057 if (ctype_isAbstract (b))
2062 ("Modifies clause in header file arrow accesses abstract "
2063 "type %s (interface modifies clause should not depend "
2064 "on or expose type representation): %q",
2072 if (ctype_isAbstract (rt))
2077 ("Modifies clause arrow accesses inaccessible abstract "
2078 "type %s (interface modifies clause should not depend "
2079 "on or expose type representation): %q",
2087 cstring_markOwned (f);
2088 return (sRef_makeArrow (s, f));
2094 message ("Modifies clause arrow accesses pointer to "
2095 "non-structure (type %s): %q",
2105 message ("Modifies clause arrow accesses non-pointer (type %s): %q",
2115 sRef checkStateClausesId (uentry ue)
2117 cstring s = uentry_rawName (ue);
2119 if (sRef_isFileOrGlobalScope (uentry_getSref (ue)))
2123 message ("Global variable %s used state clause. (Global variables "
2124 "are not recognized in state clauses. If there is "
2125 "sufficient interest in support for this, it may be "
2126 "added to a future release. Send mail to "
2127 "info@splint.org.)",
2131 return sRef_undefined;
2135 if (cstring_equalLit (s, "result"))
2139 message ("Special clause list uses %s which is a variable and has special "
2140 "meaning in a modifies list. (Special meaning assumed.)", s),
2143 uentry_showWhereDeclared (ue);
2147 return uentry_getSref (ue);
2153 don;t know what the real date is...
2159 based on checkSpecClausesId
2163 sRef checkbufferConstraintClausesId (uentry ue)
2166 cstring s = uentry_rawName (ue);
2168 if (cstring_equalLit (s, "result"))
2172 message ("Function clause list uses %s which is a variable and has special "
2173 "meaning in a modifies list. (Special meaning assumed.)", s),
2176 uentry_showWhereDeclared (ue);
2180 DPRINTF (("constraint id: %s", uentry_unparseFull (ue)));
2181 sr = uentry_getSref (ue);
2183 if (sRef_isInvalid (sr) )
2185 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." ));
2187 return sRef_saveCopy (sr); /*@i523 why the saveCopy? */
2190 void checkModifiesId (uentry ue)
2192 cstring s = uentry_rawName (ue);
2194 if (cstring_equalLit (s, "nothing")
2195 || cstring_equalLit (s, "internalState")
2196 || cstring_equalLit (s, "systemState")
2197 || (cstring_equalLit (s, "fileSystem")))
2201 message ("Modifies list uses %s which is a variable and has special "
2202 "meaning in a modifies list. (Special meaning assumed.)", s),
2205 uentry_showWhereDeclared (ue);
2210 /*@exposed@*/ sRef fixModifiesId (cstring s)
2213 cstring pname = makeParam (s);
2214 uentry ue = usymtab_lookupSafe (pname);
2216 cstring_free (pname);
2218 if (cstring_equalLit (s, "nothing"))
2220 ret = sRef_makeNothing ();
2222 else if (cstring_equalLit (s, "internalState"))
2224 ret = sRef_makeInternalState ();
2226 else if (cstring_equalLit (s, "fileSystem")
2227 || cstring_equalLit (s, "systemState"))
2229 ret = sRef_makeSystemState ();
2233 ret = sRef_undefined;
2236 if (sRef_isValid (ret))
2238 if (uentry_isValid (ue))
2242 message ("Modifies list uses %s which is a parameter and has special "
2243 "meaning in a modifies list. (Special meaning assumed.)", s),
2249 if (uentry_isValid (ue))
2251 ret = uentry_getSref (ue);
2255 fileloc loc = fileloc_decColumn (g_currentloc, size_toInt (cstring_length (s)));
2256 ret = sRef_undefined;
2260 message ("Unrecognized identifier in modifies comment: %s", s),
2270 sRef fixStateClausesId (cstring s)
2273 cstring pname = makeParam (s);
2274 uentry ue = usymtab_lookupSafe (pname);
2276 cstring_free (pname);
2278 if (cstring_equalLit (s, "result"))
2280 ret = sRef_makeResult (ctype_unknown);
2284 ret = sRef_undefined;
2287 if (sRef_isValid (ret))
2289 if (uentry_isValid (ue))
2293 message ("Function clause uses %s which is a parameter and has special "
2294 "meaning in a function clause. (Special meaning assumed.)", s),
2300 if (uentry_isValid (ue))
2302 ret = uentry_getSref (ue);
2304 if (sRef_isFileOrGlobalScope (ret))
2308 message ("Global variable %s used in function clause. (Global variables "
2309 "are not recognized in function clauses. If there is "
2310 "sufficient interest in support for this, it may be "
2311 "added to a future release. Send mail to "
2312 "info@splint.org.)",
2316 ret = sRef_undefined;
2322 /*drl handle structure invariant */
2325 /*check that we're in a structure */
2327 /*@unused@*/ uentryList ueL;
2328 /*@unused@*/ uentry ue2;
2329 /*@unused@*/ ctype ct;
\r
2331 fileloc loc = fileloc_decColumn (g_currentloc, size_toInt (cstring_length (s)));
2332 ret = sRef_undefined;
2334 /*drl commenting this out for now
2335 ct = context_getLastStruct ( ct );
2337 llassert( ctype_isStruct(ct) );
2339 ueL = ctype_getFields (ct);
2341 ue2 = uentryList_lookupField (ueL, s);
2343 if (!uentry_isUndefined(ue2) )
2345 ret = uentry_getSref(ue2);
2348 message("Got field in structure in the annotation constraint: %s (or sref: %s)", s, sRef_unparse(ret) )
2358 message ("Unrecognized identifier in function clause: %s", s),
2368 sRef modListArrayFetch (/*@exposed@*/ sRef s, /*@unused@*/ sRef mexp)
2370 ctype ct = sRef_getType (s);
2371 ctype rt = ctype_realType (ct);
2373 if (ctype_isAP (rt))
2375 if (context_inHeader () && ctype_isAbstract (ct))
2380 ("Modifies clause in header file indexes abstract "
2381 "type %s (interface modifies clause should not depend "
2382 "on or expose type representation): %q",
2388 return (sRef_makeAnyArrayFetch (s));
2395 ("Implementation modifies clause uses array fetch on non-array (type %s): %q",
2396 ctype_unparse (ct), sRef_unparse (s)),
2402 static void clabstract_prepareFunction (uentry e)
2404 uentry_checkParams (e);
2405 DPRINTF (("After prepare: %s", uentry_unparseFull (e)));
2408 sRef clabstract_checkGlobal (exprNode e)
2411 llassert (exprNode_isInitializer (e));
2413 s = exprNode_getSref (e);
2414 DPRINTF (("Initializer: %s -> %s", exprNode_unparse (e), sRef_unparse (s)));
2417 return sRef_copy (s);