* src/SDCCBlock.c (addiCodeToeBBlock): fixed bug 1652207: GOTO icodes appended by...
[fw/sdcc] / src / SDCCsymt.h
index c9668d2d28192d9e9daeafab1084d07cd73658a9..6ad8662ba8e50b3ac983f1d3727be50fa8c3aaa8 100644 (file)
@@ -29,6 +29,7 @@
 #define SDCC_NAME_MAX  3*SDCC_SYMNAME_MAX // big enough for _<func>_<var>_etc
 #include "SDCChasht.h"
 #include "SDCCglobl.h"
+#include "dbuf.h"
 
 #define INTNO_MAX 255                   /* maximum allowed interrupt number */
 #define INTNO_UNSPEC (INTNO_MAX+1)      /* interrupt number unspecified */
@@ -60,10 +61,17 @@ enum {
 };
 
 // values for first byte (or 3 most significant bits) of generic pointer.
+#if 0
 #define GPTYPE_FAR       0x00
 #define GPTYPE_NEAR      0x40
 #define GPTYPE_XSTACK    0x60
 #define GPTYPE_CODE      0x80
+#else
+#define GPTYPE_FAR     (port->gp_tags.tag_far)
+#define GPTYPE_NEAR    (port->gp_tags.tag_near)
+#define GPTYPE_XSTACK  (port->gp_tags.tag_xstack)
+#define GPTYPE_CODE    (port->gp_tags.tag_code)
+#endif
 
 #define HASHTAB_SIZE 256
 
@@ -86,6 +94,8 @@ typedef struct structdef
     struct symbol *fields;              /* pointer to fields     */
     unsigned size;                      /* sizeof the table in bytes  */
     int type;                           /* STRUCT or UNION */
+    bool b_flexArrayMember;             /* has got an flexible array member,
+                                           only needed for syntax checks */
   }
 structdef;
 
@@ -127,6 +137,13 @@ typedef enum
   }
 STORAGE_CLASS;
 
