coins.casttohir
Class ToHirCast

java.lang.Object
  extended bycoins.casttohir.ToHirCast

class ToHirCast
extends java.lang.Object

This class offers the cast function.

  . explicit/implicit cast
  . usual arithmetic converson
  . integral promotion
  . comparison result type
  . ?: resultant type
 etc.
 


Field Summary
protected  int fDbgLevel
           
 
Constructor Summary
(package private) ToHirCast(ToHir tohir)
           
 
Method Summary
(package private)  Exp assignCast(Type t1, Exp e2)
          Do cast for assignment statement.
(package private)  Exp cast(Type t1, Exp e2)
          Cast for HIR type object.
(package private)  Exp daPromotion(Exp e)
          Default argument promotion
(package private)  Type getCompareType(Type t1, Type t2)
          Get the type for casting operands of comparison operation.
(package private)  Type getPointerOpType(Type t1, Type t2)
          Get the rresultant type of address expression.
(package private)  Type getSelectType(Type t2, Type t3)
          Get the resultant type of selection expression (?: expression).
(package private)  Type getUacType(Type t1, Type t2)
          Get the resultant type of UAC (usual arithmetic converson).
(package private)  Exp iPromotion(Exp e)
          Integral promotion.
(package private)  Exp siPromotion(Exp e)
          Do signed integral promotion (used at unary -).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fDbgLevel

protected int fDbgLevel
Constructor Detail

ToHirCast

ToHirCast(ToHir tohir)
Method Detail

cast

Exp cast(Type t1,
         Exp e2)
Cast for HIR type object.

Parameters:
t1 - Ttarget type.
e2 - Expression.
Returns:
Casted expression.

iPromotion

Exp iPromotion(Exp e)
Integral promotion.

Parameters:
e - Expression.
Returns:
Integral type expression.

siPromotion

Exp siPromotion(Exp e)
Do signed integral promotion (used at unary -).

Parameters:
e - Expression.
Returns:
Integral type expression.

daPromotion

Exp daPromotion(Exp e)
Default argument promotion

Parameters:
e - Expression.
Returns:
Integral type expression.

assignCast

Exp assignCast(Type t1,
               Exp e2)
Do cast for assignment statement. If assignment is permissible, then cast according to the grammar rule (cast to left hand side if required).
 Condition of permissible assignment:
 *) Both sides are array of toHir.typeChar (initiation by char string for HIR-base)
 1) Both sides are arithmetic and their types are compatible
    except for type qualifier.
 2) Both sides are struct/union and their types are compatible
    except for type qualifier.
 3) Both sides are pointer, and their pointed types are compatible
    except for type qualifier (warning if incompatible), and
    left hand side pointed type includes type qualifier of the
    pointed type of right hand side (warning if not included).
 4) Both sides are pointer, and one of them is the pointer to void,
    and left hand side pointed type includes type qualifier of the
    pointed type of right hand side (warning if not included).
 //5) Left hand side is pointer and right hand side is NULL pointer constant.
 5-1) Left hand side is pointer and right hand side is integral
    (implicitly cast to left hand side issueing warning).
 5-2) Left hand side is integral and right hand side is pointer
    (implicitly cast to left hand side issueing warning).
 

Parameters:
t1 - Left operand Type.
e2 - Right operand.
Returns:
Casted right operand.

getUacType

Type getUacType(Type t1,
                Type t2)
Get the resultant type of UAC (usual arithmetic converson).
 If the rank of left operand is less than the rannk of right operand,
 exchange operands to make processing easy.
 If one of operands is not arithmetic, result (resultant type) is null.
 If ranks are less than the rank of int then {
   Do integral promotion.
   If one of operands has precision greater than int and it is unsigned,
   then the result is unsigned int.
   In other cases return int.
 }
 If one of operands has rank greater than the rank of int then {
   If left operand precision > right operand precision,
    return left operand type.
   If one of operands is unsigned,
   then return the left oprerand type changing it to unsigned if required.
   If both operands are signed, then return the left operand type.
 }
 

Parameters:
t1 - Left operand type.
t2 - Right operand type.
Returns:
Resultant type which is null if t1 or t2 is not arithmetic type.

getCompareType

Type getCompareType(Type t1,
                    Type t2)
Get the type for casting operands of comparison operation.
 1) Both operands are arithmetic
     toHir.isArithmetic(t1) && toHir.isArithmetic(t2)
 2) Both operands are pointer and their pointed types
   are compatible with each other disregarding type qualifier.
     isPointer(t1) && isPointer(t2) && toHir.isCompatible(ptd1,ptd2,false)
 // 3) pointer and NULL pointer constant
 3) One operand is pointer and the other operand is integer
   is made permissible. In such case, 0 is converted to NULL pointer
   and other integer values are casted to pointer after issueing
   warning message.
 4) One operand is pointer and the other operand is pointer to
   void with or without type qualifier.
 

Parameters:
t1 - Right operand type.
t2 - Left operand type.
Returns:
Resultant type of comparison.

getSelectType

Type getSelectType(Type t2,
                   Type t3)
Get the resultant type of selection expression (?: expression).
 1) Both operands are arithmetic --> usual arithmetic conversion
 2) Both operands are compatible struct/union --> composite type
 3) Both operands are void --> void
 4) Both operands are pointer and pointed types are compatible with each other
   disregarding type qualifier --> pointer to composite type with
   all type qualifiers specified
 5) One operator is pointer and the oper is NULL pointer constant
   (treating as integer) --> pointer
 6) Both operands are pointer and one is the pointer to void
   --> pointer to void with all type qualifiers specified
 

Parameters:
t2 - 2nd operand type.
t3 - 3rd operand type.
Returns:
Resultant type of ?:.

getPointerOpType

Type getPointerOpType(Type t1,
                      Type t2)
Get the rresultant type of address expression.
   address expression +/- integer
   (pointer - pointer is treated in atOffset)
 

Parameters:
t1 - Type
t2 - Type
Returns:
Rresultant type of address expression.