if (IS_INTEGRAL (ftype)
&& (getSize (ftype) < (unsigned) INTSIZE))
{
- newType = newAst_LINK(INTTYPE);
+ if (IS_AST_OP(actParm) &&
+ (actParm->opval.op == LEFT_OP ||
+ actParm->opval.op == '*' ||
+ actParm->opval.op == '+' ||
+ actParm->opval.op == '-') &&
+ actParm->right) {
+ // we should cast an operand instead of the result
+ actParm->decorated = 0;
+ actParm->left = newNode( CAST, newAst_LINK(newIntLink()),
+ actParm->left);
+ actParm = decorateType(actParm);
+ } else {
+ newType = newAst_LINK(INTTYPE);
+ }
}
if (IS_PTR(ftype) && !IS_GENPTR(ftype))
/*----------------------------*/
/* leaf has been reached */
/*----------------------------*/
+ lineno=tree->lineno;
/* if this is of type value */
/* just get the type */
if (tree->type == EX_VALUE)
if (dtr != tree->right)
tree->right = dtr;
- /* special case for some operations: cast up right->left if type of left
- has greater size than right */
- if (tree->left && tree->right && IS_AST_OP(tree->right) &&
- (tree->right->opval.op == LEFT_OP ||
- (tree->right->opval.op == '*' /* for int -> long only */ &&
- tree->right->right /* but not for deref */ ) ||
- tree->right->opval.op == '+' ||
- tree->right->opval.op == '-')) {
- int lsize = getSize(LTYPE(tree));
- int rsize = getSize(RTYPE(tree));
-
- if (lsize > rsize) {
- tree->right->decorated = 0;
- tree->right->left = newNode( CAST, (lsize == 2 ?
- newAst_LINK(newIntLink()) :
- newAst_LINK(newLongLink())),
- tree->right->left);
- tree->right = decorateType(tree->right);
- }
+ if (IS_AST_OP(tree) &&
+ (tree->opval.op == CAST || tree->opval.op == '=') &&
+ (getSize(LTYPE(tree)) > getSize(RTYPE(tree))) &&
+ (getSize(RTYPE(tree)) < INTSIZE)) {
+ // this is a cast/assign to a bigger type
+ if (IS_AST_OP(tree->right) &&
+ IS_INTEGRAL(tree->right->ftype) &&
+ (tree->right->opval.op == LEFT_OP ||
+ tree->right->opval.op == '*' ||
+ tree->right->opval.op == '+' ||
+ tree->right->opval.op == '-') &&
+ tree->right->right) {
+ // we should cast an operand instead of the result
+ tree->right->decorated = 0;
+ tree->right->left = newNode( CAST, newAst_LINK(newIntLink()),
+ tree->right->left);
+ tree->right = decorateType(tree->right);
+ }
}
}
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;
}
+
return tree;
/*------------------------------------------------------------------*/
LRVAL (tree) = RRVAL (tree) = 1;
/* if the left is a pointer */
- if (IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree)))
+ if (IS_PTR (LTYPE (tree)) || IS_AGGREGATE (LTYPE (tree)) )
TETYPE (tree) = getSpec (TTYPE (tree) =
LTYPE (tree));
else
tree->opval.val->type);
return tree;
}
-#if 0
- /* a left shift must be done with at least 16bits */
- if ((tree->opval.op==LEFT_OP) && (getSize(LTYPE(tree))<2)) {
- // insert a cast
- if (IS_AST_SYM_VALUE(tree->left) || IS_AST_OP(tree->left)) {
- tree->left =
- decorateType (newNode (CAST,
- newAst_LINK(copyLinkChain(LTYPE(tree))),
- tree->left));
- SPEC_NOUN(tree->left->left->ftype)=V_INT;
- } else {
- // must be a literal, we can do it right away
- SPEC_NOUN(tree->left->opval.val->type)=V_INT;
- }
- }
-#endif
+
/* 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))
{
- /* if left shift then cast up */
- if (tree->opval.op==LEFT_OP) {
- int size = getSize(LTYPE(tree));
- tree->left =
- decorateType (newNode (CAST,
- (size == 1 ? newAst_LINK(newIntLink()) :
- (size == 2 ? newAst_LINK(newLongLink()) :
- newAst_LINK(newIntLink()))),
- tree->left));
- } else {
- 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;
- }
+ 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;
+ }
}
LRVAL (tree) = RRVAL (tree) = 1;
if (IS_LITERAL (LTYPE (tree)) && !IS_LITERAL (RTYPE (tree)))