+#define TYPE_TARGET_CHAR  TYPE_BYTE
+#define TYPE_TARGET_INT   TYPE_WORD
+#define TYPE_TARGET_LONG  TYPE_DWORD
+#define TYPE_TARGET_UCHAR TYPE_UBYTE
+#define TYPE_TARGET_UINT  TYPE_UWORD
+#define TYPE_TARGET_ULONG TYPE_UDWORD
+
 /* specifier is the last in the type-chain */
 typedef struct specifier
   {
@@ -142,6 +159,7 @@ typedef struct specifier
     unsigned b_absadr:1;                /* absolute address specfied  */
     unsigned b_volatile:1;              /* is marked as volatile      */
     unsigned b_const:1;                 /* is a constant              */
+    unsigned b_restrict:1;              /* is restricted              */
     unsigned b_typedef:1;               /* is typedefed               */
     unsigned b_isregparm:1;             /* is the first parameter     */
     unsigned b_isenum:1;                /* is an enumerated type      */
@@ -152,14 +170,14 @@ typedef struct specifier
     int argreg;                         /* reg no for regparm         */
     union
       {                                 /* Values if constant or enum */
-        TYPE_WORD   v_int;              /* 2 bytes: int and char values           */
-        char       *v_char;             /*          character string              */
-        TYPE_UWORD  v_uint;             /* 2 bytes: unsigned int const value      */
-        TYPE_DWORD  v_long;             /* 4 bytes: long constant value           */
-        TYPE_UDWORD v_ulong;            /* 4 bytes: unsigned long constant value  */
-        double      v_float;            /*          floating point constant value */
-        TYPE_UDWORD v_fixed16x16;       /* 4 bytes: fixed floating point constant value */
-        struct symbol *v_enum;          /* ptr to enum_list if enum==1            */
+        TYPE_TARGET_INT   v_int;        /* 2 bytes: int and char values           */
+        char             *v_char;       /*          character string              */
+        TYPE_TARGET_UINT  v_uint;       /* 2 bytes: unsigned int const value      */
+        TYPE_TARGET_LONG  v_long;       /* 4 bytes: long constant value           */
+        TYPE_TARGET_ULONG v_ulong;      /* 4 bytes: unsigned long constant value  */
+        double            v_float;      /*          floating point constant value */
+        TYPE_TARGET_ULONG v_fixed16x16; /* 4 bytes: fixed floating point constant value */
+        struct symbol    *v_enum;       /* ptr to enum_list if enum==1            */
       }
     const_val;
     struct structdef *v_struct;         /* structure pointer      */
@@ -185,9 +203,11 @@ DECLARATOR_TYPE;
 typedef struct declarator
   {
     DECLARATOR_TYPE dcl_type;           /* POINTER,ARRAY or FUNCTION  */
-    unsigned int num_elem;              /* # of elems if type==array  */
+    unsigned int num_elem;              /* # of elems if type==array, */
+                                        /* always 0 for flexible arrays */
     unsigned ptr_const:1;               /* pointer is constant        */
     unsigned ptr_volatile:1;            /* pointer is volatile        */
+    unsigned ptr_restrict:1;            /* pointer is resticted       */
     struct sym_link *tspec;             /* pointer type specifier     */
   }
 declarator;
@@ -243,11 +263,17 @@ typedef struct symbol
     char name[SDCC_SYMNAME_MAX + 1];    /* Input Variable Name     */
     char rname[SDCC_NAME_MAX + 1];      /* internal name           */
 
-    short level;                        /* declration lev,fld offset */
-    short block;                        /* sequential block # of defintion */
+    short level;                        /* declaration lev,fld offset */
+    short block;                        /* sequential block # of definition */
     int key;
+    unsigned flexArrayLength;           /* if the symbol specifies a struct
+    with a "flexible array member", then the additional length in bytes for
+    the "fam" is stored here. Because the lenght can be different from symbol
+    to symbol AND v_struct isn't copied in copyLinkChain(), it's located here
+    in the symbol and not in v_struct or the declarator */
     unsigned implicit:1;                /* implicit flag                     */
     unsigned undefined:1;               /* undefined variable                */
+    unsigned infertype:1;               /* type should be inferred from first assign */
     unsigned _isparm:1;                 /* is a parameter          */
     unsigned ismyparm:1;                /* is parameter of the function being generated */
     unsigned isitmp:1;                  /* is an intermediate temp */
@@ -257,7 +283,7 @@ typedef struct symbol
     unsigned isinvariant:1;             /* is a loop invariant  */
     unsigned cdef:1;                    /* compiler defined symbol */
     unsigned addrtaken:1;               /* address of the symbol was taken */
-    unsigned isreqv:1;                  /* is the register quivalent of a symbol */
+    unsigned isreqv:1;                  /* is the register equivalent of a symbol */
     unsigned udChked:1;                 /* use def checking has been already done */
 
     /* following flags are used by the backend
@@ -341,6 +367,7 @@ extern sym_link *validateLink(sym_link  *l,
 #define DCL_ELEM(l)  validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem
 #define DCL_PTR_CONST(l) validateLink(l, "DCL_PTR_CONST", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_const
 #define DCL_PTR_VOLATILE(l) validateLink(l, "DCL_PTR_VOLATILE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_volatile
+#define DCL_PTR_RESTRICT(l) validateLink(l, "DCL_PTR_RESTRICT", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_restrict
 #define DCL_TSPEC(l) validateLink(l, "DCL_TSPEC", #l, DECLARATOR, __FILE__, __LINE__)->select.d.tspec
 
 #define FUNC_DEBUG //assert(IS_FUNC(x));
@@ -414,6 +441,7 @@ extern sym_link *validateLink(sym_link  *l,
 #define SPEC_ISR_SAVED_BANKS(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
 #define SPEC_VOLATILE(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_volatile
 #define SPEC_CONST(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_const
+#define SPEC_RESTRICT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_restrict
 #define SPEC_STRUCT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.v_struct
 #define SPEC_TYPEDEF(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_typedef
 #define SPEC_REGPARM(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_isregparm
@@ -433,6 +461,7 @@ extern sym_link *validateLink(sym_link  *l,
                                      DCL_TYPE(x) == CPOINTER   ||    \
                                      DCL_TYPE(x) == UPOINTER  ))
 #define IS_PTR_CONST(x) (IS_PTR(x) && DCL_PTR_CONST(x))
+#define IS_PTR_RESTRICT(x) (IS_PTR(x) && DCL_PTR_RESTRICT(x))
 #define IS_FARPTR(x) (IS_DECL(x) && DCL_TYPE(x) == FPOINTER)
 #define IS_CODEPTR(x) (IS_DECL(x) && DCL_TYPE(x) == CPOINTER)
 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
@@ -558,7 +587,6 @@ void printSymChain (symbol *, int);
 void printStruct (structdef *, int);
 char *genSymName (int);
 sym_link *getSpec (sym_link *);
-char *genSymName (int);
 int compStructSize (int, structdef *);
 sym_link *copyLinkChain (sym_link *);
 int checkDecl (symbol *, int);
@@ -568,7 +596,6 @@ value *checkStructIval (symbol *, value *);
 value *checkArrayIval (sym_link *, value *);
 value *checkIval (sym_link *, value *);
 unsigned int getSize (sym_link *);
-unsigned int getAllocSize (sym_link *);
 unsigned int bitsForType (sym_link *);
 sym_link *newIntLink ();
 sym_link *newCharLink ();
@@ -584,9 +611,11 @@ void addSymChain (symbol **);
 sym_link *structElemType (sym_link *, value *);
 symbol *getStructElement (structdef *, symbol *);
 sym_link *computeType (sym_link *, sym_link *, RESULT_TYPE, int);
+void processFuncPtrArgs (sym_link *);
 void processFuncArgs (symbol *);
 int isSymbolEqual (symbol *, symbol *);
-int powof2 (TYPE_UDWORD);
+int powof2 (TYPE_TARGET_ULONG);
+void dbuf_printTypeChain (sym_link *, struct dbuf_s *);
 void printTypeChain (sym_link *, FILE *);
 void printTypeChainRaw (sym_link *, FILE *);
 void initCSupport ();