X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/155af98de2d41917730964947d990b7fb70ddc01..52e90c0f77bb0e3edb043873b71a73459d4ae8ab:/src/usymtab.c diff --git a/src/usymtab.c b/src/usymtab.c index 9ab0426..179723c 100644 --- a/src/usymtab.c +++ b/src/usymtab.c @@ -148,7 +148,7 @@ static /*@exposed@*/ /*@dependent@*/ uentry static /*@exposed@*/ /*@dependent@*/ uentry usymtab_lookupQuietNoAlt (usymtab p_s, cstring p_k); -static void usymtab_printAllAux (usymtab p_s) /*@modifies g_msgstream@*/ ; +static void usymtab_printAllAux (usymtab p_s) /*@modifies g_warningstream@*/ ; static int usymtab_getIndex (/*@notnull@*/ usymtab p_s, cstring p_k); static /*@exposed@*/ uentry usymtab_fetchIndex (/*@notnull@*/ usymtab p_s, int p_i); static /*@exposed@*/ uentry @@ -758,8 +758,6 @@ usymtab_supEntryAux (/*@notnull@*/ usymtab st, } } - DPRINTF (("Using symtab: %s", usymtab_unparseLocalAux (st))); - eindex = usymtab_getIndex (st, ename); if (eindex != NOT_FOUND) @@ -1315,7 +1313,6 @@ void /*@modifies utab, globtab, e@*/ { sRef old = uentry_getSref (e); - if (sRef_isType (old)) { @@ -2070,8 +2067,8 @@ usymtab_enterFile () { if (sRef_hasDerived (uentry_getSref (ue))) { - fprintf (g_msgstream, "Derived Global: %s\n", uentry_unparse (ue)); - fprintf (g_msgstream, "sRef: %s\n", sRef_unparseFull (ue->sref)); + fprintf (g_warningstream, "Derived Global: %s\n", uentry_unparse (ue)); + fprintf (g_warningstream, "sRef: %s\n", sRef_unparseFull (ue->sref)); } } end_usymtab_entries ; @@ -2329,6 +2326,8 @@ usymtab_enterFunctionScope (uentry fcn) { usymtab t = usymtab_create (US_NORMAL, utab, TRUE); + DPRINTF (("Enter function: %s", uentry_unparse (fcn))); + if (utab->lexlevel != fileScope) { if (utab->lexlevel > fileScope) @@ -2426,6 +2425,9 @@ usymtab_enterFunctionScope (uentry fcn) } end_globSet_allElements; DPRINTF (("Globs after: %s", globSet_unparse (uentry_getGlobs (fcn)))); +# ifdef DEBUGSPLINT + usymtab_checkAllValid (); +# endif } static void @@ -2586,6 +2588,8 @@ usymtab_newCase (/*@unused@*/ exprNode pred, exprNode last) bool mustReturn = usymtab_mustEscape (utab); usymtab stab = utab; + DPRINTF (("New case!")); + /* ** Find last case (or outer switch) */ @@ -2595,9 +2599,7 @@ usymtab_newCase (/*@unused@*/ exprNode pred, exprNode last) stab = stab->env; llassert (stab != GLOBAL_ENV); } - - /* ??? */ - + while (stab->kind == US_CBRANCH) { stab = stab->env; @@ -2907,13 +2909,17 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab, if (!guardSet_isGuarded (ttab->guards, el) && !sRef_isNotNull (sr)) { + DPRINTF (("Here! %s / %s", + sRef_unparseFull (sr), + sRef_unparseFull (el))); sRef_setDerivNullState (sr, el, NS_DEFNULL); - } + } } } else { - } + ; + } ue = usymtab_getRefTab (ftab, level, index); @@ -2921,7 +2927,6 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab, { sRef sr = uentry_getSref (ue); - if (!trueGuard) /* yikes! forgot the ! */ { sRef_setDerivNullState (sr, el, NS_NOTNULL); @@ -2933,7 +2938,7 @@ updateNullState (sRef el, /*@notnull@*/ usymtab ttab, && !sRef_isNotNull (sr)) { sRef_setDerivNullState (sr, el, NS_DEFNULL); - } + } } } else @@ -3695,7 +3700,7 @@ checkGlobalReturn (uentry glob, sRef orig) else { ctype ct = ctype_realType (uentry_getType (glob)); - + DPRINTF (("Check global destroyed: %s", uentry_unparseFull (glob))); if (ctype_isVisiblySharable (ct)) @@ -3773,6 +3778,7 @@ checkGlobalReturn (uentry glob, sRef orig) } else { + DPRINTF (("Check transfer: %s", uentry_unparseFull (glob))); transferChecks_globalReturn (glob); } } @@ -4336,6 +4342,10 @@ usymtab_quietExitScope (fileloc loc) usymtab_freeLevel (utab); utab = t; + +# ifdef DEBUGSPLINT + usymtab_checkAllValid (); +# endif } /* @@ -4382,32 +4392,34 @@ void usymtab_exitScope (exprNode expr) } if (utab->kind == US_TBRANCH || utab->kind == US_FBRANCH - || utab->kind == US_CBRANCH || utab->kind == US_SWITCH) { - - if (context_inMacro ()) { - /* evs 2000-07-25 */ - /* Unparseable macro may end inside nested scope. Deal with it. */ - - llerror (FLG_SYNTAX, - message ("Problem parsing macro body of %s (unbalanced scopes). " - "Attempting to recover, recommend /*@notfunction@*/ before " - "macro definition.", - context_inFunctionName ())); - - while (utab->kind == US_TBRANCH - || utab->kind == US_FBRANCH - || utab->kind == US_CBRANCH - || utab->kind == US_SWITCH) + || utab->kind == US_CBRANCH || utab->kind == US_SWITCH) + { + if (context_inMacro ()) { - utab = utab->env; - llassert (utab != GLOBAL_ENV); - } - } else { - llcontbug (message ("exitScope: in branch: %q", usymtab_unparseStack ())); - /*@-branchstate@*/ - } /*@=branchstate@*/ - } - + /* evs 2000-07-25 */ + /* Unparseable macro may end inside nested scope. Deal with it. */ + + llerror (FLG_SYNTAX, + message ("Problem parsing macro body of %s (unbalanced scopes). " + "Attempting to recover, recommend /*@notfunction@*/ before " + "macro definition.", + context_inFunctionName ())); + + while (utab->kind == US_TBRANCH + || utab->kind == US_FBRANCH + || utab->kind == US_CBRANCH + || utab->kind == US_SWITCH) + { + utab = utab->env; + llassert (utab != GLOBAL_ENV); + } + } else + { + llcontbug (message ("exitScope: in branch: %q", usymtab_unparseStack ())); + /*@-branchstate@*/ + } /*@=branchstate@*/ + } + /* ** check all variables in scope were used */ @@ -4433,7 +4445,7 @@ void usymtab_exitScope (exprNode expr) ** NOTE: note for exiting paramsScope, since checkReturn should be ** called first. */ - + if (!mustReturn && (usymtab_lexicalLevel () > functionScope)) { /* @@ -4452,7 +4464,6 @@ void usymtab_exitScope (exprNode expr) uentryList params = context_getParams (); globSet globs = context_getUsedGlobs (); - uentryList_elements (params, ue) { uentry_fixupSref (ue); @@ -4460,9 +4471,12 @@ void usymtab_exitScope (exprNode expr) clearFunctionTypes (); - + DPRINTF (("Fixing up globals: %s", globSet_unparse (globs))); + globSet_allElements (globs, el) { + DPRINTF (("Fix: %s", sRef_unparseDebug (el))); + if (sRef_isCvar (el)) { uentry current; @@ -4480,13 +4494,17 @@ void usymtab_exitScope (exprNode expr) if (uentry_isVariable (current)) { + DPRINTF (("Fixup: %s", uentry_unparse (current))); uentry_fixupSref (current); } else { + DPRINTF (("Clear: %s", uentry_getSref (current))); sRef_clearDerived (uentry_getSref (current)); } } + + sRef_clearDerived (el); /* evans 2002-03-14 - this is the likely source of many crashes! */ } end_globSet_allElements; } @@ -4498,6 +4516,11 @@ void usymtab_exitScope (exprNode expr) /*@i@*/ utab = ctab; /*@-branchstate@*/ } /*@=branchstate@*/ /*@-globstate@*/ + + +# ifdef DEBUGSPLINT + usymtab_checkAllValid (); +# endif /*@i523@*/ } /*@=globstate@*/ @@ -4514,13 +4537,7 @@ uentry_directParamNo (uentry ue) if (sRef_lexLevel (sr) == functionScope) { - int index; - - /*@access sRef@*/ - llassert (sr->info != NULL); - llassert (sr->info->cvar != NULL); - index = sr->info->cvar->index; - /*@noaccess sRef@*/ + int index = sRef_getScopeIndex (sr); if (index < uentryList_size (context_getParams ())) { @@ -4951,6 +4968,7 @@ usymtab_lookupQuietAux (usymtab s, cstring k, bool noalt) } else { + llassert (s != NULL); /*@i523 should not need this? */ s = s->env; } } @@ -5013,6 +5031,7 @@ uentry usymtab_lookupGlob (cstring k) if (uentry_isPriv (ce)) llfatalbug (message ("usymtab_lookup: private: %s", k)); + DPRINTF (("Lookup global: %s", uentry_unparseFull (ce))); return ce; } @@ -5021,7 +5040,7 @@ uentry usymtab_lookupGlob (cstring k) /*@globals globtab@*/ { uentry ce = usymtab_lookupAux (globtab, k); - + DPRINTF (("Lookup global: %s", uentry_unparseFull (ce))); return ce; } @@ -5033,6 +5052,7 @@ uentry usymtab_lookupEither (cstring k) if (uentry_isUndefined (ce)) llfatalerror (message ("usymtab_lookup: not found: %s", k)); + DPRINTF (("Lookup either: %s", uentry_unparseFull (ce))); return ce; } @@ -5655,6 +5675,7 @@ void usymtab_addMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al) void usymtab_addForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al) /*@modifies utab@*/ { + /* evans 2002-03-3: was sRef_isMeaningful -- but we need to keep aliases for new storage also! */ if (sRef_isMeaningful (s) && sRef_isMeaningful (al) && !(sRef_isConst (s) || sRef_isConst (al)) @@ -5674,10 +5695,17 @@ void usymtab_addForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al) } else { - ; + DPRINTF (("Not aliasing! %s / %s", sRef_unparseFull (s), sRef_unparseFull (al))); + DPRINTF (("meaningful: %d %d", sRef_isMeaningful (s), sRef_isMeaningful (al))); } } +void usymtab_addReallyForceMustAlias (/*@exposed@*/ sRef s, /*@exposed@*/ sRef al) + /*@modifies utab@*/ +{ + utab->aliases = aliasTable_addMustAlias (utab->aliases, s, al); +} + void usymtab_clearAlias (sRef s) /*@modifies utab, s@*/ { @@ -5688,7 +5716,7 @@ void usymtab_clearAlias (sRef s) sRefSet usymtab_allAliases (sRef s) /*@globals utab@*/ { - if (sRef_isMeaningful (s)) + if (sRef_isSomewhatMeaningful (s)) { sRefSet ret; @@ -5706,7 +5734,7 @@ sRefSet usymtab_allAliases (sRef s) /*@only@*/ sRefSet usymtab_canAlias (sRef s) /*@globals utab@*/ { - if (sRef_isMeaningful (s)) + if (sRef_isSomewhatMeaningful (s)) { sRefSet res = aliasTable_canAlias (utab->aliases, s); return res; @@ -5743,7 +5771,7 @@ usymtab_printOut (void) int depth = 0; char *ind = mstring_copy (" "); - fprintf (g_msgstream, "<<< [symbol table] >>>\n"); + fprintf (g_warningstream, "<<< [symbol table] >>>\n"); while (s != GLOBAL_ENV && s->env != GLOBAL_ENV) { @@ -5754,7 +5782,7 @@ usymtab_printOut (void) ind[depth * 3 + 1] = '\0'; } - fprintf (g_msgstream, "level: %d (%s)\n", s->lexlevel, + fprintf (g_warningstream, "level: %d (%s)\n", s->lexlevel, cstring_toCharsSafe (tname)); cstring_free (tname); @@ -5762,17 +5790,17 @@ usymtab_printOut (void) for (i = 0; i < s->nentries; i++) { cstring us = uentry_unparseFull (s->entries[i]); - fprintf (g_msgstream, "%s\n", cstring_toCharsSafe (us)); + fprintf (g_warningstream, "%s\n", cstring_toCharsSafe (us)); cstring_free (us); } if (s->reftable != NULL && s->nentries > 0) { - fprintf (g_msgstream, "\t<< Ref table >>\n"); + fprintf (g_warningstream, "\t<< Ref table >>\n"); for (i = 0; i < s->nentries; i++) { - fprintf (g_msgstream, "\t%s %3d: %d, %d\n", ind, i, + fprintf (g_warningstream, "\t%s %3d: %d, %d\n", ind, i, s->reftable[i]->level, s->reftable[i]->index); } @@ -5782,7 +5810,7 @@ usymtab_printOut (void) depth++; s = s->env; } - fprintf (g_msgstream, "<<< end usymtab >>>\n"); + fprintf (g_warningstream, "<<< end usymtab >>>\n"); mstring_free (ind); return; } @@ -5803,7 +5831,7 @@ usymtab_printAll (void) static void usymtab_printAllAux (usymtab s) - /*@modifies g_msgstream@*/ + /*@modifies g_warningstream@*/ { int i; int depth = 0; @@ -5979,9 +6007,9 @@ usymtab_printLocal (void) static bool checkDistinctExternalName (uentry e) /*@globals globtab@*/ - /*@modifies *g_msgstream@*/ + /*@modifies *g_warningstream@*/ { - int checklen = context_getValue (FLG_EXTERNALNAMELEN); + size_t checklen = size_fromInt (context_getValue (FLG_EXTERNALNAMELEN)); bool ignorecase = context_getFlag (FLG_EXTERNALNAMECASEINSENSITIVE); bool gotone = FALSE; bool extras = FALSE; @@ -6056,7 +6084,7 @@ static bool checkDistinctExternalName (uentry e) "in the first %d characters (%q)", uentry_getName (e), uentry_getName (oe), - checklen, + size_toInt (checklen), cstring_clip (uentry_getName (e), checklen)), /*@=sefparams@*/ uentry_whereLast (e))) @@ -6082,7 +6110,7 @@ static bool checkDistinctExternalName (uentry e) "is ignored", uentry_getName (e), uentry_getName (oe), - checklen), + size_toInt (checklen)), uentry_whereLast (e))) { uentry_showWhereAny (oe); @@ -6108,7 +6136,7 @@ static bool checkDistinctExternalName (uentry e) "in the first %d characters (%q)", uentry_getName (e), uentry_getName (oe), - checklen, + size_toInt (checklen), cstring_clip (uentry_getName (e), checklen)), /*@=sefparams@*/ uentry_whereLast (e))) @@ -6140,11 +6168,11 @@ static bool checkDistinctExternalName (uentry e) static bool checkDistinctInternalName (uentry e) /*@globals utab@*/ - /*@modifies *g_msgstream@*/ + /*@modifies *g_warningstream@*/ { usymtab ttab = utab; cstring name = uentry_rawName (e); - int numchars = context_getValue (FLG_INTERNALNAMELEN); + size_t numchars = size_fromInt (context_getValue (FLG_INTERNALNAMELEN)); bool caseinsensitive = context_getFlag (FLG_INTERNALNAMECASEINSENSITIVE); bool lookalike = context_getFlag (FLG_INTERNALNAMELOOKALIKE); @@ -6184,7 +6212,7 @@ static bool checkDistinctInternalName (uentry e) "in the first %d characters (%q)", uentry_getName (e), uentry_getName (oe), - numchars, + size_toInt (numchars), cstring_clip (uentry_getName (e), numchars)), /*@=sefparams@*/ uentry_whereLast (e))) @@ -6197,8 +6225,7 @@ static bool checkDistinctInternalName (uentry e) /*@switchbreak@*/ break; case CGE_CASE: - if (numchars == 0 - || (cstring_length (name) <= numchars)) + if (numchars == 0 || (cstring_length (name) <= numchars)) { if (optgenerror (FLG_DISTINCTINTERNALNAMES, @@ -6223,7 +6250,7 @@ static bool checkDistinctInternalName (uentry e) "in the first %d characters without case sensitivity", uentry_getName (e), uentry_getName (oe), - numchars), + size_toInt (numchars)), uentry_whereLast (e))) { uentry_showWhereAny (oe); @@ -6260,7 +6287,7 @@ static bool checkDistinctInternalName (uentry e) "in the first %d characters except by lookalike characters", uentry_getName (e), uentry_getName (oe), - numchars), + size_toInt (numchars)), uentry_whereLast (e))) { uentry_showWhereAny (oe); @@ -6315,3 +6342,36 @@ void usymtab_checkDistinctName (uentry e, int scope) return uentry_getSref (ue); } + +# ifdef DEBUGSPLINT +/* +** For debugging only +*/ + +void +usymtab_checkAllValid () /*@globals utab@*/ +{ + usymtab tab = utab; + + while (tab != GLOBAL_ENV) + { + int i; + + for (i = 0; i < utab->nentries; i++) + { + uentry e = utab->entries[i]; + + uentry_checkValid (e); + } + + aliasTable_checkValid (tab->aliases); + tab = tab->env; + } +} +# endif + + + + + +