static bool exprNode_isEmptyStatement (exprNode p_e);
static /*@exposed@*/ exprNode exprNode_firstStatement (/*@returned@*/ exprNode p_e);
static bool exprNode_isFalseConstant (exprNode p_e) /*@*/ ;
-static bool exprNode_isBlock (exprNode p_e);
+static bool exprNode_isStatement (exprNode p_e);
static void checkGlobUse (uentry p_glob, bool p_isCall, /*@notnull@*/ exprNode p_e);
static void exprNode_addUse (exprNode p_e, /*@exposed@*/ sRef p_s);
static bool exprNode_matchArgType (ctype p_ct, exprNode p_e);
exprNode_rawStringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
{
exprNode e = exprNode_createLoc (ctype_string, loc);
- int len = cstring_length (t);
+ size_t len = cstring_length (t);
if (context_getFlag (FLG_STRINGLITERALLEN))
{
- if (len > context_getValue (FLG_STRINGLITERALLEN))
+ if (len > size_fromInt (context_getValue (FLG_STRINGLITERALLEN)))
{
voptgenerror (FLG_STRINGLITERALLEN,
message
("String literal length (%d) exceeds maximum "
"length (%d): \"%s\"",
- len,
+ size_toInt (len),
context_getValue (FLG_STRINGLITERALLEN),
t),
e->loc);
{
exprNode res = exprNode_stringLiteral (t, loc);
res->typ = ctype_makeWideString ();
-
return res;
}
/*@only@*/ exprNode
exprNode_stringLiteral (/*@only@*/ cstring t, /*@only@*/ fileloc loc)
{
- int len = cstring_length (t) - 2;
+ size_t len = size_fromInt (cstring_length (t) - 2);
char *ts = cstring_toCharsSafe (t);
char *s = cstring_toCharsSafe (cstring_create (len + 1));
llassert (*ts == '\"' && *(ts + len + 1) == '\"');
- strncpy (s, ts+1, size_fromInt (len));
+ strncpy (s, ts+1, len);
*(s + len) = '\0';
cstring_free (t);
return exprNode_rawStringLiteral (cstring_fromCharsO (s), loc);
if (ctype_isFixedArray (t1))
{
-
int nelements = long_toInt (ctype_getArraySize (t1));
llassert (multiVal_isString (mval));
len = cstring_lengthExpandEscapes (slit);
-
+ llassert (exprNode_isDefined (e2));
+
if (len == nelements)
{
mstring temp;
- temp = cstring_expandEscapes(slit);
+ temp = cstring_expandEscapes (slit);
if (temp[len-1] == '\0')
{
}
else
{
-
-
- voptgenerror
- (FLG_STRINGLITNOROOM,
- message ("String literal with %d character%& "
- "is assigned to %s (no room for null terminator): %s",
- len + 1,
- ctype_unparse (t1),
- exprNode_unparse (e2)),
- e2->loc);
+ voptgenerror
+ (FLG_STRINGLITNOROOM,
+ message ("String literal with %d character%& "
+ "is assigned to %s (no room for null terminator): %s",
+ len + 1,
+ ctype_unparse (t1),
+ exprNode_unparse (e2)),
+ e2->loc);
}
}
else if (len > nelements)
sRefSet srs = stateClause_getRefs (cl);
sRefModVal modf = stateClause_getEnsuresFunction (cl);
int eparam = stateClause_getStateParameter (cl);
-
+
+ llassert (modf != NULL);
+
DPRINTF (("Reflect after clause: %s / %s",
stateClause_unparse (cl),
sRefSet_unparse (srs)));
stateClause_unparse (cl),
sRefSet_unparse (srs)));
+ llassert (modf != NULL);
+
sRefSet_elements (srs, sel)
{
sRef s;
}
exprNode
-exprNode_assign (/*@only@*/ exprNode e1,
- /*@only@*/ exprNode e2, /*@only@*/ lltok op)
+exprNode_assign (/*@only@*/ exprNode e1, /*@only@*/ exprNode e2, /*@only@*/ lltok op)
{
bool isalloc = FALSE;
bool isjustalloc = FALSE;
ctype_unparse (e1->typ),
ctype_unparse (e2->typ)));
- if (ctype_isNumeric (e2->typ)
- || ctype_isNumeric (e1->typ))
+ if (exprNode_isDefined (e1)
+ && exprNode_isDefined (e2))
{
- /* Its a pointer arithmetic expression like ptr += i */
- noalias = TRUE;
- }
- }
+ if (ctype_isNumeric (e2->typ)
+ || ctype_isNumeric (e1->typ))
+ {
+ /* Its a pointer arithmetic expression like ptr += i */
+ noalias = TRUE;
+ }
+ }
+ }
else
{
ret = exprNode_createPartialCopy (e1);
ctype te1 = exprNode_getType (e1);
ctype te2 = exprNode_getType (e2);
- if (!ctype_forceMatch (te1, te2))
+ if (ctype_isVoid (te2))
+ {
+ (void) gentypeerror
+ (te2, e2, te1, e1,
+ message ("Assignment of void value to %t: %s %s %s",
+ te1, exprNode_unparse (e1),
+ lltok_unparse (op),
+ exprNode_unparse (e2)),
+ e1->loc);
+ }
+ else if (!ctype_forceMatch (te1, te2))
{
if (exprNode_matchLiteral (te1, e2))
{
e1->loc);
}
}
+ else
+ {
+ /* Type checks okay */
+ }
}
exprNode_mergeUSs (ret, e2);
usymtab_setMustBreak ();
}
+ DPRINTF (("==> %s", exprNode_unparse (ret)));
return ret;
}
{
if (!exprNode_isError (e))
{
- exprNode_checkStatement(e);
+ exprChecks_checkStatementEffect(e);
}
return (exprNode_statementError (e, t));
}
}
+exprNode exprNode_compoundStatementExpression (/*@only@*/ lltok tlparen, /*@only@*/ exprNode e)
+{
+ exprNode laststmt;
+
+ DPRINTF (("Compound: %s", exprNode_unparse (e)));
+
+ if (!context_flagOn (FLG_GNUEXTENSIONS, exprNode_loc (e)))
+ {
+ (void) llgenhinterror
+ (FLG_SYNTAX,
+ message ("Compound statement expressions is not supported by ISO C99"),
+ message ("Use +gnuextensions to allow compound statement expressions (and other GNU language extensions) "
+ "without this warning"),
+ exprNode_loc (e));
+ }
+
+ /*
+ ** The type of a compoundStatementExpression is the type of the last statement
+ */
+
+ llassert (exprNode_isBlock (e));
+ laststmt = exprNode_lastStatement (e);
+
+ DPRINTF (("Last statement: %s / %s", exprNode_unparse (laststmt), ctype_unparse (exprNode_getType (laststmt))));
+ DPRINTF (("e: %s", exprNode_unparse (e)));
+ e->typ = exprNode_getType (laststmt);
+ return exprNode_addParens (tlparen, e);
+}
+
+
exprNode exprNode_makeBlock (/*@only@*/ exprNode e)
{
exprNode ret = exprNode_createPartialCopy (e);
ret->mustBreak = e->mustBreak;
}
+ DPRINTF (("Block e: %s", exprNode_unparse (e)));
ret->edata = exprData_makeSingle (e);
ret->kind = XPR_BLOCK;
+ DPRINTF (("Block: %s", exprNode_unparse (ret)));
return ret;
}
return (exprNode_isDefined (e)
&& ((e)->kind == XPR_BLOCK));
}
+
+bool exprNode_isStatement (exprNode e)
+{
+ return (exprNode_isDefined (e)
+ && ((e)->kind == XPR_STMT));
+}
bool exprNode_isAssign (exprNode e)
{
&& (lltok_isSemi (exprData_getTok (e->edata))));
}
+bool exprNode_isMultiStatement (exprNode e)
+{
+ return (exprNode_isDefined (e)
+ && ((e->kind == XPR_FOR)
+ || (e->kind == XPR_FORPRED)
+ || (e->kind == XPR_IF)
+ || (e->kind == XPR_IFELSE)
+ || (e->kind == XPR_WHILE)
+ || (e->kind == XPR_WHILEPRED)
+ || (e->kind == XPR_DOWHILE)
+ || (e->kind == XPR_BLOCK)
+ || (e->kind == XPR_STMT)
+ || (e->kind == XPR_STMTLIST)
+ || (e->kind == XPR_SWITCH)));
+}
+
void exprNode_checkIfPred (exprNode pred)
{
exprNode_checkPred (cstring_makeLiteralTemp ("if"), pred);
return hasError;
}
-static exprNode
+static /*@notnull@*/ exprNode
exprNode_makeInitializationAux (/*@temp@*/ idDecl t)
{
exprNode ret;
break;
case XPR_BLOCK:
- ret = message ("{ %s }", exprNode_unparseFirst (exprData_getSingle (data)));
+ ret = message ("{ %s }", exprNode_unparse (exprData_getSingle (data)));
+ /* evans 2002-02-20 was unparseFirst! */
break;
case XPR_STMT:
- ret = cstring_copy (exprNode_unparse (exprData_getUopNode (data)));
+ ret = message ("%s;", exprNode_unparse (exprData_getUopNode (data)));
break;
case XPR_STMTLIST:
- ret = message ("%s; %s",
- exprNode_unparse (exprData_getPairA (data)),
- exprNode_unparse (exprData_getPairB (data)));
+ if (exprNode_isStatement (exprData_getPairA (data)))
+ {
+ /*
+ ** statement expressions already print the ;
+ */
+
+ ret = message ("%s %s",
+ exprNode_unparse (exprData_getPairA (data)),
+ exprNode_unparse (exprData_getPairB (data)));
+ }
+ else
+ {
+ ret = message ("%s; %s",
+ exprNode_unparse (exprData_getPairA (data)),
+ exprNode_unparse (exprData_getPairB (data)));
+ }
break;
case XPR_FTDEFAULT: