# include "splintMacros.nf"
# include "basic.h"
# include "cgrammar.h"
+# include "cscanner.h"
# include "cgrammar_tokens.h"
# include "exprChecks.h"
{
if (initMod)
{
- uentry_free (regArg);
- uentry_free (outArg);
- uentry_free (outStringArg);
+ /* evans 2002-07-12: changed uentry_free to uentry_freeComplete */
+ uentry_freeComplete (regArg);
+ uentry_freeComplete (outArg);
+ uentry_freeComplete (outStringArg);
exprNode_free (s_mustExitNode);
initMod = FALSE;
- /*@-branchstate@*/
+ /*@-branchstate@*/
}
/*@=branchstate@*/
}
if (context_justPopped ()) /* watch out! c could be dead */
{
- uentry ce = usymtab_lookupSafe (LastIdentifier ());
+ uentry ce = usymtab_lookupSafe (cscanner_observeLastIdentifier ());
if (uentry_isValid (ce))
{
return ret;
}
-
static void exprNode_checkStringLiteralLength (ctype t1, exprNode e2)
{
multiVal mval = exprNode_getValue (e2);
cstring slit;
- int len;
+ size_t len;
if (ctype_isFixedArray (t1))
{
- int nelements = long_toInt (ctype_getArraySize (t1));
+ size_t nelements = ctype_getArraySize (t1);
llassert (multiVal_isString (mval));
slit = multiVal_forceString (mval);
/* f->typ is already set to the return type */
DPRINTF (("Function: %s", uentry_unparseFull (le)));
- ret->sref = uentry_returnedRef (le, args);
+ ret->sref = uentry_returnedRef (le, args, exprNode_loc (f));
DPRINTF (("Returned: %s / %s",
uentry_unparseFull (le),
sRef_unparseFull (ret->sref)));
reflectEnsuresClause (ret, le, f, args);
setCodePoint ();
+ DPRINTF (("Here: %s", sRef_unparseFull (ret->sref)));
return (ret);
}
ret->sref = sRef_copy (e->sref);
+ DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
+
if (!sRef_isConst (e->sref))
{
usymtab_addForceMustAlias (ret->sref, e->sref);
}
+ DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
sRef_setTypeFull (ret->sref, c);
DPRINTF (("Cast 2: -> %s", sRef_unparseFull (ret->sref)));
if (ctype_isVoid (c)) /* cast to void is always okay --- discard value */
{
- ;
+ /* evans 2002-07-19: added this warning */
+ DPRINTF (("Checking: %s / %s", exprNode_unparse (ret), sRef_unparseFull (ret->sref)));
+ if (sRef_isFresh (ret->sref))
+ {
+ voptgenerror
+ (FLG_MUSTFREEFRESH,
+ message ("New fresh storage %q(type %s) cast to void (not released): %s",
+ sRef_unparseOpt (ret->sref),
+ ctype_unparse (exprNode_getType (ret)),
+ exprNode_unparse (ret)),
+ exprNode_loc (ret));
+ }
}
else if (ctype_isRealAP (c)) /* casting to array or pointer */
{
if (ctype_isFixedArray (t1))
{
- int nelements = long_toInt (ctype_getArraySize (t1));
+ size_t nelements = ctype_getArraySize (t1);
DPRINTF (("Checked array: %s / %d",
ctype_unparse (t1), nelements));
}
else
{
- if (exprNodeList_size (vals) != nelements)
+ if (exprNodeList_size (vals) != size_toInt (nelements))
{
hasError = optgenerror
- (exprNodeList_size (vals) > nelements ? FLG_INITSIZE : FLG_INITALLELEMENTS,
+ (exprNodeList_size (vals) > size_toInt (nelements)
+ ? FLG_INITSIZE : FLG_INITALLELEMENTS,
message ("Initializer block for "
"%s has %d element%&, but declared as %s: %q",
exprNode_unparse (el),
{
sRef_setDefState (ret->sref, SS_PARTIAL, fileloc_undefined);
}
-# if 0
+
if (exprNode_isStringLiteral (e)
&& (ctype_isArray (ct))
&& (ctype_isChar (ctype_realType (ctype_baseArrayPtr (ct)))))
** If t is a char [], the literal is copied.
*/
- cstring slit;
+ exprNode_checkStringLiteralLength (ct, e);
+ sRef_setDefState (ret->sref, SS_DEFINED, e->loc);
+ ret->val = multiVal_copy (e->val);
+ sRef_setNullTerminatedState (ret->sref);
+
if (multiVal_isDefined (e->val))
{
- slit = multiVal_forceString (e->val);
- }
- else
- {
- slit = cstring_undefined;
+ cstring slit = multiVal_forceString (e->val);
+ sRef_setLen (ret->sref, cstring_length (slit) + 1);
}
- sRef_setDefState (ret->sref, SS_DEFINED, e->loc);
- ret->val = multiVal_copy (e->val);
-
- if (cstring_isDefined (slit))
+ if (ctype_isFixedArray (ct))
{
- if (ctype_isFixedArray (ct))
- {
- long int alength = ctype_getArraySize (ct);
-
- if (alength < cstring_length (slit) + 1)
- {
- voptgenerror
- (FLG_LITERALOVERSIZE,
- ("Array initialized to string literal bigger than allocated size (literal is %d chars long (plus one for nul terminator), array size is %d): %s",
- cstring_length (slit),
- alength,
- exprNode_unparse (e)),
- e->loc);
- }
- else if (alength > cstring_length (slit))
- {
- voptgenerror
- (FLG_LITERALUNDERSIZE,
- ("Array initialized to string literal smaller than allocated size (literal is %d chars long (plus one for nul terminator), array size is %d), could waste storage: %s",
- cstring_length (slit),
- alength,
- exprNode_unparse (e)),
- e->loc);
- }
- else
- {
- ;
- }
- }
- else
- {
- sRef_setNullTerminatedState (ret->sref);
- sRef_setSize (ret->sref, cstring_length (slit) + 1);
- sRef_setLen (ret->sref, cstring_length (slit) + 1);
- }
+ sRef_setSize (ret->sref, size_toInt (ctype_getArraySize (ct)));
}
}
else
-# endif
{
doAssign (ret, e, TRUE);
}