switch (tree->opval.op)
{
- /*------------------------------------------------------------------*/
- /*----------------------------*/
- /* array node */
- /*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* array node */
+ /*----------------------------*/
case '[':
/* determine which is the array & which the index */
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* ++/-- operation */
-/*----------------------------*/
+ /*----------------------------*/
case INC_OP: /* incerement operator unary so left only */
case DEC_OP:
{
return tree;
}
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* bitwise and */
-/*----------------------------*/
+ /*----------------------------*/
case '&': /* can be unary */
/* if right is NULL then unary operation */
if (tree->right) /* not an unary operation */
return tree;
}
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* address of */
-/*----------------------------*/
+ /*----------------------------*/
p = newLink ();
p->class = DECLARATOR;
/* if bit field then error */
TLVAL (tree) = 1;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* bitwise or */
-/*----------------------------*/
+ /*----------------------------*/
case '|':
/* if the rewrite succeeds then don't go any furthur */
{
if (wtree != tree)
return decorateType (wtree);
}
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* bitwise xor */
-/*----------------------------*/
+ /*----------------------------*/
case '^':
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
computeType (LTYPE (tree),
RTYPE (tree)));
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* division */
-/*----------------------------*/
+ /*----------------------------*/
case '/':
if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
{
RTYPE (tree)));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* modulus */
-/*----------------------------*/
+ /*----------------------------*/
case '%':
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
RTYPE (tree)));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
-/* address dereference */
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* address dereference */
+ /*----------------------------*/
case '*': /* can be unary : if right is null then unary operation */
if (!tree->right)
{
return tree;
}
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* multiplication */
-/*----------------------------*/
+ /*----------------------------*/
if (!IS_ARITHMETIC (LTYPE (tree)) || !IS_ARITHMETIC (RTYPE (tree)))
{
werror (E_INVALID_OP, "multiplication");
}
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* unary '+' operator */
-/*----------------------------*/
+ /*----------------------------*/
case '+':
/* if unary plus */
if (!tree->right)
return tree;
}
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* addition */
-/*----------------------------*/
+ /*----------------------------*/
/* this is not a unary operation */
/* if both pointers then problem */
RTYPE (tree)));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* unary '-' */
-/*----------------------------*/
+ /*----------------------------*/
case '-': /* can be unary */
/* if right is null then unary */
if (!tree->right)
return tree;
}
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* subtraction */
-/*----------------------------*/
+ /*----------------------------*/
if (!(IS_PTR (LTYPE (tree)) ||
IS_ARRAY (LTYPE (tree)) ||
LRVAL (tree) = RRVAL (tree) = 1;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* compliment */
-/*----------------------------*/
+ /*----------------------------*/
case '~':
/* can be only integral type */
if (!IS_INTEGRAL (LTYPE (tree)))
COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* not */
-/*----------------------------*/
+ /*----------------------------*/
case '!':
/* can be pointer */
if (!IS_ARITHMETIC (LTYPE (tree)) &&
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* shift */
-/*----------------------------*/
+ /*----------------------------*/
case RRC:
case RLC:
TTYPE (tree) = LTYPE (tree);
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* logical &&, || */
-/*----------------------------*/
+ /*----------------------------*/
case AND_OP:
case OR_OP:
/* each must me arithmetic type or be a pointer */
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* comparison operators */
-/*----------------------------*/
+ /*----------------------------*/
case '>':
case '<':
case LE_OP:
goto errorTreeReturn;
}
}
+ /* 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 == '<') {
+ return tree->right;
+ }
+ if (tree->opval.op == '>') {
+ return tree->left;
+ }
+ }
/* if they are both literal then */
/* rewrite the tree */
if (IS_LITERAL (RTYPE (tree)) &&
TTYPE (tree) = TETYPE (tree) = newCharLink ();
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* sizeof */
-/*----------------------------*/
+ /*----------------------------*/
case SIZEOF: /* evaluate wihout code generation */
/* change the type to a integer */
tree->type = EX_VALUE;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* assignment operators */
-/*----------------------------*/
+ /*----------------------------*/
case MUL_ASSIGN:
case DIV_ASSIGN:
/* for these it must be both must be integral */
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* -= operator */
-/*----------------------------*/
+ /*----------------------------*/
case SUB_ASSIGN:
if (!(IS_PTR (LTYPE (tree)) ||
IS_ARITHMETIC (LTYPE (tree))))
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* += operator */
-/*----------------------------*/
+ /*----------------------------*/
case ADD_ASSIGN:
/* this is not a unary operation */
/* if both pointers then problem */
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* straight assignemnt */
-/*----------------------------*/
+ /*----------------------------*/
case '=':
/* cannot be an aggregate */
if (IS_AGGREGATE (LTYPE (tree)))
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* comma operator */
-/*----------------------------*/
+ /*----------------------------*/
case ',':
TETYPE (tree) = getSpec (TTYPE (tree) = RTYPE (tree));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* function call */
-/*----------------------------*/
+ /*----------------------------*/
case CALL:
parmNumber = 1;
TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)->next);
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* return statement */
-/*----------------------------*/
+ /*----------------------------*/
case RETURN:
if (!tree->right)
goto voidcheck;
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* switch statement */
-/*----------------------------*/
+ /*----------------------------*/
case SWITCH:
/* the switch value must be an integer */
if (!IS_INTEGRAL (LTYPE (tree)))
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* ifx Statement */
-/*----------------------------*/
+ /*----------------------------*/
case IFX:
tree->left = backPatchLabels (tree->left,
tree->trueLabel,
TTYPE (tree) = TETYPE (tree) = NULL;
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* for Statement */
-/*----------------------------*/
+ /*----------------------------*/
case FOR:
decorateType (resolveSymbols (AST_FOR (tree, initExpr)));