C# Class ABT.TypeCast

Inheritance: Expr
Exibir arquivo Open project: phisiart/C-Compiler Class Usage Examples

Public Properties

Property Type Description
Expr Expr
Kind TypeCastType

Public Methods

Method Description
CGenAddress ( CGenState state ) : void
CGenValue ( CGenState state ) : System.Reg
EqualType ( ExprType t1, ExprType t2 ) : System.Boolean
FloatToArith ( Expr expr, ExprType type ) : Expr

From: float, double To: char, uchar, short, ushort, long, ulong, float, double

According to MSDN "Conversions from Floating-Point Types", float cannot convert to unsigned char. I don't know why, but I follow it.

FromPointer ( Expr expr, ExprType type, Env env ) : Expr

From: pointer To: pointer, integral

IntegralPromotion ( Expr expr ) : ExprTypeKind>.Tuple

All integrals are converted to LongType or ULongType.

MakeCast ( Expr expr, ExprType type ) : Expr
MakeCast ( Expr expr, ExprType type, Env env ) : Expr
SignedIntegralToArith ( Expr expr, ExprType type ) : Expr

From: char, short, long To: char, uchar, short, ushort, long, ulong, float double

ToPointer ( Expr expr, ExprType type, Env env ) : Expr

From: pointer, integral To: pointer

TypeCast ( TypeCastType kind, Expr expr, ExprType type ) : System
UnsignedIntegralToArith ( Expr expr, ExprType type ) : Expr

From: uchar, ushort, ulong To: char, uchar, short, ushort, long, ulong, float, double

Aaccording to MSDN "Conversions from Unsigned Integral Types", unsigned long converts directly to double. However, I just treat unsigned long as long.

UsualArithmeticConversion ( Expr e1, Expr e2 ) : Tuple

Perform the usual arithmetic conversion on two expressions.

If either expression is DoubleType, then both are converted to DoubleType.

Else, if either expression is FloatType, then both are converted to FloatType.

Else, if either expression is ULongType, then both are converted to ULongType.

Else, both are converted to LongType.

UsualScalarConversion ( Expr e1, Expr e2 ) : Tuple

First, convert pointers to ULongType's, then do UsualArithmeticConversion.

Private Methods

Method Description
TypeCast ( TypeCastType kind, Expr expr, ExprType type, Env env ) : System

Method Details

CGenAddress() public method

public CGenAddress ( CGenState state ) : void
state CodeGeneration.CGenState
return void

CGenValue() public method

public CGenValue ( CGenState state ) : System.Reg
state CodeGeneration.CGenState
return System.Reg

EqualType() public static method

public static EqualType ( ExprType t1, ExprType t2 ) : System.Boolean
t1 ExprType
t2 ExprType
return System.Boolean

FloatToArith() public static method

From: float, double To: char, uchar, short, ushort, long, ulong, float, double
According to MSDN "Conversions from Floating-Point Types", float cannot convert to unsigned char. I don't know why, but I follow it.
public static FloatToArith ( Expr expr, ExprType type ) : Expr
expr Expr
type ExprType
return Expr

FromPointer() public static method

From: pointer To: pointer, integral
public static FromPointer ( Expr expr, ExprType type, Env env ) : Expr
expr Expr
type ExprType
env Env
return Expr

IntegralPromotion() public static method

All integrals are converted to LongType or ULongType.
public static IntegralPromotion ( Expr expr ) : ExprTypeKind>.Tuple
expr Expr /// The integral expression to be casted. ///
return ExprTypeKind>.Tuple

MakeCast() public static method

public static MakeCast ( Expr expr, ExprType type ) : Expr
expr Expr
type ExprType
return Expr

MakeCast() public static method

public static MakeCast ( Expr expr, ExprType type, Env env ) : Expr
expr Expr
type ExprType
env Env
return Expr

SignedIntegralToArith() public static method

From: char, short, long To: char, uchar, short, ushort, long, ulong, float double
public static SignedIntegralToArith ( Expr expr, ExprType type ) : Expr
expr Expr
type ExprType
return Expr

ToPointer() public static method

From: pointer, integral To: pointer
public static ToPointer ( Expr expr, ExprType type, Env env ) : Expr
expr Expr
type ExprType
env Env
return Expr

TypeCast() public method

public TypeCast ( TypeCastType kind, Expr expr, ExprType type ) : System
kind TypeCastType
expr Expr
type ExprType
return System

UnsignedIntegralToArith() public static method

From: uchar, ushort, ulong To: char, uchar, short, ushort, long, ulong, float, double
Aaccording to MSDN "Conversions from Unsigned Integral Types", unsigned long converts directly to double. However, I just treat unsigned long as long.
public static UnsignedIntegralToArith ( Expr expr, ExprType type ) : Expr
expr Expr
type ExprType
return Expr

UsualArithmeticConversion() public static method

Perform the usual arithmetic conversion on two expressions.

If either expression is DoubleType, then both are converted to DoubleType.

Else, if either expression is FloatType, then both are converted to FloatType.

Else, if either expression is ULongType, then both are converted to ULongType.

Else, both are converted to LongType.

public static UsualArithmeticConversion ( Expr e1, Expr e2 ) : Tuple
e1 Expr The first expression to be casted. Must have .
e2 Expr The second expression to be casted. Must have .
return Tuple

UsualScalarConversion() public static method

First, convert pointers to ULongType's, then do UsualArithmeticConversion.
public static UsualScalarConversion ( Expr e1, Expr e2 ) : Tuple
e1 Expr /// The first expression to be casted. ///
e2 Expr /// The second expression to be casted. ///
return Tuple

Property Details

Expr public_oe property

public Expr,ABT Expr
return Expr

Kind public_oe property

public TypeCastType Kind
return TypeCastType