X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fdatatype.h;h=0fe46f6d2b0b781ed53a6424b6d350ad8bae888e;hb=05f72963695f843cca3fd3dac1be0175b470b179;hp=75892f0f11e6f210d48c7922cd6171691c0235da;hpb=c6abc5d9d4bbb48f91c12f34fcf67ff4380d185c;p=cc65 diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 75892f0f1..0fe46f6d2 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2002 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -42,6 +42,8 @@ /* common */ #include "attrib.h" +#include "inline.h" +#include "mmodel.h" /* cc65 */ #include "funcdesc.h" @@ -57,53 +59,60 @@ /* Basic data types */ enum { - T_END = 0x0000, + T_END = 0x000000, /* Basic types */ - T_TYPE_NONE = 0x0000, - T_TYPE_CHAR = 0x0001, - T_TYPE_SHORT = 0x0002, - T_TYPE_INT = 0x0003, - T_TYPE_LONG = 0x0004, - T_TYPE_LONGLONG = 0x0005, - T_TYPE_ENUM = 0x0006, - T_TYPE_FLOAT = 0x0007, - T_TYPE_DOUBLE = 0x0008, - T_TYPE_VOID = 0x0009, - T_TYPE_STRUCT = 0x000A, - T_TYPE_UNION = 0x000B, - T_TYPE_ARRAY = 0x000C, - T_TYPE_PTR = 0x000D, - T_TYPE_FUNC = 0x000E, - T_MASK_TYPE = 0x001F, + T_TYPE_NONE = 0x000000, + T_TYPE_CHAR = 0x000001, + T_TYPE_SHORT = 0x000002, + T_TYPE_INT = 0x000003, + T_TYPE_LONG = 0x000004, + T_TYPE_LONGLONG = 0x000005, + T_TYPE_ENUM = 0x000006, + T_TYPE_FLOAT = 0x000007, + T_TYPE_DOUBLE = 0x000008, + T_TYPE_VOID = 0x000009, + T_TYPE_STRUCT = 0x00000A, + T_TYPE_UNION = 0x00000B, + T_TYPE_ARRAY = 0x00000C, + T_TYPE_PTR = 0x00000D, + T_TYPE_FUNC = 0x00000E, + T_MASK_TYPE = 0x00000F, /* Type classes */ - T_CLASS_NONE = 0x0000, - T_CLASS_INT = 0x0020, - T_CLASS_FLOAT = 0x0040, - T_CLASS_PTR = 0x0060, - T_CLASS_STRUCT = 0x0080, - T_CLASS_FUNC = 0x00A0, - T_MASK_CLASS = 0x00E0, + T_CLASS_NONE = 0x000000, + T_CLASS_INT = 0x000010, + T_CLASS_FLOAT = 0x000020, + T_CLASS_PTR = 0x000030, + T_CLASS_STRUCT = 0x000040, + T_CLASS_FUNC = 0x000050, + T_MASK_CLASS = 0x000070, /* Type signedness */ - T_SIGN_NONE = 0x0000, - T_SIGN_UNSIGNED = 0x0100, - T_SIGN_SIGNED = 0x0200, - T_MASK_SIGN = 0x0300, + T_SIGN_NONE = 0x000000, + T_SIGN_UNSIGNED = 0x000080, + T_SIGN_SIGNED = 0x000100, + T_MASK_SIGN = 0x000180, /* Type size modifiers */ - T_SIZE_NONE = 0x0000, - T_SIZE_SHORT = 0x0400, - T_SIZE_LONG = 0x0800, - T_SIZE_LONGLONG = 0x0C00, - T_MASK_SIZE = 0x0C00, + T_SIZE_NONE = 0x000000, + T_SIZE_SHORT = 0x000200, + T_SIZE_LONG = 0x000400, + T_SIZE_LONGLONG = 0x000600, + T_MASK_SIZE = 0x000600, /* Type qualifiers */ - T_QUAL_NONE = 0x0000, - T_QUAL_CONST = 0x1000, - T_QUAL_VOLATILE = 0x2000, - T_MASK_QUAL = 0x3000, + T_QUAL_NONE = 0x000000, + T_QUAL_CONST = 0x000800, + T_QUAL_VOLATILE = 0x001000, + T_QUAL_RESTRICT = 0x002000, + T_QUAL_NEAR = 0x004000, + T_QUAL_FAR = 0x008000, + T_QUAL_ADDRSIZE = T_QUAL_NEAR | T_QUAL_FAR, + T_QUAL_FASTCALL = 0x010000, + T_QUAL_CDECL = 0x020000, + T_QUAL_CCONV = T_QUAL_FASTCALL | T_QUAL_CDECL, + T_MASK_QUAL = 0x03F800, /* Types */ T_CHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE, @@ -127,40 +136,70 @@ enum { T_PTR = T_TYPE_PTR | T_CLASS_PTR | T_SIGN_NONE | T_SIZE_NONE, T_FUNC = T_TYPE_FUNC | T_CLASS_FUNC | T_SIGN_NONE | T_SIZE_NONE, + /* Aliases */ + T_SIZE_T = T_UINT, }; -/* Forward for a symbol entry */ -struct SymEntry; +/* Type code entry */ +typedef unsigned long TypeCode; /* Type entry */ -typedef unsigned short type; +typedef struct Type Type; +struct Type { + TypeCode C; /* Code for this entry */ + union { + void* P; /* Arbitrary attribute pointer */ + long L; /* Numeric attribute value */ + unsigned long U; /* Dito, unsigned */ + } A; /* Type attribute if necessary */ +}; + +/* A macro that expands to a full initializer for struct Type */ +#define TYPE(T) { (T), { 0 } } /* Maximum length of a type string */ #define MAXTYPELEN 30 -/* Type elements needed for Encode/Decode */ -#define DECODE_SIZE 5 - -/* Sizes */ -#define SIZEOF_CHAR 1 -#define SIZEOF_SHORT 2 -#define SIZEOF_INT 2 -#define SIZEOF_LONG 4 -#define SIZEOF_LONGLONG 8 -#define SIZEOF_FLOAT 4 -#define SIZEOF_DOUBLE 4 -#define SIZEOF_PTR 2 +/* Special encodings for element counts of an array */ +#define UNSPECIFIED -1L /* Element count was not specified */ +#define FLEXIBLE 0L /* Flexible array struct member */ + +/* Sizes. Floating point sizes come from fp.h */ +#define SIZEOF_CHAR 1U +#define SIZEOF_SHORT 2U +#define SIZEOF_INT 2U +#define SIZEOF_LONG 4U +#define SIZEOF_LONGLONG 8U +#define SIZEOF_FLOAT (FP_F_Size()) +#define SIZEOF_DOUBLE (FP_D_Size()) +#define SIZEOF_PTR SIZEOF_INT + +/* Bit sizes */ +#define CHAR_BITS (8 * SIZEOF_CHAR) +#define SHORT_BITS (8 * SIZEOF_SHORT) +#define INT_BITS (8 * SIZEOF_INT) +#define LONG_BITS (8 * SIZEOF_LONG) +#define LONGLONG_BITS (8 * SIZEOF_LONGLONG) +#define FLOAT_BITS (8 * SIZEOF_FLOAT) +#define DOUBLE_BITS (8 * SIZEOF_DOUBLE) +#define PTR_BITS (8 * SIZEOF_PTR) /* Predefined type strings */ -extern type type_uchar []; -extern type type_int []; -extern type type_uint []; -extern type type_long []; -extern type type_ulong []; -extern type type_void []; -extern type type_size_t []; +extern Type type_schar[]; +extern Type type_uchar[]; +extern Type type_int[]; +extern Type type_uint[]; +extern Type type_long[]; +extern Type type_ulong[]; +extern Type type_void[]; +extern Type type_size_t[]; +extern Type type_float[]; +extern Type type_double[]; + +/* Forward for the SymEntry struct */ +struct SymEntry; @@ -170,73 +209,65 @@ extern type type_size_t []; -unsigned TypeLen (const type* Type); +unsigned TypeLen (const Type* T); /* Return the length of the type string */ -type* TypeCpy (type* Dest, const type* Src); +Type* TypeCopy (Type* Dest, const Type* Src); /* Copy a type string */ -type* TypeCat (type* Dest, const type* Src); -/* Append Src */ - -type* TypeDup (const type* Type); +Type* TypeDup (const Type* T); /* Create a copy of the given type on the heap */ -type* TypeAlloc (unsigned Len); +Type* TypeAlloc (unsigned Len); /* Allocate memory for a type string of length Len. Len *must* include the * trailing T_END. */ -void TypeFree (type* Type); +void TypeFree (Type* T); /* Free a type string */ int SignExtendChar (int C); /* Do correct sign extension of a character */ -type GetDefaultChar (void); +TypeCode GetDefaultChar (void); /* Return the default char type (signed/unsigned) depending on the settings */ -type* GetCharArrayType (unsigned Len); +Type* GetCharArrayType (unsigned Len); /* Return the type for a char array of the given length */ -type* GetImplicitFuncType (void); +Type* GetImplicitFuncType (void); /* Return a type string for an inplicitly declared function */ -type* PointerTo (const type* T); +Type* PointerTo (const Type* T); /* Return a type string that is "pointer to T". The type string is allocated * on the heap and may be freed after use. */ -void PrintType (FILE* F, const type* Type); +void PrintType (FILE* F, const Type* T); /* Output translation of type array. */ -void PrintRawType (FILE* F, const type* Type); +void PrintRawType (FILE* F, const Type* T); /* Print a type string in raw format (for debugging) */ -void PrintFuncSig (FILE* F, const char* Name, type* Type); +void PrintFuncSig (FILE* F, const char* Name, Type* T); /* Print a function signature. */ -void Encode (type* Type, unsigned long Val); -/* Encode an unsigned long into a type array */ - -void EncodePtr (type* Type, void* P); -/* Encode a pointer into a type array */ - -unsigned long Decode (const type* Type); -/* Decode an unsigned long from a type array */ - -void* DecodePtr (const type* Type); -/* Decode a pointer from a type array */ +int TypeHasAttr (const Type* T); +/* Return true if the given type has attribute data */ -int HasEncode (const type* Type); -/* Return true if the given type has encoded data */ - -void CopyEncode (const type* Source, type* Target); -/* Copy encoded data from Source to Target */ +#if defined(HAVE_INLINE) +INLINE void CopyTypeAttr (const Type* Src, Type* Dest) +/* Copy attribute data from Src to Dest */ +{ + Dest->A = Src->A; +} +#else +# define CopyTypeAttr(Src, Dest) ((Dest)->A = (Src)->A) +#endif #if defined(HAVE_INLINE) -INLINE type UnqualifiedType (type T) -/* Return the unqalified type */ +INLINE TypeCode UnqualifiedType (TypeCode T) +/* Return the unqalified type code */ { return (T & ~T_MASK_QUAL); } @@ -244,232 +275,411 @@ INLINE type UnqualifiedType (type T) # define UnqualifiedType(T) ((T) & ~T_MASK_QUAL) #endif -unsigned SizeOf (const type* Type); +unsigned SizeOf (const Type* T); /* Compute size of object represented by type array. */ -unsigned PSizeOf (const type* Type); +unsigned PSizeOf (const Type* T); /* Compute size of pointer object. */ -unsigned CheckedSizeOf (const type* T); +unsigned CheckedSizeOf (const Type* T); /* Return the size of a data type. If the size is zero, emit an error and * return some valid size instead (so the rest of the compiler doesn't have * to work with invalid sizes). */ -unsigned CheckedPSizeOf (const type* T); +unsigned CheckedPSizeOf (const Type* T); /* Return the size of a data type that is pointed to by a pointer. If the * size is zero, emit an error and return some valid size instead (so the * rest of the compiler doesn't have to work with invalid sizes). */ -unsigned TypeOf (const type* Type); +unsigned TypeOf (const Type* T); /* Get the code generator base type of the object */ -type* Indirect (type* Type); +Type* Indirect (Type* T); /* Do one indirection for the given type, that is, return the type where the * given type points to. */ +Type* ArrayToPtr (Type* T); +/* Convert an array to a pointer to it's first element */ + #if defined(HAVE_INLINE) -INLINE int IsTypeChar (const type* T) +INLINE TypeCode GetType (const Type* T) +/* Get the raw type */ +{ + return (T->C & T_MASK_TYPE); +} +#else +# define GetType(T) ((T)->C & T_MASK_TYPE) +#endif + +#if defined(HAVE_INLINE) +INLINE int IsTypeChar (const Type* T) /* Return true if this is a character type */ { - return (T[0] & T_MASK_TYPE) == T_TYPE_CHAR; + return (GetType (T) == T_TYPE_CHAR); } #else -# define IsTypeChar(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_CHAR) +# define IsTypeChar(T) (GetType (T) == T_TYPE_CHAR) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeInt (const type* T) +INLINE int IsTypeInt (const Type* T) /* Return true if this is an int type (signed or unsigned) */ { - return (T[0] & T_MASK_TYPE) == T_TYPE_INT; + return (GetType (T) == T_TYPE_INT); } #else -# define IsTypeInt(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_INT) +# define IsTypeInt(T) (GetType (T) == T_TYPE_INT) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeLong (const type* T) +INLINE int IsTypeLong (const Type* T) /* Return true if this is a long type (signed or unsigned) */ { - return (T[0] & T_MASK_TYPE) == T_TYPE_LONG; + return (GetType (T) == T_TYPE_LONG); } #else -# define IsTypeLong(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_LONG) +# define IsTypeLong(T) (GetType (T) == T_TYPE_LONG) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeFloat (const type* T) +INLINE int IsTypeFloat (const Type* T) /* Return true if this is a float type */ { - return (T[0] & T_MASK_TYPE) == T_TYPE_FLOAT; + return (GetType (T) == T_TYPE_FLOAT); } #else -# define IsTypeFloat(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_FLOAT) +# define IsTypeFloat(T) (GetType (T) == T_TYPE_FLOAT) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeDouble (const type* T) +INLINE int IsTypeDouble (const Type* T) /* Return true if this is a double type */ { - return (T[0] & T_MASK_TYPE) == T_TYPE_DOUBLE; + return (GetType (T) == T_TYPE_DOUBLE); } #else -# define IsTypeDouble(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_DOUBLE) +# define IsTypeDouble(T) (GetType (T) == T_TYPE_DOUBLE) #endif #if defined(HAVE_INLINE) -INLINE int IsTypePtr (const type* T) +INLINE int IsTypePtr (const Type* T) /* Return true if this is a pointer type */ { - return ((T[0] & T_MASK_TYPE) == T_TYPE_PTR); + return (GetType (T) == T_TYPE_PTR); } #else -# define IsTypePtr(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_PTR) +# define IsTypePtr(T) (GetType (T) == T_TYPE_PTR) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeStruct (const type* T) +INLINE int IsTypeStruct (const Type* T) /* Return true if this is a struct type */ { - return ((T[0] & T_MASK_TYPE) == T_TYPE_STRUCT); + return (GetType (T) == T_TYPE_STRUCT); } #else -# define IsTypeStruct(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_STRUCT) +# define IsTypeStruct(T) (GetType (T) == T_TYPE_STRUCT) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeUnion (const type* T) +INLINE int IsTypeUnion (const Type* T) /* Return true if this is a union type */ { - return ((T[0] & T_MASK_TYPE) == T_TYPE_UNION); + return (GetType (T) == T_TYPE_UNION); } #else -# define IsTypeUnion(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_UNION) +# define IsTypeUnion(T) (GetType (T) == T_TYPE_UNION) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeArray (const type* T) +INLINE int IsTypeArray (const Type* T) /* Return true if this is an array type */ { - return ((T[0] & T_MASK_TYPE) == T_TYPE_ARRAY); + return (GetType (T) == T_TYPE_ARRAY); } #else -# define IsTypeArray(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_ARRAY) +# define IsTypeArray(T) (GetType (T) == T_TYPE_ARRAY) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeVoid (const type* T) +INLINE int IsTypeVoid (const Type* T) /* Return true if this is a void type */ { - return (T[0] & T_MASK_TYPE) == T_TYPE_VOID; + return (GetType (T) == T_TYPE_VOID); } #else -# define IsTypeVoid(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_VOID) +# define IsTypeVoid(T) (GetType (T) == T_TYPE_VOID) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeFunc (const type* T) +INLINE int IsTypeFunc (const Type* T) /* Return true if this is a function class */ { - return ((T[0] & T_MASK_TYPE) == T_TYPE_FUNC); + return (GetType (T) == T_TYPE_FUNC); } #else -# define IsTypeFunc(T) (((T)[0] & T_MASK_TYPE) == T_TYPE_FUNC) +# define IsTypeFunc(T) (GetType (T) == T_TYPE_FUNC) #endif #if defined(HAVE_INLINE) -INLINE int IsTypeFuncPtr (const type* T) +INLINE int IsTypeFuncPtr (const Type* T) /* Return true if this is a function pointer */ { - return ((T[0] & T_MASK_TYPE) == T_TYPE_PTR && (T[1] & T_MASK_TYPE) == T_TYPE_FUNC); + return (IsTypePtr (T) && IsTypeFunc (T+1)); } #else -# define IsTypeFuncPtr(T) \ - ((((T)[0] & T_MASK_TYPE) == T_TYPE_PTR) && (((T)[1] & T_MASK_TYPE) == T_TYPE_FUNC)) +# define IsTypeFuncPtr(T) (IsTypePtr (T) && IsTypeFunc (T+1)) #endif -int IsClassInt (const type* Type) attribute ((const)); +#if defined(HAVE_INLINE) +INLINE TypeCode GetClass (const Type* T) +/* Get the class of a type string */ +{ + return (T->C & T_MASK_CLASS); +} +#else +# define GetClass(T) ((T)->C & T_MASK_CLASS) +#endif + +#if defined(HAVE_INLINE) +INLINE int IsClassInt (const Type* T) /* Return true if this is an integer type */ +{ + return (GetClass (T) == T_CLASS_INT); +} +#else +# define IsClassInt(T) (GetClass (T) == T_CLASS_INT) +#endif -int IsClassFloat (const type* Type) attribute ((const)); +#if defined(HAVE_INLINE) +INLINE int IsClassFloat (const Type* T) /* Return true if this is a float type */ +{ + return (GetClass (T) == T_CLASS_FLOAT); +} +#else +# define IsClassFloat(T) (GetClass (T) == T_CLASS_FLOAT) +#endif -int IsClassPtr (const type* Type) attribute ((const)); +#if defined(HAVE_INLINE) +INLINE int IsClassPtr (const Type* T) /* Return true if this is a pointer type */ +{ + return (GetClass (T) == T_CLASS_PTR); +} +#else +# define IsClassPtr(T) (GetClass (T) == T_CLASS_PTR) +#endif -int IsClassStruct (const type* Type) attribute ((const)); +#if defined(HAVE_INLINE) +INLINE int IsClassStruct (const Type* T) /* Return true if this is a struct type */ +{ + return (GetClass (T) == T_CLASS_STRUCT); +} +#else +# define IsClassStruct(T) (GetClass (T) == T_CLASS_STRUCT) +#endif -int IsSignUnsigned (const type* Type) attribute ((const)); +#if defined(HAVE_INLINE) +INLINE int IsClassFunc (const Type* T) +/* Return true if this is a function type */ +{ + return (GetClass (T) == T_CLASS_FUNC); +} +#else +# define IsClassFunc(T) (GetClass (T) == T_CLASS_FUNC) +#endif + +#if defined(HAVE_INLINE) +INLINE TypeCode GetSignedness (const Type* T) +/* Get the sign of a type */ +{ + return (T->C & T_MASK_SIGN); +} +#else +# define GetSignedness(T) ((T)->C & T_MASK_SIGN) +#endif + +#if defined(HAVE_INLINE) +INLINE int IsSignUnsigned (const Type* T) /* Return true if this is an unsigned type */ +{ + return (GetSignedness (T) == T_SIGN_UNSIGNED); +} +#else +# define IsSignUnsigned(T) (GetSignedness (T) == T_SIGN_UNSIGNED) +#endif -int IsQualConst (const type* T) attribute ((const)); +#if defined(HAVE_INLINE) +INLINE int IsSignSigned (const Type* T) +/* Return true if this is a signed type */ +{ + return (GetSignedness (T) == T_SIGN_SIGNED); +} +#else +# define IsSignSigned(T) (GetSignedness (T) == T_SIGN_SIGNED) +#endif + +#if defined(HAVE_INLINE) +INLINE TypeCode GetQualifier (const Type* T) +/* Get the qualifier from the given type string */ +{ + return (T->C & T_MASK_QUAL); +} +#else +# define GetQualifier(T) ((T)->C & T_MASK_QUAL) +#endif + +#if defined(HAVE_INLINE) +INLINE int IsQualConst (const Type* T) /* Return true if the given type has a const memory image */ +{ + return (T->C & T_QUAL_CONST) != 0; +} +#else +# define IsQualConst(T) (((T)->C & T_QUAL_CONST) != 0) +#endif -int IsQualVolatile (const type* T) attribute ((const)); +#if defined(HAVE_INLINE) +INLINE int IsQualVolatile (const Type* T) /* Return true if the given type has a volatile type qualifier */ +{ + return (T->C & T_QUAL_VOLATILE) != 0; +} +#else +# define IsQualVolatile(T) (((T)->C & T_QUAL_VOLATILE) != 0) +#endif -int IsFastCallFunc (const type* T) attribute ((const)); -/* Return true if this is a function type or pointer to function with - * __fastcall__ calling conventions - */ +#if defined(HAVE_INLINE) +INLINE int IsQualRestrict (const Type* T) +/* Return true if the given type has a restrict qualifier */ +{ + return (T->C & T_QUAL_RESTRICT) != 0; +} +#else +# define IsQualRestrict(T) (((T)->C & T_QUAL_RESTRICT) != 0) +#endif -int IsVariadicFunc (const type* T) attribute ((const)); -/* Return true if this is a function type or pointer to function type with - * variable parameter list - */ +#if defined(HAVE_INLINE) +INLINE int IsQualNear (const Type* T) +/* Return true if the given type has a near qualifier */ +{ + return (T->C & T_QUAL_NEAR) != 0; +} +#else +# define IsQualNear(T) (((T)->C & T_QUAL_NEAR) != 0) +#endif #if defined(HAVE_INLINE) -INLINE type GetType (const type* T) -/* Get the raw type */ +INLINE int IsQualFar (const Type* T) +/* Return true if the given type has a far qualifier */ { - return (T[0] & T_MASK_TYPE); + return (T->C & T_QUAL_FAR) != 0; } #else -# define GetType(T) ((T)[0] & T_MASK_TYPE) +# define IsQualFar(T) (((T)->C & T_QUAL_FAR) != 0) #endif #if defined(HAVE_INLINE) -INLINE type GetClass (const type* T) -/* Get the class of a type string */ +INLINE int IsQualFastcall (const Type* T) +/* Return true if the given type has a fastcall qualifier */ { - return (T[0] & T_MASK_CLASS); + return (T->C & T_QUAL_FASTCALL) != 0; } #else -# define GetClass(T) ((T)[0] & T_MASK_CLASS) +# define IsQualFastcall(T) (((T)->C & T_QUAL_FASTCALL) != 0) #endif #if defined(HAVE_INLINE) -INLINE type GetSignedness (const type* T) -/* Get the sign of a type */ +INLINE int IsQualCDecl (const Type* T) +/* Return true if the given type has a cdecl qualifier */ { - return (T[0] & T_MASK_SIGN); + return (T->C & T_QUAL_CDECL) != 0; } #else -# define GetSignedness(T) ((T)[0] & T_MASK_SIGN) +# define IsQualCDecl(T) (((T)->C & T_QUAL_CDECL) != 0) #endif +int IsVariadicFunc (const Type* T) attribute ((const)); +/* Return true if this is a function type or pointer to function type with + * variable parameter list + */ + #if defined(HAVE_INLINE) -INLINE type GetSizeModifier (const type* T) +INLINE TypeCode GetSizeModifier (const Type* T) /* Get the size modifier of a type */ { - return (T[0] & T_MASK_SIZE); + return (T->C & T_MASK_SIZE); } #else -# define GetSizeModifier(T) ((T)[0] & T_MASK_SIZE) +# define GetSizeModifier(T) ((T)->C & T_MASK_SIZE) #endif -type GetQualifier (const type* T) attribute ((const)); -/* Get the qualifier from the given type string */ - -FuncDesc* GetFuncDesc (const type* T) attribute ((const)); +FuncDesc* GetFuncDesc (const Type* T) attribute ((const)); /* Get the FuncDesc pointer from a function or pointer-to-function type */ -type* GetFuncReturn (type* T) attribute ((const)); +void SetFuncDesc (Type* T, FuncDesc* F); +/* Set the FuncDesc pointer in a function or pointer-to-function type */ + +Type* GetFuncReturn (Type* T) attribute ((const)); /* Return a pointer to the return type of a function or pointer-to-function type */ +long GetElementCount (const Type* T); +/* Get the element count of the array specified in T (which must be of + * array type). + */ + +void SetElementCount (Type* T, long Count); +/* Set the element count of the array specified in T (which must be of + * array type). + */ + +Type* GetElementType (Type* T); +/* Return the element type of the given array type. */ + +struct SymEntry* GetSymEntry (const Type* T) attribute ((const)); +/* Return a SymEntry pointer from a type */ + +void SetSymEntry (Type* T, struct SymEntry* S); +/* Set the SymEntry pointer for a type */ + +Type* IntPromotion (Type* T); +/* Apply the integer promotions to T and return the result. The returned type + * string may be T if there is no need to change it. + */ + +Type* PtrConversion (Type* T); +/* If the type is a function, convert it to pointer to function. If the + * expression is an array, convert it to pointer to first element. Otherwise + * return T. + */ + +TypeCode AddrSizeQualifier (unsigned AddrSize); +/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */ + +#if defined(HAVE_INLINE) +INLINE TypeCode CodeAddrSizeQualifier (void) +/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the code address size */ +{ + return AddrSizeQualifier (CodeAddrSize); +} +#else +# define CodeAddrSizeQualifier() (AddrSizeQualifier (CodeAddrSize)) +#endif + +#if defined(HAVE_INLINE) +INLINE TypeCode DataAddrSizeQualifier (void) +/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the data address size */ +{ + return AddrSizeQualifier (DataAddrSize); +} +#else +# define DataAddrSizeQualifier() (AddrSizeQualifier (DataAddrSize)) +#endif + /* End of datatype.h */