coins.casttohir
クラス ToHirCast

java.lang.Object
  |
  +--coins.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.
 


フィールドの概要
protected  int fDbgLevel
           
 
コンストラクタの概要
(パッケージプライベート) ToHirCast(ToHir tohir)
           
 
メソッドの概要
(パッケージプライベート)  Exp assignCast(Type t1, Exp e2)
          Do cast for assignment statement.
(パッケージプライベート)  Exp cast(Type t1, Exp e2)
          Cast for HIR type object.
(パッケージプライベート)  Exp daPromotion(Exp e)
          Default argument promotion
(パッケージプライベート)  Type getCompareType(Type t1, Type t2)
          Get the type for casting operands of comparison operation.
(パッケージプライベート)  Type getPointerOpType(Type t1, Type t2)
          Get the rresultant type of address expression.
(パッケージプライベート)  Type getSelectType(Type t2, Type t3)
          Get the resultant type of selection expression (?
(パッケージプライベート)  Type getUacType(Type t1, Type t2)
          Get the resultant type of UAC (usual arithmetic converson).
(パッケージプライベート)  Exp iPromotion(Exp e)
          Integral promotion.
(パッケージプライベート)  Exp siPromotion(Exp e)
          Do signed integral promotion (used at unary -).
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

fDbgLevel

protected int fDbgLevel
コンストラクタの詳細

ToHirCast

ToHirCast(ToHir tohir)
メソッドの詳細

cast

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

パラメータ:
t1 - Ttarget type.
e2 - Expression.
戻り値:
Casted expression.

iPromotion

Exp iPromotion(Exp e)
Integral promotion.

パラメータ:
e - Expression.
戻り値:
Integral type expression.

siPromotion

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

パラメータ:
e - Expression.
戻り値:
Integral type expression.

daPromotion

Exp daPromotion(Exp e)
Default argument promotion

パラメータ:
e - Expression.
戻り値:
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).
 

パラメータ:
t1 - Left operand Type.
e2 - Right operand.
戻り値:
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.
 }
 

パラメータ:
t1 - Left operand type.
t2 - Right operand type.
戻り値:
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.
 

パラメータ:
t1 - Right operand type.
t2 - Left operand type.
戻り値:
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
 

パラメータ:
t2 - 2nd operand type.
t3 - 3rd operand type.
戻り値:
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)
 

パラメータ:
t1 - Type
t2 - Type
戻り値:
Rresultant type of address expression.