switch (cexpr->type)
{
case EX_VALUE:
- return (IS_AST_LIT_VALUE(cexpr));
+ if (IS_AST_LIT_VALUE(cexpr)) {
+ // this is a literal
+ return TRUE;
+ }
+ if (IS_AST_SYM_VALUE(cexpr) && IS_FUNC(AST_SYMBOL(cexpr)->type)) {
+ // a function's address will never change
+ return TRUE;
+ }
+ return FALSE;
case EX_LINK:
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"unexpected link in expression tree\n");
return FALSE;
case EX_OP:
+ if (cexpr->opval.op==ARRAYINIT) {
+ // this is a list of literals
+ return TRUE;
+ }
+ if (cexpr->opval.op=='=') {
+ return constExprTree(cexpr->right);
+ }
if (cexpr->opval.op==CAST) {
// jwk: cast ignored, maybe we should throw a warning here
return constExprTree(cexpr->right);
void eval2icode (ast *);
value *constExprValue (ast *, int);
bool constExprTree (ast *);
+int setAstLineno (ast *, int);
symbol *funcOfType (char *, sym_link *, sym_link *, int, int);
symbol * funcOfTypeVarg (char *, char * , int , char **);
ast *initAggregates (symbol *, initList *, ast *);
}
codeOutFile = statsg->oFile;
-#if 1
+#if 0
if (ival) {
// set ival's lineno to where the symbol was defined
lineno=ival->lineno=sym->lineDef;
#else
if (ival) {
// set ival's lineno to where the symbol was defined
- lineno=ival->lineno=sym->lineDef;
+ setAstLineno (ival, lineno=sym->lineDef);
// check if this is a constant expression
- if (constExprTree(ival->right)) {
+ if (constExprTree(ival)) {
allocInfo = 0;
eBBlockFromiCode (iCodeFromAst (ival));
allocInfo = 1;
(&some_struct)->element */
if (IS_AST_OP (expr->left) &&
expr->left->opval.op == PTR_OP &&
- IS_ADDRESS_OF_OP (expr->left->left))
- return valForStructElem (expr->left->left->left,
- expr->left->right);
-
+ IS_ADDRESS_OF_OP (expr->left->left)) {
+ return valForStructElem (expr->left->left->left,
+ expr->left->right);
+ }
}
/* case 3. (((char *) &a) +/- constant) */
if (IS_AST_OP (expr) &&
{ W_POSSBUG, ERROR_LEVEL_WARNING,
"possible code generation error at line %d,\n"
" send source to sandeep.dutta@usa.net" },
-{ E_INCOMPAT_PTYPES, ERROR_LEVEL_WARNING,
+{ E_INCOMPAT_PTYPES, ERROR_LEVEL_ERROR,
"pointer types incompatible " },
{ W_UNKNOWN_MODEL, ERROR_LEVEL_WARNING,
"unknown memory model at %s : %d" },