* Version: $Id$
*/
-/*
- * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
- */
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <assert.h>
#include <stdio.h>
-#include <stdlib.h> /* for _MAX_PATH */
+#include <limits.h> /* for PATH_MAX */
#include <string.h>
#include "embryo_cc_sc.h"
/* find the name with the operator */
if (numparam == 2)
{
- if (oper == NULL)
+ if (!oper)
{
/* assignment operator: a special case */
strcpy(opername, "=");
- if (lval != NULL
+ if (lval
&& (lval->ident == iARRAYCELL || lval->ident == iARRAYCHAR))
savealt = TRUE;
}
{
assert((sizeof binoperstr / sizeof binoperstr[0]) ==
(sizeof op1 / sizeof op1[0]));
- for (i = 0; i < sizeof op1 / sizeof op1[0]; i++)
+ for (i = 0; i < (int)(sizeof op1 / sizeof op1[0]); i++)
{
if (oper == op1[i])
{
- strcpy(opername, binoperstr[i]);
+ strncpy(opername, binoperstr[i], sizeof(opername) - 1);
+ opername[sizeof(opername) - 1] = 0;
savepri = binoper_savepri[i];
break;
} /* if */
(sizeof unopers / sizeof unopers[0]));
if (opername[0] == '\0')
{
- for (i = 0; i < sizeof unopers / sizeof unopers[0]; i++)
+ for (i = 0; i < (int)(sizeof unopers / sizeof unopers[0]); i++)
{
if (oper == unopers[i])
{
- strcpy(opername, unoperstr[i]);
+ strncpy(opername, unoperstr[i], sizeof(opername) - 1);
+ opername[sizeof(opername) - 1] = 0;
break;
} /* if */
} /* for */
operator_symname(symbolname, opername, tag1, tag2, numparam, tag2);
swapparams = FALSE;
sym = findglb(symbolname);
- if (sym == NULL /*|| (sym->usage & uDEFINE)==0 */ )
+ if (!sym /*|| (sym->usage & uDEFINE)==0 */ )
{ /* ??? should not check uDEFINE; first pass clears these bits */
/* check for commutative operators */
- if (tag1 == tag2 || oper == NULL || !commutative(oper))
+ if (tag1 == tag2 || !oper || !commutative(oper))
return FALSE; /* not commutative, cannot swap operands */
/* if arrived here, the operator is commutative and the tags are different,
* swap tags and try again
operator_symname(symbolname, opername, tag2, tag1, numparam, tag1);
swapparams = TRUE;
sym = findglb(symbolname);
- if (sym == NULL /*|| (sym->usage & uDEFINE)==0 */ )
+ if (!sym /*|| (sym->usage & uDEFINE)==0 */ )
return FALSE;
} /* if */
- /* check existance and the proper declaration of this function */
+ /* check existence and the proper declaration of this function */
if ((sym->usage & uMISSING) != 0 || (sym->usage & uPROTOTYPED) == 0)
{
char symname[2 * sNAMEMAX + 16]; /* allow space for user defined operators */
else if (savealt)
{
/* for the assignment operator, ALT may contain an address at which the
- * result must be stored; this address must be preserved accross the
+ * result must be stored; this address must be preserved across the
* call
*/
assert(lval != NULL); /* this was checked earlier */
} /* if */
/* push parameters, call the function */
- paramspassed = (oper == NULL) ? 1 : numparam;
+ paramspassed = (!oper) ? 1 : numparam;
switch (paramspassed)
{
case 1:
ffcall(sym, paramspassed);
if (sc_status != statSKIP)
markusage(sym, uREAD); /* do not mark as "used" when this call itself is skipped */
- if (sym->x.lib != NULL)
+ if (sym->x.lib)
sym->x.lib->value += 1; /* increment "usage count" of the library */
sideeffect = TRUE; /* assume functions carry out a side-effect */
assert(resulttag != NULL);
{
symbol *sym = lval->sym;
- if (sym == NULL || (sym->ident != iFUNCTN && sym->ident != iREFFUNC))
+ if (!sym || (sym->ident != iFUNCTN && sym->ident != iREFFUNC))
return; /* no known symbol, or not a function result */
if ((sym->usage & uDEFINE) != 0)
plnge2(op1[opidx], hier, lval, &lval2);
if (op1[opidx] == ob_and || op1[opidx] == ob_or)
bitwise_opercount++;
- if (forcetag != NULL)
+ if (forcetag)
lval->tag = sc_addtag(forcetag);
}
while (nextop(&opidx, opstr)); /* do */
if (lval1->ident == iARRAY || lval1->ident == iREFARRAY)
{
char *ptr =
- (lval1->sym != NULL) ? lval1->sym->name : "-unknown-";
+ (lval1->sym) ? lval1->sym->name : "-unknown-";
error(33, ptr); /* array must be indexed */
}
else if (lval2->ident == iARRAY || lval2->ident == iREFARRAY)
{
char *ptr =
- (lval2->sym != NULL) ? lval2->sym->name : "-unknown-";
+ (lval2->sym) ? lval2->sym->name : "-unknown-";
error(33, ptr); /* array must be indexed */
} /* if */
/* ??? ^^^ should do same kind of error checking with functions */
*constant = FALSE;
*val = 0;
} /* if */
- if (tag != NULL)
+ if (tag)
*tag = lval.tag;
if (chkfuncresult)
checkfunction(&lval);
*
* Lowest hierarchy level (except for the , operator).
*
- * Global references: intest (reffered to only)
+ * Global references: intest (referred to only)
*/
int
hier14(value * lval1)
for (i = 0; i < sDIMEN_MAX; i++)
arrayidx1[i] = arrayidx2[i] = 0;
org_arrayidx = lval1->arrayidx; /* save current pointer, to reset later */
- if (lval1->arrayidx == NULL)
+ if (!lval1->arrayidx)
lval1->arrayidx = arrayidx1;
lvalue = plnge1(hier13, lval1);
if (lval1->ident != iARRAYCELL && lval1->ident != iARRAYCHAR)
lval2.arrayidx = NULL;
if (oper)
pop2();
- if (!oper && lval3.arrayidx != NULL && lval2.arrayidx != NULL
+ if (!oper && lval3.arrayidx && lval2.arrayidx
&& lval3.ident == lval2.ident && lval3.sym == lval2.sym)
{
int same = TRUE;
if (lval2.ident != iARRAY && lval2.ident != iREFARRAY)
error(33, lval3.sym->name); /* array must be indexed */
- if (lval2.sym != NULL)
+ if (lval2.sym)
{
val = lval2.sym->dim.array.length; /* array variable */
level = lval2.sym->dim.array.level;
if (array1 && !array2)
{
char *ptr =
- (lval->sym->name != NULL) ? lval->sym->name : "-unknown-";
+ (lval->sym->name) ? lval->sym->name : "-unknown-";
error(33, ptr); /* array must be indexed */
}
else if (!array1 && array2)
{
char *ptr =
- (lval2.sym->name != NULL) ? lval2.sym->name : "-unknown-";
+ (lval2.sym->name) ? lval2.sym->name : "-unknown-";
error(33, ptr); /* array must be indexed */
} /* if */
/* ??? if both are arrays, should check dimensions */
if (tok != tSYMBOL)
return error(20, st); /* illegal symbol name */
sym = findloc(st);
- if (sym == NULL)
+ if (!sym)
sym = findglb(st);
- if (sym != NULL && sym->ident != iFUNCTN && sym->ident != iREFFUNC
+ if (sym && sym->ident != iFUNCTN && sym->ident != iREFFUNC
&& (sym->usage & uDEFINE) == 0)
sym = NULL; /* symbol is not a function, it is in the table, but not "defined" */
- val = (sym != NULL);
- if (!val && find_subst(st, strlen(st)) != NULL)
+ val = !!sym;
+ if (!val && find_subst(st, strlen(st)))
val = 1;
clear_value(lval);
lval->ident = iCONSTEXPR;
if (tok != tSYMBOL)
return error(20, st); /* illegal symbol name */
sym = findloc(st);
- if (sym == NULL)
+ if (!sym)
sym = findglb(st);
- if (sym == NULL)
+ if (!sym)
return error(17, st); /* undefined symbol */
if (sym->ident == iCONSTEXPR)
error(39); /* constant symbol has no size */
error(28); /* invalid subscript */
else
lval->constval = array_levelsize(sym, level);
- if (lval->constval == 0 && strchr(lptr, PREPROC_TERM) == NULL)
+ if (lval->constval == 0 && !strchr(lptr, PREPROC_TERM))
error(224, st); /* indeterminate array size in "sizeof" expression */
} /* if */
const1(lval->constval);
else
{
sym = findloc(st);
- if (sym == NULL)
+ if (!sym)
sym = findglb(st);
- if (sym == NULL)
+ if (!sym)
return error(17, st); /* undefined symbol */
if ((sym->usage & uDEFINE) == 0)
return error(17, st); /* undefined symbol (symbol is in the table, but it is "used" only) */
if (matchtoken('[') || matchtoken('{') || matchtoken('('))
{
tok = tokeninfo(&val, &st); /* get token read by matchtoken() */
- if (sym == NULL && symtok != tSYMBOL)
+ if (!sym && symtok != tSYMBOL)
{
/* we do not have a valid symbol and we appear not to have read a valid
* symbol name (so it is unlikely that we would have read a name of an
if (tok == '[' || tok == '{')
{ /* subscript */
close = (char)((tok == '[') ? ']' : '}');
- if (sym == NULL)
+ if (!sym)
{ /* sym==NULL if lval is a constant or a literal */
error(28); /* cannot subscript */
needtoken(close);
if (lval2.ident == iCONSTEXPR)
{ /* constant expression */
stgdel(index, cidx); /* scratch generated code */
- if (lval1->arrayidx != NULL)
+ if (lval1->arrayidx)
{ /* keep constant index, for checking */
assert(sym->dim.array.level >= 0
&& sym->dim.array.level < sDIMEN_MAX);
}
else
{ /* tok=='(' -> function(...) */
- if (sym == NULL
+ if (!sym
|| (sym->ident != iFUNCTN && sym->ident != iREFFUNC))
{
- if (sym == NULL && sc_status == statFIRST)
+ if (!sym && sc_status == statFIRST)
{
/* could be a "use before declaration"; in that case, create a stub
* function so that the usage can be marked.
*/
sym = fetchfunc(lastsymbol, 0);
- if (sym != NULL)
+ if (sym)
markusage(sym, uREAD);
} /* if */
return error(12); /* invalid function call */
return FALSE; /* result of function call is no lvalue */
} /* if */
} /* if */
- if (sym != NULL && lval1->ident == iFUNCTN)
+ if (sym && lval1->ident == iFUNCTN)
{
assert(sym->ident == iFUNCTN);
address(sym);
if (matchtoken('('))
{ /* sub-expression - (expression,...) */
- /* FIXME: 64bit unsafe */
pushstk((stkitem) intest);
- /* FIXME: 64bit unsafe */
pushstk((stkitem) sc_allowtags);
intest = 0; /* no longer in "test" expression */
if (tok == tSYMBOL && !findconst(st))
{
/* first look for a local variable */
- if ((sym = findloc(st)) != 0)
+ if ((sym = findloc(st)))
{
if (sym->ident == iLABEL)
{
} /* if */
} /* if */
/* now try a global variable */
- if ((sym = findglb(st)) != 0)
+ if ((sym = findglb(st)))
{
if (sym->ident == iFUNCTN || sym->ident == iREFFUNC)
{
} /* if */
/* ??? handle const array passed by reference */
/* otherwise, the address is already in PRI */
- if (lval.sym != NULL)
+ if (lval.sym)
markusage(lval.sym, uWRITTEN);
/*
* Dont need this warning - its varargs. there is no way of knowing the
case iREFERENCE:
if (!lvalue || lval.ident == iARRAYCHAR)
error(35, argidx + 1); /* argument type mismatch */
- if (lval.sym != NULL && (lval.sym->usage & uCONST) != 0
+ if (lval.sym && (lval.sym->usage & uCONST) != 0
&& (arg[argidx].usage & uCONST) == 0)
error(35, argidx + 1); /* argument type mismatch */
if (lval.ident == iVARIABLE || lval.ident == iREFERENCE)
(arg[argidx].tags, arg[argidx].numtags, lval.tag))
error(213);
argidx++; /* argument done */
- if (lval.sym != NULL)
+ if (lval.sym)
markusage(lval.sym, uWRITTEN);
break;
case iREFARRAY:
error(35, argidx + 1); /* argument type mismatch */
break;
} /* if */
- if (lval.sym != NULL && (lval.sym->usage & uCONST) != 0
+ if (lval.sym && (lval.sym->usage & uCONST) != 0
&& (arg[argidx].usage & uCONST) == 0)
error(35, argidx + 1); /* argument type mismatch */
/* Verify that the dimensions match with those in arg[argidx].
* A literal array always has a single dimension.
* An iARRAYCELL parameter is also assumed to have a single dimension.
*/
- if (lval.sym == NULL || lval.ident == iARRAYCELL)
+ if (!lval.sym || lval.ident == iARRAYCELL)
{
if (arg[argidx].numdim != 1)
{
*/
asz = find_constval(&arrayszlst, arg[argidx].defvalue.size.symname,
arg[argidx].defvalue.size.level);
- if (asz != NULL)
+ if (asz)
{
array_sz = asz->value;
if (array_sz == 0)
assert((arg[argidx].hasdefault & uTAGOF) != 0);
sym = findloc(arg[argidx].defvalue.size.symname);
- if (sym == NULL)
+ if (!sym)
sym = findglb(arg[argidx].defvalue.size.symname);
- array_sz = (sym != NULL) ? sym->tag : 0;
+ array_sz = (sym) ? sym->tag : 0;
exporttag(array_sz);
} /* if */
const1(array_sz);
ffcall(sym, nargs);
if (sc_status != statSKIP)
markusage(sym, uREAD); /* do not mark as "used" when this call itself is skipped */
- if (sym->x.lib != NULL)
+ if (sym->x.lib)
sym->x.lib->value += 1; /* increment "usage count" of the library */
modheap(-heapalloc * sizeof(cell));
sideeffect = TRUE; /* assume functions carry out a side-effect */
symbol *sym;
tok = lex(&val, &st);
- if (tok == tSYMBOL && (sym = findconst(st)) != 0)
+ if (tok == tSYMBOL && (sym = findconst(st)))
{
lval->constval = sym->addr;
const1(lval->constval);