ex->level = NestLevel;
ex->block = currBlockno;
ex->initMode = inInitMode;
+ ex->seqPoint = seqPointNo;
return ex;
}
/*-----------------------------------------------------------------*/
/* isAstEqual - compares two asts & returns 1 if they are equal */
/*-----------------------------------------------------------------*/
-int
+static int
isAstEqual (ast * t1, ast * t2)
{
if (!t1 && !t2)
tree->trueLabel->name)))
tree->trueLabel = csym;
else
- werror (E_LABEL_UNDEF, tree->trueLabel->name);
+ werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
+ tree->trueLabel->name);
}
if (tree->falseLabel)
tree->falseLabel->name)))
tree->falseLabel = csym;
else
- werror (E_LABEL_UNDEF, tree->falseLabel->name);
+ werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
+ tree->falseLabel->name);
}
}
tree->opval.val->sym->name);
if (!csym)
- werror (E_LABEL_UNDEF, tree->opval.val->sym->name);
+ werrorfl (tree->filename, tree->lineno, E_LABEL_UNDEF,
+ tree->opval.val->sym->name);
else
tree->opval.val->sym = csym;
tree->opval.val->sym->etype = newIntLink ();
tree->opval.val->etype = tree->opval.val->etype;
tree->opval.val->type = tree->opval.val->sym->type;
- werror (W_IMPLICIT_FUNC, tree->opval.val->sym->name);
+ werrorfl (tree->filename, tree->lineno, W_IMPLICIT_FUNC,
+ tree->opval.val->sym->name);
+ //tree->opval.val->sym->undefined = 1;
allocVariables (tree->opval.val->sym);
}
else
/* exist and this is not defined as a variable arg */
if (!defParm && actParm && !IFFUNC_HASVARARGS(func->ftype))
{
+ //if (func->type==EX_VALUE && func->opval.val->sym->undefined)
+ // return 1; /* Already gave them an undefined function error */
werror (E_TOO_MANY_PARMS);
return 1;
}
}
if (iloop) {
- werror (W_EXCESS_INITIALIZERS, "struct",
- sym->opval.val->sym->name, sym->opval.val->sym->lineDef);
+ werrorfl (filename, sym->opval.val->sym->lineDef,
+ W_EXCESS_INITIALIZERS, "struct",
+ sym->opval.val->sym->name);
}
return rast;
char *name=sym->opval.val->sym->name;
int lineno=sym->opval.val->sym->lineDef;
- werror (W_EXCESS_INITIALIZERS, "array", name, lineno);
+ werrorfl (filename, lineno, W_EXCESS_INITIALIZERS, "array", name);
}
}
else
// there has to be a better way
char *name=sym->opval.val->sym->name;
int lineno=sym->opval.val->sym->lineDef;
- werror (W_EXCESS_INITIALIZERS, "array", name, lineno);
+ werrorfl (filename, lineno, W_EXCESS_INITIALIZERS, "array", name);
break;
}
char *s = SPEC_CVAL (iexpr->etype).v_char;
int i = 0;
int size = getSize (iexpr->ftype);
+ int symsize = getSize (type);
+
+ if (size>symsize)
+ {
+ if (size>(symsize+1))
+ werrorfl (iexpr->filename, iexpr->lineno, W_EXCESS_INITIALIZERS,
+ "string", sym->opval.val->sym->name);
+ size = symsize;
+ }
for (i=0;i<size;i++)
{
work = initAggregates (sym, sym->ival, NULL);
} else {
if (getNelements(sym->type, sym->ival)>1) {
- werror (W_EXCESS_INITIALIZERS, "scalar",
- sym->name, sym->lineDef);
+ werrorfl (filename, sym->lineDef,
+ W_EXCESS_INITIALIZERS, "scalar",
+ sym->name);
}
work = newNode ('=', newAst_VALUE (symbolVal (newSym)),
list2expr (sym->ival));
work = initAggregates (sym, sym->ival, NULL);
} else {
if (getNelements(sym->type, sym->ival)>1) {
- werror (W_EXCESS_INITIALIZERS, "scalar",
- sym->name, sym->lineDef);
+ werrorfl (filename, sym->lineDef,
+ W_EXCESS_INITIALIZERS, "scalar",
+ sym->name);
}
work = newNode ('=', newAst_VALUE (symbolVal (sym)),
list2expr (sym->ival));
else
return FALSE;
}
-
+
return astHasSymbol (tree->left, sym) ||
astHasSymbol (tree->right, sym);
}
case '?':
case ':':
case SIZEOF: /* evaluate wihout code generation */
-
+
if (IS_AST_SYM_VALUE (pbody->left) &&
isSymbolEqual (AST_SYMBOL (pbody->left), sym))
return FALSE;
if (astHasVolatile (pbody->left))
return FALSE;
-
+
if (astHasDeref(pbody->right)) return FALSE;
return isConformingBody (pbody->left, sym, body) &&
{
ast *dtl, *dtr;
+ #if 0
+ if (tree->opval.op == NULLOP || tree->opval.op == BLOCK)
+ {
+ if (tree->left && tree->left->type == EX_OPERAND
+ && (tree->left->opval.op == INC_OP
+ || tree->left->opval.op == DEC_OP)
+ && tree->left->left)
+ {
+ tree->left->right = tree->left->left;
+ tree->left->left = NULL;
+ }
+ if (tree->right && tree->right->type == EX_OPERAND
+ && (tree->right->opval.op == INC_OP
+ || tree->right->opval.op == DEC_OP)
+ && tree->right->left)
+ {
+ tree->right->right = tree->right->left;
+ tree->right->left = NULL;
+ }
+ }
+ #endif
+
dtl = decorateType (tree->left);
/* delay right side for '?' operator since conditional macro expansions might
rely on this */
}
TTYPE (tree) =
- computeType (LTYPE (tree), RTYPE (tree));
+ computeType (LTYPE (tree), RTYPE (tree), FALSE);
TETYPE (tree) = getSpec (TTYPE (tree));
/* if left is a literal exchange left & right */
wtree = optimizeSWAP (tree);
if (wtree != tree)
return decorateType (wtree);
-
- // fall through
}
/* if left is a literal exchange left & right */
decorateType (parent);
}
}
+ /* fall through */
+
/*------------------------------------------------------------------*/
/*----------------------------*/
/* bitwise xor */
/* if right is a literal and */
/* we can find a 2nd literal in a xor-tree then */
/* rearrange the tree */
- if (IS_LITERAL (RTYPE (tree)))
+ if (IS_LITERAL (RTYPE (tree)) &&
+ tree->opval.op == '^') /* the same source is used by 'bitwise or' */
{
ast *parent;
ast *litTree = searchLitOp (tree, &parent, "^");
LRVAL (tree) = RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
computeType (LTYPE (tree),
- RTYPE (tree)));
+ RTYPE (tree),
+ FALSE));
+
+ return tree;
/*------------------------------------------------------------------*/
/*----------------------------*/
LRVAL (tree) = RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
computeType (LTYPE (tree),
- RTYPE (tree)));
+ RTYPE (tree),
+ TRUE));
/* if right is a literal and */
/* left is also a division by a literal then */
LRVAL (tree) = RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
computeType (LTYPE (tree),
- RTYPE (tree)));
+ RTYPE (tree),
+ TRUE));
return tree;
/*------------------------------------------------------------------*/
LRVAL (tree) = RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
computeType (LTYPE (tree),
- RTYPE (tree)));
-
- /* promote result to int if left & right are char
- this will facilitate hardware multiplies 8bit x 8bit = 16bit */
- if (IS_CHAR(LETYPE(tree)) && IS_CHAR(RETYPE(tree))) {
- SPEC_NOUN(TETYPE(tree)) = V_INT;
- }
+ RTYPE (tree),
+ TRUE));
return tree;
else
TETYPE (tree) = getSpec (TTYPE (tree) =
computeType (LTYPE (tree),
- RTYPE (tree)));
+ RTYPE (tree),
+ FALSE));
return tree;
/*------------------------------------------------------------------*/
else
TETYPE (tree) = getSpec (TTYPE (tree) =
computeType (LTYPE (tree),
- RTYPE (tree)));
+ RTYPE (tree),
+ FALSE));
LRVAL (tree) = RRVAL (tree) = 1;
return tree;
}
+ LRVAL (tree) = RRVAL (tree) = 1;
+ if (tree->opval.op == LEFT_OP)
+ {
+ /* promote char to int */
+ TETYPE (tree) = getSpec (TTYPE (tree) =
+ computeType (LTYPE (tree),
+ LTYPE (tree), /* no, not RTYPE! */
+ TRUE));
+ }
+ else /* RIGHT_OP */
+ {
+ /* no promotion necessary */
+ TTYPE (tree) = TETYPE (tree) = copyLinkChain (LTYPE (tree));
+ if (IS_LITERAL (TTYPE (tree)))
+ SPEC_SCLS (TTYPE (tree)) &= ~S_LITERAL;
+ }
+
/* if only the right side is a literal & we are
shifting more than size of the left operand then zero */
if (IS_LITERAL (RTYPE (tree)) &&
- ((unsigned) floatFromVal (valFromType (RETYPE (tree)))) >=
- (getSize (LTYPE (tree)) * 8))
+ ((TYPE_UDWORD) floatFromVal (valFromType (RETYPE (tree)))) >=
+ (getSize (TETYPE (tree)) * 8))
{
if (tree->opval.op==LEFT_OP ||
- (tree->opval.op==RIGHT_OP && SPEC_USIGN(LETYPE(tree)))) {
- lineno=tree->lineno;
- werror (W_SHIFT_CHANGED,
- (tree->opval.op == LEFT_OP ? "left" : "right"));
- tree->type = EX_VALUE;
- tree->left = tree->right = NULL;
- tree->opval.val = constVal ("0");
- TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
- return tree;
- }
+ (tree->opval.op==RIGHT_OP && SPEC_USIGN(LETYPE(tree))))
+ {
+ lineno=tree->lineno;
+ werror (W_SHIFT_CHANGED,
+ (tree->opval.op == LEFT_OP ? "left" : "right"));
+ tree->type = EX_VALUE;
+ tree->left = tree->right = NULL;
+ tree->opval.val = constVal ("0");
+ TETYPE (tree) = TTYPE (tree) = tree->opval.val->type;
+ return tree;
+ }
}
- LRVAL (tree) = RRVAL (tree) = 1;
- TTYPE (tree) = TETYPE (tree) = copyLinkChain (LTYPE (tree));
- if (IS_LITERAL (TTYPE (tree)))
- SPEC_SCLS (TTYPE (tree)) &= ~S_LITERAL;
+
return tree;
/*------------------------------------------------------------------*/
/* make sure the type is complete and sane */
checkTypeSanity(LETYPE(tree), "(cast)");
+ /* If code memory is read only, then pointers to code memory */
+ /* implicitly point to constants -- make this explicit */
+ {
+ sym_link *t = LTYPE(tree);
+ while (t && t->next)
+ {
+ if (IS_CODEPTR(t) && port->mem.code_ro)
+ {
+ if (IS_SPEC(t->next))
+ SPEC_CONST (t->next) = 1;
+ else
+ DCL_PTR_CONST (t->next) = 1;
+ }
+ t = t->next;
+ }
+ }
+
#if 0
/* if the right is a literal replace the tree */
if (IS_LITERAL (RETYPE (tree))) {
/* if the right is a literal replace the tree */
if (IS_LITERAL (RETYPE (tree))) {
- if (IS_PTR (LTYPE (tree)) && !IS_GENPTR (LTYPE (tree)) ) {
+ #if 0
+ if (IS_PTR (LTYPE (tree)) && !IS_GENPTR (LTYPE (tree)) ) {
/* rewrite (type *)litaddr
as &temp
and define type at litaddr temp
TLVAL (newTree) = 1;
return newTree;
}
+ #endif
if (!IS_PTR (LTYPE (tree))) {
tree->type = EX_VALUE;
tree->opval.val =
}
}
/* if unsigned value < 0 then always false */
- /* if (unsigned value) > 0 then (unsigned value) */
- if (SPEC_USIGN(LETYPE(tree)) && IS_LITERAL(RTYPE(tree)) &&
- ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0) {
-
- if (tree->opval.op == '<') {
+ /* if (unsigned value) > 0 then '(unsigned value) ? 1 : 0' */
+ if (SPEC_USIGN(LETYPE(tree)) && IS_LITERAL(RTYPE(tree)) &&
+ ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0)
+ {
+ if (tree->opval.op == '<')
+ {
return tree->right;
- }
- if (tree->opval.op == '>') {
- return tree->left;
- }
- }
+ }
+ if (tree->opval.op == '>')
+ {
+ /* if the parent is an ifx, then we could do */
+ /* return tree->left; */
+ tree->opval.op = '?';
+ tree->right = newNode (':',
+ newAst_VALUE (constVal ("1")),
+ tree->right); /* val 0 */
+ tree->right->lineno = tree->lineno;
+ tree->right->left->lineno = tree->lineno;
+ decorateType (tree->right);
+ }
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) &&
goto errorTreeReturn;
}
- TTYPE (tree) = computeType (LTYPE (tree), RTYPE (tree));
+ TTYPE (tree) = computeType (LTYPE (tree), RTYPE (tree), FALSE);
TETYPE (tree) = getSpec (TTYPE (tree));
return tree;
RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
computeType (LTYPE (tree),
- RTYPE (tree)));
+ RTYPE (tree),
+ FALSE));
if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
werror (E_CODE_WRITE, "-=");
RRVAL (tree) = 1;
TETYPE (tree) = getSpec (TTYPE (tree) =
computeType (LTYPE (tree),
- RTYPE (tree)));
+ RTYPE (tree),
+ FALSE));
if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
werror (E_CODE_WRITE, "+=");
if (compareType (currFunc->type->next, RTYPE (tree)) == 0)
{
- werror (W_RETURN_MISMATCH);
+ werrorfl (tree->filename, tree->lineno, W_RETURN_MISMATCH);
printFromToType (RTYPE(tree), currFunc->type->next);
goto errorTreeReturn;
}
&& tree->right &&
!IS_VOID (RTYPE (tree)))
{
- werror (E_FUNC_VOID);
+ werrorfl (tree->filename, tree->lineno, E_FUNC_VOID);
goto errorTreeReturn;
}
/* the switch value must be an integer */
if (!IS_INTEGRAL (LTYPE (tree)))
{
- werror (E_SWITCH_NON_INTEGER);
+ werrorfl (tree->filename, tree->lineno, E_SWITCH_NON_INTEGER);
goto errorTreeReturn;
}
LRVAL (tree) = 1;
/* then case is out of context */
if (!swStat)
{
- werror (E_CASE_CONTEXT);
+ werrorfl (caseVal->filename, caseVal->lineno, E_CASE_CONTEXT);
return NULL;
}
/* if not a constant then error */
if (!IS_LITERAL (caseVal->ftype))
{
- werror (E_CASE_CONSTANT);
+ werrorfl (caseVal->filename, caseVal->lineno, E_CASE_CONSTANT);
return NULL;
}
/* if not a integer than error */
if (!IS_INTEGRAL (caseVal->ftype))
{
- werror (E_CASE_NON_INTEGER);
+ werrorfl (caseVal->filename, caseVal->lineno, E_CASE_NON_INTEGER);
return NULL;
}
{
pval->next = caseVal->opval.val;
}
+ else if ((int) floatFromVal (val) == cVal)
+ {
+ werrorfl (caseVal->filename, caseVal->lineno, E_DUPLICATE_LABEL,
+ "case");
+ return NULL;
+ }
else
{
/* we found a value greater than */
/* createDefault - creates the parse tree for the default statement */
/*-----------------------------------------------------------------*/
ast *
-createDefault (ast * swStat, ast * stmnt)
+createDefault (ast * swStat, ast * defaultVal, ast * stmnt)
{
char defLbl[SDCC_NAME_MAX + 1];
/* then case is out of context */
if (!swStat)
{
- werror (E_CASE_CONTEXT);
+ werrorfl (defaultVal->filename, defaultVal->lineno, E_CASE_CONTEXT);
+ return NULL;
+ }
+
+ if (swStat->values.switchVals.swDefault)
+ {
+ werrorfl (defaultVal->filename, defaultVal->lineno, E_DUPLICATE_LABEL,
+ "default");
return NULL;
}
fprintf(outfile,"%u", (TYPE_UDWORD) floatFromVal(tree->opval.val));
else
fprintf(outfile,"%d", (TYPE_DWORD) floatFromVal(tree->opval.val));
- fprintf(outfile,", 0x%x, %g", (TYPE_UDWORD) floatFromVal(tree->opval.val),
+ fprintf(outfile,", 0x%x, %f", (TYPE_UDWORD) floatFromVal(tree->opval.val),
floatFromVal(tree->opval.val));
} else if (tree->opval.val->sym) {
/* if the undefined flag is set then give error message */
ast_print(tree->left,outfile,indent+2);
ast_print(tree->right,outfile,indent+2);
return ;
-
+
/*------------------------------------------------------------------*/
/*----------------------------*/
/* assignment operators */