|
||||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
Type interface
Interface for Type class which specifies type information. Base type Following types are base types corresponding to abstract operations of the HIR model: bool boolean (false=0, true=1) s_char signed character short signed short integer int signed integer long signed long integer long_long signed long long integer char character wchar multi-byte character u_char unsigned character u_short unsigned short integer u_int unsigned integer u_long unsigned long integer u_long_long unsigned long long integer offset storage address offset, sizeof void void float floating point double floating point double long_double floating point long double string character string wstring multi-byte character string In some cases, int, long, long_long, u_short, u_int, u_long, u_long_long are called integer as whole. Defined type pointer pointer type vector vector type (array) struct structure type union union (overlaid) type enum enumeration type subp subprogram type region region type defined type defined by typedef A pointer type is defined by pointer indication (* in C) and the type of the target of the pointer. The value of pointer is integer value representing storage address. A vector type is derived from element type by specifying the type of vector element and the number of elements in the vector. A structure type is defined by specifying its elements that represent object different with each other. A union type is defined by specifying overlaid elements. A subprogram type is defined by specifying type of parameters and the type of return value. An enumeration type is defined by specifying enumeration literals representing some integer value. Defined types may be a renaming of base type or a compound type derived from base type or defined type. Type defining construct such as typedef in C introduces a new type name. Declaration typedef typeSpec typeName; gives a type name (typeName) to the type specification (typeSpec), where, let us say typeName can be reduced to typeSpec. If type1 can be reduced to type2 and type2 can be reduced to type3, then let us say type1 can be reduced to type3. Origin Type defining construct such as typedef typeSpec typeName; introduces a new type (typeName in this case) from type specification (typeSpec in this case). Let us say the type described in the specification part (typeSpec) as "origin" of the introduced type (typeName). Operations allowed on the origin can be performed on the introduced type, too. In Pascal, etc., a new type T1 can be introduced by delimiting the value range of a type T. In such case, T is called the origin of the intruduced type T1 in HIR. Let the origin of basic type be itself except for some cases that depend on input language specifications. (How to set the origin for base types is treated as source language parameter.) In C language, char can be treaed as int in arithmetic operations, and so, let int be the origin of char in HIR for C language. In C language, enumeration literals can be treaed as int constant, and so, let int be the origin of enumeration litrals in HIR for C language. The bool type also has int as its origin in HIR for C language. Type qualifiers such as const, volatile, restrict give variation of types. If type T2 is defined by qualifying a type T with const, volatile or restrict, then T2 is treated as a new type introduced from the origin T. In this case, the type qualified by const can not be used as the type of the first operand of assign operator, and operatons on expression having the type qualified by volatile can not be deleted in optimization. Type of operands and result Binary arithmetic operators, comparison operators, and bit-wise logical operators take the same type as their operands and result except for some special cases as listed below: Operator Operand 1 Operand 2 Result add pointer offset pointer add offset offset offset sub pointer offset pointer sub offset offset offset mult offset integer offset div offset integer offset div offset offset u_long index offset integer offset index offset integer integer Pointer is not permitted as operands of mult and div. More over, following combinations are not permitted (in HIR-base): add pointer pointer add pointer int add offset pointer add offset int add int pointer add int offset sub pointer pointer sub pointer int sub offset pointer sub offset int sub int pointer sub int offset mult offset offset mult int offset div int offset Type kind code KIND_UNDEF = 0, // Not yet defined but defined later. KIND_BOOL = 1, //## KIND_S_CHAR = 2, KIND_WCHAR = 2, //##51 KIND_SHORT = 3, KIND_INT = 4, KIND_LONG = 5, KIND_LONG_LONG = 6, KIND_CHAR = 7, KIND_UNSIGNED_LOWER_LIM = 8, // Unsigned type may not have // kind number less than this. KIND_U_CHAR = 8, KIND_U_SHORT = 9, KIND_U_INT = 10, KIND_U_LONG = 11, KIND_U_LONG_LONG = 12, KIND_INT_UPPER_LIM = 12, KIND_ADDRESS = 13, // Not used. POINTER is used. KIND_OFFSET = 14, KIND_VOID = 15, KIND_FLOAT_LOWER_LIM = 16, KIND_FLOAT = 16, KIND_DOUBLE = 17, KIND_LONG_DOUBLE = 18, KIND_FLOAT_UPPER_LIM = 19, KIND_STRING = 20, KIND_BASE_LIM = 20, // if (getTypeKind() <= KIND_BASE_LIM) // then it is a base type. KIND_ENUM = 21, KIND_POINTER = 22, KIND_VECTOR = 23, KIND_STRUCT = 24, KIND_UNION = 25, KIND_DEFINED = 26, KIND_SUBP = 27, KIND_REGION = 28; Type conversion between scalar types *** Operand x Result r Conversion operation ------- -------- -------------------- int char The character code of r is the value of x. enum The order number of r is the value of x. offset The value of r is the value of x. pointer The value of r is the value of x. (##25) char int The value of r is the character code of x. enum The order number of r is the character code of x. offset Same as (conv offset (conv int (x char))). enum int The value of r is the order number of x. enum The order number of r is the order number of x. offset Same as (conv offset (conv int (x Ts))). offset int The value of r is the value of x.. enum The order number of r is the value of x. pointer If the value of pointer is signed (##25) then the value of r is the value of x. If the value of pointer is unsigend (##25) then the value of r is signed-to-unsigned converted value of x. pointer int The value of r is the address represented by x. (##25) enum The order number of r is the value of x. (##25) offset If address is signed then the value of r is the value of x. If address is unsigend then the value of r is unsigned-to-signed converted value of x. pointer Address represented by r is the same to the address represented by x. Whether the internal representation of the objects pointed by x can be treated as an object pointed by r or not is programmer's responsibility. Type conversion rank indexed by type kind code. KIND_RANKS[] = { 0: undefined. // Operand with lower rank will be casted to higher rank if its // type differs from that of other operand of arithmetic operator. // The last bit of rank number is 1 if it can be treated as // integer ultimately. // undefined 0, // bool wchar short int long long_long //##51 11, 31, 31, 41, 51, 61, //##51 // char u_char u_short u_int u_long u_long_long 21, 25, 33, 43, 53, 63, // address offset void // 0, 41, 0, 0, 35, 0, // float double long_double float_lim string enum 70, 72, 74, 0, 0, 35, // pointer vector struct union defined subprog -10, 0, 0, 0, 0, 0 // region 0 }; } Alignment number indexed by type kind code. KIND_ALIGNMENT[] = { // indexed by type kind code. MachineParam.ALIGN_INT, // undefined // Not used. MachineParam.ALIGN_BOOL, // bool MachineParam.ALIGN_WCHAR, // wchar //##51 MachineParam.ALIGN_SHORT, // short MachineParam.ALIGN_INT, // int MachineParam.ALIGN_LONG, // long MachineParam.ALIGN_LONG_LONG, // long_long MachineParam.ALIGN_CHAR, // char MachineParam.ALIGN_CHAR, // u_char MachineParam.ALIGN_SHORT, // u_short MachineParam.ALIGN_INT, // u_int MachineParam.ALIGN_LONG, // u_long MachineParam.ALIGN_LONG_LONG, // u_long_long MachineParam.ALIGN_ADDRESS, // address // Not used MachineParam.ALIGN_OFFSET, // offset MachineParam.ALIGN_INT, // void // Not used. MachineParam.ALIGN_FLOAT, // float MachineParam.ALIGN_DOUBLE, // double MachineParam.ALIGN_LONG_DOUBLE,// long_double MachineParam.ALIGN_LONG_DOUBLE,// float upper lim MachineParam.ALIGN_CHAR, // string MachineParam.ALIGN_INT, // enum MachineParam.ALIGN_ADDRESS, // pointer MachineParam.ALIGN_INT, // vector // Not used. MachineParam.ALIGN_INT, // struct // Not used MachineParam.ALIGN_INT, // union // Not used MachineParam.ALIGN_INT, // defined// Not used. MachineParam.ALIGN_SUBP // subp }; Note about the size of type. There are 3 states in type size representation: State 1: fSizeExp==null fSizeValue<0 No information is given about Size value. State 2: fSizeExp!=null fSizeValue<0 Size is given as expression. Its size will be given at execution time. State 3: fSizeExp!=null fSizeValue>=0 Size value is given as constant expression or constant value. The size may be 0 in some case. In C language, we can deside if a type is incomplete or not by seeing whether getSizeExp()==null or not because types of C are statically defined. fSizeExp/fSizeValue are set by the methods setSizeExp/setSizeValue. The method setSizeValue will set not only fSizeValue but also set fSizeExp by making the expression representing the value. The method setSizeExp will set not only fSizeExp but also set fSizeValue by converting the expression into a value if the expression is a constant expression. If setSizeExp(null) or setSizeValue(-1) are given, the type state changes to state 1. If setSizeExp(non-constant expression) is given, the type state changes to state 2. If setSizeExp(constant expression) or setSizeValue(0 or plus value) is are given, the type state changes to state 3.
フィールドの概要 | |
static int |
KIND_ADDRESS
Type kind code |
static int[] |
KIND_ALIGNMENT
Alignment number indexed by type kind code. |
static int |
KIND_BASE_LIM
Type kind code |
static int |
KIND_BOOL
Type kind code |
static int |
KIND_CHAR
Type kind code |
static int |
KIND_DEFINED
Type kind code |
static int |
KIND_DOUBLE
Type kind code |
static int |
KIND_ENUM
Type kind code |
static int |
KIND_FLOAT
Type kind code |
static int |
KIND_FLOAT_LOWER_LIM
Type kind code |
static int |
KIND_FLOAT_UPPER_LIM
Type kind code |
static int |
KIND_INT
Type kind code |
static int |
KIND_INT_UPPER_LIM
Type kind code |
static int |
KIND_LONG
Type kind code |
static int |
KIND_LONG_DOUBLE
Type kind code |
static int |
KIND_LONG_LONG
Type kind code |
static int |
KIND_OFFSET
Type kind code |
static int |
KIND_POINTER
Type kind code |
static int[] |
KIND_RANKS
|
static int |
KIND_REGION
Type kind code |
static int |
KIND_SHORT
Type kind code |
static int |
KIND_STRING
Type kind code |
static int |
KIND_STRUCT
Type kind code |
static int |
KIND_SUBP
Type kind code |
static int |
KIND_U_CHAR
Type kind code |
static int |
KIND_U_INT
Type kind code |
static int |
KIND_U_LONG
Type kind code |
static int |
KIND_U_LONG_LONG
Type kind code |
static int |
KIND_U_SHORT
Type kind code |
static int |
KIND_UNDEF
Type kind code |
static int |
KIND_UNION
Type kind code |
static int |
KIND_UNSIGNED_LOWER_LIM
Type kind code |
static int |
KIND_VECTOR
Type kind code |
static int |
KIND_VOID
Type kind code |
static int |
KIND_WCHAR
Type kind code |
インタフェース coins.sym.Sym から継承したフィールド |
KIND_NAME, VISIBILITY |
メソッドの概要 | |
int |
getAlignment()
getAlignment Get alignment value for this type. |
int |
getAlignmentGap(long pPrecedingSize)
getAlignmentGap Get alignment gap size if cumulative size of preceeding elements is pPreceedingSize. |
Type |
getCompleteType()
getCompleteType Get complete type corresponding to this type. |
int |
getDimension()
getDimension Get the dimension of this type. |
IrList |
getElemList()
getElemList: Get the list of struct/union elements. |
java.lang.String |
getElemListString()
getElemListString Get element type list of struct, union type in String form. |
Type |
getFinalOrigin()
getFinalOrigin Trace the chain of origin types and return the origin as the last one of the chain. |
Type |
getOrigin()
getOrigin |
Type |
getPointedType()
getPointedType Get the type of pointed object for PointerType. |
Exp |
getSizeExp()
getSizeExp Get the expression representing the size of this type in bytes. |
long |
getSizeValue()
getSizeValue Get the size of this type in bytes. |
int |
getTypeKind()
getTypeKind Get the type kind code (Type.KIND_INT, KIND_FLOAT, KIND_POINTER, KIND_STRUCT, etc. defined in Type interface). |
int |
getTypeRank()
getTypeRank The type rank shows conversion rank. |
Type |
getUnqualifiedType()
Trace the chain of origin types and return unqualified type. |
boolean |
isBasicType()
isBasicType |
boolean |
isCompatibleWith(Type pType)
isCompatibleWith The origin type of this type and pType are compared to be equal or not. |
boolean |
isConst()
isConst |
boolean |
isFloating()
isUnsigned |
boolean |
isInteger()
isInteger |
boolean |
isRestrict()
isRestrict |
boolean |
isScalar()
|
boolean |
isSizeEvaluable()
isSizeEvaluable |
boolean |
isUnsigned()
isUnsigned |
boolean |
isVolatile()
isVolatile |
Type |
makeConstType()
makeConstType Make a new type qualifying this type by "const" and return it. |
Type |
makeRestrictType()
makeRestrictType Make a new type qualifying this type by "restrict" and return it. |
Type |
makeVolatileType()
makeVolatileType Make a new type qualifying this type by "volatile" and return it. |
void |
setOrigin(Type pOrigin)
setOrigin Set the origin type. |
void |
setSizeExp(Exp pSizeExp)
setSizeExp Set the size expression of this type. |
void |
setSizeValue(long pSizeValue)
setSizeValue Set the size of this type. |
インタフェース coins.sym.Sym0 から継承したメソッド |
charConst, definedType, defineElem, defineLabel, defineParam, defineSubp, defineVar, enumType, floatConst, getDefinedFile, getDefinedIn, getFlag, getName, getNextSym, getRecordedIn, getSymKind, getSymType, getUniqueName, intConst, isGlobal, namedConst, pointerType, setFlag, stringConst, structType, subpType, unionType, vectorType, vectorTypeUnfixed |
フィールドの詳細 |
public static final int KIND_UNDEF
public static final int KIND_BOOL
public static final int KIND_WCHAR
public static final int KIND_SHORT
public static final int KIND_INT
public static final int KIND_LONG
public static final int KIND_LONG_LONG
public static final int KIND_CHAR
public static final int KIND_UNSIGNED_LOWER_LIM
public static final int KIND_U_CHAR
public static final int KIND_U_SHORT
public static final int KIND_U_INT
public static final int KIND_U_LONG
public static final int KIND_U_LONG_LONG
public static final int KIND_INT_UPPER_LIM
public static final int KIND_ADDRESS
public static final int KIND_OFFSET
public static final int KIND_VOID
public static final int KIND_FLOAT_LOWER_LIM
public static final int KIND_FLOAT
public static final int KIND_DOUBLE
public static final int KIND_LONG_DOUBLE
public static final int KIND_FLOAT_UPPER_LIM
public static final int KIND_STRING
public static final int KIND_BASE_LIM
public static final int KIND_ENUM
public static final int KIND_POINTER
public static final int KIND_VECTOR
public static final int KIND_STRUCT
public static final int KIND_UNION
public static final int KIND_DEFINED
public static final int KIND_SUBP
public static final int KIND_REGION
public static final int[] KIND_RANKS
public static final int[] KIND_ALIGNMENT
メソッドの詳細 |
public int getTypeKind()
public Type getOrigin()
public Type getFinalOrigin()
public Type getUnqualifiedType()
public void setOrigin(Type pOrigin)
pOrigin
- origin type of this type.public boolean isBasicType()
public boolean isInteger()
public boolean isUnsigned()
public boolean isFloating()
public boolean isScalar()
public long getSizeValue()
public Exp getSizeExp()
public boolean isSizeEvaluable()
public void setSizeExp(Exp pSizeExp)
pSizeExp
- Size expression or null if the size is not yet defined.public void setSizeValue(long pSizeValue)
pSizeValue
- size of this type;public Type makeConstType()
public Type makeVolatileType()
public Type makeRestrictType()
public boolean isConst()
public boolean isVolatile()
public boolean isRestrict()
public int getTypeRank()
public int getDimension()
public IrList getElemList()
public Type getPointedType()
public java.lang.String getElemListString()
public int getAlignment()
public int getAlignmentGap(long pPrecedingSize)
public boolean isCompatibleWith(Type pType)
pType
- a type to be compared with this type.
public Type getCompleteType()
|
||||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |