]> git.sur5r.net Git - cc65/blobdiff - src/cc65/datatype.h
Working on the new backend
[cc65] / src / cc65 / datatype.h
index a9838c642797a5da26a37c42633dde72d1b73b4f..b561da26f0bd60fc615934d5ffd13bf960551ea4 100644 (file)
 
 #include <stdio.h>
 
+/* common */
+#include "attrib.h"
+
+/* cc65 */
+#include "funcdesc.h"
+
 
 
 /*****************************************************************************/
 
 
 
-// Basic data types
-enum type_t {
-    T_NONE                 = 0x0000,
+/* Basic data types */
+enum {
+    T_END          = 0x0000,
 
-    // Basic types
+    /* Basic types */
     T_TYPE_NONE            = 0x0000,
     T_TYPE_CHAR            = 0x0001,
-    T_TYPE_INT             = 0x0002,
-    T_TYPE_ENUM            = 0x0003,
-    T_TYPE_FLOAT    = 0x0004,
-    T_TYPE_DOUBLE   = 0x0005,
-    T_TYPE_VOID     = 0x0006,
-    T_TYPE_STRUCT   = 0x0007,
-    T_TYPE_UNION    = 0x0008,
-    T_TYPE_ARRAY    = 0x0009,
-    T_TYPE_PTR      = 0x000A,
-    T_TYPE_FUNC     = 0x000B,
+    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,
 
-    // Type classes
+    /* Type classes */
     T_CLASS_NONE    = 0x0000,
     T_CLASS_INT            = 0x0020,
     T_CLASS_FLOAT   = 0x0040,
@@ -77,81 +86,51 @@ enum type_t {
     T_CLASS_FUNC    = 0x00A0,
     T_MASK_CLASS    = 0x00E0,
 
-    // Type signedness
+    /* Type signedness */
     T_SIGN_NONE            = 0x0000,
     T_SIGN_UNSIGNED = 0x0100,
     T_SIGN_SIGNED   = 0x0200,
     T_MASK_SIGN     = 0x0300,
 
-    // Type size modifiers
+    /* Type size modifiers */
     T_SIZE_NONE            = 0x0000,
     T_SIZE_SHORT    = 0x0400,
     T_SIZE_LONG     = 0x0800,
     T_SIZE_LONGLONG = 0x0C00,
     T_MASK_SIZE            = 0x0C00,
 
-    // Type qualifiers
+    /* Type qualifiers */
     T_QUAL_NONE     = 0x0000,
     T_QUAL_CONST    = 0x1000,
     T_QUAL_VOLATILE = 0x2000,
     T_MASK_QUAL            = 0x3000,
 
-    // Types
-    T_CHAR                 = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
-    T_SCHAR        = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
-    T_UCHAR        = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
-    T_SHORT        = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_SHORT,
-    T_USHORT        = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_SHORT,
-    T_INT          = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
-    T_UINT         = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
-    T_LONG         = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_LONG,
-    T_ULONG        = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_LONG,
-    T_LONGLONG             = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_LONGLONG,
-    T_ULONGLONG            = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_LONGLONG,
-    T_ENUM         = T_TYPE_ENUM     | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
-    T_FLOAT        = T_TYPE_FLOAT    | T_CLASS_FLOAT  | T_SIGN_NONE     | T_SIZE_NONE,
-    T_DOUBLE       = T_TYPE_DOUBLE   | T_CLASS_FLOAT  | T_SIGN_NONE     | T_SIZE_NONE,
-    T_VOID         = T_TYPE_VOID     | T_CLASS_NONE   | T_SIGN_NONE     | T_SIZE_NONE,
-    T_STRUCT        = T_TYPE_STRUCT   | T_CLASS_STRUCT | T_SIGN_NONE     | T_SIZE_NONE,
-    T_UNION         = T_TYPE_UNION    | T_CLASS_STRUCT | T_SIGN_NONE     | T_SIZE_NONE,
-    T_ARRAY        = T_TYPE_ARRAY    | T_CLASS_PTR    | T_SIGN_NONE     | T_SIZE_NONE,
-    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,
+    /* Types */
+    T_CHAR             = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
+    T_SCHAR            = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
+    T_UCHAR            = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
+    T_SHORT            = T_TYPE_SHORT    | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_SHORT,
+    T_USHORT    = T_TYPE_SHORT    | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_SHORT,
+    T_INT              = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
+    T_UINT             = T_TYPE_INT      | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
+    T_LONG             = T_TYPE_LONG     | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_LONG,
+    T_ULONG            = T_TYPE_LONG     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_LONG,
+    T_LONGLONG         = T_TYPE_LONGLONG | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_LONGLONG,
+    T_ULONGLONG        = T_TYPE_LONGLONG | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_LONGLONG,
+    T_ENUM             = T_TYPE_ENUM     | T_CLASS_INT    | T_SIGN_SIGNED   | T_SIZE_NONE,
+    T_FLOAT            = T_TYPE_FLOAT    | T_CLASS_FLOAT  | T_SIGN_NONE     | T_SIZE_NONE,
+    T_DOUBLE           = T_TYPE_DOUBLE   | T_CLASS_FLOAT  | T_SIGN_NONE     | T_SIZE_NONE,
+    T_VOID             = T_TYPE_VOID     | T_CLASS_NONE   | T_SIGN_NONE     | T_SIZE_NONE,
+    T_STRUCT    = T_TYPE_STRUCT   | T_CLASS_STRUCT | T_SIGN_NONE     | T_SIZE_NONE,
+    T_UNION     = T_TYPE_UNION    | T_CLASS_STRUCT | T_SIGN_NONE     | T_SIZE_NONE,
+    T_ARRAY            = T_TYPE_ARRAY    | T_CLASS_PTR    | T_SIGN_NONE     | T_SIZE_NONE,
+    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,
 
 };
 
 
 
-/* Data types */
-#define        T_END           0x0000
-#define T_CHAR                 0x0011
-#define T_INT                  0x0012
-#define        T_SHORT         0x0013
-#define T_LONG                 0x0014
-#define T_ENUM                 0x0015
-#define T_UCHAR                0x0019
-#define T_UINT                 0x001A
-#define T_USHORT               0x001B
-#define T_ULONG                0x001C
-
-#define T_FLOAT                0x0025
-#define T_DOUBLE               0x0026
-
-#define T_VOID                 0x0001          /* void parameter list */
-#define T_FUNC                 0x0002          /* Function */
-
-#define T_UNSIGNED             0x0008          /* Class */
-#define T_INTEGER              0x0010          /* Class */
-#define T_REAL                 0x0020          /* Class */
-#define T_POINTER              0x0040          /* Class */
-#define T_PTR                  0x0049
-#define T_ARRAY                0x004A
-#define T_STRUCT               0x0080
-#define T_UNION                0x0081
-#define T_SMASK                0x003F
-
-
-
 /* Forward for a symbol entry */
 struct SymEntry;
 
@@ -161,17 +140,17 @@ typedef unsigned short type;
 /* Maximum length of a type string */
 #define MAXTYPELEN     30
 
-/* type elements needed for Encode/Decode */
+/* Type elements needed for Encode/Decode */
 #define DECODE_SIZE            5
 
 /* 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_pschar [];
-extern type type_puchar [];
+extern type type_size_t [];
 
 
 
@@ -184,9 +163,6 @@ extern type type_puchar [];
 unsigned TypeLen (const type* Type);
 /* Return the length of the type string */
 
-int TypeCmp (const type* T1, const type* T2);
-/* Compare two type strings */
-
 type* TypeCpy (type* Dest, const type* Src);
 /* Copy a type string */
 
@@ -213,12 +189,20 @@ type* GetCharArrayType (unsigned Len);
 type* GetImplicitFuncType (void);
 /* Return a type string for an inplicitly declared function */
 
+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);
 /* Output translation of type array. */
 
 void PrintRawType (FILE* F, const type* Type);
 /* Print a type string in raw format (for debugging) */
 
+void PrintFuncSig (FILE* F, const char* Name, type* Type);
+/* Print a function signature. */
+
 void Encode (type* Type, unsigned long Val);
 /* Encode an unsigned long into a type array */
 
@@ -237,6 +221,9 @@ int HasEncode (const type* Type);
 void CopyEncode (const type* Source, type* Target);
 /* Copy encoded data from Source to Target */
 
+type UnqualifiedType (type T);
+/* Return the unqalified type */
+
 unsigned SizeOf (const type* Type);
 /* Compute size of object represented by type array. */
 
@@ -251,42 +238,84 @@ type* Indirect (type* Type);
  * given type points to.
  */
 
-int IsVoid (const type* Type);
-/* Return true if this is a void type */
+int IsTypeChar (const type* T) attribute ((const));
+/* Return true if this is a character type */
+
+int IsTypeInt (const type* T) attribute ((const));
+/* Return true if this is an int type (signed or unsigned) */
+
+int IsTypeLong (const type* T) attribute ((const));
+/* Return true if this is a long type (signed or unsigned) */
+
+int IsTypeFloat (const type* T) attribute ((const));
+/* Return true if this is a float type */
 
-int IsPtr (const type* Type);
+int IsTypeDouble (const type* T) attribute ((const));
+/* Return true if this is a double type */
+
+int IsTypePtr (const type* Type) attribute ((const));
 /* Return true if this is a pointer type */
 
-int IsChar (const type* Type);
-/* Return true if this is a character type */
+int IsTypeArray (const type* Type) attribute ((const));
+/* Return true if this is an array type */
+
+int IsTypeVoid (const type* Type) attribute ((const));
+/* Return true if this is a void type */
 
-int IsInt (const type* Type);
+int IsTypeFunc (const type* Type) attribute ((const));
+/* Return true if this is a function class */
+
+int IsClassInt (const type* Type) attribute ((const));
 /* Return true if this is an integer type */
 
-int IsLong (const type* Type);
-/* Return true if this is a long type (signed or unsigned) */
+int IsClassFloat (const type* Type) attribute ((const));
+/* Return true if this is a float type */
 
-int IsUnsigned (const type* Type);
-/* Return true if this is an unsigned type */
+int IsClassPtr (const type* Type) attribute ((const));
+/* Return true if this is a pointer type */
 
-int IsStruct (const type* Type);
+int IsClassStruct (const type* Type) attribute ((const));
 /* Return true if this is a struct type */
 
-int IsFunc (const type* Type);
-/* Return true if this is a function type */
+int IsSignUnsigned (const type* Type) attribute ((const));
+/* Return true if this is an unsigned type */
 
-int IsFastCallFunc (const type* Type);
+int IsQualConst (const type* T) attribute ((const));
+/* Return true if the given type has a const memory image */
+
+int IsQualVolatile (const type* T) attribute ((const));
+/* Return true if the given type has a volatile type qualifier */
+
+int IsFastCallFunc (const type* T) attribute ((const));
 /* Return true if this is a function type with __fastcall__ calling conventions */
 
-int IsFuncPtr (const type* Type);
+int IsVariadicFunc (const type* T) attribute ((const));
+/* Return true if this is a function type with variable parameter list */
+
+int IsTypeFuncPtr (const type* T) attribute ((const));
 /* Return true if this is a function pointer */
 
-int IsArray (const type* Type);
-/* Return true if this is an array type */
+type GetType (const type* T) attribute ((const));
+/* Get the raw type */
+
+type GetClass (const type* T) attribute ((const));
+/* Get the class of a type string */
 
-struct FuncDesc* GetFuncDesc (const type* Type);
+type GetSignedness (const type* T) attribute ((const));
+/* Get the sign of a type */
+
+type GetSizeModifier (const type* T) attribute ((const));
+/* Get the size modifier of a type */
+
+type GetQualifier (const type* T) attribute ((const));
+/* Get the qualifier from the given type string */
+
+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));
+/* Return a pointer to the return type of a function or pointer-to-function type */
+
 
 
 /* End of datatype.h */