]> git.sur5r.net Git - cc65/blobdiff - src/cc65/datatype.h
Fixed two compiler warnings.
[cc65] / src / cc65 / datatype.h
index 84155f3050cdcf8b82655b6ce260442434afbde7..0fe46f6d2b0b781ed53a6424b6d350ad8bae888e 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2008 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (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       */
@@ -43,6 +43,7 @@
 /* common */
 #include "attrib.h"
 #include "inline.h"
+#include "mmodel.h"
 
 /* cc65 */
 #include "funcdesc.h"
@@ -109,7 +110,9 @@ enum {
     T_QUAL_FAR      = 0x008000,
     T_QUAL_ADDRSIZE = T_QUAL_NEAR | T_QUAL_FAR,
     T_QUAL_FASTCALL = 0x010000,
-    T_MASK_QUAL            = 0x01F800,
+    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,
@@ -164,14 +167,24 @@ struct Type {
 #define FLEXIBLE        0L      /* Flexible array struct member */
 
 /* Sizes. Floating point sizes come from fp.h */
-#define SIZEOF_CHAR     1
-#define SIZEOF_SHORT    2
-#define SIZEOF_INT      2
-#define SIZEOF_LONG     4
-#define SIZEOF_LONGLONG 8
+#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      2
+#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_schar[];
@@ -199,7 +212,7 @@ struct SymEntry;
 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* TypeDup (const Type* T);
@@ -287,7 +300,7 @@ Type* Indirect (Type* T);
  * given type points to.
  */
 
-Type* ArrayToPtr (const Type* T);
+Type* ArrayToPtr (Type* T);
 /* Convert an array to a pointer to it's first element */
 
 #if defined(HAVE_INLINE)
@@ -527,7 +540,7 @@ INLINE int IsQualConst (const Type* T)
     return (T->C & T_QUAL_CONST) != 0;
 }
 #else
-#  define IsQualConst(T)        ((T->C & T_QUAL_CONST) != 0)
+#  define IsQualConst(T)        (((T)->C & T_QUAL_CONST) != 0)
 #endif
 
 #if defined(HAVE_INLINE)
@@ -537,7 +550,7 @@ INLINE int IsQualVolatile (const Type* T)
     return (T->C & T_QUAL_VOLATILE) != 0;
 }
 #else
-#  define IsQualVolatile(T)     (T->C & T_QUAL_VOLATILE) != 0)
+#  define IsQualVolatile(T)     (((T)->C & T_QUAL_VOLATILE) != 0)
 #endif
 
 #if defined(HAVE_INLINE)
@@ -547,7 +560,7 @@ INLINE int IsQualRestrict (const Type* T)
     return (T->C & T_QUAL_RESTRICT) != 0;
 }
 #else
-#  define IsQualRestrict(T)     (T->C & T_QUAL_RESTRICT) != 0)
+#  define IsQualRestrict(T)     (((T)->C & T_QUAL_RESTRICT) != 0)
 #endif
 
 #if defined(HAVE_INLINE)
@@ -557,7 +570,7 @@ INLINE int IsQualNear (const Type* T)
     return (T->C & T_QUAL_NEAR) != 0;
 }
 #else
-#  define IsQualNear(T)         (T->C & T_QUAL_NEAR) != 0)
+#  define IsQualNear(T)         (((T)->C & T_QUAL_NEAR) != 0)
 #endif
 
 #if defined(HAVE_INLINE)
@@ -567,7 +580,7 @@ INLINE int IsQualFar (const Type* T)
     return (T->C & T_QUAL_FAR) != 0;
 }
 #else
-#  define IsQualFar(T)          (T->C & T_QUAL_FAR) != 0)
+#  define IsQualFar(T)          (((T)->C & T_QUAL_FAR) != 0)
 #endif
 
 #if defined(HAVE_INLINE)
@@ -577,7 +590,17 @@ INLINE int IsQualFastcall (const Type* T)
     return (T->C & T_QUAL_FASTCALL) != 0;
 }
 #else
-#  define IsQualFastcall(T)     (T->C & T_QUAL_FASTCALL) != 0)
+#  define IsQualFastcall(T)     (((T)->C & T_QUAL_FASTCALL) != 0)
+#endif
+
+#if defined(HAVE_INLINE)
+INLINE int IsQualCDecl (const Type* T)
+/* Return true if the given type has a cdecl qualifier */
+{
+    return (T->C & T_QUAL_CDECL) != 0;
+}
+#else
+#  define IsQualCDecl(T)        (((T)->C & T_QUAL_CDECL) != 0)
 #endif
 
 int IsVariadicFunc (const Type* T) attribute ((const));
@@ -634,11 +657,28 @@ Type* PtrConversion (Type* T);
  * return T.
  */
 
-TypeCode CodeAddrSizeQualifier (void);
+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
 
-TypeCode DataAddrSizeQualifier (void);
+#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